package com.qxueyou.scc.org.service.impl; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.stereotype.Service; import com.alibaba.druid.util.StringUtils; import com.qxueyou.scc.base.model.Result; import com.qxueyou.scc.base.service.impl.CommonAppService; import com.qxueyou.scc.base.util.ClientUtils; import com.qxueyou.scc.base.util.CollectionUtils; import com.qxueyou.scc.org.model.OrgAppInfo; import com.qxueyou.scc.org.model.OrgText; import com.qxueyou.scc.org.model.Organization; import com.qxueyou.scc.org.model.QOrgAppInfo; import com.qxueyou.scc.org.model.QOrgBanner; import com.qxueyou.scc.org.service.IOrganizationService; /** * 组织结构服务类 * * @author 何楷 */ @Service public class OrganizationService extends CommonAppService implements IOrganizationService { @SuppressWarnings("unused") private final Logger log = LogManager.getLogger(OrganizationService.class); /** * 根据用户当前组织ID获取所在局的组织ID */ @SuppressWarnings("unchecked") @Override public String getTopOrgId(String orgId) { String topOrgId = null; String sql = null; //查询所在单位的区局内设机构的orgID sql = "select d.value" + " from sys_dictionary d " + " where d.dic_key = 'TOP_ORG' " + " and d.value in " + " (select organization_id " + " from organization o " + " start with o.organization_id = ? " + " connect by prior o.parent_organization_id = o.organization_id)"; List queryResult = this.findBySql(sql, CollectionUtils.newList(orgId)); if (queryResult != null && !queryResult.isEmpty()) { topOrgId = String.valueOf(queryResult.get(0)); } return topOrgId; } @SuppressWarnings("unchecked") @Override public List queryAllParentOrganizations(String orgId) { String sql = "select organization_id, org_name, short_name, code_, org_code, parent_organization_id, " + " type_,level from organization o start with o.organization_id = ? connect by prior o.parent_organization_id = o.organization_id "; List queryResult = this.findBySql(sql, CollectionUtils.newList(orgId)); List parents = null; Organization tempOrg = null; if (queryResult != null && !queryResult.isEmpty()) { parents = new ArrayList(queryResult.size()); for (Object[] objs : queryResult) { tempOrg = new Organization(); tempOrg.setOrganizationId(String.valueOf(objs[0])); tempOrg.setName(String.valueOf(objs[1])); tempOrg.setShortName(String.valueOf(objs[2])); tempOrg.setCode(String.valueOf(objs[3])); tempOrg.setOrgCode(String.valueOf(objs[4])); tempOrg.setParentOrganizationId(String.valueOf(objs[5])); tempOrg.setType(String.valueOf(objs[6])); tempOrg.setLevel(Short.valueOf(String.valueOf(objs[7]))); parents.add(tempOrg); } } return parents; } @SuppressWarnings("unchecked") @Override public List queryAllChildOrganizations(String orgId) { String sql = "select organization_id, org_name, short_name, code_, org_code, parent_organization_id, " + " type_,level from organization o start with o.organization_id = ? connect by o.parent_organization_id = prior o.organization_id "; List queryResult = this.findBySql(sql, CollectionUtils.newList(orgId)); List childs = null; Organization tempOrg = null; if (queryResult != null && !queryResult.isEmpty()) { childs = new ArrayList(queryResult.size()); for (Object[] objs : queryResult) { tempOrg = new Organization(); tempOrg.setOrganizationId(String.valueOf(objs[0])); tempOrg.setName(String.valueOf(objs[1])); tempOrg.setShortName(String.valueOf(objs[2])); tempOrg.setCode(String.valueOf(objs[3])); tempOrg.setOrgCode(String.valueOf(objs[4])); tempOrg.setParentOrganizationId(String.valueOf(objs[5])); tempOrg.setType(String.valueOf(objs[6])); tempOrg.setLevel(Short.valueOf(String.valueOf(objs[7]))); childs.add(tempOrg); } } return childs; } /** * 查询用户所在的所有组织 * * @param userId * @return */ @Override public List queryUserOrganizaions(String userId) { String hql = "select o from User u,Organization o where u.organizationId = o.organizationId and u.userId =?"; List lstOrgs = this.find(hql, CollectionUtils.newList(userId), Organization.class); return lstOrgs; } @Override public List> getOrgLst() { String hql = "select organizationId as orgId ,shortName as orgName,serverUrl as serverUrl from Organization where deleteFlag = 0 "; return findListWithMapByHql(hql, CollectionUtils.newObjectMap()); } /** * 获取机构信息 * * @return */ public Result getOrgInfo(String appCode, String orgId) { QOrgBanner qOrgBanner = QOrgBanner.orgBanner; QOrgAppInfo qOrgAppInfo = QOrgAppInfo.orgAppInfo; orgId = StringUtils.isEmpty(orgId)?ClientUtils.getOrgId():orgId; List> lstBanner = this.getQueryFactory().selectFrom(qOrgBanner).where(qOrgBanner.deleteFlag.isFalse().and(qOrgBanner.orgId.eq(orgId))). orderBy(qOrgBanner.photoOrder.asc()).fetch().stream() .map(tuple -> { Map map = new HashMap(3); map.put("bannerId", tuple.getBannerId()); map.put("content", tuple.getContent()); map.put("imgPath", tuple.getImgPath()); map.put("photoName", tuple.getPhotoName()); map.put("title", tuple.getTitle()); return map; }).collect(Collectors.toList()); OrgText orgText = this.read(OrgText.class, orgId); Organization org = this.read(Organization.class, orgId); OrgAppInfo orgAppInfo = null; if(!StringUtils.isEmpty(appCode)) { orgAppInfo = this.getQueryFactory().selectFrom(qOrgAppInfo).where(qOrgAppInfo.orgId.eq(orgId) .and(qOrgAppInfo.appCode.eq(appCode)).and(qOrgAppInfo.deleteFlag.isFalse())).fetchFirst(); } return new Result(true, "success", CollectionUtils.newObjectMap("orgName", org.getName(), "shortName", org.getShortName(), "tel", org.getTel(), "orgLogo", orgAppInfo == null?org.getLogoPath():orgAppInfo.getLogoUrl(), "lstBanner", lstBanner, "content", orgText == null ? "" : orgText.getContent(), "appInfo", orgAppInfo)); } }