选择车队不一致修改

This commit is contained in:
秦鸿展
2026-01-19 15:32:00 +08:00
parent ff334b155c
commit 7f8732dd02
8 changed files with 127 additions and 118 deletions
@@ -196,16 +196,16 @@
<if test="expenseAccountDO.organizationId != null"> <if test="expenseAccountDO.organizationId != null">
<!-- 如果设置了 organizationId,添加 organization_id 条件 --> <!-- 如果设置了 organizationId,添加 organization_id 条件 -->
and a.organization_id = #{expenseAccountDO.organizationId} and a.organization_id = #{expenseAccountDO.organizationId}
and a.organization_name IS NOT NULL -- and a.organization_name IS NOT NULL
and a.organization_name != '' -- and a.organization_name != ''
and LENGTH(TRIM(a.organization_name)) > 0 -- and LENGTH(TRIM(a.organization_name)) > 0
</if> </if>
<if test="expenseAccountDO.topOrganizationId != null and expenseAccountDO.organizationId == null"> <if test="expenseAccountDO.topOrganizationId != null and expenseAccountDO.organizationId == null">
<!-- 如果设置了 topOrganizationId 但没有设置 organizationId,添加 top_organization_id 条件 --> <!-- 如果设置了 topOrganizationId 但没有设置 organizationId,添加 top_organization_id 条件 -->
and a.top_organization_id = #{expenseAccountDO.topOrganizationId} and a.top_organization_id = #{expenseAccountDO.topOrganizationId}
and a.organization_name IS NOT NULL -- and a.organization_name IS NOT NULL
and a.organization_name != '' -- and a.organization_name != ''
and LENGTH(TRIM(a.organization_name)) > 0 -- and LENGTH(TRIM(a.organization_name)) > 0
</if> </if>
<if test="expenseAccountDO.organizationName != null and expenseAccountDO.organizationName != ''"> <if test="expenseAccountDO.organizationName != null and expenseAccountDO.organizationName != ''">
and a.organization_name like concat('%', #{expenseAccountDO.organizationName}, '%') and a.organization_name like concat('%', #{expenseAccountDO.organizationName}, '%')
@@ -8,36 +8,36 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectServiceItemsManagePo1"> <sql id="selectServiceItemsManagePo1">
<where> <where>
<!-- 删除标记:0-无状态,1-正常,2-已删除,查询时只查询正常的数据 --> <!-- &lt;!&ndash; 删除标记:0-无状态,1-正常,2-已删除,查询时只查询正常的数据 &ndash;&gt;-->
<choose> <!-- <choose>-->
<when test="delFlag != null"> <!-- <when test="delFlag != null">-->
and del_flag = #{delFlag} <!-- and del_flag = #{delFlag}-->
</when> <!-- </when>-->
<otherwise> <!-- <otherwise>-->
and del_flag = 1 <!-- and del_flag = 1-->
</otherwise> <!-- </otherwise>-->
</choose> <!-- </choose>-->
<if test="createByName != null and createByName != ''"> <!-- <if test="createByName != null and createByName != ''">-->
and create_by_name like concat('%', #{createByName}, '%') <!-- and create_by_name like concat('%', #{createByName}, '%')-->
</if> <!-- </if>-->
<if test="updateByName != null and updateByName != ''"> <!-- <if test="updateByName != null and updateByName != ''">-->
and update_by_name like concat('%', #{updateByName}, '%') <!-- and update_by_name like concat('%', #{updateByName}, '%')-->
</if> <!-- </if>-->
<!-- 数据权限:南光组织(organizationId=2827)查全部,其他组织查自己 --> <!-- 数据权限:南光组织(organizationId=2827)查全部,其他组织查自己 -->
<!-- 如果 organizationId 和 topOrganizationId 都为 null,表示查询所有组织的数据(不添加组织过滤条件) --> <!-- 如果 organizationId 和 topOrganizationId 都为 null,表示查询所有组织的数据(不添加组织过滤条件) -->
<if test="organizationId != null"> <if test="organizationId != null">
<!-- 如果设置了 organizationId,添加 organization_id 条件 --> <!-- 如果设置了 organizationId,添加 organization_id 条件 -->
and organization_id = #{organizationId} and organization_id = #{organizationId}
and organization_name IS NOT NULL -- and organization_name IS NOT NULL
and organization_name != '' -- and organization_name != ''
and LENGTH(TRIM(organization_name)) > 0 -- and LENGTH(TRIM(organization_name)) > 0
</if> </if>
<if test="topOrganizationId != null and organizationId == null"> <if test="topOrganizationId != null and organizationId == null">
<!-- 如果设置了 topOrganizationId 但没有设置 organizationId,添加 top_organization_id 条件 --> <!-- 如果设置了 topOrganizationId 但没有设置 organizationId,添加 top_organization_id 条件 -->
and top_organization_id = #{topOrganizationId} and top_organization_id = #{topOrganizationId}
and organization_name IS NOT NULL -- and organization_name IS NOT NULL
and organization_name != '' -- and organization_name != ''
and LENGTH(TRIM(organization_name)) > 0 -- and LENGTH(TRIM(organization_name)) > 0
</if> </if>
<if test="organizationName != null and organizationName != ''"> <if test="organizationName != null and organizationName != ''">
and organization_name like concat('%', #{organizationName}, '%') and organization_name like concat('%', #{organizationName}, '%')
@@ -86,6 +86,7 @@ public class RoleApplicationService {
// 先保存前端传递的 organizationId(如果存在) // 先保存前端传递的 organizationId(如果存在)
Long frontendOrganizationId = roleDo.getOrganizationId(); Long frontendOrganizationId = roleDo.getOrganizationId();
log.info("角色查询 - 初始 roleDo.getOrganizationId(): {}", frontendOrganizationId);
// 获取登录用户信息 // 获取登录用户信息
Long loginUserOrganizationId = null; Long loginUserOrganizationId = null;
@@ -94,6 +95,12 @@ public class RoleApplicationService {
loginUserOrganizationId = userPo.getOrganizationId(); loginUserOrganizationId = userPo.getOrganizationId();
topOrganizationId = userPo.getTopOrganizationId(); topOrganizationId = userPo.getTopOrganizationId();
} }
log.info("角色查询 - 当前登录用户组织ID: {}", loginUserOrganizationId);
// 先保存前端传递的 organizationId(如果存在)
// 因为后续的 BeanUtils.copyProperties 可能会覆盖掉前端传递的值
Long savedFrontendOrganizationId = frontendOrganizationId;
log.info("角色查询 - 保存的前端 organizationId: {}", savedFrontendOrganizationId);
if (userPo.getUserAccountType() != null && userPo.getUserAccountType() == 5){ if (userPo.getUserAccountType() != null && userPo.getUserAccountType() == 5){
roleDo.setCreateBy(userPo.getCreateBy()); roleDo.setCreateBy(userPo.getCreateBy());
@@ -102,29 +109,30 @@ public class RoleApplicationService {
userDataPermissionQueryDTO.setPermissionMenuId(roleDo.getPermissionMenuId()); userDataPermissionQueryDTO.setPermissionMenuId(roleDo.getPermissionMenuId());
userDataPermissionQueryDTO = userDataPermissionApplicationService.getUserDataPermissionQueryDTO(userDataPermissionQueryDTO); userDataPermissionQueryDTO = userDataPermissionApplicationService.getUserDataPermissionQueryDTO(userDataPermissionQueryDTO);
// 在复制属性之前,先保存前端传递的 organizationId(如果存在)
// 因为 BeanUtils.copyProperties 可能会覆盖掉前端传递的值
Long savedFrontendOrganizationId = frontendOrganizationId;
BeanUtils.copyProperties(userDataPermissionQueryDTO, roleDo, IgnoreNullUtil.getNullPropertyNames(userDataPermissionQueryDTO)); BeanUtils.copyProperties(userDataPermissionQueryDTO, roleDo, IgnoreNullUtil.getNullPropertyNames(userDataPermissionQueryDTO));
UserPo loginUserPo = loginUser.getUserPo(); log.info("角色查询 - BeanUtils.copyProperties 后 roleDo.getOrganizationId(): {}", roleDo.getOrganizationId());
}
// 重新获取前端传递的 organizationId(优先使用前端传递的值) UserPo loginUserPo = loginUser.getUserPo();
// 对于南光组织,如果前端传递了 organizationId,必须使用前端传递的值
Long currentFrontendOrganizationId = savedFrontendOrganizationId != null ? savedFrontendOrganizationId : roleDo.getOrganizationId();
// 数据权限:查询权限根据 organizationId 来设置,与其他模块保持一致 // 数据权限:查询权限根据 organizationId 来设置,与其他模块保持一致
// organizationId等于2827时,为南光组织,查所有;其他组织查自己 // organizationId等于2827时,为南光组织,查所有;其他组织查自己
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) { if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织(organizationId=2827):可以查询所有组织的数据 // 南光组织(organizationId=2827):可以查询所有组织的数据
// 如果前端传递了 organizationId(包括2827,使用前端传递的值进行过滤 // 如果前端传递了 organizationId 且不等于当前登录用户的组织ID,使用前端传递的值进行过滤
// 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 // 如果前端没有传递 organizationId或者传递的值等于当前登录用户的组织ID,清空组织过滤条件,查询所有组织的数据
if (currentFrontendOrganizationId != null) { log.info("角色查询 - 南光组织,savedFrontendOrganizationId: {}", savedFrontendOrganizationId);
// 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 if (savedFrontendOrganizationId != null && !savedFrontendOrganizationId.equals(loginUserOrganizationId)) {
roleDo.setOrganizationId(currentFrontendOrganizationId); // 前端传递了其他组织的 organizationId(不等于2827),使用前端传递的值进行过滤
log.info("角色查询 - 南光组织:使用前端传递的其他组织 organizationId: {}", savedFrontendOrganizationId);
roleDo.setOrganizationId(savedFrontendOrganizationId);
roleDo.setTopOrganizationId(null); roleDo.setTopOrganizationId(null);
} else { } else {
// 前端没有传递 organizationId清空组织过滤条件,查询所有组织的数据 // 前端没有传递 organizationId或者传递的值等于当前登录用户的组织ID(2827),
// 清空组织过滤条件,查询所有组织的数据
// 注意:这里必须清空 organizationId,不能使用 roleDo.getOrganizationId()
// 因为 roleDo.getOrganizationId() 可能被 BeanUtils.copyProperties 从其他地方复制过来
log.info("角色查询 - 南光组织:前端未传递 organizationId 或传递的值等于当前登录用户组织ID,清空组织过滤条件,查询所有组织的数据");
roleDo.setOrganizationId(null); roleDo.setOrganizationId(null);
roleDo.setTopOrganizationId(null); roleDo.setTopOrganizationId(null);
} }
@@ -137,6 +145,8 @@ public class RoleApplicationService {
} else { } else {
// 其他组织:设置organizationId,只查询当前组织的数据 // 其他组织:设置organizationId,只查询当前组织的数据
// 其他组织只能查询自己组织的数据,不能查询其他组织的数据 // 其他组织只能查询自己组织的数据,不能查询其他组织的数据
// 重新获取前端传递的 organizationId(优先使用前端传递的值)
Long currentFrontendOrganizationId = savedFrontendOrganizationId != null ? savedFrontendOrganizationId : roleDo.getOrganizationId();
if (currentFrontendOrganizationId != null) { if (currentFrontendOrganizationId != null) {
// 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致
if (!currentFrontendOrganizationId.equals(loginUserOrganizationId)) { if (!currentFrontendOrganizationId.equals(loginUserOrganizationId)) {
@@ -156,7 +166,6 @@ public class RoleApplicationService {
} }
//roleDo.setRoleGrade(2); //roleDo.setRoleGrade(2);
} }
}
return roleDomainService.selecRolePoList(roleDo); return roleDomainService.selecRolePoList(roleDo);
} }
@@ -167,7 +176,9 @@ public class RoleApplicationService {
*/ */
@DataPermissions(cacheName = "wlhyRole_createBy") @DataPermissions(cacheName = "wlhyRole_createBy")
public List<RolePO> getUserRolelist(RoleDo roleDo) {//获取登录人信息 public List<RolePO> getUserRolelist(RoleDo roleDo) {//获取登录人信息
return roleDomainService.selecRolePoList(roleDo); // 调用应用服务层的方法,包含数据权限控制逻辑
// 当前登录用户组织ID为2827时查询全部组织信息,其他组织只查自己
return selecRolePoList(roleDo);
} }
public List<RolePO> queryList(RoleDo roleDo) { public List<RolePO> queryList(RoleDo roleDo) {
@@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@@ -57,9 +58,20 @@ public class RoleAPI extends BaseController {
@Log(title = "职务/角色管理-查询", description ="查询角色列表",businessType = BusinessType.INQUIRE) @Log(title = "职务/角色管理-查询", description ="查询角色列表",businessType = BusinessType.INQUIRE)
@ApiOperation("查询角色列表-分页") @ApiOperation("查询角色列表-分页")
@GetMapping("/getUserRolelist") @GetMapping("/getUserRolelist")
public TableDataInfo getUserRolelist(RoleDTO roleDTO) { public TableDataInfo getUserRolelist(RoleDTO roleDTO, HttpServletRequest request) {
// 检查前端是否明确传递了 organizationId 参数
// 如果前端没有传递,清空 roleDTO 中的 organizationId,避免从其他地方自动设置的值影响查询
String organizationIdParam = request.getParameter("organizationId");
log.info("角色查询接口 - 前端传递的 organizationId 参数: {}", organizationIdParam);
if (organizationIdParam == null || organizationIdParam.isEmpty()) {
log.info("角色查询接口 - 前端未传递 organizationId,清空 roleDTO.organizationId");
roleDTO.setOrganizationId(null);
} else {
log.info("角色查询接口 - 前端传递了 organizationId: {}", organizationIdParam);
}
//转换实体 //转换实体
RoleDo roleDo = roleAssember.toRoleDo(roleDTO); RoleDo roleDo = roleAssember.toRoleDo(roleDTO);
log.info("角色查询接口 - 转换后 roleDo.getOrganizationId(): {}", roleDo.getOrganizationId());
startPage(); startPage();
List<RolePO> list = roleApplicationService.getUserRolelist(roleDo); List<RolePO> list = roleApplicationService.getUserRolelist(roleDo);
return getDataTable(list); return getDataTable(list);
@@ -17,4 +17,10 @@ public class NonePagingListVO {
@ApiModelProperty(value = "车队名称") @ApiModelProperty(value = "车队名称")
private String motorcadeName; private String motorcadeName;
@ApiModelProperty(value = "组织ID")
private Long organizationId;
@ApiModelProperty(value = "组织名称")
private String organizationName;
} }
@@ -380,31 +380,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
group by u.user_id group by u.user_id
</select> </select>
<select id="queryNonePagingList" resultType="com.mhd.user.domain.motorcade.repository.po.MotorcadePo"> <select id="queryNonePagingList" resultType="com.mhd.user.domain.motorcade.repository.po.MotorcadePo">
SELECT SELECT DISTINCT
m.motorcade_id, m.motorcade_id,
m.motorcade_name m.motorcade_name,
m.organization_id,
m.organization_name
FROM FROM
motorcade m motorcade m
LEFT JOIN INNER JOIN
motorcade_driver d motorcade_driver d
ON m.motorcade_id = d.motorcade_id and d.del_flag = 1 ON m.motorcade_id = d.motorcade_id and d.del_flag = 1
INNER JOIN
user_driver ud
ON d.user_id = ud.user_id and ud.del_flag = 1
LEFT JOIN
user_driver_enterprise ude
ON ud.user_id = ude.user_id and ude.del_flag = 1
<where> <where>
m.del_flag = 1 m.del_flag = 1
<!-- 数据权限:南光组织(organizationId=2827)查全部,其他组织查自己 --> <!-- 数据权限:南光组织(organizationId=2827)查全部,其他组织查自己 -->
<if test="organizationId != null"> <if test="organizationId != null">
<!-- 如果设置了 organizationId,添加 organization_id 条件 --> <!-- 如果设置了 organizationId,添加 organization_id 条件 -->
and m.organization_id = #{organizationId} and m.organization_id = #{organizationId}
and m.organization_name IS NOT NULL
</if>
<if test="topOrganizationId != null">
<!-- 如果设置了 topOrganizationId,添加 top_organization_id 条件 -->
and m.top_organization_id = #{topOrganizationId}
<if test="organizationId == null">
<!-- 如果没有设置 organizationId,添加 organization_name IS NOT NULL 条件 -->
and m.organization_name IS NOT NULL
</if>
</if> </if>
</where> </where>
ORDER BY m.motorcade_id
</select> </select>
</mapper> </mapper>
@@ -122,13 +122,13 @@
</if> </if>
<if test="organizationId !=null"> <if test="organizationId !=null">
and a.organization_id = #{organizationId} and a.organization_id = #{organizationId}
and a.organization_name IS NOT NULL -- and a.organization_name IS NOT NULL
</if> </if>
<if test="topOrganizationId !=null"> <if test="topOrganizationId !=null">
and a.top_organization_id = #{topOrganizationId} and a.top_organization_id = #{topOrganizationId}
<if test="organizationId == null"> <!-- <if test="organizationId == null">-->
and a.organization_name IS NOT NULL <!-- and a.organization_name IS NOT NULL-->
</if> <!-- </if>-->
</if> </if>
<if test="organizationName != null and organizationName != ''"> <if test="organizationName != null and organizationName != ''">
and a.organization_name like concat('%' , #{organizationName} , '%') and a.organization_name like concat('%' , #{organizationName} , '%')
@@ -185,27 +185,13 @@
ude.driver_corp_legal_name, ude.driver_corp_legal_name,
ude.driver_corp_name, ude.driver_corp_name,
ude.driver_corp_idcard_number, ude.driver_corp_idcard_number,
r.roleName, b.role_name AS roleName,
dvb.vehicle_id, dvb.vehicle_id,
wlhydriver.id as wlhydriverId, wlhydriver.id as wlhydriverId,
WM_CONCAT(DISTINCT dvb.vehicle_license_plate_number ) AS vehicleLicensePlateNumber, WM_CONCAT(DISTINCT dvb.vehicle_license_plate_number ) AS vehicleLicensePlateNumber,
WM_CONCAT(DISTINCT m.motorcade_name ) AS driverTeamName WM_CONCAT(DISTINCT m.motorcade_name ) AS driverTeamName
FROM FROM
"USER" b "USER" b
LEFT JOIN (
SELECT
user_id,
LISTAGG(DISTINCT r.role_name, '&amp;') WITHIN GROUP(ORDER BY r.role_name) AS roleName
FROM
role r
LEFT JOIN user_role ur ON r.role_id = ur.role_id
AND ur.del_flag = 1
WHERE
r.del_flag = 1
AND role_code IN ( 'driver', 'carrier', 'captain' )
GROUP BY
user_id
) r ON r.user_id = b.user_id
LEFT JOIN user_driver a ON a.user_id = b.user_id LEFT JOIN user_driver a ON a.user_id = b.user_id
LEFT JOIN NGWL_TEST_WLHY.sys_user wlhyuser ON wlhyuser.szwl_user_id = b.user_id LEFT JOIN NGWL_TEST_WLHY.sys_user wlhyuser ON wlhyuser.szwl_user_id = b.user_id
LEFT JOIN NGWL_TEST_WLHY.tms_driver wlhydriver ON wlhydriver.driver_id = wlhyuser.id LEFT JOIN NGWL_TEST_WLHY.tms_driver wlhydriver ON wlhydriver.driver_id = wlhyuser.id
@@ -220,7 +206,7 @@
left join motorcade m on md.motorcade_id = m.motorcade_id and m.del_flag = 1 left join motorcade m on md.motorcade_id = m.motorcade_id and m.del_flag = 1
LEFT JOIN motorcade mo ON a.driver_id = mo.motorcade_header_id LEFT JOIN motorcade mo ON a.driver_id = mo.motorcade_header_id
AND m.del_flag = 1 AND mo.del_flag = 1
left join motorcade_driver mdr on mo.motorcade_id = mdr.motorcade_id and mdr.del_flag = 1 left join motorcade_driver mdr on mo.motorcade_id = mdr.motorcade_id and mdr.del_flag = 1
WHERE WHERE
b.del_flag = 1 b.del_flag = 1
@@ -353,12 +339,6 @@
select count(1) select count(1)
from ( select b.user_id from ( select b.user_id
from "USER" b from "USER" b
left join (select user_id, WM_CONCAT(r.role_name separator '&amp;') roleName
from role r
left join user_role ur on r.role_id = ur.role_id and ur.del_flag = 1
where r.del_flag = 1
and role_code in ('driver', 'carrier', 'captain', 'must')
group by user_id) r on r.user_id = b.user_id
left join user_driver a on a.user_id = b.user_id left join user_driver a on a.user_id = b.user_id
left join user_driver_enterprise ude on b.user_id = ude.user_id and ude.driver_type = 1 left join user_driver_enterprise ude on b.user_id = ude.user_id and ude.driver_type = 1
left join user_driver_enterprise ud on b.user_id = ud.user_id and ud.driver_type = 2 left join user_driver_enterprise ud on b.user_id = ud.user_id and ud.driver_type = 2
@@ -558,7 +538,7 @@
</if> </if>
/*角色*/ /*角色*/
<if test="userDriverDO.roleName != null and userDriverDO.roleName != ''"> <if test="userDriverDO.roleName != null and userDriverDO.roleName != ''">
AND r.roleName like concat('%', #{userDriverDO.roleName}, '%') AND b.role_name like concat('%', #{userDriverDO.roleName}, '%')
</if> </if>
/*车牌号*/ /*车牌号*/
<if test="userDriverDO.vehicleLicensePlateNumber != null and userDriverDO.vehicleLicensePlateNumber != ''"> <if test="userDriverDO.vehicleLicensePlateNumber != null and userDriverDO.vehicleLicensePlateNumber != ''">