EsignFlowListOSFService.java 20 KB

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