浏览代码

场景列表平台数据隔离

lyhzzz 9 月之前
父节点
当前提交
61d552d7da

+ 2 - 0
doc/update-1.5.0.sql

@@ -44,6 +44,8 @@ CREATE TABLE `4dkankan_v4`.`jy_user_platform_user`  (
                                            PRIMARY KEY (`id`)
 );
 
+ALTER TABLE `4dkankan_v4`.`jy_user`
+    ADD COLUMN `platform_id` int NULL AFTER `is_jm`;
 
 
 INSERT INTO `sys_role` VALUES (48, '平台管理员', 'manage', 'A', 1, 1, '江门公安局', '2024-11-18 10:48:24', '2024-11-18 10:48:24');

+ 3 - 0
src/main/java/com/fdkankan/manage/entity/JyUser.java

@@ -79,4 +79,7 @@ public class JyUser implements Serializable {
      */
     @TableField("status")
     private Integer status;
+
+    @TableField("platform_id")
+    private Integer platformId;
 }

+ 2 - 0
src/main/java/com/fdkankan/manage/service/IJyPlatformService.java

@@ -30,4 +30,6 @@ public interface IJyPlatformService extends IService<JyPlatform> {
     void disable(JyPlatformVo param);
 
     List<String> getIds();
+
+    JyPlatform getByIdCard(String idCard);
 }

+ 0 - 6
src/main/java/com/fdkankan/manage/service/IJyUserPlatformService.java

@@ -22,7 +22,6 @@ public interface IJyUserPlatformService extends IService<JyUserPlatform> {
 
     JyUserPlatform getByIdCard(String idCard);
 
-    void bindJyUserId(Integer id, Integer jyUserId);
 
 
     void del(JyUserPlatformAddParam param);
@@ -37,14 +36,9 @@ public interface IJyUserPlatformService extends IService<JyUserPlatform> {
 
     void bindPlatform(Integer id, Integer platformId);
 
-    JyUserPlatform getByJyUserId(Integer jyUserId);
-
-
-    void updatePlatformId(Integer id, Integer toPlatformId);
 
     Integer addPlatformUser(List<HashMap<Integer, String>> excelRowList);
 
     Integer getLoginPlatformId();
 
-    List<Integer> getUserIdsByFaltform(Integer loginPlatformId);
 }

+ 4 - 0
src/main/java/com/fdkankan/manage/service/IJyUserService.java

@@ -37,4 +37,8 @@ public interface IJyUserService extends IService<JyUser> {
     List<JyUser> getListByJm();
 
     JyUser getByIdCard(String idCard);
+
+    void updatePlatformId(Integer id, Integer id1);
+
+    List<Long> getByUserIdPlatform(Integer loginPlatformId);
 }

+ 8 - 14
src/main/java/com/fdkankan/manage/service/impl/JyPlatformServiceImpl.java

@@ -70,7 +70,6 @@ public class JyPlatformServiceImpl extends ServiceImpl<IJyPlatformMapper, JyPlat
             throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
         }
         JyPlatform jyPlatform ;
-        JyUserPlatform jyUserPlatform ;
         if(param.getId() == null){  //创建平台自动生成平台访问地址
             String uuid = UUID.randomUUID().toString().substring(0, 18).replace("-", "");
             param.setPlatformAddress(uuid);
@@ -79,11 +78,9 @@ public class JyPlatformServiceImpl extends ServiceImpl<IJyPlatformMapper, JyPlat
                 throw new BusinessException(ResultCode.ID_CARD_EXIT);
             }
             jyPlatform = new JyPlatform();
-            jyUserPlatform = new JyUserPlatform();
             JyUser jyUser = jyUserService.getByIdCard(param.getIdCard());
             if(jyUser != null){
-                param.setJyUserId(jyUser.getId());
-                sysUserService.updateRoleId(jyUser.getSysUserId(),48);
+                throw new BusinessException(ResultCode.ID_CARD_EXIT);
             }
 
         }else {
@@ -96,18 +93,15 @@ public class JyPlatformServiceImpl extends ServiceImpl<IJyPlatformMapper, JyPlat
             if(jyPlatform2 != null && !jyPlatform2.getId().equals(jyPlatform.getId())){
                 throw new BusinessException(ResultCode.ID_CARD_EXIT);
             }
-            jyUserPlatform = jyUserPlatformService.getByIdCard(jyPlatform.getIdCard());
         }
         BeanUtils.copyProperties(param,jyPlatform);
