From b02beccf4567068cb47a3f1181a00039456c872d Mon Sep 17 00:00:00 2001
From: zqy <2522236926@qq.com>
Date: 星期三, 06 八月 2025 15:37:20 +0800
Subject: [PATCH] 用户修改姓名和电话同步修改uaid

---
 zhang-content/src/main/java/com/ruoyi/service/impl/ZAuthorityServiceImpl.java |  336 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 332 insertions(+), 4 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..e28ff97 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.common.utils.StringUtils;
+import com.ruoyi.domain.*;
+import com.ruoyi.domain.dto.AuthorityDto;
+import com.ruoyi.domain.dto.AuthorityDto2;
+import com.ruoyi.domain.dto.AuthorityDtoWithName;
+import com.ruoyi.domain.dto.EmpowerDto;
 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 java.util.List;
+import javax.annotation.Resource;
+import java.util.*;
+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;
+
     /**
      * 鏌ヨ褰撳墠鐢ㄦ埛鐨勬潈闄�
      */
@@ -26,10 +51,313 @@
     public List<ZAuthority> getAuthority() {
         SysUser user = SecurityUtils.getLoginUser().getUser();
         Long userId = user.getUserId();
-
+        ZInfoUser zInfoUser = zInfoUserService.getInfoBysysId(userId);
         LambdaQueryWrapper<ZAuthority> lqw = new LambdaQueryWrapper<>();
-        lqw.eq(ZAuthority::getUid,userId);
+        lqw.eq(ZAuthority::getUid,zInfoUser.getUserId());
 
         return list(lqw);
     }
