You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

708 lines
24 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. using Microsoft.Extensions.FileSystemGlobbing.Internal;
  2. using Microsoft.Extensions.FileSystemGlobbing;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Volo.Abp;
  9. using Shentun.Peis.Models;
  10. using Shentun.Peis.Enums;
  11. namespace Shentun.Peis
  12. {
  13. public static class DataHelper
  14. {
  15. /// <summary>
  16. /// 生成历次综述医生小结
  17. /// </summary>
  18. /// <param name="SumSummaryHeaders"></param>
  19. /// <returns></returns>
  20. public static string SetSumSummarys(List<SumSummaryHeader> SumSummaryHeaders)
  21. {
  22. StringBuilder msg = new StringBuilder();
  23. if (SumSummaryHeaders.Count > 0)
  24. {
  25. foreach (var item in SumSummaryHeaders)
  26. {
  27. msg.Append("* " + item.SummaryTitle + ":" + "<br/>");
  28. if (item.SumSummaryContents.Count > 0)
  29. {
  30. var SumSummaryContents = item.SumSummaryContents.ToList();
  31. foreach (var item2 in SumSummaryContents)
  32. {
  33. msg.Append("(" + SumSummaryContents.IndexOf(item2) + 1 + ")" + item2.SummaryContent + "<br/>");
  34. }
  35. }
  36. }
  37. }
  38. return msg.ToString();
  39. }
  40. /// <summary>
  41. /// 生成历次综述医生小结
  42. /// </summary>
  43. /// <param name="SumSummaryHeaders"></param>
  44. /// <returns></returns>
  45. public static string SetSumSummarysInReport(List<SumSummaryHeader> SumSummaryHeaders)
  46. {
  47. StringBuilder msg = new StringBuilder();
  48. if (SumSummaryHeaders.Count > 0)
  49. {
  50. foreach (var item in SumSummaryHeaders)
  51. {
  52. msg.Append("* " + item.SummaryTitle + ":" + "\n");
  53. if (item.SumSummaryContents.Count > 0)
  54. {
  55. var SumSummaryContents = item.SumSummaryContents.ToList();
  56. foreach (var item2 in SumSummaryContents)
  57. {
  58. msg.Append("(" + SumSummaryContents.IndexOf(item2) + 1 + ")" + item2.SummaryContent + "\n");
  59. }
  60. }
  61. }
  62. }
  63. return msg.ToString();
  64. }
  65. /// <summary>
  66. /// 生成总诊建议
  67. /// </summary>
  68. /// <param name="SumSummaryHeaders"></param>
  69. /// <returns></returns>
  70. public static string SetSumSuggestionInReport(List<SumSuggestionHeader> SumSuggestionHeaders)
  71. {
  72. StringBuilder msg = new StringBuilder();
  73. if (SumSuggestionHeaders.Count > 0)
  74. {
  75. foreach (var item in SumSuggestionHeaders)
  76. {
  77. msg.Append("* " + item.SuggestionTitle + ":" + "\n");
  78. if (item.SumSuggestionContents.Count > 0)
  79. {
  80. var SumSuggestionContents = item.SumSuggestionContents.ToList();
  81. foreach (var item2 in SumSuggestionContents)
  82. {
  83. msg.Append("(" + SumSuggestionContents.IndexOf(item2) + 1 + ")" + item2.SuggestionContent + "\n");
  84. }
  85. }
  86. }
  87. }
  88. return msg.ToString();
  89. }
  90. /// <summary>
  91. /// 统一转换日期为字符串格式
  92. /// </summary>
  93. /// <param name="dateTime"></param>
  94. /// <returns></returns>
  95. public static string ConversionDateToString(DateTime? dateTime)
  96. {
  97. if (dateTime == null)
  98. {
  99. return "";
  100. }
  101. else
  102. {
  103. return dateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  104. }
  105. }
  106. /// <summary>
  107. /// 转换 只保留年月日
  108. /// </summary>
  109. /// <param name="dateTime"></param>
  110. /// <returns></returns>
  111. public static string ConversionDateShortToString(DateTime? dateTime)
  112. {
  113. if (dateTime == null)
  114. {
  115. return "";
  116. }
  117. else
  118. {
  119. return dateTime.Value.ToString("yyyy-MM-dd");
  120. }
  121. }
  122. /// <summary>
  123. /// 验证是否为空或者空字符串
  124. /// </summary>
  125. /// <param name="obj"></param>
  126. /// <returns></returns>
  127. public static bool IsNullOrEmpty(string obj)
  128. {
  129. bool msg = false;
  130. if (string.IsNullOrEmpty(obj))
  131. {
  132. msg = true;
  133. }
  134. else
  135. {
  136. if (obj.Trim() == "")
  137. {
  138. msg = true;
  139. }
  140. }
  141. return msg;
  142. }
  143. /// <summary>
  144. /// 验证十进制颜色代码是否合规
  145. /// </summary>
  146. /// <param name="str"></param>
  147. /// <returns>格式不正确返回为false</returns>
  148. public static bool IsColorNumber(int str)
  149. {
  150. //0~16777215
  151. if (str > 16777215 || str < 0)
  152. return false;
  153. else
  154. return true;
  155. }
  156. /// <summary>
  157. /// 转换guid
  158. /// </summary>
  159. /// <param name="id"></param>
  160. /// <returns></returns>
  161. public static Guid ConvertGuid(Guid? id)
  162. {
  163. if (id == null)
  164. {
  165. return Guid.Empty;
  166. }
  167. else
  168. {
  169. return id.Value;
  170. }
  171. }
  172. /// <summary>将大驼峰命名转为蛇形命名</summary>
  173. public static string RenameSnakeCase(string str)
  174. {
  175. var builder = new StringBuilder();
  176. var name = str;
  177. var previousUpper = false;
  178. for (var i = 0; i < name.Length; i++)
  179. {
  180. var c = name[i];
  181. if (char.IsUpper(c))
  182. {
  183. if (i > 0 && !previousUpper)
  184. {
  185. builder.Append("_");
  186. }
  187. builder.Append(char.ToLowerInvariant(c));
  188. previousUpper = true;
  189. }
  190. else
  191. {
  192. builder.Append(c);
  193. previousUpper = false;
  194. }
  195. }
  196. return builder.ToString();
  197. }
  198. public static string RenameSnakeCase2(string str)
  199. {
  200. return str;
  201. }
  202. /// <summary>
  203. /// 转换人民币大小金额
  204. /// </summary>
  205. /// <param name="num">金额</param>
  206. /// <returns>返回大写形式</returns>
  207. public static string CmycurD(decimal num)
  208. {
  209. string str1 = "零壹贰叁肆伍陆柒捌玖"; //0-9所对应的汉字
  210. string str2 = "万仟佰拾亿仟佰拾万仟佰拾元角分"; //数字位所对应的汉字
  211. string str3 = ""; //从原num值中取出的值
  212. string str4 = ""; //数字的字符串形式
  213. string str5 = ""; //人民币大写金额形式
  214. int i; //循环变量
  215. int j; //num的值乘以100的字符串长度
  216. string ch1 = ""; //数字的汉语读法
  217. string ch2 = ""; //数字位的汉字读法
  218. int nzero = 0; //用来计算连续的零值是几个
  219. int temp; //从原num值中取出的值
  220. num = Math.Round(Math.Abs(num), 2); //将num取绝对值并四舍五入取2位小数
  221. str4 = ((long)(num * 100)).ToString(); //将num乘100并转换成字符串形式
  222. j = str4.Length; //找出最高位
  223. if (j > 15) { return "溢出"; }
  224. str2 = str2.Substring(15 - j); //取出对应位数的str2的值。如:200.55,j为5所以str2=佰拾元角分
  225. //循环取出每一位需要转换的值
  226. for (i = 0; i < j; i++)
  227. {
  228. str3 = str4.Substring(i, 1); //取出需转换的某一位的值
  229. temp = Convert.ToInt32(str3); //转换为数字
  230. if (i != (j - 3) && i != (j - 7) && i != (j - 11) && i != (j - 15))
  231. {
  232. //当所取位数不为元、万、亿、万亿上的数字时
  233. if (str3 == "0")
  234. {
  235. ch1 = "";
  236. ch2 = "";
  237. nzero = nzero + 1;
  238. }
  239. else
  240. {
  241. if (str3 != "0" && nzero != 0)
  242. {
  243. ch1 = "零" + str1.Substring(temp * 1, 1);
  244. ch2 = str2.Substring(i, 1);
  245. nzero = 0;
  246. }
  247. else
  248. {
  249. ch1 = str1.Substring(temp * 1, 1);
  250. ch2 = str2.Substring(i, 1);
  251. nzero = 0;
  252. }
  253. }
  254. }
  255. else
  256. {
  257. //该位是万亿,亿,万,元位等关键位
  258. if (str3 != "0" && nzero != 0)
  259. {
  260. ch1 = "零" + str1.Substring(temp * 1, 1);
  261. ch2 = str2.Substring(i, 1);
  262. nzero = 0;
  263. }
  264. else
  265. {
  266. if (str3 != "0" && nzero == 0)
  267. {
  268. ch1 = str1.Substring(temp * 1, 1);
  269. ch2 = str2.Substring(i, 1);
  270. nzero = 0;
  271. }
  272. else
  273. {
  274. if (str3 == "0" && nzero >= 3)
  275. {
  276. ch1 = "";
  277. ch2 = "";
  278. nzero = nzero + 1;
  279. }
  280. else
  281. {
  282. if (j >= 11)
  283. {
  284. ch1 = "";
  285. nzero = nzero + 1;
  286. }
  287. else
  288. {
  289. ch1 = "";
  290. ch2 = str2.Substring(i, 1);
  291. nzero = nzero + 1;
  292. }
  293. }
  294. }
  295. }
  296. }
  297. if (i == (j - 11) || i == (j - 3))
  298. {
  299. //如果该位是亿位或元位,则必须写上
  300. ch2 = str2.Substring(i, 1);
  301. }
  302. str5 = str5 + ch1 + ch2;
  303. if (i == j - 1 && str3 == "0")
  304. {
  305. //最后一位(分)为0时,加上“整”
  306. str5 = str5 + '整';
  307. }
  308. }
  309. if (num == 0)
  310. {
  311. str5 = "零元整";
  312. }
  313. return str5;
  314. }
  315. /// <summary>
  316. /// 解析身份证信息
  317. /// </summary>
  318. /// <param name="IdNo">身份证号码</param>
  319. /// <returns></returns>
  320. public static AutoCardInfo AutoIDCard(string IdNo)
  321. {
  322. if (!string.IsNullOrEmpty(IdNo) && (IdNo.Trim().Length == 15 || IdNo.Trim().Length == 18))
  323. {
  324. AutoCardInfo msg = new AutoCardInfo();
  325. string birthday = "";
  326. string sex = "";
  327. string identityCard = IdNo.Trim();
  328. if (identityCard.Length == 18)
  329. {
  330. birthday = identityCard.Substring(6, 4) + "-" + identityCard.Substring(10, 2) + "-" + identityCard.Substring(12, 2);
  331. sex = identityCard.Substring(14, 3);
  332. }
  333. else if (identityCard.Length == 15)
  334. {
  335. birthday = "19" + identityCard.Substring(6, 2) + "-" + identityCard.Substring(8, 2) + "-" + identityCard.Substring(10, 2);
  336. sex = identityCard.Substring(12, 3);
  337. }
  338. try
  339. {
  340. DateTime cvdate = Convert.ToDateTime(birthday);
  341. if (cvdate > DateTime.Now || cvdate < new DateTime(1900, 1, 1))
  342. {
  343. return null;
  344. }
  345. if (int.Parse(sex) % 2 == 0)
  346. {
  347. msg.SexId = 'F';
  348. }
  349. else
  350. {
  351. msg.SexId = 'M';
  352. }
  353. }
  354. catch
  355. {
  356. return null;
  357. }
  358. short age = 0;
  359. DateTime dt = Convert.ToDateTime(birthday);
  360. age = (short)(DateTime.Now.Year - dt.Year);
  361. if (DateTime.Now.Month < dt.Month || (DateTime.Now.Month == dt.Month && DateTime.Now.Day < dt.Day))
  362. {
  363. age--;
  364. }
  365. msg.BirthDate = birthday;
  366. msg.IdNo = IdNo;
  367. msg.Age = age;
  368. return msg;
  369. }
  370. else
  371. {
  372. return null;
  373. }
  374. }
  375. /// <summary>
  376. /// 出生日期转换年龄
  377. /// </summary>
  378. /// <param name="birthday">出生日期</param>
  379. /// <returns></returns>
  380. public static short? AutoAgeInBirthday(string birthday)
  381. {
  382. if (!string.IsNullOrEmpty(birthday))
  383. {
  384. short age;
  385. try
  386. {
  387. DateTime cvdate = Convert.ToDateTime(birthday);
  388. if (cvdate > DateTime.Now || cvdate < new DateTime(1900, 1, 1))
  389. {
  390. return null;
  391. }
  392. }
  393. catch
  394. {
  395. return null;
  396. }
  397. DateTime dt = Convert.ToDateTime(birthday);
  398. age = (short)(DateTime.Now.Year - dt.Year);
  399. if (DateTime.Now.Month < dt.Month || (DateTime.Now.Month == dt.Month && DateTime.Now.Day < dt.Day))
  400. {
  401. age--;
  402. }
  403. return age;
  404. }
  405. else
  406. {
  407. return null;
  408. }
  409. }
  410. /// <summary>
  411. /// 年龄转换出生日期
  412. /// </summary>
  413. /// <param name="age">年龄</param>
  414. /// <returns></returns>
  415. public static string AutoBirthdayInAge(short age)
  416. {
  417. string birthday;
  418. DateTime now = DateTime.Now;
  419. birthday = now.AddYears(0 - age).ToString("yyyy-MM-dd");
  420. return birthday;
  421. }
  422. /// <summary>
  423. /// 保留小数 转换decimal
  424. /// </summary>
  425. /// <param name="value"></param>
  426. /// <param name="decimalLength"></param>
  427. /// <returns></returns>
  428. public static decimal DecimalRetainDecimals(decimal? value, int decimalLength)
  429. {
  430. decimal newValue = 0;
  431. if (value != null)
  432. {
  433. newValue = Math.Round(value.Value, decimalLength);
  434. }
  435. return newValue;
  436. }
  437. #region 数据检查
  438. /// <summary>
  439. /// 数据检查 对象
  440. /// </summary>
  441. /// <param name="value">需要验证的对象</param>
  442. /// <param name="parameterName">字段名称</param>
  443. /// <param name="ExceptionMessage">异常提示后缀</param>
  444. /// <exception cref="ArgumentException"></exception>
  445. public static void CheckEntityIsNull(object value, string parameterName = "对象", string ExceptionMessage = "不能为空")
  446. {
  447. if (value == null)
  448. {
  449. throw new UserFriendlyException($"{parameterName}{ExceptionMessage}");
  450. }
  451. }
  452. /// <summary>
  453. /// 数据检查 字符串
  454. /// </summary>
  455. /// <param name="value">需要验证的值</param>
  456. /// <param name="parameterName">字段名称</param>
  457. /// <param name="ExceptionMessage">异常提示后缀</param>
  458. /// <exception cref="ArgumentException"></exception>
  459. public static void CheckStringIsNull(string value, string parameterName, string ExceptionMessage = "不能为空")
  460. {
  461. if (string.IsNullOrWhiteSpace(value))
  462. {
  463. throw new UserFriendlyException($"{parameterName}{ExceptionMessage}");
  464. }
  465. }
  466. #region 验证char类型参数
  467. /// <summary>
  468. /// 验证char类型参数是否为null
  469. /// </summary>
  470. /// <param name="value">需要验证的值</param>
  471. /// <param name="parameterName">字段名称</param>
  472. /// <param name="ExceptionMessage">异常提示后缀</param>
  473. /// <exception cref="ArgumentException"></exception>
  474. public static void CheckCharIsNull(char? value, string parameterName, string ExceptionMessage = "不能为空")
  475. {
  476. if (value == null)
  477. {
  478. throw new ArgumentException($"{parameterName}{ExceptionMessage}");
  479. }
  480. }
  481. /// <summary>
  482. /// 验证char类型参数是否为0
  483. /// </summary>
  484. /// <param name="value">需要验证的值</param>
  485. /// <param name="parameterName">字段名称</param>
  486. /// <param name="ExceptionMessage">异常提示后缀</param>
  487. /// <exception cref="ArgumentException"></exception>
  488. public static void CheckCharIsZero(char value, string parameterName, string ExceptionMessage = "不能为0")
  489. {
  490. if (value == '0')
  491. {
  492. throw new ArgumentException($"{parameterName}{ExceptionMessage}");
  493. }
  494. }
  495. /// <summary>
  496. /// 验证char类型参数是否为Y、N
  497. /// </summary>
  498. /// <param name="value">需要验证的值</param>
  499. /// <param name="parameterName">字段名称</param>
  500. /// <exception cref="ArgumentException"></exception>
  501. public static void CheckCharIsYOrN(char value, string parameterName)
  502. {
  503. if (value != 'Y' && value != 'N')
  504. {
  505. throw new ArgumentException($"{parameterName}参数为:{value},是无效值,只能为Y跟N");
  506. }
  507. }
  508. #endregion
  509. /// <summary>
  510. /// 验证Int类型数据是否>0
  511. /// </summary>
  512. /// <param name="value">需要验证的值</param>
  513. /// <param name="parameterName">字段名称</param>
  514. /// <param name="ExceptionMessage">异常提示后缀</param>
  515. /// <exception cref="ArgumentException"></exception>
  516. public static void CheckIntIsGeaterThanZero(int value, string parameterName, string ExceptionMessage = "只能为大于0的值")
  517. {
  518. if (value <= 0)
  519. {
  520. throw new UserFriendlyException($"{parameterName}{ExceptionMessage}");
  521. }
  522. }
  523. /// <summary>
  524. /// 验证Guid数据是否为null
  525. /// </summary>
  526. /// <param name="value">需要验证的值</param>
  527. /// <param name="parameterName">字段名称</param>
  528. /// <param name="ExceptionMessage">异常提示后缀</param>
  529. /// <exception cref="ArgumentException"></exception>
  530. public static void CheckGuidIsNull(Guid? value, string parameterName, string ExceptionMessage = "不能为空")
  531. {
  532. if (value == null)
  533. {
  534. throw new UserFriendlyException($"{parameterName}{ExceptionMessage}");
  535. }
  536. }
  537. /// <summary>
  538. /// 验证Guid数据是否为默认值00000000-0000-0000-0000-000000000000
  539. /// </summary>
  540. /// <param name="value">需要验证的值</param>
  541. /// <param name="parameterName">字段名称</param>
  542. /// <param name="ExceptionMessage">异常提示后缀</param>
  543. /// <exception cref="ArgumentException"></exception>
  544. public static void CheckGuidIsDefaultValue(Guid value, string parameterName, string ExceptionMessage = "不能为默认值00000000-0000-0000-0000-000000000000")
  545. {
  546. if (value == Guid.Empty || value == default(Guid))
  547. {
  548. throw new UserFriendlyException($"{parameterName}{ExceptionMessage}");
  549. }
  550. }
  551. /// <summary>
  552. ///验证decimal类型数据大于0
  553. /// </summary>
  554. /// <param name="value">需要验证的值</param>
  555. /// <param name="parameterName">字段名称</param>
  556. /// <param name="ExceptionMessage">异常提示后缀</param>
  557. /// <exception cref="ArgumentException"></exception>
  558. public static void CheckDecimalIsGeaterThanZero(decimal value, string parameterName, string ExceptionMessage = "值只能大于0")
  559. {
  560. if (value <= 0)
  561. {
  562. throw new UserFriendlyException($"{parameterName}{ExceptionMessage}");
  563. }
  564. }
  565. /// <summary>
  566. /// 数据检查 decimal
  567. /// </summary>
  568. /// <param name="value">需要验证的值</param>
  569. /// <param name="parameterName">字段名称</param>
  570. /// <param name="ExceptionMessage">异常提示后缀</param>
  571. /// <exception cref="ArgumentException"></exception>
  572. public static void CheckDecimalIsNull(decimal? value, string parameterName, string ExceptionMessage = "不能为空")
  573. {
  574. if (value == null)
  575. {
  576. throw new UserFriendlyException($"{parameterName}{ExceptionMessage}");
  577. }
  578. }
  579. public static void CheckSex(char value)
  580. {
  581. if (value != SexFlag.Male && value != SexFlag.Female && value != SexFlag.UnKnown)
  582. {
  583. throw new ArgumentException($"性别参数不正确");
  584. }
  585. }
  586. public static void CheckForSex(char value)
  587. {
  588. if (value != ForSexFlag.Male && value != ForSexFlag.Female && value != ForSexFlag.All)
  589. {
  590. throw new UserFriendlyException($"性别参数不正确");
  591. }
  592. }
  593. public static void CheckMaritalStatus(char value)
  594. {
  595. if (value != MaritalStatusFlag.UnMarried && value != MaritalStatusFlag.Married &&
  596. value != MaritalStatusFlag.Divorce && value != MaritalStatusFlag.Widowed &&
  597. value != MaritalStatusFlag.DivorceOrWidowed &&
  598. value != MaritalStatusFlag.UnKnown)
  599. {
  600. throw new UserFriendlyException($"婚姻状况参数不正确");
  601. }
  602. }
  603. public static void CheckForMaritalStatus(char value)
  604. {
  605. if (value != MaritalStatusFlag.UnMarried && value != MaritalStatusFlag.Married &&
  606. value != MaritalStatusFlag.All)
  607. {
  608. throw new UserFriendlyException($"婚姻状况参数不正确");
  609. }
  610. }
  611. public static void CheckIdNo(string idNo)
  612. {
  613. if (string.IsNullOrWhiteSpace(idNo))
  614. {
  615. throw new Exception("身份证号不能是空值");
  616. }
  617. if (idNo.Length != 18)
  618. throw new Exception("身份证号长度必须为18位");
  619. var birthDate = Convert.ToDateTime(idNo.Substring(6, 4) + "-" +
  620. idNo.Substring(10, 2) + "-" +
  621. idNo.Substring(12, 2));
  622. if (birthDate < new DateTime(1880, 1, 1) || birthDate > DateTime.Now.Date)
  623. {
  624. throw new Exception("身份证号中的出生日期不正确");
  625. }
  626. }
  627. #endregion
  628. }
  629. }