|
|
@ -3,9 +3,11 @@ using System.Collections.Generic; |
|
|
|
using System.ComponentModel.DataAnnotations; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Data; |
|
|
|
using Volo.Abp.Users; |
|
|
|
using Win_in.Sfs.Auth.Application.Contracts; |
|
|
|
using Win_in.Sfs.Basedata.Application.Contracts; |
|
|
|
using Win_in.Sfs.Shared.Domain; |
|
|
@ -23,25 +25,53 @@ public class UnplannedIssueRequestForDongyangAppService : UnplannedIssueRequestA |
|
|
|
private readonly IDepartmentAppService _departmentApp; |
|
|
|
private readonly IUnplannedIssueRequestManager _unplannedIssueRequestManager; |
|
|
|
private readonly IBalanceAppService _balanceAppService; |
|
|
|
private readonly IDepartmentAppService _departmentAppService; |
|
|
|
private readonly ILocationAppService _locationAppService; |
|
|
|
private readonly ITransactionTypeAclService _transactionTypeAclService; |
|
|
|
|
|
|
|
|
|
|
|
public UnplannedIssueRequestForDongyangAppService(IUnplannedIssueRequestRepository repository, |
|
|
|
IUnplannedIssueRequestManager unplannedIssueRequestManager, |
|
|
|
IDepartmentAppService departmentApp, IBalanceAppService balanceAppService, IDepartmentAppService departmentAppService, ILocationAppService locationAppService, |
|
|
|
IDepartmentAppService departmentApp, IBalanceAppService balanceAppService, ILocationAppService locationAppService, |
|
|
|
ITransactionTypeAclService transactionTypeAclService |
|
|
|
) : base(repository, unplannedIssueRequestManager) |
|
|
|
{ |
|
|
|
_unplannedIssueRequestManager = unplannedIssueRequestManager; |
|
|
|
_departmentApp = departmentApp; |
|
|
|
_balanceAppService = balanceAppService; |
|
|
|
_departmentAppService = departmentAppService; |
|
|
|
_locationAppService = locationAppService; |
|
|
|
_transactionTypeAclService = transactionTypeAclService; |
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// OA创建计划外出库申请
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("create-by-oa")] |
|
|
|
//[Authorize(UnplannedIssueRequestPermissions.Create)]
|
|
|
|
public override async Task<UnplannedIssueRequestDTO> CreateByOAAsync(UnplannedIssueRequestEditInput input) |
|
|
|
{ |
|
|
|
var entity = ObjectMapper.Map<UnplannedIssueRequestEditInput, UnplannedIssueRequest>(input); |
|
|
|
foreach (var item in entity.Details) |
|
|
|
{ |
|
|
|
await SetDetailPropertiesAsync(item, input.UnplannedIssueType).ConfigureAwait(false); |
|
|
|
} |
|
|
|
entity.AutoCompleteJob = false; |
|
|
|
entity.AutoSubmit = true; |
|
|
|
entity.AutoAgree = true; |
|
|
|
entity.AutoHandle = true; |
|
|
|
if (entity.UnplannedIssueType == EnumUnplannedIssueType.Wip) |
|
|
|
{ |
|
|
|
entity.DirectCreateNote = true; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
entity.DirectCreateNote = false; |
|
|
|
} |
|
|
|
await _unplannedIssueRequestManager.CreateAsync(entity).ConfigureAwait(false); |
|
|
|
|
|
|
|
var dto = ObjectMapper.Map<UnplannedIssueRequest, UnplannedIssueRequestDTO>(entity); |
|
|
|
return dto; |
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// 用来重写 导入数据时可以加工数据
|
|
|
|
/// </summary>
|
|
|
@ -53,57 +83,99 @@ public class UnplannedIssueRequestForDongyangAppService : UnplannedIssueRequestA |
|
|
|
|
|
|
|
foreach (var unplannedIssueRequest in addList) |
|
|
|
{ |
|
|
|
unplannedIssueRequest.Worker = CurrentUser.GetUserName(); |
|
|
|
unplannedIssueRequest.CreatorId = CurrentUser.Id; |
|
|
|
|
|
|
|
if(unplannedIssueRequest.UnplannedIssueType != EnumUnplannedIssueType.Wip&& unplannedIssueRequest.UnplannedIssueType != EnumUnplannedIssueType.Raw) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"【{unplannedIssueRequest.UnplannedIssueType}】领料类型," + |
|
|
|
$"不是{EnumUnplannedIssueType.Wip.GetDisplayName()}" + |
|
|
|
$"或{EnumUnplannedIssueType.Raw.GetDisplayName()}】"); |
|
|
|
} |
|
|
|
await SetRequestAutoPropertiesAsync(unplannedIssueRequest).ConfigureAwait(false); |
|
|
|
await SetEntityPropertiesAsync(unplannedIssueRequest).ConfigureAwait(false); |
|
|
|
|
|
|
|
List<UnplannedIssueRequestDetail> newDetails = new List<UnplannedIssueRequestDetail>(); |
|
|
|
foreach (var detail in unplannedIssueRequest.Details) |
|
|
|
{ |
|
|
|
if (unplannedIssueRequest.UnplannedIssueType == EnumUnplannedIssueType.Raw) |
|
|
|
{ |
|
|
|
var locationDto = await _locationAppService.GetByCodeAsync(detail.LocationCode).ConfigureAwait(false); |
|
|
|
if (locationDto.Type != EnumLocationType.RAW || locationDto.Type != EnumLocationType.SEMI) |
|
|
|
if (locationDto.Type != EnumLocationType.RAW && locationDto.Type != EnumLocationType.SEMI) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"【{detail.LocationCode}】库位类型错误," + |
|
|
|
$"不是{EnumLocationType.RAW.GetDisplayName()}" + |
|
|
|
$"或{EnumLocationType.SEMI.GetDisplayName()}】"); |
|
|
|
} |
|
|
|
|
|
|
|
//需要复制一个这个方法 去掉区域参数 换成库位参数
|
|
|
|
//_balanceAppService.GetRecommendBalancesAsync(new RecommendBalanceRequestInput()
|
|
|
|
//{
|
|
|
|
// ItemCode = detail.ItemCode,
|
|
|
|
|
|
|
|
//});
|
|
|
|
unplannedIssueRequest.DirectCreateNote = false; |
|
|
|
} |
|
|
|
|
|
|
|
if (unplannedIssueRequest.UnplannedIssueType == EnumUnplannedIssueType.Wip) |
|
|
|
{ |
|
|
|
var locationDto = await _locationAppService.GetByCodeAsync(detail.LocationCode).ConfigureAwait(false); |
|
|
|
if (locationDto.Type != EnumLocationType.WIP) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"【{detail.LocationCode}】库位类型错误," + |
|
|
|
$"不是{EnumLocationType.WIP.GetDisplayName()}"); |
|
|
|
} |
|
|
|
|
|
|
|
//需要复制一个这个方法 去掉区域参数 换成库位参数
|
|
|
|
//_balanceAppService.GetRecommendBalancesAsync(new RecommendBalanceRequestInput()
|
|
|
|
//{
|
|
|
|
// ItemCode = detail.ItemCode,
|
|
|
|
|
|
|
|
//});
|
|
|
|
unplannedIssueRequest.DirectCreateNote = true; //线边 直接生成记录
|
|
|
|
$"不是{EnumLocationType.WIP.GetDisplayName()}】"); |
|
|
|
} |
|
|
|
} |
|
|
|
//需要复制一个这个方法 去掉区域参数 换成库位参数
|
|
|
|
RecommendBalanceRequestInput input = new RecommendBalanceRequestInput(); |
|
|
|
input.ItemCode = detail.ItemCode; |
|
|
|
input.Locations = new List<string>() { detail.LocationCode }; |
|
|
|
input.Qty = detail.Qty; |
|
|
|
input.Statuses = new List<EnumInventoryStatus> { EnumInventoryStatus.OK }; |
|
|
|
var balanceLst = await _balanceAppService.GetRecommendBalancesByLocationsAsync(input).ConfigureAwait(false); |
|
|
|
if (balanceLst.Count == 0) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"GetRecommendBalancesByLocationsAsync返回0条记录"); |
|
|
|
} |
|
|
|
var sumQty = balanceLst.Sum(itm => itm.Qty); |
|
|
|
if (detail.Qty > sumQty) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"库存数量不足:GetRecommendBalancesByLocationsAsync"); |
|
|
|
} |
|
|
|
foreach (var balance in balanceLst) |
|
|
|
{ |
|
|
|
var newDetail = CreateNewDetail(detail, balance); |
|
|
|
await SetDetailPropertiesAsync(newDetail, unplannedIssueRequest.UnplannedIssueType).ConfigureAwait(false); |
|
|
|
newDetails.Add(newDetail); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await SetDetailPropertiesAsync(detail).ConfigureAwait(false); |
|
|
|
} |
|
|
|
unplannedIssueRequest.Details.Clear();//删除所有明细}
|
|
|
|
unplannedIssueRequest.Details.AddRange(newDetails);//按推荐添加
|
|
|
|
} |
|
|
|
|
|
|
|
return dictionary; |
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// 创建明细
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="detail"></param>
|
|
|
|
/// <param name="balance"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
protected UnplannedIssueRequestDetail CreateNewDetail(UnplannedIssueRequestDetail detail,BalanceDTO balance) |
|
|
|
{ |
|
|
|
UnplannedIssueRequestDetail newDetail = new UnplannedIssueRequestDetail(); |
|
|
|
newDetail.ArriveDate = detail.ArriveDate; |
|
|
|
newDetail.CaseCode = detail.CaseCode; |
|
|
|
newDetail.ContainerCode = detail.ContainerCode; |
|
|
|
newDetail.Explain = detail.Explain; |
|
|
|
newDetail.ItemCode = detail.ItemCode; |
|
|
|
newDetail.LocationCode = detail.LocationCode; |
|
|
|
newDetail.Number = detail.Number; |
|
|
|
newDetail.OnceBusiCode = detail.OnceBusiCode; |
|
|
|
newDetail.ProjCapacityCode = detail.ProjCapacityCode; |
|
|
|
newDetail.ProduceDate = detail.ProduceDate; |
|
|
|
newDetail.PackingCode = balance.PackingCode; |
|
|
|
newDetail.Qty = balance.Qty; |
|
|
|
newDetail.SetIdAndNumber(GuidGenerator, detail.MasterID, detail.Number); |
|
|
|
return newDetail; |
|
|
|
} |
|
|
|
|
|
|
|
protected override UnplannedIssueRequest ModifyEntityBeforeAgree(UnplannedIssueRequest obj) |
|
|
|
{ |
|
|
|
if (obj.UnplannedIssueType == EnumUnplannedIssueType.Wip) |
|
|
|
{ |
|
|
|
obj.DirectCreateNote = true; //线边 直接生成记录
|
|
|
|
} |
|
|
|
return obj; |
|
|
|
} |
|
|
|
|
|
|
|
#region 赋值
|
|
|
|
|
|
|
@ -112,7 +184,7 @@ public class UnplannedIssueRequestForDongyangAppService : UnplannedIssueRequestA |
|
|
|
/// </summary>
|
|
|
|
/// <param name="detail"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private async Task SetDetailPropertiesAsync(UnplannedIssueRequestDetail detail) |
|
|
|
private async Task SetDetailPropertiesAsync(UnplannedIssueRequestDetail detail, EnumUnplannedIssueType type) |
|
|
|
{ |
|
|
|
var itemBasic = await ItemBasicAclService.GetByCodeAsync(detail.ItemCode).ConfigureAwait(false); |
|
|
|
CheckItemBasic(itemBasic, detail.ItemCode); |
|
|
@ -138,9 +210,13 @@ public class UnplannedIssueRequestForDongyangAppService : UnplannedIssueRequestA |
|
|
|
detail.LocationArea = location.AreaCode; |
|
|
|
detail.LocationCode = location.Code; |
|
|
|
} |
|
|
|
|
|
|
|
string packingcode = string.Empty; |
|
|
|
if(type!= EnumUnplannedIssueType.Wip) |
|
|
|
{ |
|
|
|
packingcode = detail.PackingCode; |
|
|
|
} |
|
|
|
var balance = await _balanceAppService.GetByItemLocationAndPackingAsync( |
|
|
|
string.Empty, |
|
|
|
packingcode, |
|
|
|
detail.ItemCode, |
|
|
|
detail.LocationCode).ConfigureAwait(false); |
|
|
|
|
|
|
@ -211,19 +287,23 @@ public class UnplannedIssueRequestForDongyangAppService : UnplannedIssueRequestA |
|
|
|
/// <returns></returns>
|
|
|
|
private async Task SetEntityPropertiesAsync(UnplannedIssueRequest entity) |
|
|
|
{ |
|
|
|
//var userName = CurrentUser.GetUserName();
|
|
|
|
|
|
|
|
//var department = await _departmentAppService.GetByUsernameAsync(userName).ConfigureAwait(false);
|
|
|
|
var userName = CurrentUser.GetUserName_New(); |
|
|
|
var name = CurrentUser.GetName(); |
|
|
|
if (userName != null) |
|
|
|
{ |
|
|
|
var department = await _departmentApp.GetByUsernameAsync(userName).ConfigureAwait(false); |
|
|
|
|
|
|
|
//if (department != null)
|
|
|
|
//{
|
|
|
|
// entity.DeptCode = department.Code;
|
|
|
|
// entity.DeptName = department.Name;
|
|
|
|
//}
|
|
|
|
if (department != null) |
|
|
|
{ |
|
|
|
entity.DeptCode = department.Code; |
|
|
|
entity.DeptName = department.Name; |
|
|
|
} |
|
|
|
|
|
|
|
//entity.Worker = userName;
|
|
|
|
entity.Worker = name; |
|
|
|
entity.CreatorId = CurrentUser.Id; |
|
|
|
} |
|
|
|
|
|
|
|
//entity.BuildDate = DateTime.Now;
|
|
|
|
entity.BuildDate = DateTime.Now; |
|
|
|
|
|
|
|
await SetRequestAutoPropertiesAsync(entity).ConfigureAwait(false); |
|
|
|
} |
|
|
@ -329,7 +409,7 @@ public class UnplannedIssueRequestForDongyangAppService : UnplannedIssueRequestA |
|
|
|
await CheckOnceBusiCodeAsync(model, validationRresult).ConfigureAwait(false);//次交易码
|
|
|
|
await CheckCaseCodeAsync(model, validationRresult).ConfigureAwait(false);//专案代码
|
|
|
|
await CheckProjCapacityCodeAsync(model, validationRresult).ConfigureAwait(false);//项目分类
|
|
|
|
_ = await CheckBalanceAsync(model, validationRresult).ConfigureAwait(false); |
|
|
|
// _ = await CheckBalanceAsync(model, validationRresult).ConfigureAwait(false);
|
|
|
|
} |
|
|
|
|
|
|
|
protected async Task<ItemBasicDTO> CheckItemBasicAsync(UnplannedIssueRequestImportInput importInput, List<ValidationResult> validationRresult) |
|
|
|