NewClientDataView.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using OASystem.Domain.AesEncryption;
  4. using OASystem.Domain.Attributes;
  5. using OASystem.Domain.Entities.Customer;
  6. using OASystem.Domain.Enums;
  7. using Org.BouncyCastle.Asn1.Ocsp;
  8. using Org.BouncyCastle.Asn1.X9;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.ComponentModel;
  12. using System.Linq;
  13. using System.Reflection;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using static Google.Protobuf.Reflection.SourceCodeInfo.Types;
  17. namespace OASystem.Domain.ViewModels.CRM
  18. {
  19. public class DetailsView
  20. {
  21. public int Id { get; set; }
  22. /// <summary>
  23. /// 客户分类
  24. /// </summary>
  25. public int Category { get; set; }
  26. /// <summary>
  27. /// 地市州Id
  28. /// </summary>
  29. public int Lvlid { get; set; }
  30. /// <summary>
  31. /// 权重
  32. /// </summary>
  33. [Encrypted]
  34. public string Weight { get; set; }
  35. /// <summary>
  36. /// 联系人
  37. /// </summary>
  38. [Encrypted]
  39. public string Contact { get; set; }
  40. /// <summary>
  41. /// 联系人性别
  42. /// </summary>
  43. public int Gender { get; set; }
  44. /// <summary>
  45. /// 联系手机号
  46. /// </summary>
  47. [Encrypted]
  48. public string Telephone { get; set; }
  49. /// <summary>
  50. /// 联系座机号
  51. /// </summary>
  52. [Encrypted]
  53. public string Phone { get; set; }
  54. /// <summary>
  55. /// 邮件
  56. /// </summary>
  57. [Encrypted]
  58. public string Email { get; set; }
  59. /// <summary>
  60. /// 职位
  61. /// </summary>
  62. [Encrypted]
  63. public string Job { get; set; }
  64. /// <summary>
  65. /// 客户单位
  66. /// </summary>
  67. [Encrypted]
  68. public string Client { get; set; }
  69. /// <summary>
  70. /// 客户单位简写
  71. /// </summary>
  72. [Encrypted]
  73. public string ClientShort { get; set; }
  74. /// <summary>
  75. /// 所属区域(所在城市)
  76. /// </summary>
  77. [Encrypted]
  78. public string Location { get; set; }
  79. /// <summary>
  80. /// 地址
  81. /// </summary>
  82. [Encrypted]
  83. public string Address { get; set; }
  84. /// <summary>
  85. /// 护照
  86. /// </summary>
  87. [Encrypted]
  88. public string Passport { get; set; }
  89. /// <summary>
  90. /// 护照日期
  91. /// </summary>
  92. [Encrypted]
  93. public string? PassportDate { get; set; }
  94. /// <summary>
  95. /// 生日
  96. /// </summary>
  97. [Encrypted]
  98. public string Birthday { get; set; }
  99. /// <summary>
  100. /// 预计出团
  101. /// </summary>
  102. public int PreDele { get; set; }
  103. /// <summary>
  104. /// 已出团
  105. /// </summary>
  106. public int FinlishedDele { get; set; }
  107. /// <summary>
  108. /// 归属人员
  109. /// </summary>
  110. public List<int>? AscribedUser { get; set; }
  111. /// <summary>
  112. /// 归属部门
  113. /// </summary>
  114. public List<int>? AscribedDepartment { get; set; }
  115. /// <summary>
  116. /// 微信
  117. /// </summary>
  118. [Encrypted]
  119. public string WeChat { get; set; }
  120. /// <summary>
  121. /// 备注
  122. /// </summary>
  123. [Encrypted]
  124. public string Remark { get; set; }
  125. }
  126. public class NewClientDataAndroidIOSView
  127. {
  128. /// <summary>
  129. /// 编号
  130. /// </summary>
  131. public int RowNumber { get; set; }
  132. public int Id { get; set; }
  133. /// <summary>
  134. /// 客户单位
  135. /// </summary>
  136. public string? Client { get; set; }
  137. /// <summary>
  138. /// 联系人
  139. /// </summary>
  140. public string? Contact { get; set; }
  141. /// <summary>
  142. /// 职位
  143. /// </summary>
  144. public string? Job { get; set; }
  145. /// <summary>
  146. /// 联系手机号
  147. /// </summary>
  148. public string? Telephone { get; set; }
  149. /// <summary>
  150. /// 所在区域
  151. /// </summary>
  152. public string? Location { get; set; }
  153. }
  154. public class NewClientDataView : Crm_NewClientData
  155. {
  156. /// <summary>
  157. /// 总条数
  158. /// </summary>
  159. public int CountPage { get; set; }
  160. /// <summary>
  161. /// 编号
  162. /// </summary>
  163. public int RowNumber { get; set; }
  164. /// <summary>
  165. /// 客户分类
  166. /// </summary>
  167. public string CategoryStr { get; set; }
  168. /// <summary>
  169. /// 地市州Id
  170. /// </summary>
  171. public string LvlidStr { get; set; }
  172. /// <summary>
  173. /// 归属人员
  174. /// </summary>
  175. public dynamic AscribedUser { get; set; }
  176. /// <summary>
  177. /// 归属部门
  178. /// </summary>
  179. public dynamic AscribedDepartment { get; set; }
  180. /// <summary>
  181. /// 未更新信息天数
  182. /// </summary>
  183. public int NotUpdateDays
  184. {
  185. get
  186. {
  187. if (LastUpdateTime == DateTime.MinValue)
  188. {
  189. LastUpdateTime = CreateTime;
  190. return DateTime.Now.Subtract(CreateTime).Days;
  191. }
  192. else return DateTime.Now.Subtract(LastUpdateTime).Days;
  193. }
  194. }
  195. }
  196. /// <summary>
  197. ///归属人员
  198. /// </summary>
  199. public class AscribedUser
  200. {
  201. /// <summary>
  202. /// 人员Id
  203. /// </summary>
  204. public int UserId { get; set; }
  205. /// <summary>
  206. /// 归属人员姓名
  207. /// </summary>
  208. public string CnName { get; set; }
  209. public int NewClientDataId { get; set; }
  210. }
  211. /// <summary>
  212. ///归属部门
  213. /// </summary>
  214. public class AscribedDepartment
  215. {
  216. /// <summary>
  217. /// setData部门部门Id
  218. /// </summary>
  219. public int Id { get; set; }
  220. /// <summary>
  221. /// 归属部门名称
  222. /// </summary>
  223. public string Name { get; set; }
  224. public int NewClientDataId { get; set; }
  225. }
  226. public class NewClientDataExcelDownloadView : Crm_NewClientData
  227. {
  228. /// <summary>
  229. /// 编号
  230. /// </summary>
  231. public int RowNumber { get; set; }
  232. /// <summary>
  233. /// 客户分类
  234. /// </summary>
  235. public string CategoryStr { get; set; }
  236. /// <summary>
  237. /// 地市州Id
  238. /// </summary>
  239. public string LvlidStr { get; set; }
  240. public string CreateUserName { get; set; }
  241. public string WeightLable {
  242. get
  243. {
  244. if (int.TryParse(Weight,out int weightId))
  245. {
  246. if (weightId == 393) return "A";
  247. else if (weightId == 392) return "B";
  248. else if (weightId == 391) return "C";
  249. else return "D";
  250. }
  251. return "D";
  252. }
  253. }
  254. public string SexLable
  255. {
  256. get
  257. {
  258. return Gender == 0 ? "男" : Gender == 1 ? "女" : "未设置";
  259. }
  260. }
  261. public string AscribedUserLable { get; set; } = "";
  262. public string AscribedDepartmentLable { get; set; } = "";
  263. }
  264. public class CRMWeekStatisticsView
  265. {
  266. public string UserName { get; set; }
  267. public int InsertNum { get; set; }
  268. public int DeleteNum { get; set; }
  269. }
  270. public class NewClientDataRecordInfoView
  271. {
  272. public int RowIndex { get; set; }
  273. public int Id { get; set; }
  274. public int PortType { get; set; }
  275. public string PortTypeLabel
  276. {
  277. get
  278. {
  279. string lable = string.Empty;
  280. if (PortType == 1) lable = "WEB";
  281. else if (PortType == 2) lable = "ANDROID";
  282. else if (PortType == 3) lable = "IOS";
  283. return lable;
  284. }
  285. }
  286. public OperationEnum OperationItem { get; set; }
  287. public string OperationItemLable
  288. {
  289. get
  290. {
  291. return OperationItem.GetEnumDescription();
  292. }
  293. }
  294. public int DataId { get; set; }
  295. public string Client { get; set; }
  296. public string ClientLable
  297. {
  298. get
  299. {
  300. if (OperationItem is OperationEnum.Add or OperationEnum.Details or OperationEnum.Edit or OperationEnum.Del)
  301. {
  302. if (!string.IsNullOrEmpty(Client))
  303. {
  304. return string.IsNullOrEmpty(Client) ? null : AesEncryptionHelper.Decrypt(Client);
  305. }
  306. }
  307. return string.Empty;
  308. }
  309. }
  310. public int CreateUserId { get; set; }
  311. public string CreateUserName { get; set; }
  312. public DateTime CreateTime { get; set; }
  313. public string UpdatePreData { get; set; }
  314. public string UpdateBefData { get; set; }
  315. public string Label
  316. {
  317. get
  318. {
  319. string lable = string.Empty;
  320. if (OperationItem == OperationEnum.Edit)
  321. {
  322. Crm_NewClientData? originalInfo = null;
  323. Crm_NewClientData? newInfo = null;
  324. if (!string.IsNullOrEmpty(UpdatePreData) && IsValidJson(UpdatePreData)) originalInfo = JsonConvert.DeserializeObject<Crm_NewClientData>(UpdatePreData);
  325. if (!string.IsNullOrEmpty(UpdateBefData) && IsValidJson(UpdateBefData)) newInfo = JsonConvert.DeserializeObject<Crm_NewClientData>(UpdateBefData);
  326. string operationLabel = $"执行了{OperationItemLable}操作。";
  327. if (originalInfo != null && newInfo != null)
  328. {
  329. string updatedFieldLable = GetUpdatedFields(originalInfo, newInfo);
  330. if (!string.IsNullOrEmpty(updatedFieldLable)) operationLabel = $"{OperationItemLable}了“{ClientLable}”单位的{GetUpdatedFields(originalInfo, newInfo)}数据。";
  331. else operationLabel = $"未{OperationItemLable}“{ClientLable}”单位的数据,但点击了保存。";
  332. }
  333. lable = $"{CreateUserName}{operationLabel}";
  334. }
  335. else if (OperationItem == OperationEnum.List || OperationItem == OperationEnum.NoOperation) lable = $"{CreateUserName}查看了列表数据。";
  336. else if (OperationItem == OperationEnum.Details)
  337. {
  338. if (!string.IsNullOrEmpty(ClientLable)) lable = $"{CreateUserName}查看了“{ClientLable}”单位数据。";
  339. else lable = $"{CreateUserName}查看了详情数据。";
  340. }
  341. else if (OperationItem == OperationEnum.Add)
  342. {
  343. if (!string.IsNullOrEmpty(ClientLable)) lable = $"{CreateUserName}添加了“{ClientLable}”单位数据。";
  344. else lable = $"{CreateUserName}添加了数据。";
  345. }
  346. else if (OperationItem == OperationEnum.Del) {
  347. if (!string.IsNullOrEmpty(ClientLable)) lable = $"{CreateUserName}删除了“{ClientLable}”单位数据。";
  348. else lable = $"{CreateUserName}删除了数据。";
  349. }
  350. else if (OperationItem == OperationEnum.Download) lable = $"{CreateUserName}下载了“公司客户资料”文件。";
  351. else if (OperationItem == OperationEnum.BatchAssignment) lable = $"{CreateUserName}{OperationItemLable}了“公司客户资料”查看权限。";
  352. return lable;
  353. }
  354. }
  355. private static string GetUpdatedFields(Crm_NewClientData originalInfo, Crm_NewClientData newInfo)
  356. {
  357. var updatedFields = new List<string>();
  358. // 使用反射获取字段名称
  359. var columnNames = originalInfo.GetType().GetProperties().Select(p => p.Name).ToList();
  360. foreach (var columnName in columnNames)
  361. {
  362. var originalValue = originalInfo.GetType().GetProperty(columnName).GetValue(originalInfo, null)?.ToString() ?? "";
  363. var newValue = newInfo.GetType().GetProperty(columnName).GetValue(newInfo, null)?.ToString() ?? "";
  364. if (!originalValue.Equals(newValue) )
  365. {
  366. var propertyInfo = typeof(Crm_NewClientData).GetProperty(columnName);
  367. var descriptionAttribute = propertyInfo.GetCustomAttribute<DescriptionAttribute>();
  368. var fieldName = descriptionAttribute?.Description;
  369. if (!string.IsNullOrEmpty(fieldName)) updatedFields.Add(fieldName);
  370. }
  371. }
  372. return string.Join("、", updatedFields);
  373. }
  374. /// <summary>
  375. /// 验证json字符串是否合法
  376. /// </summary>
  377. /// <param name="jsonString"></param>
  378. /// <returns></returns>
  379. private static bool IsValidJson(string jsonString)
  380. {
  381. try
  382. {
  383. JToken.Parse(jsonString);
  384. return true;
  385. }
  386. catch (JsonReaderException)
  387. {
  388. return false;
  389. }
  390. }
  391. }
  392. public class NewClientDataRecordView
  393. {
  394. public int RowIndex { get; set; }
  395. public string Label { get; set; }
  396. public DateTime CreateTime { get; set; }
  397. }
  398. }