shichongfu
2023-04-25 ce0b49552668d3331055e2b1a1447a743dc54939
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
package com.product.admin.service;
 
import com.alibaba.fastjson.JSONObject;
import com.beust.jcommander.internal.Lists;
import com.google.common.collect.Sets;
import com.product.admin.config.CmnConst;
import com.product.common.lang.StringUtils;
import com.product.core.cache.DataPoolCacheImpl;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.file.service.FileManagerService;
import com.product.module.sys.entity.SystemUser;
import com.product.util.BaseUtil;
import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.io.IOException;
import java.util.List;
import java.util.Set;
 
/**
 * @Author cheng
 * @Description 单位用户组
 * @Date 2021/6/29 14:22
 * @Version 1.0
 */
@Service
public class CompanyUserGroupService extends AbstractBaseService {
 
    @Autowired
    public PublicService publicService;
    @Autowired
    FileManagerService fileManagerService;
 
 
    public Set<Integer> getGroupUserIds(String uuid) throws BaseException {
 
        if (StringUtils.isEmpty(uuid)) {
            return Sets.newHashSet();
        }
        String[] uuids = uuid.split(",");
        DataTableEntity dt = getBaseDao().listTable(CmnConst.PRODUCT_SYS_COMPANY_USER_GROUP, BaseUtil.buildQuestionMarkFilter(CmnConst.UUID, uuids.length, true), uuids);
        for (int i = 0; i < dt.getRows(); i++) {
 
        }
 
        return null;
    }
 
 
    /**
     * 获取单位用户组
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public List<Object> getCompanyUserGroup(FieldSetEntity fse) throws BaseException {
        SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
        fse.setValue("filter", "org_level_uuid =?");
        fse.setValue("~select_params~", currentUser.getOrg_level_uuid());
        fse.setValue("orderby", "length(tricode)," + CmnConst.GROUP_NAME);
        DataTableEntity dataTableEntity = publicService.listTable(fse, false);
        List<Object> array = Lists.newArrayList();
        FieldSetEntity currentManager = currentUser.getCurrentManager();
        if (currentManager == null) {
            currentManager = currentUser.getCurrentCompany();
        }
        if (currentManager != null) {
            array.add(BaseUtil.fieldSetEntityToJson(currentManager, (json) -> {
                if (json[0] != null) {
                    json[0].put(CmnConst.NAME, currentUser.getOrg_level_name());
                    json[0].put(CmnConst.ICON, "el-icon-s-home");
                    json[0].put("~type~", "company");
                    List<Object> options = Lists.newArrayList();
                    json[0].put("children", BaseUtil.dataTableToTreeData(dataTableEntity, CmnConst.TRICODE, CmnConst.TRICODE_PARENT, (d) -> {
                        JSONObject jsonObject = d[0];
                        if (jsonObject != null) {
                            jsonObject.put(CmnConst.NAME, jsonObject.getString(CmnConst.GROUP_NAME));
                            jsonObject.put(CmnConst.ICON, "fa fa-users");
                            if (!StringUtils.isEmpty(jsonObject.getString("group_sorts")) && !options.contains(jsonObject.getString("group_sorts")))
                                options.add(jsonObject.getString("group_sorts"));
                        }
                    }, true));
                    json[0].put("sort_options", options);
                }
            }));
        }
 
        return array;
    }
 
 
    /**
     * 保存单位用户组
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public String saveCompanyUserGroup(FieldSetEntity fse) throws BaseException {
        if (StringUtils.isEmpty(fse.getString(CmnConst.TRICODE))) {
            publicService.createdCode(fse, fse.getTableName(), CmnConst.TRICODE, fse.getString(CmnConst.TRICODE_PARENT));
        }
        return publicService.saveFieldSetEntity(fse);
    }
 
    /**
     * 删除单位用户组
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public boolean deleteCompanyUserGroup(FieldSetEntity fse) throws BaseException {
        return getBaseDao().delete(fse.getTableName(), "tricode like concat(?,'%')", new String[]{fse.getString(CmnConst.TRICODE)});
    }
 
    /**
     * 获取用户全称 “部门/姓名”
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public DataTableEntity getStaffLevelAll(FieldSetEntity fse) throws BaseException {
        if (!StringUtils.isEmpty(fse.getString("user_ids"))) {
            String[] user_ids = fse.getString("user_ids").split(",");
            StringBuilder sql = new StringBuilder();
            sql.append(" SELECT  a.user_id,c.thumbnail_img,concat(b.org_level_all,'>',a.show_name)  name FROM product_sys_staffs a ");
            sql.append(" JOIN product_sys_users c ON c.user_id=a.user_id ");
            sql.append(" JOIN product_sys_org_levels b ");
            sql.append(" ON a.dept_uuid=b.uuid ");
            sql.append(" WHERE ");
            sql.append(BaseUtil.buildQuestionMarkFilter("a.user_id", user_ids.length, true));
            sql.append(" order by a.user_id in( ");
            sql.append(fse.getString("user_ids"));
            sql.append(" ) desc");
            DataTableEntity dt = getBaseDao().listTable(sql.toString(), user_ids);
            for (int i = 0; i < dt.getRows(); i++) {
                if (!StringUtils.isEmpty(dt.getString(i, CmnConst.THUMBNAIL_IMG))) {
                    byte[] fileContent = fileManagerService.getFileContent(dt.getString(i, CmnConst.THUMBNAIL_IMG));
                    if (fileContent != null) {
                        String bytes = Base64.encodeBase64String(fileContent);
                        dt.setFieldValue(i, CmnConst.THUMBNAIL_IMG, "data:image/*;base64," + bytes);
                    } else {
                        dt.setFieldValue(i, CmnConst.THUMBNAIL_IMG, null);
                    }
                }
            }
            return dt;
        }
        return null;
    }
}