-        BeanUtils.copyProperties(param,jyUserPlatform);
         this.saveOrUpdate(jyPlatform);
-        jyUserPlatform.setPlatformId(jyPlatform.getId());
-        jyUserPlatformService.saveOrUpdate(jyUserPlatform);
 
         return jyPlatform;
     }
 
-    private JyPlatform getByIdCard(String idCard) {
+    @Override
+    public JyPlatform getByIdCard(String idCard) {
         LambdaQueryWrapper<JyPlatform> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(JyPlatform::getIdCard,idCard);
         return this.getOne(wrapper);
@@ -139,8 +133,7 @@ public class JyPlatformServiceImpl extends ServiceImpl<IJyPlatformMapper, JyPlat
             throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
         }
         //update userRole
-        JyUserPlatform jyUserPlatform = jyUserPlatformService.getByIdCard(jyPlatform.getIdCard());
-        JyUser jyUser = jyUserService.getById(jyUserPlatform.getJyUserId());
+        JyUser jyUser = jyUserService.getById(param.getJyUserId());
         if(jyUser != null){
             sysUserService.updateRoleId(jyUser.getSysUserId(),48);
         }
@@ -164,12 +157,11 @@ public class JyPlatformServiceImpl extends ServiceImpl<IJyPlatformMapper, JyPlat
             throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
         }
         //update userRole
-        JyUserPlatform jyUserPlatform = jyUserPlatformService.getByIdCard(jyPlatform.getIdCard());
-        JyUser jyUser = jyUserService.getById(jyUserPlatform.getJyUserId());
+        JyUser jyUser = jyUserService.getById(param.getJyUserId());
         if(jyUser != null){
             sysUserService.updateRoleId(jyUser.getSysUserId(),47);
         }
-        jyUserPlatformService.updatePlatformId(param.getId(),param.getToPlatformId());
+        jyUserService.updatePlatformId(param.getId(),param.getToPlatformId());
         this.updateStatus(jyPlatform.getId(),1);
 
 
@@ -185,4 +177,6 @@ public class JyPlatformServiceImpl extends ServiceImpl<IJyPlatformMapper, JyPlat
         }
         return list.stream().map(JyPlatform::getIdCard).collect(Collectors.toList());
     }
+
+
 }

+ 5 - 37
src/main/java/com/fdkankan/manage/service/impl/JyUserPlatformServiceImpl.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fdkankan.manage.common.PageInfo;
 import com.fdkankan.manage.common.ResultCode;
 import com.fdkankan.manage.entity.JyPlatform;
+import com.fdkankan.manage.entity.JyUser;
 import com.fdkankan.manage.entity.JyUserPlatform;
 import com.fdkankan.manage.exception.BusinessException;
 import com.fdkankan.manage.mapper.IJyUserPlatformMapper;
@@ -14,6 +15,7 @@ import com.fdkankan.manage.service.IExcelService;
 import com.fdkankan.manage.service.IJyPlatformService;
 import com.fdkankan.manage.service.IJyUserPlatformService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.manage.service.IJyUserService;
 import com.fdkankan.manage.vo.request.*;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -39,6 +41,8 @@ public class JyUserPlatformServiceImpl extends ServiceImpl<IJyUserPlatformMapper
 
     @Autowired
     IJyPlatformService platformService;
+    @Autowired
+    IJyUserService jyUserService;
     @Override
     public JyUserPlatform getByIdCard(String idCard) {
         LambdaQueryWrapper<JyUserPlatform> wrapper = new LambdaQueryWrapper<>();
@@ -46,20 +50,10 @@ public class JyUserPlatformServiceImpl extends ServiceImpl<IJyUserPlatformMapper
         return this.getOne(wrapper);
     }
 
