kj-wcs的生产区入库校验

main
zxh 7 months ago
parent eca9f6727d
commit 3b1890b526
  1. 6
      shkj-admin/src/main/resources/application-pro.yml
  2. 90
      shkj-wms/src/main/java/com/shkj/wcs/controller/busin/WcsTaskController.java
  3. 262
      shkj-wms/src/main/java/com/shkj/wcs/third/workbinWcs/WCSUtil.java
  4. 2
      shkj-wms/src/main/java/com/shkj/wcs/third/workbinWcs/dto/WcsIncomingTrayCheckBody.java
  5. 14
      shkj-wms/src/main/java/com/shkj/wcs/vo/WcsResponseVo.java

@ -83,3 +83,9 @@ spring:
max-active: 8
# #连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1ms
ZKWJ:
# 中科wcs接口
wcsIncomingTrayCheckUrl: http://172.168.61.200:18990/api/toWzWcs/wcsIncomingTrayCheck
wcsCancelTaskUrl: http://172.168.61.200:18990/api/wms/wmsTask/changeTaskStatus
wcsPushNewPointUrl: http://172.168.61.200:18990/api/wms/stacker/setStackerTaskNewDestination

@ -1,5 +1,7 @@
package com.shkj.wcs.controller.busin;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shkj.common.annotation.Log;
import com.shkj.common.annotation.RepeatSubmit;
@ -12,13 +14,18 @@ import com.shkj.wcs.vo.WcsResponseVo;
import com.shkj.wcs.domain.BusinDataTask;
import com.shkj.wms.service.IBusinTaskService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@RequiredArgsConstructor(onConstructor_ =@Autowired)
@RestController
@RequestMapping("/api")
@ -31,14 +38,14 @@ public class WcsTaskController {
/**
* wz-wcs任务下发
*/
@Log(title = "wz-wcs任务下发",businessType = BusinessType.UPDATE)
@Log(title = "wz-wcs任务下发", businessType = BusinessType.UPDATE)
@PostMapping("/toKjWcs/commonApi")
@RepeatSubmit
public WcsResponseVo commonApi(WcsCreateTaskDto bo){
if(bo != null){
public WcsResponseVo commonApi(WcsCreateTaskDto bo) {
if (bo != null) {
List<WcsCreateTaskBody> body = bo.getBody();
if(!body.isEmpty()){
for(WcsCreateTaskBody by : body){
if (!body.isEmpty()) {
for (WcsCreateTaskBody by : body) {
String taskId = by.getTaskId();
String trayCode = by.getTrayCode();
String taskType = by.getTaskType();
@ -47,12 +54,12 @@ public class WcsTaskController {
String dataChange = by.getDataChange();
String priority = by.getPriority();
LambdaQueryWrapper<BusinDataTask> lqwDataTask = new LambdaQueryWrapper<BusinDataTask>()
.eq(BusinDataTask::getContainerId,trayCode)
.in(BusinDataTask::getTaskStatus,"1","2");
.eq(BusinDataTask::getContainerId, trayCode)
.in(BusinDataTask::getTaskStatus, "1", "2");
BusinDataTask one = iBusinDataTaskService.getOne(lqwDataTask);
if(dataChange.equals("1")){
if (one != null){
return WcsResponseVo.error(500,"该托盘"+trayCode+"存在未完成的任务");
if (dataChange.equals("1")) {
if (one != null) {
return WcsResponseVo.error(500, "该托盘" + trayCode + "存在未完成的任务");
}
BusinDataTask businDataTask = new BusinDataTask();
businDataTask.setTaskCode(taskId);
@ -63,13 +70,66 @@ public class WcsTaskController {
businDataTask.setCreateTime(DateUtils.getNowDate());
businDataTask.setPriority(priority);
boolean save = iBusinDataTaskService.save(businDataTask);
if(save){
if (save) {
//调用下游接口下任务
}
}else if(dataChange.equals("2")){
if (one == null){
return WcsResponseVo.error(500,"未查询到该托盘"+trayCode+"存在未完成的任务");
} else if (dataChange.equals("2")) {
if (one == null) {
return WcsResponseVo.error(500, "未查询到该托盘" + trayCode + "存在未完成的任务");
}
one.setTaskStatus("6");
iBusinDataTaskService.updateById(one);
//推送给下游
}
}
}
}
return WcsResponseVo.success();
}
@Log(title = "wz-wcs任务下发", businessType = BusinessType.UPDATE)
@PostMapping("/toWzWcs/wcsIncomingTrayCheck")
@RepeatSubmit
public WcsResponseVo wcsIncomingTrayCheck(WcsCreateTaskDto bo) {
if (bo != null) {
List<WcsCreateTaskBody> body = bo.getBody();
if (!body.isEmpty()) {
for (WcsCreateTaskBody by : body) {
String taskId = by.getTaskId();
String trayCode = by.getTrayCode();
String taskType = by.getTaskType();
String fromBinCode = by.getFromBinCode();
String toBinCode = by.getToBinCode();
String dataChange = by.getDataChange();
String priority = by.getPriority();
LambdaQueryWrapper<BusinDataTask> lqwDataTask = new LambdaQueryWrapper<BusinDataTask>()
.eq(BusinDataTask::getContainerId, trayCode)
.in(BusinDataTask::getTaskStatus, "1", "2");
BusinDataTask one = iBusinDataTaskService.getOne(lqwDataTask);
if (dataChange.equals("1")) {
if (one != null) {
return WcsResponseVo.error(500, "该托盘" + trayCode + "存在未完成的任务");
}
BusinDataTask businDataTask = new BusinDataTask();
businDataTask.setTaskCode(taskId);
businDataTask.setTaskType(taskType);
businDataTask.setContainerId(Long.valueOf(trayCode));
businDataTask.setFromSide(fromBinCode);
businDataTask.setToSide(toBinCode);
businDataTask.setCreateTime(DateUtils.getNowDate());
businDataTask.setPriority(priority);
boolean save = iBusinDataTaskService.save(businDataTask);
if (save) {
//调用下游接口下任务
}
} else if (dataChange.equals("2")) {
if (one == null) {
return WcsResponseVo.error(500, "未查询到该托盘" + trayCode + "存在未完成的任务");
}
one.setTaskStatus("6");
iBusinDataTaskService.updateById(one);
@ -83,3 +143,5 @@ public class WcsTaskController {
return WcsResponseVo.success();
}
}

@ -4,8 +4,7 @@ import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import com.shkj.common.constant.RedisConstant;
import com.shkj.common.core.domain.Result;
import com.shkj.plc.sdk.device.PLCReadAndWrite;
import com.shkj.plc.sdk.device.PlcOperate;
import com.shkj.system.service.ISysParameterService;
import com.shkj.wcs.bo.AGVStatesBo;
import com.shkj.wcs.bo.AGVUploadStatusBo;
@ -19,6 +18,9 @@ import com.shkj.wcs.third.rcs.dto.RcsCancelTaskDto;
import com.shkj.wcs.third.rcs.dto.RcsCreateTaskDto;
import com.shkj.wcs.third.rcs.dto.RcsIdList;
import com.shkj.wcs.third.rcs.dto.RcsThirdResult;
import com.shkj.wcs.third.workbinWcs.dto.WcsIncomingCheckDto;
import com.shkj.wcs.third.workbinWcs.dto.WcsIncomingTrayCheckBody;
import com.shkj.wcs.vo.WcsResponseVo;
import com.shkj.wms.bo.AGVMoveBo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -42,270 +44,54 @@ import java.util.Map;
@Component
public class WCSUtil {
@Value("${third.wcsIncomingTrayCheckUrl:}")
@Value("${ZKWZ.wcsIncomingTrayCheckUrl:}")
private String wcsIncomingTrayCheckUrl;
@Value("${third.agvCancelTaskUrl:}")
private String agvCancelTaskUrl;
@Value("${third.agvStatesUrl:}")
private String agvStatesUrl;
@Value("${third.queryAckByTaskUrl:}")
private String queryAckByTaskUrl;
@Autowired
BusinDataTaskMapper businDataTaskMapper;
@Resource
RedisTemplate redisTemplate;
@Autowired
IWcsPlcPropertyService iWcsPlcPropertyService;
@Autowired
PLCReadAndWrite plcReadAndWrite;
@Autowired
ISysParameterService isysParameterService;
@Autowired
IWcsPlcConnectService iWcsPlcConnectService;
@Autowired
PlcInit plcInit;
/**
* 设置头部信息
* WMS向WCS推送新的目的地
*
* @return {@code Map<String, String>}
* @param dto
* @return
*/
public Map<String, String> getHeaderMap() {
public WcsResponseVo wcsPushNewPoint(WcsIncomingCheckDto dto) {
Map<String, String> headerMap = new HashMap<>(1);
headerMap.put("authorization", "mrbase64 mrrest:YWRtaW4mYWRtaW4=");
return headerMap;
}
/**
* 创建任务
* wcs系统通过此接口向rcs系统下发创建任务指令
*
* @param dto dto
* @return {@code Result}
*/
public Result rcsCreateTask(RcsCreateTaskDto dto) {
headerMap.put("businessType", "trayCheck");
String json = JSONObject.toJSONString(dto);
log.info("KJ向WZ请求生产区入库托盘码校验参数"+json);
try {
Map<String, String> headerMap = getHeaderMap();
String res = HttpRequest.post(agvCreateTaskUrl)
String res = HttpRequest.post(wcsIncomingTrayCheckUrl)
.addHeaders(headerMap)
.body(json)
.execute().body();
Result result = parseThirdRcsResult(res);
return result;
log.info("KJ向WZ请求生产区入库托盘码校验返回:" + res);
WcsResponseVo wcsThirdResult = parseThirdRcsResult(res);
return wcsThirdResult;
} catch (Exception e) {
e.printStackTrace();
log.error("createTask 方法出错了 = {}", e.getMessage());
return Result.err().msg(e.getMessage());
}
}
/**
* 创建任务
* wcs系统通过此接口向rcs系统下发创建任务指令
*
* @param dto dto
* @return {@code Result}
*/
public Result wcsIncomingTrayCheck(Wcs dto) {
String json = JSONObject.toJSONString(dto);
try {
Map<String, String> headerMap = getHeaderMap();
String res = HttpRequest.post(agvCreateTaskUrl)
.addHeaders(headerMap)
.body(json)
.execute().body();
Result result = parseThirdRcsResult(res);
return result;
} catch (Exception e) {
e.printStackTrace();
log.error("createTask 方法出错了 = {}", e.getMessage());
return Result.err().msg(e.getMessage());
}
}
/**
* 放行任务
* wcs系统通过此接口向rcs系统下发放行任务指令
*
* @param dto dto
* @return {@code Result}
*/
public Result queryAck(RcsCreateTaskDto dto) {
String json = JSONObject.toJSONString(dto);
try {
Map<String, String> headerMap = getHeaderMap();
String res = HttpRequest.post(queryAckByTaskUrl)
.addHeaders(headerMap)
.body(json)
.execute().body();
return parseThirdRcsResult(res);
} catch (Exception e) {
e.printStackTrace();
log.error("放行 方法出错了 = {}", e.getMessage());
return Result.err().msg(e.getMessage());
log.error("KJ向WZ请求生产区入库托盘码校验 方法出错了 = {}", e.getMessage());
return WcsResponseVo.error(500,e.getMessage());
}
}
public Result parseThirdRcsResult(String res) {
public WcsResponseVo parseThirdRcsResult(String res) {
try {
res = res.trim();
RcsThirdResult thirdResult = JSONObject.parseObject(res, RcsThirdResult.class);
WcsResponseVo thirdResult = JSONObject.parseObject(res, WcsResponseVo.class);
if (thirdResult == null) {
// 添加到异常中去
return Result.err().msg(res);
return WcsResponseVo.error(500,res);
}
if (!RcsThirdResult.isOk(thirdResult)) {
return Result.err().msg(res);
if (!WcsResponseVo.isOk(thirdResult)) {
return WcsResponseVo.error(500,res);
}
return Result.ok();
return thirdResult;
} catch (Exception e) {
log.error("parseThirdRcsResult res = {} e = {}", res, e);
return Result.err().msg(res);
return WcsResponseVo.error(500,res);
}
}
/**
* 任务取消
* 上游系统调此接将已下发待处理的任务取消
*
* @param /rest/tasks/del
* @return {@code Result}
*/
public Result rcsTaskCancel(RcsCancelTaskDto dto) {
String json = JSONObject.toJSONString(dto);
try {
Map<String, String> headerMap = getHeaderMap();
String res = HttpRequest.post(agvCancelTaskUrl)
.addHeaders(headerMap)
.body(json)
.execute().body();
return parseThirdRcsResult(res);
} catch (Exception e) {
e.printStackTrace();
log.error("rcs taskCancel 方法出错了 = {}", e.getMessage());
return Result.err().msg(e.getMessage());
}
}
/**
* AGV搬运
*
* @param bo
* @return {@link Result}<{@link Boolean}>
*/
public Result<Boolean> moveByAGV(AGVMoveBo bo) {
RcsCreateTaskDto dto = new RcsCreateTaskDto();
dto.setMapId(1);
dto.setTaskType(bo.getTaskType());
dto.setTaskId(bo.getTaskId().toString());
//库位编号
List<RcsIdList> idList = new ArrayList<>();
List<String> points = bo.getPoints();
for (String point : points) {
RcsIdList rcsIdList = new RcsIdList();
rcsIdList.setId(point);
log.error(point);
idList.add(rcsIdList);
}
dto.setTargets(idList);
return rcsCreateTask(dto);
// return Result.ok();
}
/**
* 获取AGV实时状态信息
*
* @param mapId bo
* @return {@code Result}
*/
public Result rcsRobotsStates(String mapId) {
String json = JSONObject.toJSONString(mapId);
try {
Map<String, String> headerMap = getHeaderMap();
String res = HttpRequest.post(agvStatesUrl)
.addHeaders(headerMap)
.body(json)
.execute().body();
//获取AGV状态信息 推送前端及存储数据库及存储redis TODO
return parseThirdRcsResult(res);
} catch (Exception e) {
e.printStackTrace();
log.error("createTask 方法出错了 = {}", e.getMessage());
return Result.err().msg(e.getMessage());
}
}
/**
* AGV上报任务每一步状态
*
* @param bo bo
* @return {@code Result}
*/
public Result<AGVStatesBo> uploadAgvTaskStatus(AGVUploadStatusBo bo) {
Long plcId = (Long) redisTemplate.opsForValue().get(RedisConstant.redistaskPlc + bo.getTaskId().toString());
//根据plcId获取plc信息
WcsPlcConnect wcsplc = (WcsPlcConnect) redisTemplate.opsForValue().get(RedisConstant.redisPlcConnect + plcId);
List<WcsPlcProperty> propertyList = iWcsPlcPropertyService.getWcsPlcPropertyByPlcId(plcId);
String writeTaskId = "";
String valueType = "";
for (WcsPlcProperty wcsPlcProperty : propertyList) {
//AGV取走完成
if (wcsPlcProperty.getPointType().equals("7")) {
writeTaskId = wcsPlcProperty.getAddress();
valueType = wcsPlcProperty.getValueType();
}
}
Map<String, String> writeMap = new HashMap<>(1);
writeMap.put(valueType, "true");
Map<String, Object> allMap = new HashMap<>(1);
allMap.put(writeTaskId, writeMap);
Map<String, String> readMap = new HashMap<>(1);
readMap.put(writeTaskId, valueType);
PlcOperate plcOperate = plcInit.getPlcOperateByIp(wcsplc.getPlcIp());
//回填plc状态
PLCReadAndWrite plcReadAndWrite = new PLCReadAndWrite();
//首先读取任务编号,同目前返回的任务编号是否一致,如果一致则回填状态;
Map<String, Object> stringObjectMap = plcReadAndWrite.readPlcData(plcOperate, JSONObject.toJSONString(readMap));
//if(stringObjectMap.get(writeTaskId).equals(bo.getTaskId())){
plcReadAndWrite.execWrite(plcOperate, JSONObject.toJSONString(allMap));
//}
return Result.ok();
}
/**
* AGV上报任务每一步状态
*
* @param
* @return {@code Result}
*/
public Result uploadAgvTaskStatusTmp(AGVUploadStatusBo bo) {
return Result.ok();
}
}

@ -42,7 +42,7 @@ public class WcsIncomingTrayCheckBody implements Serializable {
/**
* 新增1
*/
private String bussinessType;
private String bussinessType ="trayCheck";
}

@ -40,6 +40,20 @@ public class WcsResponseVo<T> {
return response;
}
public static Boolean isOk(WcsResponseVo result) {
if (result == null){
return false;
}
Integer msgCode = result.getHeader().getMsgCode();
if (msgCode == null) {
return false;
}
if (msgCode == 200) {
return true;
}
return false;
}
// 错误响应
public static <T> WcsResponseVo<T> error(int code, String msg) {
WcsResponseVo<T> response = new WcsResponseVo<>();

Loading…
Cancel
Save