From d5bd2c90904133f19d2819e6bf7a3b900cfddb08 Mon Sep 17 00:00:00 2001 From: liuxiaoxu <1793812695@qq.com> Date: Wed, 30 Oct 2024 15:12:07 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=E5=B7=A5=E7=A8=8B=E7=AE=A1=E7=90=86=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=A2=E6=88=B7=E4=BF=A1=E6=81=AF=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E6=9F=A5=E8=AF=A2=E5=90=8E=E7=AB=AF=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=9A=E5=8E=BB=E6=8E=89=E4=B9=8B=E5=89=8D=E6=B2=A1=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E7=AD=9B=E9=80=89=E5=8F=AA=E6=9C=89=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E5=91=98=E6=89=8D=E8=83=BD=E6=9F=A5=E7=9C=8B=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84=E8=BF=87=E6=BB=A4=E6=9D=A1=E4=BB=B6=E3=80=82=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=A0=B9=E6=8D=AE=E5=BD=93=E5=89=8D=E7=99=BB=E9=99=86?= =?UTF-8?q?=E4=BA=BA=E6=9F=A5=E6=89=BE=E5=AF=B9=E5=BA=94=E7=9A=84=E8=A7=92?= =?UTF-8?q?=E8=89=B2Id=E5=BE=97=E5=88=B0=E6=89=80=E6=9C=89=E7=9A=84?= =?UTF-8?q?=E4=B8=8D=E9=87=8D=E5=A4=8DroleKeys=E7=84=B6=E5=90=8E=E5=85=B3?= =?UTF-8?q?=E8=81=94=E5=AE=A2=E6=88=B7=E4=BF=A1=E6=81=AF=E7=9A=84creatBy?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=AE=9E=E7=8E=B0=E6=B7=BB=E5=8A=A0=E4=BA=BA?= =?UTF-8?q?=E5=8F=8A=E4=B8=8A=E7=BA=A7=E5=8F=AF=E6=9F=A5=E7=9C=8B=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=BA=E7=9A=84=E6=95=B0=E6=8D=AE=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=A7=92=E8=89=B2=E8=BF=87=E6=BB=A4=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=90=8E=E7=AB=AF=E6=96=B9=E6=B3=95=20=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E4=BF=A1=E6=81=AF=E5=AE=9E=E4=BD=93=E7=B1=BB?= =?UTF-8?q?=E5=92=8C=E6=95=B0=E6=8D=AE=E5=BA=93=E8=A1=A8=E6=96=B0=E5=A2=9E?= =?UTF-8?q?createBy=E5=AD=97=E6=AE=B5=EF=BC=8C=E6=96=B0=E5=A2=9E=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E9=9B=86=E5=90=88allowedCreators=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=92=8C=E5=85=B6=E5=AF=B9=E5=BA=94=E7=9A=84get=E3=80=81set?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20=E4=BF=AE=E6=94=B9=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E4=BF=A1=E6=81=AFMapper.xml=E5=B1=82?= =?UTF-8?q?=E7=9A=84=E6=89=80=E6=9C=89=E6=96=B9=E6=B3=95=E5=8A=A0=E4=B8=8A?= =?UTF-8?q?createBy=E5=AD=97=E6=AE=B5=EF=BC=9B=E4=BF=AE=E6=94=B9=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E6=9F=A5=E8=AF=A2=E6=96=B9=E6=B3=95=EF=BC=9A=E5=8A=A0?= =?UTF-8?q?=E4=B8=8A=E5=AF=B9allowedCreators=E9=87=8C=E9=9D=A2=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9A=84=E9=81=8D=E5=8E=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SysCustomerController.java | 24 ++++++++++++++----- .../com/ruoyi/system/domain/SysCustomer.java | 13 ++++++++++ .../system/service/ISysCustomerService.java | 6 +++++ .../service/impl/SysCustomerServiceImpl.java | 23 ++++++++++++++++++ .../mapper/system/SysCustomerMapper.xml | 16 +++++++++---- 5 files changed, 72 insertions(+), 10 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysCustomerController.java b/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysCustomerController.java index ac0f692f..42f60f60 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysCustomerController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysCustomerController.java @@ -44,6 +44,7 @@ import javax.servlet.http.HttpSession; import java.io.IOException; import java.net.URLEncoder; import java.util.*; +import java.util.stream.Collectors; /** * 客户基本信息Controller @@ -104,15 +105,26 @@ public class SysCustomerController extends BaseController @ResponseBody public TableDataInfo list(SysCustomerVo sysCustomerVo) { - SysUser curUser = ShiroUtils.getSysUser(); - Long userId = curUser.getUserId(); - Set roleKeys = roleService.selectRoleKeys(userId); - // 业务员角色只能看到自己创建的数据 - if (roleKeys.contains("ywyRole")) { - sysCustomerVo.setApplyUser(curUser.getLoginName()); + + Long userId = ShiroUtils.getUserId(); + List sysUserRoles = userService.selectUserRoleByUserId(userId); + //得到所有的不重复roleKeys + Set roleKeys = sysUserRoles.stream() + .map(SysUserRole::getRoleId) + .map(roleService::selectRoleById) + .map(SysRole::getRoleKey) + .collect(Collectors.toSet()); + + Set allowedCreators = sysCustomerService.getAllowedCreators(roleKeys); + + // 设置可查看的创建者 + if (!allowedCreators.isEmpty()) { + sysCustomerVo.setAllowedCreators(new ArrayList<>(allowedCreators)); } + startPage(); List list = sysCustomerService.selectSysCustomerList(sysCustomerVo); + return getDataTable(list); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysCustomer.java b/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysCustomer.java index feb73f1a..e0bb762d 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysCustomer.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysCustomer.java @@ -293,6 +293,9 @@ public class SysCustomer extends BaseEntity private String customerId; + /** 角色权限*/ + private List allowedCreators; + public String getCustomerSign() { return customerSign; } @@ -778,6 +781,14 @@ public class SysCustomer extends BaseEntity this.customerId = customerId; } + public List getAllowedCreators() { + return allowedCreators; + } + + public void setAllowedCreators(List allowedCreators) { + this.allowedCreators = allowedCreators; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) @@ -828,6 +839,8 @@ public class SysCustomer extends BaseEntity .append("customerName",getCustomerName()) .append("createTime", getCreateTime()) .append("cancelRemark",getCancelRemark()) + .append("allowedCreators",getAllowedCreators()) .toString(); } + } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysCustomerService.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysCustomerService.java index b92f35a3..f8030bef 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysCustomerService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysCustomerService.java @@ -9,6 +9,7 @@ import org.activiti.engine.runtime.ProcessInstance; import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.Set; /** * 客户基本信息Service接口 @@ -126,4 +127,9 @@ public interface ISysCustomerService * 根据客户名称查询客户信息 * */ SysCustomer selectSysCustomerByEnterpriseName(String enterpriseName); + + /** + * 角色过滤数据 + * */ + Set getAllowedCreators(Set roleKeys); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysCustomerServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysCustomerServiceImpl.java index 9c304744..2646ec22 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysCustomerServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysCustomerServiceImpl.java @@ -182,6 +182,29 @@ public class SysCustomerServiceImpl implements ISysCustomerService return sysCustomerMapper.selectSysCustomerByEnterpriseName(enterpriseName); } + + /** + * 角色过滤数据 + * */ + @Override + public Set getAllowedCreators(Set roleKeys) { + Set allowedCreators = new HashSet<>(); + if (roleKeys.contains("ywyRole")) { + allowedCreators.add(ShiroUtils.getLoginName()); // 只能看到自己的数据 + } + if (roleKeys.contains("ywzgRole")) { + allowedCreators.add("sales_m2"); + allowedCreators.add("sales_01"); + } + if (roleKeys.contains("ywjlRole")) { + allowedCreators.add("sales_m2"); + allowedCreators.add("sales_01"); + allowedCreators.add("sales_m1"); + } + + return allowedCreators; + } + /** * 新增客户基本信息 * diff --git a/ruoyi-admin/src/main/resources/mapper/system/SysCustomerMapper.xml b/ruoyi-admin/src/main/resources/mapper/system/SysCustomerMapper.xml index 03ccc6d0..09f9cf11 100644 --- a/ruoyi-admin/src/main/resources/mapper/system/SysCustomerMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/system/SysCustomerMapper.xml @@ -48,6 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -64,7 +65,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select id,enterprise_code,enterprise_name,english_name,customer_abbreviation ,customer_purser , @@ -74,7 +74,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" customer_contact_id,customer_contact,customer_office,contact_number,customer_email,customer_fax, delivery_address_id,delivery_customer_person,delivery_customer_phone, delivery_address,delivery_customer_postal,delivery_customer_fax,business_members, - identifying_people,first_add_time,update_info_time, create_time ,audit_status,use_status,update_by, update_time,rmb_flag,usd_flag, cancel_remark, + identifying_people,first_add_time,update_info_time, create_time ,audit_status,use_status,update_by, create_by,update_time,rmb_flag,usd_flag, cancel_remark, apply_user,apply_time , instance_id , instance_type from sys_customer @@ -86,7 +86,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" customer_contact_id,customer_contact,customer_office,contact_number,customer_email,customer_fax, delivery_address_id,delivery_customer_person,delivery_customer_phone, delivery_address,delivery_customer_postal,delivery_customer_fax,business_members,rmb_flag,usd_flag, - identifying_people,first_add_time,update_info_time,audit_status,use_status, create_time,update_time from + identifying_people,first_add_time,update_info_time,audit_status,use_status, create_by,create_time,update_time from sys_customer and audit_status = '1' and use_status = '1' @@ -102,7 +102,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" s.customs_code,s.customer_contact_id,s.customer_contact,s.customer_office,s.contact_number,s.customer_email, s.customer_fax,s.delivery_address_id,s.delivery_customer_person,s.delivery_customer_phone,s.delivery_address, s.delivery_customer_postal,s.delivery_customer_fax,s.business_members,s.identifying_people,s.first_add_time, - s.update_info_time,s.audit_status,s.use_status,s.update_by,s.instance_id, s.instance_type,p.dict_value as instance_type_name, + s.update_info_time,s.audit_status,s.use_status,s.update_by, s.create_by,s.instance_id, s.instance_type,p.dict_value as instance_type_name, s.submit_instance_id, s.cancel_instance_id, s.restore_instance_id, s.apply_title, s.apply_user, s.apply_time ,s.create_time,s.update_time ,s.rmb_flag,s.usd_flag from sys_customer as s left join( @@ -122,6 +122,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and s.delivery_address like concat('%', #{deliveryAddress}, '%') and s.create_time between #{params.beginCreateTime} and #{params.endCreateTime} and s.customer_sign = #{customerSign} + + + and s.create_by in ( + #{item} + ) + order by s.audit_status asc, s.create_time desc @@ -225,6 +231,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" usd_flag, cancel_remark, customer_sign, + create_by, #{enterpriseCode}, @@ -281,6 +288,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{usdFlag}, #{cancelRemark}, #{customerSign}, + #{createBy},