Commit 3ab70f07 LN

感应料架接口修改

1 个父辈 e91fb981
......@@ -75,7 +75,7 @@ public class CodeBean {
}
public boolean isValid(){
return error == null && barcode != null;
return (error == null) && (barcode != null);
}
/**
......
......@@ -15,7 +15,7 @@ public interface IOpAuthApi {
* @return
* @throws ValidateException
*/
Barcode resolveBarcode(String code) throws ValidateException;
Barcode resolveBarcode(String loginUser, String groupId,String storageId, String code) throws ValidateException;
/**
* 是否可入库验证
......@@ -26,4 +26,6 @@ public interface IOpAuthApi {
* 是否要出库验证
*/
boolean canCheckout(Barcode barcode) throws ValidateException;
boolean isEnable();
}
......@@ -303,7 +303,7 @@ public class BaseDeviceHandler implements IDeviceHandler {
return responseBarcode;
}
}
return barcode;
return null;
}
/**
......
......@@ -8,6 +8,7 @@ import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.SecurityUtils;
import com.neotel.smfcore.common.utils.StorageConstants;
import com.neotel.smfcore.core.barcode.bean.CodeBean;
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.manager.IComponentManager;
......@@ -26,8 +27,11 @@ import com.neotel.smfcore.core.system.util.DevicesStatusUtil;
import com.neotel.smfcore.core.system.websocket.MsgType;
import com.neotel.smfcore.core.system.websocket.SocketMsg;
import com.neotel.smfcore.core.system.websocket.WebSocketServer;
import com.neotel.smfcore.hella.tcp.command.HellaReqCommand;
import com.neotel.smfcore.hella.tcp.command.HellaRespCommand;
import com.neotel.smfcore.security.annotation.AnonymousAccess;
import com.neotel.smfcore.security.service.po.Group;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -44,6 +48,7 @@ import java.util.*;
* 感应料架
* Created by sunke on 2021/7/12.
*/
@Api(tags = "感应料架")
@RestController
@Slf4j
public class SensorShelfHandler extends BaseDeviceHandler {
......@@ -56,7 +61,7 @@ public class SensorShelfHandler extends BaseDeviceHandler {
* 扫码
*/
@ApiOperation("扫码入库")
@PostMapping("/codeIn")
@PostMapping("/api/sensorShelf/codeIn")
@PreAuthorize("@el.check('sensorShelf:putIn')")
public ResultBean codeIn( @RequestBody Map<String, String> mapValues) {
String code = mapValues.get("code");
......@@ -93,7 +98,7 @@ public class SensorShelfHandler extends BaseDeviceHandler {
}
}
Barcode barcodeSave = resolveBarcodeFromApiForShelf(code);
Barcode barcodeSave = resolveBarcodeFromApiForShelf(loginUser,groupId,storageId,code);
if(barcodeSave == null){
barcodeSave = codeResolve.resolveOneValideBarcode(code);
}
......@@ -106,20 +111,68 @@ public class SensorShelfHandler extends BaseDeviceHandler {
}
//从API验证
barcodeSave = verifyPutInFromApi(barcodeSave);
Barcode verResult = verifyPutInFromApi(barcodeSave);
if(verResult==null){
return testPutIn(loginUser,groupId,storageId, barcodeSave);
}
// resultBean = hellaServiceHandler.checkMaterial(loginUser, groupId, code);
return resultBean;
return ResultBean.newOkResult("");
}
private ResultBean testPutIn(String loginUser, String groupId,String storageId,Barcode barcode) {
// CodeBean codeBean = codeResolve.resolveSingleCode(codeStr);
if (barcode == null || barcode.getBarcode() == null) {
return ResultBean.newErrorResult(1, "smfcode.error.barcode.invalid", "条码无效");
}
String pn = barcode.getPartNumber();
String reelId = barcode.getBarcode();
String num = barcode.getAmount() + "";
Integer qty = barcode.getAmount();
String msl = barcode.getMsl();
try {
//需要模拟一个库位
DataLog dataLog = new DataLog();
dataLog.setBarcode(reelId);
dataLog.setPartNumber(pn);
dataLog.setType(OP.PUT_IN);
dataLog.setNum(barcode.getAmount());
dataLog.setStatus(OP_STATUS.WAIT.name());
dataLog.setGroupId(groupId);
dataLog.setStorageId(storageId);
dataLog.setMemo(barcode.getMemo());
dataLog.setOperator(loginUser);
if (ObjectUtil.isNotEmpty(storageId)) {
Storage storage = dataCache.getStorageById(storageId);
if (storage != null) {
dataLog.setCid(storage.getCid());
dataLog.setStorageName(storage.getName());
}
}
try {
taskService.addTaskToExecute(dataLog);
} catch (Exception e) {
WebSocketServer.sendGroupMsg(groupId, new SocketMsg(e.getMessage(), MsgType.INFO));
}
} catch (ValidateException e) {
log.error(e.toString());
return ResultBean.newErrorResult(1, e.getMsgKey(), e.getDefaultMsg());
}
return ResultBean.newOkResult("");
}
/**
* 从API接口解析条码,通常料架使用(其他设备会有尺寸信息且会有多个条码所以不适用此方法)
*/
protected Barcode resolveBarcodeFromApiForShelf(String code) throws ValidateException{
protected Barcode resolveBarcodeFromApiForShelf(String loginUser, String groupId,String storageId, String code) throws ValidateException{
for (IOpAuthApi opAuthApi : opAuthApiList) {
Barcode responseBarcode = opAuthApi.resolveBarcode(code);
Barcode responseBarcode = opAuthApi.resolveBarcode(loginUser,groupId,storageId,code);
if(responseBarcode != null){
return responseBarcode;
}
......
......@@ -98,7 +98,7 @@ public class SettingsController {
@ApiOperation("获取系统设置信息")
@GetMapping("sysSettings")
@GetMapping("/sysSettings")
@PreAuthorize("@el.check('sysSetting')")
public SysSettingsDto getSysSettings() {
......@@ -112,7 +112,7 @@ public class SettingsController {
}
@ApiOperation("修改系统设置信息")
@PutMapping("sysSettings")
@PutMapping("/sysSettings")
@PreAuthorize("@el.check('sysSetting')")
public ResultBean updateSysSettings(@Validated @RequestBody SysSettingsDto sysSettingsDto) {
dataCache.updateCache(Constants.CACHE_StopOut, sysSettingsDto.isStopOut());
......@@ -123,7 +123,7 @@ public class SettingsController {
}
@ApiOperation("获取出库策略信息")
@GetMapping("checkoutSettings")
@GetMapping("/checkoutSettings")
@PreAuthorize("@el.check('outSetting')")
public Map<String,String> getCheckOutSettings() {
String outSet = dataCache.getCache(Constants.CACHE_CheckOutType);
......@@ -133,7 +133,7 @@ public class SettingsController {
}
@ApiOperation("修改出库策略")
@PutMapping("checkoutSettings")
@PutMapping("/checkoutSettings")
@PreAuthorize("@el.check('outSetting')")
public ResultBean update(@Validated @RequestBody String type) {
// String type=map.get("checkOutType");
......
package com.neotel.smfcore.hella.handler;
import cn.hutool.core.util.ObjectUtil;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.core.barcode.service.po.Barcode;
import com.neotel.smfcore.core.device.api.IOpAuthApi;
import com.neotel.smfcore.core.storage.service.po.Storage;
import com.neotel.smfcore.hella.tcp.HellaTcpClient;
import com.neotel.smfcore.hella.tcp.command.HellaReqCommand;
import com.neotel.smfcore.hella.tcp.command.HellaRespCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class HellaApiHandler implements IOpAuthApi {
@Autowired
private HellaServiceHandler hellaServiceHandler;
@Override
public Barcode resolveBarcode(String loginUser, String groupId,String storageId, String code) throws ValidateException {
if (!isEnable()) {
return null;
}
hellaServiceHandler.checkMaterial(loginUser, groupId, storageId, code);
Barcode barcode = new Barcode();
barcode.setFullCode(code);
return barcode;
}
@Override
public Barcode canPutIn(Barcode barcode) throws ValidateException {
if (!isEnable()) {
return null;
}
return barcode;
}
@Override
public boolean canCheckout(Barcode barcode) throws ValidateException {
if(!isEnable()){
return false;
}
return false;
}
@Override
public boolean isEnable() {
return HellaTcpClient.isEnable();
}
}
package com.neotel.smfcore.hella.rest;
import cn.hutool.core.util.ObjectUtil;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.SecurityUtils;
import com.neotel.smfcore.core.barcode.service.manager.IBarcodeManager;
import com.neotel.smfcore.core.barcode.service.po.Barcode;
import com.neotel.smfcore.core.device.util.DataCache;
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.StoragePos;
import com.neotel.smfcore.core.system.service.po.DataLog;
import com.neotel.smfcore.core.system.util.TaskService;
import com.neotel.smfcore.hella.handler.HellaServiceHandler;
import com.neotel.smfcore.security.service.manager.IGroupManager;
import com.neotel.smfcore.security.service.po.Group;
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.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.*;
/**
* 感应料架
*/
@Api(tags = "海拉感应料架")
@RequestMapping("/api/sensorShelf")
@RestController
@Slf4j
public class HellaSensorShelfController {
@Autowired
private DataCache dataCache;
@Autowired
private HellaServiceHandler hellaServiceHandler;
@Autowired
private TaskService taskService;
@Autowired
protected IStoragePosManager storagePosManager;
@Autowired
protected IBarcodeManager barcodeManager;
@Autowired
protected IGroupManager groupManager;
/**
* 扫码
*/
@ApiOperation("扫码入库")
@PostMapping("/codeIn")
@PreAuthorize("@el.check('sensorShelf:putIn')")
public ResultBean codeIn( @RequestBody Map<String, String> mapValues) {
String code = mapValues.get("code");
String groupId = mapValues.get("group");
String storageId=mapValues.get("storageId");
if(ObjectUtils.isEmpty(code)){
throw new ValidateException("smfcode.valueCanotNull", "{0}不能为空", new String[]{"code"});
}
if(groupId==null&&storageId==null){
throw new ValidateException("smfcode.valueCanotNull", "{0}不能为空", new String[]{"group"});
}
if(groupId==null&&storageId!=null){
Storage storage=dataCache.getStorageById(storageId);
if(storage!=null){
groupId=storage.getGroupId();
}
}
if(groupId!=null&&groupId.equals("-1")){
groupId="";
}
String loginUser = SecurityUtils.getLoginUsername();
Collection<DataLog> queueTasks = taskService.getQueueTasks();
ResultBean resultBean = null;
for (DataLog queueTask : queueTasks) {
if (queueTask.isPutInTask() && queueTask.isWait()) {
if (ObjectUtil.isEmpty(storageId)&& groupId != null && queueTask.getGroupId().equals(groupId)) {
log.info("codeIn [" + code + "][" + groupId + "]入库失败:条码[" + queueTask.getBarcode() + "]的任务还未结束 ");
throw new ValidateException("smfcore.unfinished", "the task of [{0}] is unfinished", new String[]{queueTask.getBarcode()});
}
if (storageId != null && queueTask.getStorageId().equals(storageId)) {
log.info("codeIn [" + code + "][" + storageId + "]入库失败:条码[" + queueTask.getBarcode() + "]的任务还未结束 ");
throw new ValidateException("smfcore.unfinished", "the task of [{0}] is unfinished", new String[]{queueTask.getBarcode()});
}
}
}
resultBean = hellaServiceHandler.checkMaterial(loginUser, groupId,storageId, code);
return resultBean;
}
}
......@@ -73,6 +73,14 @@ public class HellaTcpClient {
}
}
public static boolean isEnable() {
if (ObjectUtil.isEmpty(host) || ObjectUtil.isEmpty(port)) {
return false;
} else {
return true;
}
}
public static void updateServerInfo(String serverHost, int serverPort){
host = serverHost;
port = serverPort;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!