Commit 4138aa95ca0e3cbb5eb9f47b583fcb230932b102
Merge branch 'develop4' of http://172.16.29.40:8010/wms/wms4 into develop4
Showing
32 changed files
with
552 additions
and
422 deletions
ant-design-vue-jeecg/src/components/layouts/UserLayout.vue
huaheng-wms-core/src/main/java/org/jeecg/JeecgSystemApplication.java
@@ -18,6 +18,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; | @@ -18,6 +18,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
18 | import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; | 18 | import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; |
19 | import org.springframework.boot.builder.SpringApplicationBuilder; | 19 | import org.springframework.boot.builder.SpringApplicationBuilder; |
20 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; | 20 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; |
21 | +import org.springframework.cache.annotation.EnableCaching; | ||
21 | import org.springframework.context.ConfigurableApplicationContext; | 22 | import org.springframework.context.ConfigurableApplicationContext; |
22 | import org.springframework.core.env.Environment; | 23 | import org.springframework.core.env.Environment; |
23 | 24 | ||
@@ -28,6 +29,7 @@ import net.bytebuddy.asm.Advice.This; | @@ -28,6 +29,7 @@ import net.bytebuddy.asm.Advice.This; | ||
28 | * 单体启动类(采用此类启动为单体模式) | 29 | * 单体启动类(采用此类启动为单体模式) |
29 | */ | 30 | */ |
30 | @Slf4j | 31 | @Slf4j |
32 | +@EnableCaching | ||
31 | @SpringBootApplication | 33 | @SpringBootApplication |
32 | @EnableAutoConfiguration(exclude = {MongoAutoConfiguration.class}) | 34 | @EnableAutoConfiguration(exclude = {MongoAutoConfiguration.class}) |
33 | public class JeecgSystemApplication extends SpringBootServletInitializer { | 35 | public class JeecgSystemApplication extends SpringBootServletInitializer { |
huaheng-wms-core/src/main/java/org/jeecg/modules/system/controller/LoginController.java
@@ -429,29 +429,28 @@ public class LoginController { | @@ -429,29 +429,28 @@ public class LoginController { | ||
429 | } | 429 | } |
430 | } | 430 | } |
431 | 431 | ||
432 | + // 暂时移除唯一登录功能 | ||
432 | // 删除相同用户名称对应的key | 433 | // 删除相同用户名称对应的key |
433 | - Collection<String> keys = redisTemplate.keys(CommonConstant.PREFIX_USER_TOKEN + "*"); | ||
434 | - for (String key : keys) { | ||
435 | - String token = (String)redisUtil.get(key); | ||
436 | - LoginUser loginUser = sysBaseAPI.getUserByName(JwtUtil.getUsername(token)); | ||
437 | - if (loginUser != null) { | ||
438 | - if (oConvertUtils.isNotEmpty(username) && loginUser.getUsername().contains(username)) { | ||
439 | - log.info("强制 " + sysUser.getRealname() + " 退出成功! "); | ||
440 | - // 清空用户登录Token缓存 | ||
441 | - redisUtil.del(token); | ||
442 | - // 清空用户登录Token缓存 | ||
443 | - redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + token); | ||
444 | - // 清空用户登录Shiro权限缓存 | ||
445 | - redisUtil.del(CommonConstant.PREFIX_USER_SHIRO_CACHE + sysUser.getId()); | ||
446 | - // 清空用户的缓存信息(包括部门信息),例如sys:cache:user::<username> | ||
447 | - redisUtil.del(String.format("%s::%s", CacheConstant.SYS_USERS_CACHE, sysUser.getUsername())); | ||
448 | - // 调用shiro的logout | ||
449 | - SecurityUtils.getSubject().logout(); | ||
450 | - // | ||
451 | - redisUtil.del(key); | ||
452 | - } | ||
453 | - } | ||
454 | - } | 434 | +// Collection<String> keys = redisTemplate.keys(CommonConstant.PREFIX_USER_TOKEN + "*"); |
435 | +// for (String key : keys) { | ||
436 | +// String token = (String)redisUtil.get(key); | ||
437 | +// LoginUser loginUser = sysBaseAPI.getUserByName(JwtUtil.getUsername(token)); | ||
438 | +// if (loginUser != null) { | ||
439 | +// if (oConvertUtils.isNotEmpty(username) && loginUser.getUsername().contains(username)) { | ||
440 | +// log.info("强制 " + sysUser.getRealname() + " 退出成功! "); | ||
441 | +// // 清空用户登录Token缓存 | ||
442 | +// redisUtil.del(token); | ||
443 | +// // 清空用户登录Token缓存 | ||
444 | +// redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + token); | ||
445 | +// // 清空用户登录Shiro权限缓存 | ||
446 | +// redisUtil.del(CommonConstant.PREFIX_USER_SHIRO_CACHE + sysUser.getId()); | ||
447 | +// // 清空用户的缓存信息(包括部门信息),例如sys:cache:user::<username> | ||
448 | +// redisUtil.del(String.format("%s::%s", CacheConstant.SYS_USERS_CACHE, sysUser.getUsername())); | ||
449 | +// // 调用shiro的logout | ||
450 | +// SecurityUtils.getSubject().logout(); | ||
451 | +// } | ||
452 | +// } | ||
453 | +// } | ||
455 | // update-end--Author:sunjianlei Date:20210802 for:获取用户租户信息 | 454 | // update-end--Author:sunjianlei Date:20210802 for:获取用户租户信息 |
456 | // 生成token | 455 | // 生成token |
457 | String token = HuahengJwtUtil.sign(username, syspassword, warehouseCode); | 456 | String token = HuahengJwtUtil.sign(username, syspassword, warehouseCode); |
huaheng-wms-core/src/main/java/org/jeecg/modules/system/controller/SysUserOnlineController.java
@@ -136,8 +136,6 @@ public class SysUserOnlineController { | @@ -136,8 +136,6 @@ public class SysUserOnlineController { | ||
136 | redisUtil.del(CommonConstant.PREFIX_USER_SHIRO_CACHE + sysUser.getId()); | 136 | redisUtil.del(CommonConstant.PREFIX_USER_SHIRO_CACHE + sysUser.getId()); |
137 | // 清空用户的缓存信息 | 137 | // 清空用户的缓存信息 |
138 | redisUtil.del(String.format("%s::%s", CacheConstant.SYS_USERS_CACHE, sysUser.getUsername())); | 138 | redisUtil.del(String.format("%s::%s", CacheConstant.SYS_USERS_CACHE, sysUser.getUsername())); |
139 | - // 真*清空Token | ||
140 | - redisUtil.del(key); | ||
141 | // 调用shiro的logout | 139 | // 调用shiro的logout |
142 | SecurityUtils.getSubject().logout(); | 140 | SecurityUtils.getSubject().logout(); |
143 | return Result.ok("退出登录成功!"); | 141 | return Result.ok("退出登录成功!"); |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/acs/controller/AcsController.java
@@ -6,13 +6,13 @@ import javax.annotation.Resource; | @@ -6,13 +6,13 @@ import javax.annotation.Resource; | ||
6 | import javax.servlet.http.HttpServletRequest; | 6 | import javax.servlet.http.HttpServletRequest; |
7 | 7 | ||
8 | import org.jeecg.common.api.vo.Result; | 8 | import org.jeecg.common.api.vo.Result; |
9 | -import org.jeecg.common.system.util.JwtUtil; | ||
10 | import org.jeecg.modules.wms.api.acs.entity.AcsStatus; | 9 | import org.jeecg.modules.wms.api.acs.entity.AcsStatus; |
11 | import org.jeecg.modules.wms.api.acs.service.IAcsService; | 10 | import org.jeecg.modules.wms.api.acs.service.IAcsService; |
12 | -import org.jeecg.modules.wms.framework.aspectj.PassApiAuthentication; | 11 | +import org.jeecg.modules.wms.config.address.service.IAddressService; |
13 | import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; | 12 | import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; |
14 | import org.jeecg.modules.wms.framework.controller.HuahengBaseController; | 13 | import org.jeecg.modules.wms.framework.controller.HuahengBaseController; |
15 | import org.jeecg.modules.wms.task.agvTask.service.IAgvTaskService; | 14 | import org.jeecg.modules.wms.task.agvTask.service.IAgvTaskService; |
15 | +import org.jeecg.utils.OkHttpUtils; | ||
16 | import org.jeecg.utils.StringUtils; | 16 | import org.jeecg.utils.StringUtils; |
17 | import org.jeecg.utils.constant.QuantityConstant; | 17 | import org.jeecg.utils.constant.QuantityConstant; |
18 | import org.springframework.transaction.annotation.Transactional; | 18 | import org.springframework.transaction.annotation.Transactional; |
@@ -22,6 +22,8 @@ import org.springframework.web.bind.annotation.RequestMapping; | @@ -22,6 +22,8 @@ import org.springframework.web.bind.annotation.RequestMapping; | ||
22 | import org.springframework.web.bind.annotation.ResponseBody; | 22 | import org.springframework.web.bind.annotation.ResponseBody; |
23 | import org.springframework.web.bind.annotation.RestController; | 23 | import org.springframework.web.bind.annotation.RestController; |
24 | 24 | ||
25 | +import com.alibaba.fastjson.JSON; | ||
26 | + | ||
25 | import io.swagger.annotations.ApiOperation; | 27 | import io.swagger.annotations.ApiOperation; |
26 | 28 | ||
27 | @RestController | 29 | @RestController |
@@ -30,15 +32,22 @@ public class AcsController extends HuahengBaseController { | @@ -30,15 +32,22 @@ public class AcsController extends HuahengBaseController { | ||
30 | 32 | ||
31 | @Resource | 33 | @Resource |
32 | private IAcsService acsService; | 34 | private IAcsService acsService; |
35 | + | ||
33 | @Resource | 36 | @Resource |
34 | private IAgvTaskService agvTaskService; | 37 | private IAgvTaskService agvTaskService; |
35 | 38 | ||
39 | + @Resource | ||
40 | + private IAddressService addressService; | ||
41 | + | ||
36 | // @PassApiAuthentication | 42 | // @PassApiAuthentication |
37 | - @ApiLogger(apiName = "API接口第三方Token校验测试", from = "TEST") | 43 | +// @ApiLogger(apiName = "API接口第三方Token校验测试", from = "TEST") |
38 | @ResponseBody | 44 | @ResponseBody |
39 | @PostMapping(value = "/testTokenCheck") | 45 | @PostMapping(value = "/testTokenCheck") |
40 | public Result<?> testTokenCheck(@RequestBody Map<String, String> paramMap, HttpServletRequest request) { | 46 | public Result<?> testTokenCheck(@RequestBody Map<String, String> paramMap, HttpServletRequest request) { |
41 | - return new Result<>(); | 47 | + String url = "http://127.0.0.1:8080/wms/api/wms/acs/testTokenCheck"; |
48 | + String body = OkHttpUtils.sendPostByJsonStr(url, JSON.toJSONString(paramMap)); | ||
49 | +// String url = addressService.getUrlByParam(QuantityConstant.ADDRESS_AGV_TASK_ASSIGN); | ||
50 | + return Result.ok(body); | ||
42 | } | 51 | } |
43 | 52 | ||
44 | 53 |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/acs/service/impl/AcsServiceImpl.java
@@ -10,9 +10,9 @@ import org.jeecg.modules.wms.config.location.entity.Location; | @@ -10,9 +10,9 @@ import org.jeecg.modules.wms.config.location.entity.Location; | ||
10 | import org.jeecg.modules.wms.config.location.service.ILocationService; | 10 | import org.jeecg.modules.wms.config.location.service.ILocationService; |
11 | import org.jeecg.modules.wms.task.agvTask.entity.AgvTask; | 11 | import org.jeecg.modules.wms.task.agvTask.entity.AgvTask; |
12 | import org.jeecg.modules.wms.task.agvTask.service.IAgvTaskService; | 12 | import org.jeecg.modules.wms.task.agvTask.service.IAgvTaskService; |
13 | +import org.jeecg.utils.OkHttpUtils; | ||
13 | import org.jeecg.utils.StringUtils; | 14 | import org.jeecg.utils.StringUtils; |
14 | import org.jeecg.utils.constant.QuantityConstant; | 15 | import org.jeecg.utils.constant.QuantityConstant; |
15 | -import org.jeecg.utils.http.OkHttpUtils; | ||
16 | import org.springframework.stereotype.Service; | 16 | import org.springframework.stereotype.Service; |
17 | 17 | ||
18 | import com.alibaba.fastjson.JSON; | 18 | import com.alibaba.fastjson.JSON; |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/erp/service/impl/ErpServiceImpl.java
@@ -38,9 +38,9 @@ import org.jeecg.modules.wms.shipment.shipmentHeader.entity.ShipmentDetail; | @@ -38,9 +38,9 @@ import org.jeecg.modules.wms.shipment.shipmentHeader.entity.ShipmentDetail; | ||
38 | import org.jeecg.modules.wms.shipment.shipmentHeader.entity.ShipmentHeader; | 38 | import org.jeecg.modules.wms.shipment.shipmentHeader.entity.ShipmentHeader; |
39 | import org.jeecg.modules.wms.shipment.shipmentHeader.service.IShipmentDetailService; | 39 | import org.jeecg.modules.wms.shipment.shipmentHeader.service.IShipmentDetailService; |
40 | import org.jeecg.modules.wms.shipment.shipmentHeader.service.IShipmentHeaderService; | 40 | import org.jeecg.modules.wms.shipment.shipmentHeader.service.IShipmentHeaderService; |
41 | +import org.jeecg.utils.OkHttpUtils; | ||
41 | import org.jeecg.utils.StringUtils; | 42 | import org.jeecg.utils.StringUtils; |
42 | import org.jeecg.utils.constant.QuantityConstant; | 43 | import org.jeecg.utils.constant.QuantityConstant; |
43 | -import org.jeecg.utils.http.OkHttpUtils; | ||
44 | import org.springframework.stereotype.Service; | 44 | import org.springframework.stereotype.Service; |
45 | import org.springframework.transaction.annotation.Transactional; | 45 | import org.springframework.transaction.annotation.Transactional; |
46 | 46 |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/mes/servuce/impl/MesServiceImpl.java
@@ -33,9 +33,9 @@ import org.jeecg.modules.wms.task.taskHeader.entity.TaskDetail; | @@ -33,9 +33,9 @@ import org.jeecg.modules.wms.task.taskHeader.entity.TaskDetail; | ||
33 | import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; | 33 | import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; |
34 | import org.jeecg.modules.wms.task.taskHeader.service.ITaskDetailService; | 34 | import org.jeecg.modules.wms.task.taskHeader.service.ITaskDetailService; |
35 | import org.jeecg.modules.wms.task.taskHeader.service.ITaskHeaderService; | 35 | import org.jeecg.modules.wms.task.taskHeader.service.ITaskHeaderService; |
36 | +import org.jeecg.utils.OkHttpUtils; | ||
36 | import org.jeecg.utils.StringUtils; | 37 | import org.jeecg.utils.StringUtils; |
37 | import org.jeecg.utils.constant.QuantityConstant; | 38 | import org.jeecg.utils.constant.QuantityConstant; |
38 | -import org.jeecg.utils.http.OkHttpUtils; | ||
39 | import org.springframework.stereotype.Service; | 39 | import org.springframework.stereotype.Service; |
40 | import org.springframework.transaction.annotation.Transactional; | 40 | import org.springframework.transaction.annotation.Transactional; |
41 | 41 |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsServiceImpl.java
@@ -35,9 +35,9 @@ import org.jeecg.modules.wms.task.taskHeader.entity.TaskDetail; | @@ -35,9 +35,9 @@ import org.jeecg.modules.wms.task.taskHeader.entity.TaskDetail; | ||
35 | import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; | 35 | import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; |
36 | import org.jeecg.modules.wms.task.taskHeader.service.ITaskDetailService; | 36 | import org.jeecg.modules.wms.task.taskHeader.service.ITaskDetailService; |
37 | import org.jeecg.modules.wms.task.taskHeader.service.ITaskHeaderService; | 37 | import org.jeecg.modules.wms.task.taskHeader.service.ITaskHeaderService; |
38 | +import org.jeecg.utils.OkHttpUtils; | ||
38 | import org.jeecg.utils.StringUtils; | 39 | import org.jeecg.utils.StringUtils; |
39 | import org.jeecg.utils.constant.QuantityConstant; | 40 | import org.jeecg.utils.constant.QuantityConstant; |
40 | -import org.jeecg.utils.http.OkHttpUtils; | ||
41 | import org.springframework.stereotype.Service; | 41 | import org.springframework.stereotype.Service; |
42 | import org.springframework.transaction.annotation.Transactional; | 42 | import org.springframework.transaction.annotation.Transactional; |
43 | 43 |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/address/service/impl/AddressServiceImpl.java
@@ -6,6 +6,7 @@ import org.apache.commons.math3.analysis.function.Add; | @@ -6,6 +6,7 @@ import org.apache.commons.math3.analysis.function.Add; | ||
6 | import org.jeecg.modules.wms.config.address.entity.Address; | 6 | import org.jeecg.modules.wms.config.address.entity.Address; |
7 | import org.jeecg.modules.wms.config.address.mapper.AddressMapper; | 7 | import org.jeecg.modules.wms.config.address.mapper.AddressMapper; |
8 | import org.jeecg.modules.wms.config.address.service.IAddressService; | 8 | import org.jeecg.modules.wms.config.address.service.IAddressService; |
9 | +import org.springframework.cache.annotation.Cacheable; | ||
9 | import org.springframework.stereotype.Service; | 10 | import org.springframework.stereotype.Service; |
10 | 11 | ||
11 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 12 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
@@ -20,6 +21,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | @@ -20,6 +21,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||
20 | public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements IAddressService { | 21 | public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements IAddressService { |
21 | 22 | ||
22 | @Override | 23 | @Override |
24 | + @Cacheable(cacheNames = "getAddressByUrl#300", key = "#root.methodName + '_' + #url + '_' + #warehouseCode") | ||
23 | public Address getAddressByUrl(String url, String warehouseCode) { | 25 | public Address getAddressByUrl(String url, String warehouseCode) { |
24 | LambdaQueryWrapper<Address> addressLambdaQueryWrapper = Wrappers.lambdaQuery(); | 26 | LambdaQueryWrapper<Address> addressLambdaQueryWrapper = Wrappers.lambdaQuery(); |
25 | addressLambdaQueryWrapper.eq(Address::getUrl, url).eq(Address::getWarehouseCode, warehouseCode).last(" limit 1"); | 27 | addressLambdaQueryWrapper.eq(Address::getUrl, url).eq(Address::getWarehouseCode, warehouseCode).last(" limit 1"); |
@@ -28,6 +30,7 @@ public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> impl | @@ -28,6 +30,7 @@ public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> impl | ||
28 | } | 30 | } |
29 | 31 | ||
30 | @Override | 32 | @Override |
33 | + @Cacheable(cacheNames = "getUrlByParam#300", key = "#root.methodName + '_' + #param + '_' + #warehouseCode + '_' + #zoneCode") | ||
31 | public String getUrlByParam(String param, String warehouseCode, String zoneCode) { | 34 | public String getUrlByParam(String param, String warehouseCode, String zoneCode) { |
32 | LambdaQueryWrapper<Address> addressLambdaQueryWrapper = Wrappers.lambdaQuery(); | 35 | LambdaQueryWrapper<Address> addressLambdaQueryWrapper = Wrappers.lambdaQuery(); |
33 | addressLambdaQueryWrapper.eq(Address::getParam, param).eq(Address::getWarehouseCode, warehouseCode).eq(Address::getZoneCode, zoneCode); | 36 | addressLambdaQueryWrapper.eq(Address::getParam, param).eq(Address::getWarehouseCode, warehouseCode).eq(Address::getZoneCode, zoneCode); |
@@ -39,7 +42,9 @@ public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> impl | @@ -39,7 +42,9 @@ public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> impl | ||
39 | return url; | 42 | return url; |
40 | } | 43 | } |
41 | 44 | ||
45 | + /** #300 缓存300秒 */ | ||
42 | @Override | 46 | @Override |
47 | + @Cacheable(cacheNames = "getUrlByParam#300", key = "#root.methodName + '_' + #param") | ||
43 | public String getUrlByParam(String param) { | 48 | public String getUrlByParam(String param) { |
44 | LambdaQueryWrapper<Address> addressLambdaQueryWrapper = Wrappers.lambdaQuery(); | 49 | LambdaQueryWrapper<Address> addressLambdaQueryWrapper = Wrappers.lambdaQuery(); |
45 | addressLambdaQueryWrapper.eq(Address::getParam, param); | 50 | addressLambdaQueryWrapper.eq(Address::getParam, param); |
@@ -47,8 +52,6 @@ public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> impl | @@ -47,8 +52,6 @@ public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> impl | ||
47 | if (address == null) { | 52 | if (address == null) { |
48 | return null; | 53 | return null; |
49 | } | 54 | } |
50 | - String url = address.getUrl(); | ||
51 | - return url; | 55 | + return address.getUrl(); |
52 | } | 56 | } |
53 | - | ||
54 | } | 57 | } |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/location/service/impl/LocationServiceImpl.java
@@ -93,10 +93,13 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i | @@ -93,10 +93,13 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i | ||
93 | if (location == null) { | 93 | if (location == null) { |
94 | return false; | 94 | return false; |
95 | } | 95 | } |
96 | + boolean success = false; | ||
96 | // 如果这个托盘号已经在库位表里,那么不能再写入 | 97 | // 如果这个托盘号已经在库位表里,那么不能再写入 |
97 | - boolean success = havaContainerCodeInLocation(containerCode, warehouseCode); | ||
98 | - if (success) { | ||
99 | - throw new ServiceException("库位表已经存在这个容器号,不能再写入"); | 98 | + if (StringUtils.isNotEmpty(containerCode)) { |
99 | + success = havaContainerCodeInLocation(containerCode, warehouseCode); | ||
100 | + if (success) { | ||
101 | + throw new ServiceException("库位表已经存在这个容器号,不能再写入"); | ||
102 | + } | ||
100 | } | 103 | } |
101 | location.setContainerCode(containerCode); | 104 | location.setContainerCode(containerCode); |
102 | location.setStatus(status); | 105 | location.setStatus(status); |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiAuthenticationAspect.java
@@ -10,6 +10,7 @@ import org.aspectj.lang.annotation.Aspect; | @@ -10,6 +10,7 @@ import org.aspectj.lang.annotation.Aspect; | ||
10 | import org.aspectj.lang.annotation.Before; | 10 | import org.aspectj.lang.annotation.Before; |
11 | import org.aspectj.lang.annotation.Pointcut; | 11 | import org.aspectj.lang.annotation.Pointcut; |
12 | import org.aspectj.lang.reflect.MethodSignature; | 12 | import org.aspectj.lang.reflect.MethodSignature; |
13 | +import org.bouncycastle.crypto.RuntimeCryptoException; | ||
13 | import org.jeecg.modules.wms.framework.aspectj.dto.RSA256Key; | 14 | import org.jeecg.modules.wms.framework.aspectj.dto.RSA256Key; |
14 | import org.jeecg.utils.HuahengJwtUtil; | 15 | import org.jeecg.utils.HuahengJwtUtil; |
15 | import org.springframework.beans.factory.annotation.Autowired; | 16 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -23,9 +24,11 @@ import com.auth0.jwt.JWTVerifier; | @@ -23,9 +24,11 @@ import com.auth0.jwt.JWTVerifier; | ||
23 | import com.auth0.jwt.algorithms.Algorithm; | 24 | import com.auth0.jwt.algorithms.Algorithm; |
24 | import com.auth0.jwt.exceptions.JWTVerificationException; | 25 | import com.auth0.jwt.exceptions.JWTVerificationException; |
25 | import com.auth0.jwt.interfaces.DecodedJWT; | 26 | import com.auth0.jwt.interfaces.DecodedJWT; |
27 | +import com.baomidou.mybatisplus.extension.service.IService; | ||
26 | 28 | ||
27 | import cn.hutool.core.date.DatePattern; | 29 | import cn.hutool.core.date.DatePattern; |
28 | import cn.hutool.core.date.DateUtil; | 30 | import cn.hutool.core.date.DateUtil; |
31 | +import cn.hutool.core.util.StrUtil; | ||
29 | import lombok.extern.slf4j.Slf4j; | 32 | import lombok.extern.slf4j.Slf4j; |
30 | 33 | ||
31 | /** | 34 | /** |
@@ -68,12 +71,16 @@ public class ApiAuthenticationAspect { | @@ -68,12 +71,16 @@ public class ApiAuthenticationAspect { | ||
68 | ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes(); | 71 | ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes(); |
69 | HttpServletRequest request = attributes.getRequest(); | 72 | HttpServletRequest request = attributes.getRequest(); |
70 | String token = request.getHeader("token"); | 73 | String token = request.getHeader("token"); |
74 | + if (token == null) { | ||
75 | + log.error("Authentication token is null"); | ||
76 | + throw new RuntimeException("Authentication token is null"); | ||
77 | + } | ||
71 | try { | 78 | try { |
72 | Algorithm algorithm = Algorithm.RSA256(rsa256Key.getPublicKey(), rsa256Key.getPrivateKey()); | 79 | Algorithm algorithm = Algorithm.RSA256(rsa256Key.getPublicKey(), rsa256Key.getPrivateKey()); |
73 | JWTVerifier verifier = JWT.require(algorithm).withIssuer(HuahengJwtUtil.HUAHENG_SYSTEM_ID).build(); | 80 | JWTVerifier verifier = JWT.require(algorithm).withIssuer(HuahengJwtUtil.HUAHENG_SYSTEM_ID).build(); |
74 | verifier.verify(token); | 81 | verifier.verify(token); |
75 | } catch (JWTVerificationException e) { | 82 | } catch (JWTVerificationException e) { |
76 | - log.error("TOKEN认证失败:{}", e.getMessage()); | 83 | + log.error(e.getMessage()); |
77 | throw e; | 84 | throw e; |
78 | } | 85 | } |
79 | } | 86 | } |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiLogAspect.java
@@ -27,6 +27,7 @@ import org.jeecg.modules.wms.config.address.service.IAddressService; | @@ -27,6 +27,7 @@ import org.jeecg.modules.wms.config.address.service.IAddressService; | ||
27 | import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; | 27 | import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; |
28 | import org.jeecg.modules.wms.monitor.apiLog.entity.ApiLog; | 28 | import org.jeecg.modules.wms.monitor.apiLog.entity.ApiLog; |
29 | import org.jeecg.modules.wms.monitor.apiLog.service.IApiLogService; | 29 | import org.jeecg.modules.wms.monitor.apiLog.service.IApiLogService; |
30 | +import org.jeecg.utils.HuahengJwtUtil; | ||
30 | import org.jeecg.utils.ServletUtils; | 31 | import org.jeecg.utils.ServletUtils; |
31 | import org.jeecg.utils.SpringUtils; | 32 | import org.jeecg.utils.SpringUtils; |
32 | import org.jeecg.utils.StringUtils; | 33 | import org.jeecg.utils.StringUtils; |
@@ -239,47 +240,47 @@ public class ApiLogAspect { | @@ -239,47 +240,47 @@ public class ApiLogAspect { | ||
239 | /** | 240 | /** |
240 | * 记录WMS调用第三方系统接口的请求信息 | 241 | * 记录WMS调用第三方系统接口的请求信息 |
241 | * 在OKHttpUtils.bodypost方法中直接调用本类static方法 | 242 | * 在OKHttpUtils.bodypost方法中直接调用本类static方法 |
243 | + * @param apiLog | ||
242 | **/ | 244 | **/ |
243 | - public static ApiLog initApiLog(Request request, String body) { | ||
244 | - ApiLog log = new ApiLog(); | 245 | + public static void initApiLog(ApiLog apiLog, Request request, String body) { |
245 | try { | 246 | try { |
246 | - log.setApiMethod(request.method()); | ||
247 | - log.setUrl(request.url().toString()); | ||
248 | - log.setRequestTime(new Date()); | ||
249 | - parseUrl(log, request.url().url()); | ||
250 | - log.setRequestHeader(request.headers().toString()); | ||
251 | - log.setRequestBody(body); | 247 | + apiLog.setApiMethod(request.method()); |
248 | + apiLog.setUrl(request.url().toString()); | ||
249 | + apiLog.setRequestTime(new Date()); | ||
250 | + parseUrl(apiLog, request.url().url()); | ||
251 | + apiLog.setRequestHeader(request.headers().toString()); | ||
252 | + apiLog.setRequestBody(body); | ||
252 | } catch (Exception e) { | 253 | } catch (Exception e) { |
253 | e.printStackTrace(); | 254 | e.printStackTrace(); |
254 | } | 255 | } |
255 | - return log; | ||
256 | } | 256 | } |
257 | 257 | ||
258 | /** 记录响应头信息 **/ | 258 | /** 记录响应头信息 **/ |
259 | - public static void finishApiLog(ApiLog log, Response response, String body) { | 259 | + public static void finishApiLog(ApiLog log, Response response, String responseBody) { |
260 | try { | 260 | try { |
261 | - log.setResponseBody(body); | ||
262 | log.setResponseTime(new Date()); | 261 | log.setResponseTime(new Date()); |
263 | Long duration = log.getResponseTime().getTime() - log.getRequestTime().getTime(); | 262 | Long duration = log.getResponseTime().getTime() - log.getRequestTime().getTime(); |
264 | log.setDuration(duration.intValue()); | 263 | log.setDuration(duration.intValue()); |
264 | + if (response == null) { | ||
265 | + return; | ||
266 | + } | ||
265 | log.setHttpCode(response.code()); | 267 | log.setHttpCode(response.code()); |
266 | - | ||
267 | - // 响应头 | ||
268 | log.setResponseHeader(response.headers().toString()); | 268 | log.setResponseHeader(response.headers().toString()); |
269 | - Result ajaxResult = null; | 269 | + log.setResponseBody(responseBody); |
270 | + Result result = null; | ||
270 | try { | 271 | try { |
271 | - ajaxResult = JSON.parseObject(body, Result.class); | 272 | + result = JSON.parseObject(responseBody, Result.class); |
272 | } catch (Exception ex) { | 273 | } catch (Exception ex) { |
273 | - body = JSON.parse(body).toString(); | ||
274 | - ajaxResult = JSON.parseObject(body, Result.class); | 274 | + responseBody = JSON.parse(responseBody).toString(); |
275 | + result = JSON.parseObject(responseBody, Result.class); | ||
275 | } | 276 | } |
276 | - log.setRetCode(ajaxResult.getCode()); | 277 | + log.setRetCode(result.getCode()); |
277 | } catch (Exception e) { | 278 | } catch (Exception e) { |
278 | e.printStackTrace(); | 279 | e.printStackTrace(); |
279 | } finally { | 280 | } finally { |
280 | try { | 281 | try { |
281 | if (StringUtils.isNotEmpty(log.getResponseBody()) && log.getResponseBody().length() > 2001) { | 282 | if (StringUtils.isNotEmpty(log.getResponseBody()) && log.getResponseBody().length() > 2001) { |
282 | - log.setResponseBody(log.getResponseBody().substring(0, 2000) + "...\nResponseBodyLength:" + log.getResponseBody().length()); | 283 | + log.setResponseBody(log.getResponseBody().substring(0, 2000) + "...\n"); |
283 | } | 284 | } |
284 | } catch (Exception e) { | 285 | } catch (Exception e) { |
285 | e.printStackTrace(); | 286 | e.printStackTrace(); |
@@ -289,16 +290,16 @@ public class ApiLogAspect { | @@ -289,16 +290,16 @@ public class ApiLogAspect { | ||
289 | } | 290 | } |
290 | 291 | ||
291 | /** 根据url,从address表中判断调用的去向 **/ | 292 | /** 根据url,从address表中判断调用的去向 **/ |
292 | - public static void parseUrl(ApiLog log, URL url) { | 293 | + public static void parseUrl(ApiLog apiLog, URL url) { |
293 | try { | 294 | try { |
294 | String[] spList = url.toString().split("/"); | 295 | String[] spList = url.toString().split("/"); |
295 | String apiName = spList[spList.length - 1]; | 296 | String apiName = spList[spList.length - 1]; |
296 | String ip = JeecgSystemApplication.getLocalHostExactAddress().getHostAddress(); | 297 | String ip = JeecgSystemApplication.getLocalHostExactAddress().getHostAddress(); |
297 | - Address address = addressService.getAddressByUrl(url.toString(), QuantityConstant.DEFAULT_WAREHOUSE); | ||
298 | - log.setApiName(apiName); | ||
299 | - log.setRequestFrom("WMS"); | ||
300 | - log.setIp(ip); | ||
301 | - log.setResponseBy(address.getParam().toUpperCase()); | 298 | + apiLog.setApiName(apiName); |
299 | + apiLog.setRequestFrom(HuahengJwtUtil.HUAHENG_SYSTEM_ID); | ||
300 | + apiLog.setIp(ip); | ||
301 | +// Address address = addressService.getAddressByUrl(url.toString(), QuantityConstant.DEFAULT_WAREHOUSE); | ||
302 | +// apiLog.setResponseBy(address.getParam().toUpperCase()); | ||
302 | } catch (Exception e) { | 303 | } catch (Exception e) { |
303 | e.printStackTrace(); | 304 | e.printStackTrace(); |
304 | } | 305 | } |
@@ -398,7 +399,7 @@ public class ApiLogAspect { | @@ -398,7 +399,7 @@ public class ApiLogAspect { | ||
398 | public static void setApiLogException(ApiLog log, Exception e) { | 399 | public static void setApiLogException(ApiLog log, Exception e) { |
399 | try { | 400 | try { |
400 | String exception = ExceptionUtils.getFullStackTrace(e); | 401 | String exception = ExceptionUtils.getFullStackTrace(e); |
401 | - String shortExpInfo = e.getMessage() + "\n" + org.apache.commons.lang3.StringUtils.left(exception, 1000); | 402 | + String shortExpInfo = e.getMessage() + "\n" + org.apache.commons.lang3.StringUtils.left(exception, 1000) + "..."; |
402 | log.setException(shortExpInfo); | 403 | log.setException(shortExpInfo); |
403 | } catch (Exception ex) { | 404 | } catch (Exception ex) { |
404 | ex.printStackTrace(); | 405 | ex.printStackTrace(); |
@@ -408,7 +409,7 @@ public class ApiLogAspect { | @@ -408,7 +409,7 @@ public class ApiLogAspect { | ||
408 | public static void setApiLogThrowable(ApiLog log, Throwable e) { | 409 | public static void setApiLogThrowable(ApiLog log, Throwable e) { |
409 | try { | 410 | try { |
410 | String exception = ExceptionUtils.getFullStackTrace(e); | 411 | String exception = ExceptionUtils.getFullStackTrace(e); |
411 | - String shortExpInfo = e.getMessage() + "\n" + org.apache.commons.lang3.StringUtils.left(exception, 1000); | 412 | + String shortExpInfo = e.getMessage() + "\n" + org.apache.commons.lang3.StringUtils.left(exception, 1000) + "..."; |
412 | log.setException(shortExpInfo); | 413 | log.setException(shortExpInfo); |
413 | } catch (Exception ex) { | 414 | } catch (Exception ex) { |
414 | ex.printStackTrace(); | 415 | ex.printStackTrace(); |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/controller/HuahengBaseController.java
@@ -5,7 +5,7 @@ import java.util.concurrent.TimeUnit; | @@ -5,7 +5,7 @@ import java.util.concurrent.TimeUnit; | ||
5 | import javax.annotation.Nonnull; | 5 | import javax.annotation.Nonnull; |
6 | 6 | ||
7 | import org.jeecg.common.api.vo.Result; | 7 | import org.jeecg.common.api.vo.Result; |
8 | -import org.jeecg.utils.RedissonDistributedLocker; | 8 | +import org.jeecg.utils.support.RedissonDistributedLocker; |
9 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
10 | 10 | ||
11 | import cn.hutool.core.date.SystemClock; | 11 | import cn.hutool.core.date.SystemClock; |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/shipment/shipmentCombination/service/impl/ShipmentCombinationServiceImpl.java
@@ -135,9 +135,9 @@ public class ShipmentCombinationServiceImpl implements IShipmentCombinationServi | @@ -135,9 +135,9 @@ public class ShipmentCombinationServiceImpl implements IShipmentCombinationServi | ||
135 | } | 135 | } |
136 | } | 136 | } |
137 | if (over) { | 137 | if (over) { |
138 | - return Result.OK("出库单已经配盘"); | 138 | + return Result.OK("出库单已经配盘", null); |
139 | } | 139 | } |
140 | - return Result.OK("自动组盘成功"); | 140 | + return Result.OK("自动组盘成功", null); |
141 | } | 141 | } |
142 | 142 | ||
143 | @Override | 143 | @Override |
@@ -210,7 +210,7 @@ public class ShipmentCombinationServiceImpl implements IShipmentCombinationServi | @@ -210,7 +210,7 @@ public class ShipmentCombinationServiceImpl implements IShipmentCombinationServi | ||
210 | throw new ServiceException(result.getMessage()); | 210 | throw new ServiceException(result.getMessage()); |
211 | } | 211 | } |
212 | } | 212 | } |
213 | - return Result.OK("自动组盘成功"); | 213 | + return Result.OK("自动组盘成功", null); |
214 | } | 214 | } |
215 | 215 | ||
216 | @Override | 216 | @Override |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/task/taskHeader/controller/TaskHeaderController.java
@@ -25,6 +25,7 @@ import org.jeecg.modules.wms.config.port.entity.Port; | @@ -25,6 +25,7 @@ import org.jeecg.modules.wms.config.port.entity.Port; | ||
25 | import org.jeecg.modules.wms.config.port.service.IPortService; | 25 | import org.jeecg.modules.wms.config.port.service.IPortService; |
26 | import org.jeecg.modules.wms.config.zone.entity.Zone; | 26 | import org.jeecg.modules.wms.config.zone.entity.Zone; |
27 | import org.jeecg.modules.wms.config.zone.service.IZoneService; | 27 | import org.jeecg.modules.wms.config.zone.service.IZoneService; |
28 | +import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; | ||
28 | import org.jeecg.modules.wms.framework.controller.HuahengBaseController; | 29 | import org.jeecg.modules.wms.framework.controller.HuahengBaseController; |
29 | import org.jeecg.modules.wms.task.taskHeader.entity.TaskDetail; | 30 | import org.jeecg.modules.wms.task.taskHeader.entity.TaskDetail; |
30 | import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; | 31 | import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; |
@@ -648,4 +649,46 @@ public class TaskHeaderController extends HuahengBaseController { | @@ -648,4 +649,46 @@ public class TaskHeaderController extends HuahengBaseController { | ||
648 | return Result.OK(portList); | 649 | return Result.OK(portList); |
649 | } | 650 | } |
650 | 651 | ||
652 | + /** | ||
653 | + * 修复空出的数据 | ||
654 | + * @return | ||
655 | + */ | ||
656 | + @AutoLog(value = "修复空出的数据") | ||
657 | + @PostMapping("/handleEmptyOut") | ||
658 | + @ApiOperation("修复空出的数据") | ||
659 | + @ResponseBody | ||
660 | + @ApiLogger(apiName = "修复空出的数据", from = "WMS") | ||
661 | + public Result handleEmptyOut(@RequestBody String taskNo) { | ||
662 | + Result result = taskHeaderService.handleEmptyOut(taskNo); | ||
663 | + return result; | ||
664 | + } | ||
665 | + | ||
666 | + /** | ||
667 | + * 修复重入的数据 | ||
668 | + * @return | ||
669 | + */ | ||
670 | + @AutoLog(value = "修复重入的数据") | ||
671 | + @PostMapping("/handleDoubleIn") | ||
672 | + @ApiOperation("修复重入的数据") | ||
673 | + @ResponseBody | ||
674 | + @ApiLogger(apiName = "修复重入的数据", from = "WMS") | ||
675 | + public Result handleDoubleIn(@RequestBody String taskNo) { | ||
676 | + Result result = taskHeaderService.handleDoubleIn(taskNo); | ||
677 | + return result; | ||
678 | + } | ||
679 | + | ||
680 | + /** | ||
681 | + * 修复取货错的数据 | ||
682 | + * @return | ||
683 | + */ | ||
684 | + @AutoLog(value = "修复取货错的数据") | ||
685 | + @PostMapping("handlePickupError") | ||
686 | + @ApiOperation("修复取货错的数据") | ||
687 | + @ResponseBody | ||
688 | + @ApiLogger(apiName = "修复取货错的数据", from = "WMS") | ||
689 | + public Result handlePickupError(@RequestBody String taskNo) { | ||
690 | + Result result = taskHeaderService.handlePickupError(taskNo); | ||
691 | + return result; | ||
692 | + } | ||
693 | + | ||
651 | } | 694 | } |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/task/taskHeader/service/impl/TaskHeaderServiceImpl.java
@@ -2126,14 +2126,14 @@ public class TaskHeaderServiceImpl extends ServiceImpl<TaskHeaderMapper, TaskHea | @@ -2126,14 +2126,14 @@ public class TaskHeaderServiceImpl extends ServiceImpl<TaskHeaderMapper, TaskHea | ||
2126 | if (StringUtils.isNotEmpty(lastStatus)) { | 2126 | if (StringUtils.isNotEmpty(lastStatus)) { |
2127 | container.setStatus(lastStatus); // 解决空托盘组移库问题 | 2127 | container.setStatus(lastStatus); // 解决空托盘组移库问题 |
2128 | } | 2128 | } |
2129 | - if (StringUtils.isNotEmpty(fromLocationCode)) { | ||
2130 | - success = containerService.havaLocationCodeByContainer(fromLocationCode, warehouseCode); | ||
2131 | - if (success) { | ||
2132 | - throw new ServiceException("库位表已经存在这个容器号,不能再写入"); | ||
2133 | - } | ||
2134 | - } | 2129 | +// if (StringUtils.isNotEmpty(fromLocationCode)) { |
2130 | +// success = containerService.havaLocationCodeByContainer(fromLocationCode, warehouseCode); | ||
2131 | +// if (success) { | ||
2132 | +// throw new ServiceException("库位表已经存在这个容器号,不能再写入"); | ||
2133 | +// } | ||
2134 | +// } | ||
2135 | container.setLastStatus(QuantityConstant.EMPTY_STRING); | 2135 | container.setLastStatus(QuantityConstant.EMPTY_STRING); |
2136 | - container.setLocationCode(fromLocationCode); | 2136 | +// container.setLocationCode(fromLocationCode); |
2137 | success = containerService.updateById(container); | 2137 | success = containerService.updateById(container); |
2138 | if (!success) { | 2138 | if (!success) { |
2139 | throw new ServiceException("取消任务时, 更新容器失败"); | 2139 | throw new ServiceException("取消任务时, 更新容器失败"); |
huaheng-wms-core/src/main/java/org/jeecg/utils/HuahengJwtUtil.java
@@ -28,7 +28,7 @@ public class HuahengJwtUtil { | @@ -28,7 +28,7 @@ public class HuahengJwtUtil { | ||
28 | /** token失效时间 1天 */ | 28 | /** token失效时间 1天 */ |
29 | public static final long EXPIRE_TIME = 24 * 60 * 60 * 1000; | 29 | public static final long EXPIRE_TIME = 24 * 60 * 60 * 1000; |
30 | 30 | ||
31 | - public static final String HUAHENG_SYSTEM_ID = "HUAHENG-WMS4-4.0.1"; | 31 | + public static final String HUAHENG_SYSTEM_ID = "HUAHENG-WMS4"; |
32 | 32 | ||
33 | /** | 33 | /** |
34 | * 根据request中的token获取用户账号 | 34 | * 根据request中的token获取用户账号 |
huaheng-wms-core/src/main/java/org/jeecg/utils/OkHttpUtils.java
0 → 100644
1 | +package org.jeecg.utils; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSON; | ||
4 | +import com.alibaba.fastjson.TypeReference; | ||
5 | +import com.alibaba.fastjson.parser.Feature; | ||
6 | +import com.aliyun.oss.ServiceException; | ||
7 | +import com.xkcoding.http.util.StringUtil; | ||
8 | + | ||
9 | +import antlr.StringUtils; | ||
10 | +import cn.hutool.core.util.StrUtil; | ||
11 | +import net.bytebuddy.asm.Advice.This; | ||
12 | +import okhttp3.*; | ||
13 | +import org.jeecg.modules.wms.framework.aspectj.ApiLogAspect; | ||
14 | +import org.jeecg.modules.wms.monitor.apiLog.entity.ApiLog; | ||
15 | +import org.slf4j.Logger; | ||
16 | +import org.slf4j.LoggerFactory; | ||
17 | +import org.springframework.messaging.support.ErrorMessage; | ||
18 | + | ||
19 | +import java.io.IOException; | ||
20 | +import java.lang.reflect.Type; | ||
21 | +import java.util.HashMap; | ||
22 | +import java.util.Map; | ||
23 | +import java.util.Objects; | ||
24 | +import java.util.concurrent.TimeUnit; | ||
25 | +import java.util.concurrent.TimeoutException; | ||
26 | + | ||
27 | +import javax.validation.constraints.NotNull; | ||
28 | + | ||
29 | +/** | ||
30 | + * OkHttp发送请求 | ||
31 | + * @author huaheng | ||
32 | + * @Date 2022-5-30 | ||
33 | + */ | ||
34 | +public class OkHttpUtils { | ||
35 | + | ||
36 | + private static final Logger log = LoggerFactory.getLogger(OkHttpUtils.class); | ||
37 | + | ||
38 | + /** | ||
39 | + * 最多重试次数 | ||
40 | + */ | ||
41 | + public final static int MAX_RENTRY_COUNT = 3; | ||
42 | + | ||
43 | + /** | ||
44 | + * 最大连接时间(秒) | ||
45 | + */ | ||
46 | + public final static int CONNECTION_TIMEOUT = 1; | ||
47 | + | ||
48 | + /** | ||
49 | + * 最大读取时间(秒) | ||
50 | + */ | ||
51 | + public final static int READ_TIMEOUT = 30; | ||
52 | + | ||
53 | + /** | ||
54 | + * 最大写入时间(秒) | ||
55 | + */ | ||
56 | + public final static int WRITE_TIMEOUT = 30; | ||
57 | + | ||
58 | + /** | ||
59 | + * JSON格式 | ||
60 | + */ | ||
61 | + public static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8"); | ||
62 | + /** | ||
63 | + * OkHTTP线程池最大空闲线程数 | ||
64 | + */ | ||
65 | + public final static int MAX_IDLE_CONNECTIONS = 100; | ||
66 | + /** | ||
67 | + * OkHTTP线程池空闲线程存活时间(秒) | ||
68 | + */ | ||
69 | + public final static long KEEP_ALIVE_DURATION = 60; | ||
70 | + | ||
71 | + private static final String CONTENT_TYPE = "Content-Type"; | ||
72 | + | ||
73 | + /** 访问接口参数配置 */ | ||
74 | + private final static OkHttpClient HTTP_CLIENT = | ||
75 | + new OkHttpClient.Builder().connectTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS).readTimeout(READ_TIMEOUT, TimeUnit.SECONDS) | ||
76 | + .writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS).addInterceptor(new OkHttpUtils.OkhttpInterceptor(MAX_RENTRY_COUNT)) // 过滤器,设置最大重试次数 | ||
77 | + .retryOnConnectionFailure(false).connectionPool(new ConnectionPool(MAX_IDLE_CONNECTIONS, KEEP_ALIVE_DURATION, TimeUnit.SECONDS)).build(); | ||
78 | + | ||
79 | + /** | ||
80 | + * 向指定 URL 发送GET方法的请求 | ||
81 | + * @param url 发送请求的 URL | ||
82 | + * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式 | ||
83 | + * @return 所代表远程资源的响应结果 | ||
84 | + * @throws Exception | ||
85 | + */ | ||
86 | + public static String sendGet(String url, String param) { | ||
87 | + Map<String, String> headers = new HashMap<String, String>(); | ||
88 | + return sendGet(url, headers, param); | ||
89 | + } | ||
90 | + | ||
91 | + /** | ||
92 | + * 向指定 URL 发送GET方法的请求 | ||
93 | + * @param url 发送请求的 URL | ||
94 | + * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式 | ||
95 | + * @param headers 请求头 | ||
96 | + * @return 所代表远程资源的响应结果 | ||
97 | + * @throws Exception | ||
98 | + */ | ||
99 | + public static String sendGet(String url, Map<String, String> headers, String param) { | ||
100 | + ApiLog apiLog = new ApiLog(); | ||
101 | + Request.Builder builder = new Request.Builder(); | ||
102 | + buildHeader(builder, headers); | ||
103 | + Request request = builder.url(url + "?" + param).get().build(); | ||
104 | + Response response = null; | ||
105 | + String result = null; | ||
106 | + try { | ||
107 | + ApiLogAspect.initApiLog(apiLog, request, param); | ||
108 | + response = HTTP_CLIENT.newCall(request).execute(); | ||
109 | + result = response.body().string(); | ||
110 | + } catch (Exception e) { | ||
111 | + String errorString = | ||
112 | + StrUtil.format("执行GET请求异常,url:{},header:{},param:{},errorMessage:{}", url, JSON.toJSONString(headers), param, e.getMessage()); | ||
113 | + ApiLogAspect.setApiLogException(apiLog, e); | ||
114 | + throw new RuntimeException(errorString, e); | ||
115 | + } finally { | ||
116 | + ApiLogAspect.finishApiLog(apiLog, response, result); | ||
117 | + } | ||
118 | + if (response.isSuccessful() && Objects.nonNull(response.body())) {// 调用成功 | ||
119 | + log.info("执行GET请求成功,url:{},header:{},param:{},result:{}", url, JSON.toJSONString(headers), param, result); | ||
120 | + } else { | ||
121 | + String errorString = StrUtil.format("执行GET请求失败,url:{},header:{},param:{},responseCode:{},responseMessage:{}", url, | ||
122 | + JSON.toJSONString(headers), param, response.code(), response.message()); | ||
123 | + throw new ServiceException(errorString); | ||
124 | + } | ||
125 | + return result; | ||
126 | + } | ||
127 | + | ||
128 | + /** | ||
129 | + * 向指定 URL 发送POST方法的请求 | ||
130 | + * @param url 发送请求的 URL | ||
131 | + * @param param 请求参数,请求参数是 name1=value1&name2=value2 的形式 | ||
132 | + * @return 远程资源的响应结果 | ||
133 | + * @throws IOException | ||
134 | + */ | ||
135 | + public static String sendPost(String url, String param) throws IOException { | ||
136 | + Map<String, String> headers = new HashMap<String, String>(); | ||
137 | + return sendPost(url, headers, param); | ||
138 | + } | ||
139 | + | ||
140 | + /** | ||
141 | + * 向指定 URL 发送POST方法的请求 | ||
142 | + * @param url 发送请求的 URL | ||
143 | + * @param param 请求参数,请求参数是 name1=value1&name2=value2 的形式 | ||
144 | + * @param headers 请求头 | ||
145 | + * @return 远程资源的响应结果 | ||
146 | + * @throws IOException | ||
147 | + */ | ||
148 | + public static String sendPost(String url, Map<String, String> headers, String param) { | ||
149 | + ApiLog apiLog = new ApiLog(); | ||
150 | + Request.Builder builder = new Request.Builder(); | ||
151 | + buildHeader(builder, headers); | ||
152 | + FormBody body = new FormBody.Builder().build(); | ||
153 | + Request request = builder.url(url + "?" + param).post(body).build(); | ||
154 | + Response response = null; | ||
155 | + String result = null; | ||
156 | + try { | ||
157 | + ApiLogAspect.initApiLog(apiLog, request, param); | ||
158 | + response = HTTP_CLIENT.newCall(request).execute(); | ||
159 | + result = response.body().string(); | ||
160 | + } catch (Exception e) { | ||
161 | + String errorString = | ||
162 | + StrUtil.format("执行POST请求异常,url:{},header:{},param:{},errorMessage:{}", url, JSON.toJSONString(headers), param, e.getMessage()); | ||
163 | + ApiLogAspect.setApiLogException(apiLog, e); | ||
164 | + throw new RuntimeException(errorString, e); | ||
165 | + } finally { | ||
166 | + ApiLogAspect.finishApiLog(apiLog, response, result); | ||
167 | + } | ||
168 | + if (response.isSuccessful() && Objects.nonNull(response.body())) {// 调用成功 | ||
169 | + log.info("执行POST请求成功,url:{},header:{},param:{},result:{}", url, JSON.toJSONString(headers), param, result); | ||
170 | + } else { | ||
171 | + String errorString = StrUtil.format("执行POST请求失败,url:{},header:{},param:{},responseCode:{},responseMessage:{}", url, | ||
172 | + JSON.toJSONString(headers), param, response.code(), response.message()); | ||
173 | + throw new RuntimeException(errorString); | ||
174 | + } | ||
175 | + return result; | ||
176 | + } | ||
177 | + | ||
178 | + public static String sendPostByJsonStr(String url, String jsonString) { | ||
179 | + Map<String, String> headers = new HashMap<String, String>(); | ||
180 | + return sendPostByJsonStr(url, headers, jsonString); | ||
181 | + } | ||
182 | + | ||
183 | + /** | ||
184 | + * JSONString形式发送POST请求 | ||
185 | + * @throws Exception | ||
186 | + * @throws IOException | ||
187 | + */ | ||
188 | + public static String sendPostByJsonStr(String url, Map<String, String> headers, String jsonString) { | ||
189 | + ApiLog apiLog = new ApiLog(); | ||
190 | + headers.put("Accept", "application/json");// 设置接收数据的格式 | ||
191 | + headers.put("Content-Type", "application/json");// 设置发送数据的格式 | ||
192 | + Request.Builder builder = new Request.Builder(); | ||
193 | + buildHeader(builder, headers); | ||
194 | + RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, jsonString); | ||
195 | + Request request = builder.url(url).post(body).build(); | ||
196 | + Response response = null; | ||
197 | + String result = null; | ||
198 | + try { | ||
199 | + ApiLogAspect.initApiLog(apiLog, request, jsonString); | ||
200 | + response = HTTP_CLIENT.newCall(request).execute(); | ||
201 | + result = response.body().string(); | ||
202 | + } catch (Exception e) { | ||
203 | + String errorString = StrUtil.format("执行POST请求异常,url:{},header:{},param:{},errorMessage:{}", url, JSON.toJSONString(headers), jsonString, e.getMessage()); | ||
204 | + ApiLogAspect.setApiLogException(apiLog, e); | ||
205 | + throw new RuntimeException(errorString); | ||
206 | + } finally { | ||
207 | + ApiLogAspect.finishApiLog(apiLog, response, result); | ||
208 | + } | ||
209 | + if (response.isSuccessful() && Objects.nonNull(response.body())) {// 调用成功 | ||
210 | + log.info("执行POST请求成功,url:{},header:{},param:{},result:{}", url, JSON.toJSONString(headers), jsonString, result); | ||
211 | + } else { | ||
212 | + String errorString = StrUtil.format("执行POST请求失败,url:{},header:{},param:{},responseCode:{},responseMessage:{}", url, | ||
213 | + JSON.toJSONString(headers), jsonString, response.code(), response.message()); | ||
214 | + throw new RuntimeException(errorString); | ||
215 | + } | ||
216 | + return result; | ||
217 | + } | ||
218 | + | ||
219 | + /** | ||
220 | + * 设置请求头 | ||
221 | + * @param builder . | ||
222 | + * @param headers 请求头 | ||
223 | + */ | ||
224 | + private static void buildHeader(Request.Builder builder, Map<String, String> headers) { | ||
225 | + if (Objects.nonNull(headers) && headers.size() > 0) { | ||
226 | + headers.forEach((k, v) -> { | ||
227 | + if (Objects.nonNull(k) && Objects.nonNull(v)) { | ||
228 | + builder.addHeader(k, v); | ||
229 | + } | ||
230 | + }); | ||
231 | + } | ||
232 | + } | ||
233 | + | ||
234 | + /** | ||
235 | + * 支持嵌套泛型的POST请求 | ||
236 | + * @param url 链接 | ||
237 | + * @param json 请求json | ||
238 | + * @param type 嵌套泛型 | ||
239 | + * @return 响应对象, 可进行强转。 | ||
240 | + * @throws Exception | ||
241 | + */ | ||
242 | + public static <T> T sendPostByJsonStr(String url, String jsonString, TypeReference<T> type) throws Exception { | ||
243 | + String result = sendPostByJsonStr(url, jsonString); | ||
244 | + if (Objects.nonNull(result) && Objects.nonNull(type)) { | ||
245 | + return JSON.parseObject(result, type); | ||
246 | + } | ||
247 | + return null; | ||
248 | + } | ||
249 | + | ||
250 | + public static class OkhttpInterceptor implements Interceptor { | ||
251 | + // 最大重试次数 | ||
252 | + private int maxRentry; | ||
253 | + | ||
254 | + public OkhttpInterceptor(int maxRentry) { | ||
255 | + this.maxRentry = maxRentry; | ||
256 | + } | ||
257 | + | ||
258 | + /** 递归 2次下发请求,如果仍然失败 则返回 null 但是 intercept must not return null. 返回 null 会报 IllegalStateException 异常 */ | ||
259 | + public Response intercept(@NotNull Chain chain) throws IOException { | ||
260 | + return retry(chain, 0); | ||
261 | + } | ||
262 | + | ||
263 | + private Response retry(Chain chain, int retryCent) throws IOException { | ||
264 | + Request request = chain.request(); | ||
265 | + Response response = null; | ||
266 | + try { | ||
267 | + response = chain.proceed(request); | ||
268 | + } catch (Exception e) { | ||
269 | + if (maxRentry > retryCent) { | ||
270 | + return retry(chain, retryCent + 1); | ||
271 | + } | ||
272 | + if (Objects.isNull(response)) { | ||
273 | + throw e; | ||
274 | + } | ||
275 | + } | ||
276 | + return response; | ||
277 | + } | ||
278 | + } | ||
279 | +} |
huaheng-wms-core/src/main/java/org/jeecg/utils/SecretKeyUtils.java
@@ -16,13 +16,9 @@ import java.util.Map; | @@ -16,13 +16,9 @@ import java.util.Map; | ||
16 | 16 | ||
17 | import org.jeecg.modules.wms.framework.aspectj.dto.RSA256Key; | 17 | import org.jeecg.modules.wms.framework.aspectj.dto.RSA256Key; |
18 | 18 | ||
19 | -import sun.misc.BASE64Decoder; | ||
20 | -import sun.misc.BASE64Encoder; | ||
21 | - | ||
22 | /** | 19 | /** |
23 | * KeyPairGenerator https://www.jianshu.com/p/4de1ee0e7206 key的生成使用方法 | 20 | * KeyPairGenerator https://www.jianshu.com/p/4de1ee0e7206 key的生成使用方法 |
24 | */ | 21 | */ |
25 | -@SuppressWarnings("restriction") | ||
26 | public class SecretKeyUtils { | 22 | public class SecretKeyUtils { |
27 | 23 | ||
28 | public static final String KEY_ALGORITHM = "RSA"; | 24 | public static final String KEY_ALGORITHM = "RSA"; |
@@ -68,12 +64,12 @@ public class SecretKeyUtils { | @@ -68,12 +64,12 @@ public class SecretKeyUtils { | ||
68 | 64 | ||
69 | // 解码返回byte | 65 | // 解码返回byte |
70 | public static byte[] decryptBASE64(String key) throws Exception { | 66 | public static byte[] decryptBASE64(String key) throws Exception { |
71 | - return (new BASE64Decoder()).decodeBuffer(key); | 67 | + return Base64.getDecoder().decode(key); |
72 | } | 68 | } |
73 | 69 | ||
74 | // 编码返回字符串 | 70 | // 编码返回字符串 |
75 | public static String encryptBASE64(byte[] key) throws Exception { | 71 | public static String encryptBASE64(byte[] key) throws Exception { |
76 | - return (new BASE64Encoder()).encodeBuffer(key); | 72 | + return Base64.getEncoder().encodeToString(key); |
77 | } | 73 | } |
78 | 74 | ||
79 | // 使用KeyPairGenerator 生成公私钥,存放于map对象中 | 75 | // 使用KeyPairGenerator 生成公私钥,存放于map对象中 |
huaheng-wms-core/src/main/java/org/jeecg/utils/StringUtils.java
1 | package org.jeecg.utils; | 1 | package org.jeecg.utils; |
2 | 2 | ||
3 | -import org.apache.commons.lang.text.StrBuilder; | ||
4 | -import org.jeecg.utils.support.StrFormatter; | ||
5 | - | ||
6 | import java.lang.reflect.Field; | 3 | import java.lang.reflect.Field; |
7 | import java.util.Collection; | 4 | import java.util.Collection; |
8 | import java.util.Map; | 5 | import java.util.Map; |
9 | 6 | ||
7 | +import org.apache.commons.lang.text.StrBuilder; | ||
8 | + | ||
10 | /** | 9 | /** |
11 | * 字符串工具类 | 10 | * 字符串工具类 |
12 | * @author huaheng | 11 | * @author huaheng |
@@ -238,25 +237,6 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils { | @@ -238,25 +237,6 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils { | ||
238 | } | 237 | } |
239 | 238 | ||
240 | /** | 239 | /** |
241 | - * 格式化文本, {} 表示占位符<br> | ||
242 | - * 此方法只是简单将占位符 {} 按照顺序替换为参数<br> | ||
243 | - * 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可<br> | ||
244 | - * 例:<br> | ||
245 | - * 通常使用:format("this is {} for {}", "a", "b") -> this is a for b<br> | ||
246 | - * 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a<br> | ||
247 | - * 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br> | ||
248 | - * @param template 文本模板,被替换的部分用 {} 表示 | ||
249 | - * @param params 参数值 | ||
250 | - * @return 格式化后的文本 | ||
251 | - */ | ||
252 | - public static String format(String template, Object... params) { | ||
253 | - if (isEmpty(params) || isEmpty(template)) { | ||
254 | - return template; | ||
255 | - } | ||
256 | - return StrFormatter.format(template, params); | ||
257 | - } | ||
258 | - | ||
259 | - /** | ||
260 | * 驼峰首字符小写 | 240 | * 驼峰首字符小写 |
261 | */ | 241 | */ |
262 | public static String uncapitalize(String str) { | 242 | public static String uncapitalize(String str) { |
huaheng-wms-core/src/main/java/org/jeecg/utils/config/HuahengRedisConfig.java
0 → 100644
1 | +package org.jeecg.utils.config; | ||
2 | + | ||
3 | +import com.fasterxml.jackson.annotation.JsonAutoDetect; | ||
4 | +import com.fasterxml.jackson.annotation.PropertyAccessor; | ||
5 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
6 | +import lombok.extern.slf4j.Slf4j; | ||
7 | + | ||
8 | +import org.jeecg.utils.manager.RedisConfigCacheManager; | ||
9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
10 | +import org.springframework.context.annotation.Bean; | ||
11 | +import org.springframework.context.annotation.Configuration; | ||
12 | +import org.springframework.context.annotation.Primary; | ||
13 | +import org.springframework.data.redis.cache.RedisCacheConfiguration; | ||
14 | +import org.springframework.data.redis.cache.RedisCacheManager; | ||
15 | +import org.springframework.data.redis.cache.RedisCacheWriter; | ||
16 | +import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
17 | +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; | ||
18 | +import org.springframework.data.redis.serializer.RedisSerializationContext; | ||
19 | +import org.springframework.data.redis.serializer.RedisSerializer; | ||
20 | +import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
21 | + | ||
22 | +import java.time.Duration; | ||
23 | + | ||
24 | +@Slf4j | ||
25 | +@Configuration | ||
26 | +public class HuahengRedisConfig { | ||
27 | + | ||
28 | + @Bean | ||
29 | + @Primary | ||
30 | + public RedisCacheManager redisCacheManager(RedisConnectionFactory factory) { | ||
31 | + ObjectMapper om = new ObjectMapper(); | ||
32 | + RedisSerializer<String> redisSerializer = new StringRedisSerializer(); | ||
33 | + Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class); | ||
34 | + // 解决查询缓存转换异常的问题 | ||
35 | + om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); | ||
36 | + om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); | ||
37 | + jackson2JsonRedisSerializer.setObjectMapper(om); | ||
38 | + // 配置序列化(解决乱码的问题) | ||
39 | + RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofMillis(-1)) | ||
40 | + .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer)) | ||
41 | + .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer)).disableCachingNullValues(); | ||
42 | + RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(factory); | ||
43 | + | ||
44 | + /* | ||
45 | + * return RedisConfigCacheManager.builder(factory).withInitialCacheConfigurations().transactionAware().build(); | ||
46 | + */ | ||
47 | + return new RedisConfigCacheManager(cacheWriter, config); | ||
48 | + } | ||
49 | +} | ||
0 | \ No newline at end of file | 50 | \ No newline at end of file |
huaheng-wms-core/src/main/java/org/jeecg/utils/HuahengShiroConfig.java renamed to huaheng-wms-core/src/main/java/org/jeecg/utils/config/HuahengShiroConfig.java
huaheng-wms-core/src/main/java/org/jeecg/utils/http/OkHttpUtils.java deleted
1 | -package org.jeecg.utils.http; | ||
2 | - | ||
3 | -import com.alibaba.fastjson.JSON; | ||
4 | -import com.alibaba.fastjson.TypeReference; | ||
5 | -import com.alibaba.fastjson.parser.Feature; | ||
6 | - | ||
7 | -import net.bytebuddy.asm.Advice.This; | ||
8 | -import okhttp3.*; | ||
9 | -import org.jeecg.modules.wms.framework.aspectj.ApiLogAspect; | ||
10 | -import org.jeecg.modules.wms.monitor.apiLog.entity.ApiLog; | ||
11 | -import org.slf4j.Logger; | ||
12 | -import org.slf4j.LoggerFactory; | ||
13 | - | ||
14 | -import java.io.IOException; | ||
15 | -import java.lang.reflect.Type; | ||
16 | -import java.util.HashMap; | ||
17 | -import java.util.Map; | ||
18 | -import java.util.Objects; | ||
19 | -import java.util.concurrent.TimeUnit; | ||
20 | - | ||
21 | -import javax.validation.constraints.NotNull; | ||
22 | - | ||
23 | -/** | ||
24 | - * OkHttp发送请求 | ||
25 | - * @author huaheng | ||
26 | - * @Date 2022-5-30 | ||
27 | - */ | ||
28 | -public class OkHttpUtils { | ||
29 | - | ||
30 | - private static final Logger log = LoggerFactory.getLogger(OkHttpUtils.class); | ||
31 | - | ||
32 | - /** | ||
33 | - * 最多重试次数 | ||
34 | - */ | ||
35 | - public final static int MAX_RENTRY_COUNT = 3; | ||
36 | - | ||
37 | - /** | ||
38 | - * 最大连接时间(秒) | ||
39 | - */ | ||
40 | - public final static int CONNECTION_TIMEOUT = 1; | ||
41 | - | ||
42 | - /** | ||
43 | - * 最大读取时间(秒) | ||
44 | - */ | ||
45 | - public final static int READ_TIMEOUT = 30; | ||
46 | - | ||
47 | - /** | ||
48 | - * 最大写入时间(秒) | ||
49 | - */ | ||
50 | - public final static int WRITE_TIMEOUT = 30; | ||
51 | - | ||
52 | - /** | ||
53 | - * JSON格式 | ||
54 | - */ | ||
55 | - public static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8"); | ||
56 | - /** | ||
57 | - * OkHTTP线程池最大空闲线程数 | ||
58 | - */ | ||
59 | - public final static int MAX_IDLE_CONNECTIONS = 100; | ||
60 | - /** | ||
61 | - * OkHTTP线程池空闲线程存活时间 | ||
62 | - */ | ||
63 | - public final static long KEEP_ALIVE_DURATION = 30L; | ||
64 | - | ||
65 | - private static final String CONTENT_TYPE = "Content-Type"; | ||
66 | - | ||
67 | - /** | ||
68 | - * client 配置重试 | ||
69 | - */ | ||
70 | - private final static OkHttpClient HTTP_CLIENT = | ||
71 | - new OkHttpClient.Builder().connectTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS).readTimeout(READ_TIMEOUT, TimeUnit.SECONDS) | ||
72 | - .writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS).addInterceptor(new OkHttpUtils.OkhttpInterceptor(MAX_RENTRY_COUNT)) // 过滤器,设置最大重试次数 | ||
73 | - .retryOnConnectionFailure(false).connectionPool(new ConnectionPool(MAX_IDLE_CONNECTIONS, KEEP_ALIVE_DURATION, TimeUnit.MINUTES)).build(); | ||
74 | - | ||
75 | - /** | ||
76 | - * 向指定 URL 发送GET方法的请求 | ||
77 | - * @param url 发送请求的 URL //* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 | ||
78 | - * @return 所代表远程资源的响应结果 | ||
79 | - */ | ||
80 | - public static String sendGet(String url, String param) { | ||
81 | - ApiLog apiLog = null; | ||
82 | - // headers 请求头 | ||
83 | - Map<String, String> headers = new HashMap<>(); | ||
84 | - // 请求URI | ||
85 | - String urlNameString = url + "?" + param; | ||
86 | - Request.Builder builder = new Request.Builder(); | ||
87 | - buildHeader(builder, headers); | ||
88 | - | ||
89 | - Request request = builder.url(urlNameString).get().build(); | ||
90 | - Response response = null; | ||
91 | - String result = null; | ||
92 | - try { | ||
93 | - apiLog = ApiLogAspect.initApiLog(request, param); | ||
94 | - response = HTTP_CLIENT.newCall(request).execute(); | ||
95 | - if (response.isSuccessful() && Objects.nonNull(response.body())) { | ||
96 | - result = response.body().string(); | ||
97 | - log.info("执行GET请求,url:{},header:{},param:{} 成功,返回结果:{}", url, JSON.toJSONString(headers), param, result); | ||
98 | - } | ||
99 | - } catch (IOException e) { | ||
100 | - log.error("执行GET请求,url:{},header:{},param:{} 失败!", url, JSON.toJSONString(headers), param, e); | ||
101 | - ApiLogAspect.setApiLogException(apiLog, e); | ||
102 | - } finally { | ||
103 | - ApiLogAspect.finishApiLog(apiLog, response, result); | ||
104 | - } | ||
105 | - return result; | ||
106 | - } | ||
107 | - | ||
108 | - /** | ||
109 | - * 向指定 URL 发送POST方法的请求 | ||
110 | - * @param url 发送请求的 URL | ||
111 | - * @param param 请求参数,请求参数是 name1=value1&name2=value2 的形式。 | ||
112 | - * @return 远程资源的响应结果 | ||
113 | - * @throws IOException | ||
114 | - */ | ||
115 | - public static String sendPost(String url, String param) { | ||
116 | - ApiLog apiLog = null; | ||
117 | - FormBody.Builder builder = new FormBody.Builder(); | ||
118 | - String urlNameString = url + "?" + param; | ||
119 | - FormBody body = builder.build(); | ||
120 | - Request request = new Request.Builder().url(urlNameString).post(body).build(); | ||
121 | - Response response = null; | ||
122 | - String result = null; | ||
123 | - try { | ||
124 | - apiLog = ApiLogAspect.initApiLog(request, param); | ||
125 | - response = HTTP_CLIENT.newCall(request).execute(); | ||
126 | - // 调用成功 | ||
127 | - if (response.isSuccessful() && response.body() != null) { | ||
128 | - result = response.body().string(); | ||
129 | - log.info("执行GET请求,url:{},param:{} 成功,返回结果:{}", url, param, result); | ||
130 | - } | ||
131 | - } catch (IOException e) { | ||
132 | - log.error("执行GET请求,url:{},param:{} 失败!", url, param, e); | ||
133 | - ApiLogAspect.setApiLogException(apiLog, e); | ||
134 | - } finally { | ||
135 | - ApiLogAspect.finishApiLog(apiLog, response, result); | ||
136 | - } | ||
137 | - return result; | ||
138 | - } | ||
139 | - | ||
140 | - /** JSONString形式发送POST请求 | ||
141 | - * @throws IOException */ | ||
142 | - public static String sendPostByJsonStr(String url, String json) { | ||
143 | - ApiLog apiLog = null; | ||
144 | - // using above json body as a input to post API call | ||
145 | - RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, json); | ||
146 | - // headers 请求头 | ||
147 | - Map<String, String> headers = new HashMap<>(); | ||
148 | - headers.put("Accept", "application/json");// 设置接收数据的格式 | ||
149 | - headers.put("Content-Type", "application/json");// 设置发送数据的格式 | ||
150 | - Request.Builder builder = new Request.Builder(); | ||
151 | - buildHeader(builder, headers); | ||
152 | - Request request = builder.url(url).post(body).build(); | ||
153 | - Response response = null; | ||
154 | - String result = null; | ||
155 | - try { | ||
156 | - apiLog = ApiLogAspect.initApiLog(request, json); | ||
157 | - response = HTTP_CLIENT.newCall(request).execute(); | ||
158 | - if (response.isSuccessful() && Objects.nonNull(response.body())) { | ||
159 | - result = response.body().string(); | ||
160 | - log.info("执行POST请求,url:{},header:{},param:{} 成功,返回结果:{}", url, JSON.toJSONString(headers), json, result); | ||
161 | - } | ||
162 | - } catch (IOException e) { | ||
163 | - log.error("执行POST请求,url:{},header:{},param:{} 失败!", url, JSON.toJSONString(headers), json, e); | ||
164 | - ApiLogAspect.setApiLogException(apiLog, e); | ||
165 | - } finally { | ||
166 | - ApiLogAspect.finishApiLog(apiLog, response, result); | ||
167 | - } | ||
168 | - return result; | ||
169 | - } | ||
170 | - | ||
171 | - /** | ||
172 | - * 设置请求头 | ||
173 | - * @param builder . | ||
174 | - * @param headers 请求头 | ||
175 | - */ | ||
176 | - private static void buildHeader(Request.Builder builder, Map<String, String> headers) { | ||
177 | - if (Objects.nonNull(headers) && headers.size() > 0) { | ||
178 | - headers.forEach((k, v) -> { | ||
179 | - if (Objects.nonNull(k) && Objects.nonNull(v)) { | ||
180 | - builder.addHeader(k, v); | ||
181 | - } | ||
182 | - }); | ||
183 | - } | ||
184 | - } | ||
185 | - | ||
186 | - /** | ||
187 | - * 支持嵌套泛型的POST请求 | ||
188 | - * @param url 链接 | ||
189 | - * @param json 请求json | ||
190 | - * @param type 嵌套泛型 | ||
191 | - * @return 响应对象, 可进行强转。 | ||
192 | - * @throws IOException | ||
193 | - */ | ||
194 | - public static <T> T sendPostByJsonStr(String url, String jsonString, TypeReference<T> type) throws IOException { | ||
195 | - String result = sendPostByJsonStr(url, jsonString); | ||
196 | - if (Objects.nonNull(result) && Objects.nonNull(type)) { | ||
197 | - return JSON.parseObject(result, type); | ||
198 | - } | ||
199 | - return null; | ||
200 | - } | ||
201 | - | ||
202 | - public static class OkhttpInterceptor implements Interceptor { | ||
203 | - // 最大重试次数 | ||
204 | - private int maxRentry; | ||
205 | - | ||
206 | - public OkhttpInterceptor(int maxRentry) { | ||
207 | - this.maxRentry = maxRentry; | ||
208 | - } | ||
209 | - | ||
210 | - @NotNull | ||
211 | - @Override | ||
212 | - public Response intercept(@NotNull Chain chain) throws IOException { | ||
213 | - /* | ||
214 | - * 递归 2次下发请求,如果仍然失败 则返回 null ,但是 intercept must not return null. 返回 null 会报 IllegalStateException 异常 | ||
215 | - */ | ||
216 | - return retry(chain, 0); | ||
217 | - } | ||
218 | - | ||
219 | - private Response retry(Chain chain, int retryCent) { | ||
220 | - Request request = chain.request(); | ||
221 | - Response response = null; | ||
222 | - try { | ||
223 | - response = chain.proceed(request); | ||
224 | - } catch (Exception e) { | ||
225 | - if (maxRentry > retryCent) { | ||
226 | - return retry(chain, retryCent + 1); | ||
227 | - } | ||
228 | - } | ||
229 | - return response; | ||
230 | - } | ||
231 | - } | ||
232 | - | ||
233 | -} |
huaheng-wms-core/src/main/java/org/jeecg/utils/CustomLogContextListener.java renamed to huaheng-wms-core/src/main/java/org/jeecg/utils/listener/CustomLogContextListener.java
huaheng-wms-core/src/main/java/org/jeecg/utils/manager/RedisConfigCacheManager.java
0 → 100644
1 | +package org.jeecg.utils.manager; | ||
2 | + | ||
3 | +import java.time.Duration; | ||
4 | +import java.util.Map; | ||
5 | + | ||
6 | +import org.apache.commons.lang3.StringUtils; | ||
7 | +import org.springframework.data.redis.cache.CacheKeyPrefix; | ||
8 | +import org.springframework.data.redis.cache.RedisCache; | ||
9 | +import org.springframework.data.redis.cache.RedisCacheConfiguration; | ||
10 | +import org.springframework.data.redis.cache.RedisCacheManager; | ||
11 | +import org.springframework.data.redis.cache.RedisCacheWriter; | ||
12 | +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; | ||
13 | +import org.springframework.data.redis.serializer.RedisSerializationContext; | ||
14 | + | ||
15 | +import lombok.extern.slf4j.Slf4j; | ||
16 | + | ||
17 | +/** | ||
18 | + * redis 配置类 | ||
19 | + */ | ||
20 | +@Slf4j | ||
21 | +public class RedisConfigCacheManager extends RedisCacheManager { | ||
22 | + | ||
23 | + public RedisConfigCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) { | ||
24 | + super(cacheWriter, defaultCacheConfiguration); | ||
25 | + } | ||
26 | + | ||
27 | + public RedisConfigCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, String... initialCacheNames) { | ||
28 | + super(cacheWriter, defaultCacheConfiguration, initialCacheNames); | ||
29 | + } | ||
30 | + | ||
31 | + public RedisConfigCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, boolean allowInFlightCacheCreation, | ||
32 | + String... initialCacheNames) { | ||
33 | + super(cacheWriter, defaultCacheConfiguration, allowInFlightCacheCreation, initialCacheNames); | ||
34 | + } | ||
35 | + | ||
36 | + public RedisConfigCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, | ||
37 | + Map<String, RedisCacheConfiguration> initialCacheConfigurations) { | ||
38 | + super(cacheWriter, defaultCacheConfiguration, initialCacheConfigurations); | ||
39 | + } | ||
40 | + | ||
41 | + public RedisConfigCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, | ||
42 | + Map<String, RedisCacheConfiguration> initialCacheConfigurations, boolean allowInFlightCacheCreation) { | ||
43 | + super(cacheWriter, defaultCacheConfiguration, initialCacheConfigurations, allowInFlightCacheCreation); | ||
44 | + } | ||
45 | + | ||
46 | + private static final RedisSerializationContext.SerializationPair<Object> DEFAULT_PAIR = | ||
47 | + RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()); | ||
48 | + | ||
49 | + private static final CacheKeyPrefix DEFAULT_CACHE_KEY_PREFIX = cacheName -> cacheName + ":"; | ||
50 | + | ||
51 | + @Override | ||
52 | + protected RedisCache createRedisCache(String name, RedisCacheConfiguration cacheConfig) { | ||
53 | + final int lastIndexOf = StringUtils.lastIndexOf(name, '#'); | ||
54 | + if (lastIndexOf > -1) { | ||
55 | + final String ttl = StringUtils.substring(name, lastIndexOf + 1); | ||
56 | + final Duration duration = Duration.ofSeconds(Long.parseLong(ttl)); | ||
57 | + cacheConfig = cacheConfig.entryTtl(duration); | ||
58 | + // 修改缓存key和value值的序列化方式 | ||
59 | + cacheConfig = cacheConfig.computePrefixWith(DEFAULT_CACHE_KEY_PREFIX).serializeValuesWith(DEFAULT_PAIR); | ||
60 | + final String cacheName = StringUtils.substring(name, 0, lastIndexOf); | ||
61 | + return super.createRedisCache(cacheName, cacheConfig); | ||
62 | + } else { | ||
63 | + // 修改缓存key和value值的序列化方式 | ||
64 | + cacheConfig = cacheConfig.computePrefixWith(DEFAULT_CACHE_KEY_PREFIX).serializeValuesWith(DEFAULT_PAIR); | ||
65 | + return super.createRedisCache(name, cacheConfig); | ||
66 | + } | ||
67 | + // throw new RuntimeException("字符串中必须包含#号,#号后为过期时间, -1为永不过期"); | ||
68 | + } | ||
69 | +} | ||
0 | \ No newline at end of file | 70 | \ No newline at end of file |
huaheng-wms-core/src/main/java/org/jeecg/utils/RedissonDistributedLocker.java renamed to huaheng-wms-core/src/main/java/org/jeecg/utils/support/RedissonDistributedLocker.java
huaheng-wms-core/src/main/java/org/jeecg/utils/support/StrFormatter.java deleted
1 | -package org.jeecg.utils.support; | ||
2 | - | ||
3 | -import org.jeecg.utils.StringUtils; | ||
4 | - | ||
5 | -/** | ||
6 | - * 字符串格式化 | ||
7 | - * @author huaheng | ||
8 | - */ | ||
9 | -public class StrFormatter { | ||
10 | - | ||
11 | - public static final String EMPTY_JSON = "{}"; | ||
12 | - public static final char C_BACKSLASH = '\\'; | ||
13 | - public static final char C_DELIM_START = '{'; | ||
14 | - public static final char C_DELIM_END = '}'; | ||
15 | - | ||
16 | - /** | ||
17 | - * 格式化字符串<br> | ||
18 | - * 此方法只是简单将占位符 {} 按照顺序替换为参数<br> | ||
19 | - * 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可<br> | ||
20 | - * 例:<br> | ||
21 | - * 通常使用:format("this is {} for {}", "a", "b") -> this is a for b<br> | ||
22 | - * 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a<br> | ||
23 | - * 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br> | ||
24 | - * @param strPattern 字符串模板 | ||
25 | - * @param argArray 参数列表 | ||
26 | - * @return 结果 | ||
27 | - */ | ||
28 | - public static String format(final String strPattern, final Object... argArray) { | ||
29 | - if (StringUtils.isEmpty(strPattern) || StringUtils.isEmpty(argArray)) { | ||
30 | - return strPattern; | ||
31 | - } | ||
32 | - final int strPatternLength = strPattern.length(); | ||
33 | - | ||
34 | - // 初始化定义好的长度以获得更好的性能 | ||
35 | - StringBuilder sbuf = new StringBuilder(strPatternLength + 50); | ||
36 | - | ||
37 | - int handledPosition = 0; | ||
38 | - int delimIndex;// 占位符所在位置 | ||
39 | - for (int argIndex = 0; argIndex < argArray.length; argIndex++) { | ||
40 | - delimIndex = strPattern.indexOf(EMPTY_JSON, handledPosition); | ||
41 | - if (delimIndex == -1) { | ||
42 | - if (handledPosition == 0) { | ||
43 | - return strPattern; | ||
44 | - } else { // 字符串模板剩余部分不再包含占位符,加入剩余部分后返回结果 | ||
45 | - sbuf.append(strPattern, handledPosition, strPatternLength); | ||
46 | - return sbuf.toString(); | ||
47 | - } | ||
48 | - } else { | ||
49 | - if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == C_BACKSLASH) { | ||
50 | - if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == C_BACKSLASH) { | ||
51 | - // 转义符之前还有一个转义符,占位符依旧有效 | ||
52 | - sbuf.append(strPattern, handledPosition, delimIndex - 1); | ||
53 | - sbuf.append(Convert.utf8Str(argArray[argIndex])); | ||
54 | - handledPosition = delimIndex + 2; | ||
55 | - } else { | ||
56 | - // 占位符被转义 | ||
57 | - argIndex--; | ||
58 | - sbuf.append(strPattern, handledPosition, delimIndex - 1); | ||
59 | - sbuf.append(C_DELIM_START); | ||
60 | - handledPosition = delimIndex + 1; | ||
61 | - } | ||
62 | - } else { | ||
63 | - // 正常占位符 | ||
64 | - sbuf.append(strPattern, handledPosition, delimIndex); | ||
65 | - sbuf.append(Convert.utf8Str(argArray[argIndex])); | ||
66 | - handledPosition = delimIndex + 2; | ||
67 | - } | ||
68 | - } | ||
69 | - } | ||
70 | - // append the characters following the last {} pair. | ||
71 | - // 加入最后一个占位符后所有的字符 | ||
72 | - sbuf.append(strPattern, handledPosition, strPattern.length()); | ||
73 | - | ||
74 | - return sbuf.toString(); | ||
75 | - } | ||
76 | - | ||
77 | -} |
huaheng-wms-core/src/main/resources/application-dev.yml
@@ -276,6 +276,7 @@ logging: | @@ -276,6 +276,7 @@ logging: | ||
276 | org.jeecg.common: WARN | 276 | org.jeecg.common: WARN |
277 | org.jeecg.modules: WARN | 277 | org.jeecg.modules: WARN |
278 | org.jeecg.modules.wms: DEBUG | 278 | org.jeecg.modules.wms: DEBUG |
279 | + org.jeecg.config.shiro: INFO | ||
279 | #swagger | 280 | #swagger |
280 | knife4j: | 281 | knife4j: |
281 | #开启增强配置 | 282 | #开启增强配置 |
huaheng-wms-core/src/main/resources/application-prod.yml
@@ -265,6 +265,7 @@ logging: | @@ -265,6 +265,7 @@ logging: | ||
265 | org.jeecg.common: WARN | 265 | org.jeecg.common: WARN |
266 | org.jeecg.modules: WARN | 266 | org.jeecg.modules: WARN |
267 | org.jeecg.modules.wms: DEBUG | 267 | org.jeecg.modules.wms: DEBUG |
268 | + org.jeecg.config.shiro: INFO | ||
268 | #swagger | 269 | #swagger |
269 | knife4j: | 270 | knife4j: |
270 | #开启增强配置 | 271 | #开启增强配置 |
huaheng-wms-core/src/main/resources/application.yml
huaheng-wms-core/src/main/resources/logback-spring.xml
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | <configuration debug="false"> | 2 | <configuration debug="false"> |
3 | 3 | ||
4 | <!-- 监听器,指定日志文件存放目录 --> | 4 | <!-- 监听器,指定日志文件存放目录 --> |
5 | - <contextListener class="org.jeecg.utils.CustomLogContextListener" /> | 5 | + <contextListener class="org.jeecg.utils.listener.CustomLogContextListener" /> |
6 | 6 | ||
7 | <!--定义日志文件的存储地址 --> | 7 | <!--定义日志文件的存储地址 --> |
8 | <property name="LOG_HOME" value="${LOG_PATH}/logs" /> | 8 | <property name="LOG_HOME" value="${LOG_PATH}/logs" /> |