#
luxiaotao1123
2021-06-29 cc2b7c021293f25748711617ef182b2d15192dbd
src/main/java/zy/cloud/wms/manager/controller/LocSyncController.java
@@ -2,7 +2,6 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.annotations.ManagerAuth;
import com.core.common.Cools;
import com.core.common.R;
@@ -11,24 +10,21 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import zy.cloud.wms.common.entity.Parameter;
import zy.cloud.wms.common.model.BillDto;
import zy.cloud.wms.common.service.erp.ErpService;
import zy.cloud.wms.common.web.BaseController;
import zy.cloud.wms.manager.entity.LocSum;
import zy.cloud.wms.manager.entity.Pakout;
import zy.cloud.wms.manager.entity.WrkLocSync;
import zy.cloud.wms.manager.service.LocSyncService;
import zy.cloud.wms.manager.service.PakoutService;
import zy.cloud.wms.manager.service.WrkLocSyncService;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@RestController
@Slf4j
@@ -57,18 +53,26 @@
    @RequestMapping(value = "/locSync/insertWrklocSync")
    @ManagerAuth(memo = "同步上传清单数据插入")
    @Transactional
    public R insertWrklocSync(@RequestBody JSONObject param) {
        Date now = new Date();
        Long userId = getUserId();
        List<WrkLocSync> list = JSONObject.parseArray(param.getJSONArray("list").toJSONString(), WrkLocSync.class);
        // 插入创建人员和创建时间
        if (list.size() > 0) {
            for (WrkLocSync elist : list) {
                elist.setCreateBy(getUserId());
                elist.setCreateTime(new Date());
        for (WrkLocSync wrkLocSync : list) {
            WrkLocSync sync = new WrkLocSync();
            sync.setMatnr(wrkLocSync.getMatnr());
            sync.setQty(wrkLocSync.getQty());
            sync.setState("N");
            sync.setCreateTime(now);
            sync.setCreateBy(userId);
            sync.setUpdateBy(userId);
            sync.setUpdateTime(now);
            if (!wrkLocSyncService.insert(sync)) {
                throw new CoolException("同步失败");
            }
        }
        Integer result = 0;
        result = wrkLocSyncService.insertWrkLocSync(list);
        return R.ok(result);
        return R.ok(list.size());
    }
@@ -94,38 +98,42 @@
    }
    /* 同步上传erp[uploadBill] 单据上传 */
    @Scheduled(cron = "0/5 * * * * ? ")
    @Scheduled(cron = "0/2 * * * * ? ")
    public void execute() {
        List<String> orderList = new ArrayList<>();
        orderList.add("state");
        orderList.add("create_time");
        List<WrkLocSync> syncList = wrkLocSyncService.selectList(new EntityWrapper<WrkLocSync>().orderDesc(orderList));
        // 同步上传清单处理,取第一条
        if (!Cools.isEmpty(syncList)) {
            WrkLocSync executeData = syncList.get(0);
            // 订单号
            String docNum = String.valueOf(snowflakeIdWorker.nextId());
            // 订单类型 34采购单
            Integer docId = 34;
            List<BillDto> dtos = new ArrayList<BillDto>();
            BillDto res = new BillDto();
            res.setMatnr(executeData.getMatnr());
            res.setQty(executeData.getQty());
            dtos.add(res);
            if (erpService.uploadBill(dtos, docId, docNum)) {
                // 成功后删除任务
                if (!wrkLocSyncService.delete(new EntityWrapper<WrkLocSync>().eq("matnr", executeData.getMatnr()))) {
                    log.info("库存同步删除任务失败,任务matnr=" + executeData.getMatnr() + "时间=" + new Date());
                }
            } else {
                // 失败后将任务状态state更新为N
                executeData.setState("X");
                executeData.setUpdateBy(getUserId());
                executeData.setCreateTime(new Date());
                if(!wrkLocSyncService.update(executeData, new EntityWrapper<WrkLocSync>().eq("matnr", executeData.getMatnr()))) {
                    log.info("库存同步更新任务失败,任务matnr=" + executeData.getMatnr() + "时间=" + new Date());
        if (!Cools.isEmpty(Parameter.get().getSyncSwitch()) && Parameter.get().getSyncSwitch().equals("Y")) {
            List<String> orderList = new ArrayList<>();
            orderList.add("state");
            orderList.add("create_time");
            List<WrkLocSync> syncList = wrkLocSyncService.selectList(new EntityWrapper<WrkLocSync>()
                    .eq("state", "N").orderDesc(orderList));
            // 同步上传清单处理,取第一条
            if (!Cools.isEmpty(syncList)) {
                WrkLocSync executeData = syncList.get(0);
                // 订单号
                String docNum = "PU-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);
                // 订单类型 34采购单
                Integer docId = 34;
                List<BillDto> dtos = new ArrayList<BillDto>();
                BillDto res = new BillDto();
                res.setMatnr(executeData.getMatnr());
                res.setQty(executeData.getQty());
                dtos.add(res);
                if (erpService.uploadBill(dtos, docId, docNum).getSuccess()) {
                    // 成功后删除任务
                    if (!wrkLocSyncService.delete(new EntityWrapper<WrkLocSync>().eq("matnr", executeData.getMatnr()))) {
                        log.info("库存同步删除任务失败,任务matnr=" + executeData.getMatnr() + "时间=" + new Date());
                    }
                } else {
                    // 失败后将任务状态state更新为N
                    executeData.setState("X");
                    executeData.setUpdateBy(9527L);
                    executeData.setCreateTime(new Date());
                    if(!wrkLocSyncService.update(executeData, new EntityWrapper<WrkLocSync>().eq("matnr", executeData.getMatnr()))) {
                        log.info("库存同步更新任务失败,任务matnr=" + executeData.getMatnr() + "时间=" + new Date());
                    }
                }
            }
        }
    }
}