package com.zy.asrs.task.handler;
|
|
import com.core.common.Cools;
|
import com.core.common.DateUtils;
|
import com.core.exception.CoolException;
|
import com.zy.asrs.entity.*;
|
import com.zy.asrs.service.*;
|
import com.zy.asrs.service.impl.OrderDetl1ServiceImpl;
|
import com.zy.asrs.task.AbstractHandler;
|
import com.zy.asrs.task.core.ReturnT;
|
import com.zy.third.entity.ExdInstockTarget;
|
import com.zy.third.entity.ExdOutstockTarget;
|
import com.zy.third.entity.ExdvYanbu;
|
import com.zy.third.mapper.ExdMaterialMapper;
|
import com.zy.third.service.ExdInstockTargetService;
|
import com.zy.third.service.ExdOutstockTargetService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.math.BigDecimal;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* Created by vincent on 2020/7/7
|
*/
|
@Slf4j
|
@Service
|
public class OrderSyncHandler extends AbstractHandler<String> {
|
|
|
@Autowired
|
private OrderService orderService;
|
@Autowired
|
private OrderDetlService orderDetlService;
|
@Autowired
|
private ApiLogService apiLogService;
|
@Autowired
|
private DocTypeService docTypeService;
|
|
@Autowired
|
private ExdInstockTargetService exdInstockTargetService;
|
|
@Autowired
|
private ExdOutstockTargetService exdOutstockTargetService;
|
@Autowired
|
private MatService matService;
|
@Autowired
|
private OrderDetl1ServiceImpl orderDetl1Service;
|
@Autowired
|
private ExdMaterialMapper exdMaterialMapper;
|
@Autowired
|
private Order1Service order1Service;
|
|
@Transactional
|
public ReturnT<String> start(Order order) {
|
DocType docType = docTypeService.selectById(order.getDocType());
|
if (null == docType) {
|
return SUCCESS;
|
}
|
List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId());
|
if (orderDetls.isEmpty()) {
|
return SUCCESS;
|
}
|
// 入库完成上报
|
if (docType.getPakin() == 1) {
|
ExdInstockTarget exdInstockTarge = null;
|
for (OrderDetl orderDetl : orderDetls) {
|
exdInstockTarge = new ExdInstockTarget();
|
exdInstockTarge.setFinterid(orderDetl.getDeadWarn());
|
exdInstockTarge.setFbillno(orderDetl.getOrderNo());
|
exdInstockTarge.setFtrantype(order.getDocType().intValue());
|
exdInstockTarge.setFdate(DateUtils.convert(order.getOrderTime()));
|
exdInstockTarge.setFrob(orderDetl.getInspect());
|
exdInstockTarge.setFuserid(Integer.getInteger(orderDetl.getColor()));
|
exdInstockTarge.setWritetime(new Date());
|
exdInstockTarge.setWritor("WMS");
|
exdInstockTarge.setStatus(0);
|
exdInstockTargetService.insert(exdInstockTarge);
|
}
|
if (!orderService.updateSettle(order.getId(), 6L, null)) {
|
throw new CoolException("服务器内部错误,请联系管理员");
|
}
|
} else if (docType.getPakout() == 1) {
|
// 出库完成上报
|
ExdOutstockTarget exdOutstockTarget = null;
|
for (OrderDetl orderDetl : orderDetls) {
|
exdOutstockTarget = new ExdOutstockTarget();
|
exdOutstockTarget.setFinterid(orderDetl.getDeadWarn());
|
exdOutstockTarget.setFbillno(orderDetl.getOrderNo());
|
if (order.getDocType() == 42) {
|
exdOutstockTarget.setFtrantype(41);
|
} else {
|
exdOutstockTarget.setFtrantype(order.getDocType().intValue());
|
}
|
exdOutstockTarget.setFdate(DateUtils.convert(order.getOrderTime()));
|
exdOutstockTarget.setFrob(orderDetl.getInspect());
|
exdOutstockTarget.setFuserid(Integer.getInteger(orderDetl.getColor()));
|
exdOutstockTarget.setWritetime(new Date());
|
exdOutstockTarget.setWritor("WMS");
|
exdOutstockTarget.setStatus(0);
|
exdOutstockTargetService.insert(exdOutstockTarget);
|
|
}
|
if (!orderService.updateSettle(order.getId(), 6L, null)) {
|
throw new CoolException("服务器内部错误,请联系管理员");
|
}
|
}
|
return SUCCESS;
|
}
|
|
@Transactional
|
public ReturnT<String> start1(Order1 order) {
|
DocType docType = docTypeService.selectById(order.getDocType());
|
if (null == docType) {
|
return FAIL;
|
}
|
List<OrderDetl1> orderDetls = orderDetl1Service.selectByOrderId(order.getId());
|
if (orderDetls.isEmpty()) {
|
return FAIL;
|
}
|
|
|
for (OrderDetl1 orderDetl : orderDetls) {
|
|
ExdvYanbu bacode = exdMaterialMapper.getBacode(orderDetl.getThreeCode());
|
//获取主表明细
|
OrderDetl orderDetl1 = orderDetlService.selectItem(orderDetl.getOrderNo(), orderDetl.getMatnr(), null);
|
//上报数量
|
BigDecimal anfme = new BigDecimal(orderDetl1.getAnfme());
|
BigDecimal Units = new BigDecimal((Cools.isEmpty(orderDetl1.getUnits()) ? 0.0 : orderDetl1.getUnits()));
|
BigDecimal result = anfme.subtract(Units);
|
double count = result.doubleValue();
|
|
// //剩余数量
|
// BigDecimal Anfme = new BigDecimal(orderDetl.getAnfme());
|
// BigDecimal subtract = Anfme.subtract(Qty);
|
|
|
// 出库完成上报
|
ExdOutstockTarget exdOutstockTarget = null;
|
exdOutstockTarget = new ExdOutstockTarget();
|
//订单内码
|
exdOutstockTarget.setFinterid(orderDetl.getDeadWarn());
|
//单号 = erp订单号+物料编号+上报次数
|
exdOutstockTarget.setFbillno(order.getOrderNo());
|
|
//部门ID
|
exdOutstockTarget.setFdeptid(7502);
|
//供应商/客户ID
|
exdOutstockTarget.setFsupplyid(0);
|
//制单用户ID
|
exdOutstockTarget.setFbillerid(Math.toIntExact(orderDetl.getUpdateBy()));
|
//细表ID
|
Integer c = Integer.valueOf(order.getOrderNo().split("-")[1]);
|
exdOutstockTarget.setFentryid(c);
|
//物料ID
|
Mat mat = matService.selectByMatnr(orderDetl.getMatnr());
|
exdOutstockTarget.setFitemid(Integer.valueOf(mat.getUuid()));
|
//源单数量
|
exdOutstockTarget.setFqtymust(count);
|
//出库数量
|
exdOutstockTarget.setFqty(orderDetl.getQty());
|
//单价
|
exdOutstockTarget.setFprice(0.0);
|
//批号 暂定
|
exdOutstockTarget.setFbatchno(orderDetl.getBatch());
|
//单位ID
|
exdOutstockTarget.setFunitid(0);
|
//源单号
|
exdOutstockTarget.setFsourcebillno(orderDetl.getOrderNo());
|
//源单细表ID 暂定
|
exdOutstockTarget.setFsourceentryid(0);
|
//源单内码 暂定
|
exdOutstockTarget.setFsourceinterid(0);
|
//源单单据类型
|
exdOutstockTarget.setFsourcetrantype(0);
|
//库位ID
|
exdOutstockTarget.setFdcspid(0);
|
//仓库ID 暂定
|
exdOutstockTarget.setFdcstockid(0);
|
//销售订单单号 暂定
|
exdOutstockTarget.setForderbillno(orderDetl.getOrderNo());
|
//销售订单细表ID 暂定
|
exdOutstockTarget.setForderentryid(0);
|
//销售订单内码 暂定
|
exdOutstockTarget.setForderinterid(0);
|
//计划模式
|
exdOutstockTarget.setFplanmode(0);
|
|
//单据类型
|
exdOutstockTarget.setFtrantype(21);
|
|
//单据日期
|
exdOutstockTarget.setFdate(DateUtils.convert(order.getOrderTime()));
|
//红蓝字
|
exdOutstockTarget.setFrob(orderDetl.getBeBatch());
|
//操作用户
|
exdOutstockTarget.setFuserid(Integer.getInteger(orderDetl.getColor()));
|
|
exdOutstockTarget.setBarcode(orderDetl.getBatch());
|
exdOutstockTarget.setGross(BigDecimal.valueOf(bacode.getGross()));
|
exdOutstockTarget.setWidth(BigDecimal.valueOf(bacode.getWidth()));
|
exdOutstockTarget.setDefects(BigDecimal.valueOf(bacode.getDefects()));
|
exdOutstockTarget.setBackcode(bacode.getBackcode());
|
exdOutstockTarget.setWritetime(new Date());
|
exdOutstockTarget.setWritor("WMS");
|
exdOutstockTarget.setStatus(0);
|
//
|
// //仓库
|
exdOutstockTarget.setProdinkind(bacode.getProdinkind());
|
|
//写入时间
|
exdOutstockTarget.setWritetime(new Date());
|
//写入者
|
exdOutstockTarget.setWritor("WMS");
|
//状态
|
exdOutstockTarget.setStatus(0);
|
if (exdOutstockTargetService.insert(exdOutstockTarget)) {
|
|
|
|
}
|
}
|
for (OrderDetl1 orderDetl : orderDetls) {
|
OrderDetl orderDetl1 = orderDetlService.selectItem(orderDetl.getOrderNo(), orderDetl.getMatnr(), null);
|
orderDetl1.setUnits(orderDetl.getAnfme() + (Cools.isEmpty(orderDetl.getUnits()) ? 0.0 : orderDetl.getUnits()));
|
orderDetl1.setUpdateTime(new Date());
|
orderDetl1Service.updateById(orderDetl);
|
}
|
return SUCCESS;
|
}
|
}
|
|
|
// @Transactional
|
// public ReturnT<String> start1(Order order, OrderDetl orderDetl) {
|
// DocType docType = docTypeService.selectById(order.getDocType());
|
// if (null == docType) {
|
// return SUCCESS;
|
// }
|
// List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId());
|
// if (orderDetls.isEmpty()) {
|
// return SUCCESS;
|
// }
|
//
|
//// ExdvYanbu bacode = exdMaterialMapper.getBacode(wrkDetl.getThreeCode());
|
//
|
// //上报数量
|
// BigDecimal Qty = new BigDecimal(orderDetl.getQty());
|
// BigDecimal Units = new BigDecimal((Cools.isEmpty(orderDetl.getUnits()) ? 0.0 : orderDetl.getUnits()));
|
// BigDecimal result = Qty.subtract(Units);
|
// double count = result.doubleValue();
|
//
|
// //剩余数量
|
// BigDecimal Anfme = new BigDecimal(orderDetl.getAnfme());
|
// BigDecimal subtract = Anfme.subtract(Qty);
|
//
|
//
|
// // 出库完成上报
|
// ExdOutstockTarget exdOutstockTarget = null;
|
// exdOutstockTarget = new ExdOutstockTarget();
|
// //订单内码
|
// exdOutstockTarget.setFinterid(orderDetl.getDeadWarn());
|
// //单号 = erp订单号+物料编号+上报次数
|
// exdOutstockTarget.setFbillno(orderDetl.getOrderNo() + "--" + orderDetl.getMatnr() + "--" + (Cools.isEmpty(orderDetl.getInspect()) ? 1 : (orderDetl.getInspect() + 1)));
|
//
|
// //部门ID
|
// exdOutstockTarget.setFdeptid(7502);
|
// //供应商/客户ID
|
// exdOutstockTarget.setFsupplyid(0);
|
// //制单用户ID
|
// exdOutstockTarget.setFbillerid(Math.toIntExact(orderDetl.getUpdateBy()));
|
// //细表ID
|
// exdOutstockTarget.setFentryid((Cools.isEmpty(orderDetl.getInspect()) ? 1 : (orderDetl.getInspect() + 1)));
|
// //物料ID
|
// Mat mat = matService.selectByMatnr(orderDetl.getMatnr());
|
// exdOutstockTarget.setFitemid(Integer.valueOf(mat.getUuid()));
|
// //源单数量
|
// exdOutstockTarget.setFqtymust(subtract.doubleValue());
|
// //出库数量
|
// exdOutstockTarget.setFqty(count);
|
// //单价
|
// exdOutstockTarget.setFprice(0.0);
|
// //批号 暂定
|
// exdOutstockTarget.setFbatchno(orderDetl.getBatch());
|
// //单位ID
|
// exdOutstockTarget.setFunitid(0);
|
// //源单号
|
// exdOutstockTarget.setFsourcebillno(orderDetl.getOrderNo());
|
// //源单细表ID 暂定
|
// exdOutstockTarget.setFsourceentryid(0);
|
// //源单内码 暂定
|
// exdOutstockTarget.setFsourceinterid(0);
|
// //源单单据类型
|
// exdOutstockTarget.setFsourcetrantype(0);
|
// //库位ID
|
// exdOutstockTarget.setFdcspid(0);
|
// //仓库ID 暂定
|
// exdOutstockTarget.setFdcstockid(0);
|
// //销售订单单号 暂定
|
// exdOutstockTarget.setForderbillno(orderDetl.getOrderNo());
|
// //销售订单细表ID 暂定
|
// exdOutstockTarget.setForderentryid(0);
|
// //销售订单内码 暂定
|
// exdOutstockTarget.setForderinterid(0);
|
// //计划模式
|
// exdOutstockTarget.setFplanmode(0);
|
//
|
// //单据类型
|
// exdOutstockTarget.setFtrantype(21);
|
//
|
// //单据日期
|
// exdOutstockTarget.setFdate(DateUtils.convert(order.getOrderTime()));
|
// //红蓝字
|
// exdOutstockTarget.setFrob(orderDetl.getBeBatch());
|
// //操作用户
|
// exdOutstockTarget.setFuserid(Integer.getInteger(orderDetl.getColor()));
|
//
|
//// exdOutstockTarget.setBarcode(wrkDetl.getBatch());
|
//// exdOutstockTarget.setGross(bacode.getGross());
|
//// exdOutstockTarget.setWidth(bacode.getWidth());
|
//// exdOutstockTarget.setDefects(bacode.getDefects());
|
//// exdOutstockTarget.setBackcode(bacode.getBackcode());
|
//// exdOutstockTarget.setWritetime(new Date());
|
//// exdOutstockTarget.setWritor("WMS");
|
//// exdOutstockTarget.setStatus(0);
|
////
|
//// //仓库
|
//// exdOutstockTarget.setProdinkind(bacode.getProdinkind());
|
//
|
// //写入时间
|
// exdOutstockTarget.setWritetime(new Date());
|
// //写入者
|
// exdOutstockTarget.setWritor("WMS");
|
// //状态
|
// exdOutstockTarget.setStatus(0);
|
// if (exdOutstockTargetService.insert(exdOutstockTarget)) {
|
// orderDetl.setInspect((Cools.isEmpty(orderDetl.getInspect()) ? 1 : (orderDetl.getInspect() + 1)));
|
// orderDetl.setUnits(count + (Cools.isEmpty(orderDetl.getUnits()) ? 0.0 : orderDetl.getUnits()));
|
// orderDetlService.updateById(orderDetl);
|
// }
|
//
|
// return SUCCESS;
|
// }
|