Commit f1cbf96a authored by ZWT's avatar ZWT

feat(能源管理系统): 组织机构管理

1.修改组织机构管理分页列表功能,优化sql查询逻辑及代码业务处理逻辑,解决组织部分信息获取错误问题,完成接口冒烟测试并添加线上接口文档;

BREAKING CHANGE: 无

Closes 无

[skip ci]
parent 958c80ce
package pps.core.system.service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import pps.cloud.base.service.BaseBaseStationService;
......@@ -13,47 +10,45 @@ import pps.cloud.base.service.data.BaseOuIdInput;
import pps.cloud.base.service.data.QueryBaseStationInput;
import pps.cloud.base.service.data.QueryBaseStationOutput;
import pps.cloud.system.service.SystemDictionaryService;
import pps.cloud.system.service.data.*;
import pps.cloud.system.service.data.CreateSysDictionaryInput;
import pps.cloud.system.service.data.GetOuListTreeOutput;
import pps.cloud.system.service.data.QuerySysDictionaryViewOutput;
import pps.cloud.system.service.data.SelectRegionFirmInput;
import pps.core.common.constant.Constant;
import pps.core.common.constant.UserConstant;
import pps.core.common.pattern.Builder;
import pps.core.common.session.PpsUserSession;
import pps.core.common.session.SysOrganization;
import pps.core.common.utils.NamedServiceProvider;
import pps.core.system.cache.SysOrganizationCache;
import pps.core.system.constant.DicMenuConstant;
import pps.core.system.constant.OuLevelConstant;
import pps.core.system.constant.SysOrganizationCode;
import pps.core.system.mapper.*;
import pps.core.system.entity.*;
import pps.core.system.mapper.*;
import pps.core.system.service.data.sys_organization.*;
import pps.core.system.service.data.sys_organization.GetSysOrganizationViewOutput;
import pps.core.system.service.data.sys_organization.QuerySysOrganizationViewInput;
import pps.core.system.service.data.sys_organization_rel.GetOuInfoByConditionInput;
import pps.core.system.service.data.sys_organization_rel.GetSysOrganizationRelInput;
import pps.core.system.service.data.sys_organization_rel.QuerySysOrganizationRelInput;
import pps.core.system.service.data.sys_organization_rel.UpdateSysOrganizationRelInput;
import pps.core.common.session.PpsUserSession;
import xstartup.annotation.XService;
import xstartup.annotation.XText;
import xstartup.base.XContext;
import xstartup.base.exception.XServiceException;
import xstartup.base.util.XCopyUtils;
import xstartup.base.util.XDateUtils;
import xstartup.base.util.XStringUtils;
import xstartup.feature.api.annotation.XApiPost;
import xstartup.feature.api.annotation.XApiGet;
import xstartup.feature.api.annotation.XApiAnonymous;
import xstartup.data.XServiceResult;
import xstartup.data.XSingleResult;
import xstartup.data.XListResult;
import xstartup.data.XPageResult;
import xstartup.annotation.XText;
import xstartup.base.XContext;
import xstartup.base.util.XCopyUtils;
import xstartup.data.XServiceResult;
import xstartup.data.XSingleResult;
import xstartup.error.XError;
import xstartup.base.data.CustomQueryInput;
import xstartup.feature.mybatis.helper.XMapperHelper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import xstartup.feature.api.annotation.XApiAnonymous;
import xstartup.feature.api.annotation.XApiPost;
import xstartup.helper.XTransactionHelper;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@XText("组织机构接口")
@XService
public class SysOrganizationService {
......@@ -61,7 +56,7 @@ public class SysOrganizationService {
@XText("根据ouName查询组织机构树和场站")
@XApiPost
public XListResult<QuerySysOrganizationViewOutputTree> selectOuTreeAndStationByOuNameAndStationName(XContext context,GetSysOrganizationInput input){
public XListResult<QuerySysOrganizationViewOutputTree> selectOuTreeAndStationByOuNameAndStationName(XContext context, GetSysOrganizationInput input) {
List<String> ouIds = new ArrayList<>();
BaseBaseStationService stationService = context.getBean(BaseBaseStationService.class);
QueryBaseStationInput stationInput = new QueryBaseStationInput();
......@@ -69,9 +64,9 @@ public class SysOrganizationService {
stationInput.setStationName(input.getOuName());
XListResult<QueryBaseStationOutput> listResult = stationService.selectStationAllByStationName(context, stationInput);
List<QueryBaseStationOutput> stationLikeList = listResult.getResult();
if (!CollectionUtils.isEmpty(stationLikeList)){
if (!CollectionUtils.isEmpty(stationLikeList)) {
for (QueryBaseStationOutput baseStationView : stationLikeList) {
if (XStringUtils.isNotEmpty(baseStationView.getOuId())){
if (XStringUtils.isNotEmpty(baseStationView.getOuId())) {
ouIds.add(baseStationView.getOuId());
}
}
......@@ -93,11 +88,11 @@ public class SysOrganizationService {
for (QuerySysOrganizationViewOutputTree tree : list) {
//如果是超级管理员查所以组织机构
if (UserConstant.ISSUPERADMIN_TRUE.equals(isSuperAdmin)){
if (UserConstant.ISSUPERADMIN_TRUE.equals(isSuperAdmin)) {
if (tree.getParentOuId().equals("00000000-0000-0000-0000-000000000000")) {
trees.add(tree);
}
}else{
} else {
if (tree.getId().equals(session.getOuId())) {
trees.add(tree);
}
......@@ -106,10 +101,10 @@ public class SysOrganizationService {
//子集
for (QuerySysOrganizationViewOutputTree it : list) {
if (OuLevelConstant.CHANG_ZHAN.getCode().equals(it.getOuLevel()) && !CollectionUtils.isEmpty(stationLikeList)){
if (OuLevelConstant.CHANG_ZHAN.getCode().equals(it.getOuLevel()) && !CollectionUtils.isEmpty(stationLikeList)) {
List<QuerySysOrganizationViewOutputTree> stationList = new ArrayList<>();
for (QueryBaseStationOutput baseStationView : stationLikeList) {
if (it.getId().equals(baseStationView.getOuId())){
if (it.getId().equals(baseStationView.getOuId())) {
QuerySysOrganizationViewOutputTree outputTree = new QuerySysOrganizationViewOutputTree();
outputTree.setId(baseStationView.getId());
outputTree.setOuName(baseStationView.getStationName());
......@@ -126,30 +121,30 @@ public class SysOrganizationService {
tree.getChildren().add(it);
}
}
if (tree.getChildren() != null && tree.getChildren().size() > 1){
if (tree.getChildren() != null && tree.getChildren().size() > 1) {
List<QuerySysOrganizationViewOutputTree> children = tree.getChildren();
children.forEach(outputTree -> {
if (outputTree.getSort() == null){
if (outputTree.getSort() == null) {
outputTree.setSort(999);
}
});
children=children.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
children = children.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
tree.setChildren(children);
}
}
trees.forEach(outputTree -> {
if (outputTree.getSort() == null){
if (outputTree.getSort() == null) {
outputTree.setSort(999);
}
});
trees=trees.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
trees = trees.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
return XListResult.success(trees);
}
@XText("根据父级id查询儿子级--最后一级查的是场站")
@XApiPost
public XListResult<GetSysOrganizationViewOutput> selectOuInfoOrStationByParentOuId(XContext context, GetSysOrganizationRelInput input){
public XListResult<GetSysOrganizationViewOutput> selectOuInfoOrStationByParentOuId(XContext context, GetSysOrganizationRelInput input) {
SysOrganizationViewMapper mapper = context.getBean(SysOrganizationViewMapper.class);
SysOrganizationView record = new SysOrganizationView();
XCopyUtils.copyObject(input, record);
......@@ -159,7 +154,7 @@ public class SysOrganizationService {
Integer isSuperAdmin = session.getIsSuperAdmin();
List<SysOrganizationView> viewList = new ArrayList<>();
if (XStringUtils.isNotEmpty(input.getOuLevel()) && OuLevelConstant.CHANG_ZHAN.getCode().equals(input.getOuLevel())){
if (XStringUtils.isNotEmpty(input.getOuLevel()) && OuLevelConstant.CHANG_ZHAN.getCode().equals(input.getOuLevel())) {
if (XStringUtils.isNotEmpty(input.getParentOuId())) {
BaseBaseStationService stationService = context.getBean(BaseBaseStationService.class);
BaseOuIdInput ouIdInput = new BaseOuIdInput();
......@@ -181,16 +176,16 @@ public class SysOrganizationService {
}
}
if (XStringUtils.isEmpty(input.getParentOuId())){
if (XStringUtils.isEmpty(input.getParentOuId())) {
//如果是超级管理员查所以组织机构
if (UserConstant.ISSUPERADMIN_TRUE.equals(isSuperAdmin) || OuLevelConstant.YOU_QI_DIAO_KONG_ZHONG_XIN.getCode().equals(session.getOwnerOrgLevel())){
if (UserConstant.ISSUPERADMIN_TRUE.equals(isSuperAdmin) || OuLevelConstant.YOU_QI_DIAO_KONG_ZHONG_XIN.getCode().equals(session.getOwnerOrgLevel())) {
record.setParentOuId("00000000-0000-0000-0000-000000000000");
viewList = mapper.selectOuSonByParentOuId(record);
}else{
} else {
record.setId(session.getOuId());
viewList = mapper.selectOuByOuId(record);
}
}else{
} else {
viewList = mapper.selectOuSonByParentOuId(record);
}
......@@ -200,22 +195,20 @@ public class SysOrganizationService {
}
@XText("根据用户id查询地区公司")
@XApiPost
public XListResult<GetSysOrganizationViewOutput> selectRegionFirmByUserId(XContext context,SelectRegionFirmInput input){
public XListResult<GetSysOrganizationViewOutput> selectRegionFirmByUserId(XContext context, SelectRegionFirmInput input) {
PpsUserSession session = context.getSession(PpsUserSession.class);
SysOrganizationMapper bean = context.getBean(SysOrganizationMapper.class);
QueryWrapper<SysOrganizationEnt> wrapper = new QueryWrapper<>();
String ouId = session.getOuId();
if(StringUtils.isNotBlank(input.getOuId())){
if (StringUtils.isNotBlank(input.getOuId())) {
ouId = input.getOuId();
}
wrapper.lambda().eq(SysOrganizationEnt::getId,ouId).eq(SysOrganizationEnt::getIsDeleted,SysOrganizationCode.NORMAL);
wrapper.lambda().eq(SysOrganizationEnt::getId, ouId).eq(SysOrganizationEnt::getIsDeleted, SysOrganizationCode.NORMAL);
SysOrganizationEnt ou = bean.selectOne(wrapper);
if (ou == null){
if (ou == null) {
return XListResult.success(new ArrayList<>());
}
List<GetSysOrganizationViewOutput> outputs = new ArrayList<>();
......@@ -228,21 +221,21 @@ public class SysOrganizationService {
view.setOuLevel(OuLevelConstant.YOU_QI_DIAO_KONG_ZHONG_XIN.getCode());
SysOrganizationView organization = viewMapper.getSysOrganizationByOuLevelAndOuId(view);
if (OuLevelConstant.ZHUAN_YE_GONG_SI.getCode().equals(ou.getOuLevel()) || organization != null && OuLevelConstant.YOU_QI_DIAO_KONG_ZHONG_XIN.getCode().equals(organization.getOuLevel()) ){
if (OuLevelConstant.ZHUAN_YE_GONG_SI.getCode().equals(ou.getOuLevel()) || organization != null && OuLevelConstant.YOU_QI_DIAO_KONG_ZHONG_XIN.getCode().equals(organization.getOuLevel())) {
wrapper = new QueryWrapper<>();
wrapper.lambda().eq(SysOrganizationEnt::getOuLevel,OuLevelConstant.DI_QU_GONG_SI.getCode())
.eq(SysOrganizationEnt::getIsDeleted,SysOrganizationCode.NORMAL)
.orderBy(true,true,SysOrganizationEnt::getId);
wrapper.lambda().eq(SysOrganizationEnt::getOuLevel, OuLevelConstant.DI_QU_GONG_SI.getCode())
.eq(SysOrganizationEnt::getIsDeleted, SysOrganizationCode.NORMAL)
.orderBy(true, true, SysOrganizationEnt::getId);
List<SysOrganizationEnt> organizationEnts = bean.selectList(wrapper);
outputs = XCopyUtils.copyNewList(organizationEnts, GetSysOrganizationViewOutput.class);
}else{
} else {
view = new SysOrganizationView();
view.setEndTime(new Date());
view.setId(ouId);
view.setOuLevel(OuLevelConstant.DI_QU_GONG_SI.getCode());
SysOrganizationView organization1 = viewMapper.getSysOrganizationByOuLevelAndOuId(view);
GetSysOrganizationViewOutput output = new GetSysOrganizationViewOutput();
XCopyUtils.copyObject(organization1,output);
XCopyUtils.copyObject(organization1, output);
outputs.add(output);
}
......@@ -251,7 +244,7 @@ public class SysOrganizationService {
@XText("根据ouName查询组织机构树")
@XApiPost
public XListResult<QuerySysOrganizationViewOutputTree> selectSysOrganizationTreeByOuName(XContext context,GetSysOrganizationInput input){
public XListResult<QuerySysOrganizationViewOutputTree> selectSysOrganizationTreeByOuName(XContext context, GetSysOrganizationInput input) {
SysOrganizationViewMapper mapper = context.getBean(SysOrganizationViewMapper.class);
SysOrganizationView record = new SysOrganizationView();
XCopyUtils.copyObject(input, record);
......@@ -265,11 +258,11 @@ public class SysOrganizationService {
for (QuerySysOrganizationViewOutputTree tree : list) {
//如果是超级管理员查所以组织机构
if (UserConstant.ISSUPERADMIN_TRUE.equals(isSuperAdmin)){
if (UserConstant.ISSUPERADMIN_TRUE.equals(isSuperAdmin)) {
if (tree.getParentOuId().equals("00000000-0000-0000-0000-000000000000")) {
trees.add(tree);
}
}else{
} else {
if (tree.getId().equals(session.getOuId())) {
trees.add(tree);
}
......@@ -284,23 +277,23 @@ public class SysOrganizationService {
tree.getChildren().add(it);
}
}
if (tree.getChildren() != null && tree.getChildren().size() > 1){
if (tree.getChildren() != null && tree.getChildren().size() > 1) {
List<QuerySysOrganizationViewOutputTree> children = tree.getChildren();
children.forEach(outputTree -> {
if (outputTree.getSort() == null){
if (outputTree.getSort() == null) {
outputTree.setSort(999);
}
});
children=children.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
children = children.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
tree.setChildren(children);
}
}
trees.forEach(outputTree -> {
if (outputTree.getSort() == null){
if (outputTree.getSort() == null) {
outputTree.setSort(999);
}
});
trees=trees.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
trees = trees.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
return XListResult.success(trees);
}
......@@ -308,7 +301,7 @@ public class SysOrganizationService {
@XText("根据条件组织机构树")
@XApiPost
public XListResult<QuerySysOrganizationViewOutputTree> getOuTreeByCondition(XContext context,GetOuInfoByConditionInput input){
public XListResult<QuerySysOrganizationViewOutputTree> getOuTreeByCondition(XContext context, GetOuInfoByConditionInput input) {
SysOrganizationViewMapper mapper = context.getBean(SysOrganizationViewMapper.class);
SysOrganizationView record = new SysOrganizationView();
XCopyUtils.copyObject(input, record);
......@@ -319,19 +312,19 @@ public class SysOrganizationService {
List<QuerySysOrganizationViewOutputTree> trees = new ArrayList<>();
String rootId = null;
String ouId = null;
if(input.getShowAll() != null && input.getShowAll()){
if (input.getShowAll() != null && input.getShowAll()) {
rootId = "00000000-0000-0000-0000-000000000000";
}else{
} else {
PpsUserSession session = context.getSession(PpsUserSession.class);
ouId = session.getOuId();
}
for (QuerySysOrganizationViewOutputTree tree : list) {
if (rootId != null){
if (rootId != null) {
if (tree.getParentOuId().equals(rootId)) {
trees.add(tree);
}
}else{
} else {
if (tree.getId().equals(ouId)) {
trees.add(tree);
}
......@@ -345,23 +338,23 @@ public class SysOrganizationService {
tree.getChildren().add(it);
}
}
if (tree.getChildren() != null && tree.getChildren().size() > 1){
if (tree.getChildren() != null && tree.getChildren().size() > 1) {
List<QuerySysOrganizationViewOutputTree> children = tree.getChildren();
children.forEach(outputTree -> {
if (outputTree.getSort() == null){
if (outputTree.getSort() == null) {
outputTree.setSort(999);
}
});
children=children.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
children = children.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
tree.setChildren(children);
}
}
trees.forEach(outputTree -> {
if (outputTree.getSort() == null){
if (outputTree.getSort() == null) {
outputTree.setSort(999);
}
});
trees=trees.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
trees = trees.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
return XListResult.success(trees);
}
......@@ -369,7 +362,7 @@ public class SysOrganizationService {
@XText("根据条件查询组织机构")
@XApiPost
public XListResult<GetSysOrganizationViewOutput> getOuInfoByCondition(XContext context, GetOuInfoByConditionInput input){
public XListResult<GetSysOrganizationViewOutput> getOuInfoByCondition(XContext context, GetOuInfoByConditionInput input) {
SysOrganizationViewMapper mapper = context.getBean(SysOrganizationViewMapper.class);
SysOrganizationView record = new SysOrganizationView();
XCopyUtils.copyObject(input, record);
......@@ -377,23 +370,23 @@ public class SysOrganizationService {
record.setIsDeleted(SysOrganizationCode.NORMAL);
String rootId = null;
String ouId = null;
if(input.getShowAll() != null && input.getShowAll()){
if (input.getShowAll() != null && input.getShowAll()) {
rootId = "00000000-0000-0000-0000-000000000000";
}else{
} else {
PpsUserSession session = context.getSession(PpsUserSession.class);
ouId = session.getOuId();
}
List<SysOrganizationView> viewList = new ArrayList<>();
if (XStringUtils.isEmpty(input.getParentOuId())){
if (XStringUtils.isEmpty(input.getParentOuId())) {
//如果是超级管理员查所以组织机构
if (rootId != null){
if (rootId != null) {
record.setParentOuId(rootId);
viewList = mapper.selectOuSonByParentOuId(record);
}else{
} else {
record.setId(ouId);
viewList = mapper.selectOuByOuId(record);
}
}else{
} else {
viewList = mapper.selectOuSonByParentOuId(record);
}
List<GetSysOrganizationViewOutput> outputs = XCopyUtils.copyNewList(viewList, GetSysOrganizationViewOutput.class);
......@@ -402,7 +395,7 @@ public class SysOrganizationService {
@XText("根据父级id查询儿子级")
@XApiPost
public XListResult<GetSysOrganizationViewOutput> selectOuInfoByParentOuId(XContext context, GetSysOrganizationRelInput input){
public XListResult<GetSysOrganizationViewOutput> selectOuInfoByParentOuId(XContext context, GetSysOrganizationRelInput input) {
SysOrganizationViewMapper mapper = context.getBean(SysOrganizationViewMapper.class);
SysOrganizationView record = new SysOrganizationView();
XCopyUtils.copyObject(input, record);
......@@ -411,28 +404,27 @@ public class SysOrganizationService {
PpsUserSession session = context.getSession(PpsUserSession.class);
Integer isSuperAdmin = session.getIsSuperAdmin();
List<SysOrganizationView> viewList = new ArrayList<>();
if (XStringUtils.isEmpty(input.getParentOuId())){
if (XStringUtils.isEmpty(input.getParentOuId())) {
//如果是超级管理员查所以组织机构
if (UserConstant.ISSUPERADMIN_TRUE.equals(isSuperAdmin)){
if (UserConstant.ISSUPERADMIN_TRUE.equals(isSuperAdmin)) {
record.setParentOuId("00000000-0000-0000-0000-000000000000");
viewList = mapper.selectOuSonByParentOuId(record);
}else{
} else {
record.setId(session.getOuId());
viewList = mapper.selectOuByOuId(record);
}
}else{
} else {
viewList = mapper.selectOuSonByParentOuId(record);
}
List<GetSysOrganizationViewOutput> outputs = XCopyUtils.copyNewList(viewList, GetSysOrganizationViewOutput.class);
return XListResult.success(outputs);
}
@XText("根据父级id查询儿子级-特殊")
@XApiPost
public XListResult<GetSysOrganizationViewOutput> selectSpecailOuInfoByParentOuId(XContext context, GetSysOrganizationRelInput input){
public XListResult<GetSysOrganizationViewOutput> selectSpecailOuInfoByParentOuId(XContext context, GetSysOrganizationRelInput input) {
SysOrganizationViewMapper mapper = context.getBean(SysOrganizationViewMapper.class);
SysOrganizationView record = new SysOrganizationView();
XCopyUtils.copyObject(input, record);
......@@ -446,21 +438,21 @@ public class SysOrganizationService {
dictionaryView.setAlias("sys_inform_org");
Boolean isSpecial = false;
List<SysDictionaryView> dictionaryViews = dictionaryViewMapper.selectListsByAlias(dictionaryView);
if(!CollectionUtils.isEmpty(dictionaryViews)){
SysDictionaryView isExit = dictionaryViews.stream().filter(item->XDateUtils.compare(item.getEndTime() , new Date()) >= 0 && item.getRemark().equals(session.getOuId())).findFirst().orElse(null);
if(isExit != null)
if (!CollectionUtils.isEmpty(dictionaryViews)) {
SysDictionaryView isExit = dictionaryViews.stream().filter(item -> XDateUtils.compare(item.getEndTime(), new Date()) >= 0 && item.getRemark().equals(session.getOuId())).findFirst().orElse(null);
if (isExit != null)
isSpecial = true;
}
if (XStringUtils.isEmpty(input.getParentOuId())){
if (XStringUtils.isEmpty(input.getParentOuId())) {
//如果是超级管理员查所以组织机构
if (UserConstant.ISSUPERADMIN_TRUE.equals(isSuperAdmin) || isSpecial){
if (UserConstant.ISSUPERADMIN_TRUE.equals(isSuperAdmin) || isSpecial) {
record.setParentOuId("00000000-0000-0000-0000-000000000000");
viewList = mapper.selectOuSonByParentOuId(record);
}else{
} else {
record.setId(session.getOuId());
viewList = mapper.selectOuByOuId(record);
}
}else{
} else {
viewList = mapper.selectOuSonByParentOuId(record);
}
List<GetSysOrganizationViewOutput> outputs = XCopyUtils.copyNewList(viewList, GetSysOrganizationViewOutput.class);
......@@ -469,7 +461,7 @@ public class SysOrganizationService {
@XText("根据登录用户所属组织机构ID查询组织机构子级树")
@XApiPost
public XListResult<QuerySysOrganizationViewOutputTree> getSysOrganizationTreeByUserId(XContext context, GetSysOrganizationInput input){
public XListResult<QuerySysOrganizationViewOutputTree> getSysOrganizationTreeByUserId(XContext context, GetSysOrganizationInput input) {
SysOrganizationViewMapper mapper = context.getBean(SysOrganizationViewMapper.class);
SysOrganizationView view = new SysOrganizationView();
PpsUserSession session = context.getSession(PpsUserSession.class);
......@@ -491,34 +483,34 @@ public class SysOrganizationService {
tree.getChildren().add(it);
}
}
if (tree.getChildren() != null && tree.getChildren().size() > 1){
if (tree.getChildren() != null && tree.getChildren().size() > 1) {
List<QuerySysOrganizationViewOutputTree> children = tree.getChildren();
children.forEach(outputTree -> {
if (outputTree.getSort() == null){
if (outputTree.getSort() == null) {
outputTree.setSort(999);
}
});
children=children.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
children = children.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
tree.setChildren(children);
}
}
trees.forEach(outputTree -> {
if (outputTree.getSort() == null){
if (outputTree.getSort() == null) {
outputTree.setSort(999);
}
});
trees=trees.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
trees = trees.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
return XListResult.success(trees);
}
@XText("查询组织机构树")
@XApiPost
public XListResult<QuerySysOrganizationViewOutputTree> getSysOrganizationTree(XContext context, GetSysOrganizationInput input){
public XListResult<QuerySysOrganizationViewOutputTree> getSysOrganizationTree(XContext context, GetSysOrganizationInput input) {
//先从缓存中获取
List<SysOrganizationCache> sysOrganizationCaches = SysOrganizationCache.list(context, SysOrganizationCode.SYS_ORGANIZATION_CACHE);
//缓存不存在从数据库获取
if (CollectionUtils.isEmpty(sysOrganizationCaches)){
if (CollectionUtils.isEmpty(sysOrganizationCaches)) {
List<SysOrganizationCache> caches = selectSysOrganizationTree(context, input);
List<QuerySysOrganizationViewOutputTree> resultTree = XCopyUtils.copyNewList(caches, QuerySysOrganizationViewOutputTree.class);
......@@ -529,7 +521,7 @@ public class SysOrganizationService {
return XListResult.success(resultTree);
}
private List<SysOrganizationCache> selectSysOrganizationTree(XContext context,GetSysOrganizationInput input){
private List<SysOrganizationCache> selectSysOrganizationTree(XContext context, GetSysOrganizationInput input) {
SysOrganizationViewMapper mapper = context.getBean(SysOrganizationViewMapper.class);
SysOrganizationView record = new SysOrganizationView();
XCopyUtils.copyObject(input, record);
......@@ -552,32 +544,32 @@ public class SysOrganizationService {
tree.getChildren().add(it);
}
}
if (tree.getChildren() != null && tree.getChildren().size() > 1){
if (tree.getChildren() != null && tree.getChildren().size() > 1) {
List<QuerySysOrganizationViewOutputTree> children = tree.getChildren();
children.forEach(outputTree -> {
if (outputTree.getSort() == null){
if (outputTree.getSort() == null) {
outputTree.setSort(999);
}
});
children=children.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
children = children.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
tree.setChildren(children);
}
}
trees.forEach(outputTree -> {
if (outputTree.getSort() == null){
if (outputTree.getSort() == null) {
outputTree.setSort(999);
}
});
trees=trees.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
trees = trees.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
List<SysOrganizationCache> caches = XCopyUtils.copyNewList(trees, SysOrganizationCache.class);
//放入redis缓存中
SysOrganizationCache.set(context,SysOrganizationCode.SYS_ORGANIZATION_CACHE,caches);
SysOrganizationCache.set(context, SysOrganizationCode.SYS_ORGANIZATION_CACHE, caches);
return caches;
}
@XText("查询组织机构单节点树")
@XApiPost
public XListResult<QuerySysOrganizationViewOutputTree> selectSysOrganizationTreeByParentOuId(XContext context,GetSysOrganizationInput input){
public XListResult<QuerySysOrganizationViewOutputTree> selectSysOrganizationTreeByParentOuId(XContext context, GetSysOrganizationInput input) {
SysOrganizationViewMapper mapper = context.getBean(SysOrganizationViewMapper.class);
SysOrganizationView record = new SysOrganizationView();
XCopyUtils.copyObject(input, record);
......@@ -585,7 +577,7 @@ public class SysOrganizationService {
List<SysOrganizationView> viewList = mapper.selectOrganizationByParentOuIdOrOuId(record);
List<QuerySysOrganizationViewOutputTree> list = XCopyUtils.copyNewList(viewList, QuerySysOrganizationViewOutputTree.class);
List<QuerySysOrganizationViewOutputTree> trees = new ArrayList<>();
if ("00000000-0000-0000-0000-000000000000".equals(input.getId())){
if ("00000000-0000-0000-0000-000000000000".equals(input.getId())) {
trees.add(list.get(0));
} else {
for (QuerySysOrganizationViewOutputTree tree : list) {
......@@ -601,32 +593,32 @@ public class SysOrganizationService {
tree.getChildren().add(it);
}
}
if (tree.getChildren() != null && tree.getChildren().size() > 1){
if (tree.getChildren() != null && tree.getChildren().size() > 1) {
List<QuerySysOrganizationViewOutputTree> children = tree.getChildren();
children.forEach(outputTree -> {
if (outputTree.getSort() == null){
if (outputTree.getSort() == null) {
outputTree.setSort(999);
}
});
children=children.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
children = children.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
tree.setChildren(children);
}
}
}
trees.forEach(outputTree -> {
if (outputTree.getSort() == null){
if (outputTree.getSort() == null) {
outputTree.setSort(999);
}
});
trees=trees.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
trees = trees.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutputTree::getSort)).collect(Collectors.toList());
return XListResult.success(trees);
}
@XText("查询组织机构列表")
@XApiPost
public XPageResult<QuerySysOrganizationViewOutput> querySysOrganizationViewPage(XContext context, QuerySysOrganizationViewInput input){
public XPageResult<QuerySysOrganizationViewOutput> querySysOrganizationViewPage(XContext context, QuerySysOrganizationViewInput input) {
SysOrganizationViewMapper mapper = context.getBean(SysOrganizationViewMapper.class);
SystemDictionaryService dictService = context.getBean(SystemDictionaryService.class);
SysOrganizationView record = new SysOrganizationView();
......@@ -635,12 +627,12 @@ public class SysOrganizationService {
record.setIsDeleted(SysOrganizationCode.NORMAL);
record.setEndTime(new Date());
List<SysOrganizationView> list = mapper.selectSysOrganizationList(record);
if(!CollectionUtils.isEmpty(list)){
if (!CollectionUtils.isEmpty(list)) {
List<String> parentIds = list.stream().map(SysOrganizationView::getId).collect(Collectors.toList());
List<SysOrganizationView> childList = mapper.selectCountByParentOuIds(parentIds , new Date());
Map<String , List<SysOrganizationView>> groupChildList = childList.stream().collect(Collectors.groupingBy(SysOrganizationView::getParentOuId));
list.stream().forEach(item->{
if(groupChildList.get(item.getId()) != null)
List<SysOrganizationView> childList = mapper.selectCountByParentOuIds(parentIds, new Date());
Map<String, List<SysOrganizationView>> groupChildList = childList.stream().collect(Collectors.groupingBy(SysOrganizationView::getParentOuId));
list.stream().forEach(item -> {
if (groupChildList.get(item.getId()) != null)
item.setIsHasChildren(1);
else
item.setIsHasChildren(0);
......@@ -693,7 +685,7 @@ public class SysOrganizationService {
}
}
}
if (buffer.length()>0){
if (buffer.length() > 0) {
String mediaTypeName = buffer.substring(1);
view.setPropertyName(mediaTypeName);
}
......@@ -724,141 +716,80 @@ public class SysOrganizationService {
}
PageInfo<SysOrganizationView> pageInfo = new PageInfo<>(list);
List<QuerySysOrganizationViewOutput> outputs = XCopyUtils.copyNewList(pageInfo.getList(), QuerySysOrganizationViewOutput.class);
outputs=outputs.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutput::getSort)).collect(Collectors.toList());
outputs = outputs.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutput::getSort)).collect(Collectors.toList());
return XPageResult.success(outputs, input, pageInfo.getTotal());
}
@XText("查询组织机构列表")
@XApiAnonymous
@XApiPost
public XPageResult<QuerySysOrganizationViewOutput> querySysOrganizationViewIncluedOwnerPage(XContext context, QuerySysOrganizationViewInput input){
public XPageResult<QuerySysOrganizationViewOutput> querySysOrganizationViewIncluedOwnerPage(XContext context, QuerySysOrganizationViewInput input) {
SysOrganizationViewMapper mapper = context.getBean(SysOrganizationViewMapper.class);
SystemDictionaryService dictService = context.getBean(SystemDictionaryService.class);
SysOrganizationView record = new SysOrganizationView();
XCopyUtils.copyObject(input, record);
PageHelper.startPage(input.getPage(), input.getLimit());
record.setIsDeleted(SysOrganizationCode.NORMAL);
record.setEndTime(new Date());
List<SysOrganizationView> list = mapper.selectSysOrganizationList(record);
if(CollectionUtils.isEmpty(list) && XStringUtils.isNotEmpty(record.getId())
&& StringUtils.isEmpty(record.getOuCode()) && StringUtils.isEmpty(record.getOuName()) && StringUtils.isEmpty(record.getShortName())){
if (CollectionUtils.isEmpty(list) && StringUtils.isNotBlank(record.getId())) {
SysOrganizationView owner = mapper.selectOne(record);
List<String> ids = new ArrayList<>();
ids.add(record.getId());
List<SysOrganizationView> parentList = mapper.selectOrganizationBySubOuIds(Arrays.asList(record.getId()));
SysOrganizationView parent = parentList.stream().filter(item ->item.getEndTime() != null && XDateUtils.compare(item.getEndTime() , new Date()) >= 1).findFirst().orElse(null);
if(null != parent){
if (!CollectionUtils.isEmpty(parentList)) {
SysOrganizationView parent = parentList.get(0);
owner.setParentOuId(parent.getParentOuId());
owner.setPartentName(parent.getPartentName());
}
list.add(owner);
}
if(!CollectionUtils.isEmpty(list)){
List<String> parentIds = list.stream().map(SysOrganizationView::getId).collect(Collectors.toList());
List<SysOrganizationView> childList = mapper.selectCountByParentOuIds(parentIds , new Date());
Map<String , List<SysOrganizationView>> groupChildList = childList.stream().collect(Collectors.groupingBy(SysOrganizationView::getParentOuId));
list.stream().forEach(item->{
if(groupChildList.get(item.getId()) != null)
item.setIsHasChildren(1);
else
item.setIsHasChildren(0);
});
}
//单位级别
CreateSysDictionaryInput unitLevelInput = new CreateSysDictionaryInput();
unitLevelInput.setAlias("UNIT_LEVEL");
XListResult<QuerySysDictionaryViewOutput> unitLevel = dictService.querySysDictionarysByAlias(context, unitLevelInput);
//介质类型
CreateSysDictionaryInput mediaTypesInput = new CreateSysDictionaryInput();
mediaTypesInput.setAlias("MEDIUM_TYPE");
XListResult<QuerySysDictionaryViewOutput> mediaTypes = dictService.querySysDictionarysByAlias(context, mediaTypesInput);
//国家
CreateSysDictionaryInput countryInput = new CreateSysDictionaryInput();
countryInput.setAlias("COUNTRIES");
XListResult<QuerySysDictionaryViewOutput> countrys = dictService.querySysDictionarysByAlias(context, countryInput);
unitLevel.throwIfFail();
if (!CollectionUtils.isEmpty(list)) {
List<String> parentIds = list.stream()
.map(SysOrganizationView::getId)
.collect(Collectors.toList());
List<SysOrganizationView> childList = mapper.selectCountByParentOuIds(parentIds, null);
Map<String, List<SysOrganizationView>> groupChildList = childList.stream()
.collect(Collectors.groupingBy(SysOrganizationView::getParentOuId));
for (SysOrganizationView view : list) {
if(view.getSort() == null)
if (Objects.isNull(view.getSort())) {
view.setSort(0);
//单位级别
if (view.getOuLevel() != null) {
if (unitLevel.getResult() != null) {
List<QuerySysDictionaryViewOutput> items = unitLevel.getResult();
for (QuerySysDictionaryViewOutput item : items) {
if (view.getOuLevel().equals(item.getDicKey())) {
view.setLevelDicName(item.getDicName());
}
}
}
if (view.getLevelDicName() == null) {
view.setLevelDicName(view.getOuLevel());
}
}
//介质类型
if (view.getMediaType() != null) {
if (mediaTypes.getResult() != null) {
List<QuerySysDictionaryViewOutput> items = mediaTypes.getResult();
String[] split = view.getMediaType().split(",");
StringBuilder buffer = new StringBuilder();
for (String mediaType : split) {
for (QuerySysDictionaryViewOutput item : items) {
if (mediaType.equals(item.getDicKey())) {
buffer.append(",");
buffer.append(item.getDicName());
}
}
}
if (buffer.length()>0){
String mediaTypeName = buffer.substring(1);
view.setPropertyName(mediaTypeName);
}
}
if (view.getPropertyName() == null) {
view.setPropertyName(view.getMediaType());
}
}
//国家
if (view.getCountry() != null) {
if (countrys.getResult() != null) {
List<QuerySysDictionaryViewOutput> items = countrys.getResult();
for (QuerySysDictionaryViewOutput item : items) {
if (view.getCountry().equals(item.getDicKey())) {
view.setCountryName(item.getDicName());
}
}
if (Objects.nonNull(groupChildList.get(view.getId()))) {
view.setIsHasChildren(1);
} else {
view.setIsHasChildren(0);
}
if (view.getCountryName() == null) {
view.setCountryName(view.getCountry());
//单位级别
if (!CollectionUtils.isEmpty(unitLevel.getResult())) {
view.setLevelDicName(unitLevel.getResult().stream()
.filter(row -> StringUtils.equals(row.getDicKey(), view.getOuLevel()))
.map(QuerySysDictionaryViewOutput::getDicName)
.findAny()
.orElse(null));
}
}
}
PageInfo<SysOrganizationView> pageInfo = new PageInfo<>(list);
List<QuerySysOrganizationViewOutput> outputs = XCopyUtils.copyNewList(pageInfo.getList(), QuerySysOrganizationViewOutput.class);
outputs=outputs.stream().sorted(Comparator.comparing(QuerySysOrganizationViewOutput::getSort)).collect(Collectors.toList());
return XPageResult.success(outputs, input, pageInfo.getTotal());
}
@XText("组织机构排序")
@XApiPost
public XServiceResult updateSysOrganizationRelSort(XContext context, UpdateSysOrganizationRelInput input) throws XServiceException{
public XServiceResult updateSysOrganizationRelSort(XContext context, UpdateSysOrganizationRelInput input) throws XServiceException {
return XTransactionHelper.begin(context, () -> {
SysOrganizationRelMapper mapper = context.getBean(SysOrganizationRelMapper.class);
Date date = new Date();
QueryWrapper<SysOrganizationRelEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SysOrganizationRelEnt::getOuId, input.getId());
queryWrapper.lambda().le(true,SysOrganizationRelEnt::getEffectTime,date);
queryWrapper.lambda().ge(true,SysOrganizationRelEnt::getEndTime,date);
queryWrapper.lambda().le(true, SysOrganizationRelEnt::getEffectTime, date);
queryWrapper.lambda().ge(true, SysOrganizationRelEnt::getEndTime, date);
SysOrganizationRelEnt entity = mapper.selectOne(queryWrapper);
if(entity == null) {
if (entity == null) {
return XServiceResult.error(context, XError.NotFound);
}
Integer entitySort = entity.getSort();
......@@ -866,15 +797,15 @@ public class SysOrganizationService {
QueryWrapper<SysOrganizationRelEnt> sortQueryWrapper = new QueryWrapper<>();
sortQueryWrapper.lambda().eq(SysOrganizationRelEnt::getParentOuId, entity.getParentOuId());
sortQueryWrapper.lambda().le(true,SysOrganizationRelEnt::getEffectTime,date);
sortQueryWrapper.lambda().ge(true,SysOrganizationRelEnt::getEndTime,date);
sortQueryWrapper.lambda().le(true, SysOrganizationRelEnt::getEffectTime, date);
sortQueryWrapper.lambda().ge(true, SysOrganizationRelEnt::getEndTime, date);
//判断是上移还是下移
if (input.getSortFlag().equals("up")){
if (input.getSortFlag().equals("up")) {
//sort-=1;
sortQueryWrapper.lambda().le(SysOrganizationRelEnt::getSort, entitySort);
sortQueryWrapper.lambda().orderByDesc(SysOrganizationRelEnt::getSort);
}else{
} else {
//sort+=1;
sortQueryWrapper.lambda().ge(SysOrganizationRelEnt::getSort, entitySort);
sortQueryWrapper.lambda().orderByAsc(SysOrganizationRelEnt::getSort);
......@@ -884,16 +815,16 @@ public class SysOrganizationService {
List<SysOrganizationRelEnt> relEnts = mapper.selectList(sortQueryWrapper);
PpsUserSession session = context.getSession(PpsUserSession.class);
if (!CollectionUtils.isEmpty(relEnts) && relEnts.size()>1){
if (!CollectionUtils.isEmpty(relEnts) && relEnts.size() > 1) {
SysOrganizationRelEnt relEnt = relEnts.get(1);
Integer relEntSort = relEnt.getSort();
if (input.getSortFlag().equals("up")){
if (relEntSort != null && relEntSort.equals(entitySort)){
relEntSort-=1;
if (input.getSortFlag().equals("up")) {
if (relEntSort != null && relEntSort.equals(entitySort)) {
relEntSort -= 1;
}
}else{
if (relEntSort != null && relEntSort.equals(entitySort)){
relEntSort+=1;
} else {
if (relEntSort != null && relEntSort.equals(entitySort)) {
relEntSort += 1;
}
}
......@@ -920,7 +851,7 @@ public class SysOrganizationService {
@XText("新增组织机构信息")
@XApiPost
public XServiceResult createSysOrganization(XContext context, CreateSysOrganizationInput input)throws XServiceException{
public XServiceResult createSysOrganization(XContext context, CreateSysOrganizationInput input) throws XServiceException {
return XTransactionHelper.begin(context, () -> {
SysOrganizationMapper mapper = context.getBean(SysOrganizationMapper.class);
......@@ -933,7 +864,7 @@ public class SysOrganizationService {
entity.setIsDeleted(SysOrganizationCode.NORMAL);
entity.setCreateTime(date);
PpsUserSession session = context.getSession(PpsUserSession.class);
if (session != null){
if (session != null) {
entity.setCreateById(session.getId());
entity.setCreateByName(session.getUserName());
}
......@@ -942,14 +873,14 @@ public class SysOrganizationService {
//先修改父级为有子集状态
if (input.getParentOuId() != null) {
QueryWrapper<SysOrganizationRelEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().le(true,SysOrganizationRelEnt::getEffectTime,new Date());
queryWrapper.lambda().ge(true,SysOrganizationRelEnt::getEndTime,new Date());
queryWrapper.lambda().le(true, SysOrganizationRelEnt::getEffectTime, new Date());
queryWrapper.lambda().ge(true, SysOrganizationRelEnt::getEndTime, new Date());
queryWrapper.lambda().eq(SysOrganizationRelEnt::getOuId, input.getParentOuId());
SysOrganizationRelEnt parent = relMapper.selectOne(queryWrapper);
if (parent !=null){
if (parent != null) {
parent.setIsHasChildren(Constant.ISHASHCHILDREN_TRUE);
parent.setModifyTime(new Date());
if (session != null){
if (session != null) {
parent.setModifyById(session.getId());
parent.setModifyByName(session.getUserName());
}
......@@ -958,10 +889,10 @@ public class SysOrganizationService {
}
//新增组织机构关系表
insertSysOrganizationRel(context,date,uuid,input.getParentOuId(),input.getSort(),session);
insertSysOrganizationRel(context, date, uuid, input.getParentOuId(), input.getSort(), session);
//新增组织机构属性表
insertSysOrganizationProperty(context,date,input.getId(),"GAS",session);
insertSysOrganizationProperty(context, date, input.getId(), "GAS", session);
//更新缓存中组织机构树
selectSysOrganizationTree(context, new GetSysOrganizationInput());
......@@ -972,14 +903,14 @@ public class SysOrganizationService {
@XText("获取当前父级下最大的序号")
@XApiPost
public XSingleResult<QuerySysOrganizationRelInput> selectMaxSort (XContext context, GetSysOrganizationRelInput input){
public XSingleResult<QuerySysOrganizationRelInput> selectMaxSort(XContext context, GetSysOrganizationRelInput input) {
SysOrganizationRelViewMapper relViewMapper = context.getBean(SysOrganizationRelViewMapper.class);
SysOrganizationRelView relView = relViewMapper.selectMaxSort(input.getParentOuId());
QuerySysOrganizationRelInput output = new QuerySysOrganizationRelInput();
if (relView !=null){
if (relView != null) {
Integer sort1 = relView.getSort();
output.setSort(++sort1);
}else {
} else {
output.setSort(1);
}
return XSingleResult.success(output);
......@@ -987,7 +918,7 @@ public class SysOrganizationService {
@XText("修改组织机构信息")
@XApiPost
public XServiceResult updateSysOrganization(XContext context, UpdateSysOrganizationInput input)throws XServiceException{
public XServiceResult updateSysOrganization(XContext context, UpdateSysOrganizationInput input) throws XServiceException {
return XTransactionHelper.begin(context, () -> {
SysOrganizationMapper mapper = context.getBean(SysOrganizationMapper.class);
......@@ -996,7 +927,7 @@ public class SysOrganizationService {
QueryWrapper<SysOrganizationEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SysOrganizationEnt::getId, input.getId());
SysOrganizationEnt entity = mapper.selectOne(queryWrapper);
if(entity == null) {
if (entity == null) {
return XServiceResult.error(context, XError.NotFound);
}
......@@ -1004,7 +935,7 @@ public class SysOrganizationService {
Date date = new Date();
entity.setModifyTime(date);
PpsUserSession session = context.getSession(PpsUserSession.class);
if (session != null){
if (session != null) {
entity.setModifyById(session.getId());
entity.setModifyByName(session.getUserName());
}
......@@ -1017,7 +948,7 @@ public class SysOrganizationService {
relQueryWrapper.lambda().le(SysOrganizationRelEnt::getEffectTime, new Date());
relQueryWrapper.lambda().ge(SysOrganizationRelEnt::getEndTime, new Date());
SysOrganizationRelEnt relEntity = relMapper.selectOne(relQueryWrapper);
if (relEntity == null){
if (relEntity == null) {
throw new XServiceException("数据有误!");
}
try {
......@@ -1055,11 +986,11 @@ public class SysOrganizationService {
}
relEntity.setEndTime(date);
//新增组织机构关系表
insertSysOrganizationRel(context,date,input.getId(),input.getParentOuId(),input.getSort(),session);
insertSysOrganizationRel(context, date, input.getId(), input.getParentOuId(), input.getSort(), session);
}
relEntity.setSort(input.getSort());
relEntity.setModifyTime(date);
if (session != null){
if (session != null) {
relEntity.setModifyById(session.getId());
relEntity.setModifyByName(session.getUserName());
}
......@@ -1069,21 +1000,21 @@ public class SysOrganizationService {
//修改组织机构属性表
QueryWrapper<SysOrganizationPropertyEnt> propertyQueryWrapper = new QueryWrapper<>();
propertyQueryWrapper.lambda().eq(SysOrganizationPropertyEnt::getOuId, input.getId())
.le(SysOrganizationPropertyEnt::getEffectTime,new Date())
.ge(SysOrganizationPropertyEnt::getEndTime,new Date());
.le(SysOrganizationPropertyEnt::getEffectTime, new Date())
.ge(SysOrganizationPropertyEnt::getEndTime, new Date());
List<SysOrganizationPropertyEnt> propertyEntitys = propertyMapper.selectList(propertyQueryWrapper);
//组织机构属性数据全部改为失效
propertyEntitys.forEach(sysOrganizationPropertyEnt -> {
sysOrganizationPropertyEnt.setEndTime(date);
sysOrganizationPropertyEnt.setModifyTime(date);
if (session != null){
if (session != null) {
sysOrganizationPropertyEnt.setModifyById(session.getId());
sysOrganizationPropertyEnt.setModifyByName(session.getUserName());
}
propertyMapper.updateById(sysOrganizationPropertyEnt);
});
insertSysOrganizationProperty(context,date,input.getId(),"GAS",session);
insertSysOrganizationProperty(context, date, input.getId(), "GAS", session);
// if (XStringUtils.isNotEmpty(input.getMediaType())){
// String[] split = input.getMediaType().split(",");
// StringBuilder builder = new StringBuilder();
......@@ -1119,7 +1050,7 @@ public class SysOrganizationService {
// }
// }
}catch (Exception e){
} catch (Exception e) {
throw new XServiceException(e);
}
......@@ -1141,21 +1072,21 @@ public class SysOrganizationService {
QueryWrapper<SysOrganizationEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SysOrganizationEnt::getId, input.getId());
SysOrganizationEnt entity = mapper.selectOne(queryWrapper);
if(entity == null) {
if (entity == null) {
return XServiceResult.error(context, XError.NotFound);
}
QueryWrapper<SysUserOrganizationRelEnt> wrapper = new QueryWrapper<>();
wrapper.lambda().eq(SysUserOrganizationRelEnt::getOuId,entity.getId())
.le(true,SysUserOrganizationRelEnt::getEffectTime,new Date())
.ge(true,SysUserOrganizationRelEnt::getEndTime,new Date());
wrapper.lambda().eq(SysUserOrganizationRelEnt::getOuId, entity.getId())
.le(true, SysUserOrganizationRelEnt::getEffectTime, new Date())
.ge(true, SysUserOrganizationRelEnt::getEndTime, new Date());
List<SysUserOrganizationRelEnt> relEnts = userOuRelMapper.selectList(wrapper);
if (!CollectionUtils.isEmpty(relEnts)){
if (!CollectionUtils.isEmpty(relEnts)) {
return XServiceResult.error(200, "当前组织机构下已绑定人员禁止删除!");
}
entity.setModifyTime(new Date());
PpsUserSession session = context.getSession(PpsUserSession.class);
if (session != null){
if (session != null) {
entity.setModifyById(session.getId());
entity.setModifyByName(session.getUserName());
}
......@@ -1166,18 +1097,18 @@ public class SysOrganizationService {
SysOrganizationRelMapper relmapper = context.getBean(SysOrganizationRelMapper.class);
QueryWrapper<SysOrganizationRelEnt> relWrapper = new QueryWrapper<>();
relWrapper.lambda().eq(SysOrganizationRelEnt::getOuId, input.getId());
relWrapper.lambda().le(true,SysOrganizationRelEnt::getEffectTime,new Date());
relWrapper.lambda().ge(true,SysOrganizationRelEnt::getEndTime,new Date());
relWrapper.lambda().le(true, SysOrganizationRelEnt::getEffectTime, new Date());
relWrapper.lambda().ge(true, SysOrganizationRelEnt::getEndTime, new Date());
SysOrganizationRelEnt relEnt = relmapper.selectOne(relWrapper);
try {
relEnt.setEndTime(new Date());
relEnt.setModifyTime(new Date());
if (session != null){
if (session != null) {
relEnt.setModifyById(session.getId());
relEnt.setModifyByName(session.getUserName());
}
relmapper.updateById(relEnt);
}catch (Exception e){
} catch (Exception e) {
throw new XServiceException(e);
}
......@@ -1185,13 +1116,13 @@ public class SysOrganizationService {
SysOrganizationPropertyMapper propertyMapper = context.getBean(SysOrganizationPropertyMapper.class);
QueryWrapper<SysOrganizationPropertyEnt> propertyWrapper = new QueryWrapper<>();
propertyWrapper.lambda().eq(SysOrganizationPropertyEnt::getOuId, input.getId());
propertyWrapper.lambda().le(true,SysOrganizationPropertyEnt::getEffectTime,new Date());
propertyWrapper.lambda().ge(true,SysOrganizationPropertyEnt::getEndTime,new Date());
propertyWrapper.lambda().le(true, SysOrganizationPropertyEnt::getEffectTime, new Date());
propertyWrapper.lambda().ge(true, SysOrganizationPropertyEnt::getEndTime, new Date());
List<SysOrganizationPropertyEnt> propertyEnts = propertyMapper.selectList(propertyWrapper);
propertyEnts.forEach(propertyEnt -> {
propertyEnt.setEndTime(new Date());
propertyEnt.setModifyTime(new Date());
if (session != null){
if (session != null) {
propertyEnt.setModifyById(session.getId());
propertyEnt.setModifyByName(session.getUserName());
}
......@@ -1207,7 +1138,7 @@ public class SysOrganizationService {
}
//新增组织机构属性表
public void insertSysOrganizationProperty(XContext context,Date date,String uuid,String mediaTypes,PpsUserSession session){
public void insertSysOrganizationProperty(XContext context, Date date, String uuid, String mediaTypes, PpsUserSession session) {
//新增组织机构属性表
SysOrganizationPropertyMapper propertyMapper = context.getBean(SysOrganizationPropertyMapper.class);
String[] split = mediaTypes.split(",");
......@@ -1219,89 +1150,88 @@ public class SysOrganizationService {
propertyEnt.setPropertyValue(mediumType);
propertyEnt.setEffectTime(date);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String datetime="9999-12-31";
String datetime = "9999-12-31";
try {
propertyEnt.setEndTime(sdf.parse(datetime));
} catch (ParseException e) {
e.printStackTrace();
}
propertyEnt.setCreateTime(date);
if (session != null){
if (session != null) {
propertyEnt.setCreateById(session.getId());
propertyEnt.setCreateByName(session.getUserName());
}
list.add(propertyEnt);
}
if (!CollectionUtils.isEmpty(list)){
if (!CollectionUtils.isEmpty(list)) {
list.forEach(propertyMapper::insert);
}
}
//新增组织机构关系表
public void insertSysOrganizationRel(XContext context,Date date,String ouId,String parentOuId,Integer sort,PpsUserSession session){
public void insertSysOrganizationRel(XContext context, Date date, String ouId, String parentOuId, Integer sort, PpsUserSession session) {
SysOrganizationRelMapper relMapper = context.getBean(SysOrganizationRelMapper.class);
SysOrganizationRelViewMapper relViewMapper = context.getBean(SysOrganizationRelViewMapper.class);
//新增组织机构关系表
SysOrganizationRelEnt relEnt = new SysOrganizationRelEnt();
relEnt.setId(UUID.randomUUID().toString());
relEnt.setOuId(ouId);
relEnt.setParentOuId(parentOuId);
QueryWrapper<SysOrganizationRelEnt> relWrapper = new QueryWrapper<>();
relWrapper.lambda().eq(SysOrganizationRelEnt::getOuId,parentOuId)
.le(SysOrganizationRelEnt::getEffectTime,date)
.ge(true,SysOrganizationRelEnt::getEndTime,date);
relWrapper.lambda().eq(SysOrganizationRelEnt::getOuId, parentOuId)
.le(SysOrganizationRelEnt::getEffectTime, date)
.ge(true, SysOrganizationRelEnt::getEndTime, date);
SysOrganizationRelEnt relEnt1 = relMapper.selectOne(relWrapper);
if (relEnt1 == null){
if (relEnt1 == null) {
relEnt.setOuIdPath(ouId);
}else{
} else {
String ouIdPath = relEnt1.getOuIdPath();
ouIdPath=ouIdPath+"/"+ouId;
ouIdPath = ouIdPath + "/" + ouId;
relEnt.setOuIdPath(ouIdPath);
relEnt.setLevels(relEnt1.getLevels() == null ? 1 : relEnt1.getLevels() + 1);
}
//如果用户不填写序号需要取表中最大的序号然后+1作为当前数据的序号
if (sort == null){
if (sort == null) {
SysOrganizationRelView relView = relViewMapper.selectMaxSort(parentOuId);
if (relView !=null){
if (relView != null) {
Integer sort1 = relView.getSort();
relEnt.setSort(++sort1);
}else {
} else {
relEnt.setSort(1);
}
}else {
} else {
relEnt.setSort(sort);
}
relEnt.setEffectTime(date);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String datetime="9999-12-31";
String datetime = "9999-12-31";
try {
relEnt.setEndTime(sdf.parse(datetime));
} catch (ParseException e) {
e.printStackTrace();
}
relEnt.setCreateTime(date);
if (session != null){
if (session != null) {
relEnt.setCreateById(session.getId());
relEnt.setCreateByName(session.getUserName());
}
relMapper.insert(relEnt);
//判断当前组织机构是否存在下级,如果存在下级,更新下级组织机构的路径
updateSysOrganizationChildRel(context, date ,relEnt , session);
updateSysOrganizationChildRel(context, date, relEnt, session);
}
public void updateSysOrganizationChildRel(XContext context,Date date,SysOrganizationRelEnt relEnt,PpsUserSession session){
public void updateSysOrganizationChildRel(XContext context, Date date, SysOrganizationRelEnt relEnt, PpsUserSession session) {
SysOrganizationRelMapper relMapper = context.getBean(SysOrganizationRelMapper.class);
QueryWrapper<SysOrganizationRelEnt> relWrapper = new QueryWrapper<>();
relWrapper.lambda().like(SysOrganizationRelEnt::getOuIdPath,relEnt.getOuId()+ "/");
relWrapper.lambda().like(SysOrganizationRelEnt::getOuIdPath, relEnt.getOuId() + "/");
List<SysOrganizationRelEnt> childList = relMapper.selectList(relWrapper);
if (!CollectionUtils.isEmpty(childList)){
childList.stream().forEach(item->{
if (!CollectionUtils.isEmpty(childList)) {
childList.stream().forEach(item -> {
int index = item.getOuIdPath().indexOf(relEnt.getOuId());
item.setOuIdPath(relEnt.getOuIdPath() + item.getOuIdPath().substring(index + relEnt.getOuId().length()));
item.setModifyById(session.getId());
......@@ -1315,37 +1245,37 @@ public class SysOrganizationService {
@XText("获取用户组织机构及授权的组织机构")
@XApiPost
public XListResult<GetOuListTreeOutput> getOuListWithSelfAndAuth(XContext context, GetOuListWithSelfAndAuthInput input){
public XListResult<GetOuListTreeOutput> getOuListWithSelfAndAuth(XContext context, GetOuListWithSelfAndAuthInput input) {
PpsUserSession session = context.getSession(PpsUserSession.class);
String ouId = session.getOuId();
if(StringUtils.isBlank(ouId)) return XListResult.success();
if (StringUtils.isBlank(ouId)) return XListResult.success();
//根据组织机构id获取所有的子级组织机构
List<GetOuListTreeOutput> ouList = this.getAllOuListByOuId(context, ouId);
if(CollectionUtils.isEmpty(ouList)) return XListResult.success();
if (CollectionUtils.isEmpty(ouList)) return XListResult.success();
if(StringUtils.isBlank(input.getMenuId())){
if (StringUtils.isBlank(input.getMenuId())) {
return XListResult.success(this.createOuTree(ouList));
}
//获取用户授权的组织机构
Map<String, List<SysOrganization>> pageOrgMap = session.getPageOrgMap();
if(pageOrgMap != null){
if (pageOrgMap != null) {
//获取当前用户在指定菜单下被授权的组织机构
List<SysOrganization> authList = pageOrgMap.get(input.getMenuId());
if(!CollectionUtils.isEmpty(authList)){
if (!CollectionUtils.isEmpty(authList)) {
List<String> authOutIds = new ArrayList<>();
for(SysOrganization auth:authList){
for (SysOrganization auth : authList) {
boolean isAdd = true;
for(GetOuListTreeOutput ou: ouList){
if(ou.getOuId().equals(auth.getOuId())){
for (GetOuListTreeOutput ou : ouList) {
if (ou.getOuId().equals(auth.getOuId())) {
isAdd = false;
break;
}
}
if(isAdd){
if (isAdd) {
authOutIds.add(auth.getOuId());
}
}
if(authOutIds.size()>0){
if (authOutIds.size() > 0) {
List<GetOuListTreeOutput> resultAuthList = this.getOuListByOuIds(context, authOutIds);
ouList.addAll(resultAuthList);
}
......@@ -1357,15 +1287,15 @@ public class SysOrganizationService {
/**
* 根据组织机构id获取所有的子级组织机构
*/
private List<GetOuListTreeOutput> getAllOuListByOuId(XContext context,String ouId){
private List<GetOuListTreeOutput> getAllOuListByOuId(XContext context, String ouId) {
List<GetOuListTreeOutput> outputs = new ArrayList<>();
SysOrganizationViewMapper mapper = context.getBean(SysOrganizationViewMapper.class);
SysOrganizationView view = new SysOrganizationView();
view.setIsDeleted(1);
view.setId(ouId);
List<SysOrganizationView> list = mapper.selectAllListByOuId(view);
if(list.size()>0){
for(SysOrganizationView item : list){
if (list.size() > 0) {
for (SysOrganizationView item : list) {
GetOuListTreeOutput out = new GetOuListTreeOutput();
out.setId(item.getId());
out.setOuId(item.getId());
......@@ -1381,13 +1311,13 @@ public class SysOrganizationService {
/**
* 根据组织机构id的集合,获取组织机构信息
*/
private List<GetOuListTreeOutput> getOuListByOuIds(XContext context,List<String> ouIds){
private List<GetOuListTreeOutput> getOuListByOuIds(XContext context, List<String> ouIds) {
List<GetOuListTreeOutput> outputs = new ArrayList<>();
if(CollectionUtils.isEmpty(ouIds)) return outputs;
if (CollectionUtils.isEmpty(ouIds)) return outputs;
SysOrganizationViewMapper mapper = context.getBean(SysOrganizationViewMapper.class);
List<SysOrganizationView> list = mapper.selectListByOuIds(ouIds);
if(list.size()>0){
for(SysOrganizationView item : list){
if (list.size() > 0) {
for (SysOrganizationView item : list) {
GetOuListTreeOutput out = new GetOuListTreeOutput();
out.setId(item.getId());
out.setOuId(item.getId());
......@@ -1400,10 +1330,10 @@ public class SysOrganizationService {
return outputs;
}
public List<GetOuListTreeOutput> createOuTree(List<GetOuListTreeOutput> list){
List<GetOuListTreeOutput> treeList =new ArrayList<>();
if(list.size()>0){
for(GetOuListTreeOutput tree:list){
public List<GetOuListTreeOutput> createOuTree(List<GetOuListTreeOutput> list) {
List<GetOuListTreeOutput> treeList = new ArrayList<>();
if (list.size() > 0) {
for (GetOuListTreeOutput tree : list) {
boolean isHaveParent = false;
for (GetOuListTreeOutput item : list) {
//子集
......@@ -1418,7 +1348,7 @@ public class SysOrganizationService {
isHaveParent = true;
}
}
if(!isHaveParent){
if (!isHaveParent) {
treeList.add(tree);
}
}
......
......@@ -2,43 +2,44 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="pps.core.system.mapper.SysOrganizationViewMapper">
<resultMap id="BaseResultMap" type="pps.core.system.entity.SysOrganizationView">
<id column="id" property="id" jdbcType="VARCHAR" />
<result column="ou_code" property="ouCode" jdbcType="VARCHAR" />
<result column="ou_name" property="ouName" jdbcType="VARCHAR" />
<result column="short_name" property="shortName" jdbcType="VARCHAR" />
<result column="ou_level" property="ouLevel" jdbcType="VARCHAR" />
<result column="description" property="description" jdbcType="VARCHAR" />
<result column="create_by_id" property="createById" jdbcType="VARCHAR" />
<result column="create_by_name" property="createByName" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="modify_by_id" property="modifyById" jdbcType="VARCHAR" />
<result column="modify_by_name" property="modifyByName" jdbcType="VARCHAR" />
<result column="modify_time" property="modifyTime" jdbcType="TIMESTAMP" />
<result column="end_time" property="endTime" jdbcType="TIMESTAMP" />
<result column="post_code" property="postCode" jdbcType="VARCHAR" />
<result column="post_address" property="postAddress" jdbcType="VARCHAR" />
<result column="fax_no" property="faxNo" jdbcType="VARCHAR" />
<result column="phone" property="phone" jdbcType="VARCHAR" />
<result column="country" property="country" jdbcType="VARCHAR" />
<result column="province" property="province" jdbcType="INTEGER" />
<result column="partent_name" property="partentName" jdbcType="VARCHAR" />
<result column="sor_id" property="sorId" jdbcType="VARCHAR" />
<result column="level_dic_name" property="levelDicName" jdbcType="VARCHAR" />
<result column="country_name" property="countryName" jdbcType="VARCHAR" />
<result column="province_name" property="provinceName" jdbcType="VARCHAR" />
<result column="property_name" property="propertyName" jdbcType="VARCHAR" />
<result column="parent_ou_id" property="parentOuId" jdbcType="VARCHAR" />
<result column="media_type" property="mediaType" jdbcType="VARCHAR" />
<result column="is_has_children" property="isHasChildren" jdbcType="INTEGER" />
<result column="is_deleted" property="isDeleted" jdbcType="INTEGER" />
<result column="type" property="type" jdbcType="VARCHAR" />
<result column="longitude" property="longitude" jdbcType="DECIMAL" />
<result column="latitude" property="latitude" jdbcType="DECIMAL" />
<result column="elevation" property="elevation" jdbcType="DECIMAL" />
<id column="id" property="id" jdbcType="VARCHAR"/>
<result column="ou_code" property="ouCode" jdbcType="VARCHAR"/>
<result column="ou_name" property="ouName" jdbcType="VARCHAR"/>
<result column="short_name" property="shortName" jdbcType="VARCHAR"/>
<result column="ou_level" property="ouLevel" jdbcType="VARCHAR"/>
<result column="description" property="description" jdbcType="VARCHAR"/>
<result column="create_by_id" property="createById" jdbcType="VARCHAR"/>
<result column="create_by_name" property="createByName" jdbcType="VARCHAR"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
<result column="modify_by_id" property="modifyById" jdbcType="VARCHAR"/>
<result column="modify_by_name" property="modifyByName" jdbcType="VARCHAR"/>
<result column="modify_time" property="modifyTime" jdbcType="TIMESTAMP"/>
<result column="end_time" property="endTime" jdbcType="TIMESTAMP"/>
<result column="post_code" property="postCode" jdbcType="VARCHAR"/>
<result column="post_address" property="postAddress" jdbcType="VARCHAR"/>
<result column="fax_no" property="faxNo" jdbcType="VARCHAR"/>
<result column="phone" property="phone" jdbcType="VARCHAR"/>
<result column="country" property="country" jdbcType="VARCHAR"/>
<result column="province" property="province" jdbcType="INTEGER"/>
<result column="partent_name" property="partentName" jdbcType="VARCHAR"/>
<result column="sor_id" property="sorId" jdbcType="VARCHAR"/>
<result column="level_dic_name" property="levelDicName" jdbcType="VARCHAR"/>
<result column="country_name" property="countryName" jdbcType="VARCHAR"/>
<result column="province_name" property="provinceName" jdbcType="VARCHAR"/>
<result column="property_name" property="propertyName" jdbcType="VARCHAR"/>
<result column="parent_ou_id" property="parentOuId" jdbcType="VARCHAR"/>
<result column="media_type" property="mediaType" jdbcType="VARCHAR"/>
<result column="is_has_children" property="isHasChildren" jdbcType="INTEGER"/>
<result column="is_deleted" property="isDeleted" jdbcType="INTEGER"/>
<result column="type" property="type" jdbcType="VARCHAR"/>
<result column="longitude" property="longitude" jdbcType="DECIMAL"/>
<result column="latitude" property="latitude" jdbcType="DECIMAL"/>
<result column="elevation" property="elevation" jdbcType="DECIMAL"/>
</resultMap>
<sql id="Base_Column_List">
id,
id
,
ou_code,
ou_name,
short_name,
......@@ -61,28 +62,27 @@
<select id="selectOne" parameterType="pps.core.system.entity.SysOrganizationView" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from sys_organization
where
id=#{id}
</select>
<select id="selectList" parameterType="pps.core.system.entity.SysOrganizationView" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from sys_organization
where
id=#{id}
</select>
<select id="selectEffective" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from sys_organization
where is_deleted =1
</select>
<select id="selectSysOrganizationList" parameterType="pps.core.system.entity.SysOrganizationView"
resultMap="BaseResultMap">
select
SELECT
ou.id,
ou.ou_code,
ou.ou_name,
......@@ -95,50 +95,37 @@
ou.phone,
ou.country,
ou.province,
sor.id as sor_id,
sor.id AS sor_id,
sor.sort,
sor.parent_ou_id,
sor.is_has_children,
ssop.property_value as media_type,
so.ou_name as partent_name,
sd2.name as province_name,
so.longitude,
so.latitude,
so.elevation
from sys_organization_rel sor
left join sys_organization ou on ou.id = sor.ou_id
left join sys_organization so on sor.parent_ou_id = so.id
left join sys_area sd2 on sd2.id = ou.province
left join (
select ou_id,GROUP_CONCAT(property_value) as property_value from sys_organization_property sop where sop.end_time &gt;= #{endTime}
group by ou_id
) ssop
on ssop.ou_id = ou.id
ou.longitude,
ou.latitude,
ou.elevation,
( SELECT so.ou_name FROM sys_organization so WHERE sor.parent_ou_id = so.id ) AS partent_name
FROM
sys_organization_rel sor
LEFT JOIN sys_organization ou ON ou.id = sor.ou_id
<where>
ou.is_deleted = #{isDeleted}
and sor.end_time &gt;= #{endTime}
<if test="id != null and id != ''">
and sor.parent_ou_id = #{id}
</if>
<if test="ouCode != null and ouCode != ''">
AND ou.ou_code like concat('%',#{ouCode},'%')
</if>
<if test="ouName != null and ouName != ''">
AND ou.ou_name like concat('%',#{ouName},'%')
</if>
<if test="shortName != null and shortName != ''">
AND ou.short_name like concat('%',#{shortName},'%')
</if>
</where>
order by sor.sort asc
</select>
<select id="selectOrganizationEffective" parameterType="pps.core.system.entity.SysOrganizationView" resultMap="BaseResultMap">
select
so.id,
<select id="selectOrganizationEffective" parameterType="pps.core.system.entity.SysOrganizationView"
resultMap="BaseResultMap">
select so.id,
ou_code,
ou_name,
short_name,
......@@ -147,12 +134,13 @@
from sys_organization so
left join sys_organization_rel sor on sor.ou_id = so.id
where so.is_deleted = #{isDeleted}
and sor.effect_time &lt;= #{endTime} and sor.end_time &gt;= #{endTime}
and sor.effect_time &lt;= #{endTime}
and sor.end_time &gt;= #{endTime}
</select>
<select id="selectOrganizationEffectiveByOuName" parameterType="pps.core.system.entity.SysOrganizationView" resultMap="BaseResultMap">
select
so.id,
<select id="selectOrganizationEffectiveByOuName" parameterType="pps.core.system.entity.SysOrganizationView"
resultMap="BaseResultMap">
select so.id,
ou_code,
ou_name,
short_name,
......@@ -162,10 +150,12 @@
left join sys_organization_rel sor on sor.ou_id = so.id
where so.is_deleted = #{isDeleted}
and so.ou_name = #{ouName}
and sor.effect_time &lt;= #{endTime} and sor.end_time &gt;= #{endTime}
and sor.effect_time &lt;= #{endTime}
and sor.end_time &gt;= #{endTime}
</select>
<select id="selectOuSonByParentOuId" parameterType="pps.core.system.entity.SysOrganizationView" resultMap="BaseResultMap">
<select id="selectOuSonByParentOuId" parameterType="pps.core.system.entity.SysOrganizationView"
resultMap="BaseResultMap">
select
so.id,
ou_code,
......@@ -184,7 +174,8 @@
</if>
order by sor.sort
</select>
<select id="selectOrganizationByParentOuIdOrOuId" parameterType="pps.core.system.entity.SysOrganizationView" resultMap="BaseResultMap">
<select id="selectOrganizationByParentOuIdOrOuId" parameterType="pps.core.system.entity.SysOrganizationView"
resultMap="BaseResultMap">
select
so.id,
ou_code,
......@@ -202,7 +193,8 @@
</where>
</select>
<select id="selectOrganizationByParentOuId" parameterType="pps.core.system.entity.SysOrganizationView" resultMap="BaseResultMap">
<select id="selectOrganizationByParentOuId" parameterType="pps.core.system.entity.SysOrganizationView"
resultMap="BaseResultMap">
select
so.id,
ou_code,
......@@ -219,14 +211,17 @@
</where>
</select>
<select id="selectAllListByOuId" parameterType="pps.core.system.entity.SysOrganizationView" resultMap="BaseResultMap" >
select r.ou_id as id,r.parent_ou_id,s.ou_name,s.short_name from sys_organization_rel r
<select id="selectAllListByOuId" parameterType="pps.core.system.entity.SysOrganizationView"
resultMap="BaseResultMap">
select r.ou_id as id, r.parent_ou_id, s.ou_name, s.short_name
from sys_organization_rel r
left join sys_organization s on r.ou_id = s.id
where s.is_deleted = #{isDeleted} and (r.ou_id = #{id} or r.ou_id_path like '%${id}%')
where s.is_deleted = #{isDeleted}
and (r.ou_id = #{id} or r.ou_id_path like '%${id}%')
order by s.create_time
</select>
<select id="selectListByOuIds" parameterType="java.util.List" resultMap="BaseResultMap" >
<select id="selectListByOuIds" parameterType="java.util.List" resultMap="BaseResultMap">
select r.ou_id as id,r.parent_ou_id,s.ou_name,s.short_name from sys_organization_rel r
left join sys_organization s on r.ou_id = s.id
where s.is_deleted = 1 and r.ou_id in
......@@ -236,14 +231,14 @@
order by s.create_time
</select>
<select id="selectCountByParentOuIds" parameterType="pps.core.system.entity.SysOrganizationView" resultMap="BaseResultMap">
<select id="selectCountByParentOuIds" parameterType="pps.core.system.entity.SysOrganizationView"
resultMap="BaseResultMap">
select
count(so.id) as id,
sor.parent_ou_id
from sys_organization so
left join sys_organization_rel sor on sor.ou_id = so.id
where so.is_deleted = 1
and sor.effect_time &lt;= #{endTime} and sor.end_time &gt;= #{endTime}
and sor.parent_ou_id in
<foreach collection="list" open="(" close=")" separator="," item="item">
#{item}
......@@ -251,7 +246,8 @@
group by sor.parent_ou_id
</select>
<select id="getSysOrganizationByOuLevelAndOuId" parameterType="pps.core.system.entity.SysOrganizationView" resultType="pps.core.system.entity.SysOrganizationView">
<select id="getSysOrganizationByOuLevelAndOuId" parameterType="pps.core.system.entity.SysOrganizationView"
resultType="pps.core.system.entity.SysOrganizationView">
with RECURSIVE temps as
(
......@@ -282,12 +278,14 @@
limit 1
</select>
<select id="getSysOrganizationByOuLevelAndUserId" parameterType="pps.core.system.entity.SysOrganizationView" resultType="pps.core.system.entity.SysOrganizationView">
<select id="getSysOrganizationByOuLevelAndUserId" parameterType="pps.core.system.entity.SysOrganizationView"
resultType="pps.core.system.entity.SysOrganizationView">
with RECURSIVE temps as
(
select so.ou_level ,so.id,so.ou_name ,tt.ou_id ,tt.parent_ou_id ,tt.ou_id_path ,tt.sort from(
select sor.ou_id ,sor.parent_ou_id ,sor.ou_id_path ,sor.sort from sys_organization_rel sor where sor.effect_time &lt;= #{endTime} and sor.end_time &gt;= #{endTime} and ou_id =
select sor.ou_id ,sor.parent_ou_id ,sor.ou_id_path ,sor.sort from sys_organization_rel sor where sor.effect_time
&lt;= #{endTime} and sor.end_time &gt;= #{endTime} and ou_id =
(select ou_id from sys_user_organization_rel suor
where suor.user_id = #{userId}
and suor.effect_time &lt;= #{endTime} and suor.end_time &gt;= #{endTime})
......@@ -318,7 +316,8 @@
</select>
<select id="getSysOrganizationListByOuLevelAndUserId" parameterType="pps.core.system.entity.SysOrganizationView" resultType="pps.core.system.entity.SysOrganizationView">
<select id="getSysOrganizationListByOuLevelAndUserId" parameterType="pps.core.system.entity.SysOrganizationView"
resultType="pps.core.system.entity.SysOrganizationView">
with RECURSIVE temps as
(
......@@ -380,66 +379,86 @@
</select>
<select id="selectOuAllByUserId" parameterType="pps.core.system.entity.SysOrganizationView" resultMap="BaseResultMap">
<select id="selectOuAllByUserId" parameterType="pps.core.system.entity.SysOrganizationView"
resultMap="BaseResultMap">
with RECURSIVE temps as
(
select so.ou_level ,so.id,so.ou_name ,tt.ou_id ,tt.parent_ou_id ,tt.ou_id_path ,tt.sort from(
select sor.ou_id ,sor.parent_ou_id ,sor.ou_id_path ,sor.sort from sys_organization_rel sor where sor.effect_time &lt;= #{endTime} and sor.end_time &gt;= #{endTime} and ou_id =
(select ou_id from sys_user_organization_rel suor
(select so.ou_level, so.id, so.ou_name, tt.ou_id, tt.parent_ou_id, tt.ou_id_path, tt.sort
from (select sor.ou_id, sor.parent_ou_id, sor.ou_id_path, sor.sort
from sys_organization_rel sor
where sor.effect_time &lt;= #{endTime}
and sor.end_time &gt;= #{endTime}
and ou_id =
(select ou_id
from sys_user_organization_rel suor
where suor.user_id = #{userId}
and suor.effect_time &lt;= #{endTime} and suor.end_time &gt;= #{endTime})
)tt
left join sys_organization so on tt.ou_id=so.id and so.is_deleted =1
and suor.effect_time &lt;= #{endTime}
and suor.end_time &gt;= #{endTime})) tt
left join sys_organization so on tt.ou_id = so.id and so.is_deleted = 1
union
select a.ou_level,a.id,a.ou_name ,a.ou_id ,a.parent_ou_id ,a.ou_id_path ,a.sort
from temps inner join (
select so.ou_level ,so.id,so.ou_name ,tt.ou_id ,tt.parent_ou_id ,tt.ou_id_path ,tt.sort from(
select sor.ou_id ,sor.parent_ou_id ,sor.ou_id_path ,sor.sort from sys_organization_rel sor
where sor.effect_time &lt;= #{endTime} and sor.end_time &gt;= #{endTime}
)tt
right join sys_organization so on tt.ou_id=so.id and so.is_deleted =1
) a on temps.ou_id = a.parent_ou_id
)
select temps.* from temps
select a.ou_level, a.id, a.ou_name, a.ou_id, a.parent_ou_id, a.ou_id_path, a.sort
from temps
inner join (select so.ou_level,
so.id,
so.ou_name,
tt.ou_id,
tt.parent_ou_id,
tt.ou_id_path,
tt.sort
from (select sor.ou_id, sor.parent_ou_id, sor.ou_id_path, sor.sort
from sys_organization_rel sor
where sor.effect_time &lt;= #{endTime}
and sor.end_time &gt;= #{endTime}) tt
right join sys_organization so on tt.ou_id = so.id and so.is_deleted = 1) a
on temps.ou_id = a.parent_ou_id)
select temps.*
from temps
</select>
<select id="selectOuSonByOuId" parameterType="pps.core.system.entity.SysOrganizationView" resultMap="BaseResultMap">
with RECURSIVE temps as
(
select ou_id,parent_ou_id
(select ou_id, parent_ou_id
from sys_organization_rel
where ou_id =#{id}
where ou_id = #{id}
union all
select a.ou_id,a.parent_ou_id
from temps inner join sys_organization_rel a on temps.ou_id = a.parent_ou_id
)
select temps.* from temps
select a.ou_id, a.parent_ou_id
from temps
inner join sys_organization_rel a on temps.ou_id = a.parent_ou_id)
select temps.*
from temps
</select>
<select id="selectOuTreeByOuName" parameterType="pps.core.system.entity.SysOrganizationView" resultMap="BaseResultMap">
<select id="selectOuTreeByOuName" parameterType="pps.core.system.entity.SysOrganizationView"
resultMap="BaseResultMap">
with RECURSIVE temps as
(
select so.ou_level ,so.id,so.ou_name ,sor.ou_id ,sor.parent_ou_id ,sor.ou_id_path ,sor.sort from
sys_organization so
left join sys_organization_rel sor on sor.ou_id=so.id and so.is_deleted =1
where so.ou_name like concat('%',#{ouName},'%') and sor.effect_time &lt;= #{endTime} and sor.end_time &gt;= #{endTime} and so.is_deleted =1
(select so.ou_level, so.id, so.ou_name, sor.ou_id, sor.parent_ou_id, sor.ou_id_path, sor.sort
from sys_organization so
left join sys_organization_rel sor on sor.ou_id = so.id and so.is_deleted = 1
where so.ou_name like concat('%', #{ouName}, '%')
and sor.effect_time &lt;= #{endTime}
and sor.end_time &gt;= #{endTime}
and so.is_deleted = 1
union
select a.ou_level,a.id,a.ou_name ,a.ou_id ,a.parent_ou_id ,a.ou_id_path ,a.sort
from temps inner join (
select so.ou_level ,so.id,so.ou_name ,tt.ou_id ,tt.parent_ou_id ,tt.ou_id_path ,tt.sort from(
select sor.ou_id ,sor.parent_ou_id ,sor.ou_id_path ,sor.sort from sys_organization_rel sor
where sor.effect_time &lt;= #{endTime} and sor.end_time &gt;= #{endTime}
)tt
left join sys_organization so on tt.ou_id=so.id and so.is_deleted =1
) a on temps.parent_ou_id = a.id
)
select temps.* from temps
select a.ou_level, a.id, a.ou_name, a.ou_id, a.parent_ou_id, a.ou_id_path, a.sort
from temps
inner join (select so.ou_level,
so.id,
so.ou_name,
tt.ou_id,
tt.parent_ou_id,
tt.ou_id_path,
tt.sort
from (select sor.ou_id, sor.parent_ou_id, sor.ou_id_path, sor.sort
from sys_organization_rel sor
where sor.effect_time &lt;= #{endTime}
and sor.end_time &gt;= #{endTime}) tt
left join sys_organization so on tt.ou_id = so.id and so.is_deleted = 1) a
on temps.parent_ou_id = a.id)
select temps.*
from temps
</select>
......@@ -453,7 +472,7 @@
from sys_organization so
left join sys_organization_rel sor on sor.parent_ou_id = so.id
<where>
sor.end_time >= now() and sor.ou_id in
sor.ou_id in
<foreach collection="list" open="(" close=")" separator="," item="item">
#{item}
</foreach>
......@@ -461,14 +480,15 @@
</select>
<select id="selectOuByOuId" parameterType="pps.core.system.entity.SysOrganizationView" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />,
<include refid="Base_Column_List"/>,
ou_level,
'ou' as type
from sys_organization
where
id=#{id} and is_deleted =1
</select>
<select id="selectOuByOuIdsAndOuName" parameterType="pps.core.system.entity.SysOrganizationView" resultMap="BaseResultMap">
<select id="selectOuByOuIdsAndOuName" parameterType="pps.core.system.entity.SysOrganizationView"
resultMap="BaseResultMap">
with RECURSIVE temps as
(
select so.ou_level ,so.id,so.ou_name ,sor.ou_id ,sor.parent_ou_id ,sor.ou_id_path ,sor.sort,'ou' as type from
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment