自动化立体仓库 - WMS系统
zyx
2023-07-19 4665167843394f4586db8198d5d1c5852ede3bf7
src/main/java/com/zy/asrs/service/impl/AgvWrkMastServiceImp.java
@@ -12,7 +12,9 @@
import com.zy.asrs.service.AgvWrkMastService;
import com.zy.asrs.service.ApiLogService;
import com.zy.common.utils.HttpHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.IOException;
@@ -23,11 +25,17 @@
import java.util.stream.Collectors;
@Service
@Slf4j
public class AgvWrkMastServiceImp extends ServiceImpl<AgvWrkMastMapper, AgvWrkMast> implements AgvWrkMastService {
    @Value("${agv.url}")
    private String url;
    private String path;
    @Value("${agv.taskCreatePath}")
    private String taskCreatePath;
    @Value("${agv.containerMoveInPath}")
    private String containerMoveInPath;
    @Autowired
    AgvWrkMastMapper agvWrkMastMapper;
@@ -50,6 +58,20 @@
        List<Map<String,String>> positionCodeMapList = new ArrayList<>();
        containerMoveParam.put("containerMoveIns",positionCodeMapList);
        getRequestParam(agvTaskCreateParam,agvWrkMastList,positionCodeMapList);
        doHttpRequest(agvTaskCreateParam,"上架任务下发",url, taskCreatePath,null,"127.0.0.1");
        return containerMoveParam;
    }
    public int containerMove(Map<String, List<Map<String, String>>> containerMoveParam) throws IOException {
        return doHttpRequest(containerMoveParam,"容器入场任务下发",url, containerMoveInPath,null,"127.0.0.1");
    }
    private void getRequestParam(AgvTaskCreateParam agvTaskCreateParam,List<AgvWrkMast> agvWrkMastList,List<Map<String,String>> positionCodeMapList){
        List<AgvTaskParam> agvTaskParamList = agvWrkMastList.stream().map(agvWrkMast -> {
            AgvTaskParam agvTaskParam = new AgvTaskParam();
            AgvTaskkDescribeParam agvTaskkDescribeParam = new AgvTaskkDescribeParam();
@@ -71,50 +93,42 @@
        }).collect(Collectors.toList());
        agvTaskCreateParam.setTasks(agvTaskParamList);
    }
    private int doHttpRequest(Object requestParam, String namespace, String url, String path, String appkey, String ip){
        String response = "";
        boolean success = false;
        try {
            response = new HttpHandler.Builder()
                    .setUri("localhost:8080")
                    .setPath("test/task/create")
                    .setJson(JSONObject.toJSONString(agvTaskCreateParam))
                    .setUri(url)
                    .setPath(path)
                    .setJson(JSONObject.toJSONString(requestParam))
                    .build()
                    .doPost();
            JSONObject jsonObject = JSON.parseObject(response);
            int code = (int) jsonObject.get("code");
            if(code != 0){
                throw new CoolException("调用AGV响应错误");
            }
            success = true;
            return code;
        }catch (Exception e){
            log.error(e.getMessage());
            throw new CoolException("调用AGV响应错误");
        }finally {
//            apiLogService.save(
//                    "上架任务下发",
//                    url + path,
//                    null,
//                    "127.0.0.1",
//                    JSON.toJSONString(requestMap),
//                    response,
//                    success
//            );
            apiLogService.save(
                    namespace,
                    url + path,
                    appkey,
                    ip,
                    JSON.toJSONString(JSONObject.toJSONString(requestParam)),
                    response,
                    success
            );
        }
        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");
    }
}