Commit 3f00a623 authored by tank.li@mushiny.com's avatar tank.li@mushiny.com

拣货任务完善,出库单与系统绑定 完成后反馈

parent 058b5fa6
......@@ -325,4 +325,44 @@ public class CommonUtils {
public static Long int2Long(int i) {
return Long.parseLong(i+"");
}
public static int faceToInteger(String face){
int faceInt = 0;
if(face == null || "".equals(face)){
return faceInt;
}
switch (face){
case "A":faceInt = 0;break;
case "B":faceInt = 1;break;
case "C":faceInt = 2;break;
case "D":faceInt = 3;break;
default:faceInt = 0;
}
return faceInt;
}
/**
* 0 -A 1-B 2-C 3-D
* @param faceInt
* @return
*/
public static String IntegerToFace(int faceInt){
String face = null;
if(faceInt > 3 || faceInt < 0){
return face;
}
switch (faceInt){
case 0:face = "A";break;
case 1:face = "B";break;
case 2:face = "C";break;
case 3:face = "D";break;
default:face = null;
}
return face;
}
}
......@@ -77,7 +77,7 @@ public class WMSController {
public ResponseEntity<MessageDTO> podRelease(
@RequestBody String json){
Map req = JsonUtils.json2Map(json);
logger.debug("收到出库单下发指令:" + json);
logger.debug("释放货架:" + json);
MessageDTO dto = MessageDTO.success();
try {
this.wmsService.podRelease(req);
......@@ -87,4 +87,5 @@ public class WMSController {
}
return ResponseEntity.ok(dto);
}
}
......@@ -124,7 +124,7 @@ public class ICQAService {
@Scheduled(fixedDelay = 10*1000L)
public void startICQATrip(){
//6db9c7c0-4f93-4fa1-82c0-fb6435af7aae
if(isLocked("6db9c7c0-4f93-4fa1-82c0-fb6435af7aae")){
if(isLocked(WMSService.stationId)){
logger.error("工作站被锁定,无法启动盘点任务!");
return ;
}
......
......@@ -5,9 +5,11 @@ import com.mushiny.heli.xnr.comm.CommonUtils;
import com.mushiny.heli.xnr.dto.MessageDTO;
import com.mushiny.heli.xnr.dto.StorageLocation;
import com.mushiny.heli.xnr.jdbc.repositories.JdbcRepository;
import com.mushiny.heli.xnr.wcs.WmsToWcsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
......@@ -120,7 +122,7 @@ public class InboundService {
baseBpo.addKV("AMOUNT",stored);//上架的数量
baseBpo.addKV("UNITLOAD_ID",uid);
baseBpo.addKV("RESERVED_AMOUNT",0);
baseBpo.addKV("CLIENT_ID",factory);
baseBpo.addKV("CLIENT_ID",factory); //同一个factory
baseBpo.addKV("WAREHOUSE_ID",factory);//TODO
this.jdbcRepository.insertBusinessObject(baseBpo);
//end of 新增记录
......@@ -310,6 +312,8 @@ public class InboundService {
return dto;
}
/*@Value("${xnr.stationId}")
private String stationId = "6db9c7c0-4f93-4fa1-82c0-fb6435af7aae";*/
/**
* 定时启动任务
......@@ -317,7 +321,7 @@ public class InboundService {
@Scheduled(fixedDelay = 10*1000L)
public void startInboundTrip(){
//6db9c7c0-4f93-4fa1-82c0-fb6435af7aae
if(isLocked("6db9c7c0-4f93-4fa1-82c0-fb6435af7aae")){
if(isLocked(WMSService.stationId)){
logger.error("工作站被锁定,无法启动上架任务!");
return ;
}
......
......@@ -6,9 +6,11 @@ import com.mushiny.heli.xnr.comm.DateUtils;
import com.mushiny.heli.xnr.comm.JsonUtils;
import com.mushiny.heli.xnr.dto.*;
import com.mushiny.heli.xnr.jdbc.repositories.JdbcRepository;
import com.mushiny.heli.xnr.wcs.WmsToWcsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -26,6 +28,9 @@ public class WMSService {
private final static Logger logger = LoggerFactory.getLogger(WMSService.class);
@Autowired
private WmsToWcsService wmsToWcsService;
@Transactional
public void saveInboundOrder(InboundOrderDTO inboundOrderDTO){
......@@ -156,9 +161,16 @@ public class WMSService {
`ITEMGROUP_ID` varchar(255) NOT NULL DEFAULT '' COMMENT '商品类型',
`HANDLINGUNIT_ID` varchar(255) NOT NULL DEFAULT '' COMMENT '商品单位',
`VERSION` int(11) NOT NULL,*/
@Value("${xnr.stationId}")
public static String stationId = "6db9c7c0-4f93-4fa1-82c0-fb6435af7aae";
/*保存到商品信息表*/
@Value("${xnr.item_group}")
public static final String ITEM_GROUP = "fd335ce3-1b83-4819-81d9-34f8aa5a2139";
@Value("${xnr.handling_unit_id}")
public static final String HANDLING_UNIT_ID = "d7599399-3da6-478c-b14d-60e6be6ef11e";
public void syncItem(ItemDTO itemDTO) {
List<Map> skus = this.jdbcRepository.queryBySql(Sql_Table.SQL_QUERYITEM_BYSKUNO, itemDTO.getSKUID());
......@@ -312,8 +324,15 @@ public class WMSService {
return set;
}
//TODO
/**
*
* @param req
*/
public void podRelease(Map req) {
//货架号(数字)、工作站号(ID)/ SectionID
Integer podIndex = CommonUtils.parseInteger("podIndex", req);
String stationId = CommonUtils.parseString("stationId",req);
String sectionId = CommonUtils.parseString("sectionId",req);
this.wmsToWcsService.releasePod(stationId,sectionId,podIndex);
}
}
package com.mushiny.heli.xnr.wcs;
import com.mushiny.heli.xnr.comm.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.util.Map;
@Component
public class ExecutorHandler {
private final Logger logger = LoggerFactory.getLogger(ExecutorHandler.class);
RestTemplate restTemplate = new RestTemplate();
//获取token
public String getToken(String getTokenUrl, String params) {
logger.info("获取wcs token认证信息。。。params = {} ",params);
String tokenInfo = "";
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
headers.setContentType(type);
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
HttpEntity<String> formEntity = new HttpEntity<String>(params,headers);
String result = restTemplate.postForObject(getTokenUrl, formEntity, String.class);
logger.info("获取token 时 wcs 返回结果 : {} ",result);
Map<String,String> resultMap = JsonUtils.json2Map(result);
String code = resultMap.get("code");
if("1".equals(code)){
tokenInfo = resultMap.get("authorization");
}
return tokenInfo;
}
public String getForObject(String url,Map params,String token){
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
headers.setContentType(type);
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
headers.add("Authorization",token);
HttpEntity<String> formEntity = new HttpEntity<String>(headers);
ResponseEntity<String> result = restTemplate.exchange(url, HttpMethod.GET,formEntity,String.class,params);
String body = result.getBody();
return body;
}
public String postForObject(String url,String params,String token){
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
headers.setContentType(type);
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
headers.add("Authorization",token);
HttpEntity<String> formEntity = new HttpEntity<String>(params, headers);
String result = restTemplate.postForObject(url, formEntity, String.class);
return result;
}
}
package com.mushiny.heli.xnr.wcs;
import com.mushiny.heli.xnr.comm.JsonUtils;
import com.mushiny.heli.xnr.jdbc.repositories.JdbcRepository;
import com.mushiny.heli.xnr.service.Sql_Table;
import org.springframework.stereotype.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import java.util.*;
@Component
public class WmsToWcsBusiness {
private final Logger logger = LoggerFactory.getLogger(WmsToWcsBusiness.class);
@Autowired
private ExecutorHandler executorHandler;
@Autowired
private JdbcRepository jdbcRepository;
@Value("${wcs.getEnroutedPodsUrl}")
private String enroutedPodsUrl;
@Value("${wcs.acpFacesByPodUrl}")
private String acpFacesByPodUrl;
@Value("${wcs.getPodInfo}")
private String getPodInfo;
@Value("${wcs.getTokenUrl}")
private String getTokenUrl;
@Value("${wcs.username}")
private String username;
@Value("${wcs.password}")
private String password;
@Value("{wcs.type}")
private String type;
public Map getPodByIndexAndSection(Integer podIndex, String sectionId) {
return this.jdbcRepository.queryOneBySql(Sql_Table.SQL_QUERYPODBYINDEX,sectionId,podIndex);
}
/*public boolean getFacesByPod(String workStationId, String podId) {
String token = getTokenFromWcs();
if("".equals(token)){
logger.info("获取wcs token失败");
return false;
}
token = "Bearer " + token;
Map<String, Object> taskMap = new HashMap<>();
taskMap.put("sectionId", workStation.getSection().getRcsSection());
taskMap.put("podId", pod.getPodIndex());
taskMap.put("stopCellId", workStation.getStoppoint());
taskMap.put("direction", workStation.getWorkFace());
String result = executorHandler.getForObject(this.acpFacesByPodUrl, taskMap,token);
logger.info("获取pod当前调度任务信息,wcs返回结果:{}",result);
if(result == null || "".equals(result)){
return false;
}
List<Map> pods = JsonUtils.json2List(result,Map.class);
if(pods == null || pods.isEmpty()){
return false;
}
return true;
}*/
public String getTokenFromWcs() {
Map<String,String> userMap = new HashMap<>();
userMap.put("username",this.username);
userMap.put("password",this.password);
userMap.put("type",this.type);
String token = executorHandler.getToken(this.getTokenUrl, JsonUtils.map2Json(userMap));
return token;
}
/* public Section getSection(String sectionId) {
Query query = entityManager.createQuery("select s from "+Section.class.getSimpleName()+" s where s.id = :sectionId");
query.setParameter("sectionId",sectionId);
Section section = (Section) query.getSingleResult();
return section;
}
public WorkStation getWorkStationById(String workStationId) {
Query query = entityManager.createQuery("select w from "+WorkStation.class.getSimpleName()+" w where w.id = :stationId");
query.setParameter("stationId",workStationId);
WorkStation workStation = (WorkStation)query.getSingleResult();
return workStation;
}
public TripPod getTripPodById(String taskId) {
Query query = entityManager.createQuery("select t from " + TripPod.class.getSimpleName()+" t where t.taskId = :taskId");
query.setParameter("taskId",taskId);
TripPod tripPod = (TripPod)query.getSingleResult();
return tripPod;
}
public void updateTripState(String taskId) {
Query query = entityManager.createNativeQuery("UPDATE WCS_TRIP p SET p.TRIP_STATE = 'Finish' WHERE p.TASK_ID = '" + taskId + "'");
query.executeUpdate();
}
public void updatePodState(String podId) {
Query query = entityManager.createNativeQuery("UPDATE MD_POD p SET p.STATE = 'Available' WHERE p.ID = '" + podId + "'");
query.executeUpdate();
}*/
}
package com.mushiny.heli.xnr.wcs;
/**
* Created by Lisi on 2019-12-13.
*/
import com.mushiny.heli.xnr.comm.CommonUtils;
import com.mushiny.heli.xnr.comm.JsonUtils;
import com.mushiny.heli.xnr.jdbc.repositories.JdbcRepository;
import com.mushiny.heli.xnr.service.Sql_Table;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
@Service
public class WmsToWcsService{
private final Logger logger = LoggerFactory.getLogger(WmsToWcsService.class);
@Value("${wcs.getPods}")
private String getPodAmountUrl;
@Value("${wcs.callPod}")
private String callPodUrl;
@Value("${wcs.superCarryPod}")
private String superCarryPod;
@Value("${wcs.releasePod}")
private String releasePod;
@Autowired
private WmsToWcsBusiness wmsToWcsBusiness;
@Autowired
private ExecutorHandler executorHandler;
@Autowired
private JdbcRepository jdbcRepository;
//通过wcs接口获取当前工作站任务数量
public int getEnroutedPodAmount(Map station) {
String token = wmsToWcsBusiness.getTokenFromWcs();
if("".equals(token)){
logger.info("获取wcs token失败");
return 0;
}
token = "Bearer " + token;
int amount = 0;
Map<String, Object> getPodsMap = new HashMap<>();
getPodsMap.put("sectionId", CommonUtils.parseInteger("sectionId",station));
getPodsMap.put("stopCellId", CommonUtils.parseInteger("stopCellId",station));
getPodsMap.put("direction", CommonUtils.parseInteger("direction",station));
logger.info("查询工作站={} 在途pod数量,参数是:params = {}.",station, getPodsMap.toString());
try {
String result = executorHandler.postForObject(getPodAmountUrl, JsonUtils.map2Json(getPodsMap),token);
logger.info("通过wcs接口获取当前工作站任务数量 :{}",result);
if(result != null && !"".equals(result)){
amount = Integer.parseInt(result);
}
}catch (Exception e){
logger.info("通过wcs接口获取当前工作站任务数量 +++++++++++出现异常。",e,e.getMessage());
}
return amount;
}
/**
* 向wcs发送调度任务
*/
public List<Map> sendTripToWcs(String podIndex,
Integer sectionId,
Integer stopCellId,
Integer direction,
List<String> availableFaces) {
String token = wmsToWcsBusiness.getTokenFromWcs();
if("".equals(token)){
logger.info("获取wcs token失败");
return null;
}
token = "Bearer " + token;
Map<String, Object> taskMap = new HashMap<>();
taskMap.put("sectionId", sectionId);
taskMap.put("podId", podIndex);
taskMap.put("stopCellId", stopCellId);
taskMap.put("direction", direction);
List<Map> ret = new ArrayList<>();
for (String podFace:availableFaces){
taskMap.put("targetDirection", CommonUtils.faceToInteger(podFace));
String taskIdFromWcs = executorHandler.postForObject(this.callPodUrl,
JsonUtils.map2Json(taskMap),token);
logger.info("发送调度任务,wcs返回taskId:{}",taskIdFromWcs);
Map<String,String> resultMap = JsonUtils.json2Map(taskIdFromWcs);
String taskId = "";
if (resultMap != null
&& resultMap.get("taskId") != null) {
taskId = resultMap.get("taskId");
}
if(CommonUtils.isEmpty(taskId)){
logger.info("发送{}的face{}调度任务时,获取taskId失败。。。", podIndex, podFace);
continue;
}
Map data = new HashMap();
data.put("taskId",taskId);
data.put("targetDirection", CommonUtils.faceToInteger(podFace));
data.put("sectionId", sectionId);
data.put("podId", podIndex);
data.put("stopCellId", stopCellId);
data.put("direction", direction);
ret.add(data);
}
return ret;
}
@Transactional
public void releasePod(String workStationId,String sectionId, Integer podIndex) {
logger.info("工作站 = {} 释放pod = {} ,sectionId = {} ",workStationId,podIndex,sectionId);
//先查询该停止点是否有任务
Map podStation = this.getByWorkStationIdAndPodIndex(workStationId,sectionId,podIndex);
if(podStation == null){
logger.info("工作站 :{} 没有pod : {} ,无法释放。。",workStationId, podIndex);
return;
}
String token = wmsToWcsBusiness.getTokenFromWcs();
if("".equals(token)){
logger.info("获取wcs token失败");
return;
}
token = "Bearer " + token;
Map<String, Object> taskMap = new HashMap<>();
taskMap.put("taskId", CommonUtils.parseString("TRIP_TASKID",podStation));
this.executorHandler.getForObject(this.releasePod, taskMap, token);
logger.info("工作站 = {} 释放pod = {} ,wcs返回taskId:{}", workStationId, podIndex);
//更显pod状态
updatePodState(podIndex,sectionId, Sql_Table.AVAILABLE);
}
private Map getPodByIndexAndSection(Integer podIndex, String sectionId) {
return this.jdbcRepository.queryOneBySql(Sql_Table.SQL_QUERYPODBYINDEX, sectionId, podIndex);
}
private Map getByWorkStationIdAndPodIndex(String workStationId, String sectionId, Integer podIndex) {
logger.debug("条件 workStationId :"+workStationId+" sectionId:"
+sectionId+" pod: "+podIndex);
Map data = this.jdbcRepository.queryOneBySql(Sql_Table.SQL_QUERY_CURRENTPOD, workStationId);
if(Objects.equals(podIndex, CommonUtils.parseInteger("POD_INDEX",data))){
return data;
}
return null;
}
private void updatePodState(Integer podId, String sectionId,String status) {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment