Commit 895cceb8 sunke

消息推送

1 个父辈 4881ed4e
......@@ -85,7 +85,7 @@ public class GlobalExceptionHandler {
public ResponseEntity<ApiError> validateException(HttpServletRequest servlet,ValidateException e){
String language= servlet.getLocale().getLanguage();
// 打印堆栈信息
log.error(ThrowableUtil.getStackTrace(e));
//log.error(ThrowableUtil.getStackTrace(e));
String targetMsg=messageUtils.getText(e.getMsgKey(),e.getMsgParam(),new Locale(language) ,e.getDefaultMsg());
return buildResponseEntity(ApiError.error(e.getStatus(),targetMsg));
}
......
......@@ -194,7 +194,7 @@ public class DataInitManager {
//用户管理:用户管理,角色管理
Menu pMenuUser=Menu.CreatePMenu("用户管理",30,"user",2,"Steve-Jobs");
Menu pMenuUser=Menu.CreatePMenu("用户管理",30,"userManager",2,"Steve-Jobs");
Menu menuUser = new Menu(new ArrayList<Menu>(), 1, "user:list", "用户管理", 1, "peoples", "system/user/index", "", 0, "peoples");
Menu menuRole = new Menu(new ArrayList<Menu>(), 1, "role:list", "角色管理", 1, "role", "system/role/index", "", 0, "role");
......
......@@ -19,6 +19,9 @@ 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.StoragePos;
import com.neotel.smfcore.core.system.service.po.DataLog;
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.security.annotation.AnonymousAccess;
import com.neotel.smfcore.security.service.po.Group;
import lombok.extern.slf4j.Slf4j;
......@@ -83,11 +86,11 @@ public class SensorShelfHandler extends BaseDeviceHandler {
return ResultBean.newErrorResult(-1,"smfcore.shelfNotExist", "{0}对应的料架不存在",new String[]{cid} );
}
String groupId = storage.getGroupId();
String groupName = "";
Group group = groupManager.get(groupId);
if(group != null){
groupName = group.getGroupName();
}
// String groupName = "";
// Group group = groupManager.get(groupId);
// if(group != null){
// groupName = group.getGroupName();
// }
String[] hasReelPosList = request.getParameterValues("hasReelPosList");
String[] noReelPosList = request.getParameterValues("noReelPosList");
......@@ -99,19 +102,22 @@ public class SensorShelfHandler extends BaseDeviceHandler {
if(hasReelPosList != null){
//入库的库位列表
if(hasReelPosList.length > 1){
log.error("不可同时放入多盘物料:"+ hasReelPosList);
String msg = "不可同时放入多盘物料:"+ hasReelPosList;
log.error(msg);
WebSocketServer.sendGroupMsg(groupId,new SocketMsg(msg, MsgType.ERROR));
for (String posStr : hasReelPosList) {
inNgList.add(posStr);
}
}else{
StoragePos pos = storagePosManager.getByPosName(hasReelPosList[0]);
if(pos == null){
inNgList.add(hasReelPosList[0]);
log.error("未找到库位:"+ hasReelPosList);
String msg = "未找到库位:"+ hasReelPosList;
log.error(msg);
WebSocketServer.sendGroupMsg(groupId,new SocketMsg(msg, MsgType.ERROR));
}else{
Collection<DataLog> queueTasks = taskService.getQueueTasks();
for (DataLog queueTask : queueTasks) {
if(queueTask.isPutInTask() && queueTask.getSourceName().equals(groupName)){
if(queueTask.isPutInTask() && queueTask.getGroupId().equals(groupId)){
queueTask.setCid(cid);
queueTask.setPosId(pos.getId());
queueTask.setPosName(pos.getPosName());
......@@ -121,6 +127,9 @@ public class SensorShelfHandler extends BaseDeviceHandler {
//入库完成,发送入库完成请求
super.finishedPutIn(cid,pos.getPosName());
inOkList.add(hasReelPosList[0]);
String msg = queueTask.getBarcode()+ "入库到"+ pos.getPosName()+"成功";
log.error(msg);
WebSocketServer.sendGroupMsg(groupId,new SocketMsg(msg, MsgType.INFO));
break;
} catch (Exception e) {
log.error("入库出错",e);
......@@ -148,6 +157,10 @@ public class SensorShelfHandler extends BaseDeviceHandler {
try {
outResult = posName;
super.finishedOutPos(cid,posName);
inOkList.add(hasReelPosList[0]);
String msg = queueTask.getBarcode()+ "从"+ posName+"出库成功";
log.error(msg);
WebSocketServer.sendGroupMsg(groupId,new SocketMsg(msg, MsgType.INFO));
break;
} catch (Exception e) {
log.error("出库出错",e);
......@@ -156,8 +169,10 @@ public class SensorShelfHandler extends BaseDeviceHandler {
}
}
if(outResult.isEmpty()){
log.info("未找到["+posName+"]的出库任务");
outNgList.add(posName);
String msg = "未找到["+posName+"]的出库任务";
log.error(msg);
WebSocketServer.sendGroupMsg(groupId,new SocketMsg(msg, MsgType.ERROR));
}else{
outOkList.add(outResult);
}
......
package com.neotel.smfcore.core.language.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import java.util.Locale;
/**
* 配置国际化语言
* Created by sunke on 2021/7/30.
*/
@Configuration
public class LocaleConfig {
/**
* 默认解析器 其中locale表示默认语言
*/
//package com.neotel.smfcore.core.language.config;
//
//import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.ComponentScan;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.web.servlet.LocaleResolver;
//import org.springframework.web.servlet.config.annotation.*;
//import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
//import org.springframework.web.servlet.i18n.SessionLocaleResolver;
//
//import java.util.Locale;
//
///**
// * 配置国际化语言
// * Created by sunke on 2021/7/30.
// */
//@Configuration
////@EnableAutoConfiguration
//public class LocaleConfig implements WebMvcConfigurer {
//
// /**
// * 默认解析器 其中locale表示默认语言
// */
// @Bean
public LocaleResolver localeResolver() {
SessionLocaleResolver localeResolver = new SessionLocaleResolver();
localeResolver.setDefaultLocale(Locale.CHINESE);
return localeResolver;
}
/**
* 默认拦截器 其中lang表示切换语言的参数名
*/
@Bean
public WebMvcConfigurer localeInterceptor() {
return new WebMvcConfigurer() {
@Override
public void addInterceptors(InterceptorRegistry registry) {
LocaleChangeInterceptor localeInterceptor = new LocaleChangeInterceptor();
localeInterceptor.setParamName("lang");
registry.addInterceptor(localeInterceptor);
}
};
}
}
// public LocaleResolver localeResolver() {
// SessionLocaleResolver localeResolver = new SessionLocaleResolver();
// localeResolver.setDefaultLocale(Locale.JAPAN);
// return localeResolver;
// }
//
// @Bean
// public LocaleChangeInterceptor localeChangeInterceptor() {
// LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
// // 参数名
// lci.setParamName("lang");
// return lci;
// }
//
// @Override
// public void addInterceptors(InterceptorRegistry registry) {
// registry.addInterceptor(localeChangeInterceptor());
//
// }
//}
......@@ -2,6 +2,7 @@ package com.neotel.smfcore.core.storage.rest;
import com.google.common.base.Strings;
import com.neotel.smfcore.common.bean.PageData;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.Constants;
import com.neotel.smfcore.common.utils.QueryHelp;
......@@ -202,7 +203,7 @@ public class StoragePosController {
@ApiOperation("查找出库")
@PutMapping("/checkout")
public ResponseEntity<Object> checkout(@Validated @RequestBody CheckOutDto checkOutDto) {
public ResultBean checkout(@Validated @RequestBody CheckOutDto checkOutDto) {
if (checkOutDto.getPids() == null) {
throw new ValidateException("smfcode.valueCanotNull","{0}不能为空",new String[]{"ID"} );
......@@ -232,6 +233,6 @@ public class StoragePosController {
throw new ValidateException("smfcode.error", outResult);
}
}
return new ResponseEntity<>(HttpStatus.OK);
return ResultBean.newOkResult("");
}
}
......@@ -30,6 +30,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Calendar;
import java.util.List;
import java.util.Set;
......@@ -79,22 +80,10 @@ public class TaskController {
@ApiOperation("获取队列中的任务")
@GetMapping
@PreAuthorize("@el.check('task:inQueue','task:list')")
public PageData<TaskDto> filterTask(TaskQueryCondition criteria, Pageable pageable){
if(ObjectUtils.isEmpty(criteria.getGroupId())){
throw new ValidateException("smfcode.valueCanotNull","{0}不能为空",new String[]{"groupId"} );
}
List<String> cids=getCids(criteria.getGroupId(),criteria.getCids());
Query query=new Query(Criteria.where("cid").in(cids) );
Criteria c = Criteria.where("status").nin(OP_STATUS.FINISHED.name(),OP_STATUS.CANCEL.name());
//只查找近12个小时未完成的任务
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.HOUR_OF_DAY,-24);
c.and("createDate").gte(calendar.getTime());
query.addCriteria(c);
PageData<DataLog> taskList = dataLogManager.findByPage(query, pageable);
List<TaskDto> taskDtos=taskMapper.toDto(taskList.getContent());
return new PageData<TaskDto>(taskDtos,taskList.getTotalElements());
public List<TaskDto> filterTask(TaskQueryCondition criteria,HttpServletRequest request){
String groupId = criteria.getGroupId();
String[] cids = criteria.getCids();
return getTaskList(groupId,cids);
}
private List<String> getCids(String groupId,String[] cids) {
List<String> cidList = Lists.newArrayList();
......@@ -131,11 +120,15 @@ public class TaskController {
}
}
}
if(cidList.isEmpty()){
if(!cidList.isEmpty()){
for (DataLog task : allTasks) {
String cid = task.getCid();
if(cidList.contains(cid)){
resultTasks.add(task);
}else if(!ObjectUtils.isEmpty(groupId)){
if(task.getGroupId().equals(groupId)){
resultTasks.add(task);
}
}
}
}else{
......
......@@ -5,6 +5,7 @@ import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
@Getter
......@@ -122,4 +123,6 @@ public class TaskDto implements Serializable {
* 亮灯料架颜色
*/
private String lightColor = "";
private Date updateDate;
}
......@@ -51,6 +51,11 @@ public class DataLog extends BasePo implements Serializable {
private String cid;
/**
* 分组ID
*/
private String groupId;
/**
* 料仓 ID
*/
private String storageId;
......@@ -63,10 +68,10 @@ public class DataLog extends BasePo implements Serializable {
/**
* 仓位名称
*/
private String posName;
private String posName = "";
//二维码(Reel ID)
private String barcode;
private String barcode = "";
/**
* 物料编号
......
......@@ -56,25 +56,25 @@ public class WebSocketServer {
public void onOpen(Session session, @PathParam("sid") String sid) {
log.info(sid+"的webSocket已连接:" + session.getId());
this.session = session;
this.sid=sid;
//如果存在就先删除一个,防止重复推送消息
for (WebSocketServer webSocket:webSocketSet) {
if (webSocket.sid.equals(sid)) {
log.info("清理旧的["+this.sid+"]的连接:"+ session.getId());
log.info("清理旧的["+sid+"]的连接:"+ session.getId());
webSocketSet.remove(webSocket);
}
}
webSocketSet.add(this);
this.sid=sid;
for (int i =0;i<10;i++){
try {
Thread.sleep(1000);
WebSocketServer.sendInfo(new SocketMsg(new Date() + "的消息",MsgType.ERROR),"hella");
} catch (Exception e) {
log.error("发送失败",e);
}
}
// for (int i =0;i<10;i++){
// try {
// Thread.sleep(1000);
// WebSocketServer.sendInfo(new SocketMsg(new Date() + "的消息",MsgType.ERROR),"group-1");
// } catch (Exception e) {
// log.error("发送失败",e);
// }
// }
}
......@@ -83,7 +83,7 @@ public class WebSocketServer {
*/
@OnClose
public void onClose() {
log.info("清理连接:"+ session.getId());
log.info("清理["+this.sid+"]连接:"+ session.getId());
webSocketSet.remove(this);
}
......@@ -115,11 +115,19 @@ public class WebSocketServer {
this.session.getBasicRemote().sendText(message);
}
/**
* 发送分组消息
*/
public static void sendGroupMsg(String groupId, SocketMsg socketMsg) {
String sid = "group-"+groupId;
sendInfo(socketMsg,sid);
}
/**
* 群发自定义消息
* */
public static void sendInfo(SocketMsg socketMsg,@PathParam("sid") String sid) throws IOException {
public static void sendInfo(SocketMsg socketMsg,@PathParam("sid") String sid){
String message = JSONObject.toJSONString(socketMsg);
log.info("推送消息到"+sid+",推送内容:"+message);
for (WebSocketServer item : webSocketSet) {
......@@ -130,7 +138,9 @@ public class WebSocketServer {
}else if(item.sid.equals(sid)){
item.sendMessage(message);
}
} catch (IOException ignored) { }
} catch (IOException ignored) {
log.error("发送消息到"+sid+"出错",ignored);
}
}
}
......
......@@ -22,6 +22,9 @@ import com.neotel.smfcore.core.system.listener.ITaskListener;
import com.neotel.smfcore.core.system.service.dao.IDataLogDao;
import com.neotel.smfcore.core.system.service.po.DataLog;
import com.neotel.smfcore.core.system.util.TaskService;
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.HellaTcpClient;
import com.neotel.smfcore.hella.tcp.command.HellaReqCommand;
import com.neotel.smfcore.hella.tcp.command.HellaRespCommand;
......@@ -79,25 +82,14 @@ public class HellaServiceHandler extends IoHandlerAdapter implements ITaskListen
private Map<String,HellaReqCommand> commandMap = new ConcurrentHashMap<>();
private Map<String,ResultBean> groupMsg = new ConcurrentHashMap<>();
public void updateGroupMsg(String group, ResultBean msgBean){
groupMsg.put(group,msgBean);
}
public ResultBean getGroupMsg(String group){
return groupMsg.get(group);
}
/**
* 检查物料条码
* <STX>checkMaterial;eventId;scannedCode<CR><LF>
* @return
*/
public ResultBean checkMaterial(String loginUser, String groupId, String groupName, String scannedCode){
public ResultBean checkMaterial(String loginUser, String groupId, String scannedCode){
HellaReqCommand command = HellaReqCommand.newCheckMaterialCmd(eventId.incrementAndGet(),scannedCode);
command.setGroupId(groupId);
command.setGroupName(groupName);
command.setLoginUser(loginUser);
for (HellaReqCommand hellaReqCommand : commandMap.values()) {
......@@ -166,10 +158,10 @@ public class HellaServiceHandler extends IoHandlerAdapter implements ITaskListen
if(respCommand.isOkResp()){
ResultBean okResult = ResultBean.newOkResult("smfcore.loadMaterialFinished","loading material is finished: {0}" ,new String[]{messageText});
groupMsg.put(groupId,okResult);
WebSocketServer.sendGroupMsg(groupId,new SocketMsg(okResult.getMsg(), MsgType.INFO));
}else{
ResultBean ngResult = ResultBean.newErrorResult(Integer.valueOf(returnCode),"smfcore.loadMaterialFailed","loading material failed:{0}",new String[]{messageText} );
groupMsg.put(groupId,ngResult);
WebSocketServer.sendGroupMsg(groupId,new SocketMsg(ngResult.getMsg(), MsgType.ERROR));
}
commandMap.remove(respCommand.getEventId());
}else if(respCommand.isUnloadMaterialCmd()){
......@@ -278,7 +270,6 @@ public class HellaServiceHandler extends IoHandlerAdapter implements ITaskListen
return;
}
String groupId = requestCommand.getGroupId();
String groupName = requestCommand.getGroupName();
String loginUser = requestCommand.getLoginUser();
String fullCode = requestCommand.getData().toString();
if(respCommand.isOkResp()){
......@@ -327,18 +318,21 @@ public class HellaServiceHandler extends IoHandlerAdapter implements ITaskListen
dataLog.setType(OP.PUT_IN);
dataLog.setNum(barcode.getAmount());
dataLog.setStatus(OP_STATUS.WAIT.name());
dataLog.setSourceId(groupId);
dataLog.setSourceName(groupName);
dataLog.setGroupId(groupId);
dataLog.setMemo(barcode.getMemo());
dataLog.setOperator(loginUser);
dataLog = dataLogDao.save(dataLog);
taskService.addTaskToExecute(dataLog);
ResultBean okResult = ResultBean.newOkResult("checking material is ok: " + messageText);
groupMsg.put(groupId,okResult);
try{
taskService.addTaskToExecute(dataLog);
ResultBean okResult = ResultBean.newOkResult("checking material is ok: " + messageText);
WebSocketServer.sendGroupMsg(groupId,new SocketMsg(okResult.getMsg(), MsgType.INFO));
}catch(Exception e){
WebSocketServer.sendGroupMsg(groupId,new SocketMsg(e.getMessage(), MsgType.INFO));
}
}else{
//NG,需要在界面上进行提示
ResultBean ngResult = ResultBean.newErrorResult(Integer.valueOf(returnCode),"smfcore.checkNg","checking material is ng:{0}" ,new String[]{messageText} );
groupMsg.put(groupId,ngResult);
WebSocketServer.sendGroupMsg(groupId,new SocketMsg(ngResult.getMsg(), MsgType.ERROR));
}
commandMap.remove(respCommand.getEventId());
}
......@@ -447,10 +441,9 @@ public class HellaServiceHandler extends IoHandlerAdapter implements ITaskListen
* <STX>loadMaterial;eventId;scannedCode;shelfNumber;shelfSlot<CR><LF>
* @return
*/
private void loadMaterial(String groupId,String goupName, String scannedCode,String shelfNumber, String shelfSlot){
private void loadMaterial(String groupId, String scannedCode,String shelfNumber, String shelfSlot){
HellaReqCommand command = HellaReqCommand.newLoadMaterialCmd(eventId.incrementAndGet(),scannedCode,shelfNumber,shelfSlot);
command.setGroupId(groupId);
command.setGroupName(goupName);
commandMap.put(command.getEventId(),command);
log.info("发送入库完成通知:" + command.toReqMsg());
HellaTcpClient.sendMsg(command.toReqMsg());
......@@ -460,14 +453,13 @@ public class HellaServiceHandler extends IoHandlerAdapter implements ITaskListen
public void onTaskStatusChange(DataLog task) {
if(task.isFinished()){
if(task.isPutInTask()){
String groupId = task.getSourceId();
String groupName = task.getSourceName();
String groupId = task.getGroupId();
String fullCode = task.getBarcode();
Barcode barcode = barcodeManager.findByBarcode(task.getBarcode());
if(barcode != null){
fullCode = barcode.getFullCode();
}
loadMaterial(groupId,groupName,fullCode,task.getStorageName(),task.getPosName());
loadMaterial(groupId,fullCode,task.getStorageName(),task.getPosName());
}
}
}
......
......@@ -75,19 +75,18 @@ public class HellaSensorShelfController {
if(ObjectUtils.isEmpty(groupId)){
throw new ValidateException("smfcode.valueCanotNull", "{0}不能为空", new String[]{"group"});
}
Group opGroup = groupManager.get(groupId);
String loginUser = SecurityUtils.getLoginUsername();
Collection<DataLog> queueTasks = taskService.getQueueTasks();
ResultBean resultBean = null;
for (DataLog queueTask : queueTasks) {
if (queueTask.isPutInTask() && queueTask.getSourceId().equals(groupId)) {
log.info("codeIn ["+code+"]["+opGroup.getGroupName()+"]入库失败:条码["+queueTask.getBarcode()+"]的任务还未结束 ");
if (queueTask.isPutInTask() && queueTask.isWait() && 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()});
// resultBean = ResultBean.newErrorResult(-1, "the task of [" + queueTask.getBarcode() + "] is unfinished.");
// return new ResponseEntity<ResultBean>(resultBean, HttpStatus.OK);
}
}
resultBean = hellaServiceHandler.checkMaterial(loginUser, opGroup.getId(),opGroup.getGroupName(), code);
resultBean = hellaServiceHandler.checkMaterial(loginUser, groupId, code);
return resultBean;
}
......
......@@ -11,11 +11,6 @@ public class HellaReqCommand extends HellaCommand {
private String groupId;
/**
* 组名称
*/
private String groupName;
/**
* 料仓Id;
*/
private String loginUser;
......@@ -70,12 +65,4 @@ public class HellaReqCommand extends HellaCommand {
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!