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},