| | |
| | | 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.*; |
| | | import zy.cloud.wms.manager.entity.*; |
| | | import zy.cloud.wms.manager.mapper.CustOrderMapper; |
| | |
| | | * Created by vincent on 2020/11/27 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | @RestController |
| | | //@Component |
| | | //@RestController |
| | | public class ErpScheduler { |
| | | |
| | | public static final String URI = "http://8.133.182.21:8080/api"; |
| | |
| | | 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 CustOrderService custOrderService; |
| | |
| | | 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 (custOrderService.selectCount(new EntityWrapper<CustOrder>() |
| | | .eq("number", data.getNumber()) |
| | | // .ne("bType_id", data.getBTypeID()) |
| | | ) > 0) { |
| | | // log.error("{}单号已存在", data.getNumber()); |
| | | complete = false; |
| | | // complete = false; |
| | | existNumbers.add(data.getNumber()); |
| | | continue; |
| | | } |
| | | for (GetOrderResultDetl0 detl0 : data.getDetail()) { |
| | |
| | | data.getBillDate(), // 单据日期[非空] |
| | | data.getBTypeID(), // 客户编号 |
| | | data.getETypeID(), // 经手人编号[非空] |
| | | data.getVchcode(), // 单据自增ID |
| | | detl0.getUserCode(), // 商品编号 |
| | | detl0.getQty(), // 商品数量 |
| | | detl0.getQty(), // 总数量 |
| | | detl0.getPrice(), // 商品单价 |
| | | detl0.getRowNo(), // 商品明细行号 |
| | | detl0.getComment(), // 商品备注[非空] |
| | | 0, // 状态 |
| | | now, // 添加时间 |
| | | now, // 修改时间 |
| | | data.getSummary() // 备注 |
| | | ); |
| | | boolean insert = custOrderService.insert(custOrder); |
| | | if (!insert) { |
| | | if (!custOrderService.insert(custOrder)) { |
| | | 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); |
| | | if (!existNumbers.contains(number)) { |
| | | custOrderService.updateStatus(number, 1); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | /** |
| | | * 完成销售订单 |
| | | */ |
| | | // @Scheduled(cron = "0/10 * * * * ? ") |
| | | @Scheduled(cron = "0/10 * * * * ? ") |
| | | @Transactional |
| | | // @PostConstruct |
| | | public void finishOrdersExecute(){ |
| | | try { |
| | | List<CustOrder> custOrders = custOrderService.selectList(new EntityWrapper<CustOrder>().eq("status", 4)); |
| | | List<CustOrder> custOrders = custOrderService.selectList(new EntityWrapper<CustOrder>().eq("status", 4).isNotNull("vch_code")); |
| | | if (!Cools.isEmpty(custOrders)) { |
| | | List<String> numbers = custOrders.stream().map(CustOrder::getNumber).distinct().collect(Collectors.toList()); |
| | | for (String number : numbers) { |
| | |
| | | getOrderResult0.setBillDate(custOrder.getBillDate()); |
| | | getOrderResult0.setBTypeID(custOrder.getBTypeId()); |
| | | getOrderResult0.setKTypeID("宏挺仓库"); |
| | | getOrderResult0.setVchcode(custOrder.getVchcode()); |
| | | } |
| | | // 表体 |
| | | GetOrderResultDetl0 detl0 = new GetOrderResultDetl0(); |
| | |
| | | detl0.setQty(custOrder.getTotal()); |
| | | detl0.setPrice(custOrder.getPrice()); |
| | | detl0.setComment(custOrder.getComment()); |
| | | detl0.setRowNo(custOrder.getRowNo()); |
| | | list.add(detl0); |
| | | iterator.remove(); |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取取消订单 |
| | | */ |
| | | @Scheduled(cron = "0/5 * * * * ? ") |
| | | @Transactional |
| | | // @PostConstruct |
| | | public void getCancelOrdersExecute(){ |
| | | try { |
| | | Map<String, Object> json = new HashMap<>(); |
| | | String response = new HttpHandler.Builder() |
| | | .setUri(URI) |
| | | .setPath(OVER_BILL) |
| | | .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; |
| | | Set<String> existNumbers = new HashSet<>(); |
| | | |
| | | String cancelNumber = ""; |
| | | if (!custOrderService.updateStatus(cancelNumber, 5)) { |
| | | throw new CoolException("修改订单状态失败"); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | throw new RuntimeException(e.getMessage()); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 上传销售订单取消结果 |
| | | */ |
| | | @Scheduled(cron = "0/5 * * * * ? ") |
| | | @Transactional |
| | | // @PostConstruct |
| | | public void uploadCancelOrdersExecute(){ |
| | | try { |
| | | List<CustOrder> custOrders = custOrderService.selectList(new EntityWrapper<CustOrder>().eq("status", 3).isNotNull("vch_code")); |
| | | if (Cools.isEmpty(custOrders)) { |
| | | 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()); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |