123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463 |
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using OASystem.Domain.AesEncryption;
- using OASystem.Domain.Attributes;
- using OASystem.Domain.Entities.Customer;
- using OASystem.Domain.Enums;
- using Org.BouncyCastle.Asn1.Ocsp;
- using Org.BouncyCastle.Asn1.X9;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using static Google.Protobuf.Reflection.SourceCodeInfo.Types;
- namespace OASystem.Domain.ViewModels.CRM
- {
- public class DetailsView
- {
- public int Id { get; set; }
- /// <summary>
- /// 客户分类
- /// </summary>
- public int Category { get; set; }
- /// <summary>
- /// 地市州Id
- /// </summary>
- public int Lvlid { get; set; }
- /// <summary>
- /// 权重
- /// </summary>
- [Encrypted]
- public string Weight { get; set; }
- /// <summary>
- /// 联系人
- /// </summary>
- [Encrypted]
- public string Contact { get; set; }
- /// <summary>
- /// 联系人性别
- /// </summary>
- public int Gender { get; set; }
- /// <summary>
- /// 联系手机号
- /// </summary>
- [Encrypted]
- public string Telephone { get; set; }
- /// <summary>
- /// 联系座机号
- /// </summary>
- [Encrypted]
- public string Phone { get; set; }
- /// <summary>
- /// 邮件
- /// </summary>
- [Encrypted]
- public string Email { get; set; }
- /// <summary>
- /// 职位
- /// </summary>
- [Encrypted]
- public string Job { get; set; }
- /// <summary>
- /// 客户单位
- /// </summary>
- [Encrypted]
- public string Client { get; set; }
- /// <summary>
- /// 客户单位简写
- /// </summary>
- [Encrypted]
- public string ClientShort { get; set; }
- /// <summary>
- /// 所属区域(所在城市)
- /// </summary>
- [Encrypted]
- public string Location { get; set; }
- /// <summary>
- /// 地址
- /// </summary>
- [Encrypted]
- public string Address { get; set; }
- /// <summary>
- /// 护照
- /// </summary>
- [Encrypted]
- public string Passport { get; set; }
- /// <summary>
- /// 护照日期
- /// </summary>
- [Encrypted]
- public string? PassportDate { get; set; }
- /// <summary>
- /// 生日
- /// </summary>
- [Encrypted]
- public string Birthday { get; set; }
- /// <summary>
- /// 预计出团
- /// </summary>
- public int PreDele { get; set; }
- /// <summary>
- /// 已出团
- /// </summary>
- public int FinlishedDele { get; set; }
- /// <summary>
- /// 归属人员
- /// </summary>
- public List<int>? AscribedUser { get; set; }
- /// <summary>
- /// 归属部门
- /// </summary>
- public List<int>? AscribedDepartment { get; set; }
- /// <summary>
- /// 微信
- /// </summary>
- [Encrypted]
- public string WeChat { get; set; }
- /// <summary>
- /// 备注
- /// </summary>
- [Encrypted]
- public string Remark { get; set; }
- }
- public class NewClientDataAndroidIOSView
- {
- /// <summary>
- /// 编号
- /// </summary>
- public int RowNumber { get; set; }
- public int Id { get; set; }
- /// <summary>
- /// 客户单位
- /// </summary>
- public string? Client { get; set; }
- /// <summary>
- /// 联系人
- /// </summary>
- public string? Contact { get; set; }
- /// <summary>
- /// 职位
- /// </summary>
- public string? Job { get; set; }
- /// <summary>
- /// 联系手机号
- /// </summary>
- public string? Telephone { get; set; }
- /// <summary>
- /// 所在区域
- /// </summary>
- public string? Location { get; set; }
- }
- public class NewClientDataView : Crm_NewClientData
- {
- /// <summary>
- /// 总条数
- /// </summary>
- public int CountPage { get; set; }
- /// <summary>
- /// 编号
- /// </summary>
- public int RowNumber { get; set; }
- /// <summary>
- /// 客户分类
- /// </summary>
- public string CategoryStr { get; set; }
- /// <summary>
- /// 地市州Id
- /// </summary>
- public string LvlidStr { get; set; }
- /// <summary>
- /// 归属人员
- /// </summary>
- public dynamic AscribedUser { get; set; }
- /// <summary>
- /// 归属部门
- /// </summary>
- public dynamic AscribedDepartment { get; set; }
- /// <summary>
- /// 未更新信息天数
- /// </summary>
- public int NotUpdateDays
- {
- get
- {
- if (LastUpdateTime == DateTime.MinValue)
- {
- LastUpdateTime = CreateTime;
- return DateTime.Now.Subtract(CreateTime).Days;
- }
- else return DateTime.Now.Subtract(LastUpdateTime).Days;
- }
- }
- }
- /// <summary>
- ///归属人员
- /// </summary>
- public class AscribedUser
- {
- /// <summary>
- /// 人员Id
- /// </summary>
- public int UserId { get; set; }
- /// <summary>
- /// 归属人员姓名
- /// </summary>
- public string CnName { get; set; }
- public int NewClientDataId { get; set; }
- }
- /// <summary>
- ///归属部门
- /// </summary>
- public class AscribedDepartment
- {
- /// <summary>
- /// setData部门部门Id
- /// </summary>
- public int Id { get; set; }
- /// <summary>
- /// 归属部门名称
- /// </summary>
- public string Name { get; set; }
- public int NewClientDataId { get; set; }
- }
- public class NewClientDataExcelDownloadView : Crm_NewClientData
- {
- /// <summary>
- /// 编号
- /// </summary>
- public int RowNumber { get; set; }
- /// <summary>
- /// 客户分类
- /// </summary>
- public string CategoryStr { get; set; }
- /// <summary>
- /// 地市州Id
- /// </summary>
- public string LvlidStr { get; set; }
- public string CreateUserName { get; set; }
- public string WeightLable {
- get
- {
- if (int.TryParse(Weight,out int weightId))
- {
- if (weightId == 393) return "A";
- else if (weightId == 392) return "B";
- else if (weightId == 391) return "C";
- else return "D";
- }
- return "D";
- }
- }
- public string SexLable
- {
- get
- {
- return Gender == 0 ? "男" : Gender == 1 ? "女" : "未设置";
- }
- }
- public string AscribedUserLable { get; set; } = "";
- public string AscribedDepartmentLable { get; set; } = "";
- }
- public class CRMWeekStatisticsView
- {
- public string UserName { get; set; }
- public int InsertNum { get; set; }
- public int DeleteNum { get; set; }
- }
- public class NewClientDataRecordInfoView
- {
- public int RowIndex { get; set; }
- public int Id { get; set; }
- public int PortType { get; set; }
- public string PortTypeLabel
- {
- get
- {
- string lable = string.Empty;
- if (PortType == 1) lable = "WEB";
- else if (PortType == 2) lable = "ANDROID";
- else if (PortType == 3) lable = "IOS";
- return lable;
- }
- }
- public OperationEnum OperationItem { get; set; }
- public string OperationItemLable
- {
- get
- {
- return OperationItem.GetEnumDescription();
- }
- }
- public int DataId { get; set; }
- public string Client { get; set; }
- public string ClientLable
- {
- get
- {
- if (OperationItem is OperationEnum.Add or OperationEnum.Details or OperationEnum.Edit or OperationEnum.Del)
- {
- if (!string.IsNullOrEmpty(Client))
- {
- return string.IsNullOrEmpty(Client) ? null : AesEncryptionHelper.Decrypt(Client);
- }
- }
- return string.Empty;
- }
- }
- public int CreateUserId { get; set; }
- public string CreateUserName { get; set; }
- public DateTime CreateTime { get; set; }
- public string UpdatePreData { get; set; }
- public string UpdateBefData { get; set; }
- public string Label
- {
- get
- {
- string lable = string.Empty;
- if (OperationItem == OperationEnum.Edit)
- {
- Crm_NewClientData? originalInfo = null;
- Crm_NewClientData? newInfo = null;
- if (!string.IsNullOrEmpty(UpdatePreData) && IsValidJson(UpdatePreData)) originalInfo = JsonConvert.DeserializeObject<Crm_NewClientData>(UpdatePreData);
- if (!string.IsNullOrEmpty(UpdateBefData) && IsValidJson(UpdateBefData)) newInfo = JsonConvert.DeserializeObject<Crm_NewClientData>(UpdateBefData);
- string operationLabel = $"执行了{OperationItemLable}操作。";
- if (originalInfo != null && newInfo != null)
- {
- string updatedFieldLable = GetUpdatedFields(originalInfo, newInfo);
- if (!string.IsNullOrEmpty(updatedFieldLable)) operationLabel = $"{OperationItemLable}了“{ClientLable}”单位的{GetUpdatedFields(originalInfo, newInfo)}数据。";
- else operationLabel = $"未{OperationItemLable}“{ClientLable}”单位的数据,但点击了保存。";
- }
- lable = $"{CreateUserName}{operationLabel}";
- }
- else if (OperationItem == OperationEnum.List || OperationItem == OperationEnum.NoOperation) lable = $"{CreateUserName}查看了列表数据。";
- else if (OperationItem == OperationEnum.Details)
- {
- if (!string.IsNullOrEmpty(ClientLable)) lable = $"{CreateUserName}查看了“{ClientLable}”单位数据。";
- else lable = $"{CreateUserName}查看了详情数据。";
- }
- else if (OperationItem == OperationEnum.Add)
- {
- if (!string.IsNullOrEmpty(ClientLable)) lable = $"{CreateUserName}添加了“{ClientLable}”单位数据。";
- else lable = $"{CreateUserName}添加了数据。";
- }
- else if (OperationItem == OperationEnum.Del) {
- if (!string.IsNullOrEmpty(ClientLable)) lable = $"{CreateUserName}删除了“{ClientLable}”单位数据。";
- else lable = $"{CreateUserName}删除了数据。";
- }
- else if (OperationItem == OperationEnum.Download) lable = $"{CreateUserName}下载了“公司客户资料”文件。";
- else if (OperationItem == OperationEnum.BatchAssignment) lable = $"{CreateUserName}{OperationItemLable}了“公司客户资料”查看权限。";
- return lable;
- }
- }
- private static string GetUpdatedFields(Crm_NewClientData originalInfo, Crm_NewClientData newInfo)
- {
- var updatedFields = new List<string>();
- // 使用反射获取字段名称
- var columnNames = originalInfo.GetType().GetProperties().Select(p => p.Name).ToList();
- foreach (var columnName in columnNames)
- {
- var originalValue = originalInfo.GetType().GetProperty(columnName).GetValue(originalInfo, null)?.ToString() ?? "";
- var newValue = newInfo.GetType().GetProperty(columnName).GetValue(newInfo, null)?.ToString() ?? "";
- if (!originalValue.Equals(newValue) )
- {
- var propertyInfo = typeof(Crm_NewClientData).GetProperty(columnName);
- var descriptionAttribute = propertyInfo.GetCustomAttribute<DescriptionAttribute>();
- var fieldName = descriptionAttribute?.Description;
- if (!string.IsNullOrEmpty(fieldName)) updatedFields.Add(fieldName);
- }
- }
- return string.Join("、", updatedFields);
- }
- /// <summary>
- /// 验证json字符串是否合法
- /// </summary>
- /// <param name="jsonString"></param>
- /// <returns></returns>
- private static bool IsValidJson(string jsonString)
- {
- try
- {
- JToken.Parse(jsonString);
- return true;
- }
- catch (JsonReaderException)
- {
- return false;
- }
- }
- }
- public class NewClientDataRecordView
- {
- public int RowIndex { get; set; }
- public string Label { get; set; }
- public DateTime CreateTime { get; set; }
- }
- }
|