You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
277 lines
11 KiB
277 lines
11 KiB
2 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Threading.Tasks;
|
||
|
using Microsoft.AspNetCore.Mvc;
|
||
|
using Newtonsoft.Json;
|
||
|
using Volo.Abp.Application.Services;
|
||
|
using Volo.Abp.Domain.Repositories;
|
||
|
using Volo.Abp.Uow;
|
||
|
using WmsWebApi.EntityFrameworkCore;
|
||
|
using WmsWebApi.Wms;
|
||
|
|
||
|
namespace WmsWebApi.Parts;
|
||
|
|
||
|
[Route("/api/part")]
|
||
|
public class PartService : ApplicationService, IPartService
|
||
|
{
|
||
|
private readonly ITmPgPartgroupRepository _tmPgPartgroupRepository;
|
||
|
private readonly ITaPartRepository _taPartRepository;
|
||
|
private readonly ITaCustPartRepository _taCustPartRepository;
|
||
|
private readonly IPartManager _partDtoRepository;
|
||
|
private readonly TmPgWmsUpdate _tmPgWmsUpdate;
|
||
|
|
||
|
public PartService(ITmPgPartgroupRepository tmPgPartgroupRepository, ITaPartRepository taPartRepository,
|
||
|
ITaCustPartRepository taCustPartRepository,
|
||
|
IPartManager partDtoRepository,
|
||
|
TmPgWmsUpdate tmPgWmsUpdate)
|
||
|
{
|
||
|
_tmPgPartgroupRepository = tmPgPartgroupRepository;
|
||
|
_taPartRepository = taPartRepository;
|
||
|
_taCustPartRepository = taCustPartRepository;
|
||
|
_partDtoRepository = partDtoRepository;
|
||
|
_tmPgWmsUpdate = tmPgWmsUpdate;
|
||
|
}
|
||
|
|
||
|
[HttpPost("add")]
|
||
|
//[UnitOfWork(false)]
|
||
|
public async Task<ReturnResult> AddAsync([FromBody] object content)
|
||
|
{
|
||
|
var result = new ReturnResult();
|
||
|
PartDto _part;
|
||
|
bool bUpdate = false,bOtherWork = false,bErr = false;
|
||
|
try
|
||
|
{
|
||
|
_part = JsonConvert.DeserializeObject<PartDto>(content.ToString());
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
result.TYPE = 'E';
|
||
|
result.MESSAGE = "Json格式不正确,详细信息:" + ex.Message;
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
try
|
||
|
{
|
||
|
//判断是否是长春工厂
|
||
|
if (_part.WERKS != "1000")
|
||
|
{
|
||
|
bOtherWork = true;
|
||
|
result.MESSAGE = "其他工厂数据";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (string.IsNullOrEmpty(_part.MATNR))
|
||
|
throw new Exception($"物料号不能为空!");
|
||
|
|
||
|
if (_part.MATNR.Trim().StartsWith("1") || _part.MATNR.Trim().StartsWith("2") || _part.MATNR.Trim().StartsWith("3") || _part.MATNR.Trim().StartsWith("7"))
|
||
|
{
|
||
|
#region part信息更新
|
||
|
var part = new TA_PART();
|
||
|
//更新part信息
|
||
|
part.ErpPartCode = _part.MATNR.Trim();
|
||
|
part.PartCode = _part.MATNR.Trim();
|
||
|
|
||
|
//[DisplayName("物料描述1")]--物料描述
|
||
|
part.PartDesc1 = _part.MAKTX.Trim();
|
||
|
|
||
|
//[DisplayName("物料描述2")]--大小量纲
|
||
|
part.PartDesc2 = _part.GROES.Trim();
|
||
|
|
||
|
//[DisplayName("项目类别组")]--MRP类型
|
||
|
part.ProjectId = _part.DISMM.Trim();
|
||
|
|
||
|
//[DisplayName("单位")]--单位
|
||
|
part.Unit = _part.MEINS.Trim();
|
||
|
|
||
|
//[DisplayName("物料类型")] 直接是成品---物料类型编码
|
||
|
part.PartType = _part.MTART.Trim();
|
||
|
|
||
|
////[DisplayName("物料种类")]--
|
||
|
//part.PartKind = dr["物料种类"].ToString();
|
||
|
part.PartKind = string.Empty;
|
||
|
|
||
|
//[DisplayName("物料组")]--物料组编码
|
||
|
part.PartGroup = _part.MATKL.Trim();
|
||
|
|
||
|
//[DisplayName("状态")]
|
||
|
part.State = "A";
|
||
|
if(_part.MMSTA.Trim().ToUpper() == "Z2")
|
||
|
part.State = "H";
|
||
|
|
||
|
//[DisplayName("管理类型")] --判断物料组属性
|
||
|
//part.ManageType = dr["序列号管理"].ToString() == "1" ? EnumManageType.单包装 : EnumManageType.批量;
|
||
|
part.ManageType = 0;
|
||
|
var partgroup = await _tmPgPartgroupRepository.FirstOrDefaultAsync(p => p.WERKS == "1000" && p.PARTGROUP == part.PartGroup && p.IsManageType);
|
||
|
if (partgroup != null)
|
||
|
{
|
||
|
part.ManageType = 1;
|
||
|
}
|
||
|
|
||
|
//[DisplayName("价格标识")]---价格标识
|
||
|
var detail1 = _part.zzchar.FirstOrDefault(p => p.CHARACT == "ZMM005");
|
||
|
if (detail1 != null)
|
||
|
part.Promo = detail1.VALUE_NEUTRAL.Trim();
|
||
|
|
||
|
//更新时间
|
||
|
part.PalletTemplate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
|
||
|
//[DisplayName("ABC类")] 暂时作为位置信息使用---总成控制号标识
|
||
|
detail1 = _part.zzchar.FirstOrDefault(p => p.CHARACT == "ZMM006");
|
||
|
if (detail1 != null)
|
||
|
part.AbcClass = detail1.VALUE_NEUTRAL.Trim();
|
||
|
|
||
|
// ---关键控制号标识
|
||
|
detail1 = _part.zzchar.FirstOrDefault(p => p.CHARACT == "ZMM007");
|
||
|
if (detail1 != null)
|
||
|
part.PalletSize = detail1.VALUE_NEUTRAL.Trim();
|
||
|
|
||
|
//[DisplayName("配置信息")] 暂时作为位置信息使用--位置
|
||
|
detail1 = _part.zzchar.FirstOrDefault(p => p.CHARACT == "ZMM003");
|
||
|
if (detail1 != null)
|
||
|
part.Configuration = detail1.VALUE_NEUTRAL.Trim();
|
||
|
|
||
|
//[DisplayName("存储标包数")] --序列号管理
|
||
|
decimal stockPackQty = 1;
|
||
|
if (part.ManageType == 1)
|
||
|
{
|
||
|
part.StockPackQty = 1;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
detail1 = _part.zzchar.FirstOrDefault(p => p.CHARACT == "ZMM008");
|
||
|
if (detail1 == null)
|
||
|
{
|
||
|
part.StockPackQty = 1;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (decimal.TryParse(detail1.VALUE_NEUTRAL, out stockPackQty))
|
||
|
{
|
||
|
part.StockPackQty = stockPackQty;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
part.StockPackQty = 1;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//[DisplayName("收货口")]--交货工厂
|
||
|
part.ReceivePort = _part.DWERK.Trim();
|
||
|
|
||
|
//[DisplayName("备注")]--补充备注
|
||
|
part.Remark = _part.ZTEXT.Trim();
|
||
|
|
||
|
//[DisplayName("图号")] 物料组描述--物料组
|
||
|
part.DrawingNumber = _part.WGBEZ.Trim();
|
||
|
|
||
|
//[DisplayName("旧物料号")]--旧物料号
|
||
|
part.StoreKeeper = _part.BISMT.Trim();
|
||
|
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
var current = await _taPartRepository.FirstOrDefaultAsync(p => p.PartCode == part.PartCode);
|
||
|
if (current == null)
|
||
|
{
|
||
|
await _taPartRepository.UpsertAsync(part);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
bUpdate = true;
|
||
|
await _tmPgWmsUpdate.UpdateTaPartAsync(part);
|
||
|
}
|
||
|
//没有客户物料号就不管理 --客户物料号 ZTEXT22
|
||
|
string custPartCode = _part.ZTEXT22.Trim();
|
||
|
// 分销渠道
|
||
|
string custId = _part.VTWEG.Trim();
|
||
|
//判断有没有对应的CustP
|
||
|
//art信息,没有就新建,有就更新
|
||
|
var custpart = new TA_CUST_PART();
|
||
|
|
||
|
#region custpart信息更新
|
||
|
|
||
|
//[DisplayName("客户编号")]
|
||
|
custpart.CustId = custId;
|
||
|
|
||
|
//[DisplayName("客户物料号")]--客户物料号
|
||
|
custpart.CustPartCode = _part.ZTEXT22.Trim();
|
||
|
|
||
|
//[DisplayName("客户物料描述")]--补充备注
|
||
|
custpart.CustPartName = _part.ZTEXT.Trim();
|
||
|
|
||
|
//[DisplayName("物料号")]
|
||
|
custpart.PartCode = part.PartCode.Trim();
|
||
|
|
||
|
//[DisplayName("备注")]--分销渠道
|
||
|
custpart.Remark = _part.VTWEG.Trim();
|
||
|
#endregion
|
||
|
if (!string.IsNullOrEmpty(custPartCode))
|
||
|
{
|
||
|
//var curCustPart = await _taCustPartRepository.FirstOrDefaultAsync(p => p.CustId == custpart.CustId && p.PartCode == custpart.PartCode);
|
||
|
//if (curCustPart == null)
|
||
|
//{
|
||
|
// await _taCustPartRepository.UpsertAsync(custpart);
|
||
|
//}
|
||
|
//else
|
||
|
//{
|
||
|
// await _tmPgWmsUpdate.UpdateTaCustPartAsync(custpart);
|
||
|
//}
|
||
|
await _tmPgWmsUpdate.DeleteTaCustPartAsync(custpart);
|
||
|
await _taCustPartRepository.UpsertAsync(custpart);
|
||
|
|
||
|
}
|
||
|
else //删除对应客户物料
|
||
|
{
|
||
|
await _tmPgWmsUpdate.DeleteTaCustPartAsync(custpart);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
bErr = true;
|
||
|
result.MESSAGE = $"非WinWMS使用的物料号!{_part.MATNR.Trim()}";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
WmsWebApiPARTDTO partdto = new WmsWebApiPARTDTO()
|
||
|
{
|
||
|
MATNR = _part.MATNR,
|
||
|
MBRSH = _part.MBRSH,
|
||
|
MTART = _part.MTART,
|
||
|
WERKS = _part.WERKS,
|
||
|
VTWEG = _part.VTWEG,
|
||
|
MAKTX = _part.MAKTX,
|
||
|
MAKTX1 = _part.MAKTX1,
|
||
|
MEINS = _part.MEINS,
|
||
|
MATKL = _part.MATKL,
|
||
|
GROES = _part.GROES,
|
||
|
ZTEXT22 = _part.ZTEXT22,
|
||
|
DISGR = _part.DISGR,
|
||
|
JSON = content.ToString()
|
||
|
};
|
||
|
partdto.SetId(GuidGenerator);
|
||
|
if (bUpdate)
|
||
|
{
|
||
|
partdto.ITYPE = "更新";
|
||
|
}
|
||
|
if (bOtherWork)
|
||
|
{
|
||
|
partdto.ITYPE = "非长春工厂数据";
|
||
|
}
|
||
|
if(bErr)
|
||
|
{
|
||
|
partdto.ITYPE = result.MESSAGE;
|
||
|
}
|
||
|
await _partDtoRepository.AddAsync(partdto);
|
||
|
}
|
||
|
catch(Exception ex)
|
||
|
{
|
||
|
result.TYPE = 'E';
|
||
|
result.MESSAGE = ex.Message;
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
}
|