对比新文件 |
| | |
| | | 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; |
| | | } |
| | | } |