Procházet zdrojové kódy

优化数据权限

wuxw před 3 roky
rodič
revize
a956f98419

+ 38 - 16
java110-bean/src/main/java/com/java110/dto/dataPrivilegeStaff/DataPrivilegeStaffDto.java

@@ -1,6 +1,7 @@
 package com.java110.dto.dataPrivilegeStaff;
 
 import com.java110.dto.PageDto;
+
 import java.io.Serializable;
 import java.util.Date;
 
@@ -15,11 +16,13 @@ import java.util.Date;
 public class DataPrivilegeStaffDto extends PageDto implements Serializable {
 
     private String dpsId;
-private String dpId;
-private String staffName;
-private String remark;
-private String communityId;
-private String staffId;
+    private String dpId;
+    private String staffName;
+    private String remark;
+    private String communityId;
+    private String staffId;
+
+    private String storeId;
 
 
     private Date createTime;
@@ -30,37 +33,48 @@ private String staffId;
     public String getDpsId() {
         return dpsId;
     }
-public void setDpsId(String dpsId) {
+
+    public void setDpsId(String dpsId) {
         this.dpsId = dpsId;
     }
-public String getDpId() {
+
+    public String getDpId() {
         return dpId;
     }
-public void setDpId(String dpId) {
+
+    public void setDpId(String dpId) {
         this.dpId = dpId;
     }
-public String getStaffName() {
+
+    public String getStaffName() {
         return staffName;
     }
-public void setStaffName(String staffName) {
+
+    public void setStaffName(String staffName) {
         this.staffName = staffName;
     }
-public String getRemark() {
+
+    public String getRemark() {
         return remark;
     }
-public void setRemark(String remark) {
+
+    public void setRemark(String remark) {
         this.remark = remark;
     }
-public String getCommunityId() {
+
+    public String getCommunityId() {
         return communityId;
     }
-public void setCommunityId(String communityId) {
+
+    public void setCommunityId(String communityId) {
         this.communityId = communityId;
     }
-public String getStaffId() {
+
+    public String getStaffId() {
         return staffId;
     }
-public void setStaffId(String staffId) {
+
+    public void setStaffId(String staffId) {
         this.staffId = staffId;
     }
 
@@ -80,4 +94,12 @@ public void setStaffId(String staffId) {
     public void setStatusCd(String statusCd) {
         this.statusCd = statusCd;
     }
+
+    public String getStoreId() {
+        return storeId;
+    }
+
+    public void setStoreId(String storeId) {
+        this.storeId = storeId;
+    }
 }

java110-db/src/main/resources/mapper/dataPrivilegeUnit/DataPrivilegeUnitV1ServiceDaoImplMapper.xml → java110-db/src/main/resources/mapper/community/DataPrivilegeUnitV1ServiceDaoImplMapper.xml


+ 37 - 0
java110-db/src/main/resources/mapper/dataPrivilegeStaff/DataPrivilegeStaffV1ServiceDaoImplMapper.xml

@@ -110,4 +110,41 @@
 
     </select>
 
+    <!-- 查询用户权限数量 add by wuxw 2018-07-03 -->
+    <select id="queryStaffsNotInDataPrivilegeCount" parameterType="Map" resultType="Map">
+
+        select count(1) count
+        from u_user t
+        inner join s_store_user su on t.user_id = su.user_id and su.status_cd = '0'
+        left join data_privilege_staff pu on t.user_id = pu.staff_id and pu.status_cd = '0' and pu.dp_id = #{dpId}
+        where t.status_cd = '0'
+        and pu.dp_id is null
+        <if test="userName !=null and userName != ''">
+            and t.name like concat('%', #{userName},'%')
+        </if>
+        and su.store_id = #{storeId}
+
+    </select>
+
+    <!-- 查询用户权限信息 add by wuxw 2018-07-03 -->
+    <select id="queryStaffsNotInDataPrivilege" parameterType="Map" resultType="Map">
+        select
+        t.user_id,t.user_id userId,
+        t.address,t.sex,t.user_id,t.user_id userId,t.level_cd,t.level_cd
+        levelCd,t.location_cd,t.location_cd locationCd,t.score,t.name,t.tel,t.email,t.age
+        from u_user t
+        inner join s_store_user su on t.user_id = su.user_id and su.status_cd = '0'
+        left join data_privilege_staff pu on t.user_id = pu.staff_id and pu.status_cd = '0' and pu.dp_id = #{dpId}
+        where t.status_cd = '0'
+        and pu.dp_id is null
+        <if test="userName !=null and userName != ''">
+            and t.name like concat('%', #{userName},'%')
+        </if>
+        and su.store_id = #{storeId}
+        order by t.create_time desc
+        <if test="page != -1 and page != null ">
+            limit #{page}, #{row}
+        </if>
+    </select>
+
 </mapper>

+ 9 - 1
java110-interface/src/main/java/com/java110/intf/community/IDataPrivilegeStaffV1InnerServiceSMO.java

@@ -17,6 +17,8 @@ package com.java110.intf.community;
 
 import com.java110.config.feign.FeignConfiguration;
 import com.java110.dto.dataPrivilegeStaff.DataPrivilegeStaffDto;
+import com.java110.dto.user.StaffDto;
+import com.java110.dto.user.UserDto;
 import com.java110.po.dataPrivilegeStaff.DataPrivilegeStaffPo;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -33,7 +35,7 @@ import java.util.List;
  * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
  * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
  */
-@FeignClient(name = "community-service", configuration = {FeignConfiguration.class})
+@FeignClient(name = "user-service", configuration = {FeignConfiguration.class})
 @RequestMapping("/dataPrivilegeStaffV1Api")
 public interface IDataPrivilegeStaffV1InnerServiceSMO {
 
@@ -65,4 +67,10 @@ public interface IDataPrivilegeStaffV1InnerServiceSMO {
      */
     @RequestMapping(value = "/queryDataPrivilegeStaffsCount", method = RequestMethod.POST)
     int queryDataPrivilegeStaffsCount(@RequestBody DataPrivilegeStaffDto dataPrivilegeStaffDto);
+
+    @RequestMapping(value = "/queryStaffsNotInDataPrivilegeCount", method = RequestMethod.POST)
+    int queryStaffsNotInDataPrivilegeCount(@RequestBody DataPrivilegeStaffDto dataPrivilegeStaffDto);
+
+    @RequestMapping(value = "/queryStaffsNotInDataPrivilege", method = RequestMethod.POST)
+    List<UserDto> queryStaffsNotInDataPrivilege(@RequestBody DataPrivilegeStaffDto dataPrivilegeStaffDto);
 }

+ 1 - 2
service-community/src/main/java/com/java110/community/cmd/dataPrivilegeStaff/DeleteDataPrivilegeStaffCmd.java

@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.java110.community.cmd.dataPrivilegeStaff;
+package com.java110.user.cmd.dataPrivilegeStaff;
 
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.annotation.Java110Cmd;
@@ -21,7 +21,6 @@ import com.java110.core.annotation.Java110Transactional;
 import com.java110.core.context.ICmdDataFlowContext;
 import com.java110.core.event.cmd.Cmd;
 import com.java110.core.event.cmd.CmdEvent;
-import com.java110.core.factory.GenerateCodeFactory;
 import com.java110.intf.community.IDataPrivilegeStaffV1InnerServiceSMO;
 import com.java110.po.dataPrivilegeStaff.DataPrivilegeStaffPo;
 import com.java110.utils.exception.CmdException;

+ 1 - 5
service-community/src/main/java/com/java110/community/cmd/dataPrivilegeStaff/ListDataPrivilegeStaffCmd.java

@@ -13,19 +13,15 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.java110.community.cmd.dataPrivilegeStaff;
+package com.java110.user.cmd.dataPrivilegeStaff;
 
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.annotation.Java110Cmd;
-import com.java110.core.annotation.Java110Transactional;
 import com.java110.core.context.ICmdDataFlowContext;
 import com.java110.core.event.cmd.Cmd;
 import com.java110.core.event.cmd.CmdEvent;
-import com.java110.core.factory.GenerateCodeFactory;
 import com.java110.intf.community.IDataPrivilegeStaffV1InnerServiceSMO;
-import com.java110.po.dataPrivilegeStaff.DataPrivilegeStaffPo;
 import com.java110.utils.exception.CmdException;
-import com.java110.utils.util.Assert;
 import com.java110.utils.util.BeanConvertUtil;
 import com.java110.vo.ResultVo;
 import org.springframework.beans.factory.annotation.Autowired;

+ 89 - 0
service-user/src/main/java/com/java110/user/cmd/dataPrivilegeStaff/ListStaffNotInDataPrivilegeCmd.java

@@ -0,0 +1,89 @@
+/*
+ * Copyright 2017-2020 吴学文 and java110 team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.java110.user.cmd.dataPrivilegeStaff;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.annotation.Java110Cmd;
+import com.java110.core.context.ICmdDataFlowContext;
+import com.java110.core.event.cmd.Cmd;
+import com.java110.core.event.cmd.CmdEvent;
+import com.java110.dto.dataPrivilegeStaff.DataPrivilegeStaffDto;
+import com.java110.dto.user.UserDto;
+import com.java110.intf.community.IDataPrivilegeStaffV1InnerServiceSMO;
+import com.java110.utils.exception.CmdException;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
+import com.java110.vo.ResultVo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * 类表述:查询
+ * 服务编码:dataPrivilegeStaff.listDataPrivilegeStaff
+ * 请求路劲:/app/dataPrivilegeStaff.ListDataPrivilegeStaff
+ * add by 吴学文 at 2022-09-28 16:48:23 mail: 928255095@qq.com
+ * open source address: https://gitee.com/wuxw7/MicroCommunity
+ * 官网:http://www.homecommunity.cn
+ * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
+ * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
+ */
+@Java110Cmd(serviceCode = "dataPrivilegeStaff.listStaffNotInDataPrivilege")
+public class ListStaffNotInDataPrivilegeCmd extends Cmd {
+
+  private static Logger logger = LoggerFactory.getLogger(ListStaffNotInDataPrivilegeCmd.class);
+    @Autowired
+    private IDataPrivilegeStaffV1InnerServiceSMO dataPrivilegeStaffV1InnerServiceSMOImpl;
+
+    @Override
+    public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
+        super.validatePageInfo(reqJson);
+
+        Assert.hasKeyAndValue(reqJson,"dpId","未包含数据权限");
+    }
+
+    @Override
+    public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
+
+           DataPrivilegeStaffDto dataPrivilegeStaffDto = BeanConvertUtil.covertBean(reqJson, DataPrivilegeStaffDto.class);
+
+           String storeId = cmdDataFlowContext.getReqHeaders().get("store-id");
+
+           dataPrivilegeStaffDto.setStoreId(storeId);
+
+           int count = dataPrivilegeStaffV1InnerServiceSMOImpl.queryStaffsNotInDataPrivilegeCount(dataPrivilegeStaffDto);
+
+           List<UserDto> userDtos = null;
+
+           if (count > 0) {
+               userDtos = dataPrivilegeStaffV1InnerServiceSMOImpl.queryStaffsNotInDataPrivilege(dataPrivilegeStaffDto);
+           } else {
+               userDtos = new ArrayList<>();
+           }
+
+           ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) reqJson.getInteger("row")), count, userDtos);
+
+           ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
+
+           cmdDataFlowContext.setResponseEntity(responseEntity);
+    }
+}

+ 1 - 1
service-community/src/main/java/com/java110/community/cmd/dataPrivilegeStaff/SaveDataPrivilegeStaffCmd.java

@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.java110.community.cmd.dataPrivilegeStaff;
+package com.java110.user.cmd.dataPrivilegeStaff;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;

+ 1 - 2
service-community/src/main/java/com/java110/community/cmd/dataPrivilegeStaff/UpdateDataPrivilegeStaffCmd.java

@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.java110.community.cmd.dataPrivilegeStaff;
+package com.java110.user.cmd.dataPrivilegeStaff;
 
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.annotation.Java110Cmd;
@@ -21,7 +21,6 @@ import com.java110.core.annotation.Java110Transactional;
 import com.java110.core.context.ICmdDataFlowContext;
 import com.java110.core.event.cmd.Cmd;
 import com.java110.core.event.cmd.CmdEvent;
-import com.java110.core.factory.GenerateCodeFactory;
 import com.java110.intf.community.IDataPrivilegeStaffV1InnerServiceSMO;
 import com.java110.po.dataPrivilegeStaff.DataPrivilegeStaffPo;
 import com.java110.utils.exception.CmdException;

+ 4 - 1
service-community/src/main/java/com/java110/community/dao/IDataPrivilegeStaffV1ServiceDao.java

@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.java110.community.dao;
+package com.java110.user.dao;
 
 
 import com.java110.utils.exception.DAOException;
@@ -74,4 +74,7 @@ public interface IDataPrivilegeStaffV1ServiceDao {
      */
     int queryDataPrivilegeStaffsCount(Map info);
 
+    int queryStaffsNotInDataPrivilegeCount(Map map);
+
+    List<Map> queryStaffsNotInDataPrivilege(Map map);
 }

+ 23 - 6
service-community/src/main/java/com/java110/community/dao/impl/DataPrivilegeStaffV1ServiceDaoImpl.java

@@ -13,18 +13,14 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.java110.community.dao.impl;
+package com.java110.user.dao.impl;
 
-import com.alibaba.fastjson.JSONObject;
-import com.java110.utils.constant.ResponseConstant;
 import com.java110.utils.exception.DAOException;
-import com.java110.utils.util.DateUtil;
 import com.java110.core.base.dao.BaseServiceDao;
-import com.java110.community.dao.IDataPrivilegeStaffV1ServiceDao;
+import com.java110.user.dao.IDataPrivilegeStaffV1ServiceDao;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 import java.util.Map;
@@ -108,5 +104,26 @@ public class DataPrivilegeStaffV1ServiceDaoImpl extends BaseServiceDao implement
         return Integer.parseInt(businessDataPrivilegeStaffInfos.get(0).get("count").toString());
     }
 
+    @Override
+    public int queryStaffsNotInDataPrivilegeCount(Map info) {
+        logger.debug("查询 queryStaffsNotInDataPrivilegeCount 入参 info : {}",info);
+
+        List<Map> businessDataPrivilegeStaffInfos = sqlSessionTemplate.selectList("dataPrivilegeStaffV1ServiceDaoImpl.queryStaffsNotInDataPrivilegeCount", info);
+        if (businessDataPrivilegeStaffInfos.size() < 1) {
+            return 0;
+        }
+
+        return Integer.parseInt(businessDataPrivilegeStaffInfos.get(0).get("count").toString());
+    }
+
+    @Override
+    public List<Map> queryStaffsNotInDataPrivilege(Map info) {
+        logger.debug("查询 queryStaffsNotInDataPrivilege 入参 info : {}",info);
+
+        List<Map> datas = sqlSessionTemplate.selectList("dataPrivilegeStaffV1ServiceDaoImpl.queryStaffsNotInDataPrivilege",info);
+
+        return datas;
+    }
+
 
 }

+ 24 - 2
service-community/src/main/java/com/java110/community/smo/impl/DataPrivilegeStaffV1InnerServiceSMOImpl.java

@@ -13,10 +13,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.java110.community.smo.impl;
+package com.java110.user.smo.impl;
 
 
-import com.java110.community.dao.IDataPrivilegeStaffV1ServiceDao;
+import com.java110.user.dao.IDataPrivilegeStaffV1ServiceDao;
 import com.java110.intf.community.IDataPrivilegeStaffV1InnerServiceSMO;
 import com.java110.dto.dataPrivilegeStaff.DataPrivilegeStaffDto;
 import com.java110.po.dataPrivilegeStaff.DataPrivilegeStaffPo;
@@ -86,4 +86,26 @@ public class DataPrivilegeStaffV1InnerServiceSMOImpl extends BaseServiceSMO impl
     public int queryDataPrivilegeStaffsCount(@RequestBody DataPrivilegeStaffDto dataPrivilegeStaffDto) {
         return dataPrivilegeStaffV1ServiceDaoImpl.queryDataPrivilegeStaffsCount(BeanConvertUtil.beanCovertMap(dataPrivilegeStaffDto));    }
 
+    @Override
+    public int queryStaffsNotInDataPrivilegeCount(@RequestBody DataPrivilegeStaffDto dataPrivilegeStaffDto) {
+        return dataPrivilegeStaffV1ServiceDaoImpl.queryStaffsNotInDataPrivilegeCount(BeanConvertUtil.beanCovertMap(dataPrivilegeStaffDto));
+    }
+
+    @Override
+    public List<UserDto> queryStaffsNotInDataPrivilege(@RequestBody DataPrivilegeStaffDto dataPrivilegeStaffDto) {
+
+        int page = dataPrivilegeStaffDto.getPage();
+
+        if (page != PageDto.DEFAULT_PAGE) {
+            dataPrivilegeStaffDto.setPage((page - 1) * dataPrivilegeStaffDto.getRow());
+        }
+
+        List<UserDto> privilegeUsers = BeanConvertUtil.covertBeanList(
+                dataPrivilegeStaffV1ServiceDaoImpl.queryStaffsNotInDataPrivilege(BeanConvertUtil.beanCovertMap(dataPrivilegeStaffDto))
+                , UserDto.class);
+
+        return privilegeUsers;
+
+    }
+
 }