375 lines
14 KiB
C#
375 lines
14 KiB
C#
using SharedWebApi.Filter;
|
|
using System.Net;
|
|
using System.Net.Http.Headers;
|
|
using YLErp;
|
|
using YLErp.BLL.EodSettlement;
|
|
using YLErp.Modules.ClientModule;
|
|
|
|
namespace YLWebAPI.ApiModule.ManagerApi
|
|
{
|
|
/// <summary>
|
|
/// 用于管理端的客户数据API
|
|
/// </summary>
|
|
[ManagerAuth]
|
|
public class ClientDataController : BaseApiController
|
|
{
|
|
/// <summary>
|
|
/// 获取客户编辑配置
|
|
/// </summary>
|
|
[HttpPost]
|
|
[Route("api/v1/getClientConfig")]
|
|
public ApiResponseModel GetClientConfig()
|
|
{
|
|
var config = YLErp.Modules.SystemModule.ClientEditConfigService.GetConfig(true);
|
|
config.openList = null;
|
|
config.clientList = null;
|
|
return JsonSuccess(config);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取客户信息
|
|
/// </summary>
|
|
[HttpPost]
|
|
[Route("api/v1/getClientInfo")]
|
|
public ApiResponseModel GetClientInfo([FromBody] ClientInfoQueryModel queryModel)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(queryModel?.ClientNumber) && string.IsNullOrWhiteSpace(queryModel.ClientName))
|
|
{
|
|
return JsonError("缺少必需的请求参数");
|
|
}
|
|
|
|
using var db = DbContextFactory.GetClientDbContext(CurUser);
|
|
var clientQuery = db.client.AsNoTracking();
|
|
|
|
var client = !string.IsNullOrWhiteSpace(queryModel.ClientNumber)
|
|
? clientQuery.FirstOrDefault(n => n.Number == queryModel.ClientNumber)
|
|
: clientQuery.FirstOrDefault(n => n.Name == queryModel.ClientName);
|
|
|
|
if (client == null)
|
|
{
|
|
return JsonError("没有找到客户信息");
|
|
}
|
|
|
|
client.MetaDic = new ClientMetaService(CurUser).GetMetaDic(client.id);
|
|
client.CreditRatingStr = new ClientRatingService(CurUser).GetCurrentCreditRating(valuedateBLL.ValueDate, client.id)?.Item2;
|
|
return JsonSuccess(client);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取客户信息
|
|
/// </summary>
|
|
[HttpPost]
|
|
[Route("api/v1/getClientInfo2")]
|
|
public ApiResponseModel GetClientInfo2([FromBody] ClientInfoQueryModel queryModel)
|
|
{
|
|
if (queryModel is null)
|
|
{
|
|
return JsonError("缺少必需的请求参数");
|
|
}
|
|
|
|
var result = new ClientInfoQueryService(CurUser).GetClientInfo(queryModel);
|
|
|
|
if (result == null)
|
|
{
|
|
return JsonError("没有找到客户信息");
|
|
}
|
|
|
|
return JsonSuccess(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取客户信息
|
|
/// </summary>
|
|
[HttpPost]
|
|
[Route("api/v1/client/view")]
|
|
public ApiResponseModel ClientView([FromBody] ClientInfoQueryModel queryModel)
|
|
{
|
|
if (queryModel is null)
|
|
{
|
|
return JsonError("缺少必需的请求参数");
|
|
}
|
|
|
|
var result = new ClientInfoQueryService(CurUser).GetClientInfo(queryModel);
|
|
|
|
if (result == null)
|
|
{
|
|
return JsonError("没有找到客户信息");
|
|
}
|
|
|
|
var ClientInfo = ClientInfoQueryService.ConvertToViewData(result.ClientInfo);
|
|
|
|
return JsonSuccess(new { ClientInfo, result.BankCards, result.Duties });
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过API创建客户
|
|
/// </summary>
|
|
[HttpPost]
|
|
[Route("api/v1/CreateClient")]
|
|
public ApiResponseModel CreateClient(CreateClientReq req)
|
|
{
|
|
new ClientSaveService(CurUser).CreateClient(req);
|
|
return JsonSuccess("更新成功");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过API编辑(新增或者修改)客户
|
|
/// </summary>
|
|
[HttpPost]
|
|
[Route("api/v1/saveClient")]
|
|
public ApiResponseModel SaveClient(Client req)
|
|
{
|
|
var client = new ClientSaveService(CurUser).SaveClientAPI(req);
|
|
|
|
return JsonSuccess(new
|
|
{
|
|
ClientId = client.id,
|
|
ClientName = client.Name,
|
|
ClientNumber = client.Number
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存客户人员信息V2
|
|
/// </summary>
|
|
[HttpPost, Route("api/v2/saveClient")]
|
|
public ApiResponseModel SaveClientV2([FromBody] Dictionary<string, object> model)
|
|
{
|
|
var result = new ClientSaveApiV2Service(CurUser).Save(model);
|
|
|
|
return JsonSuccess(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 客户信息列表
|
|
/// </summary>
|
|
[HttpPost, Route("api/v1/clientInfoList")]
|
|
public ApiResponseModel ClientInfoList()
|
|
{
|
|
// 查询客户信息
|
|
using var db = DbContextFactory.GetClientDbContext(CurUser);
|
|
var clients = db.client.Where(n => n.ProcessStatus == "已开户")
|
|
.Select(n => new
|
|
{
|
|
ClientId = n.id,
|
|
ClientName = n.Name,
|
|
ClientNumber = n.Number,
|
|
n.ClientType,
|
|
n.LicenseCode, //证照编号
|
|
n.LicenseType
|
|
}).ToArray();
|
|
|
|
// 查询授信信息
|
|
using var yldb = DbContextFactory.GetYLDbContext();
|
|
var credits = yldb.credit.Where(g => clients.Select(b => b.ClientId).ToArray().Contains(g.ClientId ?? 0) && valuedateBLL.ValueDate >= g.CreditStartDate && valuedateBLL.ValueDate <= g.CreditDeadLine)
|
|
.ToArray().GroupBy(g => g.ClientId).Select(g => g.FirstOrDefault()).ToArray();
|
|
// yldb.ClientBalanceDaily.Where()
|
|
|
|
var result = (from client in clients
|
|
join credit in credits on client.ClientId equals credit.ClientId into creditTmp
|
|
from creditT in creditTmp.DefaultIfEmpty()
|
|
select new
|
|
{
|
|
client.ClientId,
|
|
client.ClientName,
|
|
client.ClientNumber,
|
|
client.ClientType,
|
|
client.LicenseCode, //证照编号
|
|
client.LicenseType,
|
|
creditT?.CreditStartDate,
|
|
creditT?.Credit,
|
|
creditT?.CreditDeadLine,
|
|
MetaDic = new Dictionary<string, string>()
|
|
}).ToList();
|
|
|
|
if (PS.Config.Company == CompanyEnum.兴证)
|
|
{
|
|
var ids = clients.Select(b => b.ClientId).ToArray();
|
|
var dicMetas = db.ClientMeta.Where(g => ids.Contains(g.ClientId) && g.MetaKey == "CustomerScore")
|
|
.Select(n => new { n.ClientId, n.MetaValue })
|
|
.AsEnumerable().ToDictionary(l => l.ClientId, l => l.MetaValue);
|
|
|
|
foreach (var item in result)
|
|
{
|
|
item.MetaDic["资信评分"] = dicMetas.TryGetValue(item.ClientId, out var CustomerScore) ? CustomerScore : "";
|
|
}
|
|
}
|
|
|
|
return JsonSuccess(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 客户持仓查询
|
|
/// </summary>
|
|
//[TypeFilter(typeof(ActionLogFilter))]
|
|
[HttpPost, Route("api/v1/clientPositionList")]
|
|
public ApiResponseModel ClientPositionList([FromBody] ClientPositionQueryModel reqModel)
|
|
{
|
|
reqModel ??= new ClientPositionQueryModel();
|
|
|
|
var pagedList = new ClientPositionService(CurUser).GetAllPositionsV1(reqModel);
|
|
|
|
return JsonPagedList(pagedList);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 客户持仓查询
|
|
/// </summary>
|
|
//[TypeFilter(typeof(ActionLogFilter))]
|
|
[HttpPost, Route("api/v2/clientPositionList")]
|
|
public ApiResponseModel ClientPositionListV2([FromBody] ClientPositionQueryModel reqModel)
|
|
{
|
|
reqModel ??= new ClientPositionQueryModel();
|
|
|
|
var pagedList = new ClientPositionService(CurUser).GetAllPositionsV2(reqModel);
|
|
return JsonPagedList(pagedList);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 客户持仓查询
|
|
/// </summary>
|
|
//[TypeFilter(typeof(ActionLogFilter))]
|
|
[HttpPost, Route("api/v3/clientPositionList")]
|
|
public ApiResponseModel ClientPositionListV3([FromBody] ClientPositionQueryModel reqModel)
|
|
{
|
|
reqModel ??= new ClientPositionQueryModel();
|
|
|
|
var pagedList = new ClientPositionService(CurUser).GetAllPositionsV3(reqModel);
|
|
|
|
return JsonPagedList(pagedList);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 结算报告:获取客户财务状况
|
|
/// </summary>
|
|
[HttpPost, Route("api/v1/clientLatestBalanceList")]
|
|
public ApiResponseModel ClientLatestBalanceList([FromBody] ClientLatestBalanceRequestModel reqModel)
|
|
{
|
|
if (reqModel is null)
|
|
{
|
|
reqModel = new ClientLatestBalanceRequestModel();
|
|
}
|
|
else if (reqModel.ClientId == 0)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(reqModel.ClientNumber))
|
|
{
|
|
var ids = new ClientDataService(CurUser).GetClientIdByNumber(reqModel.ClientNumber);
|
|
if (ids.Length == 0)
|
|
{
|
|
return JsonError($"根据客户编号'{reqModel.ClientNumber}'没有找到客户信息");
|
|
}
|
|
if (ids.Length > 1)
|
|
{
|
|
return JsonError($"根据客户编号'{reqModel.ClientNumber}'找到多个客户信息,不支持此种请求");
|
|
}
|
|
reqModel.ClientId = ids[0];
|
|
}
|
|
else if (!string.IsNullOrWhiteSpace(reqModel.ClientName))
|
|
{
|
|
var ids = new ClientDataService(CurUser).GetClientIdByName(reqModel.ClientName);
|
|
if (ids.Length == 0)
|
|
{
|
|
return JsonError($"根据客户名称'{reqModel.ClientName}'没有找到客户信息");
|
|
}
|
|
if (ids.Length > 1)
|
|
{
|
|
return JsonError($"根据客户名称'{reqModel.ClientName}'找到多个客户信息,不支持此种请求");
|
|
}
|
|
reqModel.ClientId = ids[0];
|
|
}
|
|
}
|
|
|
|
if (reqModel.ClientId > 0)
|
|
{
|
|
var datas = ClientBalanceUtility.GetClientBanlances(
|
|
clientIdList: new List<int> { reqModel.ClientId },
|
|
startDate: reqModel.ValueDateFrom ?? DateTime.MinValue,
|
|
endDate: reqModel.ValueDateTo ?? YLErp.BLL.valuedateBLL.ValueDate,
|
|
IsGetOuterMarginGap: reqModel.IsGetOuterMarginGap);
|
|
return JsonSuccess(datas);
|
|
}
|
|
else
|
|
{
|
|
var datas = ClientBalanceUtility.GetAllClientBanlances(
|
|
startDate: reqModel.ValueDateFrom ?? DateTime.MinValue,
|
|
endDate: reqModel.ValueDateTo ?? YLErp.BLL.valuedateBLL.ValueDate,
|
|
IsGetOuterMarginGap: reqModel.IsGetOuterMarginGap);
|
|
return JsonSuccess(datas);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 客户银行卡信息
|
|
/// </summary>
|
|
[HttpPost, Route("api/v1/clientBankCardList")]
|
|
public ApiResponseModel ClientBankCardList([FromBody] ClientInfoQueryModel queryModel)
|
|
{
|
|
if (queryModel is null)
|
|
{
|
|
return JsonError("缺少必需的请求参数");
|
|
}
|
|
|
|
var result = new ClientInfoQueryService(CurUser).GetClientBankCards(queryModel);
|
|
|
|
return JsonSuccess(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 客户人员信息
|
|
/// </summary>
|
|
[HttpPost, Route("api/v1/clientDutyList")]
|
|
public ApiResponseModel ClientDutyList([FromBody] ClientInfoQueryModel queryModel)
|
|
{
|
|
if (queryModel is null)
|
|
{
|
|
return JsonError("缺少必需的请求参数");
|
|
}
|
|
|
|
var result = new ClientInfoQueryService(CurUser).GetClientDuties(queryModel);
|
|
|
|
return JsonSuccess(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 客户文件批量导出
|
|
/// </summary>
|
|
[HttpPost, Route("api/v1/clientFileBatchExport")]
|
|
public HttpResponseMessage ClientFileBatchExport([FromBody] ClientInfoQueryModel model)
|
|
{
|
|
if (model is null)
|
|
{
|
|
return new HttpResponseMessage(HttpStatusCode.InternalServerError)
|
|
{
|
|
Content = new StringContent("参数不能为空", System.Text.Encoding.UTF8, "text/plain")
|
|
};
|
|
}
|
|
|
|
try
|
|
{
|
|
var zipBuffer = new ClientInfoQueryService(CurUser).GetZipFileOfClientFiles(model);
|
|
|
|
var result = new HttpResponseMessage(HttpStatusCode.OK)
|
|
{
|
|
Content = new ByteArrayContent(zipBuffer)
|
|
};
|
|
|
|
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
|
|
{
|
|
FileName = "客户文件批量导出.zip"
|
|
};
|
|
|
|
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
|
|
|
|
return result;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new HttpResponseMessage(HttpStatusCode.InternalServerError)
|
|
{
|
|
Content = new StringContent(ex.ToString(), System.Text.Encoding.UTF8, "text/plain")
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|