EsignFlowListOSFService.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. package com.kingdee.eas.custom.esign.osf;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.google.common.collect.Maps;
  6. import com.kingdee.bos.BOSException;
  7. import com.kingdee.bos.Context;
  8. import com.kingdee.bos.bsf.service.app.IHRMsfService;
  9. import com.kingdee.bos.dao.IObjectPK;
  10. import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
  11. import com.kingdee.bos.metadata.entity.FilterInfo;
  12. import com.kingdee.bos.metadata.entity.FilterItemInfo;
  13. import com.kingdee.bos.metadata.query.util.CompareType;
  14. import com.kingdee.bos.rabbitmq.guava.Lists;
  15. import com.kingdee.bos.util.BOSUuid;
  16. import com.kingdee.eas.basedata.person.PersonInfo;
  17. import com.kingdee.eas.common.EASBizException;
  18. import com.kingdee.eas.custom.esign.ESignGlobalStatusOverviewCollection;
  19. import com.kingdee.eas.custom.esign.ESignGlobalStatusOverviewFactory;
  20. import com.kingdee.eas.custom.esign.ESignGlobalStatusOverviewInfo;
  21. import com.kingdee.eas.custom.esign.IESignGlobalStatusOverview;
  22. import com.kingdee.eas.custom.esign.bizEnum.EsignConfigEnum;
  23. import com.kingdee.eas.custom.esign.bizEnum.EsignStatusEnum;
  24. import com.kingdee.eas.custom.esign.bizEnum.SendStatusEnum;
  25. import com.kingdee.eas.custom.esign.tsign.hz.comm.EsignHttpResponse;
  26. import com.kingdee.eas.custom.esign.tsign.hz.exception.EsignException;
  27. import com.kingdee.eas.custom.esign.util.EsignHttpUtil;
  28. import com.kingdee.eas.custom.esign.util.SyncSignedFilesUtil;
  29. import com.kingdee.eas.util.app.DbUtil;
  30. import com.kingdee.jdbc.rowset.IRowSet;
  31. import org.apache.commons.lang3.StringUtils;
  32. import java.sql.SQLException;
  33. import java.time.*;
  34. import java.time.format.DateTimeFormatter;
  35. import java.util.List;
  36. import java.util.Map;
  37. import java.util.concurrent.ScheduledThreadPoolExecutor;
  38. import java.util.concurrent.TimeUnit;
  39. /**
  40. * description: EsignFlowListOSFService <br>
  41. * date: 4/1/2026 下午 4:23 <br>
  42. * author: lhbj <br>
  43. * version: 1.0 <br>
  44. */
  45. public class EsignFlowListOSFService implements IHRMsfService {
  46. public static LocalDateTime formatter(String time) {
  47. LocalDateTime dateTime = null;
  48. if (time.length() == 10) {
  49. LocalDate localD = LocalDate.parse(time);
  50. LocalTime localT = LocalTime.of(0, 0, 0);
  51. dateTime = LocalDateTime.of(localD, localT);
  52. } else if (time.length() == 16) {
  53. dateTime = LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
  54. } else if (time.length() == 19) {
  55. dateTime = LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
  56. }
  57. return dateTime;
  58. }
  59. public static LocalDateTime startDateTimeNow() {
  60. LocalDate localD1 = LocalDate.now();
  61. LocalTime time1 = LocalTime.now();
  62. LocalTime localT1 = LocalTime.of(time1.getHour(), 0, 0);
  63. LocalDateTime dateTime = LocalDateTime.of(localD1, localT1);
  64. dateTime = dateTime.minusHours(1);
  65. return dateTime;
  66. }
  67. public static LocalDateTime endDateTimeNow() {
  68. LocalDate localD2 = LocalDate.now();
  69. LocalTime localT2 = LocalTime.of(23, 59, 59);
  70. LocalDateTime dateTime = LocalDateTime.of(localD2, localT2);
  71. return dateTime;
  72. }
  73. @Override
  74. public Object process(Context context, Map<String, Object> map) throws EASBizException, BOSException {
  75. String param = (String) map.get("data");
  76. LocalDateTime startDateTime = null;
  77. LocalDateTime endDateTime = null;
  78. StringBuilder msg = new StringBuilder();
  79. if (StringUtils.isNotBlank(param)) {
  80. JSONObject object = JSON.parseObject(param);
  81. String startTime = object.getString("startTime");
  82. String endTime = object.getString("endTime");
  83. String status = object.getString("status");
  84. String advanceHours = object.getString("advanceHours");
  85. if (StringUtils.isNotBlank(startTime)
  86. &&
  87. StringUtils.isNotBlank(endTime)
  88. ) {
  89. startDateTime = this.formatter(startTime);
  90. endDateTime = this.formatter(endTime);
  91. }
  92. if (null == startDateTime || null == endDateTime) {
  93. startDateTime = startDateTimeNow();
  94. endDateTime = endDateTimeNow();
  95. }
  96. startDateTime = startDateTime.minusHours(Integer.parseInt(advanceHours));
  97. }
  98. if (null == startDateTime || null == endDateTime) {
  99. startDateTime = startDateTimeNow();
  100. endDateTime = endDateTimeNow();
  101. }
  102. int pageNum = 0;
  103. int pageSize = 100;
  104. long totalNum = 1;
  105. IESignGlobalStatusOverview overview = ESignGlobalStatusOverviewFactory.getLocalInstance(context);
  106. Map<String, Object> jsonMap = Maps.newHashMap();
  107. long signFlowStartTimeFrom = startDateTime.atZone(ZoneId.systemDefault())
  108. .toInstant()
  109. .toEpochMilli();
  110. long signFlowStartTimeTo = endDateTime.atZone(ZoneId.systemDefault())
  111. .toInstant()
  112. .toEpochMilli();
  113. jsonMap.put("signFlowStartTimeFrom", signFlowStartTimeFrom);
  114. jsonMap.put("signFlowStartTimeTo", signFlowStartTimeTo);
  115. // List<String> list = Lists.newArrayList();
  116. // list.add("2");
  117. // jsonMap.put("signFlowStatus", list);
  118. do {
  119. pageNum++;
  120. jsonMap.put("pageNum", pageNum);
  121. jsonMap.put("pageSize", pageSize);
  122. try {
  123. EsignHttpResponse response = EsignHttpUtil.sign_flow_list(context, jsonMap, "查询签署流程列表");
  124. if (response.getStatus() >= 200 && response.getStatus() < 300) {
  125. if (StringUtils.isBlank(response.getBody())) {
  126. continue;
  127. }
  128. //System.out.println(response.getBody());
  129. JSONObject jsonObject = JSON.parseObject(response.getBody());
  130. int code = jsonObject.getInteger("code");
  131. if (0 != code) {
  132. continue;
  133. }
  134. JSONObject data = jsonObject.getJSONObject("data");
  135. if (null == data) {
  136. continue;
  137. }
  138. long total = data.getLong("total");
  139. if (total % pageSize == 0) {
  140. totalNum = total / pageSize;
  141. } else {
  142. totalNum = total / pageSize + 1;
  143. }
  144. JSONArray signFlowInfos = data.getJSONArray("signFlowInfos");
  145. for (int i = 0; i < signFlowInfos.size(); i++) {
  146. JSONObject signFlowInfo = signFlowInfos.getJSONObject(i);
  147. String signFlowId = signFlowInfo.getString("signFlowId");
  148. String signFlowTitle = signFlowInfo.getString("signFlowTitle");
  149. String sel = "select fid from CT_ESI_ESGSO where CFSignFlowId ='" + signFlowId + "'";
  150. IRowSet rowSet = DbUtil.executeQuery(context, sel);
  151. if (rowSet.next()) {
  152. String id = rowSet.getString("fid");
  153. updateSignFlow(context, overview, signFlowId, id);
  154. } else {
  155. if (signFlowTitle.indexOf("人资") < 0 && signFlowTitle.indexOf("人力资源") < 0) {
  156. continue;
  157. }
  158. addNewSignFlow(context, overview, signFlowInfo, signFlowId, signFlowTitle);
  159. }
  160. }
  161. }
  162. } catch (EsignException | SQLException e) {
  163. e.printStackTrace();
  164. }
  165. } while (pageNum < totalNum);
  166. return "ok";
  167. }
  168. private boolean updateSignFlow(Context context, IESignGlobalStatusOverview overview, String signFlowId, String id) throws BOSException, EASBizException, EsignException, SQLException {
  169. ESignGlobalStatusOverviewInfo oldInfo = overview.getESignGlobalStatusOverviewInfo(new ObjectUuidPK(id));
  170. EsignHttpResponse respsf = EsignHttpUtil.getSign_fields(context, signFlowId, "查询签署流程详情");
  171. if (respsf.getStatus() < 200 || respsf.getStatus() >= 300) {
  172. return true;
  173. }
  174. if (StringUtils.isBlank(respsf.getBody())) {
  175. return true;
  176. }
  177. JSONObject jsonObjsf = JSON.parseObject(respsf.getBody());
  178. int codesf = jsonObjsf.getInteger("code");
  179. if (0 != codesf) {
  180. return true;
  181. }
  182. JSONObject datasf = jsonObjsf.getJSONObject("data");
  183. if (null == datasf) {
  184. return true;
  185. }
  186. Integer signFlowStatus = datasf.getInteger("signFlowStatus");
  187. String statusDescription = datasf.getString("statusDescription");
  188. //签署中
  189. if (null != signFlowStatus && 1 == signFlowStatus) {
  190. JSONArray signers = datasf.getJSONArray("signers");
  191. StringBuilder signNames = new StringBuilder();
  192. for (int j = 0; j < signers.size(); j++) {
  193. JSONObject signer = signers.getJSONObject(j);
  194. JSONObject psnSigner = signer.getJSONObject("psnSigner");
  195. JSONObject orgSigner = signer.getJSONObject("orgSigner");
  196. JSONArray signFields = signer.getJSONArray("signFields");
  197. boolean signFieldBool=false;
  198. for (int x = 0; x < signFields.size(); x++) {
  199. JSONObject sign = signFields.getJSONObject(x);
  200. Integer signFieldStatus = Integer.parseInt(sign.getString("signFieldStatus"));
  201. //这三种情况的话说明是当前这个签署区所属的签署人在签署:1 - 执行中、2 - 执行失败、3 - 审批中
  202. if (signFieldStatus > 0 && signFieldStatus < 4) {
  203. signFieldBool=true;
  204. }
  205. }
  206. oldInfo.setEsignStatus(EsignStatusEnum.getEnum(signFlowStatus));
  207. //oldInfo.setDescription(statusDescription);
  208. oldInfo.setNowOperator("");
  209. if (signFieldBool) {
  210. signNames = getPsnName(context, signNames, psnSigner);
  211. signNames = getOrgName(context, signNames, orgSigner);
  212. }
  213. }
  214. if(signNames.indexOf(",") == 0) {
  215. signNames.delete(0,1);
  216. }
  217. if (signNames.length() > 500) {
  218. oldInfo.setNowOperator(signNames.substring(0, 500));
  219. } else {
  220. oldInfo.setNowOperator(signNames.toString());
  221. }
  222. } else {
  223. String signFlowDescription = datasf.getString("signFlowDescription");
  224. String revokeReason = datasf.getString("revokeReason");
  225. oldInfo.setNowOperator("");
  226. oldInfo.setErrorMsg(signFlowDescription);
  227. oldInfo.setErrorMsg(revokeReason);
  228. }
  229. overview.save(oldInfo);
  230. return false;
  231. }
  232. private StringBuilder getOrgName(Context context, StringBuilder signNames, JSONObject orgSigner) throws BOSException, SQLException {
  233. if (null == orgSigner) {
  234. return signNames;
  235. }
  236. String orgName = orgSigner.getString("orgName");
  237. JSONObject transactor = orgSigner.getJSONObject("transactor");
  238. if (null == transactor) {
  239. return signNames;
  240. }
  241. String psnName = transactor.getString("psnName");
  242. if (StringUtils.isNotBlank(psnName)) {
  243. signNames.append("," + orgName + "(" + psnName + ")");
  244. return signNames;
  245. }
  246. JSONObject psnAccount = transactor.getJSONObject("psnAccount");
  247. if (null == psnAccount) {
  248. return signNames;
  249. }
  250. String accountMobile = psnAccount.getString("accountMobile");
  251. String accountEmail = psnAccount.getString("accountEmail");
  252. if (StringUtils.isNotBlank(accountMobile)) {
  253. String selp = "select fid,fname_l2,fnumber from t_bd_person where FNCELL='" + accountMobile + "'";
  254. IRowSet rs = DbUtil.executeQuery(context, selp);
  255. if (rs.next()) {
  256. String fid = rs.getString("fid");
  257. String fname_l2 = rs.getString("fname_l2");
  258. String fnumber = rs.getString("fnumber");
  259. signNames.append("," + orgName + "(" + fname_l2 + ")");
  260. return signNames;
  261. }
  262. }
  263. if (StringUtils.isNotBlank(accountEmail)) {
  264. String selp = "select fid,fname_l2,fnumber from t_bd_person where FEMail='" + accountEmail + "'";
  265. IRowSet rs = DbUtil.executeQuery(context, selp);
  266. if (rs.next()) {
  267. String fid = rs.getString("fid");
  268. String fname_l2 = rs.getString("fname_l2");
  269. String fnumber = rs.getString("fnumber");
  270. signNames.append("," + orgName + "(" + fname_l2 + ")");
  271. return signNames;
  272. }
  273. }
  274. return signNames;
  275. }
  276. private StringBuilder getPsnName(Context context, StringBuilder signNames, JSONObject psnSigner) throws BOSException, SQLException {
  277. if (null == psnSigner) {
  278. return signNames;
  279. }
  280. String psnName = psnSigner.getString("psnName");
  281. if (StringUtils.isNotBlank(psnName)) {
  282. signNames.append("," + psnName);
  283. return signNames;
  284. }
  285. JSONObject psnAccount = psnSigner.getJSONObject("psnAccount");
  286. if (null == psnAccount) {
  287. return signNames;
  288. }
  289. String accountMobile = psnAccount.getString("accountMobile");
  290. String accountEmail = psnAccount.getString("accountEmail");
  291. if (StringUtils.isNotBlank(accountMobile)) {
  292. String selp = "select fid,fname_l2,fnumber from t_bd_person where FNCELL='" + accountMobile + "'";
  293. IRowSet rs = DbUtil.executeQuery(context, selp);
  294. if (rs.next()) {
  295. String fid = rs.getString("fid");
  296. String fname_l2 = rs.getString("fname_l2");
  297. String fnumber = rs.getString("fnumber");
  298. signNames.append("," + fname_l2);
  299. return signNames;
  300. }
  301. }
  302. if (StringUtils.isNotBlank(accountEmail)) {
  303. String selp = "select fid,fname_l2,fnumber from t_bd_person where FEMail='" + accountEmail + "'";
  304. IRowSet rs = DbUtil.executeQuery(context, selp);
  305. if (rs.next()) {
  306. String fid = rs.getString("fid");
  307. String fname_l2 = rs.getString("fname_l2");
  308. String fnumber = rs.getString("fnumber");
  309. signNames.append("," + fname_l2);
  310. return signNames;
  311. }
  312. }
  313. return signNames;
  314. }
  315. private void addNewSignFlow(Context context, IESignGlobalStatusOverview overview, JSONObject signFlowInfo, String signFlowId, String signFlowTitle) throws BOSException, SQLException, EASBizException {
  316. ESignGlobalStatusOverviewInfo nowInfo = new ESignGlobalStatusOverviewInfo();
  317. nowInfo.setSignFlowId(signFlowId);
  318. nowInfo.setFileName(signFlowTitle);
  319. nowInfo.setEsignStatus(EsignStatusEnum.COMPLETED);
  320. nowInfo.setEsignName(EsignConfigEnum.sign_flow_list);
  321. nowInfo.setRequestParams(signFlowInfo.toJSONString());
  322. nowInfo.setFiesign(true);
  323. nowInfo.setSendStatus(SendStatusEnum.SUCCESS);
  324. JSONArray signers = signFlowInfo.getJSONArray("signers");
  325. for (int x = 0; x < signers.size(); x++) {
  326. JSONObject signer = signers.getJSONObject(x);
  327. JSONObject psnSigner = signer.getJSONObject("psnSigner");
  328. if (null == psnSigner) {
  329. continue;
  330. }
  331. JSONObject psnAccount = psnSigner.getJSONObject("psnAccount");
  332. String accountMobile = psnAccount.getString("accountMobile");
  333. String accountEmail = psnAccount.getString("accountEmail");
  334. if (StringUtils.isNotBlank(accountMobile)) {
  335. String selp = "select fid from t_bd_person where FNCELL='" + accountMobile + "'";
  336. IRowSet rs = DbUtil.executeQuery(context, selp);
  337. if (rs.next()) {
  338. String fid = rs.getString("fid");
  339. PersonInfo personInfo = new PersonInfo();
  340. personInfo.setId(BOSUuid.read(fid));
  341. nowInfo.setPerson(personInfo);
  342. }
  343. } else {
  344. String selp = "select fid from t_bd_person where FEMail='" + accountEmail + "'";
  345. IRowSet rs = DbUtil.executeQuery(context, selp);
  346. if (rs.next()) {
  347. String fid = rs.getString("fid");
  348. PersonInfo personInfo = new PersonInfo();
  349. personInfo.setId(BOSUuid.read(fid));
  350. nowInfo.setPerson(personInfo);
  351. }
  352. }
  353. }
  354. //if (null != nowInfo.getPerson()) {
  355. IObjectPK pk = overview.addnew(nowInfo);
  356. ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
  357. scheduledThreadPoolExecutor.schedule(() -> {
  358. try {
  359. this.updateSignFlow(context, overview, signFlowId, nowInfo.getId().toString());
  360. SyncSignedFilesUtil.syncAttachmentsForEmpPage(context, nowInfo.getId().toString());
  361. } catch (BOSException e) {
  362. e.printStackTrace();
  363. } catch (EASBizException e) {
  364. e.printStackTrace();
  365. } catch (EsignException e) {
  366. e.printStackTrace();
  367. } catch (SQLException throwables) {
  368. throwables.printStackTrace();
  369. }
  370. }, 1, TimeUnit.MINUTES);
  371. //}
  372. }
  373. public static void main(String[] args) throws EsignException {
  374. System.setProperty("EAS_HOME","D:\\project\\kingdeeV90\\Project_hty\\tengda");
  375. // LocalDateTime startDateTime = null;
  376. // LocalDateTime endDateTime = null;
  377. // if (null == startDateTime || null == endDateTime) {
  378. // startDateTime = formatter("2025-02-01");;
  379. // endDateTime = formatter("2026-02-01");;
  380. // }
  381. // int pageNum=0;
  382. // int pageSize=100;
  383. // long totalNum=1;
  384. // do {
  385. // pageNum++;
  386. // Map<String, Object> jsonMap = Maps.newHashMap();
  387. // long signFlowStartTimeFrom = startDateTime.atZone(ZoneId.systemDefault())
  388. // .toInstant()
  389. // .toEpochMilli();
  390. // long signFlowStartTimeTo = endDateTime.atZone(ZoneId.systemDefault())
  391. // .toInstant()
  392. // .toEpochMilli();
  393. // jsonMap.put("signFlowStartTimeFrom", signFlowStartTimeFrom);
  394. // jsonMap.put("signFlowStartTimeTo", signFlowStartTimeTo);
  395. // jsonMap.put("pageNum", pageNum);
  396. // jsonMap.put("pageSize", pageSize);
  397. // List<String> list = Lists.newArrayList();
  398. // list.add("1");
  399. // list.add("2");
  400. // list.add("3");
  401. // jsonMap.put("signFlowStatus", list);
  402. // try {
  403. // EsignHttpResponse response = EsignHttpUtil.sign_flow_list(null, jsonMap, "查询签署流程列表");
  404. // System.out.println(response.getBody());
  405. // JSONObject jsonObject = JSON.parseObject(response.getBody());
  406. // int code =jsonObject.getInteger("code");
  407. // if (0==code){
  408. // JSONObject data = jsonObject.getJSONObject("data");
  409. // if (null!=data){
  410. // JSONArray signFlowInfos = data.getJSONArray("signFlowInfos");
  411. // System.out.println(signFlowInfos.size());
  412. // long total = data.getLong("total");
  413. // if(total%pageSize==0){
  414. // totalNum=total/pageSize;
  415. // }else {
  416. // totalNum=total/pageSize+1;
  417. // }
  418. // }
  419. // }
  420. // } catch (EsignException e) {
  421. // e.printStackTrace();
  422. // }
  423. // } while (pageNum<totalNum);
  424. // System.out.println(12 + (3 - 1) / 2 * 1);
  425. // EsignHttpResponse r = EsignHttpUtil.getSign_fields(null,"d4d12e6ed7374775a9dcb4747e1e5e59");
  426. // System.out.println(r.getBody());
  427. FilterInfo filterInfo2 = new FilterInfo();
  428. FilterItemInfo f = new FilterItemInfo();
  429. f.setPropertyName("isnull(t.fid,'2199-12-30')");
  430. f.setCompareValue("1");
  431. f.setCompareType(CompareType.EQUALS);
  432. filterInfo2.getFilterItems().add(f);
  433. System.out.println(filterInfo2.toSql());
  434. }
  435. }