杜洪波
2024-10-09 0265a4b398b7618880d5dcb6fdb50939409eb2a0
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
package com.product.administration.service;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.product.administration.config.CmnConst;
import com.product.common.lang.StringUtils;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldMetaEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.permission.PermissionService;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.service.support.QueryFilterService;
import com.product.module.data.service.SystemDataExportService;
import com.product.util.BaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * Copyright LX
 * @Title: AddressListService
 * @Project: product-server
 * @date: 2021-05-25 14:16
 * @author: ZhouJie
 * @Description: 通讯录
 */
@Component
@Service
public class AddressListService extends AbstractBaseService {
    @Autowired
    public BaseDao baseDao;
    @Autowired
    PermissionService permissionService;
    @Autowired
    QueryFilterService queryFilterService;
    //导出方法
    @Autowired
    SystemDataExportService systemDataExportService;
    /**
     * @description: 获取通讯录,按条件搜索(集团、部门、岗位、性别)
     * @author: ZhouJie
     * @date: 2021-05-25 15:23
     */
    public DataTableEntity Addresslist(FieldSetEntity fs) {
        StringBuffer str = new StringBuffer();
        str.append(" select lu.thumbnail_img thumbnail_img,ls.show_name show_name,lp.job_post_name job_post_name, ");
        str.append(" ls.staff_email staff_email,lu.office_phone office_phone,lu.user_mobile_number user_mobile_number, ");
        str.append(" d.org_level_all org_level_all,lu.user_id user_id, ");
        str.append(" c.org_level_name org_level_uuid, ");
        str.append(" d.org_level_name dept_uuid,lu.gender gender, ");
        str.append(" lu.inside_phone inside_phone,lu.user_phone_number user_phone_number,lu.contact_address contact_address ");
        str.append(" from (product_sys_users lu left join product_sys_staffs ls on lu.user_id=ls.user_id ) ");
        str.append(" left join product_sys_job_posts lp on ls.job_post_uuid=lp.uuid ");
        str.append(" left join product_sys_job_post_grades pg on ls.job_post_grade_uuid=pg.uuid");
        str.append(" left join product_sys_org_levels c on c.uuid=ls.org_level_uuid");
        str.append(" left join product_sys_org_levels d on d.uuid=ls.dept_uuid");
        str.append(" where ls.user_id is not null ");
        List<Object> params = new ArrayList<Object>();
//        if(!StringUtils.isEmpty(fs.getString("org_level_uuid"))){
//            str.append(" and ls.org_level_uuid=? ");
//            params.add(fs.getString("org_level_uuid"));
//        }
        if(!StringUtils.isEmpty(fs.getString("dept_uuid"))){
            str.append(" and ls.dept_uuid=? ");
            params.add(fs.getString("dept_uuid"));
        }
        if(!StringUtils.isEmpty(fs.getString("job_post_uuid"))){
            str.append(" and ls.job_post_uuid=? ");
            params.add(fs.getString("job_post_uuid"));
        }
        if(!StringUtils.isEmpty(fs.getString("gender"))){
            str.append(" and lu.gender=? ");
            params.add(fs.getString("gender"));
        }
        str.append("order by c.sequence,d.sequence,lp.sequence,pg.sequence");
        DataTableEntity dt = baseDao.listTable(str.toString(),params.toArray());
        baseDao.loadPromptData(dt);
        return dt;
    }
 
