From b31c69631ee75cdc02195a2e3efff3f9ad95943d Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期三, 17 三月 2021 16:08:45 +0800 Subject: [PATCH] # --- src/main/java/zy/cloud/wms/common/service/erp/ErpScheduler.java | 519 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 386 insertions(+), 133 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 1672dde..b494ced 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 @@ -4,26 +4,29 @@ import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.common.Cools; import com.core.common.DateUtils; +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 org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; import zy.cloud.wms.common.service.erp.entity.GetBasisResult; -import zy.cloud.wms.common.service.erp.entity.GetOrderResult; +import zy.cloud.wms.common.service.erp.entity.GetOrderResult0; +import zy.cloud.wms.common.service.erp.entity.GetOrderResultDetl0; import zy.cloud.wms.manager.entity.Cstmr; import zy.cloud.wms.manager.entity.CustOrder; import zy.cloud.wms.manager.entity.Mat; -import zy.cloud.wms.manager.service.CstmrService; -import zy.cloud.wms.manager.service.CustOrderService; -import zy.cloud.wms.manager.service.MatService; +import zy.cloud.wms.manager.entity.Tag; +import zy.cloud.wms.manager.mapper.CustOrderMapper; +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 javax.annotation.PostConstruct; import java.io.IOException; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -32,11 +35,13 @@ */ @Slf4j @Component +@RestController public class ErpScheduler { public static final String URI = "http://8.133.182.21:8080/api"; public static final String GET_ORDERS = "cM/basis/getOrders"; public static final String GET_BASIS = "cM/basis/getBasis"; + public static final String UPLOAD_STOCK = "cM/basis/uploadStock"; @Autowired private CustOrderService custOrderService; @@ -44,14 +49,383 @@ private MatService matService; @Autowired private CstmrService cstmrService; + @Autowired + private LocDetlService locDetlService; + @Autowired + private TagService tagService; + @Autowired + private TagMapper tagMapper; + @Autowired + private CustOrderMapper custOrderMapper; /** * 鍟嗗搧涓嬭浇 */ // @Scheduled(cron = "0/5 * * * * ? ") - @PostConstruct + @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/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/45 * * * * ? ") + @Transactional +// @PostConstruct + public void getOrdersExecute(){ + try { + Map<String, Object> json = new HashMap<>(); + json.put("vchType", 151); + 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)) { + boolean complete = true; + for (GetOrderResult0 data : list) { + if (custOrderService.selectCount(new EntityWrapper<CustOrder>() + .eq("number", data.getNumber()) +// .ne("bType_id", data.getBTypeID()) + ) > 0) { +// log.error("{}鍗曞彿宸插瓨鍦�", data.getNumber()); + complete = false; + continue; + } + for (GetOrderResultDetl0 detl0 : data.getDetail()) { + CustOrder custOrder = new CustOrder( + data.getNumber(), // 閿�鍞崟鍙� + data.getBillDate(), // 鍗曟嵁鏃ユ湡[闈炵┖] + data.getBTypeID(), // 瀹㈡埛缂栧彿 + data.getETypeID(), // 缁忔墜浜虹紪鍙穂闈炵┖] + detl0.getUserCode(), // 鍟嗗搧缂栧彿 + detl0.getQty(), // 鍟嗗搧鏁伴噺 + detl0.getPrice(), // 鍟嗗搧鍗曚环 + detl0.getComment(), // 鍟嗗搧澶囨敞[闈炵┖] + 0, // 鐘舵�� + now, // 娣诲姞鏃堕棿 + now, // 淇敼鏃堕棿 + data.getSummary() // 澶囨敞 + ); + boolean insert = custOrderService.insert(custOrder); + if (!insert) { + complete = false; + log.error("淇濆瓨閿�鍞鍗曞け璐ワ紒"); + } + } + } + if (complete) { + List<String> collect = list.stream().map(GetOrderResult0::getNumber).distinct().collect(Collectors.toList()); + for (String number : collect) { + custOrderService.updateStatus(number, 1); + } + } + + } + } + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException(e.getMessage()); + } + + } + + /** + * 瀹屾垚閿�鍞鍗� + */ + @Scheduled(cron = "0/10 * * * * ? ") + @Transactional +// @PostConstruct + public void finishOrdersExecute(){ + try { + List<CustOrder> custOrders = custOrderService.selectList(new EntityWrapper<CustOrder>().eq("status", 4)); + if (!Cools.isEmpty(custOrders)) { + List<String> numbers = custOrders.stream().map(CustOrder::getNumber).distinct().collect(Collectors.toList()); + for (String number : numbers) { + GetOrderResult0 getOrderResult0 = new GetOrderResult0(); + List<GetOrderResultDetl0> list = new ArrayList<>(); + getOrderResult0.setDetail(list); + // 閬嶅巻閫掑噺 + Iterator<CustOrder> iterator = custOrders.iterator(); + while (iterator.hasNext()) { + CustOrder custOrder = iterator.next(); + if (custOrder.getNumber().equals(number)) { + // 琛ㄥご + if (Cools.isEmpty(getOrderResult0.getNumber())) { + getOrderResult0.setNumber(number); + getOrderResult0.setVchType(34); // todo:luxiaotao + getOrderResult0.setBillDate(custOrder.getBillDate()); + getOrderResult0.setBTypeID(custOrder.getBTypeId()); + getOrderResult0.setKTypeID("瀹忔尯浠撳簱"); + } + // 琛ㄤ綋 + GetOrderResultDetl0 detl0 = new GetOrderResultDetl0(); + detl0.setUserCode(custOrder.getUserCode()); + detl0.setQty(custOrder.getQty()); + detl0.setPrice(custOrder.getPrice()); + detl0.setComment(custOrder.getComment()); + list.add(detl0); + iterator.remove(); + } + } + + System.out.println(JSON.toJSONString(getOrderResult0)); + + int save = custOrderMapper.saveLog(getOrderResult0.getNumber()); + if (save > 0) { + if (custOrderMapper.delete(new EntityWrapper<CustOrder>().eq("number", getOrderResult0.getNumber())) == 0) { + throw new CoolException("鍒犻櫎閿�鍞鍗曞け璐�"); + } + } + +// String response = new HttpHandler.Builder() +// .setUri(URI) +// .setPath(GET_ORDERS) +// .setJson(JSON.toJSONString(getOrderResult0)) +// .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; +// } +// // 杞巻鍙叉。 +// } + + } + } + + + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(e.getMessage()); + } + + } + + /** + * 鏇存柊搴撳瓨 + */ +// @Scheduled(cron = "0/3 * * * * ? ") + public void uploadStockExecute(){ + try { + +// locDetlService + Map<String, Object> param = new HashMap<>(); param.put("rec", 0); param.put("Flag", 1); @@ -116,132 +490,11 @@ } } catch (Exception e) { e.printStackTrace(); - } - } - - /** - * 瀹㈡埛涓嬭浇 - */ - // @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(); - } - } - - /** - * 鎸佷箙鍖栭攢鍞鍗� - */ -// @Scheduled(cron = "0/3 * * * * ? ") - @Transactional - public void getOrdersExecute(){ - try { - Map<String, Object> json = new HashMap<>(); - json.put("vchType", 41); - 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<GetOrderResult> list = JSON.parseArray(result.getData(), GetOrderResult.class); - if (!Cools.isEmpty(list)) { - boolean complete = true; - for (GetOrderResult data : list) { - CustOrder custOrder = new CustOrder( - data.getNumber(), // 閿�鍞崟鍙� - data.getBillDate(), // 鍗曟嵁鏃ユ湡[闈炵┖] - data.getBTypeID(), // 瀹㈡埛缂栧彿 - data.getETypeID(), // 缁忔墜浜虹紪鍙穂闈炵┖] - data.getUserCode(), // 鍟嗗搧缂栧彿 - data.getQty(), // 鍟嗗搧鏁伴噺 - data.getPrice(), // 鍟嗗搧鍗曚环 - data.getComment(), // 鍟嗗搧澶囨敞[闈炵┖] - 0, // 鐘舵�� - now, // 娣诲姞鏃堕棿 - now, // 淇敼鏃堕棿 - null // 澶囨敞 - ); - boolean insert = custOrderService.insert(custOrder); - if (!insert) { - complete = false; - log.error("淇濆瓨閿�鍞鍗曞け璐ワ紒"); - } - } - if (complete) { - List<String> collect = list.stream().map(GetOrderResult::getNumber).distinct().collect(Collectors.toList()); - for (String number : collect) { - custOrderService.updateStatus(number, 1); - } - } - - } - } - } catch (IOException e) { - e.printStackTrace(); + throw new RuntimeException(e.getMessage()); } - } + } } -- Gitblit v1.9.1