销售权限控制修改
This commit is contained in:
+3
@@ -57,6 +57,9 @@ public class BmsCustomer extends BaseEntity
|
||||
@Excel(name = "业务员姓名")
|
||||
private String salesUser;
|
||||
|
||||
/** 业务员昵称(join sys_user.nick_name,sales_user_id 存工号=sys_user.user_name) */
|
||||
private String salesUserNickName;
|
||||
|
||||
/** 资金额度(元) */
|
||||
@Excel(name = "资金额度", readConverterExp = "元=")
|
||||
private BigDecimal ed;
|
||||
|
||||
+2
-1
@@ -65,7 +65,8 @@ public class BmsCustomerServiceImpl implements IBmsCustomerService
|
||||
* @return 客户主
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "su", deptField = "dept_id", userAlias = "c", userField = "sales_user_id")
|
||||
// sales_user_id 存的是员工工号(=sys_user.user_name),仅本人/本部门均通过 sys_user 别名 su 关联匹配
|
||||
@DataScope(deptAlias = "su", deptField = "dept_id", userAlias = "su", userField = "user_id")
|
||||
public List<BmsCustomer> selectBmsCustomerList(BmsCustomer bmsCustomer)
|
||||
{
|
||||
return bmsCustomerMapper.selectBmsCustomerList(bmsCustomer);
|
||||
|
||||
@@ -156,7 +156,8 @@ public class OrgSyncService
|
||||
r.setRoleName(truncate(name, 30));
|
||||
r.setRoleKey("ORA_" + rid);
|
||||
r.setRoleSort(sort++);
|
||||
r.setDataScope("1");
|
||||
// 销售类角色默认数据范围:销售经理=本部门数据(3);销售员=仅本人数据(5);其余角色=全部数据(1)
|
||||
r.setDataScope(defaultDataScope(rid));
|
||||
r.setMenuCheckStrictly(true);
|
||||
r.setDeptCheckStrictly(true);
|
||||
r.setStatus("0");
|
||||
@@ -169,6 +170,23 @@ public class OrgSyncService
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步角色的默认数据范围(RuoYi:1全部 2自定义 3本部门 4本部门及以下 5仅本人)。
|
||||
* 6040 销售经理=本部门,6041 销售员=仅本人;其他角色默认全部(可在角色管理中调整)。
|
||||
*/
|
||||
private static String defaultDataScope(Long oracleRoleId)
|
||||
{
|
||||
if (Long.valueOf(6040L).equals(oracleRoleId))
|
||||
{
|
||||
return "3";
|
||||
}
|
||||
if (Long.valueOf(6041L).equals(oracleRoleId))
|
||||
{
|
||||
return "5";
|
||||
}
|
||||
return "1";
|
||||
}
|
||||
|
||||
private List<SysUser> buildUsers(List<Map<String, Object>> rows, Map<String, Long> deptIdByCode)
|
||||
{
|
||||
List<SysUser> list = new ArrayList<>();
|
||||
|
||||
@@ -14,6 +14,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="isEnable" column="is_enable" />
|
||||
<result property="salesUserId" column="sales_user_id" />
|
||||
<result property="salesUser" column="sales_user" />
|
||||
<result property="salesUserNickName" column="sales_user_nick_name" />
|
||||
<result property="ed" column="ed" />
|
||||
<result property="zq" column="zq" />
|
||||
<result property="settlementUserId" column="settlement_user_id" />
|
||||
@@ -52,11 +53,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
where ca.customer_id = c.customer_id and ca.del_flag = '0') as credit_ed,
|
||||
|
||||
c.product_codes, c.remark,
|
||||
c.create_by, c.create_time, c.update_by, c.update_time, c.del_flag
|
||||
c.create_by, c.create_time, c.update_by, c.update_time, c.del_flag,
|
||||
su.nick_name as sales_user_nick_name
|
||||
from ctr_customer c
|
||||
<!-- 数据权限:销售(仅本人 c.sales_user_id)/销售经理(本部门 su.dept_id);
|
||||
历史迁移数据 sales_user_id 为非数字工号,+0 后不匹配任何 sys_user,仅管理员可见 -->
|
||||
left join sys_user su on su.user_id = c.sales_user_id + 0
|
||||
<!-- 老系统同步数据 sales_user_id 存员工工号(=sys_user.user_name);
|
||||
BMS 手工新建数据可能存数字 user_id,两种都要能关联上。
|
||||
'WS0052'+0 在 MySQL 中结果为 0,不会误关联到任何用户 -->
|
||||
left join sys_user su
|
||||
on su.del_flag = '0'
|
||||
and (su.user_name = c.sales_user_id or su.user_id = c.sales_user_id + 0)
|
||||
</sql>
|
||||
|
||||
<select id="selectBmsCustomerList" parameterType="BmsCustomer" resultMap="BmsCustomerResult">
|
||||
@@ -93,7 +98,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="throwRatio != null "> and c.throw_ratio = #{throwRatio}</if>
|
||||
<if test="creditEd != null "> and c.credit_ed = #{creditEd}</if>
|
||||
<if test="productCodes != null and productCodes != ''"> and c.product_codes = #{productCodes}</if>
|
||||
<!-- 数据权限过滤(@DataScope 生成:仅本人= c.sales_user_id=当前用户;本部门= su.dept_id=当前用户部门) -->
|
||||
<!-- 数据权限过滤(@DataScope 生成:仅本人= su.user_id=当前用户;本部门= su.dept_id=当前用户部门) -->
|
||||
${params.dataScope}
|
||||
</where>
|
||||
order by c.customer_id desc
|
||||
|
||||
@@ -67,6 +67,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="userName != null and userName != ''">
|
||||
AND u.user_name like concat('%', #{userName}, '%')
|
||||
</if>
|
||||
<if test="nickName != null and nickName != ''">
|
||||
AND u.nick_name like concat('%', #{nickName}, '%')
|
||||
</if>
|
||||
<if test="status != null and status != ''">
|
||||
AND u.status = #{status}
|
||||
</if>
|
||||
|
||||
@@ -4,18 +4,20 @@
|
||||
:placeholder="placeholder"
|
||||
:clearable="clearable"
|
||||
:filterable="filterable"
|
||||
:filter-method="filterMethod"
|
||||
:disabled="disabled"
|
||||
:loading="loading"
|
||||
:size="size"
|
||||
:multiple="false"
|
||||
style="width: 100%;"
|
||||
@change="handleChange"
|
||||
@visible-change="handleVisibleChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in options"
|
||||
:key="item.userId"
|
||||
:label="formatLabel(item)"
|
||||
:value="String(item.userId)"
|
||||
:value="String(item[valueField])"
|
||||
:disabled="item.status === '1'"
|
||||
>
|
||||
<span>{{ item.nickName || item.userName }}<template v-if="item.status === '1'">(停用)</template></span>
|
||||
@@ -61,23 +63,53 @@ const props = defineProps({
|
||||
showCode: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
/** 绑定值字段:userId=用户ID(默认);userName=登录账号/工号(老系统迁移数据按工号存储时使用) */
|
||||
valueField: {
|
||||
type: String,
|
||||
default: 'userId'
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:modelValue', 'change'])
|
||||
|
||||
const { userList, ensureUsers, findUser } = useUsers()
|
||||
const { userList, ensureUsers } = useUsers()
|
||||
const loading = ref(false)
|
||||
/** 下拉搜索关键字(可同时匹配昵称/姓名与登录账号/工号) */
|
||||
const filterQuery = ref('')
|
||||
const innerValue = ref(props.modelValue === null || props.modelValue === undefined ? null : String(props.modelValue))
|
||||
|
||||
watch(() => props.modelValue, (val) => {
|
||||
innerValue.value = val === null || val === undefined || val === '' ? null : String(val)
|
||||
})
|
||||
|
||||
/** 按当前绑定值字段(userId 或 userName/工号)查找用户 */
|
||||
function findByValue(val) {
|
||||
if (val === null || val === undefined || val === '') return null
|
||||
return userList.value.find(u => String(u[props.valueField]) === String(val)) || null
|
||||
}
|
||||
|
||||
/** 自定义过滤:昵称/姓名、登录账号/工号 任一命中即可(忽略大小写) */
|
||||
function matchUser(item, q) {
|
||||
if (!q) return true
|
||||
const kw = q.trim().toLowerCase()
|
||||
if (!kw) return true
|
||||
return ['nickName', 'userName'].some(k => item[k] && String(item[k]).toLowerCase().includes(kw))
|
||||
}
|
||||
|
||||
function filterMethod(q) {
|
||||
filterQuery.value = q || ''
|
||||
}
|
||||
|
||||
/** 下拉收起后清空搜索词,恢复完整选项 */
|
||||
function handleVisibleChange(visible) {
|
||||
if (!visible) filterQuery.value = ''
|
||||
}
|
||||
|
||||
/** 兜底:当前值在用户列表中不存在(停用/未加载到)时补占位项,避免显示空白 */
|
||||
const options = computed(() => {
|
||||
const list = userList.value
|
||||
if (innerValue.value && !findUser(innerValue.value)) {
|
||||
const list = userList.value.filter(item => matchUser(item, filterQuery.value))
|
||||
if (innerValue.value && !findByValue(innerValue.value) && !filterQuery.value) {
|
||||
return [{ userId: innerValue.value, userName: '', nickName: String(innerValue.value) }, ...list]
|
||||
}
|
||||
return list
|
||||
@@ -92,7 +124,7 @@ function formatLabel(item) {
|
||||
function handleChange(val) {
|
||||
const value = val === '' ? null : val
|
||||
emit('update:modelValue', value)
|
||||
emit('change', value, value === null ? null : findUser(value))
|
||||
emit('change', value, value === null ? null : findByValue(value))
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
<el-form-item label="业务员" prop="salesUserId">
|
||||
<user-select
|
||||
v-model="form.salesUserId"
|
||||
value-field="userName"
|
||||
placeholder="请选择业务员"
|
||||
@change="(uid, user) => handleUserChange(uid, user, 'salesUser')"
|
||||
/>
|
||||
|
||||
@@ -32,7 +32,12 @@
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="业务员" prop="salesUserId">
|
||||
<user-select v-model="queryParams.salesUserId" placeholder="请选择业务员" @change="handleQuery" />
|
||||
<user-select
|
||||
v-model="queryParams.salesUserId"
|
||||
value-field="userName"
|
||||
placeholder="工号/姓名搜索"
|
||||
@change="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
|
||||
@@ -122,7 +127,7 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-if="isColVisible('salesUserId')" label="业务员" align="center" prop="salesUserId">
|
||||
<template #default="scope"><user-name :user-id="scope.row.salesUserId" /></template>
|
||||
<template #default="scope">{{ scope.row.salesUserNickName || scope.row.salesUser || scope.row.salesUserId }}</template>
|
||||
</el-table-column>
|
||||
|
||||
<!-- <el-table-column v-if="isColVisible('ed')" label="资金额度" align="center" prop="ed" />-->
|
||||
|
||||
@@ -188,6 +188,7 @@ const extraParams = computed(() => ({ deptId: deptId.value }))
|
||||
// 搜索项配置
|
||||
const searchColumns = [
|
||||
{ label: "用户名称", prop: "userName", component: "input", placeholder: "请输入用户名称", width: "240px" },
|
||||
{ label: "用户昵称", prop: "nickName", component: "input", placeholder: "请输入用户昵称", width: "240px" },
|
||||
{ label: "手机号码", prop: "phonenumber", component: "input", placeholder: "请输入手机号码", width: "240px" },
|
||||
{ label: "状态", prop: "status", component: "select", dict: "sys_normal_disable", placeholder: "用户状态", width: "240px" },
|
||||
{ label: "创建时间", prop: "dateRange", component: "daterange", width: "308px" }
|
||||
|
||||
Reference in New Issue
Block a user