package com.vincent.rsf.openApi.service.impl;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.cfg.CoercionAction;
|
import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
|
import com.vincent.rsf.framework.common.R;
|
import com.vincent.rsf.openApi.config.PlatformProperties;
|
import com.vincent.rsf.openApi.entity.Loc;
|
import com.vincent.rsf.openApi.entity.constant.WmsConstant;
|
import com.vincent.rsf.openApi.entity.dto.CommonResponse;
|
import com.vincent.rsf.openApi.entity.params.WcsChangeLocParam;
|
import com.vincent.rsf.openApi.entity.params.WcsCreateInTaskParam;
|
import com.vincent.rsf.openApi.entity.params.WcsReassignLocParam;
|
import com.vincent.rsf.openApi.entity.params.WcsTaskReportParam;
|
import com.vincent.rsf.openApi.mapper.LocMapper;
|
import com.vincent.rsf.openApi.service.WmsWcsService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpMethod;
|
import org.springframework.http.ResponseEntity;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.client.RestTemplate;
|
|
import java.util.Objects;
|
|
|
@Slf4j
|
@Service("wmsWcsService")
|
public class WmsWcsServiceImpl extends ServiceImpl<LocMapper, Loc> implements WmsWcsService {
|
|
@Autowired
|
private PlatformProperties.WmsApi wmsApi;
|
|
@Autowired
|
private RestTemplate restTemplate;
|
|
/**
|
* @author Munch D. Luffy
|
* @date 2026/01/09
|
* @description: 任务下发
|
* @version 1.0
|
*/
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public R wcsCreateInTask(WcsCreateInTaskParam params) {
|
String createInTask = wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.WCS_CREATE_IN_TASK;
|
/**WMS基础配置链接*/
|
log.info("入库任务申请,请求地址: {}, 请求参数: {}", createInTask , JSONObject.toJSONString(params));
|
HttpHeaders headers = new HttpHeaders();
|
headers.add("Content-Type", "application/json");
|
headers.add("api-version", "v2.0");
|
HttpEntity httpEntity = new HttpEntity(params, headers);
|
ResponseEntity<String> exchange = restTemplate.exchange(createInTask, HttpMethod.POST, httpEntity, String.class);
|
log.info("WCS入库任务申请,响应结果: {}", exchange);
|
if (Objects.isNull(exchange.getBody())) {
|
return R.error().add("下发WMS返回参数为空!!!");
|
} else {
|
ObjectMapper objectMapper = new ObjectMapper();
|
objectMapper.coercionConfigDefaults()
|
.setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
|
try {
|
CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
|
if (result.getCode() == 200) {
|
return R.ok();
|
} else {
|
return R.error(result.getMsg());
|
// throw new CoolException("任务执行状态上报失败!!");
|
}
|
} catch (JsonProcessingException e) {
|
// throw new CoolException(e.getMessage());
|
}
|
}
|
return R.error();
|
}
|
|
/**
|
* @author Munch D. Luffy
|
* @date 2026/01/09
|
* @description: WCS任务上报通知
|
* @version 1.0
|
*/
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public R wcsTaskReport(WcsTaskReportParam params) {
|
String createInTask = wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.WCS_TASK_REPORT;
|
/**WMS基础配置链接*/
|
log.info("WCS任务上报通知,请求地址: {}, 请求参数: {}", createInTask , JSONObject.toJSONString(params));
|
HttpHeaders headers = new HttpHeaders();
|
headers.add("Content-Type", "application/json");
|
headers.add("api-version", "v2.0");
|
HttpEntity httpEntity = new HttpEntity(params, headers);
|
ResponseEntity<String> exchange = restTemplate.exchange(createInTask, HttpMethod.POST, httpEntity, String.class);
|
log.info("WCS任务上报通知,响应结果: {}", exchange);
|
if (Objects.isNull(exchange.getBody())) {
|
return R.error().add("WCS任务上报通知告知wms返回参数为空!!!");
|
} else {
|
ObjectMapper objectMapper = new ObjectMapper();
|
objectMapper.coercionConfigDefaults()
|
.setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
|
try {
|
CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
|
if (result.getCode() == 200) {
|
return R.ok();
|
} else {
|
return R.error(result.getMsg());
|
// throw new CoolException("任务执行状态上报失败!!");
|
}
|
} catch (JsonProcessingException e) {
|
// throw new CoolException(e.getMessage());
|
}
|
}
|
return R.error();
|
}
|
|
/**
|
* @author Munch D. Luffy
|
* @date 2026/01/09
|
* @description: WCS申请任务重新分配入库
|
* @version 1.0
|
*/
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public R wcsReassignLoc(WcsReassignLocParam params) {
|
String createInTask = wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.WCS_REASSIGN_LOC;
|
/**WMS基础配置链接*/
|
log.info("WCS任务上报通知,请求地址: {}, 请求参数: {}", createInTask , JSONObject.toJSONString(params));
|
HttpHeaders headers = new HttpHeaders();
|
headers.add("Content-Type", "application/json");
|
headers.add("api-version", "v2.0");
|
HttpEntity httpEntity = new HttpEntity(params, headers);
|
ResponseEntity<String> exchange = restTemplate.exchange(createInTask, HttpMethod.POST, httpEntity, String.class);
|
log.info("WCS任务上报通知,响应结果: {}", exchange);
|
if (Objects.isNull(exchange.getBody())) {
|
return R.error().add("WCS任务上报通知告知wms返回参数为空!!!");
|
} else {
|
ObjectMapper objectMapper = new ObjectMapper();
|
objectMapper.coercionConfigDefaults()
|
.setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
|
try {
|
CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
|
if (result.getCode() == 200) {
|
return R.ok();
|
} else {
|
return R.error(result.getMsg());
|
// throw new CoolException("任务执行状态上报失败!!");
|
}
|
} catch (JsonProcessingException e) {
|
// throw new CoolException(e.getMessage());
|
}
|
}
|
return R.error();
|
}
|
|
/**
|
* @author Munch D. Luffy
|
* @date 2026/01/09
|
* @description: WCS申请在库库位更换库位
|
* @version 1.0
|
*/
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public R wcsChangeLoc(WcsChangeLocParam params) {
|
String createInTask = wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.WCS_CHANGE_LOC;
|
/**WMS基础配置链接*/
|
log.info("WCS任务上报通知,请求地址: {}, 请求参数: {}", createInTask , JSONObject.toJSONString(params));
|
HttpHeaders headers = new HttpHeaders();
|
headers.add("Content-Type", "application/json");
|
headers.add("api-version", "v2.0");
|
HttpEntity httpEntity = new HttpEntity(params, headers);
|
ResponseEntity<String> exchange = restTemplate.exchange(createInTask, HttpMethod.POST, httpEntity, String.class);
|
log.info("WCS任务上报通知,响应结果: {}", exchange);
|
if (Objects.isNull(exchange.getBody())) {
|
return R.error().add("WCS任务上报通知告知wms返回参数为空!!!");
|
} else {
|
ObjectMapper objectMapper = new ObjectMapper();
|
objectMapper.coercionConfigDefaults()
|
.setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
|
try {
|
CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
|
if (result.getCode() == 200) {
|
return R.ok();
|
} else {
|
return R.error(result.getMsg());
|
// throw new CoolException("任务执行状态上报失败!!");
|
}
|
} catch (JsonProcessingException e) {
|
// throw new CoolException(e.getMessage());
|
}
|
}
|
return R.error();
|
}
|
}
|