Commit f1cbf96a authored by ZWT's avatar ZWT

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

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

BREAKING CHANGE: 无

Closes 无

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