-    @Override
-    public void bindJyUserId(Integer id, Integer jyUserId) {
-        LambdaUpdateWrapper<JyUserPlatform> wrapper = new LambdaUpdateWrapper<>();
-        wrapper.eq(JyUserPlatform::getId,id);
-        wrapper.set(JyUserPlatform::getJyUserId,jyUserId);
-        this.update(wrapper);
-    }
 
     @Override
     public void bindPlatform(Integer id, Integer platformId) {
-        LambdaUpdateWrapper<JyUserPlatform> wrapper = new LambdaUpdateWrapper<>();
-        wrapper.eq(JyUserPlatform::getId,id);
-        wrapper.set(JyUserPlatform::getPlatformId,platformId);
-        this.update(wrapper);
+        jyUserService.updatePlatformId(id,platformId);
     }
 
 
@@ -111,21 +105,6 @@ public class JyUserPlatformServiceImpl extends ServiceImpl<IJyUserPlatformMapper
         return this.getBaseMapper().queryByKey(param.getQueryKey(),platformAdminIdCards);
     }
 
-    @Override
-    public JyUserPlatform getByJyUserId(Integer jyUserId) {
-        LambdaQueryWrapper<JyUserPlatform> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(JyUserPlatform::getJyUserId,jyUserId);
-        return this.getOne(wrapper);
-    }
-
-
-    @Override
-    public void updatePlatformId(Integer id, Integer toPlatformId) {
-        LambdaUpdateWrapper<JyUserPlatform> wrapper = new LambdaUpdateWrapper<>();
-        wrapper.eq(JyUserPlatform::getPlatformId,id);
-        wrapper.set(JyUserPlatform::getPlatformId,toPlatformId);
-        this.update(wrapper);
-    }
 
     @Override
     public Integer getLoginPlatformId(){
@@ -188,15 +167,4 @@ public class JyUserPlatformServiceImpl extends ServiceImpl<IJyUserPlatformMapper
         return count;
     }
 
-    @Override
-    public List<Integer> getUserIdsByFaltform(Integer loginPlatformId) {
-        LambdaQueryWrapper<JyUserPlatform> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(JyUserPlatform::getPlatformId,loginPlatformId);
-        List<JyUserPlatform> list = this.list(wrapper);
-        if(list.isEmpty()){
-            return new ArrayList<>();
-        }
-        return list.stream().map(JyUserPlatform::getJyUserId).collect(Collectors.toList());
-
-    }
 }

+ 22 - 0
src/main/java/com/fdkankan/manage/service/impl/JyUserServiceImpl.java

@@ -1,6 +1,7 @@
 package com.fdkankan.manage.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.fdkankan.manage.common.ResultCode;
 import com.fdkankan.manage.entity.JyUser;
 import com.fdkankan.manage.exception.BusinessException;
@@ -10,9 +11,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -119,4 +122,23 @@ public class JyUserServiceImpl extends ServiceImpl<IJyUserMapper, JyUser> implem
         wrapper.eq(JyUser::getIdCard,idCard);
         return this.getOne(wrapper);
     }
+
+    @Override
+    public void updatePlatformId(Integer id, Integer id1) {
+        LambdaUpdateWrapper<JyUser> wrapper = new LambdaUpdateWrapper<>();
+        wrapper.eq(JyUser::getId,id);
+        wrapper.set(JyUser::getIdCard,id1);
+        this.update(wrapper);
+    }
+
+    @Override
+    public List<Long> getByUserIdPlatform(Integer loginPlatformId) {
+        LambdaQueryWrapper<JyUser> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(JyUser::getPlatformId,loginPlatformId);
+        List<JyUser> list = this.list(wrapper);
+        if(list.isEmpty()){
+            return new ArrayList<>();
+        }
+        return list.stream().map(JyUser::getUserId).collect(Collectors.toList());
+    }
 }

+ 1 - 2
src/main/java/com/fdkankan/manage/service/impl/ManageService.java

