自动化立体仓库 - WCS系统
1
zhangc
2025-04-16 e83761d390b593cff8b7c17144529e92eb482bd6
src/main/java/com/zy/asrs/task/NotifyScheduler.java
@@ -4,6 +4,8 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zy.asrs.domain.NotifyDto;
import com.zy.asrs.entity.HttpRequestLog;
import com.zy.asrs.service.HttpRequestLogService;
import com.zy.asrs.utils.NotifyUtils;
import com.zy.common.utils.HttpHandler;
import com.zy.common.utils.RedisUtil;
@@ -18,6 +20,7 @@
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
@Component
@@ -32,6 +35,8 @@
    private SlaveProperties slaveProperties;
    @Autowired
    private ConfigService configService;
    @Autowired
    private HttpRequestLogService httpRequestLogService;
    @Scheduled(cron = "0/3 * * * * ? ")
    public synchronized void notifyShuttle(){
@@ -45,6 +50,11 @@
        for (ForkLiftSlave slave : slaveProperties.getForkLift()) {
            notifyMsg(String.valueOf(SlaveType.ForkLift), slave.getId());
        }
    }
    @Scheduled(cron = "0/3 * * * * ? ")
    public synchronized void notifyTask(){
        notifyMsg("task", 1);
    }
    private synchronized void notifyMsg(String notifyType, Integer device) {
@@ -89,6 +99,11 @@
                continue;
            }
            HttpRequestLog httpRequestLog = new HttpRequestLog();
            httpRequestLog.setName(notifyUri + notifyUriPath);
            httpRequestLog.setRequest(JSON.toJSONString(notifyDto));
            httpRequestLog.setCreateTime(new Date());
            try {
                //触发通知
                String response = new HttpHandler.Builder()
@@ -97,15 +112,21 @@
                        .setJson(JSON.toJSONString(notifyDto))
                        .build()
                        .doPost();
                httpRequestLog.setResponse(response);
                JSONObject jsonObject = JSON.parseObject(response);
                Integer code = jsonObject.getInteger("code");
                if(code == 200){
                    //通知成功
                    redisUtil.del(key);
                    continue;
                }
            }catch (Exception e){
                e.printStackTrace();
            }finally {
                //保存记录
                httpRequestLogService.insert(httpRequestLog);
            }
            //通知失败