#
luxiaotao1123
2021-03-16 587fcf4a73c44330a5d75ced8ccf0274666c3cbe
src/main/java/zy/cloud/wms/common/service/erp/ErpScheduler.java
@@ -4,18 +4,20 @@
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.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.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.mapper.TagMapper;
import zy.cloud.wms.manager.service.*;
import zy.cloud.wms.manager.utils.HttpHandler;
import java.io.IOException;
@@ -31,11 +33,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;
@@ -43,11 +47,18 @@
    private MatService matService;
    @Autowired
    private CstmrService cstmrService;
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private TagService tagService;
    @Autowired
    private TagMapper tagMapper;
    /**
     * 商品下载
     */
    //    @Scheduled(cron = "0/5 * * * * ? ")
    @GetMapping("/test1")
//    @PostConstruct
    public void getBasis1Execute(){
        try {
@@ -61,56 +72,7 @@
                    .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) {
                    Mat mat = matService.selectByMatnr(data.getUserCode());
                    String modifyDate = data.getModifyDate();
                    Date updateTime = null;
                    if (!Cools.isEmpty(modifyDate)) {
                        updateTime = DateUtils.convert(data.getModifyDate());
                    }
                    if (null == mat) {
                        mat = new Mat(
                                String.valueOf(data.getRec()),    // 编号
                                null,    // 所属区域
                                null,    // 所属归类
                                data.getUserCode(),    // 商品编号
                                data.getFullName(),    // 商品名称
                                null,    // 名称
                                null,    // 规格
                                null,    // 型号
                                null,    // 批号
                                null,    // 单位
                                null,    // 条码
                                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.setUpdateTime(updateTime);
                        matService.updateById(mat);
                    }
                    log.info("====>> 更新物料:{}", data.getUserCode());
                }
            }
        } catch (Exception e) {
@@ -206,6 +168,9 @@
                if (!Cools.isEmpty(list)) {
                    boolean complete = true;
                    for (GetOrderResult data : list) {
                        if (custOrderService.selectCount(new EntityWrapper<CustOrder>().eq("number", data.getNumber()).ne("bType_id", data.getBTypeID())) > 0) {
                            throw new CoolException("抱歉单号已存在,请修改单号:" + data.getNumber());
                        }
                        CustOrder custOrder = new CustOrder(
                                data.getNumber(),    // 销售单号
                                data.getBillDate(),    // 单据日期[非空]
@@ -242,5 +207,83 @@
    }
    /**
     * 更新库存
     */
//    @Scheduled(cron = "0/3 * * * * ? ")
    public void uploadStockExecute(){
        try {
//            locDetlService
            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);
                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());
                    }
                    if (null == mat) {
                        mat = new Mat(
                                String.valueOf(data.getRec()),    // 编号
                                null,    // 所属区域
                                null,    // 所属归类
                                data.getUserCode(),    // 商品编号
                                data.getFullName(),    // 商品名称
                                null,    // 名称
                                null,    // 规格
                                null,    // 型号
                                null,    // 批号
                                null,    // 单位
                                null,    // 条码
                                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.setUpdateTime(updateTime);
                        matService.updateById(mat);
                    }
                    log.info("====>> 更新物料:{}", data.getUserCode());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}