@@ -72,12 +72,11 @@ public class ManageService {
 
         JyUser jyUser = jyUserService.getBySysId(result.getId());
 
-        JyUserPlatform jyUserPlatform = jyUserPlatformService.getByJyUserId(jyUser.getId());
         StpUtil.login(result.getId(), SaLoginConfig
                 .setExtra("id",result.getId())
                 .setExtra("userId",user.getId())
                 .setExtra("isAdmin",1)
-                .setExtra("platformId",jyUserPlatform != null ?jyUserPlatform.getPlatformId() :null)
+                .setExtra("platformId",jyUser.getPlatformId() != null ?jyUser.getPlatformId() :null)
                 .setExtra("userName",result.getUserName())
                 .setExtra("nickName",result.getNickName()));
 

+ 2 - 6
src/main/java/com/fdkankan/manage/service/impl/SceneProServiceImpl.java

@@ -324,9 +324,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
             if(byId.getRoleId() == 48L){
                 Integer loginPlatformId = jyUserPlatformService.getLoginPlatformId();
                 if(loginPlatformId != null) {
-                    List<Integer> jyUserIds = jyUserPlatformService.getUserIdsByFaltform(loginPlatformId);
-                    List<JyUser> jyUsers = jyUserService.listByIds(jyUserIds);
-                    userIds = jyUsers.stream().map(JyUser::getUserId).collect(Collectors.toList());
+                    userIds = jyUserService.getByUserIdPlatform(loginPlatformId);
                 }
             }
 
@@ -415,9 +413,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
             if(byId.getRoleId() == 48L){
                 Integer loginPlatformId = jyUserPlatformService.getLoginPlatformId();
                 if(loginPlatformId != null){
-                    List<Integer> jyUserIds =  jyUserPlatformService.getUserIdsByFaltform(loginPlatformId);
-                    List<JyUser> jyUsers = jyUserService.listByIds(jyUserIds);
-                    userIds = jyUsers.stream().map(JyUser::getUserId).collect(Collectors.toList());
+                    userIds = jyUserService.getByUserIdPlatform(loginPlatformId);
                 }
             }
             if(byId.getRoleId() == 45L){

+ 3 - 6
src/main/java/com/fdkankan/manage/service/impl/UserServiceImpl.java

@@ -225,13 +225,10 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
         jyUserService.saveOrUpdate(jyUser);
 
         if(init && StringUtils.isNotBlank(param.getIdCard()) && param.getIsJm()!=null && param.getIsJm() != 1){
-            JyUserPlatform jyUserPlatform = jyUserPlatformService.getByIdCard(param.getIdCard());
-            JyPlatform jyPlatform = jyPlatformService.getById(jyUserPlatform.getPlatformId());
+            JyPlatform jyPlatform = jyPlatformService.getByIdCard(jyUser.getIdCard());
             if(jyPlatform != null){
-                jyUserPlatformService.bindJyUserId(jyUserPlatform.getId(),jyUser.getId());
-                if(param.getIdCard().equals(jyPlatform.getIdCard())){
-                    sysUserService.updateRoleId(sysUser.getId(),48);
-                }
+                jyUserService.updatePlatformId(jyUser.getId(),jyPlatform.getId());
+                sysUserService.updateRoleId(sysUser.getId(),48);
             }
         }
     }

+ 4 - 4
src/main/resources/mapper/manage/JyUserPlatformMapper.xml

@@ -3,8 +3,8 @@
 <mapper namespace="com.fdkankan.manage.mapper.IJyUserPlatformMapper">
 
     <select id="pageList" resultType="com.fdkankan.manage.vo.request.JyUserPlatformVo">
-        select * from jy_user_platform up left join jy_user jy on up.jy_user_id = jy.id
-                                          left join jy_platform jp on up.platform_id = jp.id
+        select * from jy_user up
+                           left join jy_platform jp on up.platform_id = jp.id
         where up.rec_status = 'A' and jy.rec_status = 'A' and jp.rec_status = 'A' and jp.status !=0 and up.id_card != jp.id_card
         <if test="param.name != null and param.name !=''">
             and up.name like concat ('%',#{param.name},'%')
@@ -16,7 +16,7 @@
             and up.id_card like concat ('%',#{param.idCard},'%')
         </if>
         <if test="param.ryNo != null and param.ryNo !=''">
-            and jy.ry_no like concat ('%',#{param.ryNo},'%')
+            and up.ry_no like concat ('%',#{param.ryNo},'%')
         </if>
         <if test="param.platformId != null ">
             and up.platform_id  = #{param.platformId}
@@ -25,7 +25,7 @@
 
     </select>
     <select id="queryByKey" resultType="com.fdkankan.manage.entity.JyUserPlatform">
-        select  * from  jy_user_platform where rec_status = 'A'
+        select  * from  jy_user where rec_status = 'A'
         <if test="queryKey != null and queryKey !=''">
             and ( name = #{queryKey} or phone = #{queryKey} or id_card = #{queryKey}  )
         </if>