|
@@ -16,7 +16,9 @@ import com.jeeplus.sys.constant.CommonConstants;
|
|
|
import com.jeeplus.sys.constant.enums.OfficeTypeEnum;
|
|
|
import com.jeeplus.sys.domain.Office;
|
|
|
import com.jeeplus.sys.mapper.OfficeMapper;
|
|
|
+import com.jeeplus.sys.mapper.UserMapper;
|
|
|
import com.jeeplus.sys.service.dto.OfficeDTO;
|
|
|
+import com.jeeplus.sys.service.dto.UserDTO;
|
|
|
import com.jeeplus.sys.service.mapstruct.OfficeWrapper;
|
|
|
import com.jeeplus.sys.utils.UserUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
@@ -45,6 +47,9 @@ public class OfficeService extends TreeService<OfficeMapper, Office> {
|
|
|
@Autowired
|
|
|
private OfficeMapper officeMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
public List <OfficeDTO> getRootTree(List<OfficeDTO> list, String extId, String type, String showAll, String showMyOffice) {
|
|
|
List<OfficeDTO> offices = Lists.newArrayList ();
|
|
|
// 获取到所有parent_id为‘0’的部门数据
|
|
@@ -57,9 +62,11 @@ public class OfficeService extends TreeService<OfficeMapper, Office> {
|
|
|
}
|
|
|
}
|
|
|
if (com.jeeplus.sys.utils.StringUtils.isNotBlank(showMyOffice)) {
|
|
|
+
|
|
|
+
|
|
|
OfficeDTO officeDTO = UserUtils.getCurrentUserDTO().getOfficeDTO();
|
|
|
// 排除管理员
|
|
|
- if (!UserUtils.getCurrentUserDTO().isAdmin()){
|
|
|
+ if (!UserUtils.getCurrentUserDTO().getOfficeDTO().isAdmin()){
|
|
|
if (StringUtils.isNotBlank(officeDTO.getParentIds())) {
|
|
|
String[] split = officeDTO.getParentIds().split(",");
|
|
|
if (split.length > 2) {
|
|
@@ -84,6 +91,92 @@ public class OfficeService extends TreeService<OfficeMapper, Office> {
|
|
|
return offices;
|
|
|
}
|
|
|
|
|
|
+ public List <OfficeDTO> getRootTreeForChild(List<OfficeDTO> list, String extId, String type, String showAll, String showMyOffice,String mobile) {
|
|
|
+ List<OfficeDTO> offices = Lists.newArrayList ();
|
|
|
+ // 获取到所有parent_id为‘0’的部门数据
|
|
|
+ List<OfficeDTO> rootTrees = officeWrapper.toDTO (super.getChildren (new Office (OfficeDTO.getRootId ())));
|
|
|
+ for (OfficeDTO root : rootTrees) {
|
|
|
+ if (this.isUseAble ( extId, type,root, showAll )){
|
|
|
+ // 不是被排除节点的子节点
|
|
|
+ List<OfficeDTO> officeList = formatListToTree (root, list, extId, type, showAll);
|
|
|
+ offices.addAll (officeList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (com.jeeplus.sys.utils.StringUtils.isNotBlank(showMyOffice)) {
|
|
|
+ UserDTO dto = userService.getUserByLoginNameForChild(mobile);
|
|
|
+
|
|
|
+ OfficeDTO officeDTO = dto.getOfficeDTO();
|
|
|
+ // 排除管理员
|
|
|
+ if (!dto.getOfficeDTO().isAdmin()){
|
|
|
+ if (StringUtils.isNotBlank(officeDTO.getParentIds())) {
|
|
|
+ String[] split = officeDTO.getParentIds().split(",");
|
|
|
+ if (split.length > 2) {
|
|
|
+ Office office = officeMapper.selectById(split[2]);
|
|
|
+ if ("0".equals(office.getIsPublic())) {
|
|
|
+ // isPublic为“0”,当前用户的公司为私有,查询的部门包含自己所属公司全部部门和其他的公有部门
|
|
|
+ if(null != officeDTO && StringUtils.isNotBlank(officeDTO.getParentIds())){
|
|
|
+ offices = this.getCompanyFromTreeForChild(offices,dto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if ("0".equals(officeDTO.getIsPublic())) {
|
|
|
+ // isPublic为“0”,当前用户的公司为私有,查询的部门包含自己所属公司全部部门和其他的公有部门
|
|
|
+ if(null != officeDTO && StringUtils.isNotBlank(officeDTO.getParentIds())){
|
|
|
+ offices = this.getCompanyFromTreeForChild(offices,dto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return offices;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 在tree数据中找到当前登录人的“集团”以及“公司”
|
|
|
+ */
|
|
|
+ public List<OfficeDTO> getCompanyFromTreeForChild(List<OfficeDTO> rootTrees,UserDTO dto){
|
|
|
+ // 当前登录人的集团id
|
|
|
+ String corporationId = dto.getCompanyDTO().getId();
|
|
|
+ // 公司id
|
|
|
+ String parentIds = officeMapper.selectById(dto.getOfficeDTO().getId()).getParentIds();
|
|
|
+ String companyId = null;
|
|
|
+ String[] split = parentIds.split(",");
|
|
|
+ if(split.length>2){
|
|
|
+ companyId = split[2];
|
|
|
+ }else{
|
|
|
+ companyId = dto.getOfficeDTO().getId();
|
|
|
+ }
|
|
|
+ List<OfficeDTO> os = new ArrayList<>();
|
|
|
+ if (CollectionUtil.isNotEmpty(rootTrees)) {
|
|
|
+ String finalCompanyId = companyId;
|
|
|
+ rootTrees.stream().forEach(item->{
|
|
|
+ if ("1".equals(item.getIsPublic())) { // 找到公有的集团
|
|
|
+ OfficeDTO officeDTO = item;
|
|
|
+ if (CollectionUtil.isNotEmpty(item.getChildren())){
|
|
|
+ officeDTO.setChildren(item.getChildren());
|
|
|
+ }
|
|
|
+ os.add(officeDTO);
|
|
|
+ }else{
|
|
|
+ if(item.getId().equals(corporationId)){ // 找到登录人的集团
|
|
|
+ OfficeDTO officeDTO = item;
|
|
|
+ if (CollectionUtil.isNotEmpty(item.getChildren())&&!"".equals(finalCompanyId)){
|
|
|
+ List<OfficeDTO> companys = new ArrayList<>();
|
|
|
+ item.getChildren().stream().forEach(child->{
|
|
|
+ if(child.getId().equals(finalCompanyId) || "1".equals(child.getIsPublic())){ // 登录人的公司 或者 公有公司
|
|
|
+ companys.add(child);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ officeDTO.setChildren(companys);
|
|
|
+ }
|
|
|
+ os.add(officeDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return os;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 在tree数据中找到当前登录人的“集团”以及“公司”
|
|
|
*/
|