ESignGlobalStatusOverviewListHandler.java 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  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. for (int i = 0; i < jsonArray.size(); i++) {
  256. JSONObject param = jsonArray.getJSONObject(i);
  257. JSONObject noticeConfig = param.getJSONObject("noticeConfig");
  258. if (null != noticeConfig) {
  259. String noticeTypeStr = noticeConfig.getString("noticeTypes");
  260. if (StringUtils.isNotBlank(noticeTypeStr)) {
  261. String[] noticeTypes = noticeTypeStr.split(",");
  262. for (String nts : noticeTypes) {
  263. noticeSet.add(nts);
  264. }
  265. }
  266. }
  267. }
  268. jsonMap.put("noticeTypes", StringUtils.join(noticeSet.toArray(), ","));
  269. EsignHttpResponse httpRes = EsignHttpUtil.urge_by_file(this.getCtx(), info.getSignFlowId(), JSON.toJSONString(jsonMap), info.getEfileId());
  270. if (httpRes.getStatus() >= 200 && httpRes.getStatus() < 300) {
  271. JSONObject object = JSON.parseObject(httpRes.getBody());
  272. if ("0".equals(String.valueOf(object.get("code")))) {
  273. BatchMessageTipsBody body = new BatchMessageTipsBody();
  274. body.setMuitTipsState(Boolean.TRUE);
  275. body.setMuitTipsMessage(httpRes.getBody());
  276. body.setId(billId);
  277. batchMessageTipsHeader.addResult(body);
  278. success++;
  279. } else {
  280. BatchMessageTipsBody body = new BatchMessageTipsBody();
  281. body.setMuitTipsState(Boolean.FALSE);
  282. body.setMuitTipsMessage(httpRes.getBody());
  283. body.setId(billId);
  284. batchMessageTipsHeader.addResult(body);
  285. }
  286. } else {
  287. BatchMessageTipsBody body = new BatchMessageTipsBody();
  288. body.setMuitTipsState(Boolean.FALSE);
  289. body.setMuitTipsMessage(httpRes.getBody());
  290. body.setId(billId);
  291. batchMessageTipsHeader.addResult(body);
  292. }
  293. } catch (EsignException e) {
  294. e.printStackTrace();
  295. throw new ShrWebBizException(e);
  296. } catch (Exception e) {
  297. e.printStackTrace();
  298. throw new ShrWebBizException(e);
  299. }
  300. batchMessageTipsHeader.setBillId(billId);
  301. batchMessageTipsHeader.setFailureCount((success <= 0 ? 1 : 0));
  302. batchMessageTipsHeader.setSuccessCount(success);
  303. this.writeSuccessData(batchMessageTipsHeader);
  304. return null;
  305. }
  306. /**
  307. * 预览附件
  308. * @param request
  309. * @param response
  310. * @param modelMap
  311. * @return
  312. * @throws SHRWebException
  313. */
  314. public String previewAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  315. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  316. String billId = this.getBillId(request);
  317. String update = request.getParameter("upd");
  318. int failure = 0;
  319. int success = 0;
  320. try {
  321. if (billId.indexOf(",") >= 0) {
  322. throw new EsignException("请选择一行记录发起签署");
  323. }
  324. ISHRAttachmentExt SHRAttchExt = SHRAttachmentExtFactory.getLocalInstance(this.getCtx());
  325. IESignGlobalStatusOverview globalStatusOverview = ESignGlobalStatusOverviewFactory.getLocalInstance(this.getCtx());
  326. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  327. selectorItemCollection.add(new SelectorItemInfo("*"));
  328. selectorItemCollection.add(new SelectorItemInfo("person.id"));
  329. selectorItemCollection.add(new SelectorItemInfo("operator.id"));
  330. ESignGlobalStatusOverviewInfo info = globalStatusOverview.getESignGlobalStatusOverviewInfo(new ObjectUuidPK(billId));
  331. if (StringUtils.isBlank(info.getSignFlowId())) {
  332. throw new EsignException("没有签署流程id");
  333. }
  334. boolean canLive = false;
  335. //更新附件
  336. if ("update".equals(update)) {
  337. this.delAttachment(this.getCtx(), info);
  338. canLive = true;
  339. } else if (EsignStatusEnum.COMPLETED.equals(info.getEsignStatus())) {
  340. //成功签署的附件
  341. FilterInfo filterInfo = new FilterInfo();
  342. filterInfo.getFilterItems().add(new FilterItemInfo("propertyName", "files"));
  343. String bunding = MessageFormat.format("{0}#{1}", EsignStatusEnum.COMPLETED_VALUE, info.getSignFlowId());
  344. filterInfo.getFilterItems().add(new FilterItemInfo("bunding", bunding));
  345. filterInfo.getFilterItems().add(new FilterItemInfo("boID", info.getId().toString()));
  346. boolean canCompleted = SHRAttchExt.exists(filterInfo);
  347. //没有成功签署的附件时,更新附件
  348. if (!canCompleted) {
  349. this.delAttachment(this.getCtx(), info);
  350. canLive = true;
  351. }
  352. } else {
  353. //预览中文件会更新所以需要删除重新下载
  354. this.delAttachment(this.getCtx(), info);
  355. canLive = true;
  356. }
  357. if (canLive) {
  358. EsignHttpResponse response1 = null;
  359. if (EsignStatusEnum.COMPLETED.equals(info.getEsignStatus())) {
  360. this.saveDocsFile(info);
  361. } else {
  362. EsignHttpResponse responsesf = EsignHttpUtil.getSign_fields(this.getCtx(), info.getSignFlowId(), info.getEfileId());
  363. JSONObject params = JSON.parseObject(responsesf.getBody());
  364. if ( 0 == params.getInteger("code")) {
  365. JSONObject data = params.getJSONObject("data");
  366. JSONArray docs = data.getJSONArray("docs");
  367. this.saveDocsPreviewFile(info, docs);
  368. JSONArray attachments = data.getJSONArray("attachments");
  369. this.saveDocsPreviewFile(info, attachments);
  370. }
  371. }
  372. }
  373. BatchMessageTipsBody body = new BatchMessageTipsBody();
  374. body.setMuitTipsState(Boolean.TRUE);
  375. body.setMuitTipsMessage("成功");
  376. body.setId(billId);
  377. batchMessageTipsHeader.addResult(body);
  378. success++;
  379. } catch (EsignException e) {
  380. e.printStackTrace();
  381. throw new ShrWebBizException(e);
  382. } catch (Exception e) {
  383. e.printStackTrace();
  384. throw new ShrWebBizException(e);
  385. }
  386. batchMessageTipsHeader.setBillId(billId);
  387. batchMessageTipsHeader.setFailureCount((success <= 0 ? 1 : 0));
  388. batchMessageTipsHeader.setSuccessCount(success);
  389. this.writeSuccessData(batchMessageTipsHeader);
  390. return null;
  391. }
  392. public void saveDocsFile(ESignGlobalStatusOverviewInfo info) throws EsignException, URISyntaxException, IOException, ShrWebBizException, BOSException, EASBizException {
  393. EsignHttpResponse response1;
  394. response1 = EsignHttpUtil.getFile_download_url(this.getCtx(), info.getSignFlowId(), 3600, info.getEfileId());
  395. JSONObject jsonObject = JSON.parseObject(response1.getBody());
  396. Integer code = (Integer) jsonObject.get("code");
  397. if (code == 0) {
  398. JSONObject jsonData = jsonObject.getJSONObject("data");
  399. JSONArray files = jsonData.getJSONArray("files");
  400. if(null!=files) {
  401. for (int i = 0; i < files.size(); i++) {
  402. JSONObject fileMap = files.getJSONObject(i);
  403. this.saveAttachment(this.getCtx(), info, fileMap, "com.kingdee.eas.custom.esign.app.ESignGlobalStatusOverview.list", "files");
  404. }
  405. }
  406. JSONArray attachments = jsonData.getJSONArray("attachments");
  407. if(null!=attachments) {
  408. for (int i = 0; i < attachments.size(); i++) {
  409. JSONObject fileMap = attachments.getJSONObject(i);
  410. this.saveAttachment(this.getCtx(), info, fileMap, "com.kingdee.eas.custom.esign.app.ESignGlobalStatusOverview.list", "attachments");
  411. }
  412. }
  413. }
  414. }
  415. public void saveDocsPreviewFile(ESignGlobalStatusOverviewInfo info, JSONArray docs) throws EsignException, URISyntaxException, IOException, ShrWebBizException, BOSException, EASBizException {
  416. EsignHttpResponse response1;
  417. for (int i = 0; i < docs.size(); i++) {
  418. JSONObject doc = docs.getJSONObject(i);
  419. String fileId = doc.getString("fileId");
  420. response1 = EsignHttpUtil.getPreview_file_download_url(this.getCtx(), info.getSignFlowId(), fileId, info.getEfileId());
  421. JSONObject jsonObject = JSON.parseObject(response1.getBody());
  422. Integer code = (Integer) jsonObject.get("code");
  423. if (code == 0) {
  424. JSONObject fileMap = jsonObject.getJSONObject("data");
  425. this.saveAttachment(this.getCtx(), info, fileMap, "com.kingdee.eas.custom.esign.app.ESignGlobalStatusOverview.list", "files");
  426. }
  427. }
  428. }
  429. /**
  430. * 同步签署状态信息
  431. * @param request
  432. * @param response
  433. * @param modelMap
  434. * @return
  435. * @throws SHRWebException
  436. */
  437. public String detail_sign_fieldsAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  438. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  439. String billId = this.getBillId(request);
  440. int failure = 0;
  441. int success = 0;
  442. try {
  443. if (billId.indexOf(",") >= 0) {
  444. throw new EsignException("请选择一行记录发起签署");
  445. }
  446. IESignGlobalStatusOverview globalStatusOverview = ESignGlobalStatusOverviewFactory.getLocalInstance(this.getCtx());
  447. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  448. selectorItemCollection.add(new SelectorItemInfo("*"));
  449. selectorItemCollection.add(new SelectorItemInfo("person.id"));
  450. selectorItemCollection.add(new SelectorItemInfo("operator.id"));
  451. ESignGlobalStatusOverviewInfo info = globalStatusOverview.getESignGlobalStatusOverviewInfo(new ObjectUuidPK(billId));
  452. if (null!=info&&StringUtils.isBlank(info.getSignFlowId())) {
  453. throw new EsignException("没有签署流程id");
  454. }
  455. EsignHttpResponse res = EsignHttpUtil.getSign_fields(this.getCtx(),info.getSignFlowId(),info.getEfileId());
  456. if (res.getStatus() >= 200 && res.getStatus() < 300) {
  457. JSONObject jsonObject = JSON.parseObject(res.getBody());
  458. Integer code = (Integer) jsonObject.get("code");
  459. if (code == 0) {
  460. JSONObject jsonData = jsonObject.getJSONObject("data");
  461. String signFlowStatus = jsonData.getString("signFlowStatus");
  462. String signFlowId = jsonData.getString("signFlowId");
  463. String statusDescription = jsonData.getString("statusDescription");
  464. info.setEsignStatus(EsignStatusEnum.getEnum(Integer.parseInt(signFlowStatus)));
  465. info.setDescription(statusDescription);
  466. SelectorItemCollection selectorUpdatePartial = new SelectorItemCollection();
  467. selectorUpdatePartial.add(new SelectorItemInfo("esignStatus"));
  468. selectorUpdatePartial.add(new SelectorItemInfo("description"));
  469. globalStatusOverview.updatePartial(info,selectorUpdatePartial);
  470. }
  471. }
  472. BatchMessageTipsBody body = new BatchMessageTipsBody();
  473. body.setMuitTipsState(Boolean.TRUE);
  474. body.setMuitTipsMessage("同步状态成功");
  475. body.setId(billId);
  476. batchMessageTipsHeader.addResult(body);
  477. success++;
  478. } catch (EsignException e) {
  479. e.printStackTrace();
  480. throw new ShrWebBizException(e);
  481. } catch (Exception e) {
  482. e.printStackTrace();
  483. throw new ShrWebBizException(e);
  484. }
  485. batchMessageTipsHeader.setBillId(billId);
  486. batchMessageTipsHeader.setFailureCount((success <= 0 ? 1 : 0));
  487. batchMessageTipsHeader.setSuccessCount(success);
  488. this.writeSuccessData(batchMessageTipsHeader);
  489. return null;
  490. }
  491. /**
  492. * 同步签署完成附件
  493. * @param request
  494. * @param response
  495. * @param modelMap
  496. * @return
  497. * @throws SHRWebException
  498. */
  499. public String syncAttachmentsAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  500. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  501. String billId = this.getBillId(request);
  502. int failure = 0;
  503. int success = 0;
  504. try {
  505. if (billId.indexOf(",") >= 0) {
  506. throw new EsignException("请选择一行记录发起签署");
  507. }
  508. IESignGlobalStatusOverview globalStatusOverview = ESignGlobalStatusOverviewFactory.getLocalInstance(this.getCtx());
  509. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  510. selectorItemCollection.add(new SelectorItemInfo("*"));
  511. selectorItemCollection.add(new SelectorItemInfo("person.id"));
  512. selectorItemCollection.add(new SelectorItemInfo("operator.id"));
  513. ESignGlobalStatusOverviewInfo info = globalStatusOverview.getESignGlobalStatusOverviewInfo(new ObjectUuidPK(billId));
  514. if (StringUtils.isBlank(info.getSignFlowId())) {
  515. throw new EsignException("没有签署流程id");
  516. }
  517. // if (!info.isFivouchered()) {
  518. // throw new EsignException("电子签全域状态总览表 [{0}],签署文件已经同步,请勿重复同步");
  519. // }
  520. SyncSignedFilesUtil.syncAttachmentsForEmpPage(this.getCtx(),billId);
  521. BatchMessageTipsBody body = new BatchMessageTipsBody();
  522. body.setMuitTipsState(Boolean.TRUE);
  523. body.setMuitTipsMessage("触发同步成功");
  524. body.setId(billId);
  525. batchMessageTipsHeader.addResult(body);
  526. success++;
  527. } catch (EsignException e) {
  528. e.printStackTrace();
  529. throw new ShrWebBizException(e);
  530. } catch (Exception e) {
  531. e.printStackTrace();
  532. throw new ShrWebBizException(e);
  533. }
  534. batchMessageTipsHeader.setBillId(billId);
  535. batchMessageTipsHeader.setFailureCount((success <= 0 ? 1 : 0));
  536. batchMessageTipsHeader.setSuccessCount(success);
  537. this.writeSuccessData(batchMessageTipsHeader);
  538. return null;
  539. }
  540. private void delAttachment(Context ctx, ESignGlobalStatusOverviewInfo info) throws BOSException, EASBizException {
  541. ISHRAttachmentExt SHRAttchExt = SHRAttachmentExtFactory.getLocalInstance(ctx);
  542. IAttachment attachment = AttachmentFactory.getLocalInstance(ctx);
  543. IBoAttchAsso attchAsso = BoAttchAssoFactory.getLocalInstance(ctx);
  544. EntityViewInfo entityViewInfo = new EntityViewInfo();
  545. FilterInfo filterInfo2 = new FilterInfo();
  546. filterInfo2.getFilterItems().add(new FilterItemInfo("boID", info.getId().toString()));
  547. entityViewInfo.setFilter(filterInfo2);
  548. SHRAttachmentExtCollection collection = SHRAttchExt.getSHRAttachmentExtCollection(entityViewInfo);
  549. for (int i = 0; i < collection.size(); i++) {
  550. String attId = collection.get(i).getAttachment().getId().toString();
  551. attchAsso.delete(MessageFormat.format(" where attachment = ''{0}''", attId));
  552. attachment.delete(new ObjectUuidPK(attId));
  553. }
  554. SHRAttchExt.delete(filterInfo2);
  555. }
  556. /**
  557. * 保存附件
  558. *
  559. * @param ctx
  560. * @param info
  561. * @param fileMap
  562. * @param uipk
  563. * @param propertyName
  564. * @throws IOException
  565. * @throws ShrWebBizException
  566. * @throws BOSException
  567. * @throws EASBizException
  568. */
  569. private void saveAttachment(Context ctx, ESignGlobalStatusOverviewInfo info, JSONObject fileMap, String uipk, String propertyName) throws IOException, ShrWebBizException, BOSException, EASBizException {
  570. String fileId = fileMap.getString("fileId");
  571. String fileName = fileMap.getString("fileName");
  572. System.out.println("saveAttachment:fileMap"+fileMap);
  573. if(StringUtils.isBlank(fileName)) {
  574. fileName = info.getFileName()+".pdf";
  575. }
  576. String downloadUrl = fileMap.getString("downloadUrl");
  577. if(StringUtils.isBlank(downloadUrl)) {
  578. downloadUrl = fileMap.getString("fileDownloadUrl");
  579. }
  580. IAttachment attachment = AttachmentFactory.getLocalInstance(ctx);
  581. IBoAttchAsso attchAsso = BoAttchAssoFactory.getLocalInstance(ctx);
  582. ISHRAttachmentExt SHRAttchExt = SHRAttachmentExtFactory.getLocalInstance(ctx);
  583. byte[] content = DownloaderUtil.downloadFileToByteArray(downloadUrl);
  584. fileName = this.checkScriptAttack(fileName);
  585. if( fileName.lastIndexOf(46)<=0) {
  586. fileName +=".pdf";
  587. }
  588. String mainname = fileName.substring(0, fileName.lastIndexOf(46));
  589. String extname = fileName.substring(fileName.lastIndexOf(46) + 1, fileName.length());
  590. extname = extname.toLowerCase();
  591. if ("html".equals(extname)){
  592. extname="pdf";
  593. }
  594. SHRAttachmentExtInfo attchExt = new SHRAttachmentExtInfo();
  595. AttachmentInfo ai = new AttachmentInfo();
  596. this.setAttMulNameAndDesc(ctx, ai, mainname, fileId);
  597. ai.setSimpleName(extname);
  598. ai.setFile(content);
  599. ai.setIsShared(false);
  600. ai.setNumber(propertyName);
  601. ai.setSharedDesc(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "false"));
  602. int size = content.length;
  603. if (size < 1024) {
  604. ai.setSize(size + SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "byte"));
  605. } else {
  606. ai.setSize(size / 1024 + "KB");
  607. }
  608. ai.setSizeInByte(size);
  609. ai.setAttachID("" + System.currentTimeMillis());
  610. ai.setType(this.getFileType(mainname+"."+extname));
  611. ai.setBeizhu(uipk);
  612. attchExt.setAttachment(ai);
  613. this.setAttExtMulNameAndDesc(ctx, attchExt, mainname+"."+extname, fileId);
  614. attchExt.setPropertyName(propertyName);
  615. attchExt.setType(AttachmentTypeEnum.PROPERTY);
  616. attchExt.setState(AttachmentState.UNSAVE);
  617. String bunding = MessageFormat.format("{0}#{1}", info.getEsignStatus().getValue(), info.getSignFlowId());
  618. attchExt.setBunding(bunding);
  619. attchExt.setBoID(info.getId().toString());
  620. try {
  621. attachment.addnew(ai);
  622. } catch (Exception var20) {
  623. throw new ShrWebBizException(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "upload_error"), var20);
  624. }
  625. attchExt.setState(AttachmentState.SAVE);
  626. BoAttchAssoInfo boAttchAssoInfo = new BoAttchAssoInfo();
  627. boAttchAssoInfo.setBoID(info.getId().toString());
  628. boAttchAssoInfo.setAssoBusObjType(String.valueOf(info.getBOSType()));
  629. boAttchAssoInfo.setAssoType("Added Accessories", LocaleUtils.locale_l1);
  630. boAttchAssoInfo.setAssoType("Added Accessories", LocaleUtils.locale_l2);
  631. boAttchAssoInfo.setAssoType("Added Accessories", LocaleUtils.locale_l3);
  632. boAttchAssoInfo.setAttachment(ai);
  633. attchAsso.addnew(boAttchAssoInfo);
  634. SHRAttchExt.addnew(attchExt);
  635. }
  636. private String getFileType(String fullname) {
  637. String extname = fullname.substring(fullname.lastIndexOf(46) + 1, fullname.length());
  638. if (!"doc".equalsIgnoreCase(extname) && !"docx".equalsIgnoreCase(extname)) {
  639. if (!"xls".equalsIgnoreCase(extname) && !"xlsx".equalsIgnoreCase(extname) && !"xlsm".equalsIgnoreCase(extname) && !"xlsb".equalsIgnoreCase(extname)) {
  640. if (!"ppt".equalsIgnoreCase(extname) && !"pptx".equalsIgnoreCase(extname) && !"pptm".equalsIgnoreCase(extname)) {
  641. 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);
  642. } else {
  643. return SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "microsoft_ppt");
  644. }
  645. } else {
  646. return SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "microsoft_excel");
  647. }
  648. } else {
  649. return SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "microsoft_word");
  650. }
  651. }
  652. private String checkScriptAttack(String str) {
  653. if (!StringUtils.isEmpty(str)) {
  654. if (str.contains("<")) {
  655. str.replaceAll("<", "&lt;");
  656. }
  657. if (str.contains(">")) {
  658. str.replaceAll(">", "&gt;");
  659. }
  660. }
  661. return str;
  662. }
  663. private void setAttMulNameAndDesc(Context ctx, AttachmentInfo att, String name, String desc) {
  664. if (att != null && !StringUtils.isEmpty(name)) {
  665. MutilanUtils.setMultiFieldValueToBean(ctx, "name", att, name);
  666. MutilanUtils.setMultiFieldValueToBean(ctx, "description", att, desc);
  667. }
  668. }
  669. private void setAttExtMulNameAndDesc(Context ctx, SHRAttachmentExtInfo info, String name, String desc) {
  670. if (info != null && !StringUtils.isEmpty(name)) {
  671. Locale locale = ctx.getLocale();
  672. info.setName(name, LocaleUtils.locale_l1);
  673. info.setDescription(desc, LocaleUtils.locale_l1);
  674. if (LocaleUtils.locale_l1.getDisplayName().equals(LocaleUtils.getLocaleString(locale))) {
  675. info.setName(name, LocaleUtils.locale_l2);
  676. info.setName(name, LocaleUtils.locale_l3);
  677. info.setDescription(desc, LocaleUtils.locale_l2);
  678. info.setDescription(desc, LocaleUtils.locale_l3);
  679. } else if (LocaleUtils.locale_l2.getDisplayName().equals(LocaleUtils.getLocaleString(locale))) {
  680. info.setName(name, LocaleUtils.locale_l2);
  681. info.setName(STConverter.sc2tc(name), LocaleUtils.locale_l3);
  682. if (!StringUtils.isEmpty(desc)) {
  683. info.setDescription(desc, LocaleUtils.locale_l2);
  684. info.setDescription(STConverter.sc2tc(desc), LocaleUtils.locale_l3);
  685. }
  686. } else {
  687. info.setName(STConverter.tc2sc(name), LocaleUtils.locale_l2);
  688. info.setName(name, LocaleUtils.locale_l3);
  689. if (!StringUtils.isEmpty(desc)) {
  690. info.setDescription(STConverter.tc2sc(desc), LocaleUtils.locale_l2);
  691. info.setDescription(desc, LocaleUtils.locale_l3);
  692. }
  693. }
  694. }
  695. }
  696. }