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; }
///
/// 客户分类
///
public int Category { get; set; }
///
/// 地市州Id
///
public int Lvlid { get; set; }
///
/// 权重
///
[Encrypted]
public string Weight { get; set; }
///
/// 联系人
///
[Encrypted]
public string Contact { get; set; }
///
/// 联系人性别
///
public int Gender { get; set; }
///
/// 联系手机号
///
[Encrypted]
public string Telephone { get; set; }
///
/// 联系座机号
///
[Encrypted]
public string Phone { get; set; }
///
/// 邮件
///
[Encrypted]
public string Email { get; set; }
///
/// 职位
///
[Encrypted]
public string Job { get; set; }
///
/// 客户单位
///
[Encrypted]
public string Client { get; set; }
///
/// 客户单位简写
///
[Encrypted]
public string ClientShort { get; set; }
///
/// 所属区域(所在城市)
///
[Encrypted]
public string Location { get; set; }
///
/// 地址
///
[Encrypted]
public string Address { get; set; }
///
/// 护照
///
[Encrypted]
public string Passport { get; set; }
///
/// 护照日期
///
[Encrypted]
public string? PassportDate { get; set; }
///
/// 生日
///
[Encrypted]
public string Birthday { get; set; }
///
/// 预计出团
///
public int PreDele { get; set; }
///
/// 已出团
///
public int FinlishedDele { get; set; }
///
/// 归属人员
///
public List? AscribedUser { get; set; }
///
/// 归属部门
///
public List? AscribedDepartment { get; set; }
///
/// 微信
///
[Encrypted]
public string WeChat { get; set; }
///
/// 备注
///
[Encrypted]
public string Remark { get; set; }
}
public class NewClientDataAndroidIOSView
{
///
/// 编号
///
public int RowNumber { get; set; }
public int Id { get; set; }
///
/// 客户单位
///
public string? Client { get; set; }
///
/// 联系人
///
public string? Contact { get; set; }
///
/// 职位
///
public string? Job { get; set; }
///
/// 联系手机号
///
public string? Telephone { get; set; }
///
/// 所在区域
///
public string? Location { get; set; }
}
public class NewClientDataView : Crm_NewClientData
{
///
/// 总条数
///
public int CountPage { get; set; }
///
/// 编号
///
public int RowNumber { get; set; }
///
/// 客户分类
///
public string CategoryStr { get; set; }
///
/// 地市州Id
///
public string LvlidStr { get; set; }
///
/// 归属人员
///
public dynamic AscribedUser { get; set; }
///
/// 归属部门
///
public dynamic AscribedDepartment { get; set; }
///
/// 未更新信息天数
///
public int NotUpdateDays
{
get
{
if (LastUpdateTime == DateTime.MinValue)
{
LastUpdateTime = CreateTime;
return DateTime.Now.Subtract(CreateTime).Days;
}
else return DateTime.Now.Subtract(LastUpdateTime).Days;
}
}
}
///
///归属人员
///
public class AscribedUser
{
///
/// 人员Id
///
public int UserId { get; set; }
///
/// 归属人员姓名
///
public string CnName { get; set; }
public int NewClientDataId { get; set; }
}
///
///归属部门
///
public class AscribedDepartment
{
///
/// setData部门部门Id
///
public int Id { get; set; }
///
/// 归属部门名称
///
public string Name { get; set; }
public int NewClientDataId { get; set; }
}
public class NewClientDataExcelDownloadView : Crm_NewClientData
{
///
/// 编号
///
public int RowNumber { get; set; }
///
/// 客户分类
///
public string CategoryStr { get; set; }
///
/// 地市州Id
///
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(UpdatePreData);
if (!string.IsNullOrEmpty(UpdateBefData) && IsValidJson(UpdateBefData)) newInfo = JsonConvert.DeserializeObject(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();
// 使用反射获取字段名称
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();
var fieldName = descriptionAttribute?.Description;
if (!string.IsNullOrEmpty(fieldName)) updatedFields.Add(fieldName);
}
}
return string.Join("、", updatedFields);
}
///
/// 验证json字符串是否合法
///
///
///
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; }
}
}