+
+    @Override
+    public AuthorityDto getByCondition(AuthorityDto authorityDto) {
+        SysUser user = SecurityUtils.getLoginUser().getUser();
+        Long userId = user.getUserId();
+        Integer clanId = user.getClanId();
+        String familyName = authorityDto.getFamilyName();
+        String modelName = authorityDto.getModelName();
+
+        //鏍规嵁瀹跺涵鐨勫悕瀛楁煡鍑哄搴殑id
+      //  Integer clanId = 0;
+        Long familyId = zfFamilyService.getByName(familyName, clanId).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();
+
+    }
+
+    @Override
+    public AjaxResult getOtherAuthority(AuthorityDto 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 fid = myself.getFamilyId();
+
+
+        //鏍规嵁瀹跺涵鐨勫悕瀛楁煡鍑哄搴殑id
+//        ZfFamily family = zfFamilyService.getByName(authorityDto.getFamilyName());
+//        Long fid = family.getId();
+
+        //寰楀埌瑕佹悳绱㈢殑妯″潡鍚嶅瓧
+        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).in(ZAuthority::getAuthority,allCodeList);
+        List<ZAuthority> resultData = zAuthorityService.list(lqw);
+
+
+        //鎷垮埌鏈夊叧鐢ㄦ埛鐨刬d鍜屽搴旂殑鏉冮檺鐮佹暟缁�
+        HashMap<Long, ArrayList<Long>> userAuthMap = new HashMap<>();
+        resultData.forEach(authority->{
+           if(userAuthMap.get(authority.getUid()) == null){
+               ArrayList<Long> codeList = new ArrayList<>();
+               codeList.add(authority.getAuthority());
+               userAuthMap.put(authority.getUid(),codeList);
+           }else {
+               userAuthMap.get(authority.getUid()).add(authority.getAuthority());
+           }
+        });
+
+
+        List<AuthorityDtoWithName> returnData = new ArrayList<>();
+
+        for (Long uid : userAuthMap.keySet()) {
+            ArrayList<Long> authCodeList = userAuthMap.get(uid);
+            List<String> authNameList = zfCodeService.getNameByCode(authCodeList);
+
+            AuthorityDto oneAuth = new AuthorityDto();
+            authNameList.forEach(name ->{
+                if(name.contains("鏌ョ湅")){
+                    oneAuth.setSearch(1);
+                }else if(name.contains("鍒犻櫎")){
+                    oneAuth.setDelete(1);
+                }else if(name.contains("娣诲姞")){
+                    oneAuth.setInsert(1);
+                }else if(name.contains("淇敼")){
+                    oneAuth.setUpdate(1);
+                }
+            });
+            oneAuth.setModelName(modelName);
+            oneAuth.setFamilyName(zfFamilyService.getById(fid).getName());
+
+            AuthorityDtoWithName authorityDtoWithName = new AuthorityDtoWithName();
+            authorityDtoWithName.setName(zInfoUserService.getInfoById(uid).getNickName());
+            authorityDtoWithName.setUserId(uid);
+            authorityDtoWithName.setAuthorityInfo(oneAuth);
+            returnData.add(authorityDtoWithName);
+        }
+
+        return AjaxResult.success(returnData);
+
+    }
+    private LambdaQueryWrapper<ZAuthority> uniqueCondition(ZAuthority zAuthority) {
+        LambdaQueryWrapper<ZAuthority> lqw = new LambdaQueryWrapper<>();
+        lqw.eq(zAuthority.getUid()!=null,ZAuthority::getUid,zAuthority.getUid());
+        lqw.eq(zAuthority.getFid()!=null,ZAuthority::getFid,zAuthority.getFid());
+
+        lqw.eq(zAuthority.getAuthority()!=null,ZAuthority::getAuthority,zAuthority.getAuthority());
+
+        return lqw;
+    }
+    public void addData(ZAuthority za)
+    {
+        //鍒ゆ柇鏄惁閲嶅鎺堟潈
+        LambdaQueryWrapper<ZAuthority> lqw = uniqueCondition(za);
+        List<ZAuthority> list = list(lqw);
+        //
+        if(list.size()>0){
+            throw new RuntimeException("璇峰嬁鏂板閲嶅鏁版嵁");
+        }
+        zAuthorityService.save(za);
+
+    }
+    public AjaxResult saveZa(EmpowerDto zAuthority)
+    {
+      //  boolean bl = zAuthorityService.saveOrUpdate(zAuthority);
+        Long [] uids = zAuthority.getUids();
+        Long [] authoritys =  zAuthority.getAuthoritys();
+        for(Long uid : uids)
+            for(Long auri: authoritys)
+            {
+                ZAuthority za = new ZAuthority();
+                za.setAuthority(auri);
+                za.setFid(zAuthority.getFid());
+                za.setUid(uid);
+                addData(za);
+                System.out.println(za);
+            }
+      //  Long []
+     //  if(bl)
+         return AjaxResult.success("鏉冮檺鏂板鎴愬姛!");
+       // else
+        //    return  AjaxResult.error("鏉冮檺鏂板澶辫触锛�");
+
+    }
+
+    @Override
+    public AjaxResult deleteZa(EmpowerDto empowerDto) {
+        Long [] uids = empowerDto.getUids();
+        Long [] authoritys =  empowerDto.getAuthoritys();
+        for(Long uid : uids)
+            for(Long auri: authoritys)
+            {
+
+                LambdaQueryWrapper<ZAuthority> lqw = new LambdaQueryWrapper<>();
+                lqw.eq(ZAuthority::getFid,empowerDto.getFid())
+                        .eq(ZAuthority::getAuthority, auri)
+                        .eq(ZAuthority::getUid, uid);
+                System.out.println("11111111111111111111"+list(lqw));
+                zAuthorityService.remove(lqw);
+             //   addData(za);
+            }
+     return AjaxResult.success("鏉冮檺鏀跺洖鎴愬姛!");
+
+    }
+
+    @Override
+    public AjaxResult listByFidAid(ZAuthority zAuthority) {
+        //鎵惧埌瀵瑰簲瀹跺涵浠ュ強鏉冮檺妯″潡瀵瑰簲鐨勭敤鎴�
+        LambdaQueryWrapper<ZAuthority> lqw = new LambdaQueryWrapper<>();
+        lqw.eq(ZAuthority::getFid,zAuthority.getFid())
+                .eq(ZAuthority::getAuthority, zAuthority.getAuthority());
+
+        List<ZAuthority> authorityList = list(lqw);
+
+        List<Long> allUserListId = authorityList.stream().map(ZAuthority::getUid).collect(Collectors.toList());//鎺堟潈鐢ㄦ埛鏁扮粍鏁扮粍
+
+
+        LambdaQueryWrapper<ZInfoUser> lq = new LambdaQueryWrapper<>();
+        List<ZInfoUser> userInfo = new ArrayList<>();
+        if(allUserListId.size()!=0) {
+            lq.in(ZInfoUser::getUserId, allUserListId);
+
+            userInfo = zInfoUserService.list(lq);
+        }
+      //  Map<Long, String> usi = userInfo.stream().collect(Collectors.toMap(ZInfoUser::getUserId,ZInfoUser::getNickName));
+        return AjaxResult.success(userInfo);
+    }
 }

--
Gitblit v1.9.1