Commit a708b1e2 by lcx

Merge branch 'feature/核算序号' into develop

parents c325f1ac 5016b565
......@@ -683,6 +683,20 @@ public ApiResponse BatchAccountingStructrue([FromRoute] int allotId)
/// <param name="allotId"></param>
/// <param name="request"></param>
/// <returns></returns>
[Route("BatchCheckAccounting/{allotId}")]
[HttpPost]
public ApiResponse BatchCheckAccounting(int allotId, [FromBody] SaveCollectData request)
{
var result = _configService.BatchSaveAccounting(allotId, request, false);
return new ApiResponse(ResponseType.OK, "校验通过");
}
/// <summary>
/// 核算单元及组别批量添加
/// </summary>
/// <param name="allotId"></param>
/// <param name="request"></param>
/// <returns></returns>
[Route("BatchSaveAccounting/{allotId}")]
[HttpPost]
public ApiResponse BatchSaveAccounting(int allotId, [FromBody] SaveCollectData request)
......
......@@ -1630,6 +1630,11 @@
核算单元
</summary>
</member>
<member name="P:Performance.EntityModels.cof_accounting.Code">
<summary>
核算单元编码
</summary>
</member>
<member name="T:Performance.EntityModels.cof_again">
<summary>
......
......@@ -34,5 +34,10 @@ public class cof_accounting
/// 核算单元
/// </summary>
public string AccountingUnit { get; set; }
/// <summary>
/// 核算单元编码
/// </summary>
public string Code { get; set; }
}
}
......@@ -786,7 +786,7 @@ public List<cof_accounting> GetAccountingList(AccoungingRequest request)
if (request.Type == (int)AccountTypeEnum.AccountingUnit && !string.IsNullOrEmpty(request.UnitType))
exp = exp.And(t => t.UnitType.Replace("行政后勤", "行政工勤") == request.UnitType.Replace("行政后勤", "行政工勤"));
return cofaccountingRepository.GetEntities(exp) ?? new List<cof_accounting>();
return cofaccountingRepository.GetEntities(exp)?.OrderBy(t => ConvertHelper.To<int>(t.Code)).ToList() ?? new List<cof_accounting>();
}
/// <summary>
......@@ -853,47 +853,67 @@ public HandsonTable GetBatchAccountingStructrue(int AllotId)
{
foreach (var column in result.Columns)
{
if (column.Data == "核算组别")
{
column.Type = "autocomplete";
column.Source = EnumHelper.GetItems<UnitType>().Select(w => w.Description.Replace("行政后勤", "行政工勤")).ToArray();
column.Strict = true;
}
if (column.Data == "核算单元编码")
{
column.Type = "text";
column.NumericFormat = null;
}
}
}
return result;
}
public bool BatchSaveAccounting(int allotId, SaveCollectData request)
public bool BatchSaveAccounting(int allotId, SaveCollectData request, bool isSave = true)
{
var dicData = CreateDataRow(0, allotId, request, Accounting);
var getAccounts = cofaccountingRepository.GetEntities(t => t.AllotId == allotId);
if (dicData == null || !dicData.Any()) throw new PerformanceException("未提交数据");
var getAccounts = cofaccountingRepository.GetEntities(t => t.AllotId == allotId) ?? new List<cof_accounting>();
var unitType = EnumHelper.GetItems<UnitType>().Select(w => w.Description.Replace("行政后勤", "行政工勤")).ToArray();
List<cof_accounting> accounts = new List<cof_accounting>();
foreach (var item in dicData)
{
var json = JsonHelper.Serialize(item);
var data = JsonHelper.Deserialize<cof_accounting>(json);
data.AllotId = allotId;
if (!unitType.Contains(data?.UnitType) && !string.IsNullOrEmpty(data?.UnitType)) return false;
if (getAccounts != null)
if (getAccounts.Any(t => t.AccountingUnit == data?.AccountingUnit && t.UnitType == data?.UnitType)) continue;
var any = accounts.Any(t => t.AccountingUnit == data?.AccountingUnit && t.UnitType == data?.UnitType);
var json = JsonHelper.Serialize(dicData);
var accounts = JsonHelper.Deserialize<List<cof_accounting>>(json);
if (accounts.Any(w => string.IsNullOrEmpty(w.Code))) throw new PerformanceException("核算单元编码有空值");
if (!string.IsNullOrEmpty(data.AccountingUnit) && !string.IsNullOrEmpty(data.UnitType) && !any)
if (accounts.GroupBy(t => t.Code).Any(w => w.Count() > 1)) throw new PerformanceException("核算单元编码有重复值");
if (accounts.Any(w => string.IsNullOrEmpty(w.AccountingUnit))) throw new PerformanceException("核算单元有空值");
if (accounts.Any(w => string.IsNullOrEmpty(w.UnitType))) throw new PerformanceException("核算单元类型有空值");
var grouped = accounts.GroupBy(t => new { t.AccountingUnit, t.UnitType });
if (grouped.Any(w => w.Count() > 1)) throw new PerformanceException("核算单元、核算单元类型有重复值");
if (isSave)
{
var delAccounts = new List<cof_accounting>();
foreach (var item in accounts)
{
accounts.Add(data);
var account = getAccounts.FirstOrDefault(w => w.Code == item.Code);
if (account != null)
delAccounts.Add(account);
}
if (delAccounts != null && delAccounts.Any())
cofaccountingRepository.RemoveRange(delAccounts.ToArray());
if (accounts != null && accounts.Any())
cofaccountingRepository.AddRange(accounts.ToArray());
}
if (accounts.Any())
cofaccountingRepository.AddRange(accounts.ToArray());
return true;
}
public static Dictionary<string, string> Accounting { get; } = new Dictionary<string, string>
{
{nameof(cof_accounting.Code), "核算单元编码"},
{nameof(cof_accounting.AccountingUnit), "核算单元"},
{nameof(cof_accounting.UnitType), "核算组别"},
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment