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<Object[]> 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<Organization> 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<Object[]> queryResult = this.findBySql(sql, CollectionUtils.newList(orgId));
|
List<Organization> parents = null;
|
Organization tempOrg = null;
|
if (queryResult != null && !queryResult.isEmpty()) {
|
parents = new ArrayList<Organization>(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<Organization> 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<Object[]> queryResult = this.findBySql(sql, CollectionUtils.newList(orgId));
|
List<Organization> childs = null;
|
Organization tempOrg = null;
|
if (queryResult != null && !queryResult.isEmpty()) {
|
childs = new ArrayList<Organization>(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<Organization> queryUserOrganizaions(String userId) {
|
String hql = "select o from User u,Organization o where u.organizationId = o.organizationId and u.userId =?";
|
List<Organization> lstOrgs = this.find(hql, CollectionUtils.newList(userId), Organization.class);
|
return lstOrgs;
|
}
|
|
@Override
|
public List<Map<String, Object>> 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<Map<String, Object>> lstBanner = this.getQueryFactory().selectFrom(qOrgBanner).where(qOrgBanner.deleteFlag.isFalse().and(qOrgBanner.orgId.eq(orgId))).
|
orderBy(qOrgBanner.photoOrder.asc()).fetch().stream()
|
.map(tuple -> {
|
Map<String,Object> map = new HashMap<String,Object>(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));
|
}
|
|
}
|