From f0bfe3ba02dda63d4e557647baac6ac263bcb115 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期二, 10 八月 2021 14:13:31 +0800
Subject: [PATCH] #
---
src/main/java/zy/cloud/wms/common/service/erp/ErpScheduler.java | 866 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 841 insertions(+), 25 deletions(-)
diff --git a/src/main/java/zy/cloud/wms/common/service/erp/ErpScheduler.java b/src/main/java/zy/cloud/wms/common/service/erp/ErpScheduler.java
index 918919a..f1ba192 100644
--- a/src/main/java/zy/cloud/wms/common/service/erp/ErpScheduler.java
+++ b/src/main/java/zy/cloud/wms/common/service/erp/ErpScheduler.java
@@ -1,20 +1,30 @@
package zy.cloud.wms.common.service.erp;
import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
+import com.core.common.DateUtils;
+import com.core.common.SnowflakeIdWorker;
+import com.core.exception.CoolException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
-import zy.cloud.wms.common.service.MainService;
-import zy.cloud.wms.common.service.erp.entity.GetDataResult;
-import zy.cloud.wms.manager.entity.Mat;
-import zy.cloud.wms.manager.service.MatService;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+import zy.cloud.wms.common.entity.Parameter;
+import zy.cloud.wms.common.service.erp.entity.*;
+import zy.cloud.wms.common.utils.VersionUtils;
+import zy.cloud.wms.manager.entity.*;
+import zy.cloud.wms.manager.mapper.TagMapper;
+import zy.cloud.wms.manager.service.*;
import zy.cloud.wms.manager.utils.HttpHandler;
+import zy.cloud.wms.manager.utils.NodeUtils;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Collectors;
/**
* erp浠诲姟鎺у埗鍣�
@@ -22,49 +32,855 @@
*/
@Slf4j
@Component
+@RestController
public class ErpScheduler {
- public static final String URI = "http://8.133.182.21:8080/api/";
+ public static final String URI = "http://123.60.34.127:6220/api";
public static final String GET_ORDERS = "cM/basis/getOrders";
+ public static final String GET_BASIS = "cM/basis/getBasis";
+ public static final String UPLOAD_BILL = "cM/basis/uploadBill";
+ public static final String UPLOAD_STOCK = "cM/basis/uploadStock";
+ public static final String OVER_BILL = "cM/basis/OverBill";
+ public static final String UPLOAD_CANCEL_RESULT = "cM/basis/cancelOrders";
@Autowired
private MatService matService;
@Autowired
- private MainService mainService;
+ private CstmrService cstmrService;
+ @Autowired
+ private LocDetlService locDetlService;
+ @Autowired
+ private TagService tagService;
+ @Autowired
+ private TagMapper tagMapper;
+ @Autowired
+ private OrderService orderService;
+ @Autowired
+ private OrderDetlService orderDetlService;
+ @Autowired
+ private SnowflakeIdWorker snowflakeIdWorker;
+ @Autowired
+ private PakoutService pakoutService;
+ @Autowired
+ private NodeService nodeService;
+ @Autowired
+ private DocLogService docLogService;
+ @Autowired
+ private RequestLogService requestLogService;
/**
- * 鍘熸潗鏂�
+ * 鍟嗗搧涓嬭浇
*/
-// @Scheduled(cron = "0/3 * * * * ? ")
+ // @Scheduled(cron = "0/5 * * * * ? ")
+ @GetMapping("/test1")
+// @PostConstruct
+ public void getBasis1Execute(){
+ try {
+ Map<String, Object> param = new HashMap<>();
+ param.put("rec", 0);
+ param.put("Flag", 1);
+ String response = new HttpHandler.Builder()
+ .setUri(URI)
+ .setPath(GET_BASIS)
+ .setJson(JSON.toJSONString(param))
+ .build()
+ .doPost();
+ if (!Cools.isEmpty(response)) {
+ log.info(response);
+ Date now = new Date();
+ Result result = JSON.parseObject(response, Result.class);
+ if (result.getCode() != 1) {
+ return;
+ }
+ List<GetBasisResult> list = JSON.parseArray(result.getData(), GetBasisResult.class);
+ Tag first = null;
+ for (GetBasisResult data : list) {
+ Mat mat = matService.selectByMatnr(data.getUserCode());
+ String modifyDate = data.getModifyDate();
+ Date updateTime = null;
+ if (!Cools.isEmpty(modifyDate)) {
+ updateTime = DateUtils.convert(data.getModifyDate());
+ }
+
+ // 鍒嗙被
+ Tag second = tagService.selectOne(new EntityWrapper<Tag>().eq("name", data.getYjfl()).eq("level", 2));
+ if (second == null) {
+ if (first == null) {
+ first = tagService.selectOne(new EntityWrapper<Tag>().eq("level", 1));
+ if (first == null) {
+ throw new CoolException("鍏ㄩ儴鍒嗙被鍑洪敊");
+ }
+ }
+ NodeUtils nodeUtils = new NodeUtils();
+ nodeUtils.executePath(first.getId());
+ second = new Tag(
+ null, // 缂栧彿
+ data.getYjfl(), // 鍚嶇О
+ first.getId(), // 鐖剁骇
+ first.getName(), // 鐖剁骇鍚嶇О
+ nodeUtils.path.toString(), // 鍏宠仈璺緞
+ nodeUtils.pathName.toString(), // 鍏宠仈璺緞鍚�
+ 0, // 绫诲瀷
+ null, // 璐熻矗浜�
+ null, // 鍥剧墖
+ null, // 绠�瑕佹弿杩�
+ null, // 鏁伴噺
+ 2, // 绛夌骇
+ null, // 鎺掑簭
+ 1, // 鐘舵��
+ now, // 娣诲姞鏃堕棿
+ null, // 娣诲姞浜哄憳
+ now, // 淇敼鏃堕棿
+ null, // 淇敼浜哄憳
+ null // 澶囨敞
+ );
+ if (tagMapper.insert(second) == 0) {
+ throw new CoolException("鎻掑叆鍒嗙被澶辫触");
+ }
+ }
+
+ Tag third = tagService.selectOne(new EntityWrapper<Tag>().eq("level", 3).eq("name", data.getEjfl()).eq("parent_name", data.getYjfl()));
+ if (third == null) {
+ NodeUtils nodeUtils = new NodeUtils();
+ nodeUtils.executePath(second.getId());
+ third = new Tag(
+ null, // 缂栧彿
+ data.getEjfl(), // 鍚嶇О
+ second.getId(), // 鐖剁骇
+ second.getName(), // 鐖剁骇鍚嶇О
+ nodeUtils.path.toString(), // 鍏宠仈璺緞
+ nodeUtils.pathName.toString(), // 鍏宠仈璺緞鍚�
+ 0, // 绫诲瀷
+ null, // 璐熻矗浜�
+ null, // 鍥剧墖
+ null, // 绠�瑕佹弿杩�
+ null, // 鏁伴噺
+ 3, // 绛夌骇
+ null, // 鎺掑簭
+ 1, // 鐘舵��
+ now, // 娣诲姞鏃堕棿
+ null, // 娣诲姞浜哄憳
+ now, // 淇敼鏃堕棿
+ null, // 淇敼浜哄憳
+ null // 澶囨敞
+ );
+ if (tagMapper.insert(third) == 0) {
+ throw new CoolException("鎻掑叆鍒嗙被澶辫触");
+ }
+ }
+
+ if (null == mat) {
+ mat = new Mat(
+ String.valueOf(data.getRec()), // 缂栧彿
+ null, // 鎵�灞炲尯鍩�
+ third.getId(), // 鎵�灞炲綊绫�
+ data.getUserCode(), // 鍟嗗搧缂栧彿
+ data.getFullName(), // 鍟嗗搧鍚嶇О
+ null, // 鍚嶇О
+ data.getStandard(), // 瑙勬牸
+ null, // 鍨嬪彿
+ null, // 鎵瑰彿
+ data.getUnit3(), // 鍗曚綅
+ data.getBarcode(), // 鏉$爜
+ null, // 鍗曟嵁绫诲瀷
+ null, // 鍗曟嵁缂栧彿
+ null, // 瀹㈡埛鍚嶇О
+ null, // 鍝侀」鏁�
+ null, // 搴撳瓨浣欓噺
+ null, // 閲嶉噺
+ 1, //
+ null, // 娣诲姞浜哄憳
+ now, // 娣诲姞鏃堕棿
+ null, // 淇敼浜哄憳
+ updateTime, // 淇敼鏃堕棿
+ null // 澶囨敞
+ );
+ matService.insert(mat);
+ } else {
+ mat.setUuid(String.valueOf(data.getRec()));
+ mat.setMatnr(data.getUserCode());
+ mat.setMaktx(data.getFullName());
+ mat.setSpecs(data.getStandard());
+ mat.setUpdateTime(updateTime);
+ mat.setBarcode(data.getBarcode());
+ mat.setUnit(data.getUnit3());
+ matService.updateById(mat);
+ }
+ log.info("====>> 鏇存柊鐗╂枡锛歿}", data.getUserCode());
+ }
+
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ /**
+ * 鍟嗗搧涓嬭浇
+ */
+ @Scheduled(cron = "0 */2 * * * ? ")
+ public void updateMatExecute(){
+ try {
+ Map<String, Object> param = new HashMap<>();
+ param.put("Flag", 6);
+ String response = new HttpHandler.Builder()
+ .setUri(URI)
+ .setPath(GET_BASIS)
+ .setJson(JSON.toJSONString(param))
+ .build()
+ .doPost();
+ if (!Cools.isEmpty(response)) {
+// log.info(response);
+ Date now = new Date();
+ Result result = JSON.parseObject(response, Result.class);
+ if (result.getCode() != 1) {
+ return;
+ }
+ List<GetBasisResult> list = JSON.parseArray(result.getData(), GetBasisResult.class);
+ Tag first = null;
+ for (GetBasisResult data : list) {
+ Mat mat = matService.selectByMatnr(data.getUserCode());
+ String modifyDate = data.getModifyDate();
+ Date updateTime = null;
+ if (!Cools.isEmpty(modifyDate)) {
+ updateTime = DateUtils.convert(data.getModifyDate());
+ }
+
+ // 鍒嗙被
+ Tag second = tagService.selectOne(new EntityWrapper<Tag>().eq("name", data.getYjfl()).eq("level", 2));
+ if (second == null) {
+ if (first == null) {
+ first = tagService.selectOne(new EntityWrapper<Tag>().eq("level", 1));
+ if (first == null) {
+ throw new CoolException("鍏ㄩ儴鍒嗙被鍑洪敊");
+ }
+ }
+ NodeUtils nodeUtils = new NodeUtils();
+ nodeUtils.executePath(first.getId());
+ second = new Tag(
+ null, // 缂栧彿
+ data.getYjfl(), // 鍚嶇О
+ first.getId(), // 鐖剁骇
+ first.getName(), // 鐖剁骇鍚嶇О
+ nodeUtils.path.toString(), // 鍏宠仈璺緞
+ nodeUtils.pathName.toString(), // 鍏宠仈璺緞鍚�
+ 0, // 绫诲瀷
+ null, // 璐熻矗浜�
+ null, // 鍥剧墖
+ null, // 绠�瑕佹弿杩�
+ null, // 鏁伴噺
+ 2, // 绛夌骇
+ null, // 鎺掑簭
+ 1, // 鐘舵��
+ now, // 娣诲姞鏃堕棿
+ null, // 娣诲姞浜哄憳
+ now, // 淇敼鏃堕棿
+ null, // 淇敼浜哄憳
+ null // 澶囨敞
+ );
+ if (tagMapper.insert(second) == 0) {
+ throw new CoolException("鎻掑叆鍒嗙被澶辫触");
+ }
+ }
+
+ Tag third = tagService.selectOne(new EntityWrapper<Tag>().eq("level", 3).eq("name", data.getEjfl()).eq("parent_name", data.getYjfl()));
+ if (third == null) {
+ NodeUtils nodeUtils = new NodeUtils();
+ nodeUtils.executePath(second.getId());
+ third = new Tag(
+ null, // 缂栧彿
+ data.getEjfl(), // 鍚嶇О
+ second.getId(), // 鐖剁骇
+ second.getName(), // 鐖剁骇鍚嶇О
+ nodeUtils.path.toString(), // 鍏宠仈璺緞
+ nodeUtils.pathName.toString(), // 鍏宠仈璺緞鍚�
+ 0, // 绫诲瀷
+ null, // 璐熻矗浜�
+ null, // 鍥剧墖
+ null, // 绠�瑕佹弿杩�
+ null, // 鏁伴噺
+ 3, // 绛夌骇
+ null, // 鎺掑簭
+ 1, // 鐘舵��
+ now, // 娣诲姞鏃堕棿
+ null, // 娣诲姞浜哄憳
+ now, // 淇敼鏃堕棿
+ null, // 淇敼浜哄憳
+ null // 澶囨敞
+ );
+ if (tagMapper.insert(third) == 0) {
+ throw new CoolException("鎻掑叆鍒嗙被澶辫触");
+ }
+ }
+
+ if (null == mat) {
+ mat = new Mat(
+ String.valueOf(data.getRec()), // 缂栧彿
+ null, // 鎵�灞炲尯鍩�
+ third.getId(), // 鎵�灞炲綊绫�
+ data.getUserCode(), // 鍟嗗搧缂栧彿
+ data.getFullName(), // 鍟嗗搧鍚嶇О
+ null, // 鍚嶇О
+ data.getStandard(), // 瑙勬牸
+ null, // 鍨嬪彿
+ null, // 鎵瑰彿
+ data.getUnit3(), // 鍗曚綅
+ data.getBarcode(), // 鏉$爜
+ null, // 鍗曟嵁绫诲瀷
+ null, // 鍗曟嵁缂栧彿
+ null, // 瀹㈡埛鍚嶇О
+ null, // 鍝侀」鏁�
+ null, // 搴撳瓨浣欓噺
+ null, // 閲嶉噺
+ 1, //
+ null, // 娣诲姞浜哄憳
+ now, // 娣诲姞鏃堕棿
+ null, // 淇敼浜哄憳
+ updateTime, // 淇敼鏃堕棿
+ null // 澶囨敞
+ );
+ matService.insert(mat);
+ } else {
+ mat.setUuid(String.valueOf(data.getRec()));
+ mat.setMatnr(data.getUserCode());
+ mat.setMaktx(data.getFullName());
+ mat.setSpecs(data.getStandard());
+ mat.setUpdateTime(updateTime);
+ mat.setBarcode(data.getBarcode());
+ mat.setUnit(data.getUnit3());
+ matService.updateById(mat);
+ }
+ log.info("====>> 鏇存柊鐗╂枡锛歿}", data.getUserCode());
+ }
+
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ /**
+ * 瀹㈡埛涓嬭浇
+ */
+ // @Scheduled(cron = "0/5 * * * * ? ")
+// @PostConstruct
+ public void getBasis2Execute(){
+ try {
+ Map<String, Object> param = new HashMap<>();
+ param.put("rec", 0);
+ param.put("Flag", 2);
+ String response = new HttpHandler.Builder()
+ .setUri(URI)
+ .setPath(GET_BASIS)
+ .setJson(JSON.toJSONString(param))
+ .build()
+ .doPost();
+ if (!Cools.isEmpty(response)) {
+ log.info(response);
+ Date now = new Date();
+ Result result = JSON.parseObject(response, Result.class);
+ if (result.getCode() != 1) {
+ return;
+ }
+ List<GetBasisResult> list = JSON.parseArray(result.getData(), GetBasisResult.class);
+ for (GetBasisResult data : list) {
+ Cstmr cstmr = cstmrService.selectOne(new EntityWrapper<Cstmr>().eq("uuid", data.getUserCode()));
+ String modifyDate = data.getModifyDate();
+ Date updateTime = null;
+ if (!Cools.isEmpty(modifyDate)) {
+ updateTime = DateUtils.convert(data.getModifyDate());
+ }
+ if (null == cstmr) {
+ cstmr = new Cstmr(
+ data.getUserCode(), // 瀹㈡埛缂栧彿[闈炵┖]
+ data.getFullName(), // 瀹㈡埛鍚嶇О
+ null, // 鑱旂郴浜�
+ null, // 鑱旂郴鐢佃瘽
+ null, // 鑱旂郴鍦板潃
+ 1, // 鐘舵��
+ null, // 娣诲姞浜哄憳
+ now, // 娣诲姞鏃堕棿
+ null, // 淇敼浜哄憳
+ updateTime, // 淇敼鏃堕棿
+ String.valueOf(data.getRec()) // 澶囨敞
+ );
+ cstmrService.insert(cstmr);
+ } else {
+ cstmr.setUuid(data.getUserCode());
+ cstmr.setName(data.getFullName());
+ cstmr.setUpdateTime(updateTime);
+ cstmr.setMemo(String.valueOf(data.getRec()));
+ cstmrService.updateById(cstmr);
+ }
+ log.info("====>> 鏇存柊瀹㈡埛璧勬枡锛歿}", data.getUserCode());
+ }
+
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ /**
+ * 鎸佷箙鍖栭攢鍞鍗�
+ */
+ @Scheduled(cron = "0 */1 * * * ?")
+ @Transactional
+// @PostConstruct
public void getOrdersExecute(){
try {
Map<String, Object> json = new HashMap<>();
- json.put("vchType", 41);
+ json.put("vchType", 11);
String response = new HttpHandler.Builder()
.setUri(URI)
.setPath(GET_ORDERS)
.setJson(JSON.toJSONString(json))
.build()
.doPost();
- if (Cools.isEmpty(response)) {
- log.error("璇锋眰锛歿}\nError锛屽搷搴旂粨鏋滀负绌�!", URI + GET_ORDERS);
- } else {
- log.info(response);
+ if (!Cools.isEmpty(response)) {
+// log.info(response);
+ Date now = new Date();
Result result = JSON.parseObject(response, Result.class);
- List<GetDataResult> datas = JSON.parseArray(result.getData(), GetDataResult.class);
- if (!Cools.isEmpty(datas)) {
- for (GetDataResult data : datas) {
- // 鐢熸垚鍑哄簱鍗�
- Mat mat = matService.selectByMatnr(data.getUserCode());
- mainService.stockOutProcess();
-
-
- }
+ if (result.getCode() != 1) {
+ return;
}
+ List<GetOrderResult0> list = JSON.parseArray(result.getData(), GetOrderResult0.class);
+ if (!Cools.isEmpty(list)) {
+ boolean complete = true;
+ Set<String> existNumbers = new HashSet<>();
+ for (GetOrderResult0 data : list) {
+ if (orderService.selectByOrderNo(data.getNumber()) != null) {
+ existNumbers.add(data.getNumber());
+ continue;
+ }
+ Cstmr cstmr = cstmrService.selectByUuid(data.getBTypeID());
+ Order order = new Order(
+ String.valueOf(snowflakeIdWorker.nextId()), // 缂栧彿[闈炵┖]
+ data.getNumber(), // 璁㈠崟缂栧彿
+ data.getBillDate(), // 鍗曟嵁鏃ユ湡
+ 11L, // 鍗曟嵁绫诲瀷
+ null, // 椤圭洰缂栧彿
+ null, // 椤圭洰鍚嶇О
+ null, // 璋冩嫧椤圭洰缂栧彿
+ null, // 鍒濆绁ㄦ嵁鍙�
+ String.valueOf(data.getVchcode()), // 绁ㄦ嵁鍙�
+ null, // 瀹㈡埛缂栧彿
+ cstmr==null?data.getBTypeID():cstmr.getName(), // 瀹㈡埛
+ data.getBTypeID(), // 鑱旂郴鏂瑰紡 *
+ null, // 鎿嶄綔浜哄憳
+ null, // 鍚堣閲戦
+ null, // 浼樻儬鐜�
+ null, // 浼樻儬閲戦
+ null, // 閿�鍞垨閲囪喘璐圭敤鍚堣
+ null, // 瀹炰粯閲戦
+ null, // 浠樻绫诲瀷
+ data.getETypeID(), // 涓氬姟鍛� *
+ null, // 缁撶畻澶╂暟
+ null, // 閭垂鏀粯绫诲瀷
+ null, // 閭垂
+ null, // 浠樻鏃堕棿
+ null, // 鍙戣揣鏃堕棿
+ null, // 鐗╂祦鍚嶇О
+ null, // 鐗╂祦鍗曞彿
+ 1L, // 璁㈠崟鐘舵��
+ 1, // 鐘舵��
+ 9527L, // 娣诲姞浜哄憳
+ now, // 娣诲姞鏃堕棿
+ 9527L, // 淇敼浜哄憳
+ now, // 淇敼鏃堕棿
+ data.getSummary() // 澶囨敞
+ );
+ if (!orderService.insert(order)) {
+ throw new CoolException("淇濆瓨璁㈠崟琛ㄥご澶辫触锛�");
+ }
+ for (GetOrderResultDetl0 detl0 : data.getDetail()) {
+ Mat mat = matService.selectByMatnr(detl0.getUserCode());
+ if (mat == null) {
+ log.error("{}鍟嗗搧涓嶅瓨鍦ㄣ��", detl0.getUserCode());
+ continue;
+ }
+ OrderDetl orderDetl = new OrderDetl();
+ VersionUtils.setOrderDetl(orderDetl, mat);
+ orderDetl.setName(String.valueOf(detl0.getRowNo())); // 鍟嗗搧鏄庣粏琛屽彿
+ orderDetl.setOrderId(order.getId()); // 璁㈠崟鍐呯爜
+ orderDetl.setAnfme(detl0.getQty()); // 鍟嗗搧鏁伴噺
+ orderDetl.setCount(detl0.getQty()); // 鎬绘暟閲� *
+ orderDetl.setUnitPrice(detl0.getPrice()); // 鍟嗗搧鍗曚环
+ orderDetl.setCreateBy(9527L);
+ orderDetl.setCreateTime(now);
+ orderDetl.setUpdateBy(9527L);
+ orderDetl.setUpdateTime(now);
+ orderDetl.setStatus(1);
+ orderDetl.setMemo(detl0.getComment());
+ if (!orderDetlService.insert(orderDetl)) {
+ complete = false;
+ log.error("淇濆瓨閿�鍞鍗曞け璐ワ紒");
+ }
+ }
+ }
+ if (complete) {
+ List<String> collect = list.stream().map(GetOrderResult0::getNumber).distinct().collect(Collectors.toList());
+ for (String number : collect) {
+ if (!existNumbers.contains(number)) {
+ orderService.updateSettle(number, 1L);
+ }
+ }
+ }
+
+ }
}
} catch (IOException e) {
e.printStackTrace();
+ throw new RuntimeException(e.getMessage());
+ }
+
+ }
+
+ /**
+ * 瀹屾垚閿�鍞鍗�
+ */
+ @Scheduled(cron = "0/10 * * * * ? ")
+ @Transactional
+// @PostConstruct
+ public void finishOrdersExecute(){
+ try {
+ Date now = new Date();
+ List<Order> orders = orderService.selectList(new EntityWrapper<Order>().eq("settle", 4).isNotNull("number"));
+ if (!Cools.isEmpty(orders)) {
+ List<String> orderNos = orders.stream().map(Order::getOrderNo).distinct().collect(Collectors.toList());
+ for (Order order : orders) {
+ GetOrderResult0 getOrderResult0 = new GetOrderResult0();
+ List<GetOrderResultDetl0> list = new ArrayList<>();
+ getOrderResult0.setDetail(list);
+
+ // 鏃ュ織
+ List<DocLog> docLogs = new ArrayList<>();
+
+ // 澶�
+ getOrderResult0.setNumber(order.getOrderNo());
+ getOrderResult0.setVchType(11);
+ getOrderResult0.setBillDate(order.getOrderTime());
+ getOrderResult0.setBTypeID(order.getTel());
+ getOrderResult0.setKTypeID("瀹忔尯浠撳簱");
+ getOrderResult0.setVchcode(Integer.parseInt(order.getNumber()));
+ getOrderResult0.setSummary("閿�鍞鍗� - " + DateUtils.convert(new Date(), "yyyy-MM-dd HH:mm"));
+
+ // 浣�
+ List<OrderDetl> orderDetls = orderDetlService.selectByOrderNo(order.getOrderNo());
+ for (OrderDetl orderDetl : orderDetls) {
+ GetOrderResultDetl0 detl0 = new GetOrderResultDetl0();
+ detl0.setUserCode(orderDetl.getMatnr());
+ detl0.setQty(orderDetl.getCount());
+ detl0.setPrice(orderDetl.getUnitPrice());
+ detl0.setComment(orderDetl.getMemo());
+ detl0.setUnit(orderDetl.getUnit());
+ detl0.setRowNo(Integer.parseInt(orderDetl.getName()));
+ list.add(detl0);
+
+ // 鏃ュ織
+ docLogs.add(new DocLog(
+ order.getOrderNo(), // 鍗曟嵁缂栧彿
+ 11L, // 鍗曟嵁绫诲瀷
+ "閿�鍞鍗�", // 鍗曟嵁鍚嶇О
+ orderDetl.getMatnr(), // 鍟嗗搧缂栧彿
+ orderDetl.getCount(), // 涓婃姤鏁伴噺
+ 1, // 缁撴灉
+ now, // 涓婃姤鏃堕棿
+ null // 澶囨敞
+ ));
+ }
+
+ log.warn(JSON.toJSONString(getOrderResult0));
+
+ String response = new HttpHandler.Builder()
+ .setUri(URI)
+ .setPath(UPLOAD_BILL)
+ .setJson(JSON.toJSONString(getOrderResult0))
+ .build()
+ .doPost();
+
+ try {
+ for (DocLog docLog : docLogs) {
+ docLogService.insert(docLog);
+ }
+
+ RequestLog logInfo = new RequestLog();
+ logInfo.setName("鍗曟嵁涓婁紶锛屽崟鎹被鍨�" + 11);
+ logInfo.setRequest(JSON.toJSONString(getOrderResult0)); // 鍏ュ弬
+ logInfo.setResponse(response); // 鍑哄弬
+ logInfo.setCreateTime(new Date());
+ requestLogService.insert(logInfo);
+
+ } catch (Exception e) {
+ log.error(e.getMessage());
+ }
+
+ if (!Cools.isEmpty(response)) {
+ log.warn(response);
+ Result result = JSON.parseObject(response, Result.class);
+ if (result.getCode() != 1 && !result.getMsg().equals("鍗曟嵁宸茬粡瀹℃牳瀹屾垚鎴栧垹闄わ紝涓嶈兘瀹℃牳銆�")) {
+ continue;
+ }
+ if (!orderService.updateSettle(order.getOrderNo(), 6L)) {
+ throw new CoolException("淇敼璁㈠崟鐘舵�佸け璐�");
+ }
+
+ }
+
+ }
+ }
+
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e.getMessage());
+ }
+
+ }
+
+ /**
+ * 瀹屾垚閲囪喘閫�璐ц鍗�
+ */
+ @Scheduled(cron = "0/10 * * * * ? ")
+ @Transactional
+// @PostConstruct
+ public void finishOrders0Execute(){
+ try {
+ Date now = new Date();
+ List<Order> orders = orderService.selectList(new EntityWrapper<Order>().eq("settle", 4).eq("doc_type", 6));
+ if (!Cools.isEmpty(orders)) {
+ List<String> orderNos = orders.stream().map(Order::getOrderNo).distinct().collect(Collectors.toList());
+ for (Order order : orders) {
+ GetOrderResult0 getOrderResult0 = new GetOrderResult0();
+ List<GetOrderResultDetl0> list = new ArrayList<>();
+ getOrderResult0.setDetail(list);
+
+ // 鏃ュ織
+ List<DocLog> docLogs = new ArrayList<>();
+
+ // 澶�
+ getOrderResult0.setNumber(order.getOrderNo());
+ getOrderResult0.setVchType(6);
+ getOrderResult0.setBillDate(order.getOrderTime());
+ getOrderResult0.setBTypeID(order.getTel());
+ getOrderResult0.setKTypeID("瀹忔尯浠撳簱");
+ getOrderResult0.setBTypeID(Cools.isEmpty(order.getCstmr())?"SHHT":String.valueOf(order.getCstmr()));
+ getOrderResult0.setBTypeID("SHHT");
+ getOrderResult0.setSummary("閲囪喘閫�璐у崟 - " + DateUtils.convert(new Date(), "yyyy-MM-dd HH:mm"));
+
+
+ // 浣�
+ List<OrderDetl> orderDetls = orderDetlService.selectByOrderNo(order.getOrderNo());
+ for (OrderDetl orderDetl : orderDetls) {
+ GetOrderResultDetl0 detl0 = new GetOrderResultDetl0();
+ detl0.setUserCode(orderDetl.getMatnr());
+ detl0.setQty(orderDetl.getAnfme());
+ detl0.setPrice(orderDetl.getUnitPrice());
+ detl0.setUnit(orderDetl.getUnit());
+ detl0.setComment(orderDetl.getMemo());
+ list.add(detl0);
+
+ // 鏃ュ織
+ docLogs.add(new DocLog(
+ order.getOrderNo(), // 鍗曟嵁缂栧彿
+ 6L, // 鍗曟嵁绫诲瀷
+ "閲囪喘閫�璐ц鍗�", // 鍗曟嵁鍚嶇О
+ orderDetl.getMatnr(), // 鍟嗗搧缂栧彿
+ orderDetl.getCount(), // 涓婃姤鏁伴噺
+ 1, // 缁撴灉
+ now, // 涓婃姤鏃堕棿
+ null // 澶囨敞
+ ));
+ }
+
+ System.out.println(JSON.toJSONString(getOrderResult0));
+
+ String response = new HttpHandler.Builder()
+ .setUri(URI)
+ .setPath(UPLOAD_BILL)
+ .setJson(JSON.toJSONString(getOrderResult0))
+ .build()
+ .doPost();
+
+ try {
+ for (DocLog docLog : docLogs) {
+ docLogService.insert(docLog);
+ }
+
+ RequestLog logInfo = new RequestLog();
+ logInfo.setName("鍗曟嵁涓婁紶锛屽崟鎹被鍨�" + 6);
+ logInfo.setRequest(JSON.toJSONString(getOrderResult0)); // 鍏ュ弬
+ logInfo.setResponse(response); // 鍑哄弬
+ logInfo.setCreateTime(new Date());
+ requestLogService.insert(logInfo);
+ } catch (Exception e) {
+ log.error(e.getMessage());
+ }
+
+ if (!Cools.isEmpty(response)) {
+ log.warn(response);
+ Result result = JSON.parseObject(response, Result.class);
+ if (result.getCode() != 1) {
+ continue;
+ }
+ if (!orderService.updateSettle(getOrderResult0.getNumber(), 6L)) {
+ throw new CoolException("淇敼璁㈠崟鐘舵�佸け璐�");
+ }
+// // 杞巻鍙叉。
+// int save = custOrderMapper.saveLog(getOrderResult0.getNumber());
+// if (save > 0) {
+// if (custOrderMapper.delete(new EntityWrapper<CustOrder>().eq("number", getOrderResult0.getNumber())) == 0) {
+// throw new CoolException("鍒犻櫎閿�鍞鍗曞け璐�");
+// }
+// log.info("{}閿�鍞鍗曟嫞璐х粨鏉�", getOrderResult0.getNumber());
+// }
+ }
+
+ }
+ }
+
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e.getMessage());
+ }
+
+ }
+
+ /**
+ * 搴撳瓨涓婁紶
+ */
+// @Scheduled(cron = "0/15 * * * * ? ")
+ @GetMapping("test2")
+ public void uploadStockExecute(){
+ try {
+
+ List<LocDetl> statis = locDetlService.getLocDetlStatis();
+ if (!Cools.isEmpty(statis)) {
+ UploadStock uploadStock = new UploadStock();
+ uploadStock.setNumber(String.valueOf(snowflakeIdWorker.nextId()));
+ uploadStock.setVchType(89);
+ uploadStock.setBillDate(DateUtils.convert(new Date(), DateUtils.yyyyMMdd_F));
+ uploadStock.setDataSize(statis.size());
+ List<UploadStockDtel> detail = new ArrayList<>();
+ uploadStock.setDetail(detail);
+ for (LocDetl locDetl : statis) {
+ Mat mat = matService.selectByMatnr(locDetl.getMatnr());
+ if (mat == null) {continue;}
+ UploadStockDtel detl = new UploadStockDtel();
+ detl.setUserCode(mat.getMatnr());
+ detl.setQty(locDetl.getAnfme());
+// detl.setPrice(Double.parseDouble());
+ detl.setComment(mat.getMemo());
+ detail.add(detl);
+ }
+
+ String response = new HttpHandler.Builder()
+ .setUri(URI)
+ .setPath(UPLOAD_STOCK)
+ .setJson(JSON.toJSONString(uploadStock))
+ .build()
+ .doPost();
+ if (!Cools.isEmpty(response)) {
+ log.info("涓婃姤搴撳瓨鏄庣粏缁熻 ======>> \nrequest:{} \nresponse:{}", JSON.toJSONString(uploadStock), response);
+ Result result = JSON.parseObject(response, Result.class);
+ if (result.getCode() != 1) {
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+
+ }
+
+
+ /**
+ * 鑾峰彇鍙栨秷璁㈠崟
+ */
+ @Scheduled(cron = "0/10 * * * * ? ")
+ @Transactional
+// @PostConstruct
+ public void getCancelOrdersExecute(){
+ try {
+ Map<String, Object> json = new HashMap<>();
+ json.put("vchType", 11);
+ json.put("flag", 2);
+ String response = new HttpHandler.Builder()
+ .setUri(URI)
+ .setPath(GET_ORDERS)
+ .setJson(JSON.toJSONString(json))
+ .build()
+ .doPost();
+ if (!Cools.isEmpty(response)) {
+// log.info(response);
+ Date now = new Date();
+ Result result = JSON.parseObject(response, Result.class);
+ if (result.getCode() != 1) {
+ return;
+ }
+ List<GetOrderResult0> list = JSON.parseArray(result.getData(), GetOrderResult0.class);
+ if (!Cools.isEmpty(list)) {
+ Set<String> existNumbers = new HashSet<>();
+ for (GetOrderResult0 result0 : list) {
+ existNumbers.add(result0.getNumber());
+ }
+ for (String number : existNumbers) {
+ Order order = orderService.selectByOrderNo(number);
+ if (order != null) {
+ if (order.getSettle() != 3L && order.getSettle() != 5L) {
+ if (orderService.updateSettle(number, 5L)) {
+ // 绔嬪簱鍑哄簱璐т綅杞嚦A99
+ List<Pakout> pakouts = pakoutService.selectList(new EntityWrapper<Pakout>()
+ .eq("node_id", -1).eq("doc_num", number).ne("memo", "1"));
+ Node node = nodeService.selectByUuid(Parameter.get().getUniNode());
+ for (Pakout pakout : pakouts) {
+ // 绔嬪簱鍑哄簱璐т綅
+ if (pakout.getLocNo().length() == 7) {
+ LocDetl locDetl = locDetlService.getLocDetl(node.getId(), pakout.getMatnr());
+ if (locDetl == null) {
+ locDetl = new LocDetl();
+ locDetl.setLocNo(node.getName());
+ locDetl.setNodeId(node.getId());
+ locDetl.setAnfme(pakout.getAnfme());
+ VersionUtils.setLocDetl(locDetl, pakout);
+ locDetl.setStatus(1);
+ locDetl.setCreateBy(9527L);
+ locDetl.setCreateTime(now);
+ locDetl.setUpdateBy(9527L);
+ locDetl.setUpdateTime(now);
+ boolean insert = locDetlService.insert(locDetl);
+ if (!insert) {
+ throw new CoolException("鏂板搴撳瓨鏄庣粏妗eけ璐�");
+ }
+ } else {
+ if (!locDetlService.incrementStock(node.getId(), pakout.getMatnr(), pakout.getAnfme())) {
+ throw new CoolException("鏂板搴撳瓨鏄庣粏妗eけ璐�");
+ }
+ }
+ if (!pakoutService.updateStep(pakout.getWrkNo(), pakout.getDocNum())) {
+ throw new CoolException("鍙栨秷璁㈠崟鍚庡洖婊氱珛搴撴嫞璐у崟澶辫触");
+ }
+ }
+ }
+ } else {
+// throw new CoolException("淇敼璁㈠崟鐘舵�佸け璐�");
+ }
+ }
+ }
+ }
+
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e.getMessage());
}
}
--
Gitblit v1.9.1