package jnpf.flowable.util; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; import com.google.common.collect.ImmutableList; import jnpf.base.ActionResult; import jnpf.base.Pagination; import jnpf.base.UserInfo; import jnpf.base.entity.DictionaryDataEntity; import jnpf.base.entity.SystemEntity; import jnpf.base.entity.VisualdevEntity; import jnpf.base.model.VisualDevJsonModel; import jnpf.base.model.flow.DataModel; import jnpf.base.model.flow.FlowFormDataModel; import jnpf.base.model.flow.FlowStateModel; import jnpf.base.model.schedule.ScheduleNewCrForm; import jnpf.base.model.systemconfig.SysConfigModel; import jnpf.base.service.*; import jnpf.base.util.SentMessageUtil; import jnpf.base.vo.DownloadVO; import jnpf.constant.*; import jnpf.emnus.ModuleTypeEnum; import jnpf.emnus.SysParamEnum; import jnpf.exception.WorkFlowException; import jnpf.extend.service.DocumentApi; import jnpf.flowable.entity.TemplateEntity; import jnpf.flowable.model.template.TemplateExportModel; import jnpf.flowable.model.util.FlowContextHolder; import jnpf.flowable.model.util.FlowNature; import jnpf.message.model.SentMessageForm; import jnpf.model.SystemParamModel; import jnpf.model.document.FlowFileModel; import jnpf.onlinedev.model.PaginationModel; import jnpf.onlinedev.model.VisualParamModel; import jnpf.permission.entity.*; import jnpf.permission.model.authorize.AuthorizeVO; import jnpf.permission.service.*; import jnpf.util.DataFileExport; import jnpf.util.StringUtil; import jnpf.util.enums.DictionaryDataEnum; import jnpf.visual.service.VisualdevApi; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.*; import java.util.stream.Collectors; import static jnpf.util.Constants.ADMIN_KEY; @Component public class ServiceUtil { @Autowired private DictionaryDataService dictionaryDataService; @Autowired private UserRelationService userRelationService; @Autowired private UserService userApi; @Autowired private RoleService roleService; @Autowired private RoleRelationService roleRelationService; @Autowired private OrganizeService organizeService; @Autowired private PositionService positionService; @Autowired private CodeNumService codeNumService; @Autowired private DataInterfaceService dataInterfaceService; @Autowired private SentMessageUtil sentMessageUtil; @Autowired private DataFileExport fileExport; @Autowired private CommonWordsService commonWordsService; @Autowired private SignService signService; @Autowired private AuthorizeService authorizeService; @Autowired private VisualdevApi visualdevApi; @Autowired private DocumentApi documentApi; @Autowired private BillRuleService billRuleService; @Autowired private SystemConfigApi systemConfigApi; @Autowired private SystemService systemApi; @Autowired private ScheduleNewApi scheduleNewApi; // 创建日程 public void createSchedule(ScheduleNewCrForm fo) throws WorkFlowException { ActionResult result = scheduleNewApi.create(fo); if (result.getCode() != 200) { throw new WorkFlowException(result.getMsg()); } } // 获取系统配置 public SysConfigModel getSysConfig() { ActionResult actionResult = systemConfigApi.list(); return actionResult.getData(); } // 获取系统配置,流程签收 public Boolean getFlowSign() { ActionResult actionResult = systemConfigApi.list(); SysConfigModel data = actionResult.getData(); return data.getFlowSign() == 0; } // 获取系统配置,流程办理 public Boolean getFlowTodo() { ActionResult actionResult = systemConfigApi.list(); SysConfigModel data = actionResult.getData(); return data.getFlowTodo() == 0; } // 流水号 public String getBillNumber() { return billRuleService.getBillNumber(FlowNature.REVOKE_BILL_CODE, false); } // -------------------------------签名----------------------------- public void updateSign(String signId, String signImg) { SignEntity signEntity = signService.getById(signId); if (null != signEntity) { signService.updateDefault(signId); } else { signEntity = new SignEntity(); signEntity.setIsDefault(1); signEntity.setSignImg(signImg); signService.create(signEntity); } } // -------------------------------流程编码----------------------------- public String getCode() { return codeNumService.getCodeOnce(CodeConst.LC); } // -------------------------------常用语----------------------------- public void addCommonWordsNum(String handleOpinion) { commonWordsService.addCommonWordsNum(handleOpinion); } // -------------------------------文件----------------------------- // 判断是否存在归档文件,不存在为true public Boolean checkFlowFile(String taskId) { return documentApi.checkFlowFile(taskId); } // 获取归档文件 public List> getFlowFile(FlowFileModel model) { return documentApi.getFlowFile(model); } // -------------------------------流程全部权限----------------------------- public List getPermission(String userId) { return getPermission(userId, AuthorizeConst.FLOW); } public List getPermission(String userId, String itmeType) { List userIdList = ImmutableList.of(userId); List objectIdList = new ArrayList<>(); List posId = getListByUserIdAll(userIdList).stream().filter(e -> Objects.equals(PermissionConst.POSITION, e.getObjectType())).map(UserRelationEntity::getObjectId).collect(Collectors.toList()); objectIdList.addAll(posId); List roleId = getRoleObjectId(userIdList).stream().map(RoleRelationEntity::getRoleId).collect(Collectors.toList()); objectIdList.addAll(roleId); List resList = new ArrayList<>(); if (!objectIdList.isEmpty()) { resList = getAuthorizeObjectId(objectIdList).stream().filter(e -> e.getItemType().equals(itmeType)).map(AuthorizeEntity::getItemId).collect(Collectors.toList()); } return resList; } // -------------------------------发起权限----------------------------- public List getLaunchPermission() { AuthorizeVO authorizeByUser = getAuthorizeByUser(); List flowIdList = authorizeByUser.getFlowIdList(); return flowIdList; } // true是普通用户 public boolean isCommonUser(String userId) { UserEntity userInfo = getUserInfo(userId); return userInfo == null || !Objects.equals(userInfo.getAccount(), ADMIN_KEY); } // 获取流程有发起权限的人员 public List getLaunchUserByTemplateId(TemplateEntity template, Pagination pagination) { if (ObjectUtil.equals(template.getVisibleType(), FlowNature.All)) { // 公开直接返回用户分页 return userApi.getUserPage(pagination); } // 根据流程主键、权限为流程类型 获取权限关联 List userIdList = new ArrayList<>(); List authorizeList = getListByObjectAndItemIdAndType(template.getId()).stream().filter(e -> !Objects.equals(PermissionConst.ORGANIZE, e.getObjectType())).collect(Collectors.toList()); for (AuthorizeEntity entity : authorizeList) { String objectType = PermissionConst.POSITION.equals(entity.getObjectType()) ? SysParamEnum.POS.getCode() : SysParamEnum.ROLE.getCode(); userIdList.add(entity.getObjectId() + "--" + objectType); } List userListAll = this.getUserListAll(userIdList); return this.getUserName(userListAll, pagination); } //--------------------------------表单------------------------------ public VisualdevEntity getFormInfo(String id) { return visualdevApi.getFormConfig(id); } public List getFormList(List formIds) { if (formIds.isEmpty()) { return new ArrayList<>(); } return visualdevApi.getFormConfigList(formIds); } public void saveOrUpdateFormData(FlowFormDataModel model) throws WorkFlowException { ActionResult actionResult = visualdevApi.saveOrUpdate(model); if (actionResult.getCode() != 200) { throw new WorkFlowException(actionResult.getMsg()); } } public void deleteFormData(String formId, String id) throws Exception { if (StringUtil.isBlank(formId) || StringUtil.isBlank(id)) { return; } try { visualdevApi.delete(formId, id); } catch (Exception e) { e.printStackTrace(); } } public Map infoData(String formId, String id) throws WorkFlowException { // 流程调用表单接口 Map dataAll = new HashMap<>(); if (StringUtil.isNotEmpty(formId) && StringUtil.isNotEmpty(id)) { ActionResult result = visualdevApi.info(formId, id); if (null != result && null != result.getData()) { dataAll = (Map) result.getData(); } } return dataAll; } public void handleFormData(String flowId, Boolean isTransfer) throws WorkFlowException { try { Map> allData = FlowContextHolder.getAllData(); Map>> formOperates = FlowContextHolder.getFormOperates(); List writeIdList = FlowContextHolder.getWriteIdList(); for (String key : writeIdList) { String[] idList = key.split(JnpfConst.SIDE_MARK); List> operates = formOperates.get(key); Map formData = allData.get(key); formData = formData == null ? new HashMap<>() : formData; FlowFormDataModel formDataModel = FlowFormDataModel.builder().formId(idList[1]).id(idList[0]).map(formData).formOperates(operates) .flowId(flowId).isTransfer(isTransfer).build(); this.saveOrUpdateFormData(formDataModel); } } catch (WorkFlowException e) { throw e; } finally { FlowContextHolder.clearAll(); } } public List> getListWithTableList(VisualDevJsonModel visualDevJsonModel, PaginationModel pagination, UserInfo userInfo) { return visualdevApi.getListWithTableList(visualDevJsonModel, pagination, userInfo); } public VisualdevEntity getReleaseInfo(String formId) { return visualdevApi.getReleaseInfo(formId); } public DataModel visualCreate(VisualdevEntity visualdevEntity, Map data) throws Exception { VisualParamModel visualParamModel = VisualParamModel.builder().visualdevEntity(visualdevEntity).data(data).build(); return visualdevApi.visualCreate(visualParamModel); } public DataModel visualUpdate(VisualdevEntity visualdevEntity, Map data, String id) throws Exception { VisualParamModel visualParamModel = VisualParamModel.builder().visualdevEntity(visualdevEntity).data(data).id(id).onlyUpdate(true).build(); return visualdevApi.visualUpdate(visualParamModel); } public void visualDelete(VisualdevEntity visualdevEntity, List> dataList) throws Exception { VisualParamModel visualParamModel = VisualParamModel.builder().visualdevEntity(visualdevEntity).dataList(dataList).build(); visualdevApi.visualDelete(visualParamModel); } public void deleteSubTable(FlowFormDataModel model) throws Exception { visualdevApi.deleteByTableName(model); } public void saveState(FlowStateModel stateModel){ visualdevApi.saveState(stateModel); } //--------------------------------数据字典------------------------------ public List getDiList() { List dictionList = dictionaryDataService.getListByTypeDataCode(DictionaryDataEnum.FLOWWOEK_ENGINE.getDictionaryTypeId()); return dictionList; } public List getDictionName(List id) { List dictionList = dictionaryDataService.getDictionName(id); return dictionList; } //--------------------------------用户关系表------------------------------ public List getListByUserIdAll(List id) { List list = userRelationService.getListByUserIdAll(id).stream().filter(t -> StringUtil.isNotEmpty(t.getObjectId())).collect(Collectors.toList()); return list; } public List getListByObjectIdAll(List id) { List list = userRelationService.getListByObjectIdAll(id); return list; } //--------------------------------用户权限------------------------------ public List getAuthorizeObjectId(List objectIdList) { List list = authorizeService.getListByObjectId(objectIdList); return list; } public List getListByObjectAndItemIdAndType(String templateId) { List flowAuthList = authorizeService.getListByObjectAndItemIdAndType(templateId, AuthorizeConst.FLOW); return flowAuthList; } public AuthorizeVO getAuthorizeByUser() { AuthorizeVO authorize = authorizeService.getAuthorizeByUser(false); return authorize; } //--------------------------------用户------------------------------ public String getAdmin() { UserEntity admin = userApi.getUserByAccount(ADMIN_KEY); return admin.getId(); } public List getUserByAccount(List accountList) { List list = new ArrayList<>(); if (CollectionUtil.isEmpty(accountList)) { return list; } for (String account : accountList) { UserEntity user = userApi.getUserByAccount(account); if (null != user) { list.add(user); } } return list; } public List getUserName(List id) { List list = getUserName(id, false); return list; } public List getUserName(List id, boolean enableMark) { List list = userApi.getUserName(id); if (enableMark) list = list.stream().filter(t -> t.getEnabledMark() == 1).collect(Collectors.toList()); return list; } public List getUserName(List id, Pagination pagination) { List list = userApi.getUserName(id, pagination); return list; } public UserEntity getUserInfo(String id) { UserEntity entity = null; if (StringUtil.isNotEmpty(id)) { entity = id.equalsIgnoreCase(ADMIN_KEY) ? userApi.getUserByAccount(id) : userApi.getInfo(id); } return entity; } public List getUserListAll(List idList) { List userIdList = userApi.getUserIdList(idList); return userIdList; } //--------------------------------角色关系表------------------------------ public List getListByRoleId(List roleIdList) { List list = roleRelationService.getListByRoleId(roleIdList, PermissionConst.USER); return list; } public List getRoleObjectId(List userId) { List list = roleRelationService.getListByObjectId(userId, PermissionConst.USER); return list; } //--------------------------------角色------------------------------ public List getRoleList(List id) { return roleService.getListByIds(id); } //--------------------------------组织------------------------------ public OrganizeEntity getOrganizeInfo(String id) { OrganizeEntity entity = StringUtil.isNotEmpty(id) ? organizeService.getInfo(id) : null; return entity; } public List getDepartmentAll(String organizeId) { List departmentAll = organizeService.getDepartmentAll(organizeId); return departmentAll; } public List getOrganizeList(List idList) { List departmentAll = organizeService.getListByIds(idList); return departmentAll; } //--------------------------------岗位------------------------------ public PositionEntity getPositionInfo(String id) { PositionEntity entity = StringUtil.isNotEmpty(id) ? positionService.getInfo(id) : null; return entity; } public List getChildPosition(String id) { List list = StringUtil.isNotEmpty(id) ? positionService.getAllChild(id) : new ArrayList<>(); return list; } public List getListByOrgIds(List orgIds) { List list = positionService.getListByOrgIds(orgIds); return list; } public List getPosList(List idList) { List list = positionService.getListByIds(idList); return list; } //--------------------------------远端------------------------------ public ActionResult infoToId(String interId, Map parameterMap) { return dataInterfaceService.infoToId(interId, null, parameterMap); } public Map getSystemFieldValue() { Map paramDataMap = userApi.getSystemFieldValue(new SystemParamModel()); return paramDataMap; } //--------------------------------应用------------------------------ public String getSystemCodeById(String systemCode) { List systemIdList = ImmutableList.of(JnpfConst.MAIN_SYSTEM_CODE, JnpfConst.WORK_FLOW_CODE); String systemId = JnpfConst.MAIN_SYSTEM_CODE; if (StringUtil.isEmpty(systemCode)) { return systemId; } if (systemIdList.contains(systemCode)) { return ""; } SystemEntity entity = getInfoByEnCode(systemCode); if (entity != null) { systemId = entity.getId(); } return systemId; } public SystemEntity getInfoByEnCode(String systemCode) { SystemEntity entity = systemApi.getInfoByEnCode(systemCode); return entity; } public List getSystemList(List idList) { List list = systemApi.getListByIds(idList, new ArrayList<>()); return list; } //--------------------------------发送消息------------------------------ public void sendMessage(List messageListAll) { for (SentMessageForm messageForm : messageListAll) { if (messageForm.isSysMessage()) { sentMessageUtil.sendMessage(messageForm); } } } public List sendDelegateMsg(List messageListAll) { List list = new ArrayList<>(); for (SentMessageForm messageForm : messageListAll) { List errList = sentMessageUtil.sendDelegateMsg(messageForm); list.addAll(errList); } return list; } //------------------------------导出------------------------------- public DownloadVO exportData(TemplateExportModel model) { DownloadVO downloadVO = fileExport.exportFile(model, FileTypeConstant.TEMPORARY, model.getTemplate().getFullName(), ModuleTypeEnum.FLOW_FLOWENGINE.getTableName()); return downloadVO; } }