#
luxiaotao1123
2022-01-17 846426425d83998dc223aabbd2e8be7ca393c952
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -1,6 +1,7 @@
package com.zy.asrs.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.Cools;
@@ -19,6 +20,8 @@
import com.zy.common.model.StartupDto;
import com.zy.common.service.CommonService;
import com.zy.common.utils.CollectionUtils;
import com.zy.common.utils.HttpHandler;
import com.zy.common.web.param.SearchLocParam;
import com.zy.core.CrnThread;
import com.zy.core.DevpThread;
import com.zy.core.cache.MessageQueue;
@@ -37,7 +40,7 @@
import com.zy.core.thread.LedThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -57,7 +60,6 @@
@Service("mainService")
@Transactional
public class MainServiceImpl {
    public static final long COMMAND_TIMEOUT = 5 * 1000;
@@ -85,8 +87,8 @@
    private BasErrLogService basErrLogService;
    @Autowired
    private BasCrnErrorMapper basCrnErrorMapper;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Value("${wms.url}")
    private String wmsUrl;
    /**
     * 组托
@@ -139,6 +141,24 @@
                    }
                    try {
                        SearchLocParam param = new SearchLocParam();
                        String response = new HttpHandler.Builder()
                                .setUri(wmsUrl)
                                .setPath("/rpc/pakin/loc/v1")
                                .setJson(JSON.toJSONString(param))
                                .build()
                                .doPost();
                        JSONObject jsonObject = JSON.parseObject(response);
                        if (jsonObject.getInteger("code").equals(200)) {
                            StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                            // todo
                        } else {
                            log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl+"/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                        }
                        // 检索库位
                        LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
                        List<String> matNos = waitPakins.stream().map(WaitPakin::getMatnr).distinct().collect(Collectors.toList());
@@ -1186,82 +1206,6 @@
            throw new CoolException("移转失败");
        }
    }
    /**
     * 堆垛机演示  ===>> 库位移转
     */
    @Async
    public void crnDemoOfLocMove(Integer crn){
        for (int i = 0; i < 5; i++) {
            LocMast sourceLoc = locMastService.queryDemoSourceLoc(crn);
            LocMast loc = locMastService.queryDemoLoc(crn);
            if (null == sourceLoc || null == loc) {
                break;
            }
            String sourceLocNo = sourceLoc.getLocNo();
            String locNo = loc.getLocNo();
            // 获取工作号
            int workNo = commonService.getWorkNo(WorkNoType.PICK.type);
            // 保存工作档
            WrkMast wrkMast = new WrkMast();
            wrkMast.setWrkNo(workNo);
            wrkMast.setIoTime(new Date());
            wrkMast.setWrkSts(11L); // 工作状态:11.生成出库ID
            wrkMast.setIoType(11); // 入出库状态: 11.库格移载
            wrkMast.setIoPri(13D);
            wrkMast.setCrnNo(crn);
            wrkMast.setSourceLocNo(sourceLocNo); // 源库位
            wrkMast.setLocNo(locNo); // 目标库位
            wrkMast.setFullPlt("N"); // 满板:Y
            wrkMast.setPicking("N"); // 拣料
            wrkMast.setExitMk("N"); // 退出
            wrkMast.setEmptyMk(sourceLoc.getLocSts().equals("D")?"Y":"N"); // 空板
            wrkMast.setBarcode(sourceLoc.getBarcode()); // 托盘码
            wrkMast.setLinkMis("N");
            wrkMast.setAppeTime(new Date());
            wrkMast.setModiTime(new Date());
            int res = wrkMastMapper.insert(wrkMast);
            if (res == 0) {
                throw new CoolException("保存工作档失败");
            }
            // 工作档明细保存
            List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo));
            for (LocDetl locDetl : locDetls) {
                WrkDetl wrkDetl = new WrkDetl();
                wrkDetl.setWrkNo(workNo);
                wrkDetl.setIoTime(new Date());
                wrkDetl.setAnfme(locDetl.getAnfme());
                VersionUtils.setWrkDetl(wrkDetl, locDetl); // 版本控制
                wrkDetl.setAppeTime(new Date());
                wrkDetl.setModiTime(new Date());
                if (!wrkDetlService.insert(wrkDetl)) {
                    throw new CoolException("保存工作档明细失败");
                }
            }
            // 修改源库位状态
            if (sourceLoc.getLocSts().equals("D") || sourceLoc.getLocSts().equals("F")) {
                sourceLoc.setLocSts("R"); // R.出库预约
                sourceLoc.setModiTime(new Date());
                if (!locMastService.updateById(sourceLoc)){
                    throw new CoolException("更新源库位状态失败");
                }
            } else {
                throw new CoolException("源库位出库失败");
            }
            // 修改目标库位状态
            if (loc.getLocSts().equals("O")) {
                loc.setLocSts("S"); // S.入库预约
                loc.setModiTime(new Date());
                if (!locMastService.updateById(loc)) {
                    throw new CoolException("更新目标库位状态失败");
                }
            } else {
                throw new CoolException("移转失败");
            }
        }
    }
    /**