package com.zy.asrs.task;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.core.exception.CoolException;
|
import com.zy.asrs.domain.enums.TaskStatusType;
|
import com.zy.asrs.entity.LocMast;
|
import com.zy.asrs.entity.TaskWrk;
|
import com.zy.asrs.entity.TaskWrkLog;
|
import com.zy.asrs.service.*;
|
import com.zy.asrs.service.impl.TaskWrkLogServiceImpl;
|
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.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import java.io.IOException;
|
import java.util.Date;
|
import java.util.HashMap;
|
|
/**
|
* 定时将完成任务上报给wms
|
*/
|
@Slf4j
|
@Component
|
public class TaskMastScheduler {
|
@Autowired
|
private TaskWrkService taskWrkService;
|
@Autowired
|
private CommandInfoService commandInfoService;
|
@Autowired
|
private ApiLogService apiLogService;
|
@Autowired
|
private BasDevpService basDevpService;
|
|
@Autowired
|
private StaDescService staDescService;
|
@Autowired
|
private LocMastService locMastService;
|
@Autowired
|
private TaskWrkLogServiceImpl wrkLogService;
|
|
@Value("${wms.url}")
|
private String wmsUrl;
|
@Value("${wms.movePath}")
|
private String movePath;
|
@Value("${wms.inboundTaskApplyPath}")
|
private String inboundTaskApplyPath;
|
@Value("${wms.TaskExecCallback}")
|
private String TaskExecCallback;
|
@Value("${wms.taskStatusFeedbackPath}")
|
private String taskStatusFeedbackPath;
|
|
/**
|
* 定时将完成任务上报给wms
|
* 出库到目标站点
|
*/
|
@Scheduled(cron = "0/3 * * * * ? ")
|
public void execute() throws IOException {
|
for (TaskWrk taskWrk : taskWrkService.selectToBeHistoryData()) {
|
HashMap<String, Object> headParam = new HashMap<>();
|
String s = "";//日志标识
|
if (taskWrk.getWrkSts() == 6) {//入库完成
|
headParam.put("Result", 1);
|
s = "入库完成";
|
taskWrk.setWrkSts(7);//入库任务转历史档6--》7
|
} else if (taskWrk.getWrkSts() == 16) {//出库完成-待搬离
|
headParam.put("Result", 1);
|
s = "出库完成-待搬离";
|
taskWrk.setWrkSts(17);//出库任务16--》17
|
} else if (taskWrk.getStatus().equals(4)) {//取消任务上报wms
|
s = "取消";
|
taskWrk.setStatus(5);//取消任务
|
headParam.put("Result", 2);
|
} else if (taskWrk.getStatus().equals(6)) {//完结任务上报wms
|
s = "手动完成";
|
taskWrk.setStatus(7);//完结
|
headParam.put("Result", 1);
|
}
|
String response = "";
|
Boolean bool = false;
|
try {
|
headParam.put("TaskNo", taskWrk.getTaskNo());
|
log.info("wcs" + s + "任务上报wms={}", taskWrk);
|
response = new HttpHandler.Builder()
|
// .setHeaders(headPraam)
|
.setUri(wmsUrl)
|
.setPath(TaskExecCallback)
|
.setJson(JSON.toJSONString(headParam))
|
.build()
|
.doPost();
|
JSONObject jsonObject = JSON.parseObject(response);
|
if (jsonObject.get("ReturnStatus").equals("0")) {
|
taskWrkService.updateById(taskWrk);
|
bool = true;
|
}
|
} catch (Exception e) {
|
log.error("wcs" + s + "任务上报wms失败={},返回值={}", taskWrk, response);
|
} finally {
|
apiLogService.save("wcs" + s + "任务上报wms"
|
, wmsUrl + TaskExecCallback
|
, null
|
, "127.0.0.1"
|
, JSON.toJSONString(headParam)
|
, response
|
, bool
|
);
|
}
|
}
|
}
|
}
|