From 23855599412c4d61b38d78f0f3abd3430a48b5b1 Mon Sep 17 00:00:00 2001 From: zhangherong <571457620@qq.com> Date: 星期三, 25 六月 2025 11:51:38 +0800 Subject: [PATCH] Merge branch 'mdc_hyjs_master' --- lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/PartsPermissionServiceImpl.java | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 112 insertions(+), 0 deletions(-) diff --git a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/PartsPermissionServiceImpl.java b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/PartsPermissionServiceImpl.java new file mode 100644 index 0000000..f2d29bc --- /dev/null +++ b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/PartsPermissionServiceImpl.java @@ -0,0 +1,112 @@ +package org.jeecg.modules.dnc.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.jeecg.modules.dnc.entity.PartsPermission; +import org.jeecg.modules.dnc.mapper.PartsPermissionMapper; +import org.jeecg.modules.dnc.ucenter.UserDepartExt; +import org.jeecg.modules.dnc.utils.ValidateUtil; +import org.jeecg.modules.system.entity.SysUser; +import org.jeecg.modules.dnc.service.IPartsPermissionService; +import org.apache.commons.collections4.ListUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +@Service +public class PartsPermissionServiceImpl extends ServiceImpl<PartsPermissionMapper, PartsPermission> implements IPartsPermissionService { + @Override + public PartsPermission getByPartsIdAndUserId(String partsId, String userId) { + if(!ValidateUtil.validateString(partsId) || !ValidateUtil.validateString(userId)) + return null; + List<PartsPermission> permissions = super.lambdaQuery().eq(PartsPermission::getPartsId, partsId).eq(PartsPermission::getUserId, userId).list(); + if(permissions == null || permissions.isEmpty()) + return null; + return permissions.get(0); + } + + @Override + @Transactional(rollbackFor = {Exception.class}) + public boolean deleteByPartsId(String partsId) { + if(!ValidateUtil.validateString(partsId)) + return false; + LambdaQueryWrapper<PartsPermission> lambdaQueryWrapper = Wrappers.lambdaQuery(); + lambdaQueryWrapper.eq(PartsPermission::getPartsId, partsId); + return super.remove(lambdaQueryWrapper); + } + + @Override + public List<UserDepartExt> getUserPermsByProductId(String partsId) { + return super.getBaseMapper().getUserPermsByProductId(partsId); + } + + @Override + public List<SysUser> getUserNonPermsByProductId(String partsId) { + return super.getBaseMapper().getUserNonPermsByProductId(partsId); + } + + @Override + @Transactional(rollbackFor = {Exception.class}) + public boolean removeByCollection(List<PartsPermission> permissionList) { + if(permissionList == null || permissionList.isEmpty()) + return false; + if(permissionList.size() == 1) + return super.removeById(permissionList.get(0).getId()); + List<String> ids = new ArrayList<>(); + permissionList.forEach(item -> { + ids.add(item.getId()); + }); + if(ids.size() > 1000){ + List<List<String>> idsArr = ListUtils.partition(ids, 1000); + for(List<String> arr : idsArr){ + super.removeByIds(arr); + } + return true; + }else { + return super.removeByIds(ids); + } + } + + @Override + public List<PartsPermission> getByPartsId(String partsId) { + List<PartsPermission> list = super.lambdaQuery().eq(PartsPermission::getPartsId, partsId).list(); + if(list == null) + list = Collections.emptyList(); + return list; + } + + @Override + public List<PartsPermission> getByPartsIdsAndUserIds(List<String> partsIds, List<String> userIds) { + if(partsIds == null || partsIds.isEmpty() || userIds == null || userIds.isEmpty()) + return null; + List<PartsPermission> total = new ArrayList<>(); + List<List<String>> partsListArr; + List<List<String>> userListArr; + if(partsIds.size() > 1000){ + partsListArr = ListUtils.partition(partsIds, 100); + }else { + partsListArr = ListUtils.partition(partsIds, 1000); + } + if(userIds.size() > 1000){ + userListArr = ListUtils.partition(userIds, 100); + }else { + userListArr = ListUtils.partition(userIds, 1000); + } + for(List<String> compList : partsListArr) { + for(List<String> userList : userListArr){ + LambdaQueryWrapper<PartsPermission> queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.in(PartsPermission::getPartsId, compList); + queryWrapper.in(PartsPermission::getUserId, userList); + List<PartsPermission> list = super.list(queryWrapper); + if(list != null && !list.isEmpty()){ + total.addAll(list); + } + } + } + return total; + } +} -- Gitblit v1.9.3