从山证v2.3.0拷贝
This commit is contained in:
@@ -0,0 +1,430 @@
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using YLErp.DBModels.Enums;
|
||||
using YLErp.Helpers;
|
||||
using YLErp.Model.Enum;
|
||||
using YLErp.Office;
|
||||
|
||||
namespace YLErp.Modules.ClientModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 客户信息查询服务
|
||||
/// </summary>
|
||||
public class ClientInfoQueryService : ClientBaseService
|
||||
{
|
||||
public ClientInfoQueryService(OptUserInfo userInfo) : base(userInfo)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ClientInfoQueryResult GetClientInfo(ClientInfoQueryModel queryModel)
|
||||
{
|
||||
Client client = null;
|
||||
|
||||
var clientQuery = DbContext.client.AsNoTracking();
|
||||
|
||||
if (queryModel.ClientId > 0)
|
||||
{
|
||||
client = clientQuery.FirstOrDefault(n => n.id == queryModel.ClientId);
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(queryModel.ClientNumber))
|
||||
{
|
||||
client = clientQuery.FirstOrDefault(n => n.Number == queryModel.ClientNumber);
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(queryModel.ClientName))
|
||||
{
|
||||
client = clientQuery.FirstOrDefault(n => n.Name == queryModel.ClientName);
|
||||
}
|
||||
|
||||
if (client == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
client.MetaDic = new ClientMetaService(this).GetMetaDic(client.id);
|
||||
|
||||
queryModel.ClientId = client.id;
|
||||
|
||||
var result = new ClientInfoQueryResult
|
||||
{
|
||||
ClientInfo = client,
|
||||
|
||||
Duties = GetClientDuties(queryModel),
|
||||
|
||||
BankCards = GetClientBankCards(queryModel)
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 客户银行卡列表
|
||||
/// </summary>
|
||||
public IEnumerable<ClientBankCardResult> GetClientBankCards(ClientInfoQueryModel queryModel)
|
||||
{
|
||||
IEnumerable<ClientBankCard> bankcards = null;
|
||||
|
||||
if (queryModel.ClientId > 0)
|
||||
{
|
||||
bankcards = DbContext.bankcard.AsNoTracking().Where(n => n.ApprovalOrder < 1 && n.ClientId == queryModel.ClientId).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
Expression<Func<Client, bool>> predicate;
|
||||
|
||||
if (!string.IsNullOrEmpty(queryModel.ClientNumber))
|
||||
{
|
||||
predicate = PredicateBuilder.Create<Client>(t => t.Number == queryModel.ClientNumber);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(queryModel.ClientName))
|
||||
{
|
||||
predicate = PredicateBuilder.Create<Client>(t => t.Name == queryModel.ClientName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Array.Empty<ClientBankCardResult>();
|
||||
}
|
||||
|
||||
var query = from bankcard in DbContext.bankcard.Where(x=> x.ApprovalOrder < 1).AsNoTracking()
|
||||
join client in DbContext.client.Where(predicate) on bankcard.ClientId equals client.id
|
||||
select bankcard;
|
||||
|
||||
bankcards = query.ToArray();
|
||||
}
|
||||
|
||||
return bankcards.Select(n =>
|
||||
{
|
||||
return new ClientBankCardResult
|
||||
{
|
||||
Bank = n.Bank,
|
||||
Card = n.Card,
|
||||
Name = n.ClientName,
|
||||
Comments = n.Comments,
|
||||
Payment = n.Payment,
|
||||
Usage = n.Use,
|
||||
ValidState = ConsGlobal.IsValid(n.ValidState) ? "有效" : "无效"
|
||||
};
|
||||
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 客户联系人列表
|
||||
/// </summary>
|
||||
public IEnumerable<ClientDutyResult> GetClientDuties(ClientInfoQueryModel queryModel)
|
||||
{
|
||||
var contactypeDic = DbContext.contactype.ToDictionary(n => n.id, n => n.ContactType);
|
||||
|
||||
IEnumerable<ClientDuty> duties = null;
|
||||
|
||||
if (queryModel.ClientId > 0)
|
||||
{
|
||||
duties = DbContext.clientduty.AsNoTracking().Where(n => n.ApprovalOrder < 1 && n.ClientId == queryModel.ClientId).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
Expression<Func<Client, bool>> predicate;
|
||||
|
||||
if (!string.IsNullOrEmpty(queryModel.ClientNumber))
|
||||
{
|
||||
predicate = PredicateBuilder.Create<Client>(t => t.Number == queryModel.ClientNumber);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(queryModel.ClientName))
|
||||
{
|
||||
predicate = PredicateBuilder.Create<Client>(t => t.Name == queryModel.ClientName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Array.Empty<ClientDutyResult>();
|
||||
}
|
||||
|
||||
var query = from duty in DbContext.clientduty.Where(n => n.ApprovalOrder < 1).AsNoTracking()
|
||||
join client in DbContext.client.Where(predicate) on duty.ClientId equals client.id
|
||||
select duty;
|
||||
|
||||
duties = query.ToArray();
|
||||
}
|
||||
|
||||
return duties.Select(n =>
|
||||
{
|
||||
var contactTypeIds = n.ContactTypeIdsInt;
|
||||
var contactTypes = new List<string>(contactTypeIds.Count);
|
||||
|
||||
foreach (var m in contactTypeIds)
|
||||
{
|
||||
if (contactypeDic.TryGetValue(m, out var type))
|
||||
{
|
||||
contactTypes.Add(type);
|
||||
}
|
||||
}
|
||||
|
||||
return new ClientDutyResult
|
||||
{
|
||||
ContactName = n.ContactName,
|
||||
ContactTypes = contactTypes,
|
||||
IdCardType = n.IdCardType.HasValue ? ((IdCardTypeEnum)n.IdCardType).ToString() : string.Empty,
|
||||
IdCardNo = n.IdCardNo,
|
||||
PhoneNumber = n.PhoneNumber,
|
||||
Fax = n.Fax,
|
||||
Email = n.Email,
|
||||
Address = n.Address,
|
||||
DeadLine = n.DeadLine?.ToString("yyyy-MM-dd"),
|
||||
IsReceiveEmail = n.IsReceiveEmail == 1
|
||||
};
|
||||
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取客户文件批量导出zip文件
|
||||
/// </summary>
|
||||
public byte[] GetZipFileOfClientFiles(ClientInfoQueryModel queryModel)
|
||||
{
|
||||
var predicate = PredicateBuilder.True<Client>();
|
||||
|
||||
if (queryModel.ClientId > 0)
|
||||
{
|
||||
predicate = PredicateBuilder.Create<Client>(n => n.id == queryModel.ClientId);
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(queryModel.ClientNumber))
|
||||
{
|
||||
predicate = PredicateBuilder.Create<Client>(n => n.Number == queryModel.ClientNumber);
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(queryModel.ClientName))
|
||||
{
|
||||
predicate = PredicateBuilder.Create<Client>(n => n.Name == queryModel.ClientName);
|
||||
}
|
||||
|
||||
var query = from c in DbContext.client.Where(predicate)
|
||||
join cf in DbContext.client_file on c.id equals cf.ClientId
|
||||
where cf.IsValid && cf.ApprovalOrder < 1
|
||||
select new ClientFileExportInfo
|
||||
{
|
||||
ClientNumber = c.Number,
|
||||
|
||||
id = cf.id,
|
||||
ParentId = cf.ParentClientFileId,
|
||||
BookTime = cf.BookTime,
|
||||
FileDesc = cf.FileDesc,
|
||||
FileName = cf.FileName,
|
||||
FilePath = cf.FilePath,
|
||||
FileTypeName = cf.FileTypeName,
|
||||
MainProtocolNumber = cf.MainProtocolNumber,
|
||||
ProtocolNumber = cf.ProtocolNumber,
|
||||
ReportorRole = cf.ReportorRole,
|
||||
SignDate = cf.SignDate,
|
||||
SignType = cf.SignType,
|
||||
OptDate = cf.OptDate
|
||||
};
|
||||
|
||||
var fileList = query.ToArray();
|
||||
|
||||
var zipEntryList = new List<MyZipEntry>(fileList.Length + 1);
|
||||
|
||||
foreach (var file in fileList)
|
||||
{
|
||||
if (file.SignDate.HasValue && file.SignDate.Value == DateTime.MinValue)
|
||||
{
|
||||
file.SignDate = null;
|
||||
}
|
||||
|
||||
if (file.BookTime.HasValue && file.BookTime.Value == DateTime.MinValue)
|
||||
{
|
||||
file.BookTime = null;
|
||||
}
|
||||
|
||||
if (file.BookTime == null)
|
||||
{
|
||||
file.BookTime = file.OptDate;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(file.FilePath))
|
||||
{
|
||||
file.ErrorMsg = "文件不存在";
|
||||
}
|
||||
else
|
||||
{
|
||||
var physicalPath = OtcAppContext.MapPath(file.FilePath);
|
||||
|
||||
if (File.Exists(physicalPath))
|
||||
{
|
||||
zipEntryList.Add(new MyZipEntry
|
||||
{
|
||||
Name = file.FileName,
|
||||
Buffer = File.ReadAllBytes(physicalPath)
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
file.ErrorMsg = "文件不存在";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
zipEntryList.Add(new MyZipEntry
|
||||
{
|
||||
Name = "info.txt",
|
||||
Buffer = Encoding.UTF8.GetBytes(JsonBeautify.Serialize(fileList))
|
||||
});
|
||||
|
||||
return ZipFileHelper.ZipFiles(zipEntryList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static Dictionary<string, string> ConvertToViewData(Client client)
|
||||
{
|
||||
var config = SystemModule.ClientEditConfigService.GetConfig();
|
||||
|
||||
var type = typeof(Client);
|
||||
|
||||
var dic = new Dictionary<string, string>();
|
||||
|
||||
foreach (var section in config.sections)
|
||||
{
|
||||
if (section.fields == null || !section.fields.Any())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var flatList = SystemModule.ClientEditConfigService.GetFlatList(section.fields, out _);
|
||||
|
||||
foreach (var f in flatList)
|
||||
{
|
||||
if (f == null || !f.visible)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string strVal = null;
|
||||
|
||||
if (f.name.StartsWith("meta_") || f.name.StartsWith("meta."))
|
||||
{
|
||||
client.MetaDic.TryGetValue(f.name, out strVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
var prop = type.GetMember(f.name, BindingFlags.Instance | BindingFlags.Public).FirstOrDefault();
|
||||
if (prop is PropertyInfo pi)
|
||||
{
|
||||
strVal = pi.GetValue(client)?.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(strVal))
|
||||
{
|
||||
strVal = string.Empty;
|
||||
}
|
||||
else if (f.name.Equals(nameof(client.TradingInstType)))
|
||||
{
|
||||
strVal = TradingInstTypeUtil.GetDesc(client.TradingInstType);
|
||||
}
|
||||
else if (config.selects.TryGetValue(f.name, out var options))
|
||||
{
|
||||
if (f.name.Equals(nameof(client.ParentId)) && client.ParentId < 1)
|
||||
{
|
||||
strVal = string.Empty;
|
||||
}
|
||||
else if (f.type == "select-m" || f.type == "select-sm")
|
||||
{
|
||||
var arr = strVal.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(s =>
|
||||
{
|
||||
var opt = options.FirstOrDefault(n => n.Value == s);
|
||||
return opt == null ? s : opt.Text;
|
||||
}).ToArray();
|
||||
|
||||
strVal = string.Join(",", arr);
|
||||
}
|
||||
else
|
||||
{
|
||||
var opt = options.FirstOrDefault(n => n.Value == strVal);
|
||||
if (opt != null)
|
||||
{
|
||||
strVal = opt.Text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dic[f.label] = strVal;
|
||||
}
|
||||
}
|
||||
|
||||
return dic;
|
||||
}
|
||||
}
|
||||
|
||||
class ClientFileExportInfo
|
||||
{
|
||||
public string ClientNumber { get; set; }
|
||||
|
||||
public int id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件名
|
||||
/// </summary>
|
||||
public string FileName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件说明
|
||||
/// </summary>
|
||||
public string FileDesc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 双录时间
|
||||
/// </summary>
|
||||
public DateTime? BookTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件类型名
|
||||
/// </summary>
|
||||
public string FileTypeName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 协议编号
|
||||
/// </summary>
|
||||
public string ProtocolNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主协议编号
|
||||
/// </summary>
|
||||
public string MainProtocolNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 母协议编号记录Id
|
||||
/// </summary>
|
||||
public int ParentId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 签署时间
|
||||
/// </summary>
|
||||
public DateTime? SignDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 签署类型
|
||||
/// </summary>
|
||||
public string SignType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 填报方角色
|
||||
/// </summary>
|
||||
public string ReportorRole { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string FilePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
internal DateTime? OptDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 错误信息
|
||||
/// </summary>
|
||||
public string ErrorMsg { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user