ESignGlobalStatusOverviewListHandler.java 34 KB

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