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.model.flow.FlowStateModel;
|
import jnpf.base.*;
|
import jnpf.base.entity.DictionaryDataEntity;
|
import jnpf.base.entity.SystemEntity;
|
import jnpf.base.entity.VisualdevEntity;
|
import jnpf.base.model.VisualDevJsonModel;
|
import jnpf.base.model.base.SystemApiByIdsModel;
|
import jnpf.base.model.flow.DataModel;
|
import jnpf.base.model.flow.FlowFormDataModel;
|
import jnpf.base.model.schedule.ScheduleNewCrForm;
|
import jnpf.base.model.systemconfig.SysConfigModel;
|
import jnpf.base.vo.DownloadVO;
|
import jnpf.config.ConfigValueUtil;
|
import jnpf.constant.*;
|
import jnpf.emnus.ModuleTypeEnum;
|
import jnpf.emnus.SysParamEnum;
|
import jnpf.exception.WorkFlowException;
|
import jnpf.file.DocumentApi;
|
import jnpf.file.FileApi;
|
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.SentMessageApi;
|
import jnpf.message.model.SentMessageForm;
|
import jnpf.model.ExportModel;
|
import jnpf.model.document.FlowFileModel;
|
import jnpf.onlinedev.VisualdevOnlineApi;
|
import jnpf.onlinedev.model.PaginationModel;
|
import jnpf.onlinedev.model.VisualParamModel;
|
import jnpf.permission.*;
|
import jnpf.permission.entity.*;
|
import jnpf.permission.model.SystemParamModel;
|
import jnpf.permission.model.authorize.AuthorizeVO;
|
import jnpf.permission.model.rolerelaiton.RoleRelationModel;
|
import jnpf.permission.model.sign.SignForm;
|
import jnpf.permission.model.user.UserModel;
|
import jnpf.util.StringUtil;
|
import jnpf.util.enums.DictionaryDataEnum;
|
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 DictionaryDataApi dictionaryDataService;
|
@Autowired
|
private UserRelationApi userRelationService;
|
@Autowired
|
private UserApi userApi;
|
@Autowired
|
private RoleApi roleService;
|
@Autowired
|
private RoleRelationApi roleRelationService;
|
@Autowired
|
private OrganizeApi organizeService;
|
@Autowired
|
private PositionApi positionService;
|
@Autowired
|
private CodeNumApi codeNumService;
|
@Autowired
|
private DataInterFaceApi dataInterfaceService;
|
@Autowired
|
private SentMessageApi sentMessageUtil;
|
@Autowired
|
private FileApi fileExport;
|
@Autowired
|
private ConfigValueUtil configValueUtil;
|
@Autowired
|
private UserSettingApi signService;
|
@Autowired
|
private AuthorizeApi authorizeService;
|
@Autowired
|
private VisualdevOnlineApi visualdevApi;
|
@Autowired
|
private DocumentApi documentApi;
|
@Autowired
|
private BillRuleApi billRuleService;
|
@Autowired
|
private SysConfigApi systemConfigApi;
|
@Autowired
|
private SystemApi 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).getData();
|
}
|
|
// -------------------------------签名-----------------------------
|
public void updateSign(String signId, String signImg) {
|
SignEntity signEntity = signService.getSignInfo(signId);
|
if (null != signEntity) {
|
signService.uptateDefault(signId);
|
} else {
|
SignForm signForm = new SignForm();
|
signForm.setIsDefault(1);
|
signForm.setSignImg(signImg);
|
signService.create(signForm);
|
}
|
}
|
|
// -------------------------------流程编码-----------------------------
|
public String getCode() {
|
return codeNumService.getCodeOnce(CodeConst.LC);
|
}
|
|
// -------------------------------常用语-----------------------------
|
public void addCommonWordsNum(String handleOpinion) {
|
systemApi.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) {
|
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) {
|
VisualParamModel visualParamModel = VisualParamModel.builder().visualDevJsonModel(visualDevJsonModel).pagination(pagination).userInfo(userInfo).build();
|
return visualdevApi.getListWithTableList(visualParamModel);
|
}
|
|
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();
|
ActionResult result = visualdevApi.visualCreate(visualParamModel);
|
if (null == result) {
|
throw new WorkFlowException(MsgCode.SYS122.getCode());
|
}
|
if (!ObjectUtil.equals(result.getCode(), 200)) {
|
throw new WorkFlowException(result.getMsg());
|
}
|
if (result.getData() instanceof DataModel) {
|
return (DataModel) result.getData();
|
}
|
return null;
|
}
|
|
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();
|
ActionResult result = visualdevApi.visualUpdate(visualParamModel);
|
if (null == result) {
|
throw new WorkFlowException(MsgCode.SYS122.get());
|
}
|
if (!ObjectUtil.equals(result.getCode(), 200)) {
|
throw new WorkFlowException(result.getMsg());
|
}
|
if (result.getData() instanceof DataModel) {
|
return (DataModel) result.getData();
|
}
|
return null;
|
}
|
|
public void visualDelete(VisualdevEntity visualdevEntity, List<Map<String, Object>> dataList) throws Exception {
|
VisualParamModel visualParamModel = VisualParamModel.builder().visualdevEntity(visualdevEntity).dataList(dataList).build();
|
ActionResult result = visualdevApi.visualDelete(visualParamModel);
|
if (null == result) {
|
throw new WorkFlowException(MsgCode.SYS122.get());
|
}
|
if (!ObjectUtil.equals(result.getCode(), 200)) {
|
throw new WorkFlowException(result.getMsg());
|
}
|
}
|
|
public void deleteSubTable(FlowFormDataModel model) throws Exception {
|
ActionResult result = visualdevApi.deleteByTableName(model);
|
if (null == result) {
|
throw new WorkFlowException(MsgCode.SYS122.get());
|
}
|
if (!ObjectUtil.equals(result.getCode(), 200)) {
|
throw new WorkFlowException(result.getMsg());
|
}
|
}
|
|
public void saveState(FlowStateModel stateModel){
|
visualdevApi.saveState(stateModel);
|
}
|
|
//--------------------------------数据字典------------------------------
|
public List<DictionaryDataEntity> getDiList() {
|
ActionResult<List<DictionaryDataEntity>> result = dictionaryDataService.getListByTypeDataCode(DictionaryDataEnum.FLOWWOEK_ENGINE.getDictionaryTypeId());
|
List<DictionaryDataEntity> dictionList = new ArrayList<>();
|
if (result.getData() != null) {
|
dictionList.addAll(result.getData());
|
}
|
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.getInfoByAccount(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.getInfoByAccount(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) {
|
UserModel userModel = new UserModel();
|
userModel.setId(id);
|
userModel.setPagination(pagination);
|
List<UserEntity> list = userApi.getUserNamePagination(userModel);
|
return list;
|
}
|
|
public UserEntity getUserInfo(String id) {
|
UserEntity entity = null;
|
if (StringUtil.isNotEmpty(id)) {
|
entity = id.equalsIgnoreCase(ADMIN_KEY) ? userApi.getInfoByAccount(id) : userApi.getInfoById(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(new RoleRelationModel(new ArrayList<>(), PermissionConst.USER, roleIdList));
|
return list;
|
}
|
|
public List<RoleRelationEntity> getRoleObjectId(List<String> userId) {
|
List<RoleRelationEntity> list = roleRelationService.getListByObjectId(new RoleRelationModel(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.getInfoById(id) : null;
|
return entity;
|
}
|
|
public List<OrganizeEntity> getDepartmentAll(String organizeId) {
|
List<OrganizeEntity> departmentAll = organizeService.getOrganizeDepartmentAll(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.queryInfoById(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.infoToIdById(interId, 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) {
|
SystemApiByIdsModel model = new SystemApiByIdsModel(idList, new ArrayList<>(), 0);
|
List<SystemEntity> list = systemApi.getListByIds(model);
|
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.sendScheduleMessage(messageForm);
|
list.addAll(errList);
|
}
|
return list;
|
}
|
|
//------------------------------导出-------------------------------
|
public DownloadVO exportData(TemplateExportModel model) {
|
DownloadVO downloadVO = fileExport.exportFile(new ExportModel(model, FileTypeConstant.TEMPORARY,
|
configValueUtil.getTemporaryFilePath(), model.getTemplate().getFullName(), ModuleTypeEnum.FLOW_FLOWENGINE.getTableName()));
|
return downloadVO;
|
}
|
}
|