    /**
     * @description: 全员搜索(匹配名字、电话、邮箱)
     * @author: ZhouJie
     * @date: 2021-05-25 17:23
     */
    public DataTableEntity FullSearch(FieldSetEntity fs) {
        DataTableEntity dt = null;
        StringBuffer str = new StringBuffer();
        str.append(" select lu.thumbnail_img thumbnail_img,ls.show_name show_name,lp.job_post_name job_post_name, ");
        str.append(" ls.staff_email staff_email,lu.office_phone office_phone,lu.user_mobile_number user_mobile_number, ");
        str.append(" (select org_level_all FROM product_sys_org_levels where uuid=ls.dept_uuid) org_level_all, ");
        str.append(" (select org_level_name FROM product_sys_org_levels where uuid=ls.org_level_uuid) org_level_uuid,lu.user_id user_id, ");
        str.append(" (select org_level_name FROM product_sys_org_levels where uuid=ls.dept_uuid) dept_uuid,lu.gender gender, ");
        str.append(" lu.inside_phone inside_phone,lu.user_phone_number user_phone_number,lu.contact_address contact_address ");
        str.append(" from (product_sys_users lu left join product_sys_staffs ls on lu.user_id=ls.user_id ");
        str.append(" ) left join product_sys_job_posts lp on ls.job_post_uuid=lp.uuid ");
        str.append(" where ls.user_id is not null ");
        String txt = fs.getString("txt");
        if(!StringUtils.isEmpty(txt)){
            str.append(" and (ls.show_name like concat('%',?,'%') or ls.staff_email like concat('%',?,'%') or " );
            str.append(" lu.user_mobile_number like concat('%',?,'%') or lu.office_phone like concat('%',?,'%')) ");
            dt = baseDao.listTable(str.toString(),new Object[]{txt,txt,txt,txt});
        }else{
            dt = baseDao.listTable(str.toString());
        }
        baseDao.loadPromptData(dt);
        return dt;
    }
 
    /**
     * 通讯录导出
     * @param fs
     */
    public void addressBookExport(FieldSetEntity fs){
        String txt = fs.getString("txt");
        DataTableEntity dt;
        if(BaseUtil.strIsNull(txt)){
            //封装dt数据为jsonArray
            dt = this.Addresslist(fs);
        }else {
            dt = this.FullSearch(fs);
        }
        JSONArray arr = new JSONArray();
        for (int i = 0; i < dt.getRows(); i++) {
            JSONObject user = new JSONObject();
            FieldSetEntity fieldSetEntity = dt.getFieldSetEntity(i);
            //所属公司
            user.put(CmnConst.ORG_LEVEL_UUID,fieldSetEntity.getString(CmnConst.ORG_LEVEL_UUID));
            //所属部门
            user.put(CmnConst.DEPT_UUID, fieldSetEntity.getString(CmnConst.DEPT_UUID));
            //所属岗位
            user.put("job_post_name",fieldSetEntity.getString("job_post_name"));
            //员工名称
            user.put("show_name",fieldSetEntity.getString("show_name"));
            //员工邮箱
            user.put("staff_email",fieldSetEntity.getString("staff_email"));
            //办公电话
            user.put("office_phone",fieldSetEntity.getString("office_phone"));
            //移动电话
            user.put("user_mobile_number",fieldSetEntity.getString("user_mobile_number"));
            //内线电话
            user.put("inside_phone",fieldSetEntity.getString("inside_phone"));
            //住宅电话
            user.put("user_phone_number",fieldSetEntity.getString("user_phone_number"));
            arr.add(user);
        }
        String[] fieldDescriptions = new String[]{"所属公司", "所属部门", "所属岗位", "员工名称", "邮箱地址", "办公电话", "移动电话", "内线电话", "住宅电话"};
        String[] fieldNames = new String[]{CmnConst.ORG_LEVEL_UUID, CmnConst.DEPT_UUID, "job_post_name", "show_name", "staff_email", "office_phone", "user_mobile_number", "inside_phone", "user_phone_number"};
        //添加表数据
        DataTableEntity export_field = new DataTableEntity();
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new String[]{"export_field"});
            export_field.setMeta(f);
            for (int i = 0; i < fieldDescriptions.length; i++) {
                FieldSetEntity fieldSetEntity = new FieldSetEntity();
                fieldSetEntity.setTableName("export_field");
                fieldSetEntity.setValue("field_description", fieldDescriptions[i]);
                fieldSetEntity.setValue(CmnConst.FIELD_NAME, fieldNames[i]);
                export_field.addFieldSetEntity(fieldSetEntity);
            }
        try {
            systemDataExportService.writeExcel(arr, export_field, "通讯录");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}