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