Commit 3be0048e zshaohui

工单出库逻辑修改

1 个父辈 8fde5746
...@@ -15,7 +15,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; ...@@ -15,7 +15,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
//@EnableAsync //@EnableAsync
@EnableScheduling //@EnableScheduling
@EnableKafka @EnableKafka
@RestController @RestController
@SpringBootApplication @SpringBootApplication
......
...@@ -46,7 +46,7 @@ public class MainTimer { ...@@ -46,7 +46,7 @@ public class MainTimer {
public void run() { public void run() {
timerTask(); timerTask();
} }
}, 5, 10, TimeUnit.SECONDS); }, 5, 30, TimeUnit.SECONDS);
//log.info("如果是人工叫料,则每2分钟执行一次"); //log.info("如果是人工叫料,则每2分钟执行一次");
scheduledThreadPool.scheduleAtFixedRate(new Runnable() { scheduledThreadPool.scheduleAtFixedRate(new Runnable() {
...@@ -72,18 +72,11 @@ public class MainTimer { ...@@ -72,18 +72,11 @@ public class MainTimer {
} }
private void timerTask() { private void timerTask() {
if (!preGenerateTaskTime()) {
return;
}
lastPreGenerateTaskTime = System.currentTimeMillis();
try { try {
log.info("生成缺料预警任务"); //log.info("生成缺料预警任务");
//PreWarningItemCache.runTimer(0); PreWarningItemCache.runTimer();
PreWarningItemCache.runTimer(1);
//liteOrderCache.runTimer(0);
//设备状态判断 //设备状态判断
DevicesStatusUtil.runTimer(); DevicesStatusUtil.runTimer();
//其他设备状态判断 //其他设备状态判断
EquipStatusUtil.runTimer(); EquipStatusUtil.runTimer();
} catch (Exception e) { } catch (Exception e) {
......
...@@ -175,4 +175,14 @@ public class Constants { ...@@ -175,4 +175,14 @@ public class Constants {
* 工单生成个数 * 工单生成个数
*/ */
public static final String CACHE_preGenerateTask_Times = "preGenerateTask_times"; public static final String CACHE_preGenerateTask_Times = "preGenerateTask_times";
/**
* 线体配置
*/
public static final String CACHE_lineConfigList = "CACHE_lineConfigList";
/**
* 迈征配置分钟
*/
public static final String CACHE_maiZhengMinute = "maiZhengMinute";
} }
...@@ -46,24 +46,36 @@ public class HttpHelper { ...@@ -46,24 +46,36 @@ public class HttpHelper {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
try { try {
String requestBody = mapper.writeValueAsString(object); String requestBody = mapper.writeValueAsString(object);
httpPost.setEntity(new StringEntity(requestBody,CONTENT_CHARSET)); httpPost.setEntity(new StringEntity(requestBody, CONTENT_CHARSET));
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new ApiException("Request params to [" + url + "] failed:" + e.getMessage()); throw new ApiException("Request params to [" + url + "] failed:" + e.getMessage());
} catch (Exception e) { } catch (Exception e) {
throw new ApiException("Request params to [" + url + "] failed:" + e.getMessage()); throw new ApiException("Request params to [" + url + "] failed:" + e.getMessage());
} }
} }
try{ CloseableHttpClient httpClient = null;
CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse response = null;
CloseableHttpResponse response = httpClient.execute(httpPost); try {
httpClient = HttpClients.createDefault();
response = httpClient.execute(httpPost);
//System.out.println(response.getStatusLine().getStatusCode() + "\n"); //System.out.println(response.getStatusLine().getStatusCode() + "\n");
HttpEntity entity = response.getEntity(); HttpEntity entity = response.getEntity();
String responseContent = EntityUtils.toString(entity, CONTENT_CHARSET); String responseContent = EntityUtils.toString(entity, CONTENT_CHARSET);
response.close();
httpClient.close();
return responseContent; return responseContent;
}catch (Exception e){ } catch (Exception e) {
throw new ApiException("Request to [" + url + "] failed:" + e.getMessage()); throw new ApiException("Request to [" + url + "] failed:" + e.getMessage());
} finally {
try {
if (response != null) {
response.close();
}
if (httpClient != null) {
httpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
} }
} }
...@@ -76,24 +88,37 @@ public class HttpHelper { ...@@ -76,24 +88,37 @@ public class HttpHelper {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
try { try {
String requestBody = mapper.writeValueAsString(params); String requestBody = mapper.writeValueAsString(params);
httpPost.setEntity(new StringEntity(requestBody,CONTENT_CHARSET)); httpPost.setEntity(new StringEntity(requestBody, CONTENT_CHARSET));
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new ApiException("Request params to [" + url + "] failed:" + e.getMessage()); throw new ApiException("Request params to [" + url + "] failed:" + e.getMessage());
} catch (Exception e) { } catch (Exception e) {
throw new ApiException("Request params to [" + url + "] failed:" + e.getMessage()); throw new ApiException("Request params to [" + url + "] failed:" + e.getMessage());
} }
} }
try{ CloseableHttpClient httpClient = null;
CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse response = null;
CloseableHttpResponse response = httpClient.execute(httpPost); try {
httpClient = HttpClients.createDefault();
response = httpClient.execute(httpPost);
//System.out.println(response.getStatusLine().getStatusCode() + "\n"); //System.out.println(response.getStatusLine().getStatusCode() + "\n");
HttpEntity entity = response.getEntity(); HttpEntity entity = response.getEntity();
String responseContent = EntityUtils.toString(entity, CONTENT_CHARSET); String responseContent = EntityUtils.toString(entity, CONTENT_CHARSET);
response.close(); response.close();
httpClient.close(); httpClient.close();
return responseContent; return responseContent;
}catch (Exception e){ } catch (Exception e) {
throw new ApiException("Request to [" + url + "] failed:" + e.getMessage()); throw new ApiException("Request to [" + url + "] failed:" + e.getMessage());
} finally {
try {
if (response != null) {
response.close();
}
if (httpClient != null) {
httpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
} }
} }
...@@ -122,15 +147,16 @@ public class HttpHelper { ...@@ -122,15 +147,16 @@ public class HttpHelper {
params.add(new BasicNameValuePair(entry.getKey(),value)); params.add(new BasicNameValuePair(entry.getKey(),value));
} }
} }
CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null;
try { try {
URI uri = new URIBuilder(url).setParameters(params).build(); URI uri = new URIBuilder(url).setParameters(params).build();
log.info("执行MES请求:"+uri.toString()); log.info("执行MES请求:"+uri.toString());
HttpPost httpPost = new HttpPost(uri); HttpPost httpPost = new HttpPost(uri);
httpPost.addHeader("Content-Type", "application/json;charset=utf-8"); httpPost.addHeader("Content-Type", "application/json;charset=utf-8");
// httpPost.setEntity(new UrlEncodedFormEntity(params, CONTENT_CHARSET)); // httpPost.setEntity(new UrlEncodedFormEntity(params, CONTENT_CHARSET));
CloseableHttpClient httpClient = HttpClients.createDefault(); httpClient = HttpClients.createDefault();
CloseableHttpResponse response = httpClient.execute(httpPost); response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity(); HttpEntity entity = response.getEntity();
String responseContent = EntityUtils.toString(entity, CONTENT_CHARSET); String responseContent = EntityUtils.toString(entity, CONTENT_CHARSET);
response.close(); response.close();
...@@ -138,6 +164,17 @@ public class HttpHelper { ...@@ -138,6 +164,17 @@ public class HttpHelper {
return responseContent; return responseContent;
} catch (Exception e) { } catch (Exception e) {
throw new ApiException("Request params to [" + url + "] failed:" + e.getMessage()); throw new ApiException("Request params to [" + url + "] failed:" + e.getMessage());
} finally {
try {
if (response != null) {
response.close();
}
if (httpClient != null) {
httpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
} }
} }
...@@ -156,9 +193,10 @@ public class HttpHelper { ...@@ -156,9 +193,10 @@ public class HttpHelper {
.setConnectTimeout(5000) .setConnectTimeout(5000)
.setConnectionRequestTimeout(5000).build(); .setConnectionRequestTimeout(5000).build();
httpget.setConfig(build); httpget.setConfig(build);
CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null; CloseableHttpResponse response = null;
try { try {
CloseableHttpClient httpClient = HttpClients.createDefault(); httpClient = HttpClients.createDefault();
response = httpClient.execute(httpget); response = httpClient.execute(httpget);
} catch (IOException e1) { } catch (IOException e1) {
e1.printStackTrace(); e1.printStackTrace();
...@@ -173,7 +211,12 @@ public class HttpHelper { ...@@ -173,7 +211,12 @@ public class HttpHelper {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
try { try {
if (httpClient != null){
httpClient.close();
}
if (response != null) {
response.close(); response.close();
}
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -23,6 +23,7 @@ import com.neotel.smfcore.core.storage.service.manager.IStoragePosManager; ...@@ -23,6 +23,7 @@ import com.neotel.smfcore.core.storage.service.manager.IStoragePosManager;
import com.neotel.smfcore.core.storage.service.po.Storage; import com.neotel.smfcore.core.storage.service.po.Storage;
import com.neotel.smfcore.core.storage.service.po.StoragePos; import com.neotel.smfcore.core.storage.service.po.StoragePos;
import com.neotel.smfcore.core.system.bean.OrderSetting; import com.neotel.smfcore.core.system.bean.OrderSetting;
import com.neotel.smfcore.core.system.rest.bean.LineConfig;
import com.neotel.smfcore.core.system.service.dao.ICacheItemDao; import com.neotel.smfcore.core.system.service.dao.ICacheItemDao;
import com.neotel.smfcore.core.system.service.dao.ISettingsDao; import com.neotel.smfcore.core.system.service.dao.ISettingsDao;
import com.neotel.smfcore.core.system.service.po.CacheItem; import com.neotel.smfcore.core.system.service.po.CacheItem;
...@@ -709,4 +710,16 @@ public class DataCache { ...@@ -709,4 +710,16 @@ public class DataCache {
} }
return 0; return 0;
} }
public int getLineConfigMinute(String line) {
List<LineConfig> lineConfigList = getCache(Constants.CACHE_lineConfigList);
if (lineConfigList != null && !lineConfigList.isEmpty()){
for (LineConfig lineConfig : lineConfigList) {
if (lineConfig.getLine().equals(line)){
return lineConfig.getMinute();
}
}
}
return 0;
}
} }
...@@ -219,6 +219,9 @@ public class LiteOrderItem extends BasePo implements Serializable ,Comparable<Li ...@@ -219,6 +219,9 @@ public class LiteOrderItem extends BasePo implements Serializable ,Comparable<Li
*/ */
private Date issuanceDate; private Date issuanceDate;
private Date receiveDate;
/** /**
* 出库是否满足要求,已出库数量大于需求数量 * 出库是否满足要求,已出库数量大于需求数量
*/ */
......
...@@ -13,6 +13,7 @@ import com.neotel.smfcore.core.language.service.po.LanguageMsg; ...@@ -13,6 +13,7 @@ import com.neotel.smfcore.core.language.service.po.LanguageMsg;
import com.neotel.smfcore.core.storage.enums.DeviceType; import com.neotel.smfcore.core.storage.enums.DeviceType;
import com.neotel.smfcore.core.storage.service.po.Storage; import com.neotel.smfcore.core.storage.service.po.Storage;
import com.neotel.smfcore.core.system.bean.OrderSetting; import com.neotel.smfcore.core.system.bean.OrderSetting;
import com.neotel.smfcore.core.system.rest.bean.LineConfig;
import com.neotel.smfcore.core.system.rest.bean.dto.SettingsDto; import com.neotel.smfcore.core.system.rest.bean.dto.SettingsDto;
import com.neotel.smfcore.core.system.rest.bean.dto.SysSettingsDto; import com.neotel.smfcore.core.system.rest.bean.dto.SysSettingsDto;
import com.neotel.smfcore.core.system.rest.bean.mapstruct.SettingsMapper; import com.neotel.smfcore.core.system.rest.bean.mapstruct.SettingsMapper;
...@@ -76,6 +77,9 @@ public class SettingsController { ...@@ -76,6 +77,9 @@ public class SettingsController {
String permissionPassword = dataCache.getCache(Constants.CACHE_permissionPassword); String permissionPassword = dataCache.getCache(Constants.CACHE_permissionPassword);
String floor = dataCache.getCache(Constants.CACHE_floor); String floor = dataCache.getCache(Constants.CACHE_floor);
Integer preGenerateTaskTimes = dataCache.getCache(Constants.CACHE_preGenerateTask_Times); Integer preGenerateTaskTimes = dataCache.getCache(Constants.CACHE_preGenerateTask_Times);
List<LineConfig> lineConfigList = dataCache.getCache(Constants.CACHE_lineConfigList);
Integer maiZhengMinute = dataCache.getCache(Constants.CACHE_maiZhengMinute);
SysSettingsDto dto = new SysSettingsDto(); SysSettingsDto dto = new SysSettingsDto();
dto.setStartJob(startJob); dto.setStartJob(startJob);
dto.setStopOut(stopOut); dto.setStopOut(stopOut);
...@@ -84,6 +88,8 @@ public class SettingsController { ...@@ -84,6 +88,8 @@ public class SettingsController {
dto.setPermissionPassword(permissionPassword); dto.setPermissionPassword(permissionPassword);
dto.setFloor(floor); dto.setFloor(floor);
dto.setPreGenerateTaskTimes(preGenerateTaskTimes); dto.setPreGenerateTaskTimes(preGenerateTaskTimes);
dto.setLineConfigList(lineConfigList);
dto.setMaiZhengMinute(maiZhengMinute);
return dto; return dto;
} }
...@@ -98,12 +104,24 @@ public class SettingsController { ...@@ -98,12 +104,24 @@ public class SettingsController {
dataCache.updateCache(Constants.CACHE_permissionPassword,sysSettingsDto.getPermissionPassword()); dataCache.updateCache(Constants.CACHE_permissionPassword,sysSettingsDto.getPermissionPassword());
dataCache.updateCache(Constants.CACHE_floor,sysSettingsDto.getFloor()); dataCache.updateCache(Constants.CACHE_floor,sysSettingsDto.getFloor());
dataCache.updateCache(Constants.CACHE_preGenerateTask_Times,sysSettingsDto.getPreGenerateTaskTimes()); dataCache.updateCache(Constants.CACHE_preGenerateTask_Times,sysSettingsDto.getPreGenerateTaskTimes());
List<LineConfig> lineConfigList = sysSettingsDto.getLineConfigList();
if (lineConfigList == null){
lineConfigList = new ArrayList<>();
}
dataCache.updateCache(Constants.CACHE_lineConfigList,lineConfigList);
if (sysSettingsDto.getMaiZhengMinute() != null) {
dataCache.updateCache(Constants.CACHE_maiZhengMinute, sysSettingsDto.getMaiZhengMinute());
}
log.info("更改系统设置:stopout=" + sysSettingsDto.isStopOut() + ",stopjob=" + sysSettingsDto.isStartJob() log.info("更改系统设置:stopout=" + sysSettingsDto.isStopOut() + ",stopjob=" + sysSettingsDto.isStartJob()
+ ",backUpMonth=" + sysSettingsDto.getBackUpMonth() + ",backUpMonth=" + sysSettingsDto.getBackUpMonth()
+ ",preGenerateTask=" + sysSettingsDto.getPreGenerateTask() + ",preGenerateTask=" + sysSettingsDto.getPreGenerateTask()
+ ",permissionPassword=" + sysSettingsDto.getPermissionPassword() + ",permissionPassword=" + sysSettingsDto.getPermissionPassword()
+ ",floor=" + sysSettingsDto.getFloor() + ",floor=" + sysSettingsDto.getFloor()
+",preGenerateTaskTimes=" +sysSettingsDto.getPreGenerateTaskTimes() +",preGenerateTaskTimes=" +sysSettingsDto.getPreGenerateTaskTimes()
+",lineConfigList="+sysSettingsDto.getLineConfigList()
+",maiZhengMinute="+sysSettingsDto.getMaiZhengMinute()
); );
return ResultBean.newOkResult("保存成功"); return ResultBean.newOkResult("保存成功");
} }
......
package com.neotel.smfcore.core.system.rest.bean;
import lombok.Data;
@Data
public class LineConfig {
private String line;
private int minute;
}
package com.neotel.smfcore.core.system.rest.bean.dto; package com.neotel.smfcore.core.system.rest.bean.dto;
import com.neotel.smfcore.core.system.rest.bean.LineConfig;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
@Getter @Getter
@Setter @Setter
public class SysSettingsDto implements Serializable { public class SysSettingsDto implements Serializable {
...@@ -30,4 +34,12 @@ public class SysSettingsDto implements Serializable { ...@@ -30,4 +34,12 @@ public class SysSettingsDto implements Serializable {
@ApiModelProperty("楼层信息") @ApiModelProperty("楼层信息")
private String floor=""; private String floor="";
@ApiModelProperty("线体配置")
private List<LineConfig> lineConfigList;
@ApiModelProperty("迈征配置时间")
private Integer maiZhengMinute;
} }
...@@ -540,8 +540,11 @@ public class TaskService { ...@@ -540,8 +540,11 @@ public class TaskService {
if (outTask != null) { if (outTask != null) {
log.info(outTask.getSourceName()+"barcode为:"+outTask.getBarcode()+"面别为:"+outTask.getSide()); log.info(outTask.getSourceName()+"barcode为:"+outTask.getBarcode()+"面别为:"+outTask.getSide());
if(StringUtils.isNotBlank(outTask.getSide())) {
exportMap.put(cid, outTask.getSide()); exportMap.put(cid, outTask.getSide());
} }
}
return outTask; return outTask;
} }
......
...@@ -517,7 +517,7 @@ public class LizhenApi extends DefaultSmfApiListener { ...@@ -517,7 +517,7 @@ public class LizhenApi extends DefaultSmfApiListener {
} }
} }
if (items != null && !items.isEmpty()) { if (items != null && !items.isEmpty()) {
return PreWarningItemCache.createAndExecuteLiteOrder(items,2,false); return PreWarningItemCache.createAndExecuteLiteOrder(items,false);
} }
} }
return null; return null;
......
...@@ -232,7 +232,12 @@ public class LizhenController { ...@@ -232,7 +232,12 @@ public class LizhenController {
item.setPartnumber(data.get("PARTNUMBER")); item.setPartnumber(data.get("PARTNUMBER"));
item.setLine(data.get("LINE")); item.setLine(data.get("LINE"));
item.setItemId(data.get("ID")); item.setItemId(data.get("ID"));
try {
item.setPriority(Integer.valueOf(data.get("PRIORITY"))); item.setPriority(Integer.valueOf(data.get("PRIORITY")));
} catch (NumberFormatException e) {
e.printStackTrace();
item.setPriority(0);
}
item.setReel(data.get("REEL")); item.setReel(data.get("REEL"));
item.setBrand(data.get("VENDOR")); item.setBrand(data.get("VENDOR"));
......
...@@ -94,7 +94,7 @@ public class InnerBoxRestController { ...@@ -94,7 +94,7 @@ public class InnerBoxRestController {
String hSerial = request.getParameter("hSerial"); //工单序号 String hSerial = request.getParameter("hSerial"); //工单序号
String outlet = request.getParameter("outlet"); //出口位置 String outlet = request.getParameter("outlet"); //出口位置
String boxSide = request.getParameter("boxSide"); //料箱隔口 String boxSide = request.getParameter("boxSide"); //料箱隔口
log.info("IA 出库更新任务状态--barcode:{},status:{},loc:{},hSerial:{},outlet:{},boxSide:{}", code, status, loc, hSerial, outlet, boxSide); log.info("IA 出库更新任务状态--barcode:{},status:{},loc:{},hSerial:{},outlet:{},boxSide:{},cid:{},outlet:{}", code, status, loc, hSerial, outlet, boxSide,cid,outlet);
CodeBean codeBean = codeResolve.resolveSingleCode(code); CodeBean codeBean = codeResolve.resolveSingleCode(code);
Barcode barcode = codeBean.getBarcode(); Barcode barcode = codeBean.getBarcode();
...@@ -121,7 +121,7 @@ public class InnerBoxRestController { ...@@ -121,7 +121,7 @@ public class InnerBoxRestController {
return ResultBean.newErrorResult(304, "smfcore.task.hasEnd", "任务已完成"); return ResultBean.newErrorResult(304, "smfcore.task.hasEnd", "任务已完成");
} }
status = status.toUpperCase(); status = status.toUpperCase();
log.info("更新任务状态:{}-->{}", opTask.getStatus(), status); //log.info("更新任务状态:{}-->{}", opTask.getStatus(), status);
//调用此接口的肯定是料盘已出仓位的 //调用此接口的肯定是料盘已出仓位的
if(opTask.isExecuting()){ if(opTask.isExecuting()){
......
...@@ -61,6 +61,8 @@ public class PrinterRestController { ...@@ -61,6 +61,8 @@ public class PrinterRestController {
String code = paramMap.get("code"); String code = paramMap.get("code");
log.info("补打印标签:"+code);
CodeBean codeBean = codeResolve.resolveSingleCode(code); CodeBean codeBean = codeResolve.resolveSingleCode(code);
Barcode barcode = codeBean.getBarcode(); Barcode barcode = codeBean.getBarcode();
......
package com.neotel.smfcore.custom.lizhen.innerBox.util; package com.neotel.smfcore.custom.lizhen.innerBox.util;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.mks.api.response.Item;
import com.neotel.smfcore.common.utils.Constants; import com.neotel.smfcore.common.utils.Constants;
import com.neotel.smfcore.common.utils.StringUtils; import com.neotel.smfcore.common.utils.StringUtils;
import com.neotel.smfcore.core.device.util.DataCache; import com.neotel.smfcore.core.device.util.DataCache;
...@@ -9,6 +10,7 @@ import com.neotel.smfcore.core.order.service.manager.ILiteOrderItemManager; ...@@ -9,6 +10,7 @@ import com.neotel.smfcore.core.order.service.manager.ILiteOrderItemManager;
import com.neotel.smfcore.core.order.service.manager.ILiteOrderManager; import com.neotel.smfcore.core.order.service.manager.ILiteOrderManager;
import com.neotel.smfcore.core.order.service.po.LiteOrder; import com.neotel.smfcore.core.order.service.po.LiteOrder;
import com.neotel.smfcore.core.order.service.po.LiteOrderItem; import com.neotel.smfcore.core.order.service.po.LiteOrderItem;
import com.neotel.smfcore.core.system.rest.bean.LineConfig;
import com.neotel.smfcore.custom.lizhen.innerBox.bean.PreWarningItem; import com.neotel.smfcore.custom.lizhen.innerBox.bean.PreWarningItem;
import com.neotel.smfcore.custom.lizhen.innerBox.service.manager.IPreWarningItemManager; import com.neotel.smfcore.custom.lizhen.innerBox.service.manager.IPreWarningItemManager;
import com.neotel.smfcore.custom.lizhen.innerBox.util.service.PreWarningItemCacheManager; import com.neotel.smfcore.custom.lizhen.innerBox.util.service.PreWarningItemCacheManager;
...@@ -22,7 +24,9 @@ import org.springframework.data.mongodb.core.query.Query; ...@@ -22,7 +24,9 @@ import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -66,112 +70,99 @@ public class PreWarningItemCache { ...@@ -66,112 +70,99 @@ public class PreWarningItemCache {
/** /**
* 从缓存列表中取出预警Item生成工单并执行 * 从缓存列表中取出预警Item生成工单并执行
*/ */
private static void generateTask(int priority) { private static void generateTask() {
boolean hasIdleBox = true; if (queueItemList == null || queueItemList.isEmpty()){
if (hasIdleBox) {
//每次最多出多少盘
//int maxReelCount = 30;
//如果取不到,从数据库中取
if (queueItemList == null || queueItemList.isEmpty()) {
queueItemList = preWarningItemManager.findAll(); queueItemList = preWarningItemManager.findAll();
} }
if (queueItemList == null || queueItemList.isEmpty()) { if (queueItemList != null && !queueItemList.isEmpty()) {
return; //迈征集合
List<PreWarningItem> maiZhengItemList = new ArrayList<>();
//其他工单集合
List<PreWarningItem> otherItemList = new ArrayList<>();
//挑出迈征和其他工单
Map<String, String> stationStatusMap = StationStatusCache.getStationStatusMap();
for (PreWarningItem item : queueItemList) {
String station = item.getStation();
String partnumber = item.getPartnumber();
String slot = item.getSlot();
String line = item.getLine();
String side = item.getSide();
String key = station + "_" + partnumber + "_" + slot + "_" + line+"_"+side;
String value = stationStatusMap.get(key);
if (StringUtils.isNotBlank(value)) {
maiZhengItemList.add(item);
} else {
otherItemList.add(item);
}
} }
//优先生成迈征的信息 //处理迈征工单信息
List<StationStatus> stationStatusList = stationStatusCache.getAllStationStatus(); if (maiZhengItemList != null && !maiZhengItemList.isEmpty()) {
if (stationStatusList != null && !stationStatusList.isEmpty()) { maiZhengItemList = maiZhengItemList.stream().sorted(Comparator.comparing(PreWarningItem::getReceiveDate)).collect(Collectors.toList());
for (StationStatus stationStatus : stationStatusList) {
List<PreWarningItem> lineItems = new ArrayList<>();
if (queueItemList != null && !queueItemList.isEmpty()) { int minute = dataCache.getCache(Constants.CACHE_maiZhengMinute);
if (minute == 0) {
minute = 20;
}
String line = stationStatus.getLINE(); //产线 //如果第一条接受的时间和当前时间相差超过设定时间
String trackNumber = stationStatus.getTrackNumber(); //轨道号 PreWarningItem firstItem = maiZhengItemList.get(0);
String side = stationStatus.getSIDE(); //面别 if (System.currentTimeMillis() - firstItem.getReceiveDate().getTime() > 1000 * 60 * minute) {
log.info("开始生成迈征的工单信息,line为:"+line+",side为:"+side+",trackNumber为:"+trackNumber); //获取迈征的线体
List<String> lineList = StationStatusCache.getStationStatusLineList();
if (lineList != null && !lineList.isEmpty()) {
for (String cacheLine : lineList) {
List<PreWarningItem> itemList = new ArrayList<>();
for (PreWarningItem item : maiZhengItemList) {
String line = item.getLine();
String station = item.getStation();
String side = item.getSide();
try { String trackNumber = "";
List<PreWarningItem> itemList = new ArrayList<>(queueItemList); if (StringUtils.isNotBlank(station)) {
for (PreWarningItem item : itemList) { trackNumber = station.substring(station.length() - 1);
//判断产线,面别,
if (StringUtils.isNotBlank(line)
&& StringUtils.isNotBlank(side)
&& StringUtils.isNotBlank(trackNumber)
) {
if (line.equals(item.getLine()) && side.equals(item.getSide())
&& StringUtils.isNotBlank(item.getStation()) && item.getStation().endsWith(trackNumber)) {
//再判断料号是否相同
for (StationStatus status : stationStatusList) {
String station = status.getSTATION();
String slot = status.getSLOT();
String partnumber = status.getPARTNUMBER();
if (StringUtils.isNotBlank(partnumber) && StringUtils.isNotBlank(slot) && StringUtils.isNotBlank(station)) {
if (station.equals(item.getStation())
&& slot.equals(item.getSlot())
&& partnumber.equals(item.getPartnumber())
&& line.equals(status.getLINE())
&& side.equals(status.getSIDE())
) {
log.info("开始添加迈征的工单明细,station为:"+station+",slot为:"+slot+",partnumber为:"+partnumber);
lineItems.add(item);
} }
line = line + "_" + side + "_" + trackNumber;
if (line.equals(cacheLine)) {
itemList.add(item);
} }
} }
if (itemList != null && !itemList.isEmpty()) {
createAndExecuteLiteOrder(itemList, true);
} }
} }
} }
} catch (Exception e) {
e.printStackTrace();
log.error("生成迈征工单报错:"+e.getMessage());
}
}
if (lineItems != null && !lineItems.isEmpty()) {
createAndExecuteLiteOrder(lineItems, priority, true);
}
} }
} }
//处理其他工单信息
if (otherItemList != null && !otherItemList.isEmpty()) {
Map<String, List<PreWarningItem>> otherItemGroupMap = otherItemList.stream().collect(Collectors.groupingBy(PreWarningItem::getLine));
for (Map.Entry<String, List<PreWarningItem>> otherItemEntry : otherItemGroupMap.entrySet()) {
//线体名称
String line = otherItemEntry.getKey();
//线体对应的item
List<PreWarningItem> itemList = otherItemEntry.getValue();
//按创建时间进行升序排列
itemList = itemList.stream().sorted(Comparator.comparing(PreWarningItem::getReceiveDate)).collect(Collectors.toList());
log.info("开始生成其他工单"); int minute = dataCache.getLineConfigMinute(line);
Integer preGenerateTaskTimes = dataCache.getCache(Constants.CACHE_preGenerateTask_Times); if (minute == 0) {
if (preGenerateTaskTimes == null || preGenerateTaskTimes == 0) { minute = 20;
preGenerateTaskTimes = 2;
} }
for (int time = 0; time < preGenerateTaskTimes; time++) { PreWarningItem firstItem = itemList.get(0);
//最早的一条预警时间 if (System.currentTimeMillis() - firstItem.getReceiveDate().getTime() < 1000 * 60 * minute) {
List<PreWarningItem> lineItems = new ArrayList<>(); continue;
String firstItemLine = "";
if (queueItemList != null && !queueItemList.isEmpty()) {
List<PreWarningItem> itemList = new ArrayList<>(queueItemList);
for (PreWarningItem preWarningItem : itemList) {
String itemLine = preWarningItem.getLine();
if (Strings.isNotBlank(itemLine)) {
if (firstItemLine.isEmpty()) {
firstItemLine = itemLine;
if (System.currentTimeMillis() - preWarningItem.getReceiveDate().getTime() < 1 * 60 * 1000) {
return;
}
} }
//同一个线别的生成一个工单 createAndExecuteLiteOrder(itemList, false);
if (itemLine.equals(firstItemLine)) {
log.info("添加明细数据,id为:" + preWarningItem.getItemId());
lineItems.add(preWarningItem);
} }
} }
} }
} }
if (!lineItems.isEmpty()) {
createAndExecuteLiteOrder(lineItems, priority, false);
}
}
}
}
/** /**
...@@ -179,7 +170,7 @@ public class PreWarningItemCache { ...@@ -179,7 +170,7 @@ public class PreWarningItemCache {
* *
* @param lineItems * @param lineItems
*/ */
public static synchronized LiteOrder createAndExecuteLiteOrder(List<PreWarningItem> lineItems,int priority,boolean maiZheng) { public static synchronized LiteOrder createAndExecuteLiteOrder(List<PreWarningItem> lineItems, boolean maiZheng) {
//1.得到优先级比较高的 //1.得到优先级比较高的
LiteOrder liteOrder = new LiteOrder(); LiteOrder liteOrder = new LiteOrder();
//List<PreWarningItem> itemsPri = new ArrayList<>(); //List<PreWarningItem> itemsPri = new ArrayList<>();
...@@ -211,6 +202,7 @@ public class PreWarningItemCache { ...@@ -211,6 +202,7 @@ public class PreWarningItemCache {
orderItem.setMachineName(item.getMachinename()); orderItem.setMachineName(item.getMachinename());
orderItem.setReel(item.getReel()); orderItem.setReel(item.getReel());
orderItem.setBrand(item.getBrand()); orderItem.setBrand(item.getBrand());
orderItem.setReceiveDate(item.getReceiveDate());
orderItems.add(orderItem); orderItems.add(orderItem);
} }
} }
...@@ -220,7 +212,7 @@ public class PreWarningItemCache { ...@@ -220,7 +212,7 @@ public class PreWarningItemCache {
liteOrder.setTaskReelCount(orderItems.size()); liteOrder.setTaskReelCount(orderItems.size());
liteOrder.setMaiZheng(maiZheng); liteOrder.setMaiZheng(maiZheng);
liteOrder = liteOrderManager.createWithItems(liteOrder); liteOrder = liteOrderManager.createWithItems(liteOrder);
log.info("生成工单信息为:"+liteOrder.getOrderNo()); log.info("生成工单信息为:" + liteOrder.getOrderNo());
liteOrderCache.addOrderToMap(liteOrder); liteOrderCache.addOrderToMap(liteOrder);
} }
//工单生成后,从缓存中清除 //工单生成后,从缓存中清除
...@@ -252,7 +244,7 @@ public class PreWarningItemCache { ...@@ -252,7 +244,7 @@ public class PreWarningItemCache {
c.and("warningItemId").is(itemIds.get(0)); c.and("warningItemId").is(itemIds.get(0));
LiteOrderItem orderItem = liteOrderItemManager.findOne(new Query().addCriteria(c)); LiteOrderItem orderItem = liteOrderItemManager.findOne(new Query().addCriteria(c));
if (orderItem != null){ if (orderItem != null) {
String warningItemId = orderItem.getWarningItemId(); String warningItemId = orderItem.getWarningItemId();
newItems = newItems.stream() newItems = newItems.stream()
.filter(item -> !item.getItemId().equals(warningItemId)) .filter(item -> !item.getItemId().equals(warningItemId))
...@@ -266,7 +258,7 @@ public class PreWarningItemCache { ...@@ -266,7 +258,7 @@ public class PreWarningItemCache {
queueItemList.addAll(newItems); queueItemList.addAll(newItems);
} }
for (PreWarningItem item : newItems) { for (PreWarningItem item : newItems) {
log.info("mes缺料预警信息为:"+ JSON.toJSONString(item)); log.info("mes缺料预警信息为:" + JSON.toJSONString(item));
preWarningItemManager.save(item); preWarningItemManager.save(item);
} }
} }
...@@ -278,13 +270,13 @@ public class PreWarningItemCache { ...@@ -278,13 +270,13 @@ public class PreWarningItemCache {
/** /**
* 定时执行,从缓存列表中取出预警Item生成工单并执行 * 定时执行,从缓存列表中取出预警Item生成工单并执行
*/ */
public static void runTimer(int priority) { public static void runTimer() {
if (processing) { if (processing) {
return; return;
} }
processing = true; processing = true;
try { try {
generateTask(priority); generateTask();
} catch (Exception e) { } catch (Exception e) {
log.error("预警缓存定时器出错", e); log.error("预警缓存定时器出错", e);
} finally { } finally {
...@@ -318,7 +310,7 @@ public class PreWarningItemCache { ...@@ -318,7 +310,7 @@ public class PreWarningItemCache {
} }
@Autowired @Autowired
public void setPreWarningItemManager(IPreWarningItemManager preWarningItemManager){ public void setPreWarningItemManager(IPreWarningItemManager preWarningItemManager) {
PreWarningItemCache.preWarningItemManager = preWarningItemManager; PreWarningItemCache.preWarningItemManager = preWarningItemManager;
} }
......
...@@ -19,7 +19,11 @@ import org.springframework.scheduling.annotation.Scheduled; ...@@ -19,7 +19,11 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.concurrent.ListenableFuture; import org.springframework.util.concurrent.ListenableFuture;
import javax.annotation.PostConstruct;
import java.util.*; import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
//@Async //@Async
...@@ -37,10 +41,21 @@ public class KafkaService { ...@@ -37,10 +41,21 @@ public class KafkaService {
Map<String,String> statusMap = Maps.newConcurrentMap(); Map<String,String> statusMap = Maps.newConcurrentMap();
ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(1);
@PostConstruct
void init(){
scheduledThreadPool.scheduleAtFixedRate(
() -> {
setMachineStatus();
setHeartbeat();
},5,60, TimeUnit.SECONDS
);
}
/** /**
* 设备状态发送 * 设备状态发送
*/ */
@Scheduled(fixedRate = 1000 * 60 * 1) //@Scheduled(fixedRate = 1000 * 60 * 2)
public void setMachineStatus() { public void setMachineStatus() {
log.info("发送设备状态开始"); log.info("发送设备状态开始");
Collection<Storage> storages = dataCache.getAllStorage().values(); Collection<Storage> storages = dataCache.getAllStorage().values();
...@@ -111,7 +126,7 @@ public class KafkaService { ...@@ -111,7 +126,7 @@ public class KafkaService {
/** /**
* 心跳数据发送 * 心跳数据发送
*/ */
@Scheduled(fixedRate = 1000 * 60 * 5) //@Scheduled(fixedRate = 1000 * 60 * 5)
public void setHeartbeat() { public void setHeartbeat() {
log.info("发送心跳开始"); log.info("发送心跳开始");
//根据machineId,找到设备状态,是否正常 //根据machineId,找到设备状态,是否正常
......
...@@ -328,6 +328,7 @@ public class InnerReportController { ...@@ -328,6 +328,7 @@ public class InnerReportController {
resultMap.put("料号", dto.getPn() == null ? "" : dto.getPn()); resultMap.put("料号", dto.getPn() == null ? "" : dto.getPn());
resultMap.put("需求卷", dto.getNeedReelCount()); resultMap.put("需求卷", dto.getNeedReelCount());
resultMap.put("实发卷", dto.getOutReelCount()); resultMap.put("实发卷", dto.getOutReelCount());
resultMap.put("创建时间",dto.getCreateDate());
results.add(resultMap); results.add(resultMap);
} }
try { try {
......
package com.neotel.smfcore.custom.lizhen.third.maicheng.util; package com.neotel.smfcore.custom.lizhen.third.maicheng.util;
import com.alibaba.fastjson.JSONObject; import com.google.common.collect.Maps;
import com.google.common.collect.Lists;
import com.neotel.smfcore.common.utils.StringUtils; import com.neotel.smfcore.common.utils.StringUtils;
import com.neotel.smfcore.core.device.util.DataCache; import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.custom.lizhen.third.maicheng.api.MaiZhengApi; import com.neotel.smfcore.custom.lizhen.third.maicheng.api.MaiZhengApi;
import com.neotel.smfcore.custom.lizhen.third.maicheng.bean.StationStatus; import com.neotel.smfcore.custom.lizhen.third.maicheng.bean.StationStatus;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
...@@ -24,10 +23,13 @@ public class StationStatusCache { ...@@ -24,10 +23,13 @@ public class StationStatusCache {
@Autowired @Autowired
private DataCache dataCache; private DataCache dataCache;
public static final String MAICHENG_STATIONSTATUS_CACHE = "MaiChengStationStatusCache"; public static final String MAIZHENG_STATIONSTATUS_CACHE_Map = "MaiZhengStationStatusCacheMap";
private static List<StationStatus> stationStatusList = Lists.newCopyOnWriteArrayList(); public static final String MAIZHENG_STATIONSTATUS_CACHE_Line_List = "MaiZhengStationStatusCacheLineList";
public static List<String> stationStatusLineList = new CopyOnWriteArrayList<>();
private static Map<String, String> stationStatusMap = Maps.newConcurrentMap();
@PostConstruct @PostConstruct
public void init() { public void init() {
...@@ -36,9 +38,13 @@ public class StationStatusCache { ...@@ -36,9 +38,13 @@ public class StationStatusCache {
if (statusList != null && !statusList.isEmpty()) { if (statusList != null && !statusList.isEmpty()) {
updateStatusList(statusList); updateStatusList(statusList);
} else { } else {
List<StationStatus> statusCacheList = dataCache.getCache(MAICHENG_STATIONSTATUS_CACHE); Map<String, String> cacheMap = dataCache.getCache(MAIZHENG_STATIONSTATUS_CACHE_Map);
if (statusCacheList != null && !statusCacheList.isEmpty()) { if (cacheMap != null) {
updateStatusList(statusCacheList); stationStatusMap.putAll(cacheMap);
}
List<String> cacheLineList = dataCache.getCache(MAIZHENG_STATIONSTATUS_CACHE_Line_List);
if (cacheLineList != null) {
stationStatusLineList.addAll(cacheLineList);
} }
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -47,30 +53,39 @@ public class StationStatusCache { ...@@ -47,30 +53,39 @@ public class StationStatusCache {
} }
public void updateStatusList(List<StationStatus> statusList) { public void updateStatusList(List<StationStatus> statusList) {
stationStatusList.clear(); stationStatusMap.clear();
stationStatusList.addAll(statusList); stationStatusLineList.clear();
dataCache.updateCache(MAICHENG_STATIONSTATUS_CACHE, stationStatusList); for (StationStatus stationStatus : statusList) {
} String station = stationStatus.getSTATION();
String partnumber = stationStatus.getPARTNUMBER();
String slot = stationStatus.getSLOT();
String line = stationStatus.getLINE();
String side = stationStatus.getSIDE();
String key = station + "_" + partnumber + "_" + slot + "_" + line+"_"+side;
stationStatusMap.put(key, key);
public List<StationStatus> getAllStationStatus() {
List<StationStatus> statusList = new ArrayList<>(); String trackNumber = "";
if (stationStatusList == null || stationStatusList.isEmpty()) {
stationStatusList = dataCache.getCache(MAICHENG_STATIONSTATUS_CACHE);
}
if (stationStatusList != null && !stationStatusList.isEmpty()) {
for (StationStatus status : stationStatusList) {
String station = status.getSTATION();
if (StringUtils.isNotBlank(station)) { if (StringUtils.isNotBlank(station)) {
String trackNumber = station.substring(station.length() - 1); trackNumber = station.substring(station.length() - 1);
status.setTrackNumber(trackNumber);
} }
statusList.add(status); String cacheLine = line + "_" + side + "_" + trackNumber;
stationStatusLineList.add(cacheLine);
}
dataCache.updateCache(MAIZHENG_STATIONSTATUS_CACHE_Map, stationStatusMap);
if (stationStatusLineList != null && !stationStatusLineList.isEmpty()){
stationStatusLineList = stationStatusLineList.stream().distinct().collect(Collectors.toList());
dataCache.updateCache(MAIZHENG_STATIONSTATUS_CACHE_Line_List, stationStatusLineList);
} }
} }
if (statusList != null && !statusList.isEmpty()){ public static Map<String, String> getStationStatusMap() {
statusList = statusList.stream().distinct().collect(Collectors.toList()); return stationStatusMap;
} }
return statusList;
public static List<String> getStationStatusLineList() {
return stationStatusLineList;
} }
} }
...@@ -13,7 +13,7 @@ api: ...@@ -13,7 +13,7 @@ api:
fetchGRUrl: #http://10.42.25.199:8082/api/wcs/fetchGR #gr标签 fetchGRUrl: #http://10.42.25.199:8082/api/wcs/fetchGR #gr标签
brandQtyUrl: #http://172.30.170.199:8082/api/wcs/brandQty #gr标签满卷数 brandQtyUrl: #http://172.30.170.199:8082/api/wcs/brandQty #gr标签满卷数
importUrl: #http://10.42.222.52:8001/smf-core/ext/forward/getDataLogs #内仓导入外仓picking虚拟仓数据 importUrl: #http://10.42.222.52:8001/smf-core/ext/forward/getDataLogs #内仓导入外仓picking虚拟仓数据
checkReelMeasure: #http://10.190.25.149:8001/Sct/CheckReelMeasure #散料量测接口 checkReelMeasure: #http://10.190.25.124:8001/Sct/CheckReelMeasure #散料量测接口
plant: 2810 plant: 2810
werks: 2810 werks: 2810
outerFactory: outerFactory:
...@@ -40,7 +40,7 @@ lizhen: ...@@ -40,7 +40,7 @@ lizhen:
url: http://172.30.97.63:8001/smf-core/api/Mes/machineCallMaterial url: http://172.30.97.63:8001/smf-core/api/Mes/machineCallMaterial
F4: F4:
name: 4F name: 4F
line: B03-4FSMT-11,B03-4FSMT-01,B03-4FSMT-13,B03-4FSMT-03,B03-4FSMT-14 line: B03-4FSMT-11,B03-4FSMT-01,B03-4FSMT-13,B03-4FSMT-03,B03-4FSMT-14,B03-4FSMT-04
url: http://172.25.252.12:8001/smf-core/api/Mes/machineCallMaterial url: http://172.25.252.12:8001/smf-core/api/Mes/machineCallMaterial
...@@ -102,6 +102,5 @@ app: ...@@ -102,6 +102,5 @@ app:
type: "" type: ""
menu: menu:
show: meInventory,meExpiredReport,meChangeReport,meprohibitedReport show: #innerMaterial
hide: hide:
\ No newline at end of file \ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!