ServiceUtil.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. package jnpf.flowable.util;
  2. import cn.hutool.core.collection.CollectionUtil;
  3. import cn.hutool.core.util.ObjectUtil;
  4. import com.google.common.collect.ImmutableList;
  5. import jnpf.base.ActionResult;
  6. import jnpf.base.Pagination;
  7. import jnpf.base.UserInfo;
  8. import jnpf.base.entity.DictionaryDataEntity;
  9. import jnpf.base.entity.SystemEntity;
  10. import jnpf.base.entity.VisualdevEntity;
  11. import jnpf.base.model.VisualDevJsonModel;
  12. import jnpf.base.model.flow.DataModel;
  13. import jnpf.base.model.flow.FlowFormDataModel;
  14. import jnpf.base.model.flow.FlowStateModel;
  15. import jnpf.base.model.schedule.ScheduleNewCrForm;
  16. import jnpf.base.model.systemconfig.SysConfigModel;
  17. import jnpf.base.service.*;
  18. import jnpf.base.util.SentMessageUtil;
  19. import jnpf.base.vo.DownloadVO;
  20. import jnpf.constant.*;
  21. import jnpf.emnus.ModuleTypeEnum;
  22. import jnpf.emnus.SysParamEnum;
  23. import jnpf.exception.WorkFlowException;
  24. import jnpf.extend.service.DocumentApi;
  25. import jnpf.flowable.entity.TemplateEntity;
  26. import jnpf.flowable.model.template.TemplateExportModel;
  27. import jnpf.flowable.model.util.FlowContextHolder;
  28. import jnpf.flowable.model.util.FlowNature;
  29. import jnpf.message.model.SentMessageForm;
  30. import jnpf.model.SystemParamModel;
  31. import jnpf.model.document.FlowFileModel;
  32. import jnpf.onlinedev.model.PaginationModel;
  33. import jnpf.onlinedev.model.VisualParamModel;
  34. import jnpf.permission.entity.*;
  35. import jnpf.permission.model.authorize.AuthorizeVO;
  36. import jnpf.permission.service.*;
  37. import jnpf.util.DataFileExport;
  38. import jnpf.util.StringUtil;
  39. import jnpf.util.enums.DictionaryDataEnum;
  40. import jnpf.visual.service.VisualdevApi;
  41. import org.springframework.beans.factory.annotation.Autowired;
  42. import org.springframework.stereotype.Component;
  43. import java.util.*;
  44. import java.util.stream.Collectors;
  45. import static jnpf.util.Constants.ADMIN_KEY;
  46. @Component
  47. public class ServiceUtil {
  48. @Autowired
  49. private DictionaryDataService dictionaryDataService;
  50. @Autowired
  51. private UserRelationService userRelationService;
  52. @Autowired
  53. private UserService userApi;
  54. @Autowired
  55. private RoleService roleService;
  56. @Autowired
  57. private RoleRelationService roleRelationService;
  58. @Autowired
  59. private OrganizeService organizeService;
  60. @Autowired
  61. private PositionService positionService;
  62. @Autowired
  63. private CodeNumService codeNumService;
  64. @Autowired
  65. private DataInterfaceService dataInterfaceService;
  66. @Autowired
  67. private SentMessageUtil sentMessageUtil;
  68. @Autowired
  69. private DataFileExport fileExport;
  70. @Autowired
  71. private CommonWordsService commonWordsService;
  72. @Autowired
  73. private SignService signService;
  74. @Autowired
  75. private AuthorizeService authorizeService;
  76. @Autowired
  77. private VisualdevApi visualdevApi;
  78. @Autowired
  79. private DocumentApi documentApi;
  80. @Autowired
  81. private BillRuleService billRuleService;
  82. @Autowired
  83. private SystemConfigApi systemConfigApi;
  84. @Autowired
  85. private SystemService systemApi;
  86. @Autowired
  87. private ScheduleNewApi scheduleNewApi;
  88. // 创建日程
  89. public void createSchedule(ScheduleNewCrForm fo) throws WorkFlowException {
  90. ActionResult result = scheduleNewApi.create(fo);
  91. if (result.getCode() != 200) {
  92. throw new WorkFlowException(result.getMsg());
  93. }
  94. }
  95. // 获取系统配置
  96. public SysConfigModel getSysConfig() {
  97. ActionResult<SysConfigModel> actionResult = systemConfigApi.list();
  98. return actionResult.getData();
  99. }
  100. // 获取系统配置,流程签收
  101. public Boolean getFlowSign() {
  102. ActionResult<SysConfigModel> actionResult = systemConfigApi.list();
  103. SysConfigModel data = actionResult.getData();
  104. return data.getFlowSign() == 0;
  105. }
  106. // 获取系统配置,流程办理
  107. public Boolean getFlowTodo() {
  108. ActionResult<SysConfigModel> actionResult = systemConfigApi.list();
  109. SysConfigModel data = actionResult.getData();
  110. return data.getFlowTodo() == 0;
  111. }
  112. // 流水号
  113. public String getBillNumber() {
  114. return billRuleService.getBillNumber(FlowNature.REVOKE_BILL_CODE, false);
  115. }
  116. // -------------------------------签名-----------------------------
  117. public void updateSign(String signId, String signImg) {
  118. SignEntity signEntity = signService.getById(signId);
  119. if (null != signEntity) {
  120. signService.updateDefault(signId);
  121. } else {
  122. signEntity = new SignEntity();
  123. signEntity.setIsDefault(1);
  124. signEntity.setSignImg(signImg);
  125. signService.create(signEntity);
  126. }
  127. }
  128. // -------------------------------流程编码-----------------------------
  129. public String getCode() {
  130. return codeNumService.getCodeOnce(CodeConst.LC);
  131. }
  132. // -------------------------------常用语-----------------------------
  133. public void addCommonWordsNum(String handleOpinion) {
  134. commonWordsService.addCommonWordsNum(handleOpinion);
  135. }
  136. // -------------------------------文件-----------------------------
  137. // 判断是否存在归档文件,不存在为true
  138. public Boolean checkFlowFile(String taskId) {
  139. return documentApi.checkFlowFile(taskId);
  140. }
  141. // 获取归档文件
  142. public List<Map<String, Object>> getFlowFile(FlowFileModel model) {
  143. return documentApi.getFlowFile(model);
  144. }
  145. // -------------------------------流程全部权限-----------------------------
  146. public List<String> getPermission(String userId) {
  147. return getPermission(userId, AuthorizeConst.FLOW);
  148. }
  149. public List<String> getPermission(String userId, String itmeType) {
  150. List<String> userIdList = ImmutableList.of(userId);
  151. List<String> objectIdList = new ArrayList<>();
  152. List<String> posId = getListByUserIdAll(userIdList).stream().filter(e -> Objects.equals(PermissionConst.POSITION, e.getObjectType())).map(UserRelationEntity::getObjectId).collect(Collectors.toList());
  153. objectIdList.addAll(posId);
  154. List<String> roleId = getRoleObjectId(userIdList).stream().map(RoleRelationEntity::getRoleId).collect(Collectors.toList());
  155. objectIdList.addAll(roleId);
  156. List<String> resList = new ArrayList<>();
  157. if (!objectIdList.isEmpty()) {
  158. resList = getAuthorizeObjectId(objectIdList).stream().filter(e -> e.getItemType().equals(itmeType)).map(AuthorizeEntity::getItemId).collect(Collectors.toList());
  159. }
  160. return resList;
  161. }
  162. // -------------------------------发起权限-----------------------------
  163. public List<String> getLaunchPermission() {
  164. AuthorizeVO authorizeByUser = getAuthorizeByUser();
  165. List<String> flowIdList = authorizeByUser.getFlowIdList();
  166. return flowIdList;
  167. }
  168. // true是普通用户
  169. public boolean isCommonUser(String userId) {
  170. UserEntity userInfo = getUserInfo(userId);
  171. return userInfo == null || !Objects.equals(userInfo.getAccount(), ADMIN_KEY);
  172. }
  173. // 获取流程有发起权限的人员
  174. public List<UserEntity> getLaunchUserByTemplateId(TemplateEntity template, Pagination pagination) {
  175. if (ObjectUtil.equals(template.getVisibleType(), FlowNature.All)) {
  176. // 公开直接返回用户分页
  177. return userApi.getUserPage(pagination);
  178. }
  179. // 根据流程主键、权限为流程类型 获取权限关联
  180. List<String> userIdList = new ArrayList<>();
  181. List<AuthorizeEntity> authorizeList = getListByObjectAndItemIdAndType(template.getId()).stream().filter(e -> !Objects.equals(PermissionConst.ORGANIZE, e.getObjectType())).collect(Collectors.toList());
  182. for (AuthorizeEntity entity : authorizeList) {
  183. String objectType = PermissionConst.POSITION.equals(entity.getObjectType()) ? SysParamEnum.POS.getCode() : SysParamEnum.ROLE.getCode();
  184. userIdList.add(entity.getObjectId() + "--" + objectType);
  185. }
  186. List<String> userListAll = this.getUserListAll(userIdList);
  187. return this.getUserName(userListAll, pagination);
  188. }
  189. //--------------------------------表单------------------------------
  190. public VisualdevEntity getFormInfo(String id) {
  191. return visualdevApi.getFormConfig(id);
  192. }
  193. public List<VisualdevEntity> getFormList(List<String> formIds) {
  194. if (formIds.isEmpty()) {
  195. return new ArrayList<>();
  196. }
  197. return visualdevApi.getFormConfigList(formIds);
  198. }
  199. public void saveOrUpdateFormData(FlowFormDataModel model) throws WorkFlowException {
  200. ActionResult actionResult = visualdevApi.saveOrUpdate(model);
  201. if (actionResult.getCode() != 200) {
  202. throw new WorkFlowException(actionResult.getMsg());
  203. }
  204. }
  205. public void deleteFormData(String formId, String id) throws Exception {
  206. if (StringUtil.isBlank(formId) || StringUtil.isBlank(id)) {
  207. return;
  208. }
  209. try {
  210. visualdevApi.delete(formId, id);
  211. } catch (Exception e) {
  212. e.printStackTrace();
  213. }
  214. }
  215. public Map<String, Object> infoData(String formId, String id) throws WorkFlowException {
  216. // 流程调用表单接口
  217. Map<String, Object> dataAll = new HashMap<>();
  218. if (StringUtil.isNotEmpty(formId) && StringUtil.isNotEmpty(id)) {
  219. ActionResult result = visualdevApi.info(formId, id);
  220. if (null != result && null != result.getData()) {
  221. dataAll = (Map<String, Object>) result.getData();
  222. }
  223. }
  224. return dataAll;
  225. }
  226. public void handleFormData(String flowId, Boolean isTransfer) throws WorkFlowException {
  227. try {
  228. Map<String, Map<String, Object>> allData = FlowContextHolder.getAllData();
  229. Map<String, List<Map<String, Object>>> formOperates = FlowContextHolder.getFormOperates();
  230. List<String> writeIdList = FlowContextHolder.getWriteIdList();
  231. for (String key : writeIdList) {
  232. String[] idList = key.split(JnpfConst.SIDE_MARK);
  233. List<Map<String, Object>> operates = formOperates.get(key);
  234. Map<String, Object> formData = allData.get(key);
  235. formData = formData == null ? new HashMap<>() : formData;
  236. FlowFormDataModel formDataModel = FlowFormDataModel.builder().formId(idList[1]).id(idList[0]).map(formData).formOperates(operates)
  237. .flowId(flowId).isTransfer(isTransfer).build();
  238. this.saveOrUpdateFormData(formDataModel);
  239. }
  240. } catch (WorkFlowException e) {
  241. throw e;
  242. } finally {
  243. FlowContextHolder.clearAll();
  244. }
  245. }
  246. public List<Map<String, Object>> getListWithTableList(VisualDevJsonModel visualDevJsonModel, PaginationModel pagination, UserInfo userInfo) {
  247. return visualdevApi.getListWithTableList(visualDevJsonModel, pagination, userInfo);
  248. }
  249. public VisualdevEntity getReleaseInfo(String formId) {
  250. return visualdevApi.getReleaseInfo(formId);
  251. }
  252. public DataModel visualCreate(VisualdevEntity visualdevEntity, Map<String, Object> data) throws Exception {
  253. VisualParamModel visualParamModel = VisualParamModel.builder().visualdevEntity(visualdevEntity).data(data).build();
  254. return visualdevApi.visualCreate(visualParamModel);
  255. }
  256. public DataModel visualUpdate(VisualdevEntity visualdevEntity, Map<String, Object> data, String id) throws Exception {
  257. VisualParamModel visualParamModel = VisualParamModel.builder().visualdevEntity(visualdevEntity).data(data).id(id).onlyUpdate(true).build();
  258. return visualdevApi.visualUpdate(visualParamModel);
  259. }
  260. public void visualDelete(VisualdevEntity visualdevEntity, List<Map<String, Object>> dataList) throws Exception {
  261. VisualParamModel visualParamModel = VisualParamModel.builder().visualdevEntity(visualdevEntity).dataList(dataList).build();
  262. visualdevApi.visualDelete(visualParamModel);
  263. }
  264. public void deleteSubTable(FlowFormDataModel model) throws Exception {
  265. visualdevApi.deleteByTableName(model);
  266. }
  267. public void saveState(FlowStateModel stateModel){
  268. visualdevApi.saveState(stateModel);
  269. }
  270. //--------------------------------数据字典------------------------------
  271. public List<DictionaryDataEntity> getDiList() {
  272. List<DictionaryDataEntity> dictionList = dictionaryDataService.getListByTypeDataCode(DictionaryDataEnum.FLOWWOEK_ENGINE.getDictionaryTypeId());
  273. return dictionList;
  274. }
  275. public List<DictionaryDataEntity> getDictionName(List<String> id) {
  276. List<DictionaryDataEntity> dictionList = dictionaryDataService.getDictionName(id);
  277. return dictionList;
  278. }
  279. //--------------------------------用户关系表------------------------------
  280. public List<UserRelationEntity> getListByUserIdAll(List<String> id) {
  281. List<UserRelationEntity> list = userRelationService.getListByUserIdAll(id).stream().filter(t -> StringUtil.isNotEmpty(t.getObjectId())).collect(Collectors.toList());
  282. return list;
  283. }
  284. public List<UserRelationEntity> getListByObjectIdAll(List<String> id) {
  285. List<UserRelationEntity> list = userRelationService.getListByObjectIdAll(id);
  286. return list;
  287. }
  288. //--------------------------------用户权限------------------------------
  289. public List<AuthorizeEntity> getAuthorizeObjectId(List<String> objectIdList) {
  290. List<AuthorizeEntity> list = authorizeService.getListByObjectId(objectIdList);
  291. return list;
  292. }
  293. public List<AuthorizeEntity> getListByObjectAndItemIdAndType(String templateId) {
  294. List<AuthorizeEntity> flowAuthList = authorizeService.getListByObjectAndItemIdAndType(templateId, AuthorizeConst.FLOW);
  295. return flowAuthList;
  296. }
  297. public AuthorizeVO getAuthorizeByUser() {
  298. AuthorizeVO authorize = authorizeService.getAuthorizeByUser(false);
  299. return authorize;
  300. }
  301. //--------------------------------用户------------------------------
  302. public String getAdmin() {
  303. UserEntity admin = userApi.getUserByAccount(ADMIN_KEY);
  304. return admin.getId();
  305. }
  306. public List<UserEntity> getUserByAccount(List<String> accountList) {
  307. List<UserEntity> list = new ArrayList<>();
  308. if (CollectionUtil.isEmpty(accountList)) {
  309. return list;
  310. }
  311. for (String account : accountList) {
  312. UserEntity user = userApi.getUserByAccount(account);
  313. if (null != user) {
  314. list.add(user);
  315. }
  316. }
  317. return list;
  318. }
  319. public List<UserEntity> getUserName(List<String> id) {
  320. List<UserEntity> list = getUserName(id, false);
  321. return list;
  322. }
  323. public List<UserEntity> getUserName(List<String> id, boolean enableMark) {
  324. List<UserEntity> list = userApi.getUserName(id);
  325. if (enableMark) list = list.stream().filter(t -> t.getEnabledMark() == 1).collect(Collectors.toList());
  326. return list;
  327. }
  328. public List<UserEntity> getUserName(List<String> id, Pagination pagination) {
  329. List<UserEntity> list = userApi.getUserName(id, pagination);
  330. return list;
  331. }
  332. public UserEntity getUserInfo(String id) {
  333. UserEntity entity = null;
  334. if (StringUtil.isNotEmpty(id)) {
  335. entity = id.equalsIgnoreCase(ADMIN_KEY) ? userApi.getUserByAccount(id) : userApi.getInfo(id);
  336. }
  337. return entity;
  338. }
  339. public List<String> getUserListAll(List<String> idList) {
  340. List<String> userIdList = userApi.getUserIdList(idList);
  341. return userIdList;
  342. }
  343. //--------------------------------角色关系表------------------------------
  344. public List<RoleRelationEntity> getListByRoleId(List<String> roleIdList) {
  345. List<RoleRelationEntity> list = roleRelationService.getListByRoleId(roleIdList, PermissionConst.USER);
  346. return list;
  347. }
  348. public List<RoleRelationEntity> getRoleObjectId(List<String> userId) {
  349. List<RoleRelationEntity> list = roleRelationService.getListByObjectId(userId, PermissionConst.USER);
  350. return list;
  351. }
  352. //--------------------------------角色------------------------------
  353. public List<RoleEntity> getRoleList(List<String> id) {
  354. return roleService.getListByIds(id);
  355. }
  356. //--------------------------------组织------------------------------
  357. public OrganizeEntity getOrganizeInfo(String id) {
  358. OrganizeEntity entity = StringUtil.isNotEmpty(id) ? organizeService.getInfo(id) : null;
  359. return entity;
  360. }
  361. public List<OrganizeEntity> getDepartmentAll(String organizeId) {
  362. List<OrganizeEntity> departmentAll = organizeService.getDepartmentAll(organizeId);
  363. return departmentAll;
  364. }
  365. public List<OrganizeEntity> getOrganizeList(List<String> idList) {
  366. List<OrganizeEntity> departmentAll = organizeService.getListByIds(idList);
  367. return departmentAll;
  368. }
  369. //--------------------------------岗位------------------------------
  370. public PositionEntity getPositionInfo(String id) {
  371. PositionEntity entity = StringUtil.isNotEmpty(id) ? positionService.getInfo(id) : null;
  372. return entity;
  373. }
  374. public List<PositionEntity> getChildPosition(String id) {
  375. List<PositionEntity> list = StringUtil.isNotEmpty(id) ? positionService.getAllChild(id) : new ArrayList<>();
  376. return list;
  377. }
  378. public List<PositionEntity> getListByOrgIds(List<String> orgIds) {
  379. List<PositionEntity> list = positionService.getListByOrgIds(orgIds);
  380. return list;
  381. }
  382. public List<PositionEntity> getPosList(List<String> idList) {
  383. List<PositionEntity> list = positionService.getListByIds(idList);
  384. return list;
  385. }
  386. //--------------------------------远端------------------------------
  387. public ActionResult infoToId(String interId, Map<String, String> parameterMap) {
  388. return dataInterfaceService.infoToId(interId, null, parameterMap);
  389. }
  390. public Map<String, String> getSystemFieldValue() {
  391. Map<String, String> paramDataMap = userApi.getSystemFieldValue(new SystemParamModel());
  392. return paramDataMap;
  393. }
  394. //--------------------------------应用------------------------------
  395. public String getSystemCodeById(String systemCode) {
  396. List<String> systemIdList = ImmutableList.of(JnpfConst.MAIN_SYSTEM_CODE, JnpfConst.WORK_FLOW_CODE);
  397. String systemId = JnpfConst.MAIN_SYSTEM_CODE;
  398. if (StringUtil.isEmpty(systemCode)) {
  399. return systemId;
  400. }
  401. if (systemIdList.contains(systemCode)) {
  402. return "";
  403. }
  404. SystemEntity entity = getInfoByEnCode(systemCode);
  405. if (entity != null) {
  406. systemId = entity.getId();
  407. }
  408. return systemId;
  409. }
  410. public SystemEntity getInfoByEnCode(String systemCode) {
  411. SystemEntity entity = systemApi.getInfoByEnCode(systemCode);
  412. return entity;
  413. }
  414. public List<SystemEntity> getSystemList(List<String> idList) {
  415. List<SystemEntity> list = systemApi.getListByIds(idList, new ArrayList<>());
  416. return list;
  417. }
  418. //--------------------------------发送消息------------------------------
  419. public void sendMessage(List<SentMessageForm> messageListAll) {
  420. for (SentMessageForm messageForm : messageListAll) {
  421. if (messageForm.isSysMessage()) {
  422. sentMessageUtil.sendMessage(messageForm);
  423. }
  424. }
  425. }
  426. public List<String> sendDelegateMsg(List<SentMessageForm> messageListAll) {
  427. List<String> list = new ArrayList<>();
  428. for (SentMessageForm messageForm : messageListAll) {
  429. List<String> errList = sentMessageUtil.sendDelegateMsg(messageForm);
  430. list.addAll(errList);
  431. }
  432. return list;
  433. }
  434. //------------------------------导出-------------------------------
  435. public DownloadVO exportData(TemplateExportModel model) {
  436. DownloadVO downloadVO = fileExport.exportFile(model, FileTypeConstant.TEMPORARY, model.getTemplate().getFullName(), ModuleTypeEnum.FLOW_FLOWENGINE.getTableName());
  437. return downloadVO;
  438. }
  439. }