派生自 projectDept/qhighschool

胡仁荣
2022-10-31 fe7381d6e8ec1f427408de0297ac7f41533202f6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
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));
    }
 
}