package com.changhong.epc.form.service.budget.department.impl; import com.changhong.epc.bean.tenant.system.DepartmentRelation; import com.changhong.epc.constter.base.BaseConst; import com.changhong.epc.constter.system.SystemClients; import com.changhong.epc.constter.system.run.EpcRestInterface; import com.changhong.epc.constter.tenant.TenantUrlConst; import com.changhong.epc.form.mapper.tenant.DepartmentRelationMapper; import com.changhong.epc.form.service.budget.department.DepartmentRelationService; import com.changhong.epc.rely.api.bean.Organization; import com.changhong.epc.rely.api.bean.Organizations; import com.iemsoft.framework.cloud.core.base.ResMsg; import com.iemsoft.framework.cloud.core.tools.JSONTool; import com.iemsoft.framework.cloud.core.tools.SpringUtil; import com.iemsoft.framework.cloud.ribbon.RestInterface; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 部门关系业务实现 * @author liush * */ @Service("departmentRelationService") public class DepartmentRelationServiceImpl implements DepartmentRelationService,SystemClients ,BaseConst,TenantUrlConst{ @Resource private DepartmentRelationMapper departmentRelationMapper; @Override public boolean judgeSuperior(DepartmentRelation departmentRelation) { boolean flag = false; List list = departmentRelationMapper.select(departmentRelation); if(!list.isEmpty()) { for(DepartmentRelation d:list) { if(d.getParentCode().equals(departmentRelation.getParentCode())) { flag = true; } } } return flag; } @Override public boolean judgeSuperior(String code, String parentCode) { DepartmentRelation departmentRelation = new DepartmentRelation(); departmentRelation.setCode(code); boolean flag = false; List list = departmentRelationMapper.select(departmentRelation); if(!list.isEmpty()) { for(DepartmentRelation d:list) { if(d.getParentCode().equals(parentCode)) { flag = true; } } } return flag; } @Override public List getSuperiorDepartment(String code) { DepartmentRelation departmentRelation = new DepartmentRelation(); departmentRelation.setCode(code); List strList = new ArrayList(); departmentRelationMapper.select(departmentRelation).forEach( s -> { strList.add(s.getParentCode()); }); return strList; } @Override public String getSuperiorDepartmentCode(String code) { DepartmentRelation departmentRelation = new DepartmentRelation(); departmentRelation.setCode(code); // System.err.println(departmentRelationMapper.selectOne(departmentRelation)); if(departmentRelationMapper.selectOne(departmentRelation) != null) { return departmentRelationMapper.selectOne(departmentRelation).getParentCode(); } else { return ""; } } @Override public List getSubordinateDepartment(String parentCode) { DepartmentRelation departmentRelation = new DepartmentRelation(); departmentRelation.setCode(parentCode); List strList = new ArrayList(); departmentRelationMapper.select(departmentRelation).forEach( s -> { strList.add(s.getCode()); }); return strList; } @Override public DepartmentRelation selectHigCode(DepartmentRelation dep) { return departmentRelationMapper.selectOne(dep); } public Object getReult(Map map,String url){ RestInterface restInterface = SpringUtil.getBean(SERVER_TENANT.getBeanName(), RestInterface.class); Object data = restInterface.post(url,map,ResMsg.class, EpcRestInterface.getEpcHeads()).getData(); return data; } /** * 查询所有一级部门 */ public List getOne(String companyId){ Map map = new HashMap<>(); map.put("companyId", companyId); Object o = this.getReult(map, TenantUrlConst.RESR_ORG_GETONE); return JSONTool.toList(JSONTool.toJson(o), Organization.class); } /** * 查询当前部门所有下级 */ public List getHigCode(String code){ Map map = new HashMap<>(); map.put("code", code); Object o = this.getReult(map, TenantUrlConst.REST_TENANT_SYSTEM_BUDGETCONFIG_GETPARENTORGS); Organizations org = JSONTool.toObj(JSONTool.toJson(o),Organizations.class); List orgs = new ArrayList<>(); for(Organization or : org.getOrgs()){ this.getCodeName(orgs, or.getChildren()); } return orgs; } public Object getCodeName(List orgs,List codes){ if(codes==null) return null; for(Organization org :codes){ Organization or = new Organization(); or.setCode(org.getCode()); or.setName(org.getName()); orgs.add(or); if(org.getChildren()!=null){ if(!(org.getChildren().isEmpty())){ this.getCodeName(orgs, org.getChildren()); } } } return null; } }