ApplyPaymentSettleService.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. package com.idea.oa.apply.service;
  2. import cn.hutool.core.codec.Base64;
  3. import cn.hutool.crypto.SecureUtil;
  4. import cn.hutool.crypto.symmetric.AES;
  5. import com.github.pagehelper.PageHelper;
  6. import com.github.pagehelper.PageInfo;
  7. import com.idea.oa.apply.mapper.ApplyPaymentSettleExtendMapper;
  8. import com.idea.oa.apply.mapper.ApplyPaymentSettleMapper;
  9. import com.idea.oa.apply.model.ApplyPaymentSettle;
  10. import com.idea.oa.apply.model.ApplyPaymentSettleExample;
  11. import com.idea.oa.apply.model.inout.ApplyPaymentSettleIn;
  12. import com.idea.oa.apply.util.constant.ConstantFlowType;
  13. import com.idea.oa.apply.util.constant.RedisToUse;
  14. import com.idea.oa.flow2.model.FlowMain;
  15. import com.idea.oa.flow2.model.FlowMainExample;
  16. import com.idea.oa.flow2.model.FlowMainPush;
  17. import com.idea.oa.flow2.model.FlowMainPushExample;
  18. import com.idea.oa.flow2.service.FlowMainPushService;
  19. import com.idea.oa.flow2.service.FlowMainService;
  20. import com.idea.util.DateUtils;
  21. import com.idea.util.OAUtil;
  22. import com.idea.workPanel.enume.HandleTypeEnum;
  23. import com.idea.workPanel.service.ParkWaitHandleService;
  24. import com.rockstar.common.base.BaseService;
  25. import com.rockstar.common.support.Convert;
  26. import com.rockstar.frame.model.FramePermission;
  27. import com.rockstar.frame.model.FramePermissionExample;
  28. import com.rockstar.frame.model.FrameUser;
  29. import com.rockstar.frame.model.extend.DateTrans;
  30. import com.rockstar.frame.model.extend.Tablepar;
  31. import com.rockstar.frame.service.FramePermissionService;
  32. import com.rockstar.frame.service.FrameUserService;
  33. import com.rockstar.shiro.util.ShiroUtils;
  34. import com.rockstar.util.UUIDUtils;
  35. import lombok.extern.slf4j.Slf4j;
  36. import org.apache.commons.collections.CollectionUtils;
  37. import org.springframework.beans.factory.annotation.Autowired;
  38. import org.springframework.beans.factory.annotation.Value;
  39. import org.springframework.stereotype.Service;
  40. import org.springframework.util.StringUtils;
  41. import java.text.SimpleDateFormat;
  42. import java.util.Date;
  43. import java.util.HashMap;
  44. import java.util.List;
  45. import java.util.Map;
  46. @Slf4j
  47. @Service
  48. public class ApplyPaymentSettleService implements BaseService<ApplyPaymentSettle, ApplyPaymentSettleExample> {
  49. //文件mapper
  50. @Autowired
  51. private ApplyPaymentSettleMapper modelMapper;
  52. @Autowired
  53. private ApplyPaymentSettleExtendMapper ApplyPaymentSettleExtendMapper;
  54. @Autowired
  55. private FlowMainPushService flowMainPushService;
  56. @Autowired
  57. private FlowMainService flowMainService;
  58. @Autowired
  59. private ParkWaitHandleService parkWaitHandleService;
  60. @Autowired
  61. private FramePermissionService framePermissionService;
  62. @Autowired
  63. private FrameUserService frameUserService;
  64. @Value("${serverUrl}")
  65. private String serverUrl;
  66. @Value("${ssoKey}")
  67. private String ssoKey;
  68. /**
  69. * 分页查询
  70. *
  71. * @return
  72. */
  73. public PageInfo<ApplyPaymentSettle> list(Tablepar tablepar, ApplyPaymentSettle model, DateTrans dt) {
  74. PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
  75. List<ApplyPaymentSettle> list = null;//modelMapper.selectByExample(getCondition(model,dt));
  76. PageInfo<ApplyPaymentSettle> pageInfo = new PageInfo<>(list);
  77. return pageInfo;
  78. }
  79. public Object listAll(ApplyPaymentSettle model, DateTrans dt) {
  80. List<ApplyPaymentSettle> list = null;//modelMapper.selectByExample(getCondition(model,dt));
  81. return list;
  82. }
  83. @Override
  84. public int deleteByPrimaryKey(String ids) {
  85. List<String> lista = Convert.toListStrArray(ids);
  86. ApplyPaymentSettleExample example = new ApplyPaymentSettleExample();
  87. example.createCriteria().andIdIn(lista);
  88. return modelMapper.deleteByExample(example);
  89. }
  90. @Override
  91. public ApplyPaymentSettle selectByPrimaryKey(String id) {
  92. return modelMapper.selectByPrimaryKey(id);
  93. }
  94. @Override
  95. public int updateByPrimaryKeySelective(ApplyPaymentSettle record) {
  96. return modelMapper.updateByPrimaryKeySelective(record);
  97. }
  98. @Override
  99. public int updateByExampleSelective(ApplyPaymentSettle record, ApplyPaymentSettleExample example) {
  100. return modelMapper.updateByExampleSelective(record, example);
  101. }
  102. @Override
  103. public int updateByExample(ApplyPaymentSettle record, ApplyPaymentSettleExample example) {
  104. return modelMapper.updateByExample(record, example);
  105. }
  106. @Override
  107. public List<ApplyPaymentSettle> selectByExample(ApplyPaymentSettleExample example) {
  108. return modelMapper.selectByExample(example);
  109. }
  110. @Override
  111. public long countByExample(ApplyPaymentSettleExample example) {
  112. return modelMapper.countByExample(example);
  113. }
  114. @Override
  115. public int deleteByExample(ApplyPaymentSettleExample example) {
  116. return modelMapper.deleteByExample(example);
  117. }
  118. public int insert(ApplyPaymentSettle record) {
  119. record.setId(UUIDUtils.middleUUID());
  120. return insertWithoutId(record);
  121. }
  122. public int insertWithoutId(ApplyPaymentSettle record) {
  123. record.setCreatedAt(new Date());
  124. return modelMapper.insert(record);
  125. }
  126. @Override
  127. public int insertSelective(ApplyPaymentSettle record) {
  128. record.setId(UUIDUtils.middleUUID());
  129. record.setCreatedAt(new Date());
  130. return modelMapper.insertSelective(record);
  131. }
  132. public ApplyPaymentSettleIn getInfoByFlowMainId(String flowMainId) {
  133. return ApplyPaymentSettleExtendMapper.getInfoByFlowMainId(flowMainId);
  134. }
  135. public ApplyPaymentSettleIn getInfoByFlowMainPushId(String flowMainPushId) {
  136. return ApplyPaymentSettleExtendMapper.getInfoByFlowMainPushId(flowMainPushId);
  137. }
  138. public Map<String, Object> getUserInfoByUserId(String userId) {
  139. Map<String, Object> userInfoByUserId = ApplyPaymentSettleExtendMapper.getUserInfoByUserId(userId);
  140. return userInfoByUserId;
  141. }
  142. // public static void main(String[] args) {
  143. // System.out.println(new ApplyPaymentSettleService().getMaxNum());
  144. // }
  145. /**
  146. * 付款记录编号 : 付款领用单20240401-002
  147. *
  148. * @return
  149. */
  150. public String getMaxNum() {
  151. String maxnum = null;
  152. try {
  153. int c = 0;
  154. while ("#".equals(RedisToUse.pmnumber)) {
  155. try {
  156. c++;
  157. Thread.sleep(100);//等待毫秒
  158. } catch (InterruptedException e) {
  159. throw new RuntimeException(e);
  160. }
  161. if (c >= 1000) {
  162. break;
  163. }
  164. }
  165. maxnum = RedisToUse.pmnumber;
  166. RedisToUse.pmnumber = "#";
  167. if (maxnum == null) {
  168. maxnum = ApplyPaymentSettleExtendMapper.selectMaxNum();
  169. }
  170. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
  171. String topName = "付款领用单" + sdf.format(new Date()) + "-";
  172. // 20221111-04
  173. if (StringUtils.isEmpty(maxnum)) {
  174. maxnum = topName + "001";
  175. } else {
  176. String substring = maxnum.substring(0, topName.length());
  177. if (topName.equals(substring)) {
  178. maxnum = RedisToUse.addNumber(topName, maxnum);
  179. } else {
  180. maxnum = topName + "001";
  181. }
  182. }
  183. } finally {
  184. RedisToUse.pmnumber = maxnum;
  185. }
  186. return maxnum;
  187. }
  188. /**
  189. * 发起流程 推送泛微和工作台待办
  190. * @param id
  191. * @param applyTheme
  192. */
  193. public void startOaAndHandle(String id,String applyTheme) {
  194. try {
  195. String flowId = "";
  196. String nodeName = "";
  197. FlowMainExample flowMainExample = new FlowMainExample();
  198. flowMainExample.createCriteria().andFormIdEqualTo(id).andFlowTypeEqualTo(ConstantFlowType.PAYMENT);
  199. List<FlowMain> flowMains = flowMainService.selectByExample(flowMainExample);
  200. if (CollectionUtils.isNotEmpty(flowMains)) {
  201. FlowMain flowMain = flowMains.get(0);
  202. flowId = flowMain.getId();
  203. FlowMainPushExample flowMainPushExample = new FlowMainPushExample();
  204. flowMainPushExample.createCriteria().andFlowMainIdEqualTo(flowId).andStatusEqualTo(0);
  205. List<FlowMainPush> flowMainPushes = flowMainPushService.selectByExample(flowMainPushExample);
  206. if (CollectionUtils.isNotEmpty(flowMainPushes)) {
  207. FlowMainPush flowMainPush = flowMainPushes.get(0);
  208. nodeName = flowMainPush.getNodeName();
  209. // 给本系统下一个节点的人推送待办
  210. /**
  211. * 添加待办
  212. * @param title 显示标题
  213. * @param typeEnum 处理类型枚举
  214. * @param srcUserType 来源用户类型 0管理,1企业
  215. * @param srcUserId 来源用户id
  216. * @param srcUserName 来源用户名称
  217. * @param receiveUserId 接收用户id or 0=全部 or 角色id
  218. * @param routeParam 跳转携带参数,例: id=***&type=**
  219. */
  220. String waitUrl = "";
  221. // 查询待办页面的 菜单id
  222. FramePermissionExample framePermissionExample = new FramePermissionExample();
  223. framePermissionExample.createCriteria().andNameEqualTo("流程审批");
  224. List<FramePermission> framePermissions = framePermissionService.selectByExample(framePermissionExample);
  225. if (CollectionUtils.isNotEmpty(framePermissions)) {
  226. String menuIndex = framePermissions.get(0).getId();
  227. FramePermissionExample permissionExample = new FramePermissionExample();
  228. permissionExample.createCriteria().andNameEqualTo("付款审批流程");
  229. List<FramePermission> permissions = framePermissionService.selectByExample(framePermissionExample);
  230. if (CollectionUtils.isNotEmpty(permissions)) {
  231. String subMenu = permissions.get(0).getId();
  232. waitUrl = "/backstage?menuIndex=" + menuIndex + "&subMenu=" + subMenu;
  233. }
  234. }
  235. String title = applyTheme;
  236. HandleTypeEnum typeEnum = HandleTypeEnum.FK;
  237. Integer srcUserType = 0;//来源用户类型 0管理,1企业
  238. String srcUserId = ShiroUtils.getUserId();
  239. String srcUserName = ShiroUtils.getUser().getTruename();
  240. String receiveUserId = flowMainPush.getPushUser();
  241. String routeParam = "id=" + flowId + "&flowMainPushId=" + flowMainPush.getId() + "&applyUser=" + flowMain.getApplyUser();
  242. HandleTypeEnum.FK.setUrl(waitUrl);
  243. parkWaitHandleService.addHandle(title, typeEnum, srcUserType, srcUserId, srcUserName, receiveUserId, routeParam);
  244. // TODO: 2024/11/21 和泛OA对接 推送待办
  245. FrameUser receiveUser = frameUserService.selectByPrimaryKey(receiveUserId);
  246. String username = encryptUsername(receiveUser.getUsername());
  247. String syscode = "AJ";
  248. String requestname = applyTheme;
  249. String workflowname = ConstantFlowType.PAYMENT_NAME;
  250. String pcurl = serverUrl + "&loginid=" + username;
  251. String appurl = "";
  252. String isremark = "0";
  253. String viewtype = "0";
  254. // TODO: 2024/11/15 创建者和接收者需求oa协商
  255. String creator = "ceshi";
  256. String receiver = "ceshi";
  257. String date = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, new Date());
  258. String receivets = System.currentTimeMillis() + "";
  259. Map map = new HashMap<String, Object>();
  260. map.put("syscode", syscode);
  261. map.put("flowid", flowId);
  262. map.put("requestname", requestname);
  263. map.put("workflowname", workflowname);
  264. map.put("nodeName", nodeName);
  265. map.put("pcurl", pcurl);
  266. map.put("appurl", appurl);
  267. map.put("creator", creator);
  268. map.put("createdatetime", date);
  269. map.put("receiver", receiver);
  270. map.put("receivedatetime", date);
  271. map.put("isremark", isremark);
  272. map.put("viewtype", viewtype);
  273. map.put("receivets", receivets);
  274. log.info("泛微推送详情:{}", map);
  275. String result = OAUtil.receiveRequestInfoByJson(map);
  276. log.info("泛微推送结果:{}", result);
  277. }
  278. }
  279. } catch (Exception e) {
  280. log.error("推送异常", e);
  281. }
  282. }
  283. /**
  284. * 推送泛微和工作台待办
  285. *
  286. * @param flowMainPush
  287. * @param flowMain
  288. * @param waitUrl
  289. */
  290. public void pushOaAndHandle(FlowMainPush flowMainPush, FlowMain flowMain, String waitUrl) {
  291. try {
  292. String flowId = flowMain.getId();
  293. FlowMainPushExample flowMainPushExample = new FlowMainPushExample();
  294. flowMainPushExample.createCriteria().andFlowMainIdEqualTo(flowId).andStatusEqualTo(0);
  295. List<FlowMainPush> flowMainPushes = flowMainPushService.selectByExample(flowMainPushExample);
  296. if (CollectionUtils.isNotEmpty(flowMainPushes)) {
  297. FlowMainPush push = flowMainPushes.get(0);
  298. // 给本系统下一个节点的人推送待办
  299. /**
  300. * 添加待办
  301. * @param title 显示标题
  302. * @param typeEnum 处理类型枚举
  303. * @param srcUserType 来源用户类型 0管理,1企业
  304. * @param srcUserId 来源用户id
  305. * @param srcUserName 来源用户名称
  306. * @param receiveUserId 接收用户id or 0=全部 or 角色id
  307. * @param routeParam 跳转携带参数,例: id=***&type=**
  308. */
  309. String title = flowMain.getApplyTheme();
  310. HandleTypeEnum typeEnum = HandleTypeEnum.FK;
  311. Integer srcUserType = 0;//来源用户类型 0管理,1企业
  312. String srcUserId = ShiroUtils.getUserId();
  313. String srcUserName = ShiroUtils.getUser().getTruename();
  314. String receiveUserId = push.getPushUser();
  315. String routeParam = "id=" + flowId + "&flowMainPushId=" + push.getId() + "&applyUser=" + flowMain.getApplyUser();
  316. HandleTypeEnum.FK.setUrl(waitUrl);
  317. parkWaitHandleService.addHandle(title, typeEnum, srcUserType, srcUserId, srcUserName, receiveUserId, routeParam);
  318. // TODO: 2024/11/21 和泛微对接 推送信息
  319. FrameUser receiveUser = frameUserService.selectByPrimaryKey(receiveUserId);
  320. String username = encryptUsername(receiveUser.getUsername());
  321. String syscode = "AJ";
  322. String requestname = flowMain.getApplyTheme();
  323. String workflowname = ConstantFlowType.PAYMENT_NAME;
  324. String nodeName = flowMainPush.getNodeName();
  325. String pcurl = serverUrl + "&loginid=" + username;
  326. String appurl = "";
  327. String isremark = "0";
  328. String viewtype = "0";
  329. // TODO: 2024/11/15 创建者和接收者需求oa协商
  330. String creator = "ceshi";
  331. String receiver = "ceshi";
  332. String date = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, new Date());
  333. String receivets = System.currentTimeMillis() + "";
  334. Map map = new HashMap<String, Object>();
  335. map.put("syscode", syscode);
  336. map.put("flowid", flowId);
  337. map.put("requestname", requestname);
  338. map.put("workflowname", workflowname);
  339. map.put("nodeName", nodeName);
  340. map.put("pcurl", pcurl);
  341. map.put("appurl", appurl);
  342. map.put("creator", creator);
  343. map.put("createdatetime", date);
  344. map.put("receiver", receiver);
  345. map.put("receivedatetime", date);
  346. map.put("isremark", isremark);
  347. map.put("viewtype", viewtype);
  348. map.put("receivets", receivets);
  349. log.info("泛微推送详情:{}", map);
  350. String result = OAUtil.receiveRequestInfoByJson(map);
  351. log.info("泛微推送结果:{}", result);
  352. }
  353. } catch (Exception e) {
  354. log.error("推送异常", e);
  355. }
  356. }
  357. /**
  358. * 获取待办页面的url
  359. *
  360. * @return
  361. */
  362. public String getWaitUrl() {
  363. String waitUrl = "";
  364. // 查询待办页面的 菜单id
  365. FramePermissionExample framePermissionExample = new FramePermissionExample();
  366. framePermissionExample.createCriteria().andNameEqualTo("流程审批");
  367. List<FramePermission> framePermissions = framePermissionService.selectByExample(framePermissionExample);
  368. if (CollectionUtils.isNotEmpty(framePermissions)) {
  369. String menuIndex = framePermissions.get(0).getId();
  370. FramePermissionExample permissionExample = new FramePermissionExample();
  371. permissionExample.createCriteria().andNameEqualTo("付款审批流程");
  372. List<FramePermission> permissions = framePermissionService.selectByExample(framePermissionExample);
  373. if (CollectionUtils.isNotEmpty(permissions)) {
  374. String subMenu = permissions.get(0).getId();
  375. waitUrl = "/backstage?menuIndex=" + menuIndex + "&subMenu=" + subMenu;
  376. }
  377. }
  378. return waitUrl;
  379. }
  380. /**
  381. * 加密用户名
  382. *
  383. * @param username
  384. * @return
  385. */
  386. public String encryptUsername(String username) {
  387. byte[] key = Base64.decode(ssoKey);
  388. // 构建
  389. AES aes = SecureUtil.aes(key);
  390. return aes.encryptHex(username);
  391. }
  392. }