自动化立体仓库 - WMS系统
zyx
2023-07-18 eadb3c4c77dd9008030ec029c4c55727084253ed
src/main/java/com/zy/asrs/service/impl/AgvWrkMastServiceImp.java
@@ -1,11 +1,97 @@
package com.zy.asrs.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.core.exception.CoolException;
import com.zy.asrs.entity.AgvWrkMast;
import com.zy.asrs.entity.param.AgvTaskCreateParam;
import com.zy.asrs.entity.param.AgvTaskParam;
import com.zy.asrs.entity.param.AgvTaskkDescribeParam;
import com.zy.asrs.mapper.AgvWrkMastMapper;
import com.zy.asrs.service.AgvWrkMastService;
import com.zy.common.utils.HttpHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class AgvWrkMastServiceImp extends ServiceImpl<AgvWrkMastMapper, AgvWrkMast> implements AgvWrkMastService {
    @Autowired
    AgvWrkMastMapper agvWrkMastMapper;
    public void updateWrkStsByWrkNo(int wrkNo, long wrkSts) {
        AgvWrkMast agvWrkMast = this.selectById(wrkNo);
        agvWrkMast.setWrkSts(wrkSts);
        this.updateById(agvWrkMast);
    }
    public Map<String,List<Map<String,String>>> startWrk(List<AgvWrkMast> agvWrkMastList) throws IOException {
        AgvTaskCreateParam agvTaskCreateParam = new AgvTaskCreateParam();
        agvTaskCreateParam.setTaskType("putaway");
        //调用容器入场时所需要参数
        Map<String,List<Map<String,String>>> containerMoveParam = new HashMap<>();
        List<Map<String,String>> positionCodeMapList = new ArrayList<>();
        containerMoveParam.put("containerMoveIns",positionCodeMapList);
        List<AgvTaskParam> agvTaskParamList = agvWrkMastList.stream().map(agvWrkMast -> {
            AgvTaskParam agvTaskParam = new AgvTaskParam();
            AgvTaskkDescribeParam agvTaskkDescribeParam = new AgvTaskkDescribeParam();
            agvTaskParam.setTaskDescribe(agvTaskkDescribeParam);
            //AgvTaskParam
            agvTaskParam.setTaskCode(agvWrkMast.getWrkNo().toString());
            agvTaskParam.setTaskPriority(agvWrkMast.getIoPri().intValue());
            //往容器入场参数中放入源站点位置
            Map<String,String> positionCodeMap = new HashMap<>();
            positionCodeMap.put("positionCode",agvWrkMast.getSourceLocNo());
            positionCodeMapList.add(positionCodeMap);
            //AgvTaskkDescribeParam
            agvTaskkDescribeParam.setFromLocationCode(agvWrkMast.getSourceLocNo());
            agvTaskkDescribeParam.setToLocationCode(agvWrkMast.getLocNo());
            agvTaskkDescribeParam.setContainerCode(agvWrkMast.getBarcode());
            return agvTaskParam;
        }).collect(Collectors.toList());
        agvTaskCreateParam.setTasks(agvTaskParamList);
        String response = new HttpHandler.Builder()
                .setUri("localhost:8080")
                .setPath("test/task/create")
                .setJson(JSONObject.toJSONString(agvTaskCreateParam))
                .build()
                .doPost();
        JSONObject jsonObject = JSON.parseObject(response);
        //save log api
        int code = (int) jsonObject.get("code");
        if(code != 0){
            throw new CoolException("调用AGV接口失败");
        }
        return containerMoveParam;
    }
    public int containerMove(Map<String, List<Map<String, String>>> containerMoveParam) throws IOException {
        String response = new HttpHandler.Builder()
                .setUri("localhost:8080")
                .setPath("test/container/moveIn")
                .setJson(JSONObject.toJSONString(containerMoveParam))
                .build()
                .doPost();
        JSONObject jsonObject = JSON.parseObject(response);
        return (int) jsonObject.get("code");
    }
}