NewClientDataView.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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. int days = 0;
  188. if (LastUpdateTime == DateTime.MinValue)
  189. {
  190. days = DateTime.Now.Subtract(CreateTime).Days;
  191. LastUpdateTime = CreateTime;
  192. }
  193. else days = DateTime.Now.Subtract(LastUpdateTime).Days;
  194. return days;
  195. }
  196. }
  197. }
  198. /// <summary>
  199. ///归属人员
  200. /// </summary>
  201. public class AscribedUser
  202. {
  203. /// <summary>
  204. /// 人员Id
  205. /// </summary>
  206. public int UserId { get; set; }
  207. /// <summary>
  208. /// 归属人员姓名
  209. /// </summary>
  210. public string CnName { get; set; }
  211. public int NewClientDataId { get; set; }
  212. }
  213. /// <summary>
  214. ///归属部门
  215. /// </summary>
  216. public class AscribedDepartment
  217. {
  218. /// <summary>
  219. /// setData部门部门Id
  220. /// </summary>
  221. public int Id { get; set; }
  222. /// <summary>
  223. /// 归属部门名称
  224. /// </summary>
  225. public string Name { get; set; }
  226. public int NewClientDataId { get; set; }
  227. }
  228. public class NewClientDataExcelDownloadView : Crm_NewClientData
  229. {
  230. /// <summary>
  231. /// 编号
  232. /// </summary>
  233. public int RowNumber { get; set; }
  234. /// <summary>
  235. /// 客户分类
  236. /// </summary>
  237. public string CategoryStr { get; set; }
  238. /// <summary>
  239. /// 地市州Id
  240. /// </summary>
  241. public string LvlidStr { get; set; }
  242. public string CreateUserName { get; set; }
  243. public string WeightLable {
  244. get
  245. {
  246. if (int.TryParse(Weight,out int weightId))
  247. {
  248. if (weightId == 393) return "A";
  249. else if (weightId == 392) return "B";
  250. else if (weightId == 391) return "C";
  251. else return "D";
  252. }
  253. return "D";
  254. }
  255. }
  256. public string SexLable
  257. {
  258. get
  259. {
  260. return Gender == 0 ? "男" : Gender == 1 ? "女" : "未设置";
  261. }
  262. }
  263. public string AscribedUserLable { get; set; } = "";
  264. public string AscribedDepartmentLable { get; set; } = "";
  265. }
  266. public class CRMWeekStatisticsView
  267. {
  268. public string UserName { get; set; }
  269. public int InsertNum { get; set; }
  270. public int DeleteNum { get; set; }
  271. }
  272. public class NewClientDataRecordInfoView
  273. {
  274. public int RowIndex { get; set; }
  275. public int Id { get; set; }
  276. public int PortType { get; set; }
  277. public string PortTypeLabel
  278. {
  279. get
  280. {
  281. string lable = string.Empty;
  282. if (PortType == 1) lable = "WEB";
  283. else if (PortType == 2) lable = "ANDROID";
  284. else if (PortType == 3) lable = "IOS";
  285. return lable;
  286. }
  287. }
  288. public OperationEnum OperationItem { get; set; }
  289. public string OperationItemLable
  290. {
  291. get
  292. {
  293. return OperationItem.GetEnumDescription();
  294. }
  295. }
  296. public int DataId { get; set; }
  297. public string Client { get; set; }
  298. public string ClientLable
  299. {
  300. get
  301. {
  302. var lable = string.Empty;
  303. if (OperationItem is OperationEnum.Add or OperationEnum.Details or OperationEnum.Edit or OperationEnum.Del)
  304. {
  305. if (!string.IsNullOrEmpty(Client))
  306. {
  307. lable = AesEncryptionHelper.Decrypt(Client);
  308. }
  309. }
  310. return lable;
  311. }
  312. }
  313. public int CreateUserId { get; set; }
  314. public string CreateUserName { get; set; }
  315. public DateTime CreateTime { get; set; }
  316. public string UpdatePreData { get; set; }
  317. public string UpdateBefData { get; set; }
  318. public string Label
  319. {
  320. get
  321. {
  322. string lable = string.Empty;
  323. if (OperationItem == OperationEnum.Edit)
  324. {
  325. Crm_NewClientData? originalInfo = null;
  326. Crm_NewClientData? newInfo = null;
  327. if (!string.IsNullOrEmpty(UpdatePreData) && IsValidJson(UpdatePreData)) originalInfo = JsonConvert.DeserializeObject<Crm_NewClientData>(UpdatePreData);
  328. if (!string.IsNullOrEmpty(UpdateBefData) && IsValidJson(UpdateBefData)) newInfo = JsonConvert.DeserializeObject<Crm_NewClientData>(UpdateBefData);
  329. string operationLabel = $"执行了{OperationItemLable}操作。";
  330. if (originalInfo != null && newInfo != null)
  331. {
  332. string updatedFieldLable = GetUpdatedFields(originalInfo, newInfo);
  333. if (!string.IsNullOrEmpty(updatedFieldLable)) operationLabel = $"{OperationItemLable}了“{ClientLable}”单位的{GetUpdatedFields(originalInfo, newInfo)}数据。";
  334. else operationLabel = $"未{OperationItemLable}“{ClientLable}”单位的数据,但点击了保存。";
  335. }
  336. lable = $"{CreateUserName}{operationLabel}";
  337. }
  338. else if (OperationItem == OperationEnum.List || OperationItem == OperationEnum.NoOperation) lable = $"{CreateUserName}查看了列表数据。";
  339. else if (OperationItem == OperationEnum.Details)
  340. {
  341. if (!string.IsNullOrEmpty(ClientLable)) lable = $"{CreateUserName}查看了“{ClientLable}”单位数据。";
  342. else lable = $"{CreateUserName}查看了详情数据。";
  343. }
  344. else if (OperationItem == OperationEnum.Add)
  345. {
  346. if (!string.IsNullOrEmpty(ClientLable)) lable = $"{CreateUserName}添加了“{ClientLable}”单位数据。";
  347. else lable = $"{CreateUserName}添加了数据。";
  348. }
  349. else if (OperationItem == OperationEnum.Del) {
  350. if (!string.IsNullOrEmpty(ClientLable)) lable = $"{CreateUserName}删除了“{ClientLable}”单位数据。";
  351. else lable = $"{CreateUserName}删除了数据。";
  352. }
  353. else if (OperationItem == OperationEnum.Download) lable = $"{CreateUserName}下载了“公司客户资料”文件。";
  354. else if (OperationItem == OperationEnum.BatchAssignment) lable = $"{CreateUserName}{OperationItemLable}了“公司客户资料”查看权限。";
  355. return lable;
  356. }
  357. }
  358. private static string GetUpdatedFields(Crm_NewClientData originalInfo, Crm_NewClientData newInfo)
  359. {
  360. var updatedFields = new List<string>();
  361. // 使用反射获取字段名称
  362. var columnNames = originalInfo.GetType().GetProperties().Select(p => p.Name).ToList();
  363. foreach (var columnName in columnNames)
  364. {
  365. var originalValue = originalInfo.GetType().GetProperty(columnName).GetValue(originalInfo, null)?.ToString() ?? "";
  366. var newValue = newInfo.GetType().GetProperty(columnName).GetValue(newInfo, null)?.ToString() ?? "";
  367. if (!originalValue.Equals(newValue) )
  368. {
  369. var propertyInfo = typeof(Crm_NewClientData).GetProperty(columnName);
  370. var descriptionAttribute = propertyInfo.GetCustomAttribute<DescriptionAttribute>();
  371. var fieldName = descriptionAttribute?.Description;
  372. if (!string.IsNullOrEmpty(fieldName)) updatedFields.Add(fieldName);
  373. }
  374. }
  375. return string.Join("、", updatedFields);
  376. }
  377. /// <summary>
  378. /// 验证json字符串是否合法
  379. /// </summary>
  380. /// <param name="jsonString"></param>
  381. /// <returns></returns>
  382. private static bool IsValidJson(string jsonString)
  383. {
  384. try
  385. {
  386. JToken.Parse(jsonString);
  387. return true;
  388. }
  389. catch (JsonReaderException)
  390. {
  391. return false;
  392. }
  393. }
  394. }
  395. public class NewClientDataRecordView
  396. {
  397. public int RowIndex { get; set; }
  398. public string Label { get; set; }
  399. public DateTime CreateTime { get; set; }
  400. }
  401. }