package com.zy.asrs.task;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.core.exception.CoolException;
|
import com.zy.asrs.entity.TaskWrk;
|
import com.zy.asrs.entity.TaskWrkLog;
|
import com.zy.asrs.service.ApiLogService;
|
import com.zy.asrs.service.TaskWrkService;
|
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.HashMap;
|
import java.util.List;
|
|
@Slf4j
|
@Component
|
public class AssignTasksRCSScheduler {
|
@Autowired
|
private TaskWrkService taskWrkService;
|
@Autowired
|
private ApiLogService apiLogService;
|
@Value("${wcs.urlWcs}")
|
private String wcsUrl;
|
@Value("${wcs.movePathWcs}")
|
private String wcsmovePath;
|
@Value("${wcs.outboundTaskRequest}")
|
private String wcsoutboundTaskRequest;
|
@Value("${wcs.inboundTaskApplyPathWcs}")
|
private String wcsInboundTaskApplyPathWcs;
|
@Value("${wms.TaskExecCallback}")
|
private String TaskExecCallback;
|
@Value("${wms.taskStatusFeedbackPath}")
|
private String taskStatusFeedbackPath;
|
|
/**
|
* 自动派发移库任务给RCS
|
*/
|
@Scheduled(cron = "0/3 * * * * ? ")
|
public void executeMove() {
|
List<TaskWrk> taskWrks = taskWrkService.selectList(new EntityWrapper<TaskWrk>()
|
.eq("wrk_sts", 1).eq("io_type", 3));
|
for (TaskWrk taskWrk : taskWrks) {
|
HashMap<String, Object> headParam = new HashMap<>();
|
String response = "";
|
boolean bool = false;
|
try {
|
headParam.put("taskNo", taskWrk.getTaskNo());
|
headParam.put("sourceLocNo", taskWrk.getStartPoint());//源库位
|
headParam.put("locNo", taskWrk.getTargetPoint());//目标库位
|
log.info("wcs派发任务给RCS移库={}", taskWrk);
|
response = new HttpHandler.Builder()
|
// .setHeaders(headParam)
|
.setUri(wcsUrl)
|
.setPath(wcsmovePath)
|
.setJson(JSON.toJSONString(headParam))
|
.build()
|
.doPost();
|
JSONObject jsonObject = JSON.parseObject(response);
|
if (jsonObject.get("code").equals(200)) {
|
//派发出库任务给RCS==>成功下发移库任务
|
taskWrk.setWrkSts(2);
|
taskWrkService.updateById(taskWrk);
|
bool = true;
|
}
|
} catch (Exception e) {
|
log.error("wcs派发任务给RCS移库失败{},返回值={}", taskWrk, response);
|
} finally {
|
apiLogService.save("wcs派发任务给RCS移库"
|
, wcsUrl + wcsmovePath
|
, null
|
, "127.0.0.1"
|
, JSON.toJSONString(headParam)
|
, response
|
, bool
|
);
|
}
|
}
|
}
|
|
/**
|
* 自动派发出库任务给RCS
|
*/
|
@Scheduled(cron = "0/3 * * * * ? ")
|
public void executeOut() {
|
List<TaskWrk> taskWrks = taskWrkService.selectList(new EntityWrapper<TaskWrk>()
|
.eq("wrk_sts", 11).eq("io_type", 2));
|
for(TaskWrk taskWrk:taskWrks){
|
HashMap<String, Object> headParam = new HashMap<>();
|
String response = "";
|
boolean bool = false;
|
try {
|
headParam.put("taskNo", taskWrk.getTaskNo());
|
headParam.put("sourceLocNo",taskWrk.getStartPoint());//源库位
|
headParam.put("staNo",taskWrk.getTargetPoint());//目标站
|
log.info("wcs派发任务给RCS出库={}", taskWrk);
|
response = new HttpHandler.Builder()
|
.setUri(wcsUrl)
|
.setPath(wcsoutboundTaskRequest)
|
.setJson(JSON.toJSONString(headParam))
|
.build()
|
.doPost();
|
JSONObject jsonObject = JSON.parseObject(response);
|
if(jsonObject.get("code").equals(200)){
|
//派发出库任务给RCS==>成功下发出库任务
|
taskWrk.setWrkSts(12);
|
taskWrkService.updateById(taskWrk);
|
bool = true;
|
}
|
} catch (Exception e) {
|
log.error("wcs派发任务给RCS出库失败{},返回值={}", taskWrk, response);
|
} finally {
|
apiLogService.save("wcs派发任务给RCS出库"
|
, wcsUrl + wcsoutboundTaskRequest
|
, null
|
, "127.0.0.1"
|
, JSON.toJSONString(headParam)
|
, response
|
, bool
|
);
|
}
|
}
|
}
|
|
/**
|
* 自动派发入库任务给RCS
|
*/
|
@Scheduled(cron = "0/3 * * * * ? ")
|
public void executeIn() {
|
List<TaskWrk> taskWrks = taskWrkService.selectList(new EntityWrapper<TaskWrk>()
|
.eq("wrk_sts", 1).eq("io_type", 1));
|
for(TaskWrk taskWrk:taskWrks){
|
HashMap<String, Object> headParam = new HashMap<>();
|
String response = "";
|
boolean bool = false;
|
try {
|
headParam.put("taskNo", taskWrk.getTaskNo());
|
headParam.put("sourceStaNo",taskWrk.getOriginStartPoint());//源站
|
headParam.put("staNo",taskWrk.getOriginTargetPoint());//目标站
|
headParam.put("locNo",taskWrk.getTargetPoint());//目标库位
|
|
log.info("wcs派发任务给RCS入库={}", taskWrk);
|
response = new HttpHandler.Builder()
|
.setUri(wcsUrl)
|
.setPath(wcsInboundTaskApplyPathWcs)
|
.setJson(JSON.toJSONString(headParam))
|
.build()
|
.doPost();
|
JSONObject jsonObject = JSON.parseObject(response);
|
if(jsonObject.get("code").equals(200)){
|
//派发出库任务给RCS==>成功下发入库任务
|
taskWrk.setWrkSts(2);
|
taskWrkService.updateById(taskWrk);
|
bool = true;
|
}
|
} catch (Exception e) {
|
log.error("wcs派发任务给RCS入库失败{},返回值={}", taskWrk, response);
|
} finally {
|
apiLogService.save("wcs派发任务给RCS入库"
|
, wcsUrl + wcsInboundTaskApplyPathWcs
|
, null
|
, "127.0.0.1"
|
, JSON.toJSONString(headParam)
|
, response
|
, bool
|
);
|
}
|
}
|
}
|
|
}
|