#
luxiaotao1123
2021-04-09 eb13b96cc3b01a3d44fbce6a730004e158418ab5
src/main/java/zy/cloud/wms/common/service/erp/ErpScheduler.java
@@ -9,10 +9,8 @@
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;
@@ -30,8 +28,8 @@
 * 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";
@@ -39,6 +37,8 @@
    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;
@@ -474,4 +474,99 @@
    }
    /**
     * 获取取消订单
     */
    @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());
        }
    }
}