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 | 17 | import org.jeecg.common.base.BaseMap; |
18 | 18 | import org.jeecg.common.constant.WebsocketConst; |
19 | 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 | 22 | import org.springframework.stereotype.Component; |
21 | 23 | |
22 | 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 | 46 | import org.jeecg.modules.system.service.ISysTenantService; |
47 | 47 | import org.jeecg.modules.system.service.ISysUserService; |
48 | 48 | import org.jeecg.modules.system.util.RandImageUtil; |
49 | +import org.jeecg.modules.wms.framework.service.IHuahengMultiHandlerService; | |
49 | 50 | import org.jeecg.utils.HuahengJwtUtil; |
50 | 51 | import org.jeecg.utils.HuahengRedisUtil; |
51 | 52 | import org.jeecg.utils.StringUtils; |
52 | 53 | import org.jeecg.utils.config.ApplicationConfig; |
53 | 54 | import org.jeecg.utils.support.SystemRSA256Key; |
55 | +import org.jeecg.utils.support.SystemSync; | |
54 | 56 | import org.springframework.beans.BeanUtils; |
55 | 57 | import org.springframework.beans.factory.annotation.Autowired; |
56 | 58 | import org.springframework.beans.factory.annotation.Value; |
... | ... | @@ -94,7 +96,6 @@ import lombok.extern.slf4j.Slf4j; |
94 | 96 | @RequestMapping("/sys") |
95 | 97 | @Api(tags = "用户登录") |
96 | 98 | @Slf4j |
97 | -@EnableAsync | |
98 | 99 | public class LoginController { |
99 | 100 | |
100 | 101 | /** Token失效时间 */ |
... | ... | @@ -114,9 +115,6 @@ public class LoginController { |
114 | 115 | @Autowired |
115 | 116 | private ISysLogService logService; |
116 | 117 | |
117 | - @Resource | |
118 | - private WebSocket webSocket; | |
119 | - | |
120 | 118 | @Autowired |
121 | 119 | private RedisUtil redisUtil; |
122 | 120 | |
... | ... | @@ -138,6 +136,9 @@ public class LoginController { |
138 | 136 | @Autowired |
139 | 137 | private ApplicationConfig applicationConfig; |
140 | 138 | |
139 | + @Resource | |
140 | + SystemSync systemSync; | |
141 | + | |
141 | 142 | @ApiOperation("登录接口") |
142 | 143 | @RequestMapping(value = "/login", method = RequestMethod.POST) |
143 | 144 | public Result<JSONObject> login(@RequestBody SysLoginModel sysLoginModel) throws IOException { |
... | ... | @@ -203,25 +204,10 @@ public class LoginController { |
203 | 204 | baseCommonService.addLog("用户名:" + username + ",登录成功!", CommonConstant.LOG_TYPE_1, null, loginUser); |
204 | 205 | // update-end--Author:wangshuai Date:20200714 for:登录日志没有记录人员 |
205 | 206 | |
206 | - sendMaterialAlarm(sysUser); | |
207 | + systemSync.sendMaterialAlarm(sysUser); | |
207 | 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 | 211 | @ApiOperation("系统激活API") |
226 | 212 | @RequestMapping(value = "/systemActivation", method = RequestMethod.POST) |
227 | 213 | public Result<JSONObject> systemAuthentication(@RequestBody SystemActivationModel systemActivationModel) throws IOException { |
... | ... | @@ -235,7 +221,7 @@ public class LoginController { |
235 | 221 | Algorithm algorithm = Algorithm.RSA256(new SystemRSA256Key().getPublicKey(), new SystemRSA256Key().getPrivateKey()); |
236 | 222 | JWTVerifier verifier = |
237 | 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 | 226 | File file = new File(System.getProperties().getProperty("user.dir") + File.separatorChar + HuahengJwtUtil.SYSTEM_ACTIVATION_CODE_FILE_NAME); |
241 | 227 | outputStream = new FileOutputStream(file, false); |
... | ... | @@ -292,7 +278,7 @@ public class LoginController { |
292 | 278 | Algorithm algorithm = Algorithm.RSA256(new SystemRSA256Key().getPublicKey(), new SystemRSA256Key().getPrivateKey()); |
293 | 279 | JWTVerifier verifier = |
294 | 280 | JWT.require(algorithm).withClaim("operator", applicationConfig.getArtifactId()).withIssuer(applicationConfig.getArtifactId()).build(); |
295 | - DecodedJWT jwt = verifier.verify(activationCode); | |
281 | + verifier.verify(activationCode); | |
296 | 282 | // 如果redis中不存在激活码或与激活码不一致 则写入redis |
297 | 283 | if (StringUtils.isEmpty(redisActivationCode) || !redisActivationCode.equals(activationCode)) { |
298 | 284 | huahengRedisUtil.setWithNoExpirationTime(HuahengJwtUtil.SYSTEM_ACTIVATION_CODE_KEY, activationCode); |
... | ... | @@ -890,8 +876,8 @@ public class LoginController { |
890 | 876 | String warehouseCode = params.get("warehouseCode"); |
891 | 877 | LoginUser loginUser = (LoginUser)SecurityUtils.getSubject().getPrincipal(); |
892 | 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 | 881 | LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>(); |
896 | 882 | queryWrapper.eq(SysUser::getUsername, username); |
897 | 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 | 8 | import org.jeecg.common.api.vo.Result; |
9 | 9 | import org.jeecg.common.constant.CacheConstant; |
10 | 10 | import org.jeecg.common.constant.CommonConstant; |
11 | +import org.jeecg.common.constant.WebsocketConst; | |
11 | 12 | import org.jeecg.common.exception.JeecgBootException; |
12 | 13 | import org.jeecg.common.system.api.ISysBaseAPI; |
13 | 14 | import org.jeecg.common.system.vo.LoginUser; |
... | ... | @@ -15,6 +16,7 @@ import org.jeecg.common.system.vo.SysUserCacheInfo; |
15 | 16 | import org.jeecg.common.util.PasswordUtil; |
16 | 17 | import org.jeecg.common.util.oConvertUtils; |
17 | 18 | import org.jeecg.modules.base.service.BaseCommonService; |
19 | +import org.jeecg.modules.message.websocket.WebSocket; | |
18 | 20 | import org.jeecg.modules.system.entity.*; |
19 | 21 | import org.jeecg.modules.system.mapper.*; |
20 | 22 | import org.jeecg.modules.system.model.SysUserSysDepartModel; |
... | ... | @@ -29,6 +31,7 @@ import org.jeecg.utils.StringUtils; |
29 | 31 | import org.jeecg.utils.constant.QuantityConstant; |
30 | 32 | import org.springframework.beans.factory.annotation.Autowired; |
31 | 33 | import org.springframework.cache.annotation.CacheEvict; |
34 | +import org.springframework.scheduling.annotation.Async; | |
32 | 35 | import org.springframework.stereotype.Service; |
33 | 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 | 3 | import java.util.List; |
4 | 4 | |
5 | 5 | import org.jeecg.common.api.vo.Result; |
6 | +import org.jeecg.modules.system.entity.SysUser; | |
6 | 7 | import org.jeecg.modules.wms.api.mobile.entity.CallBoxBean; |
7 | 8 | import org.jeecg.modules.wms.api.mobile.entity.QuickReceiptBean; |
8 | 9 | import org.jeecg.modules.wms.receipt.receiptContainerHeader.entity.ReceiptContainerHeader; |
... | ... | @@ -51,5 +52,5 @@ public interface IHuahengMultiHandlerService { |
51 | 52 | Result sendTaskToWcs(TaskHeader taskHeader, String zoneCode); |
52 | 53 | |
53 | 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 | import javax.annotation.Resource; |
7 | 7 | |
8 | 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 | 12 | import org.jeecg.modules.wms.api.erp.service.IErpService; |
10 | 13 | import org.jeecg.modules.wms.api.mobile.entity.CallBoxBean; |
11 | 14 | import org.jeecg.modules.wms.api.mobile.entity.QuickReceiptBean; |
... | ... | @@ -31,6 +34,8 @@ import org.jeecg.modules.wms.task.taskHeader.service.ITaskHeaderService; |
31 | 34 | import org.springframework.scheduling.annotation.Async; |
32 | 35 | import org.springframework.stereotype.Service; |
33 | 36 | |
37 | +import com.alibaba.fastjson.JSONObject; | |
38 | + | |
34 | 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 | 4 | import java.util.List; |
5 | 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 | 12 | import org.jeecg.modules.wms.inventory.inventoryTransaction.entity.InventoryTransaction; |
8 | 13 | import org.jeecg.modules.wms.inventory.inventoryTransaction.service.IInventoryTransactionService; |
9 | 14 | import org.jeecg.modules.wms.monitor.apiLog.entity.ApiLog; |
... | ... | @@ -14,6 +19,7 @@ import org.springframework.scheduling.annotation.AsyncResult; |
14 | 19 | import org.springframework.stereotype.Component; |
15 | 20 | |
16 | 21 | import com.alibaba.fastjson.JSON; |
22 | +import com.alibaba.fastjson.JSONObject; | |
17 | 23 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
18 | 24 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
19 | 25 | |
... | ... | @@ -28,6 +34,22 @@ public class SystemSync { |
28 | 34 | |
29 | 35 | @Autowired |
30 | 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 | 55 | * 保存API调用日志 |
... | ... |