package com.zy.third.lk.task;
|
|
import com.alibaba.fastjson.JSON;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.core.common.Cools;
|
import com.core.common.DateUtils;
|
import com.core.exception.CoolException;
|
import com.zy.asrs.entity.DocType;
|
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.common.service.erp.ErpSqlServer;
|
import com.zy.third.lk.entity.*;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 入库更新完成回报
|
*/
|
@Slf4j
|
@Component
|
public class LKInTBScheduler {
|
|
@Autowired
|
private MatService matService;
|
|
@Autowired
|
private OrderService orderService;
|
|
@Autowired
|
private OrderDetlService orderDetlService;
|
|
@Autowired
|
private DocTypeService docTypeService;
|
|
@Autowired
|
private ErpSqlServer erpSqlServer;
|
|
@Transactional(rollbackFor = Throwable.class)
|
@Scheduled(cron = "${erp.refreshtime}")
|
public void pakinOrderComplete() {
|
//log.info("开始入库更新完成回报");
|
// 所有订单
|
List<Order> orders = orderService.selectList(new EntityWrapper<Order>().eq("settle", 4L));
|
DocType docType;
|
for (Order order : orders) {
|
|
docType = docTypeService.selectById(order.getDocType());
|
if (docType == null) {
|
log.error("该订单类型不存在:" + order.getDocType());
|
throw new CoolException("服务器内部错误,请联系管理员");
|
}
|
List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId());
|
if (docType.getPakin() == 1) {
|
//入库单
|
for (OrderDetl orderDetl : orderDetls) {
|
log.info("该入库单对象:" + orderDetl);
|
insertInDet(orderDetl);
|
}
|
insertInHed(order);
|
} else {
|
//出库单
|
for (OrderDetl orderDetl : orderDetls) {
|
log.info("该出库单对象:" + orderDetl);
|
insertOutDet(orderDetl);
|
}
|
insertOutHed(order);
|
}
|
// 修改订单状态 4.完成 ===>> 6.已上报
|
if (!orderService.updateSettle(order.getId(), 6L, null)) {
|
throw new CoolException("服务器内部错误,请联系管理员");
|
}
|
}
|
}
|
|
|
/**
|
* 将入库单的信息插入到ERP表
|
*
|
* @param orderDetl
|
* @return
|
*/
|
@Transactional(rollbackFor = Throwable.class)
|
public boolean insertInDet(OrderDetl orderDetl) {
|
String sqlInDetTb = "select * from lk_InDetTB where bill_no='" + orderDetl.getOrderNo() + "' and " + " item_id='" + orderDetl.getMatnr() + "' and item_batch='" + orderDetl.getBatch() + "' and pro_type='" + orderDetl.getSpecs() + "'";
|
List<InDetTB> inDets = erpSqlServer.select(sqlInDetTb, InDetTB.class);
|
String sqlInDetTbBak = "select * from lk_InDetTB_Bak where bill_no='" + orderDetl.getOrderNo() + "' and " + " item_id='" + orderDetl.getMatnr() + "' and item_batch='" + orderDetl.getBatch() + "' and pro_type='" + orderDetl.getSpecs() + "'";
|
List<InDetTBBak> inDetBaks = erpSqlServer.select(sqlInDetTbBak, InDetTBBak.class);
|
if (!inDets.isEmpty() || !inDetBaks.isEmpty()) {
|
log.error("该单号料号中间表表身已存在:" + orderDetl.getOrderNo() + "==>>" + orderDetl.getOrderNo());
|
return true;
|
}
|
Map<String, Object> content = getMap(orderDetl);
|
int insert = erpSqlServer.insert(InDetTB.class, content);
|
|
if (insert == 1) {
|
log.info("入库单表身回传成功:{}", content);
|
return true;
|
} else {
|
log.error("入库回传失败,实体类打印:{}", content);
|
throw new CoolException("服务器内部错误,请联系管理员");
|
}
|
|
}
|
|
/**
|
* 将入库单的详情信息插入到ERP表
|
*
|
* @param order
|
* @return
|
*/
|
@Transactional(rollbackFor = Throwable.class)
|
public boolean insertInHed(Order order) {
|
String sqlInHedTb = "select * from lk_InHedTB where LKName='高霖立库' and bill_no='" + order.getOrderNo() + "'";
|
List<InHedTB> outHeds = erpSqlServer.select(sqlInHedTb, InHedTB.class);
|
String sqlInHedTbBak = "select * from lk_InHedTB_Bak where LKName='高霖立库' and bill_no='" + order.getOrderNo() + "'";
|
List<InHedTBBak> inHedBaks = erpSqlServer.select(sqlInHedTbBak, InHedTBBak.class);
|
if (!outHeds.isEmpty() || !inHedBaks.isEmpty()) {
|
log.error("该单号料号中间表表头已存在:" + order.getOrderNo());
|
return true;
|
}
|
DocType docType = docTypeService.selectById(order.getDocType());
|
HashMap<String, Object> content = new HashMap<>();
|
content.put("bill_no", "'" + order.getOrderNo() + "'");
|
content.put("bill_date", "'" + DateUtils.convert(new Date()) + "'");
|
if (!Cools.isEmpty(docType.getDocCode())) content.put("io_kind_id", "'" + docType.getDocCode() + "'");
|
if (!Cools.isEmpty(docType.getDocName())) content.put("io_kind_name", "'" + docType.getDocName() + "'");
|
if (!Cools.isEmpty(order.getWareId())) content.put("ware_id", "'" + order.getWareId() + "'");
|
if (!Cools.isEmpty(order.getWareName())) content.put("ware_name", "'" + order.getWareName() + "'");
|
if (!Cools.isEmpty(order.getTemp1())) content.put("temp1", "'" + order.getTemp1() + "'");
|
if (!Cools.isEmpty(order.getTemp2())) content.put("temp2", "'" + order.getTemp2() + "'");
|
if (!Cools.isEmpty(order.getTemp3())) content.put("temp3", "'" + order.getTemp3() + "'");
|
if (!Cools.isEmpty(order.getCstmr())) content.put("object_id", "'" + order.getCstmr() + "'");
|
if (!Cools.isEmpty(order.getCstmrName())) content.put("object_name", "'" + order.getCstmrName() + "'");
|
if (!Cools.isEmpty(order.getMemo())) content.put("remark", "'" + order.getMemo() + "'");
|
content.put("LKName", "'高霖立库'");
|
content.put("b_pass", "1");
|
int insert = erpSqlServer.insert(InHedTB.class, content);
|
if (insert == 1) {
|
log.info("入库单表头回传成功:" + content);
|
return true;
|
} else {
|
log.error("入库单表头回传失败:" + content);
|
throw new CoolException("服务器内部错误,请联系管理员");
|
}
|
}
|
|
/**
|
* 将入库单的信息插入到ERP表
|
*
|
* @param orderDetl
|
* @return
|
*/
|
@Transactional(rollbackFor = Throwable.class)
|
public boolean insertOutDet(OrderDetl orderDetl) {
|
String sqlInDetTb = "select * from lk_OutDetTB where bill_no='" + orderDetl.getOrderNo() + "' and " + " item_id='" + orderDetl.getMatnr() + "' and item_batch='" + orderDetl.getBatch() + "' and pro_type='" + orderDetl.getSpecs() + "'";
|
List<OutDetTB> inDets = erpSqlServer.select(sqlInDetTb, OutDetTB.class);
|
String sqlInDetTbBak = "select * from lk_OutDetTB_Bak where bill_no='" + orderDetl.getOrderNo() + "' and " + " item_id='" + orderDetl.getMatnr() + "' and item_batch='" + orderDetl.getBatch() + "' and pro_type='" + orderDetl.getSpecs() + "'";
|
List<OutDetTBBak> inDetBaks = erpSqlServer.select(sqlInDetTbBak, OutDetTBBak.class);
|
if (!inDets.isEmpty() || !inDetBaks.isEmpty()) {
|
log.error("该单号料号中间表表身已存在:" + orderDetl.getOrderNo() + "==>>" + orderDetl.getOrderNo());
|
return true;
|
}
|
Map<String, Object> content = getMap(orderDetl);
|
int insert = erpSqlServer.insert(OutDetTB.class, content);
|
|
if (insert == 1) {
|
log.info("入库单表身回传成功:" + content.toString());
|
return true;
|
} else {
|
log.error("入库回传失败,实体类打印:" + content.toString());
|
throw new CoolException("服务器内部错误,请联系管理员");
|
}
|
|
}
|
|
/**
|
* 将入库单的详情信息插入到ERP表
|
*
|
* @param order
|
* @return
|
*/
|
@Transactional(rollbackFor = Throwable.class)
|
public boolean insertOutHed(Order order) {
|
String sqlInHedTb = "select * from lk_OutHedTB where LKName='高霖立库' and bill_no='" + order.getOrderNo() + "'";
|
List<OutHedTB> outHeds = erpSqlServer.select(sqlInHedTb, OutHedTB.class);
|
String sqlInHedTbBak = "select * from lk_OutHedTB_Bak where LKName='高霖立库' and bill_no='" + order.getOrderNo() + "'";
|
List<OutHedTBBak> inHedBaks = erpSqlServer.select(sqlInHedTbBak, OutHedTBBak.class);
|
if (!outHeds.isEmpty() || !inHedBaks.isEmpty()) {
|
log.error("该单号料号中间表表头已存在:" + order.getOrderNo());
|
return true;
|
}
|
DocType docType = docTypeService.selectById(order.getDocType());
|
HashMap<String, Object> content = new HashMap<>();
|
content.put("bill_no", "'" + order.getOrderNo() + "'");
|
content.put("bill_no", "'" + DateUtils.convert(new Date()) + "'");
|
if (!Cools.isEmpty(docType.getDocCode())) content.put("io_kind_id", "'" + docType.getDocCode() + "'");
|
if (!Cools.isEmpty(docType.getDocName())) content.put("io_kind_name", "'" + docType.getDocName() + "'");
|
if (!Cools.isEmpty(order.getWareId())) content.put("ware_id", "'" + order.getWareId() + "'");
|
if (!Cools.isEmpty(order.getWareName())) content.put("ware_name", "'" + order.getWareName() + "'");
|
if (!Cools.isEmpty(order.getUpdateTime())) content.put("make_date", "'" + order.getUpdateTime() + "'");
|
if (!Cools.isEmpty(order.getTemp1())) content.put("temp1", "'" + order.getTemp1() + "'");
|
if (!Cools.isEmpty(order.getTemp2())) content.put("temp2", "'" + order.getTemp2() + "'");
|
if (!Cools.isEmpty(order.getTemp3())) content.put("temp3", "'" + order.getTemp3() + "'");
|
if (!Cools.isEmpty(order.getCstmr())) content.put("object_id", "'" + order.getCstmr() + "'");
|
if (!Cools.isEmpty(order.getCstmrName())) content.put("object_name", "'" + order.getCstmrName() + "'");
|
if (!Cools.isEmpty(order.getMemo())) content.put("remark", "'" + order.getMemo() + "'");
|
content.put("LKName", "'高霖立库'");
|
content.put("b_pass", "1");
|
int insert = erpSqlServer.insert(OutHedTB.class, content);
|
if (insert == 1) {
|
log.info("入库单表头回传成功:" + content);
|
return true;
|
} else {
|
log.error("入库单表头回传失败:" + content);
|
throw new CoolException("服务器内部错误,请联系管理员");
|
}
|
}
|
|
private Map<String, Object> getMap(OrderDetl orderDetl) {
|
Map<String, Object> content = new HashMap<>();
|
if (!Cools.isEmpty(orderDetl.getOrderNo())) content.put("bill_no", "'" + orderDetl.getOrderNo() + "'");
|
if (!Cools.isEmpty(orderDetl.getINo())) content.put("i_no", "'" + orderDetl.getINo() + "'");
|
if (!Cools.isEmpty(orderDetl.getThreeCode())) content.put("det_id", orderDetl.getThreeCode());
|
if (!Cools.isEmpty(orderDetl.getMatnr())) content.put("item_id", "'" + orderDetl.getMatnr() + "'");
|
if (!Cools.isEmpty(orderDetl.getModel())) content.put("item_code", "'" + orderDetl.getModel() + "'");
|
if (!Cools.isEmpty(orderDetl.getBatch())) content.put("item_batch", "'" + orderDetl.getBatch() + "'");
|
if (!Cools.isEmpty(orderDetl.getProType())) content.put("pro_type", "'" + orderDetl.getProType() + "'");
|
if (!Cools.isEmpty(orderDetl.getUpdateTime())) content.put("make_date", "'" + orderDetl.getUpdateTime() + "'");
|
if (!Cools.isEmpty(orderDetl.getMemo())) content.put("remark", "'" + orderDetl.getMemo() + "'");
|
if (!Cools.isEmpty(orderDetl.getOutOrderNo())) content.put("order_no", "'" + orderDetl.getOutOrderNo() + "'");
|
if (!Cools.isEmpty(orderDetl.getQty())) {
|
if (orderDetl.getQty() > orderDetl.getAnfme() && orderDetl.getQty() > orderDetl.getWorkQty()) {
|
log.info("修正错误数量:{}", JSON.toJSON(orderDetl));
|
content.put("main_num", orderDetl.getWorkQty());
|
} else {
|
content.put("main_num", orderDetl.getQty());
|
}
|
}
|
if (!Cools.isEmpty(orderDetl.getWareId())) content.put("ware_id", "'" + orderDetl.getWareId() + "'");
|
if (!Cools.isEmpty(orderDetl.getWareName())) content.put("ware_name", "'" + orderDetl.getWareName() + "'");
|
if (!Cools.isEmpty(orderDetl.getPacking())) content.put("packing", "'" + orderDetl.getPacking() + "'");
|
// if (!Cools.isEmpty(orderDetl.getLuHao())) content.put("LuHao", "'" + orderDetl.getLuHao() + "'");
|
if (!Cools.isEmpty(orderDetl.getSPgNO())) content.put("s_pg_no", "'" + orderDetl.getSPgNO() + "'");
|
if (!Cools.isEmpty(orderDetl.getTemp1())) content.put("temp1", "'" + orderDetl.getTemp1() + "'");
|
if (!Cools.isEmpty(orderDetl.getTemp2())) content.put("temp2", "'" + orderDetl.getTemp2() + "'");
|
if (!Cools.isEmpty(orderDetl.getTemp3())) content.put("temp3", "'" + orderDetl.getTemp3() + "'");
|
content.put("LKName", "'高霖立库'");
|
return content;
|
}
|
|
|
}
|