EsignFlowListOSFService.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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.rabbitmq.guava.Lists;
  11. import com.kingdee.bos.util.BOSUuid;
  12. import com.kingdee.eas.basedata.person.PersonInfo;
  13. import com.kingdee.eas.common.EASBizException;
  14. import com.kingdee.eas.custom.esign.ESignGlobalStatusOverviewCollection;
  15. import com.kingdee.eas.custom.esign.ESignGlobalStatusOverviewFactory;
  16. import com.kingdee.eas.custom.esign.ESignGlobalStatusOverviewInfo;
  17. import com.kingdee.eas.custom.esign.IESignGlobalStatusOverview;
  18. import com.kingdee.eas.custom.esign.bizEnum.EsignConfigEnum;
  19. import com.kingdee.eas.custom.esign.bizEnum.EsignStatusEnum;
  20. import com.kingdee.eas.custom.esign.bizEnum.SendStatusEnum;
  21. import com.kingdee.eas.custom.esign.tsign.hz.comm.EsignHttpResponse;
  22. import com.kingdee.eas.custom.esign.tsign.hz.exception.EsignException;
  23. import com.kingdee.eas.custom.esign.util.EsignHttpUtil;
  24. import com.kingdee.eas.custom.esign.util.SyncSignedFilesUtil;
  25. import com.kingdee.eas.util.app.DbUtil;
  26. import com.kingdee.jdbc.rowset.IRowSet;
  27. import org.apache.commons.lang3.StringUtils;
  28. import java.sql.SQLException;
  29. import java.time.*;
  30. import java.time.format.DateTimeFormatter;
  31. import java.util.List;
  32. import java.util.Map;
  33. /**
  34. *
  35. * description: EsignFlowListOSFService <br>
  36. * date: 4/1/2026 下午 4:23 <br>
  37. * author: lhbj <br>
  38. * version: 1.0 <br>
  39. */
  40. public class EsignFlowListOSFService implements IHRMsfService {
  41. public static LocalDateTime formatter(String time) {
  42. LocalDateTime dateTime = null;
  43. if (time.length() == 10) {
  44. LocalDate localD = LocalDate.parse(time);
  45. LocalTime localT = LocalTime.of(0, 0, 0);
  46. dateTime = LocalDateTime.of(localD, localT);
  47. } else if (time.length() == 16) {
  48. dateTime = LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
  49. } else if (time.length() == 19) {
  50. dateTime = LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
  51. }
  52. return dateTime;
  53. }
  54. public static LocalDateTime startDateTimeNow() {
  55. LocalDate localD1 = LocalDate.now();
  56. LocalTime time1 = LocalTime.now();
  57. LocalTime localT1 = LocalTime.of(time1.getHour(), 0, 0);
  58. LocalDateTime dateTime = LocalDateTime.of(localD1, localT1);
  59. dateTime=dateTime.minusHours(1);
  60. return dateTime;
  61. }
  62. public static LocalDateTime endDateTimeNow() {
  63. LocalDate localD2 = LocalDate.now();
  64. LocalTime localT2 = LocalTime.of(23, 59, 59);
  65. LocalDateTime dateTime = LocalDateTime.of(localD2, localT2);
  66. return dateTime;
  67. }
  68. @Override
  69. public Object process(Context context, Map<String, Object> map) throws EASBizException, BOSException {
  70. String param = (String) map.get("data");
  71. LocalDateTime startDateTime = null;
  72. LocalDateTime endDateTime = null;
  73. StringBuilder msg = new StringBuilder();
  74. if (StringUtils.isNotBlank(param)) {
  75. JSONObject object = JSON.parseObject(param);
  76. String startTime = object.getString("startTime");
  77. String endTime = object.getString("endTime");
  78. String status = object.getString("status");
  79. String advanceHours = object.getString("advanceHours");
  80. if (StringUtils.isNotBlank(startTime)
  81. &&
  82. StringUtils.isNotBlank(endTime)
  83. ) {
  84. startDateTime = this.formatter(startTime);
  85. endDateTime = this.formatter(endTime);
  86. }
  87. if (null == startDateTime || null == endDateTime) {
  88. startDateTime = startDateTimeNow();
  89. endDateTime = endDateTimeNow();
  90. }
  91. startDateTime = startDateTime.minusHours(Integer.parseInt(advanceHours));
  92. }
  93. if (null == startDateTime || null == endDateTime) {
  94. startDateTime = startDateTimeNow();
  95. endDateTime = endDateTimeNow();
  96. }
  97. int pageNum=0;
  98. int pageSize=100;
  99. long totalNum=1;
  100. do {
  101. pageNum++;
  102. Map<String, Object> jsonMap = Maps.newHashMap();
  103. long signFlowStartTimeFrom = startDateTime.atZone(ZoneId.systemDefault())
  104. .toInstant()
  105. .toEpochMilli();
  106. long signFlowStartTimeTo = endDateTime.atZone(ZoneId.systemDefault())
  107. .toInstant()
  108. .toEpochMilli();
  109. jsonMap.put("signFlowStartTimeFrom", signFlowStartTimeFrom);
  110. jsonMap.put("signFlowStartTimeTo", signFlowStartTimeTo);
  111. jsonMap.put("pageNum", pageNum);
  112. jsonMap.put("pageSize", pageSize);
  113. List<String> list = Lists.newArrayList();
  114. list.add("2");
  115. jsonMap.put("signFlowStatus", list);
  116. try {
  117. IESignGlobalStatusOverview overview = ESignGlobalStatusOverviewFactory.getLocalInstance(context);
  118. EsignHttpResponse response = EsignHttpUtil.sign_flow_list(context, jsonMap, "查询签署流程列表");
  119. JSONObject jsonObject = JSON.parseObject(response.getBody());
  120. int code =jsonObject.getInteger("code");
  121. if (0==code){
  122. JSONObject data = jsonObject.getJSONObject("data");
  123. if (null!=data){
  124. long total = data.getLong("total");
  125. if(total%pageSize==0){
  126. totalNum=total/pageSize;
  127. }else {
  128. totalNum=total/pageSize+1;
  129. }
  130. JSONArray signFlowInfos = data.getJSONArray("signFlowInfos");
  131. for (int i=0;i<signFlowInfos.size();i++){
  132. JSONObject signFlowInfo = signFlowInfos.getJSONObject(i);
  133. String signFlowId = signFlowInfo.getString("signFlowId");
  134. String sel = "select fid from CT_ESI_ESGSO where CFSignFlowId ='"+signFlowId+"'";
  135. IRowSet rowSet = DbUtil.executeQuery(context,sel);
  136. if(rowSet.size()<=0){
  137. ESignGlobalStatusOverviewInfo nowInfo = new ESignGlobalStatusOverviewInfo();
  138. nowInfo.setSignFlowId(signFlowId);
  139. nowInfo.setEsignStatus(EsignStatusEnum.COMPLETED);
  140. nowInfo.setEsignName(EsignConfigEnum.sign_flow_list);
  141. nowInfo.setRequestParams(response.getBody());
  142. nowInfo.setFiesign(true);
  143. nowInfo.setSendStatus(SendStatusEnum.SUCCESS);
  144. JSONArray signers = signFlowInfo.getJSONArray("signers");
  145. for(int x=0;x<signers.size();x++) {
  146. JSONObject signer = signers.getJSONObject(x);
  147. JSONObject psnSigner=signer.getJSONObject("psnSigner");
  148. if (null==psnSigner){
  149. continue;
  150. }
  151. JSONObject psnAccount=psnSigner.getJSONObject("psnAccount");
  152. String accountMobile = psnAccount.getString("accountMobile");
  153. String accountEmail = psnAccount.getString("accountEmail");
  154. if(StringUtils.isNotBlank(accountMobile)){
  155. String selp = "select fid from t_bd_person where FNCELL='"+accountMobile+"'";
  156. IRowSet rs = DbUtil.executeQuery(context,selp);
  157. if (rs.next()){
  158. String fid = rs.getString("fid");
  159. PersonInfo personInfo = new PersonInfo();
  160. personInfo.setId(BOSUuid.read(fid));
  161. nowInfo.setPerson(personInfo);
  162. }
  163. }else {
  164. String selp = "select fid from t_bd_person where FEMail='"+accountEmail+"'";
  165. IRowSet rs = DbUtil.executeQuery(context,selp);
  166. if (rs.next()){
  167. String fid = rs.getString("fid");
  168. PersonInfo personInfo = new PersonInfo();
  169. personInfo.setId(BOSUuid.read(fid));
  170. nowInfo.setPerson(personInfo);
  171. }
  172. }
  173. }
  174. if(null!=nowInfo.getPerson()) {
  175. IObjectPK pk = overview.addnew(nowInfo);
  176. SyncSignedFilesUtil.syncAttachmentsForEmpPage(context,pk.toString());
  177. }
  178. }
  179. }
  180. }
  181. }
  182. } catch (EsignException | SQLException e) {
  183. e.printStackTrace();
  184. }
  185. } while (pageNum<totalNum);
  186. return "ok";
  187. }
  188. public static void main(String[] args) {
  189. System.setProperty("EAS_HOME","D:\\project\\kingdeeV90\\Project_hty\\tengda");
  190. LocalDateTime startDateTime = null;
  191. LocalDateTime endDateTime = null;
  192. if (null == startDateTime || null == endDateTime) {
  193. startDateTime = formatter("2025-02-01");;
  194. endDateTime = endDateTimeNow();
  195. }
  196. int pageNum=0;
  197. int pageSize=20;
  198. long totalNum=1;
  199. do {
  200. pageNum++;
  201. Map<String, Object> jsonMap = Maps.newHashMap();
  202. long signFlowStartTimeFrom = startDateTime.atZone(ZoneId.systemDefault())
  203. .toInstant()
  204. .toEpochMilli();
  205. long signFlowStartTimeTo = endDateTime.atZone(ZoneId.systemDefault())
  206. .toInstant()
  207. .toEpochMilli();
  208. jsonMap.put("signFlowStartTimeFrom", signFlowStartTimeFrom);
  209. jsonMap.put("signFlowStartTimeTo", signFlowStartTimeTo);
  210. jsonMap.put("pageNum", pageNum);
  211. jsonMap.put("pageSize", pageSize);
  212. List<String> list = Lists.newArrayList();
  213. //list.add("1");
  214. list.add("2");
  215. //list.add("3");
  216. jsonMap.put("signFlowStatus", list);
  217. try {
  218. EsignHttpResponse response = EsignHttpUtil.sign_flow_list(null, jsonMap, "查询签署流程列表");
  219. System.out.println(response.getBody());
  220. JSONObject jsonObject = JSON.parseObject(response.getBody());
  221. int code =jsonObject.getInteger("code");
  222. if (0==code){
  223. JSONObject data = jsonObject.getJSONObject("data");
  224. if (null!=data){
  225. JSONArray signFlowInfos = data.getJSONArray("signFlowInfos");
  226. System.out.println(signFlowInfos.size());
  227. long total = data.getLong("total");
  228. if(total%pageSize==0){
  229. totalNum=total/pageSize;
  230. }else {
  231. totalNum=total/pageSize+1;
  232. }
  233. }
  234. }
  235. } catch (EsignException e) {
  236. e.printStackTrace();
  237. }
  238. } while (pageNum<totalNum);
  239. }
  240. }