| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512 |
- 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<SysConfigModel> actionResult = systemConfigApi.list();
- return actionResult.getData();
- }
- // 获取系统配置,流程签收
- public Boolean getFlowSign() {
- ActionResult<SysConfigModel> actionResult = systemConfigApi.list();
- SysConfigModel data = actionResult.getData();
- return data.getFlowSign() == 0;
- }
- // 获取系统配置,流程办理
- public Boolean getFlowTodo() {
- ActionResult<SysConfigModel> 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<Map<String, Object>> getFlowFile(FlowFileModel model) {
- return documentApi.getFlowFile(model);
- }
- // -------------------------------流程全部权限-----------------------------
- public List<String> getPermission(String userId) {
- return getPermission(userId, AuthorizeConst.FLOW);
- }
- public List<String> getPermission(String userId, String itmeType) {
- List<String> userIdList = ImmutableList.of(userId);
- List<String> objectIdList = new ArrayList<>();
- List<String> posId = getListByUserIdAll(userIdList).stream().filter(e -> Objects.equals(PermissionConst.POSITION, e.getObjectType())).map(UserRelationEntity::getObjectId).collect(Collectors.toList());
- objectIdList.addAll(posId);
- List<String> roleId = getRoleObjectId(userIdList).stream().map(RoleRelationEntity::getRoleId).collect(Collectors.toList());
- objectIdList.addAll(roleId);
- List<String> 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<String> getLaunchPermission() {
- AuthorizeVO authorizeByUser = getAuthorizeByUser();
- List<String> 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<UserEntity> getLaunchUserByTemplateId(TemplateEntity template, Pagination pagination) {
- if (ObjectUtil.equals(template.getVisibleType(), FlowNature.All)) {
- // 公开直接返回用户分页
- return userApi.getUserPage(pagination);
- }
- // 根据流程主键、权限为流程类型 获取权限关联
- List<String> userIdList = new ArrayList<>();
- List<AuthorizeEntity> 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<String> userListAll = this.getUserListAll(userIdList);
- return this.getUserName(userListAll, pagination);
- }
- //--------------------------------表单------------------------------
- public VisualdevEntity getFormInfo(String id) {
- return visualdevApi.getFormConfig(id);
- }
- public List<VisualdevEntity> getFormList(List<String> 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<String, Object> infoData(String formId, String id) throws WorkFlowException {
- // 流程调用表单接口
- Map<String, Object> dataAll = new HashMap<>();
- if (StringUtil.isNotEmpty(formId) && StringUtil.isNotEmpty(id)) {
- ActionResult result = visualdevApi.info(formId, id);
- if (null != result && null != result.getData()) {
- dataAll = (Map<String, Object>) result.getData();
- }
- }
- return dataAll;
- }
- public void handleFormData(String flowId, Boolean isTransfer) throws WorkFlowException {
- try {
- Map<String, Map<String, Object>> allData = FlowContextHolder.getAllData();
- Map<String, List<Map<String, Object>>> formOperates = FlowContextHolder.getFormOperates();
- List<String> writeIdList = FlowContextHolder.getWriteIdList();
- for (String key : writeIdList) {
- String[] idList = key.split(JnpfConst.SIDE_MARK);
- List<Map<String, Object>> operates = formOperates.get(key);
- Map<String, Object> 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<Map<String, Object>> 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<String, Object> data) throws Exception {
- VisualParamModel visualParamModel = VisualParamModel.builder().visualdevEntity(visualdevEntity).data(data).build();
- return visualdevApi.visualCreate(visualParamModel);
- }
- public DataModel visualUpdate(VisualdevEntity visualdevEntity, Map<String, Object> 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<Map<String, Object>> 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<DictionaryDataEntity> getDiList() {
- List<DictionaryDataEntity> dictionList = dictionaryDataService.getListByTypeDataCode(DictionaryDataEnum.FLOWWOEK_ENGINE.getDictionaryTypeId());
- return dictionList;
- }
- public List<DictionaryDataEntity> getDictionName(List<String> id) {
- List<DictionaryDataEntity> dictionList = dictionaryDataService.getDictionName(id);
- return dictionList;
- }
- //--------------------------------用户关系表------------------------------
- public List<UserRelationEntity> getListByUserIdAll(List<String> id) {
- List<UserRelationEntity> list = userRelationService.getListByUserIdAll(id).stream().filter(t -> StringUtil.isNotEmpty(t.getObjectId())).collect(Collectors.toList());
- return list;
- }
- public List<UserRelationEntity> getListByObjectIdAll(List<String> id) {
- List<UserRelationEntity> list = userRelationService.getListByObjectIdAll(id);
- return list;
- }
- //--------------------------------用户权限------------------------------
- public List<AuthorizeEntity> getAuthorizeObjectId(List<String> objectIdList) {
- List<AuthorizeEntity> list = authorizeService.getListByObjectId(objectIdList);
- return list;
- }
- public List<AuthorizeEntity> getListByObjectAndItemIdAndType(String templateId) {
- List<AuthorizeEntity> 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<UserEntity> getUserByAccount(List<String> accountList) {
- List<UserEntity> 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<UserEntity> getUserName(List<String> id) {
- List<UserEntity> list = getUserName(id, false);
- return list;
- }
- public List<UserEntity> getUserName(List<String> id, boolean enableMark) {
- List<UserEntity> list = userApi.getUserName(id);
- if (enableMark) list = list.stream().filter(t -> t.getEnabledMark() == 1).collect(Collectors.toList());
- return list;
- }
- public List<UserEntity> getUserName(List<String> id, Pagination pagination) {
- List<UserEntity> 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<String> getUserListAll(List<String> idList) {
- List<String> userIdList = userApi.getUserIdList(idList);
- return userIdList;
- }
- //--------------------------------角色关系表------------------------------
- public List<RoleRelationEntity> getListByRoleId(List<String> roleIdList) {
- List<RoleRelationEntity> list = roleRelationService.getListByRoleId(roleIdList, PermissionConst.USER);
- return list;
- }
- public List<RoleRelationEntity> getRoleObjectId(List<String> userId) {
- List<RoleRelationEntity> list = roleRelationService.getListByObjectId(userId, PermissionConst.USER);
- return list;
- }
- //--------------------------------角色------------------------------
- public List<RoleEntity> getRoleList(List<String> id) {
- return roleService.getListByIds(id);
- }
- //--------------------------------组织------------------------------
- public OrganizeEntity getOrganizeInfo(String id) {
- OrganizeEntity entity = StringUtil.isNotEmpty(id) ? organizeService.getInfo(id) : null;
- return entity;
- }
- public List<OrganizeEntity> getDepartmentAll(String organizeId) {
- List<OrganizeEntity> departmentAll = organizeService.getDepartmentAll(organizeId);
- return departmentAll;
- }
- public List<OrganizeEntity> getOrganizeList(List<String> idList) {
- List<OrganizeEntity> departmentAll = organizeService.getListByIds(idList);
- return departmentAll;
- }
- //--------------------------------岗位------------------------------
- public PositionEntity getPositionInfo(String id) {
- PositionEntity entity = StringUtil.isNotEmpty(id) ? positionService.getInfo(id) : null;
- return entity;
- }
- public List<PositionEntity> getChildPosition(String id) {
- List<PositionEntity> list = StringUtil.isNotEmpty(id) ? positionService.getAllChild(id) : new ArrayList<>();
- return list;
- }
- public List<PositionEntity> getListByOrgIds(List<String> orgIds) {
- List<PositionEntity> list = positionService.getListByOrgIds(orgIds);
- return list;
- }
- public List<PositionEntity> getPosList(List<String> idList) {
- List<PositionEntity> list = positionService.getListByIds(idList);
- return list;
- }
- //--------------------------------远端------------------------------
- public ActionResult infoToId(String interId, Map<String, String> parameterMap) {
- return dataInterfaceService.infoToId(interId, null, parameterMap);
- }
- public Map<String, String> getSystemFieldValue() {
- Map<String, String> paramDataMap = userApi.getSystemFieldValue(new SystemParamModel());
- return paramDataMap;
- }
- //--------------------------------应用------------------------------
- public String getSystemCodeById(String systemCode) {
- List<String> 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<SystemEntity> getSystemList(List<String> idList) {
- List<SystemEntity> list = systemApi.getListByIds(idList, new ArrayList<>());
- return list;
- }
- //--------------------------------发送消息------------------------------
- public void sendMessage(List<SentMessageForm> messageListAll) {
- for (SentMessageForm messageForm : messageListAll) {
- if (messageForm.isSysMessage()) {
- sentMessageUtil.sendMessage(messageForm);
- }
- }
- }
- public List<String> sendDelegateMsg(List<SentMessageForm> messageListAll) {
- List<String> list = new ArrayList<>();
- for (SentMessageForm messageForm : messageListAll) {
- List<String> 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;
- }
- }
|