package com.changhong.epc.form.service.budget.department.util; 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.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.ObjectUtil; import com.iemsoft.framework.cloud.core.tools.SpringUtil; import com.iemsoft.framework.cloud.ribbon.RestInterface; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 表单校验类 * @author DELL * */ @Slf4j @Component("formCheck") public class FormCheck implements SystemClients,BaseConst{ /** * 返回Rest */ public RestInterface getRest(String name){ return SpringUtil.getBean(name, RestInterface.class); } /** * 校验部门是否上下对应 */ public boolean isOrg(String higherOrg,String subOrg){ boolean flag = false; String orgId = null; for(Organization org :this.getOrg(higherOrg)){ orgId = org.getId(); if(org.getChildren()!=null){ for(Organization organiza:org.getChildren()){ if(organiza.getParentId().equals(orgId)){ flag = subOrg.equals(organiza.getCode()); } if(flag==true){ return flag; } } } } return flag; } /** * 取出组织机构树 */ public List getOrg(String code){ Map map = new HashMap<>(); map.put("code", code); RestInterface restInterface = this.getRest(SERVER_TENANT.getBeanName()); Object data = restInterface.post(TenantUrlConst.REST_TENANT_SYSTEM_BUDGETCONFIG_GETPARENTORGS,map,ResMsg.class, EpcRestInterface.getEpcHeads()).getData(); Organizations orgList = JSONTool.toObj(JSONTool.toJson(data),Organizations.class ); return orgList.getOrgs() ==null?new ArrayList<>():orgList.getOrgs(); } /** * 查找上级组织机构 */ public String getHigCodes(String code){ RestInterface restInterface = this.getRest(SERVER_TENANT.getBeanName()); Object data = restInterface.post(TenantUrlConst.REST_TENANT_SYSTEM_BUDGETCONFIG_GETTREE,null,ResMsg.class, EpcRestInterface.getEpcHeads()).getData(); Map maps = new HashMap<>(); List list = JSONTool.toList(JSONTool.toJson(data),Organization.class); getHigCode(list,code,maps); return maps.get(maps.get(code)); } /** * 取出组织机构上级 */ public String getHigCode(List list ,String code,Map maps){ if(ObjectUtil.empty(list)){ return null; } for(Organization org: list){ maps.put(org.getId(),org.getCode() ); if(org.getCode().equals(code)){ maps.put(code, org.getParentId()); // System.out.println(JSONTool.toJson(maps)); break; } if(org.getChildren()!=null){ getHigCode(org.getChildren(),code,maps); } if(maps.get(code)!=null){ return null; } } return null; } }