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();
|
}
|
}
|
}
|