| | |
| | | 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.MatCodeMapper; |
| | | import zy.cloud.wms.manager.mapper.TagMapper; |
| | | import zy.cloud.wms.manager.service.*; |
| | | import zy.cloud.wms.manager.utils.HttpHandler; |
| | |
| | | @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 GET_STOCK = "cM/ptype/GetStock"; |
| | | public static final String OVER_BILL = "cM/basis/OverBill"; |
| | | public static final String UPLOAD_CANCEL_RESULT = "cM/basis/cancelOrders"; |
| | | |
| | |
| | | private OrderDetlService orderDetlService; |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | @Autowired |
| | | private PakoutService pakoutService; |
| | | @Autowired |
| | | private NodeService nodeService; |
| | | @Autowired |
| | | private DocLogService docLogService; |
| | | @Autowired |
| | | private RequestLogService requestLogService; |
| | | @Autowired |
| | | private MatCodeMapper matCodeMapper; |
| | | |
| | | |
| | | /** |
| | | * 商品下载 |
| | |
| | | .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("商品数据更新:"); |
| | | log.info(response); |
| | | Date now = new Date(); |
| | | Result result = JSON.parseObject(response, Result.class); |
| | |
| | | updateTime, // 修改时间 |
| | | null // 备注 |
| | | ); |
| | | matService.insert(mat); |
| | | if (matService.insert(mat)) { |
| | | MatCode matCode = mat.beMatCode(); |
| | | matCodeMapper.insert(matCode); |
| | | } |
| | | |
| | | } else { |
| | | mat.setUuid(String.valueOf(data.getRec())); |
| | | mat.setMatnr(data.getUserCode()); |
| | |
| | | mat.setUpdateTime(updateTime); |
| | | mat.setBarcode(data.getBarcode()); |
| | | mat.setUnit(data.getUnit3()); |
| | | matService.updateById(mat); |
| | | if (matService.updateById(mat)) { |
| | | MatCode matCode = mat.beMatCode(); |
| | | matCodeMapper.updateById(matCode); |
| | | } |
| | | } |
| | | log.info("====>> 更新物料:{}", data.getUserCode()); |
| | | } |
| | |
| | | /** |
| | | * 持久化销售订单 |
| | | */ |
| | | @Scheduled(cron = "0/5 * * * * ? ") |
| | | @Scheduled(cron = "0 */1 * * * ?") |
| | | @Transactional |
| | | // @PostConstruct |
| | | public void getOrdersExecute(){ |
| | | try { |
| | | Map<String, Object> json = new HashMap<>(); |
| | | json.put("vchType", 151); |
| | | json.put("vchType", 11); |
| | | String response = new HttpHandler.Builder() |
| | | .setUri(URI) |
| | | .setPath(GET_ORDERS) |
| | |
| | | // @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()); |
| | |
| | | List<GetOrderResultDetl0> list = new ArrayList<>(); |
| | | getOrderResult0.setDetail(list); |
| | | |
| | | // 日志 |
| | | List<DocLog> docLogs = new ArrayList<>(); |
| | | |
| | | // 头 |
| | | getOrderResult0.setNumber(order.getOrderNo()); |
| | | getOrderResult0.setVchType(11); // todo:luxiaotao |
| | | getOrderResult0.setVchType(11); |
| | | getOrderResult0.setBillDate(order.getOrderTime()); |
| | | getOrderResult0.setBTypeID(order.getTel()); |
| | | getOrderResult0.setKTypeID("宏挺仓库"); |
| | |
| | | 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 // 备注 |
| | | )); |
| | | } |
| | | |
| | | System.out.println(JSON.toJSONString(getOrderResult0)); |
| | | |
| | | log.warn(JSON.toJSONString(getOrderResult0)); |
| | | |
| | | String response = new HttpHandler.Builder() |
| | | .setUri(URI) |
| | |
| | | .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) { |
| | | if (result.getCode() != 1 && !result.getMsg().equals("单据已经审核完成或删除,不能审核。")) { |
| | | continue; |
| | | } |
| | | if (!orderService.updateSettle(getOrderResult0.getNumber(), 6L)) { |
| | | if (!orderService.updateSettle(order.getOrderNo(), 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()); |
| | | // } |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | // @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()); |
| | |
| | | List<GetOrderResultDetl0> list = new ArrayList<>(); |
| | | getOrderResult0.setDetail(list); |
| | | |
| | | // 日志 |
| | | List<DocLog> docLogs = new ArrayList<>(); |
| | | |
| | | // 头 |
| | | getOrderResult0.setNumber(order.getOrderNo()); |
| | | getOrderResult0.setVchType(6); // todo:luxiaotao |
| | | getOrderResult0.setVchType(6); |
| | | getOrderResult0.setBillDate(order.getOrderTime()); |
| | | getOrderResult0.setBTypeID(order.getTel()); |
| | | getOrderResult0.setKTypeID("宏挺仓库"); |
| | |
| | | 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) |
| | |
| | | .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); |
| | |
| | | public void getCancelOrdersExecute(){ |
| | | try { |
| | | Map<String, Object> json = new HashMap<>(); |
| | | json.put("vchType", 151); |
| | | json.put("vchType", 11); |
| | | json.put("flag", 2); |
| | | String response = new HttpHandler.Builder() |
| | | .setUri(URI) |
| | |
| | | existNumbers.add(result0.getNumber()); |
| | | } |
| | | for (String number : existNumbers) { |
| | | if (!orderService.updateSettle(number, 3L)) { |
| | | // throw new CoolException("修改订单状态失败"); |
| | | 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("新增库存明细档失败"); |
| | | } |
| | | } else { |
| | | if (!locDetlService.incrementStock(node.getId(), pakout.getMatnr(), pakout.getAnfme())) { |
| | | throw new CoolException("新增库存明细档失败"); |
| | | } |
| | | } |
| | | if (!pakoutService.updateStep(pakout.getWrkNo(), pakout.getDocNum())) { |
| | | throw new CoolException("取消订单后回滚立库拣货单失败"); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | // throw new CoolException("修改订单状态失败"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | e.printStackTrace(); |
| | | throw new RuntimeException(e.getMessage()); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 上传销售订单取消结果 |
| | | */ |
| | | @Scheduled(cron = "0/5 * * * * ? ") |
| | | @Transactional |
| | | // @PostConstruct |
| | | public void uploadCancelOrdersExecute(){ |
| | | // try { |
| | | // List<Order> orders = orderService.selectList(new EntityWrapper<Order>().eq("settle", 3).isNotNull("number")); |
| | | // if (Cools.isEmpty(orders)) { |
| | | // return; |
| | | // } |
| | | // Map<String, Object> json = new HashMap<>(); |
| | | // List<UploadCancelResult> list = new ArrayList<>(); |
| | | // for (CustOrder custOrder : custOrders) { |
| | | // UploadCancelResult result = new UploadCancelResult(); |
| | | // result.setNumber(custOrder.getNumber()); |
| | | // result.setUserCode(custOrder.getUserCode()); |
| | | // result.setQty(custOrder.getTotal()); |
| | | // result.setStatus(1); |
| | | // list.add(result); |
| | | // } |
| | | // json.put("data", list); |
| | | // String response = new HttpHandler.Builder() |
| | | // .setUri(URI) |
| | | // .setPath(UPLOAD_CANCEL_RESULT) |
| | | // .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; |
| | | // } |
| | | // for (UploadCancelResult result1 : list) { |
| | | // // 转历史档 |
| | | // int save = custOrderMapper.saveLog(result1.getNumber(), result1.getUserCode()); |
| | | // if (save > 0) { |
| | | // if (custOrderMapper.delete(new EntityWrapper<CustOrder>().eq("number", result1.getNumber()).eq("user_code", result1.getUserCode())) == 0) { |
| | | // throw new CoolException("删除销售订单失败"); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // } catch (IOException e) { |
| | | // e.printStackTrace(); |
| | | // throw new RuntimeException(e.getMessage()); |
| | | // } |
| | | |
| | | } |
| | | |