From 3f50e9e810b478dbbd3225d9e5cedf47f586b69b Mon Sep 17 00:00:00 2001 From: whywhyo <1511349576@qq.com> Date: 星期二, 05 九月 2023 11:25:43 +0800 Subject: [PATCH] 45386 --- zhang-content/src/main/java/com/ruoyi/service/impl/ZAuthorityServiceImpl.java | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 164 insertions(+), 0 deletions(-) diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/ZAuthorityServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/ZAuthorityServiceImpl.java index 4fe8289..50cf44e 100644 --- a/zhang-content/src/main/java/com/ruoyi/service/impl/ZAuthorityServiceImpl.java +++ b/zhang-content/src/main/java/com/ruoyi/service/impl/ZAuthorityServiceImpl.java @@ -2,14 +2,26 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.domain.ZAuthority; +import com.ruoyi.domain.ZInfoUser; +import com.ruoyi.domain.ZfCode; +import com.ruoyi.domain.ZfFamily; +import com.ruoyi.domain.dto.AuthorityDto; +import com.ruoyi.domain.dto.AuthorityDto2; import com.ruoyi.mapper.ZAuthorityMapper; import com.ruoyi.service.ZAuthorityService; +import com.ruoyi.service.ZInfoUserService; +import com.ruoyi.service.ZfCodeService; +import com.ruoyi.service.ZfFamilyService; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import javax.annotation.Resource; import java.util.List; +import java.util.stream.Collectors; /** * @Author Jinquan_Ou @@ -19,6 +31,19 @@ **/ @Service public class ZAuthorityServiceImpl extends ServiceImpl<ZAuthorityMapper, ZAuthority> implements ZAuthorityService { + + @Resource + private ZfFamilyService zfFamilyService; + + @Resource + private ZfCodeService zfCodeService; + + @Resource + private ZAuthorityService zAuthorityService; + + @Resource + private ZInfoUserService zInfoUserService; + /** * 鏌ヨ褰撳墠鐢ㄦ埛鐨勬潈闄� */ @@ -32,4 +57,143 @@ return list(lqw); } + + @Override + public AuthorityDto getByCondition(AuthorityDto authorityDto) { + SysUser user = SecurityUtils.getLoginUser().getUser(); + Long userId = user.getUserId(); + + String familyName = authorityDto.getFamilyName(); + String modelName = authorityDto.getModelName(); + + //鏍规嵁瀹跺涵鐨勫悕瀛楁煡鍑哄搴殑id + Long familyId = zfFamilyService.getByName(familyName).getId(); + + //鏍规嵁妯″潡鐨勫悕瀛楁煡鍑哄搴旂殑鏉冮檺鐮� + List<ZfCode> zfCodeList = zfCodeService.likeGetByName(modelName); + List<Long> allCodeList = zfCodeList.stream().map(ZfCode::getCode).collect(Collectors.toList());//鏉冮檺鐮佹暟缁� + + + //鎵惧埌瀵瑰簲瀹跺涵瀵瑰簲妯″潡鐨勬潈闄愭暟缁� + LambdaQueryWrapper<ZAuthority> lqw = new LambdaQueryWrapper<>(); + lqw.eq(ZAuthority::getFid,familyId) + .eq(ZAuthority::getUid,userId) + .in(ZAuthority::getAuthority,allCodeList); + List<ZAuthority> authorityList = list(lqw); + + List<Long> codeList = authorityList.stream().map(ZAuthority::getAuthority).collect(Collectors.toList());//鐪熸鎷ユ湁鏉冮檺鐨勬潈闄愮爜鏁扮粍 + List<String> nameList = zfCodeService.getNameByCode(codeList); + + AuthorityDto resultData = new AuthorityDto(); + nameList.forEach(name ->{ + if(name.contains("鏌ョ湅")){ + resultData.setSearch(1); + }else if(name.contains("鍒犻櫎")){ + resultData.setDelete(1); + }else if(name.contains("娣诲姞")){ + resultData.setInsert(1); + }else if(name.contains("淇敼")){ + resultData.setUpdate(1); + } + }); + + resultData.setModelName(modelName); + resultData.setFamilyName(familyName); + + return resultData; + + + + } + + @Override + public List<String> getAuthorityFamilyName() { + List<ZAuthority> authorityList = getAuthority(); + List<Long> familyIds = authorityList.stream().map(ZAuthority::getFid).distinct().collect(Collectors.toList()); + List<ZfFamily> familyList = zfFamilyService.listByIds(familyIds); + return familyList.stream().map(ZfFamily::getName).distinct().collect(Collectors.toList()); + } + + /** + * + * @param authorityDto 浼犲叆浜嗙敤鎴穒d銆乵odelName + * @return + */ + @Override + @Transactional + public AjaxResult managerAuthority(AuthorityDto2 authorityDto) { + SysUser user = SecurityUtils.getLoginUser().getUser(); + Long userId = user.getUserId(); + ZInfoUser myself = zInfoUserService.getById(userId); + + //鏌ョ湅褰撳墠鐢ㄦ埛鏄笉鏄鐞嗗憳 + if(myself.getRoleId()!=1 && myself.getRoleId()!=2){ + throw new RuntimeException("浣犱笉鏄搴鐞嗗憳锛屾病鏈夋潈闄愭搷浣�"); + } + + + Long uid = authorityDto.getUid(); + Long fid = myself.getFamilyId(); + String modelName = authorityDto.getModelName(); + + //鏍规嵁妯″潡鐨勫悕瀛楁煡鍑哄搴旂殑鏉冮檺鐮� + List<ZfCode> zfCodeList = zfCodeService.likeGetByName(modelName); + List<Long> allCodeList = zfCodeList.stream().map(ZfCode::getCode).collect(Collectors.toList());//鏉冮檺鐮佹暟缁� + + //鎵惧埌瀵瑰簲瀹跺涵瀵瑰簲妯″潡鐨勬潈闄愭暟缁� + LambdaQueryWrapper<ZAuthority> lqw = new LambdaQueryWrapper<>(); + lqw.eq(ZAuthority::getFid,fid) + .eq(ZAuthority::getUid,uid) + .in(ZAuthority::getAuthority,allCodeList); + List<ZAuthority> authorityList = list(lqw); + + //鍏堝垹鎺夌幇鍦ㄦ墍鏈夌殑鏉冮檺 + List<Long> idList = authorityList.stream().map(ZAuthority::getId).collect(Collectors.toList()); + zAuthorityService.removeBatchByIds(idList); + + //鍐嶆坊鍔犳柊璁剧疆鐨勬潈闄� + if(authorityDto.getSearch() == 1){ + //鏍规嵁妯″潡鐨勫悕瀛楁煡鍒版潈闄愮爜锛屽彧浼氭湁涓�涓粨鏋� + List<ZfCode> zfcode = zfCodeService.likeGetByName(modelName + "鏌ョ湅"); + ZAuthority zAuthority = new ZAuthority(); + zAuthority.setFid(fid); + zAuthority.setUid(uid); + zAuthority.setAuthority(zfcode.get(0).getCode()); + zAuthorityService.save(zAuthority); + } + + if(authorityDto.getInsert() == 1){ + //鏍规嵁妯″潡鐨勫悕瀛楁煡鍒版潈闄愮爜锛屽彧浼氭湁涓�涓粨鏋� + List<ZfCode> zfcode = zfCodeService.likeGetByName(modelName + "娣诲姞"); + ZAuthority zAuthority = new ZAuthority(); + zAuthority.setFid(fid); + zAuthority.setUid(uid); + zAuthority.setAuthority(zfcode.get(0).getCode()); + zAuthorityService.save(zAuthority); + } + + if(authorityDto.getUpdate() == 1){ + //鏍规嵁妯″潡鐨勫悕瀛楁煡鍒版潈闄愮爜锛屽彧浼氭湁涓�涓粨鏋� + List<ZfCode> zfcode = zfCodeService.likeGetByName(modelName + "淇敼"); + ZAuthority zAuthority = new ZAuthority(); + zAuthority.setFid(fid); + zAuthority.setUid(uid); + zAuthority.setAuthority(zfcode.get(0).getCode()); + zAuthorityService.save(zAuthority); + } + + if(authorityDto.getDelete() == 1){ + //鏍规嵁妯″潡鐨勫悕瀛楁煡鍒版潈闄愮爜锛屽彧浼氭湁涓�涓粨鏋� + List<ZfCode> zfcode = zfCodeService.likeGetByName(modelName + "鍒犻櫎"); + ZAuthority zAuthority = new ZAuthority(); + zAuthority.setFid(fid); + zAuthority.setUid(uid); + zAuthority.setAuthority(zfcode.get(0).getCode()); + zAuthorityService.save(zAuthority); + } + + return AjaxResult.success(); + + } + } -- Gitblit v1.9.1