Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
hjx
2026-01-13 14:16:55 +08:00
5 changed files with 34 additions and 9 deletions
@@ -58,21 +58,35 @@ public class ExpenseAccountApplicationService {
setDataPermission(expenseAccountDO);
// 处理 createByName 和 updateByName 字段:
// 问题:ExpenseAccountAssembler 在查询场景下会自动设置 createByName 和 updateByName 为当前登录用户名
// 问题:ExpenseAccountAssembler 在查询场景下可能会自动设置 createByName 和 updateByName 为当前登录用户名
// 这会导致 SQL 中添加 create_by_name LIKE '%nanguang%' 和 update_by_name LIKE '%nanguang%' 条件
// 解决方案:
// 1. 如果查询所有组织(organizationId 和 topOrganizationId 都为 null),清空这些字段
// 1. 如果查询所有组织(organizationId 和 topOrganizationId 都为 null),清空这些字段(除非前端明确传递了这些字段作为查询条件)
// 2. 如果查询指定组织(organizationId 不为 null),且是南光组织查询,如果 createByName 或 updateByName 等于当前登录用户名,清空它们
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
String currentUserName = loginUser.getUsername();
// 先保存前端传递的 createByName 和 updateByName(用于判断是否是前端传递的查询条件)
String frontendCreateByName = expenseAccountDO.getCreateByName();
String frontendUpdateByName = expenseAccountDO.getUpdateByName();
if (expenseAccountDO.getOrganizationId() == null && expenseAccountDO.getTopOrganizationId() == null) {
// 查询所有组织的数据时,不应该通过创建者或更新者来过滤,清空这些字段
log.info("查询所有组织数据,清空 createByName 和 updateByName 过滤条件,避免限制查询结果");
expenseAccountDO.setCreateByName(null);
expenseAccountDO.setUpdateByName(null);
// 除非前端明确传递了这些字段作为查询条件
if (frontendCreateByName == null || frontendCreateByName.isEmpty() ||
(currentUserName != null && frontendCreateByName.equals(currentUserName))) {
// 前端未传递,或者等于当前登录用户名(可能是 Assembler 自动设置的),清空
log.info("查询所有组织数据,清空 createByName 过滤条件(前端未传递或由 Assembler 自动设置)");
expenseAccountDO.setCreateByName(null);
}
if (frontendUpdateByName == null || frontendUpdateByName.isEmpty() ||
(currentUserName != null && frontendUpdateByName.equals(currentUserName))) {
// 前端未传递,或者等于当前登录用户名(可能是 Assembler 自动设置的),清空
log.info("查询所有组织数据,清空 updateByName 过滤条件(前端未传递或由 Assembler 自动设置)");
expenseAccountDO.setUpdateByName(null);
}
} else if (expenseAccountDO.getOrganizationId() != null && loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织查询指定组织时,如果 createByName 或 updateByName 等于当前登录用户名,说明可能是 Assembler 自动设置的
// 清空这些字段,避免限制查询结果(因为其他组织的数据可能不是当前登录用户创建的)
@@ -102,7 +102,7 @@
WHERE
a.del_flag = 1
<include refid="common_where"/>
order by a.account_type,service_items_code,upper_subject_code,show_seq
order by a.update_time DESC
</select>
<select id="selectCostSubject" parameterType="com.mhd.basic.domain.expenseAccount.repository.todo.ExpenseAccountDO"
resultType="com.mhd.basic.domain.expenseAccount.repository.po.ExpenseAccountPO">
@@ -146,10 +146,12 @@ public class UserShipperApplicationService {
// 前端传递了 organizationId,使用前端传递的值进行过滤
userShipperDO.setOrganizationId(frontendOrganizationId);
userShipperDO.setTopOrganizationId(null);
log.info("托运人列表查询 - 南光组织查询指定组织:organizationId={}", frontendOrganizationId);
} else {
// 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
userShipperDO.setOrganizationId(null);
userShipperDO.setTopOrganizationId(null);
log.info("托运人列表查询 - 南光组织查询所有组织:不设置组织过滤条件");
}
} else {
// 其他组织:设置 organizationId,只查询当前组织的数据
@@ -177,6 +179,9 @@ public class UserShipperApplicationService {
}
}
log.info("托运人列表查询 - 设置组织ID后,查询参数:organizationId={}, topOrganizationId={}, userId={}",
userShipperDO.getOrganizationId(), userShipperDO.getTopOrganizationId(), userShipperDO.getUserId());
List<UserShipperPo> userShipperList = userShipperDomainService.userShipperList(userShipperDO);
return processShipperList(userShipperList);
}
@@ -54,8 +54,14 @@ public class UserShipperDomainService {
//获取当前登陆人
LoginUser loginUser = SecurityUtils.getLoginUser();
// 如果 organizationId 和 topOrganizationId 都为 null,表示查询所有组织的数据(南光组织查询全部)
// 此时不应该设置 userId 过滤条件,否则会限制查询结果
boolean isQueryAllOrganizations = (userShipperDO.getOrganizationId() == null && userShipperDO.getTopOrganizationId() == null);
if(loginUser != null && loginUser.getUserPo() != null &&
(loginUser.getUserPo().getBusinessType()==1||loginUser.getUserPo().getBusinessType()==3||loginUser.getUserPo().getUserAccountType()==5)){
(loginUser.getUserPo().getBusinessType()==1||loginUser.getUserPo().getBusinessType()==3||loginUser.getUserPo().getUserAccountType()==5) &&
!isQueryAllOrganizations) {
// 只有在不是查询所有组织的情况下,才设置 userId 过滤条件
userShipperDO.setUserId(loginUser.getUserid());
}
return userShipperRepositoryInterface.selectList(userShipperDO);
@@ -717,7 +717,7 @@
<select id="findAllShipperInfo" resultType="com.mhd.user.interfaces.vo.QueryAllShipperInfoVo">
SELECT u.user_id, u.user_name, u.user_area_address, u.user_area_county_id, u.user_area_name ,u.user_phone,u.has_default_address,b.shipper_id,b.shipper_enterprise_name,u.DOCUMENT_PREPARER_NC_CODE,b.CUSTOMER_NC_CODE,u.organization_id AS organizationId,u.top_organization_id AS topOrganizationId,
b.SETTLEMENT_CURRENCY
b.settlement_currency AS settlementCurrency
FROM "USER" u
LEFT JOIN user_shipper b ON u.user_id = b.user_id
left join (select user_id, LISTAGG(r.role_name, '&amp;') WITHIN GROUP(ORDER BY r.role_name) AS roleName
@@ -737,7 +737,7 @@
AND u.organization_id = #{organizationId}
AND u.organization_name IS NOT NULL
</if>
GROUP BY u.user_id
GROUP BY u.user_id, u.user_name, u.user_area_address, u.user_area_county_id, u.user_area_name, u.user_phone, u.has_default_address, b.shipper_id, b.shipper_enterprise_name, u.DOCUMENT_PREPARER_NC_CODE, b.CUSTOMER_NC_CODE, u.organization_id, u.top_organization_id, b.settlement_currency
</select>
<select id="finShipperEnterpriseNamedByUserId" resultType="string">
SELECT