Commit ff17e76451818ba11c7e225d459c256e65fe8b84
1 parent
adb09be0
登录异步消息通知修改
Signed-off-by: TanYibin <5491541@qq.com>
Showing
6 changed files
with
44 additions
and
25 deletions
huaheng-wms-core/src/main/java/org/jeecg/modules/message/websocket/WebSocket.java
@@ -17,6 +17,8 @@ import javax.websocket.server.ServerEndpoint; | @@ -17,6 +17,8 @@ import javax.websocket.server.ServerEndpoint; | ||
17 | import org.jeecg.common.base.BaseMap; | 17 | import org.jeecg.common.base.BaseMap; |
18 | import org.jeecg.common.constant.WebsocketConst; | 18 | import org.jeecg.common.constant.WebsocketConst; |
19 | import org.jeecg.common.modules.redis.client.JeecgRedisClient; | 19 | import org.jeecg.common.modules.redis.client.JeecgRedisClient; |
20 | +import org.jeecg.modules.system.entity.SysUser; | ||
21 | +import org.springframework.scheduling.annotation.Async; | ||
20 | import org.springframework.stereotype.Component; | 22 | import org.springframework.stereotype.Component; |
21 | 23 | ||
22 | import com.alibaba.fastjson.JSONObject; | 24 | import com.alibaba.fastjson.JSONObject; |
huaheng-wms-core/src/main/java/org/jeecg/modules/system/controller/LoginController.java
@@ -46,11 +46,13 @@ import org.jeecg.modules.system.service.ISysLogService; | @@ -46,11 +46,13 @@ import org.jeecg.modules.system.service.ISysLogService; | ||
46 | import org.jeecg.modules.system.service.ISysTenantService; | 46 | import org.jeecg.modules.system.service.ISysTenantService; |
47 | import org.jeecg.modules.system.service.ISysUserService; | 47 | import org.jeecg.modules.system.service.ISysUserService; |
48 | import org.jeecg.modules.system.util.RandImageUtil; | 48 | import org.jeecg.modules.system.util.RandImageUtil; |
49 | +import org.jeecg.modules.wms.framework.service.IHuahengMultiHandlerService; | ||
49 | import org.jeecg.utils.HuahengJwtUtil; | 50 | import org.jeecg.utils.HuahengJwtUtil; |
50 | import org.jeecg.utils.HuahengRedisUtil; | 51 | import org.jeecg.utils.HuahengRedisUtil; |
51 | import org.jeecg.utils.StringUtils; | 52 | import org.jeecg.utils.StringUtils; |
52 | import org.jeecg.utils.config.ApplicationConfig; | 53 | import org.jeecg.utils.config.ApplicationConfig; |
53 | import org.jeecg.utils.support.SystemRSA256Key; | 54 | import org.jeecg.utils.support.SystemRSA256Key; |
55 | +import org.jeecg.utils.support.SystemSync; | ||
54 | import org.springframework.beans.BeanUtils; | 56 | import org.springframework.beans.BeanUtils; |
55 | import org.springframework.beans.factory.annotation.Autowired; | 57 | import org.springframework.beans.factory.annotation.Autowired; |
56 | import org.springframework.beans.factory.annotation.Value; | 58 | import org.springframework.beans.factory.annotation.Value; |
@@ -94,7 +96,6 @@ import lombok.extern.slf4j.Slf4j; | @@ -94,7 +96,6 @@ import lombok.extern.slf4j.Slf4j; | ||
94 | @RequestMapping("/sys") | 96 | @RequestMapping("/sys") |
95 | @Api(tags = "用户登录") | 97 | @Api(tags = "用户登录") |
96 | @Slf4j | 98 | @Slf4j |
97 | -@EnableAsync | ||
98 | public class LoginController { | 99 | public class LoginController { |
99 | 100 | ||
100 | /** Token失效时间 */ | 101 | /** Token失效时间 */ |
@@ -114,9 +115,6 @@ public class LoginController { | @@ -114,9 +115,6 @@ public class LoginController { | ||
114 | @Autowired | 115 | @Autowired |
115 | private ISysLogService logService; | 116 | private ISysLogService logService; |
116 | 117 | ||
117 | - @Resource | ||
118 | - private WebSocket webSocket; | ||
119 | - | ||
120 | @Autowired | 118 | @Autowired |
121 | private RedisUtil redisUtil; | 119 | private RedisUtil redisUtil; |
122 | 120 | ||
@@ -138,6 +136,9 @@ public class LoginController { | @@ -138,6 +136,9 @@ public class LoginController { | ||
138 | @Autowired | 136 | @Autowired |
139 | private ApplicationConfig applicationConfig; | 137 | private ApplicationConfig applicationConfig; |
140 | 138 | ||
139 | + @Resource | ||
140 | + SystemSync systemSync; | ||
141 | + | ||
141 | @ApiOperation("登录接口") | 142 | @ApiOperation("登录接口") |
142 | @RequestMapping(value = "/login", method = RequestMethod.POST) | 143 | @RequestMapping(value = "/login", method = RequestMethod.POST) |
143 | public Result<JSONObject> login(@RequestBody SysLoginModel sysLoginModel) throws IOException { | 144 | public Result<JSONObject> login(@RequestBody SysLoginModel sysLoginModel) throws IOException { |
@@ -203,25 +204,10 @@ public class LoginController { | @@ -203,25 +204,10 @@ public class LoginController { | ||
203 | baseCommonService.addLog("用户名:" + username + ",登录成功!", CommonConstant.LOG_TYPE_1, null, loginUser); | 204 | baseCommonService.addLog("用户名:" + username + ",登录成功!", CommonConstant.LOG_TYPE_1, null, loginUser); |
204 | // update-end--Author:wangshuai Date:20200714 for:登录日志没有记录人员 | 205 | // update-end--Author:wangshuai Date:20200714 for:登录日志没有记录人员 |
205 | 206 | ||
206 | - sendMaterialAlarm(sysUser); | 207 | + systemSync.sendMaterialAlarm(sysUser); |
207 | return result; | 208 | return result; |
208 | } | 209 | } |
209 | 210 | ||
210 | - @Async("asyncPoolTaskExecutor") | ||
211 | - public void sendMaterialAlarm(SysUser sysUser) { | ||
212 | - try { | ||
213 | - Thread.sleep(20000); | ||
214 | - JSONObject obj = new JSONObject(); | ||
215 | - obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_TOPIC); | ||
216 | - obj.put(WebsocketConst.MSG_ID, "111"); | ||
217 | - obj.put(WebsocketConst.MSG_TXT, "登录通知测试"); | ||
218 | -// webSocket.sendMessage(String.valueOf(sysUser.getId()), obj.toJSONString()); | ||
219 | - webSocket.sendMessage(obj.toJSONString()); | ||
220 | - }catch (Exception e){ | ||
221 | - | ||
222 | - } | ||
223 | - } | ||
224 | - | ||
225 | @ApiOperation("系统激活API") | 211 | @ApiOperation("系统激活API") |
226 | @RequestMapping(value = "/systemActivation", method = RequestMethod.POST) | 212 | @RequestMapping(value = "/systemActivation", method = RequestMethod.POST) |
227 | public Result<JSONObject> systemAuthentication(@RequestBody SystemActivationModel systemActivationModel) throws IOException { | 213 | public Result<JSONObject> systemAuthentication(@RequestBody SystemActivationModel systemActivationModel) throws IOException { |
@@ -235,7 +221,7 @@ public class LoginController { | @@ -235,7 +221,7 @@ public class LoginController { | ||
235 | Algorithm algorithm = Algorithm.RSA256(new SystemRSA256Key().getPublicKey(), new SystemRSA256Key().getPrivateKey()); | 221 | Algorithm algorithm = Algorithm.RSA256(new SystemRSA256Key().getPublicKey(), new SystemRSA256Key().getPrivateKey()); |
236 | JWTVerifier verifier = | 222 | JWTVerifier verifier = |
237 | JWT.require(algorithm).withClaim("operator", applicationConfig.getArtifactId()).withIssuer(applicationConfig.getArtifactId()).build(); | 223 | JWT.require(algorithm).withClaim("operator", applicationConfig.getArtifactId()).withIssuer(applicationConfig.getArtifactId()).build(); |
238 | - DecodedJWT jwt = verifier.verify(systemActivationModel.getActivationCode()); | 224 | + verifier.verify(systemActivationModel.getActivationCode()); |
239 | // 验证通过写入文件 | 225 | // 验证通过写入文件 |
240 | File file = new File(System.getProperties().getProperty("user.dir") + File.separatorChar + HuahengJwtUtil.SYSTEM_ACTIVATION_CODE_FILE_NAME); | 226 | File file = new File(System.getProperties().getProperty("user.dir") + File.separatorChar + HuahengJwtUtil.SYSTEM_ACTIVATION_CODE_FILE_NAME); |
241 | outputStream = new FileOutputStream(file, false); | 227 | outputStream = new FileOutputStream(file, false); |
@@ -292,7 +278,7 @@ public class LoginController { | @@ -292,7 +278,7 @@ public class LoginController { | ||
292 | Algorithm algorithm = Algorithm.RSA256(new SystemRSA256Key().getPublicKey(), new SystemRSA256Key().getPrivateKey()); | 278 | Algorithm algorithm = Algorithm.RSA256(new SystemRSA256Key().getPublicKey(), new SystemRSA256Key().getPrivateKey()); |
293 | JWTVerifier verifier = | 279 | JWTVerifier verifier = |
294 | JWT.require(algorithm).withClaim("operator", applicationConfig.getArtifactId()).withIssuer(applicationConfig.getArtifactId()).build(); | 280 | JWT.require(algorithm).withClaim("operator", applicationConfig.getArtifactId()).withIssuer(applicationConfig.getArtifactId()).build(); |
295 | - DecodedJWT jwt = verifier.verify(activationCode); | 281 | + verifier.verify(activationCode); |
296 | // 如果redis中不存在激活码或与激活码不一致 则写入redis | 282 | // 如果redis中不存在激活码或与激活码不一致 则写入redis |
297 | if (StringUtils.isEmpty(redisActivationCode) || !redisActivationCode.equals(activationCode)) { | 283 | if (StringUtils.isEmpty(redisActivationCode) || !redisActivationCode.equals(activationCode)) { |
298 | huahengRedisUtil.setWithNoExpirationTime(HuahengJwtUtil.SYSTEM_ACTIVATION_CODE_KEY, activationCode); | 284 | huahengRedisUtil.setWithNoExpirationTime(HuahengJwtUtil.SYSTEM_ACTIVATION_CODE_KEY, activationCode); |
@@ -890,8 +876,8 @@ public class LoginController { | @@ -890,8 +876,8 @@ public class LoginController { | ||
890 | String warehouseCode = params.get("warehouseCode"); | 876 | String warehouseCode = params.get("warehouseCode"); |
891 | LoginUser loginUser = (LoginUser)SecurityUtils.getSubject().getPrincipal(); | 877 | LoginUser loginUser = (LoginUser)SecurityUtils.getSubject().getPrincipal(); |
892 | String username = loginUser.getUsername(); | 878 | String username = loginUser.getUsername(); |
893 | - String syspassword = loginUser.getPassword(); | ||
894 | - String orgCode = loginUser.getOrgCode(); | 879 | +// String syspassword = loginUser.getPassword(); |
880 | +// String orgCode = loginUser.getOrgCode(); | ||
895 | LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>(); | 881 | LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>(); |
896 | queryWrapper.eq(SysUser::getUsername, username); | 882 | queryWrapper.eq(SysUser::getUsername, username); |
897 | SysUser sysUser = sysUserService.getOne(queryWrapper); | 883 | SysUser sysUser = sysUserService.getOne(queryWrapper); |
huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java
@@ -8,6 +8,7 @@ import javax.annotation.Resource; | @@ -8,6 +8,7 @@ import javax.annotation.Resource; | ||
8 | import org.jeecg.common.api.vo.Result; | 8 | import org.jeecg.common.api.vo.Result; |
9 | import org.jeecg.common.constant.CacheConstant; | 9 | import org.jeecg.common.constant.CacheConstant; |
10 | import org.jeecg.common.constant.CommonConstant; | 10 | import org.jeecg.common.constant.CommonConstant; |
11 | +import org.jeecg.common.constant.WebsocketConst; | ||
11 | import org.jeecg.common.exception.JeecgBootException; | 12 | import org.jeecg.common.exception.JeecgBootException; |
12 | import org.jeecg.common.system.api.ISysBaseAPI; | 13 | import org.jeecg.common.system.api.ISysBaseAPI; |
13 | import org.jeecg.common.system.vo.LoginUser; | 14 | import org.jeecg.common.system.vo.LoginUser; |
@@ -15,6 +16,7 @@ import org.jeecg.common.system.vo.SysUserCacheInfo; | @@ -15,6 +16,7 @@ import org.jeecg.common.system.vo.SysUserCacheInfo; | ||
15 | import org.jeecg.common.util.PasswordUtil; | 16 | import org.jeecg.common.util.PasswordUtil; |
16 | import org.jeecg.common.util.oConvertUtils; | 17 | import org.jeecg.common.util.oConvertUtils; |
17 | import org.jeecg.modules.base.service.BaseCommonService; | 18 | import org.jeecg.modules.base.service.BaseCommonService; |
19 | +import org.jeecg.modules.message.websocket.WebSocket; | ||
18 | import org.jeecg.modules.system.entity.*; | 20 | import org.jeecg.modules.system.entity.*; |
19 | import org.jeecg.modules.system.mapper.*; | 21 | import org.jeecg.modules.system.mapper.*; |
20 | import org.jeecg.modules.system.model.SysUserSysDepartModel; | 22 | import org.jeecg.modules.system.model.SysUserSysDepartModel; |
@@ -29,6 +31,7 @@ import org.jeecg.utils.StringUtils; | @@ -29,6 +31,7 @@ import org.jeecg.utils.StringUtils; | ||
29 | import org.jeecg.utils.constant.QuantityConstant; | 31 | import org.jeecg.utils.constant.QuantityConstant; |
30 | import org.springframework.beans.factory.annotation.Autowired; | 32 | import org.springframework.beans.factory.annotation.Autowired; |
31 | import org.springframework.cache.annotation.CacheEvict; | 33 | import org.springframework.cache.annotation.CacheEvict; |
34 | +import org.springframework.scheduling.annotation.Async; | ||
32 | import org.springframework.stereotype.Service; | 35 | import org.springframework.stereotype.Service; |
33 | import org.springframework.transaction.annotation.Transactional; | 36 | import org.springframework.transaction.annotation.Transactional; |
34 | 37 |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/service/IHuahengMultiHandlerService.java
@@ -3,6 +3,7 @@ package org.jeecg.modules.wms.framework.service; | @@ -3,6 +3,7 @@ package org.jeecg.modules.wms.framework.service; | ||
3 | import java.util.List; | 3 | import java.util.List; |
4 | 4 | ||
5 | import org.jeecg.common.api.vo.Result; | 5 | import org.jeecg.common.api.vo.Result; |
6 | +import org.jeecg.modules.system.entity.SysUser; | ||
6 | import org.jeecg.modules.wms.api.mobile.entity.CallBoxBean; | 7 | import org.jeecg.modules.wms.api.mobile.entity.CallBoxBean; |
7 | import org.jeecg.modules.wms.api.mobile.entity.QuickReceiptBean; | 8 | import org.jeecg.modules.wms.api.mobile.entity.QuickReceiptBean; |
8 | import org.jeecg.modules.wms.receipt.receiptContainerHeader.entity.ReceiptContainerHeader; | 9 | import org.jeecg.modules.wms.receipt.receiptContainerHeader.entity.ReceiptContainerHeader; |
@@ -51,5 +52,5 @@ public interface IHuahengMultiHandlerService { | @@ -51,5 +52,5 @@ public interface IHuahengMultiHandlerService { | ||
51 | Result sendTaskToWcs(TaskHeader taskHeader, String zoneCode); | 52 | Result sendTaskToWcs(TaskHeader taskHeader, String zoneCode); |
52 | 53 | ||
53 | void sendTaskToWcs(List<TaskHeader> taskHeaders, String warehouseCode, String zoneCode); | 54 | void sendTaskToWcs(List<TaskHeader> taskHeaders, String warehouseCode, String zoneCode); |
54 | - | 55 | + |
55 | } | 56 | } |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/service/impl/HuahengMultiHandlerServiceImpl.java
@@ -6,6 +6,9 @@ import java.util.List; | @@ -6,6 +6,9 @@ import java.util.List; | ||
6 | import javax.annotation.Resource; | 6 | import javax.annotation.Resource; |
7 | 7 | ||
8 | import org.jeecg.common.api.vo.Result; | 8 | import org.jeecg.common.api.vo.Result; |
9 | +import org.jeecg.common.constant.WebsocketConst; | ||
10 | +import org.jeecg.modules.message.websocket.WebSocket; | ||
11 | +import org.jeecg.modules.system.entity.SysUser; | ||
9 | import org.jeecg.modules.wms.api.erp.service.IErpService; | 12 | import org.jeecg.modules.wms.api.erp.service.IErpService; |
10 | import org.jeecg.modules.wms.api.mobile.entity.CallBoxBean; | 13 | import org.jeecg.modules.wms.api.mobile.entity.CallBoxBean; |
11 | import org.jeecg.modules.wms.api.mobile.entity.QuickReceiptBean; | 14 | import org.jeecg.modules.wms.api.mobile.entity.QuickReceiptBean; |
@@ -31,6 +34,8 @@ import org.jeecg.modules.wms.task.taskHeader.service.ITaskHeaderService; | @@ -31,6 +34,8 @@ import org.jeecg.modules.wms.task.taskHeader.service.ITaskHeaderService; | ||
31 | import org.springframework.scheduling.annotation.Async; | 34 | import org.springframework.scheduling.annotation.Async; |
32 | import org.springframework.stereotype.Service; | 35 | import org.springframework.stereotype.Service; |
33 | 36 | ||
37 | +import com.alibaba.fastjson.JSONObject; | ||
38 | + | ||
34 | import lombok.extern.slf4j.Slf4j; | 39 | import lombok.extern.slf4j.Slf4j; |
35 | 40 | ||
36 | /** | 41 | /** |
huaheng-wms-core/src/main/java/org/jeecg/utils/support/SystemSync.java
@@ -4,6 +4,11 @@ import java.math.BigDecimal; | @@ -4,6 +4,11 @@ import java.math.BigDecimal; | ||
4 | import java.util.List; | 4 | import java.util.List; |
5 | import java.util.concurrent.Future; | 5 | import java.util.concurrent.Future; |
6 | 6 | ||
7 | +import javax.annotation.Resource; | ||
8 | + | ||
9 | +import org.jeecg.common.constant.WebsocketConst; | ||
10 | +import org.jeecg.modules.message.websocket.WebSocket; | ||
11 | +import org.jeecg.modules.system.entity.SysUser; | ||
7 | import org.jeecg.modules.wms.inventory.inventoryTransaction.entity.InventoryTransaction; | 12 | import org.jeecg.modules.wms.inventory.inventoryTransaction.entity.InventoryTransaction; |
8 | import org.jeecg.modules.wms.inventory.inventoryTransaction.service.IInventoryTransactionService; | 13 | import org.jeecg.modules.wms.inventory.inventoryTransaction.service.IInventoryTransactionService; |
9 | import org.jeecg.modules.wms.monitor.apiLog.entity.ApiLog; | 14 | import org.jeecg.modules.wms.monitor.apiLog.entity.ApiLog; |
@@ -14,6 +19,7 @@ import org.springframework.scheduling.annotation.AsyncResult; | @@ -14,6 +19,7 @@ import org.springframework.scheduling.annotation.AsyncResult; | ||
14 | import org.springframework.stereotype.Component; | 19 | import org.springframework.stereotype.Component; |
15 | 20 | ||
16 | import com.alibaba.fastjson.JSON; | 21 | import com.alibaba.fastjson.JSON; |
22 | +import com.alibaba.fastjson.JSONObject; | ||
17 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 23 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
18 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; | 24 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
19 | 25 | ||
@@ -28,6 +34,22 @@ public class SystemSync { | @@ -28,6 +34,22 @@ public class SystemSync { | ||
28 | 34 | ||
29 | @Autowired | 35 | @Autowired |
30 | private IInventoryTransactionService inventoryTransactionService; | 36 | private IInventoryTransactionService inventoryTransactionService; |
37 | + | ||
38 | + @Autowired | ||
39 | + private WebSocket webSocket; | ||
40 | + | ||
41 | + @Async("asyncPoolTaskExecutor") | ||
42 | + public void sendMaterialAlarm(SysUser sysUser) { | ||
43 | + try { | ||
44 | + Thread.sleep(20000); | ||
45 | + JSONObject obj = new JSONObject(); | ||
46 | + obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_TOPIC); | ||
47 | + obj.put(WebsocketConst.MSG_ID, "111"); | ||
48 | + obj.put(WebsocketConst.MSG_TXT, "登录通知测试"); | ||
49 | + webSocket.sendMessage(obj.toJSONString()); | ||
50 | + } catch (Exception e) { | ||
51 | + } | ||
52 | + } | ||
31 | 53 | ||
32 | /** | 54 | /** |
33 | * 保存API调用日志 | 55 | * 保存API调用日志 |