| | |
| | | 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.*; |
| | |
| | | @RestController |
| | | public class ErpScheduler { |
| | | |
| | | public static final String URI = "http://8.133.182.21:6220/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"; |
| | |
| | | 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/5 * * * * ? ") |
| | | @Scheduled(cron = "0 */2 * * * ? ") |
| | | public void updateMatExecute(){ |
| | | try { |
| | | Map<String, Object> param = new HashMap<>(); |
| | |
| | | /** |
| | | * 持久化销售订单 |
| | | */ |
| | | @Scheduled(cron = "0/5 * * * * ? ") |
| | | @Scheduled(cron = "0 */1 * * * ?") |
| | | @Transactional |
| | | // @PostConstruct |
| | | public void getOrdersExecute(){ |
| | |
| | | // @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()); |
| | |
| | | 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(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()); |
| | |
| | | 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); |
| | |
| | | Order order = orderService.selectByOrderNo(number); |
| | | if (order != null) { |
| | | if (order.getSettle() != 3L && order.getSettle() != 5L) { |
| | | if (!orderService.updateSettle(number, 5L)) { |
| | | // throw new CoolException("修改订单状态失败"); |
| | | 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("修改订单状态失败"); |
| | | } |
| | | } |
| | | } |