Administrator
昨天 7aef672d9920e76f2a22bb03d08eafc64e075536
src/main/java/com/zy/asrs/task/TaskReportScheduler.java
@@ -31,11 +31,14 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * 定时将任务(完成、取消)转成日志
@@ -63,6 +66,9 @@
    @Value("${wms.completeDevpTask}")
    private String completeDevpTask;
    @Value("${wms.reportPalletizingCompleted}")
    private String reportPalletizingCompleted;
    @Resource
    private TaskWrkMapper taskWrkMapper;
@@ -80,6 +86,120 @@
        add(301);add(302);add(303);add(304);add(305);add(306);add(307);add(308);
    }};
    // 侧面码盘完成上报wms
    @Scheduled(cron = "0/3 * * * * ? ")
    public synchronized void reportPalletizingCompleted() {
        DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 1);
        if (devpThread != null) {
            Map<Integer, StaProtocol> staProtocolMap = devpThread.getStation();
            int[] siteArray = new int[]{203, 207, 212};
            for (int site : siteArray) {
                StaProtocol staProtocol = staProtocolMap.get(site);
                if (staProtocol != null) {
                    short mpCompletedFlag = staProtocol.getMpCompletedFlag();
                    if (mpCompletedFlag == 1) {
                        TaskWrk taskWrk = taskWrkMapper.selectByWrkNo(Integer.valueOf(staProtocol.getWorkNo()));
                        if (taskWrk != null && taskWrk.getMp() == 1) {
                            // 请求体
                            JSONObject request = new JSONObject();
                            request.put("site", site);
                            String response = "";
                            boolean bool = false;
                            try {
                                response = new HttpHandler.Builder()
                                        // .setHeaders(headParam)
                                        .setUri(wmsUrl)
                                        .setPath(reportPalletizingCompleted)
                                        .setJson(JSON.toJSONString(request))
                                        .build()
                                        .doPost();
                                if (!Cools.isEmpty(response)) {
                                    JSONObject jsonObject = JSON.parseObject(response);
                                    if (Integer.parseInt(String.valueOf(jsonObject.get("code"))) == 200) {
                                        bool = true;
                                        // 推送队列
                                        boolean offer = MessageQueue.offer(SlaveType.Devp, 4, new Task(1, staProtocol));
                                        if (offer) {
                                            // 更新数据库
                                            taskWrk.setMpCompletedReport(1);
                                            taskWrkMapper.updateById(taskWrk);
                                        } else {
                                            log.error("侧面码盘完成上报wms推送队列失败,站点:{},任务号:{}", site, staProtocol.getWorkNo());
                                        }
                                    }
                                }
                            } catch (Exception e) {
                                log.error("侧面码盘完成上报wms失败{},返回值={}", taskWrk, response);
                            } finally {
                                apiLogService.save("侧面码盘完成上报wms"
                                        , wmsUrl + reportPalletizingCompleted
                                        , null
                                        , "127.0.0.1"
                                        , JSON.toJSONString(request)
                                        , response
                                        , bool
                                );
                            }
                        }
                    }
                }
            }
        }
    }
    // WMS分配入库库位异常上报
    @Scheduled(cron = "0/5 * * * * ? ")
    @Transactional
    public synchronized void locationAssignmentExceptionEscalation() {
        List<TaskWrk> taskWrkList = taskWrkMapper.selectList(new EntityWrapper<TaskWrk>().eq("wrk_sts", 5));
        for(TaskWrk taskWrk : taskWrkList) {
            Date now = new Date();
            WmsFeedback wmsFeedback = new WmsFeedback();
            wmsFeedback.setTaskNo(taskWrk.getTaskNo());
            wmsFeedback.setIoType(taskWrk.getIoType());
            wmsFeedback.setBarcode(taskWrk.getBarcode());
            wmsFeedback.setStatus(-1); // 入库库位分配异常
            wmsFeedback.setReportTime(DateUtils.convert(now));
            String response = "";
            boolean bool = false;
            try {
                log.info("入库wms分配库位有误上报wms={}", taskWrk);
                response = new HttpHandler.Builder()
                        // .setHeaders(headParam)
                        .setUri(wmsUrl)
                        .setPath(TaskExecCallback)
                        .setJson(JSON.toJSONString(wmsFeedback))
                        .build()
                        .doPost();
                if (!Cools.isEmpty(response)) {
                    JSONObject jsonObject = JSON.parseObject(response);
                    if (Integer.parseInt(String.valueOf(jsonObject.get("code"))) == 200) {
                        bool = true;
                        taskWrk.setWrkSts(6);
                        taskWrk.setModiTime(now);
                        taskWrkMapper.updateById(taskWrk);
                    }
                }
            } catch (Exception e) {
                log.error("入库wms分配库位有误上报wms失败{},返回值={}", taskWrk, response);
            } finally {
                apiLogService.save("wms分配库位有误上报"
                        , wmsUrl + TaskExecCallback
                        , null
                        , "127.0.0.1"
                        , JSON.toJSONString(wmsFeedback)
                        , response
                        , bool
                );
            }
        }
    }
    @Scheduled(cron = "0/5 * * * * ? ")
    public synchronized void execute() throws IOException {
        Page<TaskWrkReport> taskWrkReportPage = taskWrkReportService.selectPage(new Page<>(0, 100), new EntityWrapper<TaskWrkReport>().orderBy("create_time", true));