mirror of https://gitee.com/stylefeng/roses
【db】【system】修复db问题,解决hr_organization的表拼写问题
parent
65b6a875e6
commit
424d594f1a
|
@ -22,7 +22,7 @@ public interface DbOperatorApi {
|
|||
int selectCount(String sql, Object... args);
|
||||
|
||||
/**
|
||||
* 获取某个表,某条数据的所有子列表 TODO 测试
|
||||
* 获取某个表,某条数据的所有子列表
|
||||
* <p>
|
||||
* 本方法用在带有层级关系的表,并且有 "pids" 类似的字段
|
||||
* <p>
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package cn.stylefeng.roses.kernel.db.mp.dboperator;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.stylefeng.roses.kernel.db.api.DbOperatorApi;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -26,10 +27,11 @@ public class DbOperatorImpl implements DbOperatorApi {
|
|||
public Set<Long> findSubListByParentId(String tableName, String parentIdsFieldName, String keyFieldName, Long keyFieldValue) {
|
||||
|
||||
// 组装sql
|
||||
String sql = "select {0} from {1} where {2} like '%[{3}]%'";
|
||||
String sqlTemplate = "select {} from {} where {} like '%[{}]%'";
|
||||
String sql = StrUtil.format(sqlTemplate, keyFieldName, tableName, parentIdsFieldName, keyFieldValue.toString());
|
||||
|
||||
// 查询所有子级的id集合,结果不包含被查询的keyFieldValue
|
||||
List<Object> subIds = SqlRunner.db().selectObjs(sql, keyFieldName, tableName, parentIdsFieldName, keyFieldValue.toString());
|
||||
List<Object> subIds = SqlRunner.db().selectObjs(sql);
|
||||
|
||||
// 转为Set<Long>
|
||||
return subIds.stream().map(i -> Long.valueOf(i.toString())).collect(Collectors.toSet());
|
||||
|
|
|
@ -51,7 +51,7 @@ public class HrOrganizationRequest extends BaseRequest {
|
|||
@TableUniqueValue(
|
||||
message = "组织编码存在重复,请检查code参数",
|
||||
groups = {add.class, edit.class},
|
||||
tableName = "sys_organization",
|
||||
tableName = "hr_organization",
|
||||
columnName = "org_code")
|
||||
private String orgCode;
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ public class DataScopeService implements DataScopeApi {
|
|||
|
||||
// 获取部门及以下部门的id列表
|
||||
Long organizationId = sysUserOrgResponse.getOrgId();
|
||||
Set<Long> subOrgIds = dbOperatorApi.findSubListByParentId("sys_organization", "pids", "id", organizationId);
|
||||
Set<Long> subOrgIds = dbOperatorApi.findSubListByParentId("hr_organization", "org_pids", "org_id", organizationId);
|
||||
organizationIds.add(organizationId);
|
||||
organizationIds.addAll(subOrgIds);
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
}
|
||||
|
||||
// 级联删除子节点,逻辑删除
|
||||
Set<Long> childIdList = DbOperatorContext.me().findSubListByParentId("sys_organization", "pids", "id", organizationId);
|
||||
Set<Long> childIdList = DbOperatorContext.me().findSubListByParentId("hr_organization", "org_pids", "org_id", organizationId);
|
||||
childIdList.add(organizationId);
|
||||
LambdaUpdateWrapper<HrOrganization> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.in(HrOrganization::getOrgId, childIdList)
|
||||
|
@ -308,7 +308,8 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
private HrOrganization queryOrganization(HrOrganizationRequest hrOrganizationRequest) {
|
||||
HrOrganization hrOrganization = this.getById(hrOrganizationRequest.getOrgId());
|
||||
if (ObjectUtil.isEmpty(hrOrganization)) {
|
||||
throw new SystemModularException(OrganizationExceptionEnum.CANT_FIND_ORG);
|
||||
String userTip = StrUtil.format(OrganizationExceptionEnum.CANT_FIND_ORG.getUserTip(), hrOrganizationRequest.getOrgId());
|
||||
throw new SystemModularException(OrganizationExceptionEnum.CANT_FIND_ORG, userTip);
|
||||
}
|
||||
return hrOrganization;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue