余料库逻辑修改,柜体删除修改1

This commit is contained in:
lym
2024-06-28 18:53:52 +08:00
18 changed files with 199 additions and 44 deletions
@@ -3,7 +3,7 @@
spring: spring:
cloud: cloud:
nacos: nacos:
server-addr: 127.0.0.1:8848 server-addr: 192.168.1.205:8848
username: nacos username: nacos
password: nacos password: nacos
discovery: discovery:
@@ -18,7 +18,7 @@ spring:
nacos: nacos:
# Nacos Config 配置项,对应 NacosConfigProperties 配置属性类 # Nacos Config 配置项,对应 NacosConfigProperties 配置属性类
config: config:
server-addr: 127.0.0.1:8848 # Nacos 服务器地址 server-addr: 192.168.1.205:8848 # Nacos 服务器地址
namespace: dev # 命名空间 dev 的ID,不能直接使用 dev 名称。创建命名空间的时候需要指定ID为 dev,这里使用 dev 开发环境 namespace: dev # 命名空间 dev 的ID,不能直接使用 dev 名称。创建命名空间的时候需要指定ID为 dev,这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
name: ${spring.application.name} # 使用的 Nacos 配置集的 dataId,默认为 spring.application.name name: ${spring.application.name} # 使用的 Nacos 配置集的 dataId,默认为 spring.application.name
@@ -0,0 +1,25 @@
package com.cf.imes.module.executor.controller.admin.plan.bo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class GoodsIds {
@Schema(description = "大板ID")
private Long id;
@Schema(description = "生产单ID")
private Long orderId;
@Schema(description = "板材库的大板ID")
private Long goodsId;
@Schema(description = "余料板ID")
private Long remainId;
}
@@ -16,6 +16,8 @@ import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
/** /**
@@ -40,6 +42,11 @@ public class OrderSource {
@Schema(description = "排单数据") @Schema(description = "排单数据")
private PlanDO plan; private PlanDO plan;
@Schema(description = "大板ID列表")
private List<GoodsIds> goodsIdList;
@Schema(description = "生产单列表") @Schema(description = "生产单列表")
private List<OrderDO> orderList; private List<OrderDO> orderList;
@@ -61,4 +68,6 @@ public class OrderSource {
private List<PrintOrderPackReqVO> orderPackReqVOS; private List<PrintOrderPackReqVO> orderPackReqVOS;
} }
@@ -32,8 +32,8 @@ public class OrderPageReqVOCopy extends PageParam {
private String consigneeAddress; private String consigneeAddress;
@Schema(description = "状态列表") @Schema(description = "状态列表")
private List<Integer> stateList; private List<Integer> stateList;
/*@Schema(description = "矩形") @Schema(description = "矩形")
private Boolean rectangle;*/ private Boolean rectangle;
@Schema(description = "异形") @Schema(description = "异形")
private Boolean specialShaped; private Boolean specialShaped;
@Schema(description = "造型") @Schema(description = "造型")
@@ -52,6 +52,9 @@ public class PlanSaveReqVO {
@Schema(description = "生产单id与商品id 列表",requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "生产单id与商品id 列表",requiredMode = Schema.RequiredMode.REQUIRED)
private List<Item> itemList; private List<Item> itemList;
@Schema(description = "商品数量")
private Long goodsNum;
@Schema(description = "备注") @Schema(description = "备注")
private String remark; private String remark;
@@ -15,7 +15,7 @@ public class PlatePage {
@Schema(description = "生产单id") @Schema(description = "生产单id")
private Long orderId; private Long orderId;
@Schema(description = "商品id") @Schema(description = "商品id")
private String goodsId; private Long goodsId;
@Schema(description = "板名称") @Schema(description = "板名称")
private String name; private String name;
@Schema(description = "商品名称") @Schema(description = "商品名称")
@@ -336,6 +336,7 @@
select distinct b.id as orderId, select distinct b.id as orderId,
c.id as goodsId,
c.width, c.width,
c.height, c.height,
c.thickness, c.thickness,
@@ -359,7 +360,7 @@
#{orderIds} #{orderIds}
</foreach> </foreach>
group by b.id ,c.goods_name,c.width,c.height,c.thickness, c.material, c.color; group by c.id,b.id ,c.goods_name,c.width,c.height,c.thickness, c.material, c.color;
@@ -75,7 +75,7 @@ public class PlateDetailsRespVO {
@Schema(description = "排孔", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "排孔", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("排孔") @ExcelProperty("排孔")
private String rowHole; private Boolean rowHole;
@Schema(description = "加工组", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "加工组", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("加工组") @ExcelProperty("加工组")
@@ -14,6 +14,10 @@ public class PackageDetailsRespVO {
@Schema(description = "柜体名称", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "柜体名称", requiredMode = Schema.RequiredMode.REQUIRED)
private String cabinetName; private String cabinetName;
@Schema(description = "板材ID", requiredMode = Schema.RequiredMode.REQUIRED)
private String plateId;
@Schema(description = "板编号", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "板编号", requiredMode = Schema.RequiredMode.REQUIRED)
private String plateNo; private String plateNo;
@@ -22,8 +22,8 @@ public interface RemainPlateMapper extends BaseMapperX<RemainPlateDO> {
default PageResult<RemainPlateDO> selectPage(RemainPlatePageReqVO reqVO) { default PageResult<RemainPlateDO> selectPage(RemainPlatePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<RemainPlateDO>() return selectPage(reqVO, new LambdaQueryWrapperX<RemainPlateDO>()
.eqIfPresent(RemainPlateDO::getId, reqVO.getId()) .likeIfPresent(RemainPlateDO::getId,reqVO.getId() != null ? reqVO.getId().toString() : null)
.eqIfPresent(RemainPlateDO::getPlanId, reqVO.getPlanId()) .eqIfPresent(RemainPlateDO::getPlanId, reqVO.getPlanId() != null ? reqVO.getPlanId().toString() : null)
.eqIfPresent(RemainPlateDO::getInitPlanId, reqVO.getInitPlanId()) .eqIfPresent(RemainPlateDO::getInitPlanId, reqVO.getInitPlanId())
.eqIfPresent(RemainPlateDO::getStatus, reqVO.getStatus()) .eqIfPresent(RemainPlateDO::getStatus, reqVO.getStatus())
.eqIfPresent(RemainPlateDO::getGoodsId, reqVO.getGoodsId()) .eqIfPresent(RemainPlateDO::getGoodsId, reqVO.getGoodsId())
@@ -6,7 +6,8 @@
<resultMap id="orderItemMap" type="com.cf.imes.module.manage.controller.admin.query.vo.pack.PackageDetailsRespVO"> <resultMap id="orderItemMap" type="com.cf.imes.module.manage.controller.admin.query.vo.pack.PackageDetailsRespVO">
<result property="roomName" column="roomName"/> <result property="roomName" column="roomName"/>
<result property="cabinetName" column="bodyName"/> <result property="cabinetName" column="bodyName"/>
<result property="plateNo" column="palteId"/> <result property="plateId" column="plateId"/>
<result property="plateNo" column="plateNo"/>
<result property="plateName" column="plateName"/> <result property="plateName" column="plateName"/>
<result property="material" column="plateMaterial"/> <result property="material" column="plateMaterial"/>
<result property="color" column="palteColor"/> <result property="color" column="palteColor"/>
@@ -32,7 +33,8 @@
og.name as name, og.name as name,
ob.room_name as roomName, ob.room_name as roomName,
ob.name as bodyName, ob.name as bodyName,
op.id as palteId, op.plate_no as plateNo,
op.id as plateId,
op.name as plateName, op.name as plateName,
ogs.material as plateMaterial, ogs.material as plateMaterial,
ogs.color as palteColor, ogs.color as palteColor,
@@ -44,8 +46,7 @@
op.remark as remark, op.remark as remark,
op.is_special_shaped as specialShaped, op.is_special_shaped as specialShaped,
op.is_sculpt as profiling, op.is_sculpt as profiling,
op.is_row_hole as rowHole
CASE WHEN op.front_hole_count = 0 or op.back_model_count = 0 or op.side_hole_count = 0 THEN false ELSE true END AS rowHole
from order_item oi from order_item oi
join order_plate op on oi.plate_id = op.id and oi.organ_id = op.organ_id join order_plate op on oi.plate_id = op.id and oi.organ_id = op.organ_id
@@ -150,8 +151,7 @@
op.remark as remark, op.remark as remark,
op.is_special_shaped as specialShaped, op.is_special_shaped as specialShaped,
op.is_sculpt as profiling, op.is_sculpt as profiling,
op.is_row_hole as rowHole
CASE WHEN op.front_hole_count = 0 or op.back_model_count = 0 or op.side_hole_count = 0 THEN false ELSE true END AS rowHole
from order_item oi from order_item oi
join order_plate op on oi.plate_id = op.id and oi.organ_id = op.organ_id join order_plate op on oi.plate_id = op.id and oi.organ_id = op.organ_id
@@ -433,8 +433,7 @@
op.remark as remark, op.remark as remark,
op.is_special_shaped as specialShaped, op.is_special_shaped as specialShaped,
op.is_sculpt as profiling, op.is_sculpt as profiling,
op.is_row_hole as rowHole
CASE WHEN op.front_hole_count = 0 or op.back_model_count = 0 or op.side_hole_count = 0 THEN false ELSE true END AS rowHole
from order_item oi from order_item oi
join order_plate op on oi.plate_id = op.id and oi.organ_id = op.organ_id join order_plate op on oi.plate_id = op.id and oi.organ_id = op.organ_id
@@ -31,7 +31,8 @@ public class ProcessApiImpl implements ProcessApi {
ProcessDO processDO = processMapper.selectByType(ProcessProcessingTypeEnum.COMPONENTPROCESSING.getNumber(),getUserOrganId()); ProcessDO processDO = processMapper.selectByType(ProcessProcessingTypeEnum.COMPONENTPROCESSING.getNumber(),getUserOrganId());
return processDO.getPieceRate();
return processDO == null ? BigDecimal.ZERO : processDO.getPieceRate();
} }
@@ -37,7 +37,7 @@ public class LabelController {
@PostMapping("/create") @PostMapping("/create")
@Operation(summary = "创建标签") @Operation(summary = "创建标签")
//@PreAuthorize("@ss.hasPermission('system:label:create')") @PreAuthorize("@ss.hasPermission('sysTagDesignManager:create')")
@OperateLog(enable = false) @OperateLog(enable = false)
public CommonResult<Long> createLabel(@Valid @RequestBody LabelSaveReqVO createReqVO) { public CommonResult<Long> createLabel(@Valid @RequestBody LabelSaveReqVO createReqVO) {
return success(labelService.createLabel(createReqVO)); return success(labelService.createLabel(createReqVO));
@@ -45,7 +45,7 @@ public class LabelController {
@PutMapping("/update") @PutMapping("/update")
@Operation(summary = "更新标签") @Operation(summary = "更新标签")
//@PreAuthorize("@ss.hasPermission('system:label:update')") @PreAuthorize("@ss.hasPermission('sysTagDesignManager:update')")
@OperateLog(enable = false) @OperateLog(enable = false)
public CommonResult<Boolean> updateLabel(@Valid @RequestBody LabelSaveReqVO updateReqVO) { public CommonResult<Boolean> updateLabel(@Valid @RequestBody LabelSaveReqVO updateReqVO) {
labelService.updateLabel(updateReqVO); labelService.updateLabel(updateReqVO);
@@ -55,7 +55,7 @@ public class LabelController {
@DeleteMapping("/delete") @DeleteMapping("/delete")
@Operation(summary = "删除标签") @Operation(summary = "删除标签")
@Parameter(name = "id", description = "编号", required = true) @Parameter(name = "id", description = "编号", required = true)
//@PreAuthorize("@ss.hasPermission('system:label:delete')") @PreAuthorize("@ss.hasPermission('sysTagDesignManager:delete')")
public CommonResult<Boolean> deleteLabel(@RequestParam("id") Long id) { public CommonResult<Boolean> deleteLabel(@RequestParam("id") Long id) {
labelService.deleteLabel(id); labelService.deleteLabel(id);
return success(true); return success(true);
@@ -90,7 +90,7 @@ public class LabelController {
@GetMapping("/group-list") @GetMapping("/group-list")
@Operation(summary = "获得分组标签列表") @Operation(summary = "获得分组标签列表")
//@PreAuthorize("@ss.hasPermission('system:label:query')") @PreAuthorize("@ss.hasAnyPermissions('system:label-template:query','sysTagDesignManager:query')")
@OperateLog(enable = false) @OperateLog(enable = false)
public CommonResult<Map<String, List<LabelRespVO>>> getGroupList(@RequestParam(value = "organId", required = false) Long organId) { public CommonResult<Map<String, List<LabelRespVO>>> getGroupList(@RequestParam(value = "organId", required = false) Long organId) {
return success(labelService.getGroupList(organId)); return success(labelService.getGroupList(organId));
@@ -87,7 +87,7 @@ public class LabelTemplateController {
@GetMapping("/getDefault") @GetMapping("/getDefault")
@Operation(summary = "获得默认标签模板") @Operation(summary = "获得默认标签模板")
@Parameter(name = "type", description = "标签类型", required = true, example = "1024") @Parameter(name = "type", description = "标签类型", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('system:label-template:query')") @PreAuthorize("@ss.hasAnyPermissions('system:label-template:query','sysTagDesignManager:query')")
@OperateLog(enable = false) @OperateLog(enable = false)
public CommonResult<LabelTemplateRespVO> getDefaultLabelTemplate(@RequestParam("type") String type) { public CommonResult<LabelTemplateRespVO> getDefaultLabelTemplate(@RequestParam("type") String type) {
return success(labelTemplateService.getDefaultLabelTemplate(type)); return success(labelTemplateService.getDefaultLabelTemplate(type));
@@ -17,10 +17,10 @@ public class UserSaveReqVO {
@Schema(description = "用户编号", example = "1024") @Schema(description = "用户编号", example = "1024")
private Long id; private Long id;
@Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "chenfeng") @Schema(description = "a", requiredMode = Schema.RequiredMode.REQUIRED, example = "chenfeng")
@NotBlank(message = "用户账号不能为空") @NotBlank(message = "用户不能为空")
@Pattern(regexp = "^[a-zA-Z0-9]{4,30}$", message = "用户账号由 数字、字母 组成") @Pattern(regexp = "^[a-zA-Z0-9]{4,30}$", message = "用户由 数字、字母 组成")
@Size(min = 4, max = 30, message = "用户账号长度为 4-30 个字符") @Size(min = 4, max = 30, message = "用户长度为 4-30 个字符")
private String username; private String username;
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "晨丰") @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "晨丰")
@@ -1,6 +1,8 @@
package com.cf.imes.module.system.service.permission; package com.cf.imes.module.system.service.permission;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.framework.common.util.object.BeanUtils; import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.framework.organ.core.aop.OrganIgnore; import com.cf.imes.framework.organ.core.aop.OrganIgnore;
import com.cf.imes.module.system.controller.admin.permission.vo.menu.MenuListReqVO; import com.cf.imes.module.system.controller.admin.permission.vo.menu.MenuListReqVO;
@@ -8,13 +10,18 @@ import com.cf.imes.module.system.controller.admin.permission.vo.menu.MenuSaveVO;
import com.cf.imes.module.system.dal.dataobject.permission.MenuDO; import com.cf.imes.module.system.dal.dataobject.permission.MenuDO;
import com.cf.imes.module.system.dal.mysql.permission.MenuMapper; import com.cf.imes.module.system.dal.mysql.permission.MenuMapper;
import com.cf.imes.module.system.dal.redis.RedisKeyConstants; import com.cf.imes.module.system.dal.redis.RedisKeyConstants;
import com.cf.imes.module.system.dal.redis.RedisRefreshChannelTopicConstants;
import com.cf.imes.module.system.enums.permission.MenuTypeEnum; import com.cf.imes.module.system.enums.permission.MenuTypeEnum;
import com.cf.imes.module.system.service.organ.OrganService; import com.cf.imes.module.system.service.organ.OrganService;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -22,6 +29,7 @@ import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception; import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.framework.common.util.collection.CollectionUtils.convertList; import static com.cf.imes.framework.common.util.collection.CollectionUtils.convertList;
@@ -44,6 +52,9 @@ public class MenuServiceImpl implements MenuService {
@Lazy // 延迟,避免循环依赖报错 @Lazy // 延迟,避免循环依赖报错
private OrganService organService; private OrganService organService;
@Autowired
private RedisTemplate redisTemplate;
@Override @Override
@CacheEvict(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST, key = "#createReqVO.permission", @CacheEvict(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST, key = "#createReqVO.permission",
condition = "#createReqVO.permission != null") condition = "#createReqVO.permission != null")
@@ -57,8 +68,13 @@ public class MenuServiceImpl implements MenuService {
MenuDO menu = BeanUtils.toBean(createReqVO, MenuDO.class); MenuDO menu = BeanUtils.toBean(createReqVO, MenuDO.class);
initMenuProperty(menu); initMenuProperty(menu);
menuMapper.insert(menu); menuMapper.insert(menu);
Long menuId = menu.getId();
// 清理缓存
flushCacheWhenOperateMenu(menuId, createReqVO.getPermission(), null);
// 返回 // 返回
return menu.getId(); return menuId;
} }
@Override @Override
@@ -66,7 +82,8 @@ public class MenuServiceImpl implements MenuService {
allEntries = true) // allEntries 清空所有缓存,因为 permission 如果变更,涉及到新老两个 permission。直接清理,简单有效 allEntries = true) // allEntries 清空所有缓存,因为 permission 如果变更,涉及到新老两个 permission。直接清理,简单有效
public void updateMenu(MenuSaveVO updateReqVO) { public void updateMenu(MenuSaveVO updateReqVO) {
// 校验更新的菜单是否存在 // 校验更新的菜单是否存在
if (menuMapper.selectById(updateReqVO.getId()) == null) { MenuDO menuDO = menuMapper.selectById(updateReqVO.getId());
if (menuDO == null) {
throw exception(MENU_NOT_EXISTS); throw exception(MENU_NOT_EXISTS);
} }
// 校验父菜单存在 // 校验父菜单存在
@@ -78,6 +95,13 @@ public class MenuServiceImpl implements MenuService {
MenuDO updateObj = BeanUtils.toBean(updateReqVO, MenuDO.class); MenuDO updateObj = BeanUtils.toBean(updateReqVO, MenuDO.class);
initMenuProperty(updateObj); initMenuProperty(updateObj);
menuMapper.updateById(updateObj); menuMapper.updateById(updateObj);
// 权限串发生改变清空缓存
String oldPermission = menuDO.getPermission();
String newPermission = updateReqVO.getPermission();
if (ObjectUtil.notEqual(oldPermission, newPermission)) {
flushCacheWhenOperateMenu(menuDO.getId(), newPermission, oldPermission);
}
} }
@Override @Override
@@ -90,13 +114,76 @@ public class MenuServiceImpl implements MenuService {
throw exception(MENU_EXISTS_CHILDREN); throw exception(MENU_EXISTS_CHILDREN);
} }
// 校验删除的菜单是否存在 // 校验删除的菜单是否存在
if (menuMapper.selectById(id) == null) { MenuDO menuDO = menuMapper.selectById(id);
if (menuDO == null) {
throw exception(MENU_NOT_EXISTS); throw exception(MENU_NOT_EXISTS);
} }
// 标记删除 // 标记删除
menuMapper.deleteById(id); menuMapper.deleteById(id);
// 删除授予给角色的权限 // 删除授予给角色的权限
permissionService.processMenuDeleted(id); permissionService.processMenuDeleted(id);
// 清理缓存
flushCacheWhenOperateMenu(id, null, menuDO.getPermission());
}
/**
* 菜单增删改时清理缓存
*
* @param menuId 菜单id
* @param newPermission 新权限串
* @param oldPermission 旧权限串
*/
private void flushCacheWhenOperateMenu(Long menuId, String newPermission, String oldPermission) {
CompletableFuture.runAsync(() -> {
if (ObjectUtil.isNotNull(oldPermission)) {
// 移除 USER_ROLE_ID_LIST:*:旧的permission
String oldMenuPerPattern = String.format(String.valueOf(new StringBuffer(RedisKeyConstants.PERMISSION_MENU_ID_LIST).append(":*:%s")), oldPermission);
Long oldBatchDelPerNum = scanAndDelKeys(oldMenuPerPattern);
log.info("[updateMenu] 批量删除redis[{}]数量:{}", oldMenuPerPattern, oldBatchDelPerNum);
}
if (ObjectUtil.isNotNull(newPermission)) {
// 移除 USER_ROLE_ID_LIST:*:新的permission
String newMenuPerPattern = String.format(String.valueOf(new StringBuffer(RedisKeyConstants.PERMISSION_MENU_ID_LIST).append(":*:%s")), newPermission);
Long newBatchDelPerNum = scanAndDelKeys(newMenuPerPattern);
log.info("[updateMenu] 批量删除redis[{}]数量:{}", newMenuPerPattern, newBatchDelPerNum);
}
if (ObjectUtil.isNotNull(menuId)) {
// 移除 MENU_ROLE_ID_LIST:*:menuId
String menuRolePattern = String.format(String.valueOf(new StringBuffer(RedisKeyConstants.MENU_ROLE_ID_LIST).append(":*:%s")), menuId);
Long batchDelRoleNum = scanAndDelKeys(menuRolePattern);
log.info("[deleteMenu] 批量删除redis[{}]数量:{}", menuRolePattern, batchDelRoleNum);
}
// 清空本地缓存
redisTemplate.convertAndSend(RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, "");
}).exceptionally(e -> {
log.error("[deleteMenu] redis 清空PERMISSION_MENU_ID_LIST或message发送失败, topic:{}, 异常:{}", RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, e);
return null;
});
}
/**
* scan所有匹配的redis key并删除
*
* @param keyPattern 模糊匹配的表达式
*/
private Long scanAndDelKeys(String keyPattern) {
// 根据keyPattern scan匹配的redis key
List<String> delKeys = new ArrayList<>();
Cursor<String> cursor = redisTemplate.scan(ScanOptions.scanOptions().match(keyPattern).count(200).build());
while (cursor.hasNext()) {
delKeys.add(cursor.next());
}
cursor.close();
// 删除匹配到的key
if (CollectionUtil.isNotEmpty(delKeys)) {
return redisTemplate.delete(delKeys);
}
return 0L;
} }
@Override @Override
@@ -39,7 +39,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching; import org.springframework.cache.annotation.Caching;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -205,23 +207,44 @@ public class PermissionServiceImpl implements PermissionService {
// 角色菜单权限发生修改,通知刷新本地缓存 // 角色菜单权限发生修改,通知刷新本地缓存
if (CollectionUtil.isNotEmpty(createMenuIds) || CollectionUtil.isNotEmpty(deleteMenuIds)) { if (CollectionUtil.isNotEmpty(createMenuIds) || CollectionUtil.isNotEmpty(deleteMenuIds)) {
CompletableFuture.runAsync(() -> { CompletableFuture.runAsync(() -> {
// 当前操作人和所操作的目标菜单机构不同时,清空MENU_ROLE_ID_LIST:目标机构id:菜单id的缓存 // 当前操作人和所操作的目标菜单机构不同时,清空MENU_ROLE_ID_LIST:*:菜单id的缓存
if (ObjectUtil.notEqual(finalOrganId, currentOrganId)) { if (ObjectUtil.notEqual(finalOrganId, currentOrganId)) {
// 获取新增和删除菜单id的并集 // 获取新增和删除菜单id的并集
Collection<Long> delMenuIds = CollUtil.union(createMenuIds, deleteMenuIds); Collection<Long> delMenuIds = CollUtil.union(createMenuIds, deleteMenuIds);
// 构建批量删除的key集合 delMenuIds.forEach(delMenuId -> {
Set<String> delKeys = delMenuIds.stream().map(menuId -> String.format(String.valueOf(new StringBuffer(RedisKeyConstants.MENU_ROLE_ID_LIST).append(":%s:%s")), finalOrganId, menuId)).collect(Collectors.toSet()); String patternKey = String.format(String.valueOf(new StringBuffer(RedisKeyConstants.MENU_ROLE_ID_LIST).append(":*:%s")), delMenuId);
Long batchDelNum = redisTemplate.delete(delKeys); Long batchDelNum = scanAndDelKeys(patternKey);
log.info("[assignRoleMenu] 批量删除redis[MENU_ROLE_ID_LIST]数量:{}", batchDelNum); log.info("[assignRoleMenu] 批量删除redis[{}]数量:{}", patternKey, batchDelNum);
});
} }
redisTemplate.convertAndSend(RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, ""); redisTemplate.convertAndSend(RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, "");
}).exceptionally(e -> { }).exceptionally(e -> {
log.error("[assignRoleMenu] redis message发送失败, topic:{}, 异常:{}", RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, e); log.error("[assignRoleMenu] redis 清空MENU_ROLE_ID_LIST或message发送失败, topic:{}, 异常:{}", RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, e);
return null; return null;
}); });
} }
} }
/**
* scan所有匹配的redis key并删除
*
* @param keyPattern 模糊匹配的表达式
*/
private Long scanAndDelKeys(String keyPattern) {
// 根据keyPattern scan匹配的redis key
List<String> delKeys = new ArrayList<>();
Cursor<String> cursor = redisTemplate.scan(ScanOptions.scanOptions().match(keyPattern).count(200).build());
while (cursor.hasNext()) {
delKeys.add(cursor.next());
}
cursor.close();
// 删除匹配到的key
if (CollectionUtil.isNotEmpty(delKeys)) {
return redisTemplate.delete(delKeys);
}
return 0L;
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Caching(evict = { @Caching(evict = {
@@ -362,18 +385,19 @@ public class PermissionServiceImpl implements PermissionService {
// 角色菜单权限发生修改,通知刷新本地缓存 // 角色菜单权限发生修改,通知刷新本地缓存
if (CollectionUtil.isNotEmpty(createRoleUserIds) || CollectionUtil.isNotEmpty(deleteRoleUserIds)) { if (CollectionUtil.isNotEmpty(createRoleUserIds) || CollectionUtil.isNotEmpty(deleteRoleUserIds)) {
CompletableFuture.runAsync(() -> { CompletableFuture.runAsync(() -> {
// 当前操作人和所操作的目标菜单机构不同时,清空USER_ROLE_ID_LIST:目标机构id:用户id的缓存 // 当前操作人和所操作的目标菜单机构不同时,清空USER_ROLE_ID_LIST:*:用户id的缓存
if (ObjectUtil.notEqual(finalOrganId, currentOrganId)) { if (ObjectUtil.notEqual(finalOrganId, currentOrganId)) {
// 获取新增和删除用户id的并集 // 获取新增和删除用户id的并集
Collection<Long> delRoleUserIds = CollUtil.union(createRoleUserIds, deleteRoleUserIds); Collection<Long> delRoleUserIds = CollUtil.union(createRoleUserIds, deleteRoleUserIds);
// 构建批量删除的key集合 delRoleUserIds.forEach(delRoleUserId -> {
Set<String> delKeys = delRoleUserIds.stream().map(userId -> String.format(String.valueOf(new StringBuffer(RedisKeyConstants.USER_ROLE_ID_LIST).append(":%s:%s")), finalOrganId, userId)).collect(Collectors.toSet()); String patternKey = String.format(String.valueOf(new StringBuffer(RedisKeyConstants.USER_ROLE_ID_LIST).append(":*:%s")), delRoleUserId);
Long batchDelNum = redisTemplate.delete(delKeys); Long batchDelNum = scanAndDelKeys(patternKey);
log.info("[batchAssignRoleUsers] 批量删除redis[USER_ROLE_ID_LIST]数量:{}", batchDelNum); log.info("[batchAssignRoleUsers] 批量删除redis[{}]数量:{}", patternKey, batchDelNum);
});
} }
redisTemplate.convertAndSend(RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, ""); redisTemplate.convertAndSend(RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, "");
}).exceptionally(e -> { }).exceptionally(e -> {
log.error("[batchAssignRoleUsers] redis message发送失败, topic:{}, 异常:{}", RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, e); log.error("[batchAssignRoleUsers] redis 清空USER_ROLE_ID_LIST或message发送失败, topic:{}, 异常:{}", RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, e);
return null; return null;
}); });
} }
@@ -455,7 +479,7 @@ public class PermissionServiceImpl implements PermissionService {
redisTemplate.delete(String.format(String.valueOf(new StringBuffer(RedisKeyConstants.USER_ROLE_ID_LIST).append(":%s:%s")), organId, userId)); redisTemplate.delete(String.format(String.valueOf(new StringBuffer(RedisKeyConstants.USER_ROLE_ID_LIST).append(":%s:%s")), organId, userId));
redisTemplate.convertAndSend(RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, ""); redisTemplate.convertAndSend(RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, "");
}).exceptionally(e -> { }).exceptionally(e -> {
log.error("[assignUserRole] redis 清空USER_ROLE_ID_LIST或message发送失败, topic:{}, 异常:{}", RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, e); log.error("[assignUserRole] redis message发送失败, topic:{}, 异常:{}", RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, e);
return null; return null;
}); });
} }
@@ -363,7 +363,9 @@ public class AdminUserServiceImpl implements AdminUserService {
// 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确 // 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
DataPermissionUtils.executeIgnore(() -> { DataPermissionUtils.executeIgnore(() -> {
// 校验用户的密码是否符合规则 // 校验用户的密码是否符合规则
validatePassword(password); if(password != null) {
validatePassword(password);
}
// 校验用户存在 // 校验用户存在
validateUserExists(id); validateUserExists(id);
// 校验用户名唯一 // 校验用户名唯一