ESignGlobalStatusOverviewListHandler.java 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. package com.kingdee.eas.custom.esign.handler;
  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.google.common.collect.Sets;
  7. import com.kingdee.bos.BOSException;
  8. import com.kingdee.bos.Context;
  9. import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
  10. import com.kingdee.bos.metadata.entity.*;
  11. import com.kingdee.bos.util.BOSUuid;
  12. import com.kingdee.eas.base.attachment.*;
  13. import com.kingdee.eas.base.attachment.common.AttachmentHelper;
  14. import com.kingdee.eas.basedata.person.PersonInfo;
  15. import com.kingdee.eas.common.EASBizException;
  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.EsignStatusEnum;
  20. import com.kingdee.eas.custom.esign.tsign.hz.comm.EsignHttpResponse;
  21. import com.kingdee.eas.custom.esign.tsign.hz.exception.EsignException;
  22. import com.kingdee.eas.custom.esign.util.DownloaderUtil;
  23. import com.kingdee.eas.custom.esign.util.EsignHttpUtil;
  24. import com.kingdee.eas.custom.esign.util.SyncSignedFilesUtil;
  25. import com.kingdee.eas.hr.base.app.util.SHRBizBillAttachmentReverseUtils;
  26. import com.kingdee.shr.attachment.*;
  27. import com.kingdee.shr.attachment.AttachmentTypeEnum;
  28. import com.kingdee.shr.base.syssetting.api.bean.BatchMessageTipsBody;
  29. import com.kingdee.shr.base.syssetting.api.bean.BatchMessageTipsHeader;
  30. import com.kingdee.shr.base.syssetting.context.SHRContext;
  31. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  32. import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
  33. import com.kingdee.shr.base.syssetting.ml.SHRWebResource;
  34. import com.kingdee.shr.base.syssetting.web.handler.ListHandler;
  35. import com.kingdee.shr.ml.util.MutilanUtils;
  36. import com.kingdee.util.LocaleUtils;
  37. import com.kingdee.util.STConverter;
  38. import org.apache.commons.lang3.StringUtils;
  39. import org.springframework.ui.ModelMap;
  40. import javax.servlet.http.HttpServletRequest;
  41. import javax.servlet.http.HttpServletResponse;
  42. import java.io.IOException;
  43. import java.net.URISyntaxException;
  44. import java.text.MessageFormat;
  45. import java.util.Locale;
  46. import java.util.Map;
  47. import java.util.Set;
  48. /**
  49. * description: ESignGlobalStatusOverviewHandler <br>
  50. * date: 21/11/2025 下午 4:19 <br>
  51. * author: lhbj <br>
  52. * version: 1.0 <br>
  53. */
  54. public class ESignGlobalStatusOverviewListHandler extends ListHandler {
  55. public Context getCtx() {
  56. return SHRContext.getInstance().getContext();
  57. }
  58. /**
  59. * 基于文件发起签署
  60. *
  61. * @param request
  62. * @param response
  63. * @param modelMap
  64. * @return
  65. * @throws SHRWebException
  66. */
  67. public String create_by_fileAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  68. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  69. String billId = this.getBillId(request);
  70. int failure = 0;
  71. int success = 0;
  72. try {
  73. if (billId.indexOf(",") >= 0) {
  74. throw new EsignException("请选择一行记录发起签署");
  75. }
  76. IESignGlobalStatusOverview globalStatusOverview = ESignGlobalStatusOverviewFactory.getLocalInstance(this.getCtx());
  77. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  78. selectorItemCollection.add(new SelectorItemInfo("*"));
  79. selectorItemCollection.add(new SelectorItemInfo("person.id"));
  80. selectorItemCollection.add(new SelectorItemInfo("operator.id"));
  81. ESignGlobalStatusOverviewInfo info = globalStatusOverview.getESignGlobalStatusOverviewInfo(new ObjectUuidPK(billId));
  82. PersonInfo person = info.getPerson();
  83. PersonInfo operator = info.getOperator();
  84. String personId = null;
  85. if (null != person && null != person.getId()) {
  86. personId = person.getId().toString();
  87. }
  88. String operatorId = null;
  89. if (null != operator && null != operator.getId()) {
  90. operatorId = operator.getId().toString();
  91. }
  92. if (StringUtils.isNotBlank(info.getSignFlowId())) {
  93. BatchMessageTipsBody body = new BatchMessageTipsBody();
  94. body.setMuitTipsState(Boolean.FALSE);
  95. body.setMuitTipsMessage("已经发起签署了,不能重复发起");
  96. body.setId(billId);
  97. batchMessageTipsHeader.addResult(body);
  98. } else {
  99. EsignHttpResponse httpRes = EsignHttpUtil.create_by_file(this.getCtx(), personId, info.getFileName(), operatorId, info.getEfileId(),
  100. EsignStatusEnum.SIGNING, info.getRequestParams());
  101. if (httpRes.getStatus() >= 200 && httpRes.getStatus() < 300) {
  102. JSONObject object = JSON.parseObject(httpRes.getBody());
  103. if ("0".equals(String.valueOf(object.get("code")))) {
  104. BatchMessageTipsBody body = new BatchMessageTipsBody();
  105. body.setMuitTipsState(Boolean.TRUE);
  106. body.setMuitTipsMessage(httpRes.getBody());
  107. body.setId(billId);
  108. batchMessageTipsHeader.addResult(body);
  109. success++;
  110. } else {
  111. BatchMessageTipsBody body = new BatchMessageTipsBody();
  112. body.setMuitTipsState(Boolean.FALSE);
  113. body.setMuitTipsMessage(httpRes.getBody());
  114. body.setId(billId);
  115. batchMessageTipsHeader.addResult(body);
  116. }
  117. } else {
  118. BatchMessageTipsBody body = new BatchMessageTipsBody();
  119. body.setMuitTipsState(Boolean.FALSE);
  120. body.setMuitTipsMessage(httpRes.getBody());
  121. body.setId(billId);
  122. batchMessageTipsHeader.addResult(body);
  123. }
  124. }
  125. } catch (EsignException e) {
  126. e.printStackTrace();
  127. throw new ShrWebBizException(e);
  128. } catch (Exception e) {
  129. e.printStackTrace();
  130. throw new ShrWebBizException(e);
  131. }
  132. batchMessageTipsHeader.setBillId(billId);
  133. batchMessageTipsHeader.setFailureCount((success <= 0 ? 1 : 0));
  134. batchMessageTipsHeader.setSuccessCount(success);
  135. this.writeSuccessData(batchMessageTipsHeader);
  136. return null;
  137. }
  138. /**
  139. * 撤销签署流程
  140. *
  141. * @param request
  142. * @param response
  143. * @param modelMap
  144. * @return
  145. * @throws SHRWebException
  146. */
  147. public String revoke_by_fileAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  148. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  149. String billId = this.getBillId(request);
  150. String revokeReason = request.getParameter("revokeReason");
  151. int failure = 0;
  152. int success = 0;
  153. try {
  154. if (billId.indexOf(",") >= 0) {
  155. throw new EsignException("请选择一行记录发起签署");
  156. }
  157. IESignGlobalStatusOverview globalStatusOverview = ESignGlobalStatusOverviewFactory.getLocalInstance(this.getCtx());
  158. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  159. selectorItemCollection.add(new SelectorItemInfo("*"));
  160. selectorItemCollection.add(new SelectorItemInfo("person.id"));
  161. selectorItemCollection.add(new SelectorItemInfo("operator.id"));
  162. ESignGlobalStatusOverviewInfo info = globalStatusOverview.getESignGlobalStatusOverviewInfo(new ObjectUuidPK(billId));
  163. PersonInfo person = info.getPerson();
  164. PersonInfo operator = info.getOperator();
  165. String personId = null;
  166. if (null != person && null != person.getId()) {
  167. personId = person.getId().toString();
  168. }
  169. String operatorId = null;
  170. if (null != operator && null != operator.getId()) {
  171. operatorId = operator.getId().toString();
  172. }
  173. if (StringUtils.isBlank(info.getSignFlowId())) {
  174. throw new EsignException("没有签署流程id");
  175. }
  176. EsignHttpResponse httpRes = EsignHttpUtil.revoke_by_file(this.getCtx(), info.getSignFlowId(), revokeReason, info.getEfileId());
  177. if (httpRes.getStatus() >= 200 && httpRes.getStatus() < 300) {
  178. JSONObject object = JSON.parseObject(httpRes.getBody());
  179. if ("0".equals(String.valueOf(object.get("code")))) {
  180. BatchMessageTipsBody body = new BatchMessageTipsBody();
  181. body.setMuitTipsState(Boolean.TRUE);
  182. body.setMuitTipsMessage(httpRes.getBody());
  183. body.setId(billId);
  184. batchMessageTipsHeader.addResult(body);
  185. success++;
  186. } else {
  187. BatchMessageTipsBody body = new BatchMessageTipsBody();
  188. body.setMuitTipsState(Boolean.FALSE);
  189. body.setMuitTipsMessage(httpRes.getBody());
  190. body.setId(billId);
  191. batchMessageTipsHeader.addResult(body);
  192. }
  193. } else {
  194. BatchMessageTipsBody body = new BatchMessageTipsBody();
  195. body.setMuitTipsState(Boolean.FALSE);
  196. body.setMuitTipsMessage(httpRes.getBody());
  197. body.setId(billId);
  198. batchMessageTipsHeader.addResult(body);
  199. }
  200. } catch (EsignException e) {
  201. e.printStackTrace();
  202. throw new ShrWebBizException(e);
  203. } catch (Exception e) {
  204. e.printStackTrace();
  205. throw new ShrWebBizException(e);
  206. }
  207. batchMessageTipsHeader.setBillId(billId);
  208. batchMessageTipsHeader.setFailureCount((success <= 0 ? 1 : 0));
  209. batchMessageTipsHeader.setSuccessCount(success);
  210. this.writeSuccessData(batchMessageTipsHeader);
  211. return null;
  212. }
  213. /**
  214. * 催签流程中签署人
  215. *
  216. * @param request
  217. * @param response
  218. * @param modelMap
  219. * @return
  220. * @throws SHRWebException
  221. */
  222. public String urge_by_fileAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  223. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  224. String billId = this.getBillId(request);
  225. int failure = 0;
  226. int success = 0;
  227. try {
  228. if (billId.indexOf(",") >= 0) {
  229. throw new EsignException("请选择一行记录发起签署");
  230. }
  231. IESignGlobalStatusOverview globalStatusOverview = ESignGlobalStatusOverviewFactory.getLocalInstance(this.getCtx());
  232. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  233. selectorItemCollection.add(new SelectorItemInfo("*"));
  234. selectorItemCollection.add(new SelectorItemInfo("person.id"));
  235. selectorItemCollection.add(new SelectorItemInfo("operator.id"));
  236. ESignGlobalStatusOverviewInfo info = globalStatusOverview.getESignGlobalStatusOverviewInfo(new ObjectUuidPK(billId));
  237. PersonInfo person = info.getPerson();
  238. PersonInfo operator = info.getOperator();
  239. String personId = null;
  240. if (null != person && null != person.getId()) {
  241. personId = person.getId().toString();
  242. }
  243. String operatorId = null;
  244. if (null != operator && null != operator.getId()) {
  245. operatorId = operator.getId().toString();
  246. }
  247. if (StringUtils.isBlank(info.getSignFlowId())) {
  248. throw new EsignException("没有签署流程id");
  249. }
  250. String json = info.getRequestParams();
  251. JSONObject params = JSON.parseObject(json);
  252. Map<String, Object> jsonMap = Maps.newHashMap();
  253. Set<String> noticeSet = Sets.newHashSet();
  254. JSONArray jsonArray = params.getJSONArray("signers");
  255. if(null!=jsonArray) {
  256. for (int i = 0; i < jsonArray.size(); i++) {
  257. JSONObject param = jsonArray.getJSONObject(i);
  258. JSONObject noticeConfig = param.getJSONObject("noticeConfig");
  259. if (null != noticeConfig) {
  260. String noticeTypeStr = noticeConfig.getString("noticeTypes");
  261. if (StringUtils.isNotBlank(noticeTypeStr)) {
  262. String[] noticeTypes = noticeTypeStr.split(",");
  263. for (String nts : noticeTypes) {
  264. noticeSet.add(nts);
  265. }
  266. }
  267. }
  268. }
  269. jsonMap.put("noticeTypes", StringUtils.join(noticeSet.toArray(), ","));
  270. }else {
  271. jsonMap.put("noticeTypes", "1,2");
  272. }
  273. EsignHttpResponse httpRes = EsignHttpUtil.urge_by_file(this.getCtx(), info.getSignFlowId(), JSON.toJSONString(jsonMap), info.getEfileId());
  274. if (httpRes.getStatus() >= 200 && httpRes.getStatus() < 300) {
  275. JSONObject object = JSON.parseObject(httpRes.getBody());
  276. if ("0".equals(String.valueOf(object.get("code")))) {
  277. BatchMessageTipsBody body = new BatchMessageTipsBody();
  278. body.setMuitTipsState(Boolean.TRUE);
  279. body.setMuitTipsMessage(httpRes.getBody());
  280. body.setId(billId);
  281. batchMessageTipsHeader.addResult(body);
  282. success++;
  283. } else {
  284. BatchMessageTipsBody body = new BatchMessageTipsBody();
  285. body.setMuitTipsState(Boolean.FALSE);
  286. body.setMuitTipsMessage(httpRes.getBody());
  287. body.setId(billId);
  288. batchMessageTipsHeader.addResult(body);
  289. }
  290. } else {
  291. BatchMessageTipsBody body = new BatchMessageTipsBody();
  292. body.setMuitTipsState(Boolean.FALSE);
  293. body.setMuitTipsMessage(httpRes.getBody());
  294. body.setId(billId);
  295. batchMessageTipsHeader.addResult(body);
  296. }
  297. } catch (EsignException e) {
  298. e.printStackTrace();
  299. throw new ShrWebBizException(e);
  300. } catch (Exception e) {
  301. e.printStackTrace();
  302. throw new ShrWebBizException(e);
  303. }
  304. batchMessageTipsHeader.setBillId(billId);
  305. batchMessageTipsHeader.setFailureCount((success <= 0 ? 1 : 0));
  306. batchMessageTipsHeader.setSuccessCount(success);
  307. this.writeSuccessData(batchMessageTipsHeader);
  308. return null;
  309. }
  310. /**
  311. * 预览附件
  312. * @param request
  313. * @param response
  314. * @param modelMap
  315. * @return
  316. * @throws SHRWebException
  317. */
  318. public String previewAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  319. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  320. String billId = this.getBillId(request);
  321. String update = request.getParameter("upd");
  322. int failure = 0;
  323. int success = 0;
  324. try {
  325. if (billId.indexOf(",") >= 0) {
  326. throw new EsignException("请选择一行记录发起签署");
  327. }
  328. ISHRAttachmentExt SHRAttchExt = SHRAttachmentExtFactory.getLocalInstance(this.getCtx());
  329. IESignGlobalStatusOverview globalStatusOverview = ESignGlobalStatusOverviewFactory.getLocalInstance(this.getCtx());
  330. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  331. selectorItemCollection.add(new SelectorItemInfo("*"));
  332. selectorItemCollection.add(new SelectorItemInfo("person.id"));
  333. selectorItemCollection.add(new SelectorItemInfo("operator.id"));
  334. ESignGlobalStatusOverviewInfo info = globalStatusOverview.getESignGlobalStatusOverviewInfo(new ObjectUuidPK(billId));
  335. if (StringUtils.isBlank(info.getSignFlowId())) {
  336. throw new EsignException("没有签署流程id");
  337. }
  338. boolean canLive = false;
  339. //更新附件
  340. if ("update".equals(update)) {
  341. this.delAttachment(this.getCtx(), info);
  342. canLive = true;
  343. } else if (EsignStatusEnum.COMPLETED.equals(info.getEsignStatus())) {
  344. //成功签署的附件
  345. FilterInfo filterInfo = new FilterInfo();
  346. filterInfo.getFilterItems().add(new FilterItemInfo("propertyName", "files"));
  347. String bunding = MessageFormat.format("{0}#{1}", EsignStatusEnum.COMPLETED_VALUE, info.getSignFlowId());
  348. filterInfo.getFilterItems().add(new FilterItemInfo("bunding", bunding));
  349. filterInfo.getFilterItems().add(new FilterItemInfo("boID", info.getId().toString()));
  350. boolean canCompleted = SHRAttchExt.exists(filterInfo);
  351. //没有成功签署的附件时,更新附件
  352. if (!canCompleted) {
  353. this.delAttachment(this.getCtx(), info);
  354. canLive = true;
  355. }
  356. } else {
  357. //预览中文件会更新所以需要删除重新下载
  358. this.delAttachment(this.getCtx(), info);
  359. canLive = true;
  360. }
  361. if (canLive) {
  362. EsignHttpResponse response1 = null;
  363. if (EsignStatusEnum.COMPLETED.equals(info.getEsignStatus())) {
  364. this.saveDocsFile(info);
  365. } else {
  366. EsignHttpResponse responsesf = EsignHttpUtil.getSign_fields(this.getCtx(), info.getSignFlowId(), info.getEfileId());
  367. JSONObject params = JSON.parseObject(responsesf.getBody());
  368. if ( 0 == params.getInteger("code")) {
  369. JSONObject data = params.getJSONObject("data");
  370. JSONArray docs = data.getJSONArray("docs");
  371. this.saveDocsPreviewFile(info, docs);
  372. JSONArray attachments = data.getJSONArray("attachments");
  373. this.saveDocsPreviewFile(info, attachments);
  374. }
  375. }
  376. }
  377. BatchMessageTipsBody body = new BatchMessageTipsBody();
  378. body.setMuitTipsState(Boolean.TRUE);
  379. body.setMuitTipsMessage("成功");
  380. body.setId(billId);
  381. batchMessageTipsHeader.addResult(body);
  382. success++;
  383. } catch (EsignException e) {
  384. e.printStackTrace();
  385. throw new ShrWebBizException(e);
  386. } catch (Exception e) {
  387. e.printStackTrace();
  388. throw new ShrWebBizException(e);
  389. }
  390. batchMessageTipsHeader.setBillId(billId);
  391. batchMessageTipsHeader.setFailureCount((success <= 0 ? 1 : 0));
  392. batchMessageTipsHeader.setSuccessCount(success);
  393. this.writeSuccessData(batchMessageTipsHeader);
  394. return null;
  395. }
  396. public void saveDocsFile(ESignGlobalStatusOverviewInfo info) throws EsignException, URISyntaxException, IOException, ShrWebBizException, BOSException, EASBizException {
  397. EsignHttpResponse response1;
  398. response1 = EsignHttpUtil.getFile_download_url(this.getCtx(), info.getSignFlowId(), 3600, info.getEfileId());
  399. JSONObject jsonObject = JSON.parseObject(response1.getBody());
  400. Integer code = (Integer) jsonObject.get("code");
  401. if (code == 0) {
  402. JSONObject jsonData = jsonObject.getJSONObject("data");
  403. JSONArray files = jsonData.getJSONArray("files");
  404. if(null!=files) {
  405. for (int i = 0; i < files.size(); i++) {
  406. JSONObject fileMap = files.getJSONObject(i);
  407. this.saveAttachment(this.getCtx(), info, fileMap, "com.kingdee.eas.custom.esign.app.ESignGlobalStatusOverview.list", "files");
  408. }
  409. }
  410. JSONArray attachments = jsonData.getJSONArray("attachments");
  411. if(null!=attachments) {
  412. for (int i = 0; i < attachments.size(); i++) {
  413. JSONObject fileMap = attachments.getJSONObject(i);
  414. this.saveAttachment(this.getCtx(), info, fileMap, "com.kingdee.eas.custom.esign.app.ESignGlobalStatusOverview.list", "attachments");
  415. }
  416. }
  417. }
  418. }
  419. public void saveDocsPreviewFile(ESignGlobalStatusOverviewInfo info, JSONArray docs) throws EsignException, URISyntaxException, IOException, ShrWebBizException, BOSException, EASBizException {
  420. EsignHttpResponse response1;
  421. for (int i = 0; i < docs.size(); i++) {
  422. JSONObject doc = docs.getJSONObject(i);
  423. String fileId = doc.getString("fileId");
  424. response1 = EsignHttpUtil.getPreview_file_download_url(this.getCtx(), info.getSignFlowId(), fileId, info.getEfileId());
  425. JSONObject jsonObject = JSON.parseObject(response1.getBody());
  426. Integer code = (Integer) jsonObject.get("code");
  427. if (code == 0) {
  428. JSONObject fileMap = jsonObject.getJSONObject("data");
  429. this.saveAttachment(this.getCtx(), info, fileMap, "com.kingdee.eas.custom.esign.app.ESignGlobalStatusOverview.list", "files");
  430. }
  431. }
  432. }
  433. /**
  434. * 同步签署状态信息
  435. * @param request
  436. * @param response
  437. * @param modelMap
  438. * @return
  439. * @throws SHRWebException
  440. */
  441. public String detail_sign_fieldsAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  442. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  443. String billId = this.getBillId(request);
  444. int failure = 0;
  445. int success = 0;
  446. try {
  447. if (billId.indexOf(",") >= 0) {
  448. throw new EsignException("请选择一行记录发起签署");
  449. }
  450. IESignGlobalStatusOverview globalStatusOverview = ESignGlobalStatusOverviewFactory.getLocalInstance(this.getCtx());
  451. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  452. selectorItemCollection.add(new SelectorItemInfo("*"));
  453. selectorItemCollection.add(new SelectorItemInfo("person.id"));
  454. selectorItemCollection.add(new SelectorItemInfo("operator.id"));
  455. ESignGlobalStatusOverviewInfo info = globalStatusOverview.getESignGlobalStatusOverviewInfo(new ObjectUuidPK(billId));
  456. if (null!=info&&StringUtils.isBlank(info.getSignFlowId())) {
  457. throw new EsignException("没有签署流程id");
  458. }
  459. EsignHttpResponse res = EsignHttpUtil.getSign_fields(this.getCtx(),info.getSignFlowId(),info.getEfileId());
  460. if (res.getStatus() >= 200 && res.getStatus() < 300) {
  461. JSONObject jsonObject = JSON.parseObject(res.getBody());
  462. Integer code = (Integer) jsonObject.get("code");
  463. if (code == 0) {
  464. JSONObject jsonData = jsonObject.getJSONObject("data");
  465. String signFlowStatus = jsonData.getString("signFlowStatus");
  466. String signFlowId = jsonData.getString("signFlowId");
  467. String statusDescription = jsonData.getString("statusDescription");
  468. info.setEsignStatus(EsignStatusEnum.getEnum(Integer.parseInt(signFlowStatus)));
  469. info.setDescription(statusDescription);
  470. SelectorItemCollection selectorUpdatePartial = new SelectorItemCollection();
  471. selectorUpdatePartial.add(new SelectorItemInfo("esignStatus"));
  472. selectorUpdatePartial.add(new SelectorItemInfo("description"));
  473. globalStatusOverview.updatePartial(info,selectorUpdatePartial);
  474. }
  475. }
  476. BatchMessageTipsBody body = new BatchMessageTipsBody();
  477. body.setMuitTipsState(Boolean.TRUE);
  478. body.setMuitTipsMessage("同步状态成功");
  479. body.setId(billId);
  480. batchMessageTipsHeader.addResult(body);
  481. success++;
  482. } catch (EsignException e) {
  483. e.printStackTrace();
  484. throw new ShrWebBizException(e);
  485. } catch (Exception e) {
  486. e.printStackTrace();
  487. throw new ShrWebBizException(e);
  488. }
  489. batchMessageTipsHeader.setBillId(billId);
  490. batchMessageTipsHeader.setFailureCount((success <= 0 ? 1 : 0));
  491. batchMessageTipsHeader.setSuccessCount(success);
  492. this.writeSuccessData(batchMessageTipsHeader);
  493. return null;
  494. }
  495. /**
  496. * 同步签署完成附件
  497. * @param request
  498. * @param response
  499. * @param modelMap
  500. * @return
  501. * @throws SHRWebException
  502. */
  503. public String syncAttachmentsAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  504. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  505. String billId = this.getBillId(request);
  506. int failure = 0;
  507. int success = 0;
  508. try {
  509. if (billId.indexOf(",") >= 0) {
  510. throw new EsignException("请选择一行记录发起签署");
  511. }
  512. IESignGlobalStatusOverview globalStatusOverview = ESignGlobalStatusOverviewFactory.getLocalInstance(this.getCtx());
  513. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  514. selectorItemCollection.add(new SelectorItemInfo("*"));
  515. selectorItemCollection.add(new SelectorItemInfo("person.id"));
  516. selectorItemCollection.add(new SelectorItemInfo("operator.id"));
  517. ESignGlobalStatusOverviewInfo info = globalStatusOverview.getESignGlobalStatusOverviewInfo(new ObjectUuidPK(billId));
  518. if (StringUtils.isBlank(info.getSignFlowId())) {
  519. throw new EsignException("没有签署流程id");
  520. }
  521. // if (!info.isFivouchered()) {
  522. // throw new EsignException("电子签全域状态总览表 [{0}],签署文件已经同步,请勿重复同步");
  523. // }
  524. SyncSignedFilesUtil.syncAttachmentsForEmpPage(this.getCtx(),billId);
  525. BatchMessageTipsBody body = new BatchMessageTipsBody();
  526. body.setMuitTipsState(Boolean.TRUE);
  527. body.setMuitTipsMessage("触发同步成功");
  528. body.setId(billId);
  529. batchMessageTipsHeader.addResult(body);
  530. success++;
  531. } catch (EsignException e) {
  532. e.printStackTrace();
  533. throw new ShrWebBizException(e);
  534. } catch (Exception e) {
  535. e.printStackTrace();
  536. throw new ShrWebBizException(e);
  537. }
  538. batchMessageTipsHeader.setBillId(billId);
  539. batchMessageTipsHeader.setFailureCount((success <= 0 ? 1 : 0));
  540. batchMessageTipsHeader.setSuccessCount(success);
  541. this.writeSuccessData(batchMessageTipsHeader);
  542. return null;
  543. }
  544. private void delAttachment(Context ctx, ESignGlobalStatusOverviewInfo info) throws BOSException, EASBizException {
  545. ISHRAttachmentExt SHRAttchExt = SHRAttachmentExtFactory.getLocalInstance(ctx);
  546. IAttachment attachment = AttachmentFactory.getLocalInstance(ctx);
  547. IBoAttchAsso attchAsso = BoAttchAssoFactory.getLocalInstance(ctx);
  548. EntityViewInfo entityViewInfo = new EntityViewInfo();
  549. FilterInfo filterInfo2 = new FilterInfo();
  550. filterInfo2.getFilterItems().add(new FilterItemInfo("boID", info.getId().toString()));
  551. entityViewInfo.setFilter(filterInfo2);
  552. SHRAttachmentExtCollection collection = SHRAttchExt.getSHRAttachmentExtCollection(entityViewInfo);
  553. for (int i = 0; i < collection.size(); i++) {
  554. String attId = collection.get(i).getAttachment().getId().toString();
  555. attchAsso.delete(MessageFormat.format(" where attachment = ''{0}''", attId));
  556. attachment.delete(new ObjectUuidPK(attId));
  557. }
  558. SHRAttchExt.delete(filterInfo2);
  559. }
  560. /**
  561. * 保存附件
  562. *
  563. * @param ctx
  564. * @param info
  565. * @param fileMap
  566. * @param uipk
  567. * @param propertyName
  568. * @throws IOException
  569. * @throws ShrWebBizException
  570. * @throws BOSException
  571. * @throws EASBizException
  572. */
  573. private void saveAttachment(Context ctx, ESignGlobalStatusOverviewInfo info, JSONObject fileMap, String uipk, String propertyName) throws IOException, ShrWebBizException, BOSException, EASBizException {
  574. String fileId = fileMap.getString("fileId");
  575. String fileName = fileMap.getString("fileName");
  576. System.out.println("saveAttachment:fileMap"+fileMap);
  577. if(StringUtils.isBlank(fileName)) {
  578. fileName = info.getFileName()+".pdf";
  579. }
  580. String downloadUrl = fileMap.getString("downloadUrl");
  581. if(StringUtils.isBlank(downloadUrl)) {
  582. downloadUrl = fileMap.getString("fileDownloadUrl");
  583. }
  584. IAttachment attachment = AttachmentFactory.getLocalInstance(ctx);
  585. IBoAttchAsso attchAsso = BoAttchAssoFactory.getLocalInstance(ctx);
  586. ISHRAttachmentExt SHRAttchExt = SHRAttachmentExtFactory.getLocalInstance(ctx);
  587. byte[] content = DownloaderUtil.downloadFileToByteArray(downloadUrl);
  588. fileName = this.checkScriptAttack(fileName);
  589. if( fileName.lastIndexOf(46)<=0) {
  590. fileName +=".pdf";
  591. }
  592. String mainname = fileName.substring(0, fileName.lastIndexOf(46));
  593. String extname = fileName.substring(fileName.lastIndexOf(46) + 1, fileName.length());
  594. extname = extname.toLowerCase();
  595. if ("html".equals(extname)){
  596. extname="pdf";
  597. }
  598. SHRAttachmentExtInfo attchExt = new SHRAttachmentExtInfo();
  599. AttachmentInfo ai = new AttachmentInfo();
  600. this.setAttMulNameAndDesc(ctx, ai, mainname, fileId);
  601. ai.setSimpleName(extname);
  602. ai.setFile(content);
  603. ai.setIsShared(false);
  604. ai.setNumber(propertyName);
  605. ai.setSharedDesc(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "false"));
  606. int size = content.length;
  607. if (size < 1024) {
  608. ai.setSize(size + SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "byte"));
  609. } else {
  610. ai.setSize(size / 1024 + "KB");
  611. }
  612. ai.setSizeInByte(size);
  613. ai.setAttachID("" + System.currentTimeMillis());
  614. ai.setType(this.getFileType(mainname+"."+extname));
  615. ai.setBeizhu(uipk);
  616. attchExt.setAttachment(ai);
  617. this.setAttExtMulNameAndDesc(ctx, attchExt, mainname+"."+extname, fileId);
  618. attchExt.setPropertyName(propertyName);
  619. attchExt.setType(AttachmentTypeEnum.PROPERTY);
  620. attchExt.setState(AttachmentState.UNSAVE);
  621. String bunding = MessageFormat.format("{0}#{1}", info.getEsignStatus().getValue(), info.getSignFlowId());
  622. attchExt.setBunding(bunding);
  623. attchExt.setBoID(info.getId().toString());
  624. try {
  625. attachment.addnew(ai);
  626. } catch (Exception var20) {
  627. throw new ShrWebBizException(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "upload_error"), var20);
  628. }
  629. attchExt.setState(AttachmentState.SAVE);
  630. BoAttchAssoInfo boAttchAssoInfo = new BoAttchAssoInfo();
  631. boAttchAssoInfo.setBoID(info.getId().toString());
  632. boAttchAssoInfo.setAssoBusObjType(String.valueOf(info.getBOSType()));
  633. boAttchAssoInfo.setAssoType("Added Accessories", LocaleUtils.locale_l1);
  634. boAttchAssoInfo.setAssoType("Added Accessories", LocaleUtils.locale_l2);
  635. boAttchAssoInfo.setAssoType("Added Accessories", LocaleUtils.locale_l3);
  636. boAttchAssoInfo.setAttachment(ai);
  637. attchAsso.addnew(boAttchAssoInfo);
  638. SHRAttchExt.addnew(attchExt);
  639. }
  640. private String getFileType(String fullname) {
  641. String extname = fullname.substring(fullname.lastIndexOf(46) + 1, fullname.length());
  642. if (!"doc".equalsIgnoreCase(extname) && !"docx".equalsIgnoreCase(extname)) {
  643. if (!"xls".equalsIgnoreCase(extname) && !"xlsx".equalsIgnoreCase(extname) && !"xlsm".equalsIgnoreCase(extname) && !"xlsb".equalsIgnoreCase(extname)) {
  644. if (!"ppt".equalsIgnoreCase(extname) && !"pptx".equalsIgnoreCase(extname) && !"pptm".equalsIgnoreCase(extname)) {
  645. return "txt".equalsIgnoreCase(extname) ? SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "text") : MessageFormat.format(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "unknow_type"), extname);
  646. } else {
  647. return SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "microsoft_ppt");
  648. }
  649. } else {
  650. return SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "microsoft_excel");
  651. }
  652. } else {
  653. return SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "microsoft_word");
  654. }
  655. }
  656. private String checkScriptAttack(String str) {
  657. if (!StringUtils.isEmpty(str)) {
  658. if (str.contains("<")) {
  659. str.replaceAll("<", "&lt;");
  660. }
  661. if (str.contains(">")) {
  662. str.replaceAll(">", "&gt;");
  663. }
  664. }
  665. return str;
  666. }
  667. private void setAttMulNameAndDesc(Context ctx, AttachmentInfo att, String name, String desc) {
  668. if (att != null && !StringUtils.isEmpty(name)) {
  669. MutilanUtils.setMultiFieldValueToBean(ctx, "name", att, name);
  670. MutilanUtils.setMultiFieldValueToBean(ctx, "description", att, desc);
  671. }
  672. }
  673. private void setAttExtMulNameAndDesc(Context ctx, SHRAttachmentExtInfo info, String name, String desc) {
  674. if (info != null && !StringUtils.isEmpty(name)) {
  675. Locale locale = ctx.getLocale();
  676. info.setName(name, LocaleUtils.locale_l1);
  677. info.setDescription(desc, LocaleUtils.locale_l1);
  678. if (LocaleUtils.locale_l1.getDisplayName().equals(LocaleUtils.getLocaleString(locale))) {
  679. info.setName(name, LocaleUtils.locale_l2);
  680. info.setName(name, LocaleUtils.locale_l3);
  681. info.setDescription(desc, LocaleUtils.locale_l2);
  682. info.setDescription(desc, LocaleUtils.locale_l3);
  683. } else if (LocaleUtils.locale_l2.getDisplayName().equals(LocaleUtils.getLocaleString(locale))) {
  684. info.setName(name, LocaleUtils.locale_l2);
  685. info.setName(STConverter.sc2tc(name), LocaleUtils.locale_l3);
  686. if (!StringUtils.isEmpty(desc)) {
  687. info.setDescription(desc, LocaleUtils.locale_l2);
  688. info.setDescription(STConverter.sc2tc(desc), LocaleUtils.locale_l3);
  689. }
  690. } else {
  691. info.setName(STConverter.tc2sc(name), LocaleUtils.locale_l2);
  692. info.setName(name, LocaleUtils.locale_l3);
  693. if (!StringUtils.isEmpty(desc)) {
  694. info.setDescription(STConverter.tc2sc(desc), LocaleUtils.locale_l2);
  695. info.setDescription(desc, LocaleUtils.locale_l3);
  696. }
  697. }
  698. }
  699. }
  700. }