数据权限的修改

This commit is contained in:
1745237360-cloud
2026-01-10 16:39:33 +08:00
parent 29b24e8450
commit 4b427e1b2e
97 changed files with 3056 additions and 466 deletions
@@ -69,9 +69,37 @@ public class AddressBookApplicationService
// 获取登录人id
Long userId = SecurityUtils.getLoginUser().getUserid();
addressBookPo.setUserId(userId);
// 添加组织数据权限过滤
applyOrganizationDataPermissionForAddressBook(addressBookPo);
return addressBookDomainService.selectAddressBookList(addressBookPo);
}
/**
* 应用组织数据权限过滤(地址簿)
* 通过用户表关联来过滤组织数据
*/
private void applyOrganizationDataPermissionForAddressBook(AddressBookPo addressBookPo) {
try {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
// 如果当前登录用户的organizationId为2827(南光组织),可以查询全部组织数据
// 其他组织只能查询自己组织的数据
if (loginUserOrganizationId != null && !loginUserOrganizationId.equals(2827L)) {
// 其他组织:需要通过用户表关联来过滤,只查询同一组织下用户创建的地址簿
// 由于AddressBook表只有userId字段,需要在XML中通过用户表关联来过滤
addressBookPo.setOrganizationId(loginUserOrganizationId);
}
// 如果是2827组织,不设置organizationId,可以查询全部
}
} catch (Exception e) {
// 如果获取登录用户信息失败,不添加过滤条件,避免影响正常查询
}
}
/**
* 新增地址簿
*
@@ -156,12 +184,39 @@ public class AddressBookApplicationService
*/
public List<CommonRoutePo> selectCommonRouteList(CommonRouteDo commonRouteDo){
// 获取登录人id
// Long userId = SecurityUtils.getUserId()==0 ? 4L:SecurityUtils.getLoginUser().getUserid();
Long userId = SecurityUtils.getLoginUser().getUserid();
commonRouteDo.setCreateBy(userId);
// 添加组织数据权限过滤
applyOrganizationDataPermissionForCommonRoute(commonRouteDo);
return commonRouteDomainService.selectCommonRouteList(commonRouteDo);
}
/**
* 应用组织数据权限过滤(常用路线)
* 通过用户表关联来过滤组织数据
*/
private void applyOrganizationDataPermissionForCommonRoute(CommonRouteDo commonRouteDo) {
try {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
// 如果当前登录用户的organizationId为2827(南光组织),可以查询全部组织数据
// 其他组织只能查询自己组织的数据
if (loginUserOrganizationId != null && !loginUserOrganizationId.equals(2827L)) {
// 其他组织:需要通过用户表关联来过滤,只查询同一组织下用户创建的常用路线
// 由于CommonRoute表只有userId字段,需要在XML中通过用户表关联来过滤
commonRouteDo.setOrganizationId(loginUserOrganizationId);
}
// 如果是2827组织,不设置organizationId,可以查询全部
}
} catch (Exception e) {
// 如果获取登录用户信息失败,不添加过滤条件,避免影响正常查询
}
}
/**
* 新增常用路线
*
@@ -38,10 +38,30 @@ public class ContainerApplicationService {
public List<ContainerPO> queryList(ContainerDO containerDO) {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null){
if (loginUser != null && loginUser.getUserPo() != null){
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
if (topOrganizationId != null && topOrganizationId != 1){
containerDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
// 数据权限:根据organizationId来设置查询权限
// organizationId等于2827时查询全部,其他仅查询各自组织的信息
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织(organizationId=2827):可以查询所有组织的数据
// 如果前端传递了 organizationId,使用前端传递的值进行过滤
// 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
if (containerDO.getOrganizationId() == null) {
containerDO.setOrganizationId(null);
containerDO.setTopOrganizationId(null);
}
} else {
// 其他组织:设置organizationId,只查询当前组织的数据
if (topOrganizationId != null && topOrganizationId != 1){
containerDO.setTopOrganizationId(topOrganizationId);
}
// 如果前端传递了organizationId,验证是否与当前登录用户的组织ID一致
if (containerDO.getOrganizationId() != null && !containerDO.getOrganizationId().equals(loginUserOrganizationId)) {
// 前端传递了其他组织的organizationId,强制使用当前登录用户的组织ID,防止越权查询
containerDO.setOrganizationId(loginUserOrganizationId);
}
}
}
return containerDomainService.queryList(containerDO);
@@ -52,6 +72,13 @@ public class ContainerApplicationService {
* 新增容器管理
*/
public Boolean insert(ContainerDO containerDO) {
// 设置当前登录用户的组织信息
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
containerDO.setOrganizationId(loginUser.getUserPo().getOrganizationId());
containerDO.setOrganizationName(loginUser.getUserPo().getOrganizationName());
containerDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
}
//翻译库区类型
setDataDict(containerDO);
return containerDomainService.insert(containerDO);
@@ -22,6 +22,7 @@ import com.mhd.common.core.web.domain.AjaxResult;
import com.mhd.common.security.utils.SecurityUtils;
import com.mhd.system.api.SystemServiceFeign;
import com.mhd.system.api.model.LoginUser;
import com.mhd.common.core.domain.po.UserPo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -50,29 +51,117 @@ public class ExpenseAccountApplicationService {
/**
* 分页查询费用科目列表
*/
public List<ExpenseAccountPO> queryList(ExpenseAccountDO expenseAccountDO) {
setTopOrganizationIdLogin(expenseAccountDO);
return expenseAccountDomainService.queryList(expenseAccountDO);
try {
log.info("开始查询费用科目列表,参数:organizationId={}, topOrganizationId={}, expenseAccountDO={}",
expenseAccountDO.getOrganizationId(), expenseAccountDO.getTopOrganizationId(), expenseAccountDO);
setDataPermission(expenseAccountDO);
// 处理 createByName 和 updateByName 字段:
// 问题:ExpenseAccountAssembler 在查询场景下会自动设置 createByName 和 updateByName 为当前登录用户名
// 这会导致 SQL 中添加 create_by_name LIKE '%nanguang%' 和 update_by_name LIKE '%nanguang%' 条件
// 解决方案:
// 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();
if (expenseAccountDO.getOrganizationId() == null && expenseAccountDO.getTopOrganizationId() == null) {
// 查询所有组织的数据时,不应该通过创建者或更新者来过滤,清空这些字段
log.info("查询所有组织数据,清空 createByName 和 updateByName 过滤条件,避免限制查询结果");
expenseAccountDO.setCreateByName(null);
expenseAccountDO.setUpdateByName(null);
} else if (expenseAccountDO.getOrganizationId() != null && loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织查询指定组织时,如果 createByName 或 updateByName 等于当前登录用户名,说明可能是 Assembler 自动设置的
// 清空这些字段,避免限制查询结果(因为其他组织的数据可能不是当前登录用户创建的)
if (currentUserName != null) {
if (expenseAccountDO.getCreateByName() != null && expenseAccountDO.getCreateByName().equals(currentUserName)) {
log.info("南光组织查询指定组织数据(organizationId={}),清空 createByName 过滤条件(可能由 Assembler 自动设置)",
expenseAccountDO.getOrganizationId());
expenseAccountDO.setCreateByName(null);
}
if (expenseAccountDO.getUpdateByName() != null && expenseAccountDO.getUpdateByName().equals(currentUserName)) {
log.info("南光组织查询指定组织数据(organizationId={}),清空 updateByName 过滤条件(可能由 Assembler 自动设置)",
expenseAccountDO.getOrganizationId());
expenseAccountDO.setUpdateByName(null);
}
}
}
}
log.info("设置组织ID后,查询参数:organizationId={}, topOrganizationId={}, createByName={}, updateByName={}",
expenseAccountDO.getOrganizationId(), expenseAccountDO.getTopOrganizationId(),
expenseAccountDO.getCreateByName(), expenseAccountDO.getUpdateByName());
List<ExpenseAccountPO> result = expenseAccountDomainService.queryList(expenseAccountDO);
log.info("查询费用科目列表成功,返回数据条数:{}", result != null ? result.size() : 0);
return result;
} catch (Exception e) {
log.error("查询费用科目列表异常", e);
throw e;
}
}
public List<ExpenseAccountPO> treeCostSubject(ExpenseAccountDO expenseAccountDO){
setTopOrganizationIdLogin(expenseAccountDO);
setDataPermission(expenseAccountDO);
return expenseAccountDomainService.treeCostSubject(expenseAccountDO);
}
public List<ExpenseAccountPO> subjectTreeCost(ExpenseAccountDO expenseAccountDO){
setTopOrganizationIdLogin(expenseAccountDO);
setDataPermission(expenseAccountDO);
return expenseAccountDomainService.treeCostSubject(expenseAccountDO);
}
private void setTopOrganizationIdLogin(ExpenseAccountDO expenseAccountDO){
/**
* 根据当前登录用户的组织信息实现数据隔离
* 当前登录用户为组织ID字段organization_id为2827时可查全部组织数据,其他组织只能查自己
*/
private void setDataPermission(ExpenseAccountDO expenseAccountDO){
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null){
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
if (topOrganizationId != null && topOrganizationId != 1){
expenseAccountDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
if (loginUser == null || loginUser.getUserPo() == null) {
log.warn("费用科目查询 - 未获取到登录用户信息,跳过数据权限过滤");
return;
}
UserPo userPo = loginUser.getUserPo();
Long loginUserOrganizationId = userPo.getOrganizationId();
Long topOrganizationId = userPo.getTopOrganizationId();
// 先保存前端传递的 organizationId(如果存在)
Long frontendOrganizationId = expenseAccountDO.getOrganizationId();
// 数据权限:根据 organizationId 来设置查询权限
// 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织(organizationId=2827):可以查询所有组织的数据
// 如果前端传递了 organizationId,使用前端传递的值进行过滤
// 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
if (frontendOrganizationId != null) {
expenseAccountDO.setOrganizationId(frontendOrganizationId);
expenseAccountDO.setTopOrganizationId(null);
} else {
expenseAccountDO.setOrganizationId(null);
expenseAccountDO.setTopOrganizationId(null);
}
} else {
// 其他组织:设置 organizationId,只查询当前组织的数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致
if (!frontendOrganizationId.equals(loginUserOrganizationId)) {
log.warn("费用科目查询 - 前端传递的组织ID {} 与当前登录用户的组织ID {} 不一致,使用当前登录用户的组织ID进行过滤",
frontendOrganizationId, loginUserOrganizationId);
expenseAccountDO.setOrganizationId(loginUserOrganizationId);
} else {
expenseAccountDO.setOrganizationId(frontendOrganizationId);
}
expenseAccountDO.setTopOrganizationId(topOrganizationId);
} else {
// 前端没有传递 organizationId,使用当前登录用户的组织ID
if (loginUserOrganizationId != null) {
expenseAccountDO.setOrganizationId(loginUserOrganizationId);
}
expenseAccountDO.setTopOrganizationId(topOrganizationId);
}
}
}
@@ -287,12 +376,43 @@ public class ExpenseAccountApplicationService {
}
public List<QueryExpenseAccountPO> selectExpenseAccount(SearchExpenseAccountDO searchExpenseAccountDO){
setDataPermissionForSearch(searchExpenseAccountDO);
return expenseAccountDomainService.selectExpenseAccount(searchExpenseAccountDO);
}
public List<QueryExpenseAccountPO> selectOtherExpenseAccount(SearchExpenseAccountDO searchExpenseAccountDO){
setDataPermissionForSearch(searchExpenseAccountDO);
return expenseAccountDomainService.selectOtherExpenseAccount(searchExpenseAccountDO);
}
/**
* 为 SearchExpenseAccountDO 设置数据权限
*/
private void setDataPermissionForSearch(SearchExpenseAccountDO searchExpenseAccountDO) {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser == null || loginUser.getUserPo() == null) {
log.warn("费用科目查询 - 未获取到登录用户信息,跳过数据权限过滤");
return;
}
UserPo userPo = loginUser.getUserPo();
Long loginUserOrganizationId = userPo.getOrganizationId();
Long topOrganizationId = userPo.getTopOrganizationId();
// 数据权限:根据 organizationId 来设置查询权限
// 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织(organizationId=2827):可以查询所有组织的数据,不设置组织过滤条件
searchExpenseAccountDO.setOrganizationId(null);
searchExpenseAccountDO.setTopOrganizationId(null);
} else {
// 其他组织:只查询当前组织的数据
if (loginUserOrganizationId != null) {
searchExpenseAccountDO.setOrganizationId(loginUserOrganizationId);
}
searchExpenseAccountDO.setTopOrganizationId(topOrganizationId);
}
}
public List<QueryExpenseAccountPO> selectSocialVehicleExpenseAccount(){
return expenseAccountDomainService.selectSocialVehicleExpenseAccount();
@@ -35,24 +35,190 @@ public class ServiceItemsManageApplicationService {
/**
* 分页查询服务项管理列表
*/
public List<ServiceItemsManagePO> queryList(ServiceItemsManageDO serviceItemsManageDO) {
setTopOrganizationIdLogin(serviceItemsManageDO);
return serviceItemsManageDomainService.queryList(serviceItemsManageDO);
try {
log.info("开始查询服务项管理列表,参数:organizationId={}, topOrganizationId={}, serviceItemsManageDO={}",
serviceItemsManageDO.getOrganizationId(), serviceItemsManageDO.getTopOrganizationId(), serviceItemsManageDO);
// 先保存前端传递的 organizationId 和 topOrganizationId(如果存在)
// 注意:这里需要在设置权限逻辑之前保存,因为 Assembler 可能已经设置了这些值
Long frontendOrganizationId = serviceItemsManageDO.getOrganizationId();
Long frontendTopOrganizationId = serviceItemsManageDO.getTopOrganizationId();
// 获取登录用户信息
LoginUser loginUser = SecurityUtils.getLoginUser();
Long loginUserOrganizationId = null;
Long loginUserTopOrganizationId = null;
if (loginUser != null && loginUser.getUserPo() != null) {
loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
loginUserTopOrganizationId = loginUser.getUserPo().getTopOrganizationId();
}
log.info("登录用户信息:loginUserOrganizationId={}, loginUserTopOrganizationId={}, 前端传递:frontendOrganizationId={}, frontendTopOrganizationId={}",
loginUserOrganizationId, loginUserTopOrganizationId, frontendOrganizationId, frontendTopOrganizationId);
// 数据权限:根据 organizationId 来设置查询权限
// 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织(organizationId=2827):可以查询所有组织的数据
// 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤
// 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤
serviceItemsManageDO.setOrganizationId(frontendOrganizationId);
serviceItemsManageDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件
log.info("南光组织查询指定组织:organizationId={}", frontendOrganizationId);
} else {
// 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
serviceItemsManageDO.setOrganizationId(null);
serviceItemsManageDO.setTopOrganizationId(null);
log.info("南光组织查询所有组织:不设置组织过滤条件");
}
} else {
// 其他组织:设置organizationId,只查询当前组织的数据
// 其他组织只能查询自己组织的数据,不能查询其他组织的数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致
if (!frontendOrganizationId.equals(loginUserOrganizationId)) {
// 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询
log.warn("服务项管理查询 - 前端传递的组织ID {} 与当前登录用户的组织ID {} 不一致,使用当前登录用户的组织ID进行过滤",
frontendOrganizationId, loginUserOrganizationId);
serviceItemsManageDO.setOrganizationId(loginUserOrganizationId);
} else {
// 前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值
serviceItemsManageDO.setOrganizationId(frontendOrganizationId);
}
if (loginUserTopOrganizationId != null) {
serviceItemsManageDO.setTopOrganizationId(loginUserTopOrganizationId);
}
} else {
// 前端没有传递 organizationId,使用当前登录用户的组织ID
if (loginUserOrganizationId != null) {
serviceItemsManageDO.setOrganizationId(loginUserOrganizationId);
}
if (loginUserTopOrganizationId != null) {
serviceItemsManageDO.setTopOrganizationId(loginUserTopOrganizationId);
}
}
}
// 处理 createByName 和 updateByName 字段:
// 问题:Assembler 在查询场景下(serviceItemsManageId == null)会自动设置 createByName 和 updateByName 为当前登录用户名
// 这会导致 SQL 中添加 create_by_name LIKE '%nanguang%' 和 update_by_name LIKE '%nanguang%' 条件
// 解决方案:
// 1. 如果查询所有组织(organizationId 和 topOrganizationId 都为 null),清空这些字段
// 2. 如果查询指定组织(organizationId 不为 null),且是南光组织查询,如果 createByName 或 updateByName 等于当前登录用户名,清空它们
// 因为查询其他组织的数据时,不应该通过当前登录用户的名称来过滤
// 注意:这种方法可能会误判(如果前端确实传递了当前登录用户名作为查询条件),但这种情况很少见,且影响较小
String currentUserName = null;
if (loginUser != null && loginUser.getUserPo() != null) {
currentUserName = loginUser.getUsername();
}
if (serviceItemsManageDO.getOrganizationId() == null && serviceItemsManageDO.getTopOrganizationId() == null) {
// 查询所有组织的数据时,不应该通过创建者或更新者来过滤,清空这些字段
log.info("查询所有组织数据,清空 createByName 和 updateByName 过滤条件,避免限制查询结果");
serviceItemsManageDO.setCreateByName(null);
serviceItemsManageDO.setUpdateByName(null);
} else if (serviceItemsManageDO.getOrganizationId() != null && loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织查询指定组织时,如果 createByName 或 updateByName 等于当前登录用户名,说明可能是 Assembler 自动设置的
// 清空这些字段,避免限制查询结果(因为其他组织的数据可能不是当前登录用户创建的)
if (currentUserName != null) {
if (serviceItemsManageDO.getCreateByName() != null && serviceItemsManageDO.getCreateByName().equals(currentUserName)) {
log.info("南光组织查询指定组织数据(organizationId={}),清空 createByName 过滤条件(可能由 Assembler 自动设置)",
serviceItemsManageDO.getOrganizationId());
serviceItemsManageDO.setCreateByName(null);
}
if (serviceItemsManageDO.getUpdateByName() != null && serviceItemsManageDO.getUpdateByName().equals(currentUserName)) {
log.info("南光组织查询指定组织数据(organizationId={}),清空 updateByName 过滤条件(可能由 Assembler 自动设置)",
serviceItemsManageDO.getOrganizationId());
serviceItemsManageDO.setUpdateByName(null);
}
}
}
log.info("设置组织ID后,查询参数:organizationId={}, topOrganizationId={}, createByName={}, updateByName={}",
serviceItemsManageDO.getOrganizationId(), serviceItemsManageDO.getTopOrganizationId(),
serviceItemsManageDO.getCreateByName(), serviceItemsManageDO.getUpdateByName());
List<ServiceItemsManagePO> result = serviceItemsManageDomainService.queryList(serviceItemsManageDO);
log.info("查询服务项管理列表成功,返回数据条数:{}", result != null ? result.size() : 0);
return result;
} catch (Exception e) {
log.error("查询服务项管理列表异常", e);
throw e;
}
}
public List<ServiceItemsManagePO> getCostTypeList(ServiceItemsManageDO serviceItemsManageDO){
setTopOrganizationIdLogin(serviceItemsManageDO);
return serviceItemsManageDomainService.getCostsType(serviceItemsManageDO);
}
private void setTopOrganizationIdLogin(ServiceItemsManageDO serviceItemsManageDO){
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null){
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
if (topOrganizationId != null && topOrganizationId != 1){
serviceItemsManageDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
try {
log.info("开始查询费用类别列表,参数:{}", serviceItemsManageDO);
// 先保存前端传递的 organizationId(如果存在)
Long frontendOrganizationId = serviceItemsManageDO.getOrganizationId();
// 获取登录用户信息
LoginUser loginUser = SecurityUtils.getLoginUser();
Long loginUserOrganizationId = null;
Long topOrganizationId = null;
if (loginUser != null && loginUser.getUserPo() != null) {
loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
}
// 数据权限:根据 organizationId 来设置查询权限
// 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织(organizationId=2827):可以查询所有组织的数据
// 如果前端传递了 organizationId(包括2827),使用前端传递的值进行过滤
// 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤
serviceItemsManageDO.setOrganizationId(frontendOrganizationId);
serviceItemsManageDO.setTopOrganizationId(null);
} else {
// 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
serviceItemsManageDO.setOrganizationId(null);
serviceItemsManageDO.setTopOrganizationId(null);
}
} else {
// 其他组织:设置organizationId,只查询当前组织的数据
// 其他组织只能查询自己组织的数据,不能查询其他组织的数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致
if (!frontendOrganizationId.equals(loginUserOrganizationId)) {
// 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询
log.warn("费用类别查询 - 前端传递的组织ID {} 与当前登录用户的组织ID {} 不一致,使用当前登录用户的组织ID进行过滤",
frontendOrganizationId, loginUserOrganizationId);
serviceItemsManageDO.setOrganizationId(loginUserOrganizationId);
} else {
// 前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值
serviceItemsManageDO.setOrganizationId(frontendOrganizationId);
}
if (topOrganizationId != null) {
serviceItemsManageDO.setTopOrganizationId(topOrganizationId);
}
} else {
// 前端没有传递 organizationId,使用当前登录用户的组织ID
if (loginUserOrganizationId != null) {
serviceItemsManageDO.setOrganizationId(loginUserOrganizationId);
}
if (topOrganizationId != null) {
serviceItemsManageDO.setTopOrganizationId(topOrganizationId);
}
}
}
log.info("设置组织ID后,费用类别查询参数:organizationId={}, topOrganizationId={}",
serviceItemsManageDO.getOrganizationId(), serviceItemsManageDO.getTopOrganizationId());
List<ServiceItemsManagePO> result = serviceItemsManageDomainService.getCostsType(serviceItemsManageDO);
log.info("查询费用类别列表成功,返回数据条数:{}", result != null ? result.size() : 0);
return result;
} catch (Exception e) {
log.error("查询费用类别列表异常", e);
throw e;
}
}
@@ -56,6 +56,13 @@ public class WarehouseApplicationService {
* 新增仓库
*/
public Boolean insert(WarehouseDO warehouseDO) {
// 设置当前登录用户的组织信息
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
warehouseDO.setOrganizationId(loginUser.getUserPo().getOrganizationId());
warehouseDO.setOrganizationName(loginUser.getUserPo().getOrganizationName());
warehouseDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
}
//设置数据字典键值
setDataDict(warehouseDO);
return warehouseDomainService.insert(warehouseDO);
@@ -126,4 +126,7 @@ public class CommonRouteDo extends BaseVOEntity
@ApiModelProperty(name = "运费单价")
private BigDecimal freightUnitPrice;
@ApiModelProperty(name = "组织ID(用于数据权限过滤,内部使用)", hidden = true)
private Long organizationId;
}
@@ -10,6 +10,7 @@ import com.mhd.basic.domain.expenseAccount.repository.todo.ExpenseAccountDO;
import com.mhd.basic.domain.expenseAccount.repository.todo.ExpenseAccountDoMap;
import com.mhd.basic.domain.expenseAccount.repository.todo.SearchExpenseAccountDO;
import com.mhd.basic.interfaces.dto.expenseAccount.SearchExpenseAccountDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,6 +25,7 @@ import java.util.List;
* @author gen
* @date 2024-06-04
*/
@Slf4j
@Service
public class ExpenseAccountImpl extends ServiceImpl<ExpenseAccountMapper, ExpenseAccount> implements IExpenseAccountService{
@Autowired
@@ -35,7 +37,15 @@ public class ExpenseAccountImpl extends ServiceImpl<ExpenseAccountMapper, Expens
@Override
public List<ExpenseAccountPO> queryList(ExpenseAccountDO expenseAccountDO)
{
return expenseAccountMapper.queryList(expenseAccountDO);
// 添加日志,记录查询参数
log.info("ExpenseAccountImpl.queryList 查询参数:topOrganizationId={}, subjectName={}, subjectCode={}, status={}",
expenseAccountDO.getTopOrganizationId(),
expenseAccountDO.getSubjectName(),
expenseAccountDO.getSubjectCode(),
expenseAccountDO.getStatus());
List<ExpenseAccountPO> result = expenseAccountMapper.queryList(expenseAccountDO);
log.info("ExpenseAccountImpl.queryList 查询结果:{} 条", result != null ? result.size() : 0);
return result;
}
@Override
@@ -39,5 +39,16 @@ public class QueryExpenseAccountPO {
@Excel(name = "上级科目名称")
private String upperSubject;
@ApiModelProperty("一级组织表ID")
@Excel(name = "一级组织表ID")
private Long topOrganizationId;
@ApiModelProperty("组织表ID")
@Excel(name = "组织表ID")
private Long organizationId;
@ApiModelProperty("组织名称")
@Excel(name = "组织名称")
private String organizationName;
}
@@ -25,4 +25,10 @@ public class SearchExpenseAccountDO{
@ApiModelProperty("社会车辆固定显示(1-是,2-否)")
private Integer societyStatus;
@ApiModelProperty("组织ID")
private Long organizationId;
@ApiModelProperty("上级组织ID")
private Long topOrganizationId;
}
@@ -22,7 +22,7 @@ public interface IServiceItemsManageService extends IService<ServiceItemsManage>
/**
* 查询费用类别
*/
public List<ServiceItemsManagePO> getCostType();
public List<ServiceItemsManagePO> getCostType(ServiceItemsManageDO serviceItemsManageDO);
/**
* 新增服务项管理
*/
@@ -21,6 +21,6 @@ public interface ServiceItemsManageMapper extends BaseMapper<ServiceItemsManage>
/**
* 查询费用类别
*/
public List<ServiceItemsManagePO> selectServiceTypes();
public List<ServiceItemsManagePO> selectServiceTypes(ServiceItemsManageDO serviceItemsManageDO);
}
@@ -6,6 +6,7 @@ import com.mhd.basic.domain.serviceItemsManage.entity.ServiceItemsManage;
import com.mhd.basic.domain.serviceItemsManage.repository.facade.IServiceItemsManageService;
import com.mhd.basic.domain.serviceItemsManage.repository.po.ServiceItemsManagePO;
import com.mhd.basic.domain.serviceItemsManage.repository.todo.ServiceItemsManageDO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -19,6 +20,7 @@ import java.util.List;
* @author gen
* @date 2024-06-03
*/
@Slf4j
@Service
public class ServiceItemsManageImpl extends ServiceImpl<ServiceItemsManageMapper, ServiceItemsManage> implements IServiceItemsManageService{
@Autowired
@@ -30,12 +32,80 @@ public class ServiceItemsManageImpl extends ServiceImpl<ServiceItemsManageMapper
@Override
public List<ServiceItemsManagePO> queryList(ServiceItemsManageDO serviceItemsManageDO)
{
return serviceItemsManageMapper.queryList(serviceItemsManageDO);
// 添加日志,记录查询参数
log.info("ServiceItemsManageImpl.queryList 查询参数:topOrganizationId={}, organizationId={}, serviceItemsName={}, serviceItemsCode={}",
serviceItemsManageDO.getTopOrganizationId(),
serviceItemsManageDO.getOrganizationId(),
serviceItemsManageDO.getServiceItemsName(),
serviceItemsManageDO.getServiceItemsCode());
// 构建SQL查询条件说明(用于日志,必须与 MyBatis XML 中的条件保持一致)
StringBuilder sqlCondition = new StringBuilder("WHERE del_flag = 1");
// 组织过滤条件(与 XML 中的 <if test="organizationId != null"> 和 <if test="topOrganizationId != null and organizationId == null"> 对应)
if (serviceItemsManageDO.getOrganizationId() != null) {
// 如果设置了 organizationId,添加 organization_id 条件
sqlCondition.append(" AND organization_id = ").append(serviceItemsManageDO.getOrganizationId());
sqlCondition.append(" AND organization_name IS NOT NULL");
sqlCondition.append(" AND organization_name != ''");
sqlCondition.append(" AND LENGTH(TRIM(organization_name)) > 0");
} else if (serviceItemsManageDO.getTopOrganizationId() != null) {
// 如果设置了 topOrganizationId 但没有设置 organizationId,添加 top_organization_id 条件
sqlCondition.append(" AND top_organization_id = ").append(serviceItemsManageDO.getTopOrganizationId());
sqlCondition.append(" AND organization_name IS NOT NULL");
sqlCondition.append(" AND organization_name != ''");
sqlCondition.append(" AND LENGTH(TRIM(organization_name)) > 0");
} else {
// 如果 organizationId 和 topOrganizationId 都为 null,不添加组织过滤条件(查询所有组织的数据)
sqlCondition.append(" (无组织过滤条件,查询所有组织的数据)");
}
// 其他查询条件
if (serviceItemsManageDO.getCreateByName() != null && !serviceItemsManageDO.getCreateByName().isEmpty()) {
sqlCondition.append(" AND create_by_name LIKE '%").append(serviceItemsManageDO.getCreateByName()).append("%'");
}
if (serviceItemsManageDO.getUpdateByName() != null && !serviceItemsManageDO.getUpdateByName().isEmpty()) {
sqlCondition.append(" AND update_by_name LIKE '%").append(serviceItemsManageDO.getUpdateByName()).append("%'");
}
if (serviceItemsManageDO.getOrganizationName() != null && !serviceItemsManageDO.getOrganizationName().isEmpty()) {
sqlCondition.append(" AND organization_name LIKE '%").append(serviceItemsManageDO.getOrganizationName()).append("%'");
}
if (serviceItemsManageDO.getServiceItemsName() != null && !serviceItemsManageDO.getServiceItemsName().isEmpty()) {
sqlCondition.append(" AND service_items_name LIKE '%").append(serviceItemsManageDO.getServiceItemsName()).append("%'");
}
if (serviceItemsManageDO.getServiceItemsCode() != null && !serviceItemsManageDO.getServiceItemsCode().isEmpty()) {
sqlCondition.append(" AND service_items_code = '").append(serviceItemsManageDO.getServiceItemsCode()).append("'");
}
if (serviceItemsManageDO.getTaxRate() != null) {
sqlCondition.append(" AND tax_rate = ").append(serviceItemsManageDO.getTaxRate());
}
if (serviceItemsManageDO.getRemark() != null && !serviceItemsManageDO.getRemark().isEmpty()) {
sqlCondition.append(" AND remark LIKE '%").append(serviceItemsManageDO.getRemark()).append("%'");
}
log.info("ServiceItemsManageImpl.queryList 生成的SQL条件(预估):SELECT * FROM service_items_manage {}", sqlCondition.toString());
log.info("ServiceItemsManageImpl.queryList 实际执行的SQL请查看 MyBatis 日志,参数:organizationId={}, topOrganizationId={}, delFlag={}",
serviceItemsManageDO.getOrganizationId(), serviceItemsManageDO.getTopOrganizationId(), serviceItemsManageDO.getDelFlag());
List<ServiceItemsManagePO> result = serviceItemsManageMapper.queryList(serviceItemsManageDO);
log.info("ServiceItemsManageImpl.queryList 查询结果:{} 条", result != null ? result.size() : 0);
// 记录查询结果中的组织ID分布
if (result != null && !result.isEmpty()) {
StringBuilder orgIds = new StringBuilder();
for (ServiceItemsManagePO po : result) {
if (orgIds.length() > 0) {
orgIds.append(", ");
}
orgIds.append(po.getOrganizationId());
}
log.info("查询结果中的组织ID分布:{}", orgIds.toString());
}
return result;
}
@Override
public List<ServiceItemsManagePO> getCostType() {
return serviceItemsManageMapper.selectServiceTypes();
public List<ServiceItemsManagePO> getCostType(ServiceItemsManageDO serviceItemsManageDO) {
return serviceItemsManageMapper.selectServiceTypes(serviceItemsManageDO);
}
/**
* 新增服务项管理
@@ -37,7 +37,7 @@ public class ServiceItemsManageDomainService {
* 查询费用类型
*/
public List<ServiceItemsManagePO> getCostsType(ServiceItemsManageDO serviceItemsManageDO){
return serviceItemsManageService.getCostType();
return serviceItemsManageService.getCostType(serviceItemsManageDO);
}
@@ -27,8 +27,10 @@ public class ExpenseAccountAssembler {
*/
public ExpenseAccountDO toDO(ExpenseAccountDTO expenseAccountDTO) {
ExpenseAccountDO expenseAccountDO = new ExpenseAccountDO();
// 拷贝
BeanUtils.copyProperties(expenseAccountDTO, expenseAccountDO, IgnoreNullUtil.getNullPropertyNames(expenseAccountDTO));
// 如果 expenseAccountDTO 不为 null,才进行拷贝
if (expenseAccountDTO != null) {
BeanUtils.copyProperties(expenseAccountDTO, expenseAccountDO, IgnoreNullUtil.getNullPropertyNames(expenseAccountDTO));
}
LoginUser loginUser = SecurityUtils.getLoginUser();
if (ObjectUtil.isNull(loginUser)) {
throw new DigitalLogisticsException(UserError.TIMEOUT);
@@ -36,28 +38,45 @@ public class ExpenseAccountAssembler {
String userName = loginUser.getUsername();
// 获取登录人id
Long userId = loginUser.getUserid();
if(expenseAccountDTO.getExpenseAccountId() != null){
// 只有在新增或编辑操作时才设置 createByName 和 updateByName
// 查询列表时不应该自动设置这些字段,否则会导致 SQL 中添加过滤条件,影响查询结果
if(expenseAccountDTO != null && expenseAccountDTO.getExpenseAccountId() != null){
// 编辑操作:只设置更新相关字段
if(userId != null){
expenseAccountDO.setUpdateBy(userId);
}else {
expenseAccountDO.setUpdateBy(new Long("0"));
}
expenseAccountDO.setUpdateByName(userName);
expenseAccountDO.setUpdateTime(new Date());
}else {
if(userId != null){
expenseAccountDO.setCreateBy(userId);
expenseAccountDO.setUpdateBy(userId);
}else {
expenseAccountDO.setCreateBy(new Long("0"));
expenseAccountDO.setUpdateBy(new Long("0"));
// 只有在 DTO 中没有传递 updateByName 时才设置(避免覆盖前端传递的值)
if(expenseAccountDO.getUpdateByName() == null || expenseAccountDO.getUpdateByName().isEmpty()){
expenseAccountDO.setUpdateByName(userName);
}
expenseAccountDO.setCreateByName(userName);
expenseAccountDO.setUpdateByName(userName);
expenseAccountDO.setCreateTime(new Date());
expenseAccountDO.setUpdateTime(new Date());
expenseAccountDO.setDelFlag(1);
} else if(expenseAccountDTO != null && expenseAccountDTO.getExpenseAccountId() == null) {
// expenseAccountId == null,可能是查询操作或新增操作
// 如果前端传递了 createByName 或 updateByName,说明是查询条件,不应该设置(已经在 BeanUtils.copyProperties 中拷贝了)
// 如果前端没有传递 createByName 和 updateByName,可能是新增操作,需要设置默认值
boolean hasQueryCondition = (expenseAccountDTO.getCreateByName() != null && !expenseAccountDTO.getCreateByName().isEmpty())
|| (expenseAccountDTO.getUpdateByName() != null && !expenseAccountDTO.getUpdateByName().isEmpty());
if(!hasQueryCondition) {
// 没有查询条件,可能是新增操作,设置默认值
if(userId != null){
expenseAccountDO.setCreateBy(userId);
expenseAccountDO.setUpdateBy(userId);
}else {
expenseAccountDO.setCreateBy(new Long("0"));
expenseAccountDO.setUpdateBy(new Long("0"));
}
expenseAccountDO.setCreateByName(userName);
expenseAccountDO.setUpdateByName(userName);
expenseAccountDO.setCreateTime(new Date());
expenseAccountDO.setUpdateTime(new Date());
expenseAccountDO.setDelFlag(1);
}
// 如果有查询条件(createByName 或 updateByName),说明是查询操作,不应该设置这些字段
// 字段值已经在 BeanUtils.copyProperties 中从 DTO 拷贝过来了
}
return expenseAccountDO;
}
@@ -27,8 +27,10 @@ public class ServiceItemsManageAssembler {
*/
public ServiceItemsManageDO toDO(ServiceItemsManageDTO serviceItemsManageDTO) {
ServiceItemsManageDO serviceItemsManageDO = new ServiceItemsManageDO();
// 拷贝
BeanUtils.copyProperties(serviceItemsManageDTO, serviceItemsManageDO, IgnoreNullUtil.getNullPropertyNames(serviceItemsManageDTO));
// 如果 serviceItemsManageDTO 不为 null,才进行拷贝
if (serviceItemsManageDTO != null) {
BeanUtils.copyProperties(serviceItemsManageDTO, serviceItemsManageDO, IgnoreNullUtil.getNullPropertyNames(serviceItemsManageDTO));
}
LoginUser loginUser = SecurityUtils.getLoginUser();
if (ObjectUtil.isNull(loginUser)) {
throw new DigitalLogisticsException(UserError.TIMEOUT);
@@ -36,28 +38,49 @@ public class ServiceItemsManageAssembler {
String userName = loginUser.getUsername();
// 获取登录人id
Long userId = loginUser.getUserid();
if(serviceItemsManageDTO.getServiceItemsManageId() != null){
// 只有在新增或编辑操作时才设置 createByName 和 updateByName
// 查询列表时不应该自动设置这些字段,否则会导致 SQL 中添加过滤条件,影响查询结果
// 判断规则:
// 1. 如果 serviceItemsManageId != null,说明是编辑操作,只设置更新相关字段
// 2. 如果 serviceItemsManageId == null 且前端传递了 createByName 或 updateByName,说明是查询条件,不应该覆盖
// 3. 如果 serviceItemsManageId == null 且前端没有传递 createByName 和 updateByName,可能是新增操作,设置默认值
if(serviceItemsManageDTO != null && serviceItemsManageDTO.getServiceItemsManageId() != null){
// 编辑操作:只设置更新相关字段
if(userId != null){
serviceItemsManageDO.setUpdateBy(userId);
}else {
serviceItemsManageDO.setUpdateBy(new Long("0"));
}
serviceItemsManageDO.setUpdateByName(userName);
serviceItemsManageDO.setUpdateTime(new Date());
}else {
if(userId != null){
serviceItemsManageDO.setCreateBy(userId);
serviceItemsManageDO.setUpdateBy(userId);
}else {
serviceItemsManageDO.setCreateBy(new Long("0"));
serviceItemsManageDO.setUpdateBy(new Long("0"));
// 只有在 DTO 中没有传递 updateByName 时才设置(避免覆盖前端传递的值)
if(serviceItemsManageDO.getUpdateByName() == null || serviceItemsManageDO.getUpdateByName().isEmpty()){
serviceItemsManageDO.setUpdateByName(userName);
}
serviceItemsManageDO.setCreateByName(userName);
serviceItemsManageDO.setUpdateByName(userName);
serviceItemsManageDO.setCreateTime(new Date());
serviceItemsManageDO.setUpdateTime(new Date());
serviceItemsManageDO.setDelFlag(1);
} else if(serviceItemsManageDTO != null && serviceItemsManageDTO.getServiceItemsManageId() == null) {
// serviceItemsManageId == null,可能是查询操作或新增操作
// 如果前端传递了 createByName 或 updateByName,说明是查询条件,不应该设置(已经在 BeanUtils.copyProperties 中拷贝了)
// 如果前端没有传递 createByName 和 updateByName,可能是新增操作,需要设置默认值
boolean hasQueryCondition = (serviceItemsManageDTO.getCreateByName() != null && !serviceItemsManageDTO.getCreateByName().isEmpty())
|| (serviceItemsManageDTO.getUpdateByName() != null && !serviceItemsManageDTO.getUpdateByName().isEmpty());
if(!hasQueryCondition) {
// 没有查询条件,可能是新增操作,设置默认值
if(userId != null){
serviceItemsManageDO.setCreateBy(userId);
serviceItemsManageDO.setUpdateBy(userId);
}else {
serviceItemsManageDO.setCreateBy(new Long("0"));
serviceItemsManageDO.setUpdateBy(new Long("0"));
}
serviceItemsManageDO.setCreateByName(userName);
serviceItemsManageDO.setUpdateByName(userName);
serviceItemsManageDO.setCreateTime(new Date());
serviceItemsManageDO.setUpdateTime(new Date());
serviceItemsManageDO.setDelFlag(1);
}
// 如果有查询条件(createByName 或 updateByName),说明是查询操作,不应该设置这些字段
// 字段值已经在 BeanUtils.copyProperties 中从 DTO 拷贝过来了
}
return serviceItemsManageDO;
}
@@ -52,11 +52,29 @@ public class ExpenseAccountApi extends BaseController{
@GetMapping("/list")
public TableDataInfo list(ExpenseAccountDTO expenseAccountDTO)
{
//转换实体
ExpenseAccountDO expenseAccountDO = expenseAccountAssembler.toDO(expenseAccountDTO);
startPage();
List<ExpenseAccountPO> list = expenseAccountApplicationService.queryList(expenseAccountDO);
return getDataTable(list);
logger.info("收到查询费用科目列表请求,参数:{}", expenseAccountDTO);
try {
//转换实体,如果 expenseAccountDTO 为 null,创建一个新的对象
if (expenseAccountDTO == null) {
expenseAccountDTO = new ExpenseAccountDTO();
logger.info("expenseAccountDTO 为 null,创建新对象");
}
ExpenseAccountDO expenseAccountDO = expenseAccountAssembler.toDO(expenseAccountDTO);
logger.info("转换后的 ExpenseAccountDO{}", expenseAccountDO);
startPage();
logger.info("分页参数已设置");
List<ExpenseAccountPO> list = expenseAccountApplicationService.queryList(expenseAccountDO);
logger.info("查询完成,返回数据条数:{}", list != null ? list.size() : 0);
if (list != null && list.isEmpty()) {
logger.warn("查询结果为空,可能的原因:1.数据库中没有符合条件的数据 2.数据权限过滤 3.SQL查询条件问题");
logger.warn("查询条件:topOrganizationId={}, del_flag=1", expenseAccountDO.getTopOrganizationId());
}
return getDataTable(list);
} catch (Exception e) {
logger.error("查询费用科目列表失败", e);
e.printStackTrace();
return getDataTable(new ArrayList<>());
}
}
@ApiOperation("查询费用科目树型列表")
@@ -84,6 +102,32 @@ public class ExpenseAccountApi extends BaseController{
return AjaxResult.success(expenseAccountApplicationService.selectOtherExpenseAccount(searchExpenseAccountDO));
}
/**
* 测试查询 - 不设置组织ID,查看是否有数据
*/
@ApiOperation("测试查询费用科目列表(不设置组织ID")
@GetMapping("/testList")
public AjaxResult testList(ExpenseAccountDTO expenseAccountDTO)
{
logger.info("测试查询费用科目列表,不设置组织ID");
try {
if (expenseAccountDTO == null) {
expenseAccountDTO = new ExpenseAccountDTO();
}
ExpenseAccountDO expenseAccountDO = expenseAccountAssembler.toDO(expenseAccountDTO);
// 不设置组织ID,测试是否能查询到数据
expenseAccountDO.setTopOrganizationId(null);
logger.info("测试查询参数:{}", expenseAccountDO);
startPage();
List<ExpenseAccountPO> list = expenseAccountApplicationService.queryList(expenseAccountDO);
logger.info("测试查询结果:{} 条", list != null ? list.size() : 0);
return AjaxResult.success(list);
} catch (Exception e) {
logger.error("测试查询失败", e);
return AjaxResult.error("测试查询失败:" + e.getMessage());
}
}
@ApiOperation("查询费用科目-所有现金明细")
@GetMapping("/selectAllCashExpenseAccount")
public AjaxResult selectAllCashExpenseAccount(){
@@ -85,12 +85,25 @@ public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDi
if (ObjectUtil.isNull(loginUser)) {
throw new DigitalLogisticsException(UserError.TIMEOUT);
}
// 数据权限验证:南光组织(organizationId=2827)可以删除所有组织的数据,其他组织只能删除自己组织的数据
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
Long loginUserTopOrganizationId = loginUser.getUserPo().getTopOrganizationId();
for (Long dictCode : dictCodes)
{
SysDictData data = selectDictDataById(dictCode);
if (ObjectUtil.notEqual(data.getTopOrganizationId(), loginUser.getUserPo().getTopOrganizationId())) {
throw new ServiceException("修改失败");
// 南光组织(organizationId=2827)可以删除所有组织的数据
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织可以删除,不需要验证 topOrganizationId
} else {
// 其他组织:只能删除自己组织的数据
// 使用 Objects.equals 安全比较,处理 null 值的情况
if (!java.util.Objects.equals(data.getTopOrganizationId(), loginUserTopOrganizationId)) {
throw new ServiceException("删除失败:无权删除其他组织的字典数据");
}
}
dictDataMapper.deleteDictDataById(dictCode);
SysDictData dictData = new SysDictData();
dictData.setDictType(data.getDictType());
@@ -146,11 +159,25 @@ public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDi
if (ObjectUtil.isNull(sysDictData)) {
throw new ServiceException("字典数据未找到");
}
if ("Y".equals(sysDictData.getIsDefault())) {
throw new ServiceException("默认数据不允许修改");
}
if (ObjectUtil.notEqual(sysDictData.getTopOrganizationId(), loginUser.getUserPo().getTopOrganizationId())) {
throw new ServiceException("修改失败");
// 数据权限验证:南光组织(organizationId=2827)可以修改所有组织的数据(包括默认数据),其他组织只能修改自己组织的数据(包括默认数据)
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
Long loginUserTopOrganizationId = loginUser.getUserPo().getTopOrganizationId();
Long dictDataTopOrganizationId = sysDictData.getTopOrganizationId();
Long dictDataOrganizationId = sysDictData.getOrganizationId();
// 南光组织(organizationId=2827)可以修改所有组织的数据(包括默认数据)
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织可以修改,不需要验证 topOrganizationId
} else {
// 其他组织:只能修改自己组织的数据(包括默认数据)
// 使用 Objects.equals 安全比较,处理 null 值的情况
boolean isSameTopOrg = java.util.Objects.equals(dictDataTopOrganizationId, loginUserTopOrganizationId);
boolean isSameOrg = java.util.Objects.equals(dictDataOrganizationId, loginUserOrganizationId);
if (!isSameTopOrg || !isSameOrg) {
throw new ServiceException("修改失败:无权修改其他组织的字典数据");
}
}
data.setUpdateBy(loginUser.getUserPo().getUserName());
int row = dictDataMapper.updateDictData(data);
@@ -102,7 +102,7 @@
WHERE
a.del_flag = 1
<include refid="common_where"/>
order by account_type,service_items_code,upper_subject_code,show_seq
order by a.account_type,service_items_code,upper_subject_code,show_seq
</select>
<select id="selectCostSubject" parameterType="com.mhd.basic.domain.expenseAccount.repository.todo.ExpenseAccountDO"
resultType="com.mhd.basic.domain.expenseAccount.repository.po.ExpenseAccountPO">
@@ -191,8 +191,24 @@
<if test="expenseAccountDO.updateTimeEnd != null and expenseAccountDO.updateTimeEnd != ''">
AND date_format(a.update_time,'%Y-%m-%d') <![CDATA[<=]]> #{expenseAccountDO.updateTimeEnd}
</if>
<if test="expenseAccountDO.topOrganizationId != null ">
<!-- 数据权限:南光组织(organizationId=2827)查全部,其他组织查自己 -->
<!-- 如果 organizationId 和 topOrganizationId 都为 null,表示查询所有组织的数据(不添加组织过滤条件) -->
<if test="expenseAccountDO.organizationId != null">
<!-- 如果设置了 organizationId,添加 organization_id 条件 -->
and a.organization_id = #{expenseAccountDO.organizationId}
and a.organization_name IS NOT NULL
and a.organization_name != ''
and LENGTH(TRIM(a.organization_name)) > 0
</if>
<if test="expenseAccountDO.topOrganizationId != null and expenseAccountDO.organizationId == null">
<!-- 如果设置了 topOrganizationId 但没有设置 organizationId,添加 top_organization_id 条件 -->
and a.top_organization_id = #{expenseAccountDO.topOrganizationId}
and a.organization_name IS NOT NULL
and a.organization_name != ''
and LENGTH(TRIM(a.organization_name)) > 0
</if>
<if test="expenseAccountDO.organizationName != null and expenseAccountDO.organizationName != ''">
and a.organization_name like concat('%', #{expenseAccountDO.organizationName}, '%')
</if>
<if test="expenseAccountDO.serviceItemsCode != null and expenseAccountDO.serviceItemsCode != ''">
and b.service_items_code = #{expenseAccountDO.serviceItemsCode}
@@ -8,18 +8,36 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectServiceItemsManagePo1">
<where>
del_flag = 1
<!-- 删除标记:0-无状态,1-正常,2-已删除,查询时只查询正常的数据 -->
<choose>
<when test="delFlag != null">
and del_flag = #{delFlag}
</when>
<otherwise>
and del_flag = 1
</otherwise>
</choose>
<if test="createByName != null and createByName != ''">
and create_by_name like concat('%', #{createByName}, '%')
</if>
<if test="updateByName != null and updateByName != ''">
and update_by_name like concat('%', #{updateByName}, '%')
</if>
<if test="topOrganizationId != null ">
and top_organization_id = #{topOrganizationId}
</if>
<if test="organizationId != null ">
<!-- 数据权限:南光组织(organizationId=2827)查全部,其他组织查自己 -->
<!-- 如果 organizationId 和 topOrganizationId 都为 null,表示查询所有组织的数据(不添加组织过滤条件) -->
<if test="organizationId != null">
<!-- 如果设置了 organizationId,添加 organization_id 条件 -->
and organization_id = #{organizationId}
and organization_name IS NOT NULL
and organization_name != ''
and LENGTH(TRIM(organization_name)) > 0
</if>
<if test="topOrganizationId != null and organizationId == null">
<!-- 如果设置了 topOrganizationId 但没有设置 organizationId,添加 top_organization_id 条件 -->
and top_organization_id = #{topOrganizationId}
and organization_name IS NOT NULL
and organization_name != ''
and LENGTH(TRIM(organization_name)) > 0
</if>
<if test="organizationName != null and organizationName != ''">
and organization_name like concat('%', #{organizationName}, '%')
@@ -42,12 +60,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createTimeEnd != null and createTimeEnd != ''">
AND date_format(create_time,'%Y-%m-%d') <![CDATA[<=]]> #{createTimeEnd}
</if>
<if test="createByName != null and createByName != ''">
and create_by_name like concat('%', #{createByName}, '%')
</if>
<if test="updateByName != null and updateByName != ''">
and update_by_name like concat('%', #{updateByName}, '%')
</if>
<if test="updateTimeStart != null and updateTimeStart != ''">
AND date_format(update_time,'%Y-%m-%d') <![CDATA[>=]]> #{updateTimeStart}
</if>
@@ -63,10 +75,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectServiceItemsManagePo1"/>
</select>
<select id="selectServiceTypes"
<select id="selectServiceTypes" parameterType="com.mhd.basic.domain.serviceItemsManage.repository.todo.ServiceItemsManageDO"
resultType="com.mhd.basic.domain.serviceItemsManage.repository.po.ServiceItemsManagePO">
select organization_name,service_items_code,service_items_name,tax_rate,CONCAT(service_items_name,service_items_code) cost_type
from service_items_manage
where del_flag = 1
<include refid="selectServiceItemsManagePo1"/>
</select>
</mapper>
@@ -9,6 +9,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
a.*
from
common_route a
<if test="commonRouteDo.organizationId != null">
LEFT JOIN "USER" u ON a.user_id = u.user_id AND u.del_flag = 0
</if>
WHERE
a.del_flag = 1
</sql>
@@ -26,6 +29,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and (a.mail_name like concat('%', #{commonRouteDo.synthesize}, '%') OR a.mail_phone LIKE concat('%', #{commonRouteDo.synthesize}, '%') OR a.mail_address_plot LIKE concat('%', #{commonRouteDo.synthesize}, '%')
OR a.addressee_name like concat('%', #{commonRouteDo.synthesize}, '%') OR a.addressee_phone LIKE concat('%', #{commonRouteDo.synthesize}, '%') OR a.addressee_address_plot LIKE concat('%', #{commonRouteDo.synthesize}, '%'))
</if>
<!-- 组织数据权限过滤:通过用户表关联来过滤组织数据 -->
<if test="commonRouteDo.organizationId != null">
and u.organization_id = #{commonRouteDo.organizationId}
</if>
</sql>
<select id="selectCommonRouteByCommonRouteId" parameterType="java.lang.Long"
@@ -140,27 +140,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectAddressBookList" parameterType="com.mhd.common.core.domain.po.AddressBookPo" resultMap="AddressBookResult">
<include refid="selectAddressBookVo"/>
SELECT
ab.*
FROM
address_book ab
<if test="organizationId != null">
LEFT JOIN "USER" u ON ab.user_id = u.user_id AND u.del_flag = 0
</if>
<where>
del_flag = 1
<if test="synthesize != null and synthesize != ''"> and (link_man like concat('%', #{synthesize}, '%') OR link_phone LIKE concat('%', #{synthesize}, '%') OR area_name LIKE concat('%', #{synthesize}, '%') OR address LIKE concat('%', #{synthesize}, '%') OR address_plot LIKE concat('%', #{synthesize}, '%')) </if>
<if test="userId != null "> and user_id = #{userId}</if>
<if test="linkMan != null and linkMan != ''"> and link_man = #{linkMan}</if>
<if test="linkPhone != null and linkPhone != ''"> and link_phone = #{linkPhone}</if>
<if test="provinceCode != null "> and province_code = #{provinceCode}</if>
<if test="cityCode != null "> and city_code = #{cityCode}</if>
<if test="countyCode != null "> and county_code = #{countyCode}</if>
<if test="provinceName != null and provinceName != ''"> and province_name like concat('%', #{provinceName}, '%')</if>
<if test="cityName != null and cityName != ''"> and city_name like concat('%', #{cityName}, '%')</if>
<if test="countyName != null and countyName != ''"> and county_name like concat('%', #{countyName}, '%')</if>
<if test="address != null and address != ''"> and address = #{address}</if>
<if test="doorplate != null and doorplate != ''"> and doorplate = #{doorplate}</if>
<if test="defaultStatus != null "> and default_status = #{defaultStatus}</if>
<if test="createByName != null and createByName != ''"> and create_by_name like concat('%', #{createByName}, '%')</if>
<if test="updateByName != null and updateByName != ''"> and update_by_name like concat('%', #{updateByName}, '%')</if>
ab.del_flag = 1
<if test="synthesize != null and synthesize != ''"> and (ab.link_man like concat('%', #{synthesize}, '%') OR ab.link_phone LIKE concat('%', #{synthesize}, '%') OR ab.area_name LIKE concat('%', #{synthesize}, '%') OR ab.address LIKE concat('%', #{synthesize}, '%') OR ab.address_plot LIKE concat('%', #{synthesize}, '%')) </if>
<if test="userId != null "> and ab.user_id = #{userId}</if>
<if test="linkMan != null and linkMan != ''"> and ab.link_man = #{linkMan}</if>
<if test="linkPhone != null and linkPhone != ''"> and ab.link_phone = #{linkPhone}</if>
<if test="provinceCode != null "> and ab.province_code = #{provinceCode}</if>
<if test="cityCode != null "> and ab.city_code = #{cityCode}</if>
<if test="countyCode != null "> and ab.county_code = #{countyCode}</if>
<if test="provinceName != null and provinceName != ''"> and ab.province_name like concat('%', #{provinceName}, '%')</if>
<if test="cityName != null and cityName != ''"> and ab.city_name like concat('%', #{cityName}, '%')</if>
<if test="countyName != null and countyName != ''"> and ab.county_name like concat('%', #{countyName}, '%')</if>
<if test="address != null and address != ''"> and ab.address = #{address}</if>
<if test="doorplate != null and doorplate != ''"> and ab.doorplate = #{doorplate}</if>
<if test="defaultStatus != null "> and ab.default_status = #{defaultStatus}</if>
<if test="createByName != null and createByName != ''"> and ab.create_by_name like concat('%', #{createByName}, '%')</if>
<if test="updateByName != null and updateByName != ''"> and ab.update_by_name like concat('%', #{updateByName}, '%')</if>
<!-- 组织数据权限过滤:通过用户表关联来过滤组织数据 -->
<if test="organizationId != null">
and u.organization_id = #{organizationId}
</if>
</where>
ORDER BY
create_time DESC
ab.create_time DESC
</select>
<select id="selectAddressBookListByManifestId" parameterType="java.lang.Long" resultMap="AddressBookResult">