Commit 39006e31 zshaohui

1.保管区料架若有库存, 直接亮灯出库,保管区无库存,通知Kanban区

2.通知Kanban区失败, 保存失败信息, 页面展示发送失败内容, 并自动重试发送, 若发送成功, 清除保存的内容
3.Kanban区展示接收的内容, 并执行生成工单并出库
4.料盘扫码入库,可以修改数量信息
1 个父辈 7f1a115d
......@@ -162,6 +162,8 @@ public class MenuInit {
// addDefaultFunctionMenu(11, poutOut, "转储入库", "dumpWarehousing", "system/dumpWarehousing/index", "headIcon");
// addDefaultFunctionMenu(12, poutOut, "单盘入库", "singleDiskWarehousing", "system/singleDiskWarehousing/index", "headIcon");
addDefaultFunctionMenu(13, poutOut, "呆滞物料", "sluggishMaterials", "system/sluggishMaterials/index", "sMaterial");
addDefaultFunctionMenu(14, poutOut, "保管区", "prodUnprocessed", "prodUnprocessed/index", "prodUnprocessed");
addDefaultFunctionMenu(15, poutOut, "看板区", "shortageInfo", "shortageInfo/index", "shortageInfo");
//addDefaultFunctionMenu(16, poutOut,"生成工单", "createOrder", "system/createOrder/index", "createOrder");
addDefaultFunctionMenu(91,poutOut, "共享文件夹", "orderSetting", "system/orderSetting/index", "sysSet",DEFAULT_SHOW_MENU);
......
......@@ -207,4 +207,10 @@ public class Constants {
*/
public static final String Cache_AuthDate = "Cache_AuthDate";
/**
* 看板区出库地址
*/
public static final String Cache_KanBanAreaOutUrl = "Cache_KanBanAreaOutUrl";
}
......@@ -60,11 +60,27 @@ public class NLPShelfHandler extends BaseDeviceHandler {
String groupId = mapValues.get("group");
String storageId = mapValues.get("storageId");
String sourceId = mapValues.get("sourceId");
String token = tokenProvider.getToken(request);
if (ObjectUtils.isEmpty(code)) {
throw new ValidateException("smfcore.valueCanotNull", "{0}不能为空", new String[]{"code"});
}
//获取数量
String newAmountStr = mapValues.get("newAmount");
if (StringUtils.isEmpty(newAmountStr)){
throw new ValidateException("smfcore.valueCanotNull", "{0}不能为空", new String[]{"amount"});
}
log.info("barcode:[{}],新设置数量为[{}]",code,newAmountStr);
Integer newAmount = Integer.valueOf(newAmountStr);
if (newAmount == null || newAmount <= 0){
throw new ValidateException("smfcore.error.barcode.wrongQty", "条码[{0}]对应的数量<=0为: {1}", new String[]{code, newAmountStr});
}
String token = tokenProvider.getToken(request);
code = replaceSpecial(code);
if (groupId == null && storageId == null) {
......@@ -112,6 +128,9 @@ public class NLPShelfHandler extends BaseDeviceHandler {
if (verResult != null) {
barcodeSave = verResult;
}
//设置新数量
barcodeSave.setAmount(newAmount);
return putIn(loginUser, groupId, storageId, barcodeSave, token);
}catch (ValidateException ve){
return ResultBean.newErrorResult(-1,ve.getMsgKey(),ve.getDefaultMsg(),ve.getMsgParam());
......@@ -552,6 +571,22 @@ public class NLPShelfHandler extends BaseDeviceHandler {
return ResultBean.newOkResult(posList);
}
@ApiOperation("根据条码获取信息")
@PostMapping("/api/sensorShelf/getBarcodeInfo")
//@AnonymousAccess
public ResultBean codeIn(@RequestBody Map<String, String> mapValues) {
String code = mapValues.get("code");
if (StringUtils.isEmpty(code)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"code"});
}
Barcode barcode = codeResolve.resolveOneValideBarcode("=1x1="+code);
if (barcode == null) {
return ResultBean.newErrorResult(-1, "smfcore.error.barcode.noValidCode", "无效的条码");
}
return ResultBean.newOkResult(barcode);
}
@Override
public DeviceType getDeviceType() {
return DeviceType.NLP;
......
package com.neotel.smfcore.core.storage.rest;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.neotel.smfcore.common.bean.PageData;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.exception.ApiException;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.*;
import com.neotel.smfcore.core.barcode.enums.COMPONENT_TYPE;
import com.neotel.smfcore.core.barcode.service.manager.IBarcodeManager;
import com.neotel.smfcore.core.barcode.service.po.Barcode;
import com.neotel.smfcore.core.barcode.utils.CodeResolve;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.language.util.MessageUtils;
import com.neotel.smfcore.core.storage.bean.InventoryItem;
......@@ -26,6 +29,9 @@ import com.neotel.smfcore.core.storage.service.po.StoragePos;
import com.neotel.smfcore.core.system.service.po.DataLog;
import com.neotel.smfcore.core.system.util.DevicesStatusUtil;
import com.neotel.smfcore.core.system.util.TaskService;
import com.neotel.smfcore.custom.toyota1541.bean.ProductionAreaOut;
import com.neotel.smfcore.custom.toyota1541.util.ProductionAreaExpUtil;
import com.neotel.smfcore.security.annotation.AnonymousAccess;
import com.neotel.smfcore.security.service.manager.IGroupManager;
import com.neotel.smfcore.security.service.po.Group;
import com.neotel.smfcore.security.service.po.User;
......@@ -41,6 +47,7 @@ import org.springframework.data.mongodb.core.query.Query;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
......@@ -77,6 +84,9 @@ public class MaterialController {
@Autowired
private final IGroupManager groupManager;
@Autowired
private CodeResolve codeResolve;
@ApiOperation("导出库存列表")
@GetMapping(value = "/inventory/download")
@PreAuthorize("@el.check('tacticsOuput')")
......@@ -388,4 +398,47 @@ public class MaterialController {
}
}
@ApiOperation("扫描空盘直接出库")
@RequestMapping("/scanEmptyPallet")
//@AnonymousAccess
public ResultBean scanEmptyPallet(@RequestBody Map<String, String> paramMap) {
String code = paramMap.get("code");
log.info("扫描空盘直接出库,信息为:" + code);
if (StringUtils.isEmpty(code)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"code"});
}
Barcode barcode = codeResolve.resolveOneValideBarcode("=1x1=" + code);
if (barcode == null) {
return ResultBean.newErrorResult(-1, "smfcore.error.barcode.noValidCode", "无效的条码");
}
DataLog dataLog = taskService.scanEmptyPalletOut(barcode.getPartNumber(), 1);
if (dataLog == null) {
log.info("开始通知Kanban区进行出库");
String kanBanAreaOutUrl = dataCache.getCache(Constants.Cache_KanBanAreaOutUrl);
if (StringUtils.isNotEmpty(kanBanAreaOutUrl)) {
Map<String, Object> kanBanAreaOutMap = new HashMap<>();
long id = System.currentTimeMillis();
kanBanAreaOutMap.put("id", id);
kanBanAreaOutMap.put("partNumber", barcode.getPartNumber());
kanBanAreaOutMap.put("amount", barcode.getAmount());
kanBanAreaOutMap.put("batch", barcode.getBatch());
try {
log.info("通知看板区,参数为:"+ JSON.toJSONString(kanBanAreaOutMap));
String result = HttpHelper.postJson(kanBanAreaOutUrl, kanBanAreaOutMap);
log.info("通知结果为:" + result);
} catch (ApiException e) {
log.info("通知失败:", e);
ProductionAreaOut areaOut = new ProductionAreaOut(barcode.getPartNumber(), barcode.getAmount(), barcode.getBatch(), e.getMessage(), new Date());
areaOut.setId(id + "");
ProductionAreaExpUtil.updateProductionAreaExpOut(areaOut);
return ResultBean.newErrorResult(-1, "smfcore.notifyerror.kanban", "保管区无物料,通知看板区失败[{0}]", new String[]{e.getMessage()});
}
return ResultBean.newOkResult("smfcore.notify.kanban", "保管区无物料,通知看板区成功");
} else {
return ResultBean.newErrorResult(-1, "smfcore.label.noReel", "未找到可出库的物料");
}
}
return ResultBean.newOkResult("");
}
}
......@@ -82,6 +82,7 @@ public class SettingsController {
Integer caWarn=dataCache.getCache(Constants.CACHE_CapacityWarn);
Integer backUpMonth = dataCache.getCache(Constants.BACKUP_MONTH_KEY);
Boolean closeWorkOrder = dataCache.getCache(Constants.CACHE_closeWorkOrder);
String KanBanAreaOutUrl = dataCache.getCache(Constants.Cache_KanBanAreaOutUrl);
SysSettingsDto dto = new SysSettingsDto();
dto.setStartJob(startJob);
dto.setStopOut(stopOut);
......@@ -92,6 +93,7 @@ public class SettingsController {
if (closeWorkOrder != null) {
dto.setCloseWorkOrder(closeWorkOrder);
}
dto.setKanBanAreaOutUrl(KanBanAreaOutUrl);
return dto;
}
......@@ -106,9 +108,11 @@ public class SettingsController {
dataCache.updateCache(Constants.CACHE_CapacityWarn,sysSettingsDto.getCapacityWarn());
dataCache.updateCache(Constants.BACKUP_MONTH_KEY,sysSettingsDto.getBackUpMonth());
dataCache.updateCache(Constants.CACHE_closeWorkOrder,sysSettingsDto.isCloseWorkOrder());
dataCache.updateCache(Constants.Cache_KanBanAreaOutUrl,sysSettingsDto.getKanBanAreaOutUrl());
log.info("更改系统设置:stopout=" + sysSettingsDto.isStopOut() + ",stopjob=" + sysSettingsDto.isStartJob()+",sluggishDay="+sysSettingsDto.getSluggishDay()
+",expiresDay="+sysSettingsDto.getExpiresDay()+",capacityWarn="+sysSettingsDto.getCapacityWarn()+",backUpMonth="+sysSettingsDto.getBackUpMonth()
+",缺料不自动关闭工单="+sysSettingsDto.isCloseWorkOrder());
+",缺料不自动关闭工单="+sysSettingsDto.isCloseWorkOrder()
+",看板区出库地址="+sysSettingsDto.getKanBanAreaOutUrl());
return ResultBean.newOkResult("保存成功");
}
......
......@@ -30,4 +30,7 @@ public class SysSettingsDto implements Serializable {
@ApiModelProperty("缺料不自动关闭工单")
private boolean closeWorkOrder = false;
@ApiModelProperty("看板区出库地址")
private String kanBanAreaOutUrl = "";
}
......@@ -1294,4 +1294,42 @@ public class TaskService {
}
}
}
public synchronized DataLog scanEmptyPalletOut(String partNumber,int checkOutNum) {
CHECKOUT_TYPE checkoutType = dataCache.getCheckOutType();
List<String> availableStorageIds;
List<String> groupStorageId = SecurityUtils.getUserGroupStorageId();
if (groupStorageId != null && !groupStorageId.isEmpty()) {
availableStorageIds = groupStorageId;
} else {
availableStorageIds = dataCache.getAvailableStorageIds();
}
log.info("开始执行扫描空盘出库[" + partNumber + "] 盘数=" + checkOutNum);
int reelNum = 0;
while (reelNum < checkOutNum)
// for (int i = 1; i <= item.getPlateNumber(); i++) {
{
Collection<String> excludePosIds = excludePosIds();
StoragePos pos =
storagePosManager.findPartNumberInStorages(availableStorageIds, partNumber, excludePosIds, checkoutType);
if (pos == null) {
log.info("扫描空盘出库[" + partNumber + "] 未找到可以出库的物料[" + partNumber + "]");
return null;
//throw new ValidateException("smfcore.label.noReel", "未找到可出库的物料");
} else {
reelNum += 1;
log.info("扫描空盘出库,PN[" + partNumber + "]第[" + reelNum + "]盘, 出库位置仓位【" + pos.getPosName() + "】RI=[" + pos.getBarcode().getBarcode() + "] PN=[" + partNumber + "] num:" + pos.getBarcode().getAmount());
DataLog task = newTask(pos);
task.setType(OP.CHECKOUT);
task.setOperator(SecurityUtils.getCurrentUsername());
task.setSingleOut(true);
task.setSourceId(null);
task.setSourceName("PN");
addTaskToExecute(task);
return task;
}
}
return null;
}
}
package com.neotel.smfcore.custom.toyota1541.bean;
import com.neotel.smfcore.common.base.BasePo;
import lombok.Data;
import java.util.Date;
@Data
public class KanbanAreaOut extends BasePo {
private String partNumber;
private int amount;
private String batch;
//收到时间
private Date receiveDate;
}
package com.neotel.smfcore.custom.toyota1541.bean;
import com.neotel.smfcore.common.base.BasePo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ProductionAreaOut extends BasePo {
private String partNumber;
private int amount;
private String batch;
//异常原因
private String expReason;
//收到时间
private Date receiveDate;
}
package com.neotel.smfcore.custom.toyota1541.controller;
import cn.hutool.core.util.ObjectUtil;
import com.neotel.smfcore.common.bean.PageData;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.core.order.LiteOrderCache;
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.LiteOrderItem;
import com.neotel.smfcore.custom.toyota1541.bean.KanbanAreaOut;
import com.neotel.smfcore.custom.toyota1541.util.KanbanAreOutUtil;
import com.neotel.smfcore.security.annotation.AnonymousAccess;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
@Slf4j
@Api(tags = "看板区出库功能")
@RestController
@RequestMapping("/kanbanAreOut")
public class KanbanAreOutController {
@Autowired
private LiteOrderCache liteOrderCache;
@Autowired
private ILiteOrderManager liteOrderManager;
@ApiOperation("新增看板区出库信息")
@RequestMapping("/addKanbanAreOut")
@AnonymousAccess
public ResultBean addKanbanAreOut(@RequestBody KanbanAreaOut areaOut) {
log.info("收到生成区新出库信息,partNumber为[{}],id为[{}]",areaOut.getPartNumber(),areaOut.getId());
areaOut.setReceiveDate(new Date());
KanbanAreOutUtil.updateKanbanAreOut(areaOut);
return ResultBean.newOkResult("");
}
@ApiOperation("获取所有看板区要出库的任务")
@RequestMapping("/getAllKanbanAreOut")
//@AnonymousAccess
public PageData getAllKanbanAreOut() {
List<KanbanAreaOut> resultList = new ArrayList<>();
Collection<KanbanAreaOut> allKanbanAreOut = KanbanAreOutUtil.getAllKanbanAreOut();
if (allKanbanAreOut != null && !allKanbanAreOut.isEmpty()) {
for (KanbanAreaOut kanbanAreaOut : allKanbanAreOut) {
resultList.add(kanbanAreaOut);
}
}
return new PageData(resultList, resultList.size());
}
@ApiOperation("看板区生成工单")
@RequestMapping("/kanbanAreOutToOrder")
//@AnonymousAccess
public ResultBean kanbanAreOutToOrder() {
Collection<KanbanAreaOut> allKanbanAreOut = KanbanAreOutUtil.getAllKanbanAreOut();
if (allKanbanAreOut == null || allKanbanAreOut.isEmpty()) {
return ResultBean.newErrorResult(-1, "smfcore.order.out.noTask", "工单无可执行的任务");
}
LiteOrder order = new LiteOrder();
order.setOrderNo(System.currentTimeMillis() + "");
List<LiteOrderItem> itemList = new ArrayList<>();
for (KanbanAreaOut areaOut : allKanbanAreOut) {
LiteOrderItem item = new LiteOrderItem();
item.setPn(areaOut.getPartNumber());
item.setNeedReelCount(1);
item.addAppendDate("batch", areaOut.getBatch());
item.addAppendDate("amount", areaOut.getAmount() + "");
log.info("看板区生成工单并出库,partNumber为[{}],id为[{}],工单号为[{}]",areaOut.getPartNumber(),areaOut.getId(),order.getOrderNo());
itemList.add(item);
}
order.setOrderItems(itemList);
order = liteOrderManager.createWithItems(order);
liteOrderCache.addOrderToMap(order);
String result = liteOrderCache.checkOutLiteOrder(order.getOrderNo(), false);
//清空库存信息
KanbanAreOutUtil.clearKanbanAreOut();
if (ObjectUtil.isEmpty(result)) {
return ResultBean.newOkResult(result);
} else {
return ResultBean.newErrorResult(-1, result, result);
}
}
}
package com.neotel.smfcore.custom.toyota1541.controller;
import com.neotel.smfcore.common.bean.PageData;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.utils.StringUtils;
import com.neotel.smfcore.custom.toyota1541.bean.KanbanAreaOut;
import com.neotel.smfcore.custom.toyota1541.bean.ProductionAreaOut;
import com.neotel.smfcore.custom.toyota1541.util.ProductionAreaExpUtil;
import com.neotel.smfcore.security.annotation.AnonymousAccess;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
@Api(tags = "生产区通知看板区异常信息")
@Slf4j
@RequestMapping("/productionAreaExp")
@RestController
public class ProductionAreaExpController {
@ApiOperation("获取所有生产区异常列表")
@RequestMapping("/getAllProductionAreaExp")
//@AnonymousAccess
public PageData getAllProductionAreaExp() {
List<ProductionAreaOut> resultList = new ArrayList<>();
Collection<ProductionAreaOut> areaOuts = ProductionAreaExpUtil.getAllProductionAreaExpOut();
if (areaOuts != null && !areaOuts.isEmpty()) {
for (ProductionAreaOut areaOut : areaOuts) {
resultList.add(areaOut);
}
}
return new PageData(resultList, resultList.size());
}
@ApiOperation("重新发送生产区异常列表")
@RequestMapping("/resendProductionAreaExp")
//@AnonymousAccess
public ResultBean ResendProductionAreaExp() {
Collection<ProductionAreaOut> areaOuts = ProductionAreaExpUtil.getAllProductionAreaExpOut();
if (areaOuts == null || areaOuts.isEmpty()) {
return ResultBean.newOkResult("");
}
for (ProductionAreaOut areaOut : areaOuts) {
String result = ProductionAreaExpUtil.ResendProductionAreaExp(areaOut.getId());
if (StringUtils.isEmpty(result)){
ProductionAreaExpUtil.removeProductionAreaExpById(areaOut.getId());
} else {
areaOut.setExpReason(result);
ProductionAreaExpUtil.updateProductionAreaExpOut(areaOut);
}
}
return ResultBean.newOkResult("");
}
@ApiOperation("获取上一次推送时间")
@RequestMapping("lastResendDate")
public ResultBean lastResendDate(){
return ResultBean.newOkResult(ProductionAreaExpUtil.lastResendDate);
}
}
package com.neotel.smfcore.custom.toyota1541.controller;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.*;
import com.neotel.smfcore.core.api.SmfApi;
import com.neotel.smfcore.security.TokenProvider;
import com.neotel.smfcore.security.annotation.AnonymousPostMapping;
import com.neotel.smfcore.security.bean.LoginProperties;
import com.neotel.smfcore.security.bean.RsaProperties;
import com.neotel.smfcore.security.bean.SecurityProperties;
import com.neotel.smfcore.security.rest.bean.dto.AuthUserDto;
import com.neotel.smfcore.security.rest.bean.dto.JwtUserDto;
......@@ -27,7 +24,6 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -80,14 +76,14 @@ public class ToyotaLoginController {
}
//判断与登录是否一致
String loginCode = user.getLoginCode();
if (StringUtils.isEmpty(loginCode)){
/*if (StringUtils.isEmpty(loginCode)){
loginCode = id +"-"+ Md5Utls.getMd5(id, user.getCreateDate());
}
if (StringUtils.isEmpty(user.getLoginCode())){
user.setLoginCode(loginCode);
userManager.save(user);
}
if (!loginCode.equals(code)){
}*/
if (!code.equals(loginCode)){
throw new ValidateException("smfcore.login.codeError", "登录码[{0}]错误", new String[]{code});
}
......
package com.neotel.smfcore.custom.toyota1541.util;
import com.google.common.collect.Maps;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.custom.toyota1541.bean.KanbanAreaOut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.Map;
@Component
public class KanbanAreOutUtil {
private static DataCache dataCache;
@Autowired
private void setDataCache(DataCache cache) {
KanbanAreOutUtil.dataCache = cache;
}
public static final String Cache_KanbanAreOut_Out = "Cache_KanbanAreOut_Out";
public static void updateKanbanAreOut(KanbanAreaOut areaOut) {
Map<String, KanbanAreaOut> cacheMap = dataCache.getCache(Cache_KanbanAreOut_Out);
if (cacheMap == null) {
cacheMap = Maps.newConcurrentMap();
}
String id = areaOut.getId();
if (!cacheMap.containsKey(id)) {
cacheMap.put(id, areaOut);
}
dataCache.updateCache(Cache_KanbanAreOut_Out, cacheMap);
}
public static Collection<KanbanAreaOut> getAllKanbanAreOut(){
Map<String, KanbanAreaOut> cacheMap = dataCache.getCache(Cache_KanbanAreOut_Out);
if (cacheMap == null) {
cacheMap = Maps.newConcurrentMap();
}
return cacheMap.values();
}
public static void clearKanbanAreOut(){
Map<String, KanbanAreaOut> cacheMap = dataCache.getCache(Cache_KanbanAreOut_Out);
if (cacheMap == null) {
cacheMap = Maps.newConcurrentMap();
}
cacheMap.clear();
dataCache.updateCache(Cache_KanbanAreOut_Out, cacheMap);
}
public static KanbanAreaOut getKanbanAreOutById(String id){
Map<String, KanbanAreaOut> cacheMap = dataCache.getCache(Cache_KanbanAreOut_Out);
if (cacheMap == null) {
cacheMap = Maps.newConcurrentMap();
}
return cacheMap.get(id);
}
}
package com.neotel.smfcore.custom.toyota1541.util;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.exception.ApiException;
import com.neotel.smfcore.common.utils.Constants;
import com.neotel.smfcore.common.utils.HttpHelper;
import com.neotel.smfcore.common.utils.StringUtils;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.custom.toyota1541.bean.KanbanAreaOut;
import com.neotel.smfcore.custom.toyota1541.bean.ProductionAreaOut;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@Slf4j
@Component
public class ProductionAreaExpUtil {
private static DataCache dataCache;
@Autowired
private void setDataCache(DataCache cache) {
ProductionAreaExpUtil.dataCache = cache;
}
public static final String Cache_ProductionArea_Exp = "Cache_ProductionArea_Exp";
public static Date lastResendDate = null;
ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(1);
@PostConstruct
public void init() {
//1 分钟之后执行,每秒钟执行一次
scheduledThreadPool.scheduleAtFixedRate(() -> {
Collection<ProductionAreaOut> areaOuts = getAllProductionAreaExpOut();
if (areaOuts == null || areaOuts.isEmpty()) {
return;
}
for (ProductionAreaOut areaOut : areaOuts) {
String result = ResendProductionAreaExp(areaOut.getId());
if (StringUtils.isEmpty(result)) {
removeProductionAreaExpById(areaOut.getId());
} else {
areaOut.setExpReason(result);
updateProductionAreaExpOut(areaOut);
}
}
}, 60, 10, TimeUnit.SECONDS);
}
public static void updateProductionAreaExpOut(ProductionAreaOut areaOut) {
Map<String, ProductionAreaOut> cacheMap = dataCache.getCache(Cache_ProductionArea_Exp);
if (cacheMap == null) {
cacheMap = Maps.newConcurrentMap();
}
String id = areaOut.getId();
if (!cacheMap.containsKey(id)) {
cacheMap.put(id, areaOut);
}
dataCache.updateCache(Cache_ProductionArea_Exp, cacheMap);
}
public static Collection<ProductionAreaOut> getAllProductionAreaExpOut(){
Map<String, ProductionAreaOut> cacheMap = dataCache.getCache(Cache_ProductionArea_Exp);
if (cacheMap == null) {
cacheMap = Maps.newConcurrentMap();
}
return cacheMap.values();
}
public static String ResendProductionAreaExp(String id) {
Map<String, ProductionAreaOut> cacheMap = dataCache.getCache(Cache_ProductionArea_Exp);
if (cacheMap == null) {
cacheMap = Maps.newConcurrentMap();
}
lastResendDate = new Date();
ProductionAreaOut areaOut = cacheMap.get(id);
if (areaOut == null) {
return "";
}
String kanBanAreaOutUrl = dataCache.getCache(Constants.Cache_KanBanAreaOutUrl);
if (StringUtils.isEmpty(kanBanAreaOutUrl)) {
return "smfcore.nokanBanAreaOutUrl";
}
if (StringUtils.isNotEmpty(kanBanAreaOutUrl)) {
Map<String, Object> kanBanAreaOutMap = new HashMap<>();
kanBanAreaOutMap.put("id", areaOut.getId());
kanBanAreaOutMap.put("partNumber", areaOut.getPartNumber());
kanBanAreaOutMap.put("amount", areaOut.getAmount());
kanBanAreaOutMap.put("batch", areaOut.getBatch());
try {
log.info("重新发送生成区异常信息,参数为:"+ JSON.toJSONString(kanBanAreaOutMap));
String result = HttpHelper.postJson(kanBanAreaOutUrl, kanBanAreaOutMap);
log.info("通知结果为:" + result);
} catch (ApiException e) {
log.info("通知失败:", e);
return e.getMessage();
}
}
return "";
}
public static void removeProductionAreaExpById(String id) {
Map<String, ProductionAreaOut> cacheMap = dataCache.getCache(Cache_ProductionArea_Exp);
if (cacheMap == null) {
cacheMap = Maps.newConcurrentMap();
}
cacheMap.remove(id);
dataCache.updateCache(Cache_ProductionArea_Exp, cacheMap);
}
}
......@@ -402,4 +402,8 @@ smfcore.storagePos.yes=\u662F
smfcore.storagePos.no=\u5426
smfcore.dashBoard=\u4EEA\u8868\u76D8
smfcore.spHumiture=\u6E29\u6E7F\u5EA6
smfcore.login.codeError=\u767B\u5F55\u7801[{0}]\u9519\u8BEF
\ No newline at end of file
smfcore.login.codeError=\u767B\u5F55\u7801[{0}]\u9519\u8BEF
smfcore.notify.kanban=\u4FDD\u7BA1\u533A\u65E0\u7269\u6599,\u901A\u77E5\u770B\u677F\u533A\u6210\u529F
smfcore.notifyerror.kanban=\u4FDD\u7BA1\u533A\u65E0\u7269\u6599,\u901A\u77E5\u770B\u677F\u533A\u5931\u8D25[{0}]
smfcore.prodUnprocessed=\u4FDD\u7BA1\u533A
smfcore.shortageInfo=\u770B\u677F\u533A
......@@ -393,4 +393,8 @@ smfcore.storagePos.yes=Yes
smfcore.storagePos.no=No
smfcore.dashBoard=Dashboard
smfcore.spHumiture=Temperature & Humidity
smfcore.login.codeError=Login code [{0}] error
\ No newline at end of file
smfcore.login.codeError=Login code [{0}] error
smfcore.notify.kanban=No materials in storage area, Kanban notification successful
smfcore.notifyerror.kanban=No materials in storage area, failed to notify Kanban area [{0}]
smfcore.prodUnprocessed=Storage Area
smfcore.shortageInfo=Kanban Area
\ No newline at end of file
......@@ -389,4 +389,8 @@ smfcore.storagePos.yes=\u662F
smfcore.storagePos.no=\u5426
smfcore.dashBoard=\u30C0\u30C3\u30B7\u30E5\u30DC\u30FC\u30C9
smfcore.spHumiture=\u6E29\u6E7F\u5EA6
smfcore.login.codeError=\u30ED\u30B0\u30A4\u30F3\u30B3\u30FC\u30C9[{0}]\u30A8\u30E9\u30FC
\ No newline at end of file
smfcore.login.codeError=\u30ED\u30B0\u30A4\u30F3\u30B3\u30FC\u30C9[{0}]\u30A8\u30E9\u30FC
smfcore.notify.kanban=\u4FDD\u7BA1\u5EAB\u306B\u8CC7\u6750\u3042\u308A\u307E\u305B\u3093\u3001\u30AB\u30F3\u30D0\u30F3\u901A\u77E5\u6210\u529F
smfcore.notifyerror.kanban=\u4FDD\u7BA1\u533A\u306B\u8CC7\u6750\u3042\u308A\u307E\u305B\u3093\u3001\u770B\u677F\u533A\u3078\u306E\u901A\u77E5\u306B\u5931\u6557\u3057\u307E\u3057\u305F[{0}]
smfcore.prodUnprocessed=\u4FDD\u7BA1\u30A8\u30EA\u30A2
smfcore.shortageInfo=\u30AB\u3093\u3070\u3093\u30A8\u30EA\u30A2
\ No newline at end of file
......@@ -389,4 +389,8 @@ smfcore.storagePos.yes=\u662F
smfcore.storagePos.no=\u5426
smfcore.dashBoard=\u4EEA\u8868\u76D8
smfcore.spHumiture=\u6E29\u6E7F\u5EA6
smfcore.login.codeError=\u767B\u5F55\u7801[{0}]\u9519\u8BEF
\ No newline at end of file
smfcore.login.codeError=\u767B\u5F55\u7801[{0}]\u9519\u8BEF
smfcore.notify.kanban=\u4FDD\u7BA1\u533A\u65E0\u7269\u6599,\u901A\u77E5\u770B\u677F\u533A\u6210\u529F
smfcore.notifyerror.kanban=\u4FDD\u7BA1\u533A\u65E0\u7269\u6599,\u901A\u77E5\u770B\u677F\u533A\u5931\u8D25[{0}]
smfcore.prodUnprocessed=\u4FDD\u7BA1\u533A
smfcore.shortageInfo=\u770B\u677F\u533A
\ No newline at end of file
......@@ -389,4 +389,9 @@ smfcore.storagePos.yes=\u662F
smfcore.storagePos.no=\u5426
smfcore.dashBoard=SP\u5100\u9336\u76E4
smfcore.spHumiture=\u6E29\u6E7F\u5EA6
smfcore.login.codeError=\u767B\u9304\u78BC[{0}]\u932F\u8AA4
\ No newline at end of file
smfcore.login.codeError=\u767B\u9304\u78BC[{0}]\u932F\u8AA4
smfcore.notify.kanban=\u4FDD\u7BA1\u5340\u7121\u7269\u6599, \u901A\u77E5\u770B\u677F\u5340\u6210\u529F
smfcore.notifyerror.kanban=\u4FDD\u7BA1\u5340\u7121\u7269\u6599, \u901A\u77E5\u770B\u677F\u5340\u5931\u6557[{0}]
smfcore.prodUnprocessed=\u4FDD\u7BA1\u5340
smfcore.shortageInfo=\u770B\u677F\u5340
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!