【db】【system】修复db问题,解决hr_organization的表拼写问题

pull/3/head
fengshuonan 2020-12-21 21:43:59 +08:00
parent 65b6a875e6
commit 424d594f1a
5 changed files with 11 additions and 8 deletions

View File

@ -22,7 +22,7 @@ public interface DbOperatorApi {
int selectCount(String sql, Object... args);
/**
* TODO
*
* <p>
* "pids"
* <p>

View File

@ -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());

View File

@ -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;

View File

@ -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);
}

View File

@ -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;
}