44673626
2 years ago
5 changed files with 574 additions and 14 deletions
@ -0,0 +1,450 @@ |
|||
using Magicodes.ExporterAndImporter.Core; |
|||
using Magicodes.ExporterAndImporter.Excel; |
|||
using Shouldly; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using TaskJob.EventArgs; |
|||
using TaskJob.Interfaces; |
|||
using Volo.Abp.BlobStoring; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Uow; |
|||
using Win.Sfs.BaseData.ImportExcelCommon; |
|||
using Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report; |
|||
|
|||
namespace SettleAccount.Job.Services.Report |
|||
{ |
|||
|
|||
|
|||
public class SyncFisService : ITransientDependency, IExportJob |
|||
{ |
|||
private readonly HQHSettledDetailDapperRepository _hqkanbanDapper; |
|||
private readonly KanbanUnSettledDapperRepository _kanbanDapper; |
|||
private readonly UnSettledDetailDapperRepository _dapper; |
|||
private readonly WmsDapperRepository _wmsDapper; |
|||
private readonly OutputService _outputService; |
|||
private readonly ErpPartDapperRepository _erpDapper; |
|||
private readonly SettleSparePartDapperReportRepository _sparepartdapper; |
|||
private readonly IBlobContainer<MyFileContainer> _fileContainer; |
|||
public SyncFisService( |
|||
HQHSettledDetailDapperRepository hqkanbanDapper, |
|||
KanbanUnSettledDapperRepository kanbanDapper, |
|||
UnSettledDetailDapperRepository dapper, |
|||
OutputService outputService, |
|||
ErpPartDapperRepository erpDapper, |
|||
WmsDapperRepository wmsDapper, |
|||
SettleSparePartDapperReportRepository sparepartdapper, |
|||
IBlobContainer<MyFileContainer> fileContainer |
|||
) |
|||
{ |
|||
_wmsDapper = wmsDapper; |
|||
_hqkanbanDapper = hqkanbanDapper; |
|||
_kanbanDapper = kanbanDapper; |
|||
_dapper = dapper; |
|||
_outputService = outputService; |
|||
_erpDapper = erpDapper; |
|||
_sparepartdapper = sparepartdapper; |
|||
_fileContainer = fileContainer; |
|||
} |
|||
[UnitOfWork(false)] |
|||
public string ExportFile(Guid id, List<string> exportName, List<CustomCondition> p_list) |
|||
{ |
|||
|
|||
var _lsExport= GetReport(id,exportName,p_list); |
|||
var _lsleft = GetLeftReport(id, exportName, p_list); |
|||
|
|||
|
|||
|
|||
|
|||
//ExcelExporter _exporter = new ExcelExporter();//导出Excel
|
|||
//var result = _exporter.Append(_lsExport, "汇总核对表1")
|
|||
////.SeparateBySheet()
|
|||
////.Append(_lsleft, "汇总核对表2")
|
|||
//.ExportAppendDataAsByteArray();
|
|||
|
|||
//result.ShouldNotBeNull();
|
|||
//_fileContainer.SaveAsync(String.Format("结算未结寄售核对表{0}.xlsx",Guid.NewGuid().ToString("N")), result.Result, true);
|
|||
|
|||
|
|||
|
|||
var _first = exportName.FirstOrDefault(); |
|||
_outputService.Export<UnSettledSum>(id, _first, _lsExport); |
|||
return id.ToString(); |
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
[UnitOfWork(false)] |
|||
public List<UnSettledSum> GetFisSum(Guid id, List<string> exportName, List<CustomCondition> p_list) |
|||
{ |
|||
var _first = exportName.FirstOrDefault(); |
|||
var version = p_list.Where(p => p.Name == "Version").FirstOrDefault().Value; |
|||
|
|||
var materailCode = p_list.Where(p => p.Name == "MaterialCode").FirstOrDefault().Value; |
|||
var materialGroup = p_list.Where(p => p.Name == "MaterialGroup").FirstOrDefault().Value; |
|||
//var sapcode = p_list.Where(p => p.Name == "SapMaterialCode").FirstOrDefault().Value;
|
|||
var begin = p_list.Where(p => p.Name == "Begin").FirstOrDefault().Value; |
|||
var end = p_list.Where(p => p.Name == "End").FirstOrDefault().Value; |
|||
//var kenncode = p_list.Where(p => p.Name == "KennCode").FirstOrDefault().Value;
|
|||
//var chassisNumber = p_list.Where(p => p.Name == "ChassisNumber").FirstOrDefault().Value;
|
|||
//var sapCode = p_list.Where(p => p.Name == "SapCode").FirstOrDefault().Value;
|
|||
//var cp7begin = p_list.Where(p => p.Name == "CP7Begin").FirstOrDefault().Value;
|
|||
//var cp7end = p_list.Where(p => p.Name == "CP7End").FirstOrDefault().Value;
|
|||
var datestr = version.Substring(0, 4) + "-" + version.Substring(4, 2) + "-01"; |
|||
var date = DateTime.Parse(datestr).AddMonths(1).AddDays(-1); |
|||
var datetime = date.ToShortDateString() + " 23:59:59 "; |
|||
|
|||
var _list = _dapper.GetDiffReport(DateTime.Now.Year.ToString(), begin, datetime, "", version, materailCode, materialGroup, ""); |
|||
var _ls = _list.Where(p => p.Flag != "L").Where(p => p.ParentSapMaterialCode != p.SapMaterialCode).GroupBy(p => new { p.KENNCode, p.ChassisNumber, p.ParentSapMaterialCode }).Select(p => p.FirstOrDefault()).ToList(); |
|||
var _lst = _erpDapper.GetSapList(_ls, version, false); |
|||
_lst.ForEach(p => |
|||
{ |
|||
|
|||
p.Qty = 1; |
|||
p.DiffAMT = Math.Round(p.Qty * p.Price, 2); |
|||
p.DiffQty = 1; |
|||
} |
|||
); |
|||
|
|||
_list.AddRange(_lst); |
|||
_list = _list.Where(p => p.SapMaterialCode == p.ParentSapMaterialCode).ToList(); |
|||
|
|||
|
|||
|
|||
if (!string.IsNullOrEmpty(materialGroup)) |
|||
{ |
|||
var _groupList = materialGroup.Split(new char[] { ',' }).Distinct().ToList(); |
|||
if (_groupList.Count() > 0) |
|||
{ |
|||
_list = _list.Where(p => _groupList.Contains(p.MaterialGroup)).ToList(); |
|||
} |
|||
} |
|||
//if (!string.IsNullOrEmpty(kenncode))
|
|||
//{
|
|||
// var _groupList = kenncode.Split(new char[] { '\n' }).Distinct().ToList();
|
|||
// if (_groupList.Count() > 0)
|
|||
// {
|
|||
// _list = _list.Where(p => _groupList.Contains(p.KENNCode)).ToList();
|
|||
// }
|
|||
//}
|
|||
//if (!string.IsNullOrEmpty(chassisNumber))
|
|||
//{
|
|||
// var _groupList = chassisNumber.Split(new char[] { '\n' }).Distinct().ToList();
|
|||
// if (_groupList.Count() > 0)
|
|||
// {
|
|||
// _list = _list.Where(p => _groupList.Contains(p.ChassisNumber)).ToList();
|
|||
// }
|
|||
//}
|
|||
//if (!string.IsNullOrEmpty(sapCode))
|
|||
//{
|
|||
// var _groupList = sapCode.Split(new char[] { '\n' }).Distinct().ToList();
|
|||
// if (_groupList.Count() > 0)
|
|||
// {
|
|||
// _list = _list.Where(p => _groupList.Contains(p.SapMaterialCode)).ToList();
|
|||
// }
|
|||
//}
|
|||
if (!string.IsNullOrEmpty(materailCode)) |
|||
{ |
|||
var _groupList = materailCode.Split(new char[] { '\n' }).Distinct().ToList(); |
|||
if (_groupList.Count() > 0) |
|||
{ |
|||
_list = _list.Where(p => _groupList.Contains(p.SapMaterialCode)).ToList(); |
|||
} |
|||
} |
|||
var _fislist =_list.GroupBy(p => new { p.SapMaterialCode, p.MaterialDesc, p.MaterialGroup, p.MaterialCode }) |
|||
.Select(p => new UnSettledSum |
|||
{ |
|||
库位 = "PLJS", |
|||
版本 = version, |
|||
物料号 = p.Key.SapMaterialCode, |
|||
//客户物料 = p.Key.MaterialCode,
|
|||
物料描述 = p.Key.MaterialDesc, |
|||
物料组车型 = p.Key.MaterialGroup, |
|||
SAS未结明细汇总 = p.Sum(p => p.Qty).ToString() |
|||
|
|||
}).ToList(); |
|||
return _fislist; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 大众看板未结数据
|
|||
/// </summary>
|
|||
/// <param name="id"></param>
|
|||
/// <param name="exportName"></param>
|
|||
/// <param name="p_list"></param>
|
|||
/// <returns></returns>
|
|||
public List<UnSettledSum> GetKanbanSum(Guid id, List<string> exportName, List<CustomCondition> p_list) |
|||
{ |
|||
var _filename = exportName.FirstOrDefault(); |
|||
var version = p_list.Where(p => p.Name == "Version").FirstOrDefault().Value; |
|||
var begin = p_list.Where(p => p.Name == "Begin").FirstOrDefault().Value; |
|||
var end = p_list.Where(p => p.Name == "End").FirstOrDefault().Value; |
|||
var materailCode = p_list.Where(p => p.Name == "MaterialCode").FirstOrDefault().Value; |
|||
var materialGroup = p_list.Where(p => p.Name == "MaterialGroup").FirstOrDefault().Value; |
|||
//var sapCode = p_list.Where(p => p.Name == "SAPCode").FirstOrDefault().Value;
|
|||
//var iscontionversion = p_list.Where(p => p.Name == "IsContainVersion").FirstOrDefault().Value;
|
|||
var iscontionversion = "1";//不分版本,全查
|
|||
|
|||
|
|||
|
|||
|
|||
//var version = p_list.Where(p => p.Name == "Version").FirstOrDefault().Value;
|
|||
//var customerCode = p_list.Where(p => p.Name == "CustomerCode").FirstOrDefault().Value;
|
|||
//var materailCode = p_list.Where(p => p.Name == "MaterialCode").FirstOrDefault().Value;
|
|||
//var materialGroup = p_list.Where(p => p.Name == "MaterialGroup").FirstOrDefault().Value;
|
|||
//var sapcode = p_list.Where(p => p.Name == "SapMaterialCode").FirstOrDefault().Value;
|
|||
//var begin = p_list.Where(p => p.Name == "Begin").FirstOrDefault().Value;
|
|||
//var end = p_list.Where(p => p.Name == "End").FirstOrDefault().Value;
|
|||
//var kenncode = p_list.Where(p => p.Name == "KennCode").FirstOrDefault().Value;
|
|||
//var chassisNumber = p_list.Where(p => p.Name == "ChassisNumber").FirstOrDefault().Value;
|
|||
//var sapCode = p_list.Where(p => p.Name == "SapCode").FirstOrDefault().Value;
|
|||
var datestr = version.Substring(0, 4) + "-" + version.Substring(4, 2) + "-01"; |
|||
var date = DateTime.Parse(datestr).AddMonths(1).AddDays(-1); |
|||
var datetime = date.ToShortDateString() + " 23:59:59 "; |
|||
|
|||
var _ls = _kanbanDapper.GetKanbanReportList(version, begin, datetime, iscontionversion); |
|||
|
|||
|
|||
//if (!string.IsNullOrEmpty(sapCode))
|
|||
//{
|
|||
// var _groupList = sapCode.Split(new char[] { '\n' }).Distinct().ToList();
|
|||
// if (_groupList.Count() > 0)
|
|||
// {
|
|||
// _ls = _ls.Where(p => _groupList.Contains(p.SapCode)).ToList();
|
|||
// }
|
|||
//}
|
|||
|
|||
if (!string.IsNullOrEmpty(materailCode)) |
|||
{ |
|||
var _groupList = materailCode.Split(new char[] { '\n' }).Distinct().ToList(); |
|||
if (_groupList.Count() > 0) |
|||
{ |
|||
_ls = _ls.Where(p => _groupList.Contains(p.CustomerPartCode)).ToList(); |
|||
} |
|||
} |
|||
if (!string.IsNullOrEmpty(materialGroup)) |
|||
{ |
|||
var _groupList = materialGroup.Split(new char[] { ',' }).Distinct().ToList(); |
|||
if (_groupList.Count() > 0) |
|||
{ |
|||
_ls = _ls.Where(p => _groupList.Contains(p.MaterialGroup)).ToList(); |
|||
} |
|||
} |
|||
|
|||
|
|||
//DiffQty 为实际发货数量=发货数量-结算数量-退货数量 财务要求
|
|||
var kanbanList = _ls.GroupBy(p => new { p.SapCode, p.MaterialDesc, p.MaterialGroup, p.CustomerPartCode }) |
|||
.Select(p => new UnSettledSum |
|||
{ |
|||
库位 = "PLJS", |
|||
版本 = version, |
|||
物料号 = p.Key.SapCode, |
|||
//客户物料 = p.Key.CustomerPartCode,
|
|||
物料描述 = p.Key.MaterialDesc, |
|||
物料组车型 = p.Key.MaterialGroup, |
|||
SAS未结明细汇总 = p.Sum(p => p.DiffQty).ToString() |
|||
|
|||
}).ToList(); |
|||
|
|||
|
|||
|
|||
return kanbanList; |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 红旗看板未结明细
|
|||
/// </summary>
|
|||
/// <param name="id"></param>
|
|||
/// <param name="exportName"></param>
|
|||
/// <param name="p_list"></param>
|
|||
/// <returns></returns>
|
|||
public List<UnSettledSum> GetHQKanbanSum(Guid id, List<string> exportName, List<CustomCondition> p_list) |
|||
{ |
|||
var _filename = exportName.FirstOrDefault(); |
|||
var version = p_list.Where(p => p.Name == "Version").FirstOrDefault().Value; |
|||
var materialCode = p_list.Where(p => p.Name == "MaterialCode").FirstOrDefault().Value; |
|||
//var kanban = p_list.Where(p => p.Name == "Kanban").FirstOrDefault().Value;
|
|||
var begin = p_list.Where(p => p.Name == "Begin").FirstOrDefault().Value; |
|||
var end = p_list.Where(p => p.Name == "End").FirstOrDefault().Value; |
|||
var materialGroup = p_list.Where(p => p.Name == "MaterialGroup").FirstOrDefault().Value; |
|||
//var acceptNo = p_list.Where(p => p.Name == "AcceptNo").FirstOrDefault().Value;
|
|||
var sapCode = p_list.Where(p => p.Name == "SapCode").FirstOrDefault().Value; |
|||
//var warehouseDesc = p_list.Where(p => p.Name == "WarehouseDesc").FirstOrDefault().Value;
|
|||
//var iscontionversion = p_list.Where(p => p.Name == "IsContainVersion").FirstOrDefault().Value;
|
|||
var iscontionversion = "1";//不分区间,全查
|
|||
//有发货无结算,单独拿出去,财务要求
|
|||
|
|||
var datestr = version.Substring(0, 4) + "-" + version.Substring(4, 2) + "-01"; |
|||
var date = DateTime.Parse(datestr).AddMonths(1).AddDays(-1); |
|||
var datetime = date.ToShortDateString() + " 23:59:59 "; |
|||
|
|||
var _ls = _hqkanbanDapper.GetReverseSettledDetailDiffReportList(version, materialCode, begin, datetime, materialGroup, iscontionversion); |
|||
if (!string.IsNullOrEmpty(sapCode)) |
|||
{ |
|||
var _groupList = sapCode.Split(new char[] { '\n' }).Distinct().ToList(); |
|||
if (_groupList.Count() > 0) |
|||
{ |
|||
_ls = _ls.Where(p => _groupList.Contains(p.Sap编码)).ToList(); |
|||
} |
|||
} |
|||
|
|||
var kanbanList = _ls.GroupBy(p => new { p.Sap编码, p.零件中文名称, p.物料组, p.客户物料号 }) |
|||
.Select(p => new UnSettledSum |
|||
{ |
|||
库位="PLJS", |
|||
版本=version, |
|||
物料号 = p.Key.Sap编码, |
|||
//客户物料 = p.Key.客户物料号,
|
|||
物料描述 = p.Key.零件中文名称, |
|||
物料组车型 = p.Key.物料组, |
|||
SAS未结明细汇总 = p.Sum(p => p.未结数量).ToString() |
|||
|
|||
}).ToList(); |
|||
|
|||
return kanbanList; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 大众备件未对
|
|||
/// </summary>
|
|||
/// <param name="id"></param>
|
|||
/// <param name="exportName"></param>
|
|||
/// <param name="p_list"></param>
|
|||
/// <returns></returns>
|
|||
public List<UnSettledSum> GetSparePartSum(Guid id, List<string> exportName, List<CustomCondition> p_list) |
|||
{ |
|||
var fileName = exportName.FirstOrDefault(); |
|||
//var purchaseOrderNo = p_list.Where(p => p.Name == "PurchaseOrderNo").FirstOrDefault().Value;
|
|||
var version = p_list.Where(p => p.Name == "Version").FirstOrDefault().Value; |
|||
var sapCode = p_list.Where(p => p.Name == "SapCode").FirstOrDefault().Value; |
|||
var matialCode = p_list.Where(p => p.Name == "MaterialCode").FirstOrDefault().Value; |
|||
var beginTime = p_list.Where(p => p.Name == "Begin").FirstOrDefault().Value; |
|||
var endTime = p_list.Where(p => p.Name == "End").FirstOrDefault().Value; |
|||
|
|||
var datestr = version.Substring(0, 4) + "-" + version.Substring(4, 2) + "-01"; |
|||
var date = DateTime.Parse(datestr).AddMonths(1).AddDays(-1); |
|||
var datetime = date.ToShortDateString() + " 23:59:59 "; |
|||
|
|||
//var _ls = _sparepartdapper.GetReverseWithCodeSettleSparePartReportList(purchaseOrderNo, version, sapCode, matialCode, beginTime, endTime);
|
|||
var _ls = _sparepartdapper.GetReverseWithCodeSettleSparePartReportList("", version, sapCode, matialCode, beginTime, datetime); |
|||
if (!string.IsNullOrEmpty(sapCode)) |
|||
{ |
|||
var _groupList = sapCode.Split(new char[] { '\n' }).Distinct().ToList(); |
|||
if (_groupList.Count() > 0) |
|||
{ |
|||
_ls = _ls.Where(p => _groupList.Contains(p.SAP编码)).ToList(); |
|||
} |
|||
} |
|||
//说明 为实际发货数量=发货数量-结算数量-退货数量 财务要求
|
|||
var kanbanList = _ls.GroupBy(p => new { p.SAP编码, p.物料描述, p.物料代码 }) |
|||
.Select(p => new UnSettledSum |
|||
{ |
|||
库位 = "BJJS", |
|||
版本 = version, |
|||
物料号 = p.Key.SAP编码, |
|||
//客户物料 = p.Key.物料代码,
|
|||
物料描述 = p.Key.物料描述, |
|||
物料组车型 = string.Empty, |
|||
SAS未结明细汇总 = p.Sum(p =>Convert.ToDecimal(p.实际发货数量)).ToString() |
|||
|
|||
}).ToList(); |
|||
|
|||
return kanbanList; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
public List<UnSettledSum> GetReport(Guid id, List<string> exportName, List<CustomCondition> p_list) |
|||
{ |
|||
var version = p_list.Where(p => p.Name == "Version").FirstOrDefault().Value; |
|||
List<UnSettledSum> _ls = new List<UnSettledSum>(); |
|||
_ls.AddRange(GetFisSum(id, exportName, p_list)); |
|||
_ls.AddRange(GetHQKanbanSum(id, exportName, p_list)); |
|||
_ls.AddRange(GetKanbanSum(id, exportName, p_list)); |
|||
_ls.AddRange(GetSparePartSum(id, exportName, p_list));//大众备件未结
|
|||
|
|||
|
|||
|
|||
var _lst = _wmsDapper.GetSalesStockSum(version); |
|||
var query = from itm in _lst |
|||
join itm1 in _ls |
|||
on new { Version = itm.Version, PartCode = itm.PartCode.Trim(), LocCode= itm.LocCode.ToUpper()} equals new { Version = itm1.版本, PartCode = itm1.物料号.Trim(), LocCode = itm1.库位} |
|||
into temp |
|||
from tm in temp.DefaultIfEmpty() |
|||
select new UnSettledSum |
|||
{ |
|||
|
|||
版本 = itm.Version, |
|||
物料号 = itm.PartCode, |
|||
物料描述 = itm.PartDesc, |
|||
物料组编码= itm.PartGroup, |
|||
物料组车型 = itm.PartGroupDesc, |
|||
SAS未结明细汇总 = tm == null ? "0" : tm.SAS未结明细汇总, |
|||
WMS期初库存 = itm.StartQty.ToString(), |
|||
WMS期末库存 = itm.EndQty.ToString(), |
|||
库位 = itm.LocCode, |
|||
本月减少 = itm.OutQty.ToString(), |
|||
本月增加 = itm.InQty.ToString(), |
|||
差异= (itm.EndQty- decimal.Parse( tm == null ? "0" : tm.SAS未结明细汇总)).ToString() |
|||
|
|||
|
|||
}; |
|||
return query.ToList(); |
|||
} |
|||
|
|||
|
|||
public List<UnSettledSum> GetLeftReport(Guid id, List<string> exportName, List<CustomCondition> p_list) |
|||
{ |
|||
var version = p_list.Where(p => p.Name == "Version").FirstOrDefault().Value; |
|||
List<UnSettledSum> _ls = new List<UnSettledSum>(); |
|||
_ls.AddRange(GetFisSum(id, exportName, p_list)); |
|||
_ls.AddRange(GetHQKanbanSum(id, exportName, p_list)); |
|||
_ls.AddRange(GetKanbanSum(id, exportName, p_list)); |
|||
_ls.AddRange(GetSparePartSum(id, exportName, p_list));//大众备件未结
|
|||
|
|||
|
|||
|
|||
var _lst = _wmsDapper.GetSalesStockSum(version); |
|||
var query = from itm in _ls |
|||
join itm1 in _lst |
|||
on new { Version = itm.版本, PartCode = itm.物料号.Trim(), LocCode = itm.库位 } equals |
|||
new { Version = itm1.Version, PartCode = itm1.PartCode.Trim(), LocCode = itm1.LocCode.ToUpper() } |
|||
into temp |
|||
from tm in temp.DefaultIfEmpty() |
|||
select new UnSettledSum |
|||
{ |
|||
|
|||
版本 = itm.版本, |
|||
物料号 = itm.物料号, |
|||
物料描述 = itm.物料号, |
|||
物料组编码 = itm.物料组编码, |
|||
物料组车型 = itm.物料组车型, |
|||
SAS未结明细汇总 = tm == null ? "0" : tm.EndQty.ToString(), |
|||
WMS期初库存 = tm == null ? "0" : tm.StartQty.ToString(), |
|||
WMS期末库存 = tm == null ? "0" : tm.EndQty.ToString(), |
|||
库位 = itm.库位, |
|||
本月减少 = tm == null ? "0" : tm.OutQty.ToString(), |
|||
本月增加 = tm == null ? "0" : tm.InQty.ToString(), |
|||
差异 = ((tm == null ? 0 : tm.EndQty) - decimal.Parse(tm == null ? "0" : itm.SAS未结明细汇总)).ToString() |
|||
|
|||
|
|||
}; |
|||
return query.ToList(); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
} |
Loading…
Reference in new issue