自动化立体仓库 - WMS系统
zhangc
2025-01-10 1da002910c1d9d44cd195bd24d951b4942a4e29c
src/main/java/com/zy/asrs/controller/AgvWarnController.java
@@ -5,6 +5,7 @@
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.annotations.AppAuth;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.zy.asrs.entity.AgvWarn;
import com.zy.asrs.entity.AgvWrkMast;
import com.zy.asrs.entity.param.AgvWarnBody;
@@ -12,11 +13,13 @@
import com.zy.asrs.service.AgvWarnService;
import com.zy.asrs.service.AgvWrkMastService;
import com.zy.asrs.service.ApiLogService;
import com.zy.asrs.utils.AppAuthUtil;
import com.zy.common.web.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@@ -40,6 +43,7 @@
 */
@Slf4j
@RestController
@RequestMapping("/agv")
public class AgvWarnController extends BaseController {
@@ -58,24 +62,31 @@
    @AppAuth(memo = "AGV告警回调")
    public Object taskEventStaus(@RequestBody AgvWarnCallBackParam param, HttpServletRequest request) {
        log.info("AGV告警回调:{}", JSON.toJSONString(param));
        List<AgvWarnBody> data = param.getData();
        AppAuthUtil.auth("", param, request);
        List<AgvWarnBody> agvWarnBodies = param.getData();
        //  List<AgvWarnBody> agvWarnBodies = JSONArray.parseArray(data, AgvWarnBody.class);
        AgvWarn agvWarn = null;
        List<AgvWarn> agvWarns = new ArrayList<>();
        List<AgvWarn> updates = new ArrayList<>();
        for (AgvWarnBody body : data) {
            List<AgvWarn> agvWarnList = agvWarnService.selectList(new EntityWrapper<AgvWarn>().eq("robot_code", body.getRobotCode()).eq("begin_time", body.getBeginTime()));
        for (AgvWarnBody body : agvWarnBodies) {
            List<AgvWarn> agvWarnList = agvWarnService.selectList(new EntityWrapper<AgvWarn>().eq("robot_code", body.getRobotCode()).eq("begin_time", body.getBeginDate()).eq("warn_content", body.getWarnContent()));
            if (Cools.isEmpty(agvWarnList)) {
                agvWarn = new AgvWarn();
                agvWarn.setBeginTime(body.getBeginTime());
                agvWarn.setBeginTime(body.getBeginDate());
                agvWarn.setAppeTime(new Date());
                agvWarn.setTimes(0);
                agvWarn.setModiTime(DateUtils.convert(body.getBeginDate(), DateUtils.yyyyMMddHHmmss_F));
                agvWarn.setRobotCode(body.getRobotCode());
                agvWarn.setWarnContent(body.getWarnContent());
                if (body.getTaskCode() != null) {
                    AgvWrkMast agvWrkMast = agvWrkMastService.selectById(body.getTaskCode());
                    if (agvWrkMast != null) {
                        agvWarn.setLocNo(agvWrkMast.getLocNo());
                        agvWarn.setSourceLocNo(agvWrkMast.getSourceLocNo());
                    try {
                        AgvWrkMast agvWrkMast = agvWrkMastService.selectById(Math.abs(Integer.parseInt(body.getTaskCode())));
                        if (agvWrkMast != null) {
                            agvWarn.setLocNo(agvWrkMast.getLocNo());
                            agvWarn.setSourceLocNo(agvWrkMast.getSourceLocNo());
                        }
                    } catch (Exception e) {
                        log.info("任务不存在");
                    }
                }
                agvWarns.add(agvWarn);
@@ -84,10 +95,14 @@
                agvWarn.setWarnContent(agvWarn.getWarnContent().contains(body.getWarnContent()) ? body.getWarnContent() : agvWarn.getWarnContent() + "、" + body.getWarnContent());
                agvWarn.setModiTime(new Date());
                if (body.getTaskCode() != null) {
                    AgvWrkMast agvWrkMast = agvWrkMastService.selectById(body.getTaskCode());
                    if (agvWrkMast != null) {
                        agvWarn.setLocNo(agvWrkMast.getLocNo());
                        agvWarn.setSourceLocNo(agvWrkMast.getSourceLocNo());
                    try {
                        AgvWrkMast agvWrkMast = agvWrkMastService.selectById(body.getTaskCode());
                        if (agvWrkMast != null) {
                            agvWarn.setLocNo(agvWrkMast.getLocNo());
                            agvWarn.setSourceLocNo(agvWrkMast.getSourceLocNo());
                        }
                    } catch (Exception e) {
                        log.info("任务不存在");
                    }
                }
                updates.add(agvWarn);
@@ -100,20 +115,20 @@
            agvWarnService.updateBatchById(updates);
        }
        Map<String, Object> result = new HashMap<>();
        logPost(param, JSONObject.toJSONString(result), true);
        logPost(JSONObject.toJSONString(param), JSONObject.toJSONString(result), true);
        result.put("code", 0);
        result.put("message", "成功");
        result.put("reqCode", param.getReqCode());
        return result;
    }
    private void logPost(AgvWarnCallBackParam param, String response, boolean success) {
    private void logPost(String param, String response, boolean success) {
        apiLogService.save(
                "ESS任务回调",
                "/phyzwms/agv/task/event/status",
                null,
                null,
                JSONObject.toJSONString(param),
                param,
                response,
                success
        );