weaver-hrm-organization/src/com/engine/organization/service/impl/HrmPersonnelCardServiceImpl...

282 lines
12 KiB
Java
Raw Normal View History

2022-10-09 11:42:26 +08:00
package com.engine.organization.service.impl;
2022-11-10 10:28:14 +08:00
import com.engine.common.service.HrmCommonService;
import com.engine.common.service.impl.HrmCommonServiceImpl;
2022-10-09 11:42:26 +08:00
import com.engine.core.impl.Service;
import com.engine.organization.entity.personnelcard.*;
2022-11-10 10:28:14 +08:00
import com.engine.organization.entity.personnelcard.po.CardAccessPO;
2022-11-11 13:59:45 +08:00
import com.engine.organization.entity.personnelcard.po.CardButtonPO;
2022-12-05 17:57:33 +08:00
import com.engine.organization.entity.personnelcard.po.CusTreeFormPO;
2022-11-10 10:28:14 +08:00
import com.engine.organization.exception.OrganizationRunTimeException;
import com.engine.organization.mapper.personnelcard.CardAccessMapper;
2022-11-11 13:59:45 +08:00
import com.engine.organization.mapper.personnelcard.CardButtonMapper;
2022-10-09 11:42:26 +08:00
import com.engine.organization.mapper.personnelcard.PersonnelCardMapper;
import com.engine.organization.service.HrmPersonnelCardService;
import com.engine.organization.util.OrganizationAssert;
import com.engine.organization.util.db.MapperProxyFactory;
import com.engine.portal.biz.constants.ModuleConstants;
import com.engine.portal.biz.nonstandardfunction.SysModuleInfoBiz;
2022-10-18 11:41:11 +08:00
import org.apache.commons.collections.CollectionUtils;
2022-10-17 17:16:26 +08:00
import org.apache.commons.lang3.StringUtils;
2022-12-05 17:57:33 +08:00
import org.json.JSONObject;
2022-10-09 11:42:26 +08:00
import weaver.blog.BlogShareManager;
2022-12-14 15:38:29 +08:00
import weaver.conn.RecordSet;
2022-10-09 11:42:26 +08:00
import weaver.cowork.CoworkShareManager;
import weaver.crm.CrmShareBase;
import weaver.docs.search.DocSearchComInfo;
2022-10-18 11:41:11 +08:00
import weaver.general.BaseBean;
2022-10-09 11:42:26 +08:00
import weaver.general.Util;
2022-12-05 17:57:33 +08:00
import weaver.hrm.definedfield.HrmFieldManager;
2022-11-10 10:28:14 +08:00
import weaver.hrm.resource.ResourceComInfo;
2022-12-05 17:57:33 +08:00
import weaver.systeminfo.SystemEnv;
2022-10-09 11:42:26 +08:00
import weaver.workflow.search.WorkflowRequestUtil;
2022-11-10 10:28:14 +08:00
import java.util.*;
2022-10-09 11:42:26 +08:00
/**
* @author:dxfeng
* @createTime: 2022/10/08
* @version: 1.0
*/
public class HrmPersonnelCardServiceImpl extends Service implements HrmPersonnelCardService {
private PersonnelCardMapper getPersonnelCardMapper() {
return MapperProxyFactory.getProxy(PersonnelCardMapper.class);
}
2022-11-11 13:59:45 +08:00
private CardButtonMapper getCardButtonMapper() {
return MapperProxyFactory.getProxy(CardButtonMapper.class);
}
2022-10-09 11:42:26 +08:00
@Override
public Map<String, Object> getPersonnelCard(Long uId) {
Map<String, Object> resultMap = new HashMap<>();
2022-11-09 16:58:09 +08:00
UserCard userInfo;
2022-10-09 11:42:26 +08:00
if (null == uId) {
2022-12-05 17:57:33 +08:00
uId = (long) user.getUID();
2022-10-09 11:42:26 +08:00
}
userInfo = getPersonnelCardMapper().getUserById(uId);
2022-12-05 17:57:33 +08:00
userInfo.setEcId(uId.toString());
2022-10-09 11:42:26 +08:00
OrganizationAssert.notNull(uId, "未找到对应数据");
// 人员基本信息
// 统计报表
2022-12-05 17:57:33 +08:00
Statistical statistical = getStatistical(userInfo.getEcId());
2022-11-09 16:58:09 +08:00
2022-12-05 17:57:33 +08:00
// 获取类型分组信息
List<CusTreeFormPO> cusTreeForms = getPersonnelCardMapper().getCusTreeForms(0);
2022-12-08 11:01:30 +08:00
cusTreeForms.removeIf(item -> !hasGroupAccess(item.getId(), userInfo.getEcId()));
2022-10-09 11:42:26 +08:00
List<FormItem> formItemList = new ArrayList<>();
2022-12-05 17:57:33 +08:00
try {
for (CusTreeFormPO cusTreeForm : cusTreeForms) {
FormItem formItem = getFormItem(cusTreeForm, uId);
if (CollectionUtils.isEmpty(formItem.getItems())) {
continue;
}
2022-11-14 13:56:19 +08:00
2022-12-05 17:57:33 +08:00
//TODO 明细表暂不处理
//List<Map<String, Object>> detailList = ServiceUtil.getService(ExtServiceImpl.class, user).getExtendTables(user, "4", groupPO.getId(), "JCL_ORG_HRMRESOURCEEXT_DT1", uId, 1, false);
//formItem.setTables(detailList);
2022-11-14 13:56:19 +08:00
2022-12-05 17:57:33 +08:00
formItemList.add(formItem);
}
} catch (Exception e) {
throw new RuntimeException(e);
2022-10-09 11:42:26 +08:00
}
2022-12-05 17:57:33 +08:00
2022-10-09 11:42:26 +08:00
// 所有锚点
List<Anchor> anchorList = new ArrayList<>();
// 添加字段分组信息
2022-10-18 11:41:11 +08:00
for (FormItem formItem : formItemList) {
anchorList.add(Anchor.builder().id(formItem.getId()).title(formItem.getTitle()).build());
2022-10-09 11:42:26 +08:00
}
// 添加拓展页面信息
List<ResourceBaseTab> resourceBaseTabList = getPersonnelCardMapper().getResourceBaseTabList();
for (ResourceBaseTab resourceBaseTab : resourceBaseTabList) {
2022-10-17 17:16:26 +08:00
anchorList.add(Anchor.builder().id("tab" + resourceBaseTab.getId()).title(resourceBaseTab.getGroupName()).build());
2022-10-09 11:42:26 +08:00
}
2022-12-05 17:57:33 +08:00
resultMap.put("buttons", getButtonList(userInfo.getEcId()));
2022-10-09 11:42:26 +08:00
resultMap.put("user", userInfo);
resultMap.put("statistical", statistical);
resultMap.put("formItems", formItemList);
resultMap.put("anchorList", anchorList);
2022-10-14 09:13:28 +08:00
resultMap.put("iframeList", getIframeList());
2022-10-09 11:42:26 +08:00
return resultMap;
}
@Override
public List<Iframe> getIframeList() {
List<Iframe> iframeList = new ArrayList<>();
List<ResourceBaseTab> resourceBaseTabList = getPersonnelCardMapper().getResourceBaseTabList();
for (ResourceBaseTab resourceBaseTab : resourceBaseTabList) {
2022-10-17 17:16:26 +08:00
iframeList.add(Iframe.builder().id("tab" + resourceBaseTab.getId()).title(resourceBaseTab.getGroupName()).url(resourceBaseTab.getLinkUrl()).build());
2022-10-09 11:42:26 +08:00
}
return iframeList;
}
/**
* 获取报表统计数据
*
* @param ecResourceId
2022-10-09 11:42:26 +08:00
* @return
*/
private Statistical getStatistical(String ecResourceId) {
2022-10-09 11:42:26 +08:00
try {
2022-10-14 09:13:28 +08:00
// 获取Ec用户ID
2022-10-09 11:42:26 +08:00
Statistical statistical = new Statistical();
if (SysModuleInfoBiz.checkModuleStatus(ModuleConstants.Workflow)) {
2022-10-14 09:13:28 +08:00
statistical.setWorkflowCount(new WorkflowRequestUtil().getRequestCount(user, ecResourceId));
2022-10-09 11:42:26 +08:00
} else {
statistical.setWorkflowCount(0);
}
if (SysModuleInfoBiz.checkModuleStatus(ModuleConstants.Doc)) {
2022-10-14 09:13:28 +08:00
Object[] docCount4Hrm = new DocSearchComInfo().getDocCount4Hrm(ecResourceId, user);
2022-10-09 11:42:26 +08:00
statistical.setDocCount(null == docCount4Hrm[1] ? 0 : Integer.parseInt(Util.null2String(docCount4Hrm[1])));
} else {
statistical.setDocCount(0);
}
if (SysModuleInfoBiz.checkModuleStatus(ModuleConstants.Crm)) {
2022-10-14 09:13:28 +08:00
String[] crmCount4Hrm = new CrmShareBase().getCrmCount4Hrm(ecResourceId, ecResourceId);
2022-10-09 11:42:26 +08:00
statistical.setCusCount(null == crmCount4Hrm[1] ? 0 : Integer.parseInt(Util.null2String(crmCount4Hrm[1])));
} else {
statistical.setCusCount(0);
}
if (SysModuleInfoBiz.checkModuleStatus(ModuleConstants.Cowork)) {
2022-10-14 09:13:28 +08:00
String[] coworkCount4Hrm = new CoworkShareManager().getCoworkCount4Hrm(ecResourceId, ecResourceId);
2022-10-09 11:42:26 +08:00
statistical.setCollaborationCount(null == coworkCount4Hrm[1] ? 0 : Integer.parseInt(Util.null2String(coworkCount4Hrm[1])));
} else {
statistical.setCollaborationCount(0);
}
if (SysModuleInfoBiz.checkModuleStatus(ModuleConstants.Blog)) {
2022-10-14 09:13:28 +08:00
String[] blogCount4Hrm = new BlogShareManager().getBlogCount4Hrm(ecResourceId);
2022-10-09 11:42:26 +08:00
statistical.setWeiboCount(null == blogCount4Hrm[1] ? 0 : Integer.parseInt(Util.null2String(blogCount4Hrm[1])));
} else {
statistical.setWeiboCount(0);
}
return statistical;
} catch (Exception e) {
2022-10-18 11:41:11 +08:00
new BaseBean().writeLog(e);
2022-10-09 11:42:26 +08:00
throw new RuntimeException(e);
}
}
2022-12-05 17:57:33 +08:00
/**
* 获取人员主表信息拓展表信息
*
* @param cusTreeFormPO
* @param uId
* @return
* @throws Exception
*/
private FormItem getFormItem(CusTreeFormPO cusTreeFormPO, Long uId) throws Exception {
2022-10-09 11:42:26 +08:00
FormItem formItem = new FormItem();
2022-12-05 17:57:33 +08:00
formItem.setId(cusTreeFormPO.getId().toString());
formItem.setTitle(cusTreeFormPO.getFormLabel());
2022-10-09 11:42:26 +08:00
List<Item> itemList = new ArrayList<>();
2022-12-05 17:57:33 +08:00
HrmFieldManager hfm = new HrmFieldManager("HrmCustomFieldByInfoType", cusTreeFormPO.getId());
hfm.getHrmData(uId.intValue());
hfm.getCustomFields();
while (hfm.next()) {
String fieldName = hfm.getFieldname();
JSONObject hrmFieldConf = hfm.getHrmFieldConf(fieldName);
String fieldLabel = Util.toScreen(SystemEnv.getHtmlLabelName(hrmFieldConf.getInt("fieldlabel"), user.getLanguage()), user.getLanguage());
2022-12-14 15:38:29 +08:00
String hrmData = "";
if (hfm.isBaseField(fieldName)) {
hrmData = hfm.getHrmData(fieldName);
} else {
RecordSet recordSet = new RecordSet();
recordSet.execute("select " + fieldName + " from cus_fielddata where SCOPE = '" + cusTreeFormPO.getScope() + "' and SCOPEID =" + cusTreeFormPO.getId() + " and id = " + uId);
if (recordSet.next()) {
hrmData = recordSet.getString(fieldName);
}
}
String fieldValue = hfm.getFieldvalue(null, user, null, hrmFieldConf.getString("dmlurl"), hrmFieldConf.getInt("id"), hrmFieldConf.getInt("fieldhtmltype"), hrmFieldConf.getInt("type"), hrmData, 0, fieldName);
2022-12-05 17:57:33 +08:00
itemList.add(Item.builder().fieldId(fieldLabel).fieldValue(fieldValue).build());
2022-10-09 11:42:26 +08:00
}
formItem.setItems(itemList);
return formItem;
}
2022-11-10 10:28:14 +08:00
/**
* 判断当前人员是否有查看当前数据当前模块的权限
*
* @param typeId 人员卡片分组ID
* @param userId 当前卡片人员EcId
* @return
*/
public boolean hasGroupAccess(Integer typeId, String userId) {
// 人员信息有误,返回false
OrganizationAssert.notBlank(userId, "未获取到对应人员");
boolean hasAccess = false;
CardAccessPO cardAccessPO = MapperProxyFactory.getProxy(CardAccessMapper.class).selectById(typeId);
2022-11-14 11:19:08 +08:00
if (null == cardAccessPO || 0 == cardAccessPO.getStatus()) {
// 未配置相应数据、或者未启用返回false
2022-11-11 09:09:53 +08:00
return false;
}
2022-11-14 11:19:08 +08:00
// 系统管理员、查看本人卡片,或者所有人有权限直接返回true
2022-11-14 13:56:19 +08:00
if (user.isAdmin() || userId.equals(String.valueOf(user.getUID())) || 1 == cardAccessPO.getAllPeople()) {
2022-11-10 10:28:14 +08:00
return true;
}
try {
ResourceComInfo resourceComInfo = new ResourceComInfo();
// 上级
if ("1".equals(Util.null2String(cardAccessPO.getSuperior()))) {
String managerID = resourceComInfo.getManagerID(userId);
hasAccess = Arrays.asList(managerID.split(",")).contains(Util.null2String(user.getUID()));
}
// 所有上级
2022-11-11 13:59:45 +08:00
if (!hasAccess && "1".equals(Util.null2String(cardAccessPO.getAllSuperior()))) {
2022-11-10 10:28:14 +08:00
String managersIDs = resourceComInfo.getManagersIDs(userId);
2022-11-11 13:59:45 +08:00
hasAccess = Arrays.asList(managersIDs.split(",")).contains(Util.null2String(user.getUID()));
2022-11-10 10:28:14 +08:00
}
} catch (Exception e) {
new BaseBean().writeLog(e);
throw new OrganizationRunTimeException("人员卡片权限");
}
// 角色判断
2022-11-11 13:59:45 +08:00
if (!hasAccess && StringUtils.isNotBlank(cardAccessPO.getCustom())) {
2022-11-10 10:28:14 +08:00
HrmCommonService hrmCommonService = new HrmCommonServiceImpl();
2022-11-11 13:59:45 +08:00
List<String> roleIds = new ArrayList<>(Arrays.asList(hrmCommonService.getRoleIds(user.getUID()).split(",")));
List<String> accessRoleIds = new ArrayList<>(Arrays.asList(cardAccessPO.getCustom().split(",")));
roleIds.retainAll(accessRoleIds);
hasAccess = CollectionUtils.isNotEmpty(roleIds);
2022-11-10 10:28:14 +08:00
}
return hasAccess;
}
2022-10-09 11:42:26 +08:00
2022-11-11 13:59:45 +08:00
/**
* 获取当前人员有权限的按钮系统管理员展示所有个人卡片展示系统默认按钮其余按钮依照配置角色展示
*
* @param ecResourceId
* @return
*/
private List<CardButtonPO> getButtonList(String ecResourceId) {
boolean isMySelf = ecResourceId.equals(Util.null2String(user.getUID()));
boolean isAdmin = user.isAdmin();
List<CardButtonPO> cardButtonPOS = getCardButtonMapper().listEnableButton();
List<CardButtonPO> buttonList = new ArrayList<>();
HrmCommonService hrmCommonService = new HrmCommonServiceImpl();
List<String> roleIds = new ArrayList<>(Arrays.asList(hrmCommonService.getRoleIds(user.getUID()).split(",")));
for (CardButtonPO cardButton : cardButtonPOS) {
2022-11-11 16:52:01 +08:00
List<String> accessRoleIds = new ArrayList<>(Arrays.asList(Util.null2String(cardButton.getRoles()).split(",")));
2022-11-11 13:59:45 +08:00
roleIds.retainAll(accessRoleIds);
if (isAdmin || (isMySelf && "0".equals(cardButton.getSysDefault())) || CollectionUtils.isNotEmpty(roleIds)) {
buttonList.add(CardButtonPO.builder().name(cardButton.getName()).url(cardButton.getUrl()).sysDefault(cardButton.getSysDefault()).build());
}
}
return buttonList;
}
2022-10-09 11:42:26 +08:00
}