package com.zy.third.erp.task;
|
|
import com.core.common.Cools;
|
import com.core.common.DateUtils;
|
import com.core.common.SnowflakeIdWorker;
|
import com.core.exception.CoolException;
|
import com.zy.asrs.entity.DocType;
|
import com.zy.asrs.entity.Mat;
|
import com.zy.asrs.entity.Order;
|
import com.zy.asrs.entity.OrderDetl;
|
import com.zy.asrs.service.DocTypeService;
|
import com.zy.asrs.service.MatService;
|
import com.zy.asrs.service.OrderDetlService;
|
import com.zy.asrs.service.OrderService;
|
import com.zy.third.erp.entity.InDetTB;
|
import com.zy.third.erp.entity.InHedTB;
|
import com.zy.third.erp.entity.OutDetTB;
|
import com.zy.third.erp.entity.OutHedTB;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.Date;
|
import java.util.List;
|
|
@Slf4j
|
@Component
|
public class ERPInOrOutService {
|
|
|
@Autowired
|
private OrderService orderService;
|
|
@Autowired
|
private OrderDetlService orderDetlService;
|
|
|
@Autowired
|
private SnowflakeIdWorker snowflakeIdWorker;
|
|
|
@Autowired
|
private DocTypeService docTypeService;
|
|
|
@Autowired
|
private MatService matService;
|
|
|
/**
|
* @return
|
*/
|
@Transactional(rollbackFor = Throwable.class)
|
public boolean createInOrder(InHedTB inHedTB, List<InDetTB> inDetTBs) {
|
Order order = orderService.selectByNo(inHedTB.getBillNo());
|
// 如果单据不存在则添加;如果单据存在,作业中无法修改,反之则修改单据
|
if (!Cools.isEmpty(order)) {
|
if (order.getSettle() > 1L) {
|
throw new CoolException(inHedTB.getBillNo() + "正在出库,无法修改单据");
|
}
|
orderService.remove(order.getId());
|
}
|
DocType docType = docTypeService.selectOrAdd(inHedTB.getIoKindName(), inHedTB.getIoKindID(), Boolean.TRUE);
|
Date now = new Date();
|
// 单据主档
|
order = new Order(
|
String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空]
|
inHedTB.getBillNo(), // 订单编号
|
DateUtils.convert(inHedTB.getMakeDate()), // 单据日期
|
docType.getDocId(), // 单据类型
|
null, // 项目编号
|
null, //
|
null, // 调拨项目编号
|
null, // 初始票据号
|
null, // 票据号
|
inHedTB.getObjectId(), // 客户编号
|
inHedTB.getObjectName(), // 客户
|
null, // 联系方式
|
null, // 操作人员
|
null, // 合计金额
|
null, // 优惠率
|
null, // 优惠金额
|
null, // 销售或采购费用合计
|
null, // 实付金额
|
null, // 付款类型
|
null, // 业务员
|
null, // 结算天数
|
null, // 邮费支付类型
|
null, // 邮费
|
null, // 付款时间
|
null, // 发货时间
|
null, // 物流名称
|
null, // 物流单号
|
1L, // 订单状态
|
1, // 状态
|
9527L, // 添加人员
|
now, // 添加时间
|
9527L, // 修改人员
|
inHedTB.getMakeDate(), // 修改时间
|
inHedTB.getRemark() // 备注
|
);
|
order.setTemp1(inHedTB.getTemp1());
|
order.setTemp2(inHedTB.getTemp2());
|
order.setTemp3(inHedTB.getTemp3());
|
order.setWareId(inHedTB.getWareId());
|
order.setWareName(inHedTB.getWareName());
|
if (!orderService.insert(order)) {
|
throw new CoolException("生成单据主档失败,请联系管理员");
|
}
|
for (InDetTB outDetTB : inDetTBs) {
|
Mat mat = matService.selectByMatnr(outDetTB.getItemId());
|
if (Cools.isEmpty(mat)) {
|
throw new CoolException(outDetTB.getItemCode() + "编号商品检索失败,请先添加商品");
|
}
|
OrderDetl orderDetl = new OrderDetl();
|
orderDetl.sync(mat);
|
orderDetl.setOrderNo(outDetTB.getBillNo());
|
orderDetl.setOutOrderNo(outDetTB.getOrderNo());
|
orderDetl.setAutoId(outDetTB.getAutoId());
|
orderDetl.setLuHao(outDetTB.getLuHao());
|
orderDetl.setSpecs(outDetTB.getSPgNO());
|
orderDetl.setPacking(outDetTB.getPacking());
|
orderDetl.setWareId(outDetTB.getWareId());
|
orderDetl.setWareName(outDetTB.getWareName());
|
orderDetl.setBatch(outDetTB.getItemBatch());
|
orderDetl.setAnfme(outDetTB.getMainNum());
|
orderDetl.setINo(outDetTB.getINO());
|
orderDetl.setOrderId(order.getId());
|
orderDetl.setTemp1(outDetTB.getTemp1());
|
orderDetl.setTemp2(outDetTB.getTemp2());
|
orderDetl.setTemp3(outDetTB.getTemp3());
|
orderDetl.setOrderNo(order.getOrderNo());
|
orderDetl.setThreeCode(outDetTB.getDetId() + "");
|
orderDetl.setCreateBy(9527L);
|
orderDetl.setCreateTime(now);
|
orderDetl.setUpdateBy(9527L);
|
orderDetl.setUpdateTime(now);
|
orderDetl.setStatus(1);
|
orderDetl.setProType(outDetTB.getProtype());
|
orderDetl.setQty(0.0D);
|
orderDetl.setSPgNO(outDetTB.getSPgNO());
|
if (!orderDetlService.insert(orderDetl)) {
|
throw new CoolException("生成单据明细失败,请联系管理员");
|
}
|
}
|
return true;
|
}
|
|
|
/**
|
* @return
|
*/
|
@Transactional(rollbackFor = Throwable.class)
|
public boolean createOutOrder(OutHedTB inHedTB, List<OutDetTB> inDetTBs) {
|
Order order = orderService.selectByNo(inHedTB.getBillNo());
|
// 如果单据不存在则添加;如果单据存在,作业中无法修改,反之则修改单据
|
if (!Cools.isEmpty(order)) {
|
if (order.getSettle() > 1L) {
|
throw new CoolException(inHedTB.getBillNo() + "正在出库,无法修改单据");
|
}
|
orderService.remove(order.getId());
|
}
|
DocType docType = docTypeService.selectOrAdd(inHedTB.getIoKindName(),inHedTB.getIoKindID(), Boolean.FALSE);
|
Date now = new Date();
|
// 单据主档
|
order = new Order(
|
String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空]
|
inHedTB.getBillNo(), // 订单编号
|
DateUtils.convert(inHedTB.getBillDate()), // 单据日期
|
docType.getDocId(), // 单据类型
|
null, // 项目编号
|
null, //
|
null, // 调拨项目编号
|
null, // 初始票据号
|
null, // 票据号
|
inHedTB.getObjectId(), // 客户编号
|
inHedTB.getObjectName(), // 客户
|
null, // 联系方式
|
null, // 操作人员
|
null, // 合计金额
|
null, // 优惠率
|
null, // 优惠金额
|
null, // 销售或采购费用合计
|
null, // 实付金额
|
null, // 付款类型
|
null, // 业务员
|
null, // 结算天数
|
null, // 邮费支付类型
|
null, // 邮费
|
null, // 付款时间
|
null, // 发货时间
|
null, // 物流名称
|
null, // 物流单号
|
1L, // 订单状态
|
1, // 状态
|
9527L, // 添加人员
|
now, // 添加时间
|
9527L, // 修改人员
|
inHedTB.getMakeDate(), // 修改时间
|
inHedTB.getRemark() // 备注
|
);
|
order.setTemp1(inHedTB.getTemp1());
|
order.setTemp2(inHedTB.getTemp2());
|
order.setTemp3(inHedTB.getTemp3());
|
order.setWareId(inHedTB.getWareId());
|
order.setWareName(inHedTB.getWareName());
|
|
if (!orderService.insert(order)) {
|
throw new CoolException("生成单据主档失败,请联系管理员");
|
}
|
for (OutDetTB outDetTB : inDetTBs) {
|
Mat mat = matService.selectByMatnr(outDetTB.getItemId());
|
if (Cools.isEmpty(mat)) {
|
throw new CoolException(outDetTB.getItemCode() + "编号商品检索失败,请先添加商品");
|
}
|
OrderDetl orderDetl = new OrderDetl();
|
orderDetl.sync(mat);
|
orderDetl.setOrderNo(outDetTB.getBillNo());
|
orderDetl.setOutOrderNo(outDetTB.getOrderNo());
|
orderDetl.setAutoId(outDetTB.getAutoId());
|
orderDetl.setLuHao(outDetTB.getLuHao());
|
orderDetl.setSpecs(outDetTB.getSPgNO());
|
orderDetl.setPacking(outDetTB.getPacking());
|
orderDetl.setWareId(outDetTB.getWareId());
|
orderDetl.setWareName(outDetTB.getWareName());
|
orderDetl.setBatch(outDetTB.getItemBatch());
|
orderDetl.setAnfme(outDetTB.getMainNum());
|
orderDetl.setINo(outDetTB.getINO());
|
orderDetl.setOrderId(order.getId());
|
orderDetl.setTemp1(outDetTB.getTemp1());
|
orderDetl.setTemp2(outDetTB.getTemp2());
|
orderDetl.setTemp3(outDetTB.getTemp3());
|
orderDetl.setOrderNo(order.getOrderNo());
|
orderDetl.setThreeCode(outDetTB.getDetId() + "");
|
orderDetl.setCreateBy(9527L);
|
orderDetl.setCreateTime(now);
|
orderDetl.setUpdateBy(9527L);
|
orderDetl.setUpdateTime(now);
|
orderDetl.setStatus(1);
|
orderDetl.setQty(0.0D);
|
orderDetl.setProType(outDetTB.getProType());
|
orderDetl.setSPgNO(outDetTB.getSPgNO());
|
if (!orderDetlService.insert(orderDetl)) {
|
throw new CoolException("生成单据明细失败,请联系管理员");
|
}
|
}
|
return true;
|
}
|
}
|