whycxzp
2025-04-23 abccd023bae40d5d8ad2fcdbf848b4240928414d
src/main/java/com/whyc/service/WmsService.java
@@ -5,14 +5,12 @@
import com.google.gson.reflect.TypeToken;
import com.whyc.dto.*;
import com.whyc.pojo.db_abe_ram.AbeInf;
import com.whyc.pojo.db_param.PageParam;
import com.whyc.pojo.db_wms.Task;
import com.whyc.util.HttpUtil;
import com.whyc.util.JsonUtil;
import com.whyc.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.applet.Main;
import java.util.Date;
import java.util.HashMap;
@@ -64,29 +62,78 @@
            String dataStr = (String) response.getData();
            WmsResponse responseInside = JsonUtil.getGson().fromJson(dataStr, WmsResponse.class);
            response.set(1,responseInside);
            //对下发的任务进行数据库存储
            Date date = new Date();
            List<String> pallets = palletDto.getPallets();
            List<String> taskNos = responseInside.getTask_no();
            for (int i = 0; i < pallets.size(); i++) {
                String pallet = pallets.get(i);
                String taskNo = taskNos.get(i);
            if(responseInside.getCode() ==0) {
                //对下发的任务进行数据库存储
                Date date = new Date();
                List<String> pallets = palletDto.getPallets();
                List<String> taskNos = responseInside.getTask_no();
                for (int i = 0; i < pallets.size(); i++) {
                    String pallet = pallets.get(i);
                    String taskNo = taskNos.get(i);
                    Task task = new Task();
                    task.setTaskNo(taskNo);
                    task.setPallets(pallet);
                    task.setDes(palletDto.getDes());
                    if (palletDto.getDes() == 3) { //活化,填入活化参数
                        List<String> activateParameter = palletDto.getActivateParameter();
                        task.setActivateParameter(String.join(",", activateParameter));
                    }
                    task.setCreateTime(date);
                    taskService.add(task);
                }
            }
        }
        return response;
    }
    public Response sendTaskInbound(WmsTaskDto taskDto) {
        String httpUrl = "http://192.168.10.133:8051"+"/api/wms_task/inbound";
        Response response = HttpUtil.doPost(httpUrl, JsonUtil.getGson().toJson(taskDto));
        //对结果进行处理
        if(response.getCode() == 1){ //请求成功,data有正常数据
            String dataStr = (String) response.getData();
            WmsTaskResponse responseInside = JsonUtil.getGson().fromJson(dataStr, WmsTaskResponse.class);
            response.set(1,responseInside);
            if(responseInside.getCode() ==0) {
                //对下发的任务进行数据库存储
                Date date = new Date();
                String pallet = taskDto.getPallet_code();
                String startLocationCode = taskDto.getStartlocation_code();
                //1=搬运空托,2=搬运电池. 转化到字段Des中,1001=搬运空托,1002=搬运电池
                Integer type = taskDto.getType();
                String taskNo = responseInside.getTask_no();
                Task task = new Task();
                task.setTaskNo(taskNo);
                task.setPallets(pallet);
                task.setDes(palletDto.getDes());
                task.setStartLocationCode(startLocationCode);
                task.setDes(type ==1?1001:1002);
                if(palletDto.getDes()==3) { //活化,填入活化参数
                    List<String> activateParameter = palletDto.getActivateParameter();
                    task.setActivateParameter(String.join(",", activateParameter));
                }
                task.setCreateTime(date);
                taskService.add(task);
            }
        }
        return response;
    }
    public Response cancelTask(WmsTaskCancelDto stopDto) {
        String httpUrl = "http://192.168.10.133:8051"+"/api/wms_task/force_send";
        Response response = HttpUtil.doPost(httpUrl, JsonUtil.getGson().toJson(stopDto));
        //对结果进行处理
        if(response.getCode() == 1){ //请求成功,data有正常数据
            String dataStr = (String) response.getData();
            WmsResponseTaskCancelDto responseInside = JsonUtil.getGson().fromJson(dataStr, WmsResponseTaskCancelDto.class);
            response.set(1,responseInside);
            /*if(responseInside.getCode() ==0) {
            }*/
        }
        return response;
    }
@@ -131,10 +178,16 @@
    }
    public Response sendTaskStatus(TaskDto taskDto) {
        String taskNo = taskDto.getTask_no();
        //通过taskNo从数据库查找对应的记录
        Task taskInDB = taskService.getByTaskNo(taskNo);
        if(taskInDB == null){
            return new Response<>().setII(1,"任务上报失败,无法定位到任务,任务可能不是通过监控平台下发");
        }
        Task task = new Task();
        task.setTaskNo(taskDto.getTask_no());
        task.setTaskNo(taskNo);
        task.setTaskType(taskDto.getTask_type());
        //TODO 这个地方起始点的定义,运行过程中需要关注,以及编码对应的具体位置,需要他们提供
        //这个地方起始点的定义,运行过程中需要关注,以及编码对应的具体位置,需要他们提供
        task.setStartLocationCode(taskDto.getStart_location_code());
        task.setEndLocationCode(taskDto.getEnd_location_code());
@@ -142,7 +195,7 @@
        task.setStatusTime(ThreadLocalUtil.parse(taskDto.getStatus_time(),1));
        //对接收到的任务进行逻辑判断和数据存储
        String taskNo = task.getTaskNo();
        //String taskNo = task.getTaskNo();
        //taskType=4,入库测压任务,这个为仓储自动触发的任务,非主动平台下达,
        // 需要手动添加任务类型,和电池组编号
        Integer taskType = task.getTaskType();
@@ -167,7 +220,7 @@
                if(pallet == null){
                    pallet = taskService.getByTaskNo(taskNo).getPallets();
                }*/
                String pallet = taskService.getByTaskNo(taskNo).getPallets();
                String pallet = taskInDB.getPallets();
                //更新电池单体编号和任务编号
                AbeInf abeInf = abeInfService.get();
                abeInf.setAbeMonId(Integer.valueOf(pallet));
@@ -177,7 +230,11 @@
                task.setActivationChamberStartTime(statusTime);
            }break;
            case 14:
                task.setActivationChamberPickUpTime(statusTime);break;
            case 24:
                //测压任务,开始取测压结束的电池. 读取abe_inf表中的内阻,插入到任务里
                AbeInf abeInf = abeInfService.get();
                task.setNowMonRes(abeInf.getNowMonRes());
                task.setActivationChamberPickUpTime(statusTime);break;
            case 15:
            case 25: