ESignGlobalStatusOverviewListHandler.java 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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. for (int i = 0; i < files.size(); i++) {
  366. JSONObject fileMap = files.getJSONObject(i);
  367. this.saveAttachment(this.getCtx(), info, fileMap, "com.kingdee.eas.custom.esign.app.ESignGlobalStatusOverview.list", "files");
  368. }
  369. JSONArray attachments = jsonData.getJSONArray("attachments");
  370. for (int i = 0; i < attachments.size(); i++) {
  371. JSONObject fileMap = attachments.getJSONObject(i);
  372. this.saveAttachment(this.getCtx(), info, fileMap, "com.kingdee.eas.custom.esign.app.ESignGlobalStatusOverview.list", "attachments");
  373. }
  374. }
  375. } else {
  376. String json = info.getRequestParams();
  377. JSONObject params = JSON.parseObject(json);
  378. JSONArray docs = params.getJSONArray("docs");
  379. for (int i = 0; i < docs.size(); i++) {
  380. JSONObject doc = docs.getJSONObject(i);
  381. String fileId = doc.getString("fileId");
  382. response1 = EsignHttpUtil.getPreview_file_download_url(this.getCtx(), info.getSignFlowId(),fileId, info.getEfileId());
  383. JSONObject jsonObject = JSON.parseObject(response1.getBody());
  384. Integer code = (Integer) jsonObject.get("code");
  385. if (code == 0) {
  386. JSONObject fileMap = jsonObject.getJSONObject("data");
  387. this.saveAttachment(this.getCtx(), info, fileMap, "com.kingdee.eas.custom.esign.app.ESignGlobalStatusOverview.list", "files");
  388. }
  389. }
  390. }
  391. }
  392. BatchMessageTipsBody body = new BatchMessageTipsBody();
  393. body.setMuitTipsState(Boolean.TRUE);
  394. body.setMuitTipsMessage("成功");
  395. body.setId(billId);
  396. batchMessageTipsHeader.addResult(body);
  397. success++;
  398. } catch (EsignException e) {
  399. e.printStackTrace();
  400. throw new ShrWebBizException(e);
  401. } catch (Exception e) {
  402. e.printStackTrace();
  403. throw new ShrWebBizException(e);
  404. }
  405. batchMessageTipsHeader.setBillId(billId);
  406. batchMessageTipsHeader.setFailureCount((success <= 0 ? 1 : 0));
  407. batchMessageTipsHeader.setSuccessCount(success);
  408. this.writeSuccessData(batchMessageTipsHeader);
  409. return null;
  410. }
  411. /**
  412. * 同步签署状态信息
  413. * @param request
  414. * @param response
  415. * @param modelMap
  416. * @return
  417. * @throws SHRWebException
  418. */
  419. public String detail_sign_fieldsAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  420. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  421. String billId = this.getBillId(request);
  422. int failure = 0;
  423. int success = 0;
  424. try {
  425. if (billId.indexOf(",") >= 0) {
  426. throw new EsignException("请选择一行记录发起签署");
  427. }
  428. IESignGlobalStatusOverview globalStatusOverview = ESignGlobalStatusOverviewFactory.getLocalInstance(this.getCtx());
  429. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  430. selectorItemCollection.add(new SelectorItemInfo("*"));
  431. selectorItemCollection.add(new SelectorItemInfo("person.id"));
  432. selectorItemCollection.add(new SelectorItemInfo("operator.id"));
  433. ESignGlobalStatusOverviewInfo info = globalStatusOverview.getESignGlobalStatusOverviewInfo(new ObjectUuidPK(billId));
  434. if (null!=info&&StringUtils.isBlank(info.getSignFlowId())) {
  435. throw new EsignException("没有签署流程id");
  436. }
  437. EsignHttpResponse res = EsignHttpUtil.getSign_fields(this.getCtx(),info.getSignFlowId(),info.getEfileId());
  438. if (res.getStatus() >= 200 && res.getStatus() < 300) {
  439. JSONObject jsonObject = JSON.parseObject(res.getBody());
  440. Integer code = (Integer) jsonObject.get("code");
  441. if (code == 0) {
  442. JSONObject jsonData = jsonObject.getJSONObject("data");
  443. String signFlowStatus = jsonData.getString("signFlowStatus");
  444. String signFlowId = jsonData.getString("signFlowId");
  445. String statusDescription = jsonData.getString("statusDescription");
  446. info.setEsignStatus(EsignStatusEnum.getEnum(Integer.parseInt(signFlowStatus)));
  447. info.setDescription(statusDescription);
  448. SelectorItemCollection selectorUpdatePartial = new SelectorItemCollection();
  449. selectorUpdatePartial.add(new SelectorItemInfo("esignStatus"));
  450. selectorUpdatePartial.add(new SelectorItemInfo("description"));
  451. globalStatusOverview.updatePartial(info,selectorUpdatePartial);
  452. }
  453. }
  454. BatchMessageTipsBody body = new BatchMessageTipsBody();
  455. body.setMuitTipsState(Boolean.TRUE);
  456. body.setMuitTipsMessage("同步状态成功");
  457. body.setId(billId);
  458. batchMessageTipsHeader.addResult(body);
  459. success++;
  460. } catch (EsignException e) {
  461. e.printStackTrace();
  462. throw new ShrWebBizException(e);
  463. } catch (Exception e) {
  464. e.printStackTrace();
  465. throw new ShrWebBizException(e);
  466. }
  467. batchMessageTipsHeader.setBillId(billId);
  468. batchMessageTipsHeader.setFailureCount((success <= 0 ? 1 : 0));
  469. batchMessageTipsHeader.setSuccessCount(success);
  470. this.writeSuccessData(batchMessageTipsHeader);
  471. return null;
  472. }
  473. /**
  474. * 同步签署完成附件
  475. * @param request
  476. * @param response
  477. * @param modelMap
  478. * @return
  479. * @throws SHRWebException
  480. */
  481. public String syncAttachmentsAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  482. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  483. String billId = this.getBillId(request);
  484. int failure = 0;
  485. int success = 0;
  486. try {
  487. if (billId.indexOf(",") >= 0) {
  488. throw new EsignException("请选择一行记录发起签署");
  489. }
  490. IESignGlobalStatusOverview globalStatusOverview = ESignGlobalStatusOverviewFactory.getLocalInstance(this.getCtx());
  491. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  492. selectorItemCollection.add(new SelectorItemInfo("*"));
  493. selectorItemCollection.add(new SelectorItemInfo("person.id"));
  494. selectorItemCollection.add(new SelectorItemInfo("operator.id"));
  495. ESignGlobalStatusOverviewInfo info = globalStatusOverview.getESignGlobalStatusOverviewInfo(new ObjectUuidPK(billId));
  496. if (StringUtils.isBlank(info.getSignFlowId())) {
  497. throw new EsignException("没有签署流程id");
  498. }
  499. // if (!info.isFivouchered()) {
  500. // throw new EsignException("电子签全域状态总览表 [{0}],签署文件已经同步,请勿重复同步");
  501. // }
  502. SyncSignedFilesUtil.syncAttachmentsForEmpPage(this.getCtx(),billId);
  503. BatchMessageTipsBody body = new BatchMessageTipsBody();
  504. body.setMuitTipsState(Boolean.TRUE);
  505. body.setMuitTipsMessage("触发同步成功");
  506. body.setId(billId);
  507. batchMessageTipsHeader.addResult(body);
  508. success++;
  509. } catch (EsignException e) {
  510. e.printStackTrace();
  511. throw new ShrWebBizException(e);
  512. } catch (Exception e) {
  513. e.printStackTrace();
  514. throw new ShrWebBizException(e);
  515. }
  516. batchMessageTipsHeader.setBillId(billId);
  517. batchMessageTipsHeader.setFailureCount((success <= 0 ? 1 : 0));
  518. batchMessageTipsHeader.setSuccessCount(success);
  519. this.writeSuccessData(batchMessageTipsHeader);
  520. return null;
  521. }
  522. private void delAttachment(Context ctx, ESignGlobalStatusOverviewInfo info) throws BOSException, EASBizException {
  523. ISHRAttachmentExt SHRAttchExt = SHRAttachmentExtFactory.getLocalInstance(ctx);
  524. IAttachment attachment = AttachmentFactory.getLocalInstance(ctx);
  525. IBoAttchAsso attchAsso = BoAttchAssoFactory.getLocalInstance(ctx);
  526. EntityViewInfo entityViewInfo = new EntityViewInfo();
  527. FilterInfo filterInfo2 = new FilterInfo();
  528. filterInfo2.getFilterItems().add(new FilterItemInfo("boID", info.getId().toString()));
  529. entityViewInfo.setFilter(filterInfo2);
  530. SHRAttachmentExtCollection collection = SHRAttchExt.getSHRAttachmentExtCollection(entityViewInfo);
  531. for (int i = 0; i < collection.size(); i++) {
  532. String attId = collection.get(i).getAttachment().getId().toString();
  533. attchAsso.delete(MessageFormat.format(" where attachment = ''{0}''", attId));
  534. attachment.delete(new ObjectUuidPK(attId));
  535. }
  536. SHRAttchExt.delete(filterInfo2);
  537. }
  538. /**
  539. * 保存附件
  540. *
  541. * @param ctx
  542. * @param info
  543. * @param fileMap
  544. * @param uipk
  545. * @param propertyName
  546. * @throws IOException
  547. * @throws ShrWebBizException
  548. * @throws BOSException
  549. * @throws EASBizException
  550. */
  551. private void saveAttachment(Context ctx, ESignGlobalStatusOverviewInfo info, JSONObject fileMap, String uipk, String propertyName) throws IOException, ShrWebBizException, BOSException, EASBizException {
  552. String fileId = fileMap.getString("fileId");
  553. String fileName = fileMap.getString("fileName");
  554. String downloadUrl = fileMap.getString("downloadUrl");
  555. if(StringUtils.isBlank(downloadUrl)) {
  556. downloadUrl = fileMap.getString("fileDownloadUrl");
  557. }
  558. IAttachment attachment = AttachmentFactory.getLocalInstance(ctx);
  559. IBoAttchAsso attchAsso = BoAttchAssoFactory.getLocalInstance(ctx);
  560. ISHRAttachmentExt SHRAttchExt = SHRAttachmentExtFactory.getLocalInstance(ctx);
  561. byte[] content = DownloaderUtil.downloadFileToByteArray(downloadUrl);
  562. fileName = this.checkScriptAttack(fileName);
  563. String mainname = fileName.substring(0, fileName.lastIndexOf(46));
  564. String extname = fileName.substring(fileName.lastIndexOf(46) + 1, fileName.length());
  565. extname = extname.toLowerCase();
  566. SHRAttachmentExtInfo attchExt = new SHRAttachmentExtInfo();
  567. AttachmentInfo ai = new AttachmentInfo();
  568. this.setAttMulNameAndDesc(ctx, ai, mainname, fileId);
  569. ai.setSimpleName(extname);
  570. ai.setFile(content);
  571. ai.setIsShared(false);
  572. ai.setNumber(propertyName);
  573. ai.setSharedDesc(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "false"));
  574. int size = content.length;
  575. if (size < 1024) {
  576. ai.setSize(size + SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "byte"));
  577. } else {
  578. ai.setSize(size / 1024 + "KB");
  579. }
  580. ai.setSizeInByte(size);
  581. ai.setAttachID("" + System.currentTimeMillis());
  582. ai.setType(this.getFileType(fileName));
  583. ai.setBeizhu(uipk);
  584. attchExt.setAttachment(ai);
  585. this.setAttExtMulNameAndDesc(ctx, attchExt, fileName, fileId);
  586. attchExt.setPropertyName(propertyName);
  587. attchExt.setType(AttachmentTypeEnum.PROPERTY);
  588. attchExt.setState(AttachmentState.UNSAVE);
  589. String bunding = MessageFormat.format("{0}#{1}", info.getEsignStatus().getValue(), info.getSignFlowId());
  590. attchExt.setBunding(bunding);
  591. attchExt.setBoID(info.getId().toString());
  592. try {
  593. attachment.addnew(ai);
  594. } catch (Exception var20) {
  595. throw new ShrWebBizException(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "upload_error"), var20);
  596. }
  597. attchExt.setState(AttachmentState.SAVE);
  598. BoAttchAssoInfo boAttchAssoInfo = new BoAttchAssoInfo();
  599. boAttchAssoInfo.setBoID(info.getId().toString());
  600. boAttchAssoInfo.setAssoBusObjType(String.valueOf(info.getBOSType()));
  601. boAttchAssoInfo.setAssoType("Added Accessories", LocaleUtils.locale_l1);
  602. boAttchAssoInfo.setAssoType("Added Accessories", LocaleUtils.locale_l2);
  603. boAttchAssoInfo.setAssoType("Added Accessories", LocaleUtils.locale_l3);
  604. boAttchAssoInfo.setAttachment(ai);
  605. attchAsso.addnew(boAttchAssoInfo);
  606. SHRAttchExt.addnew(attchExt);
  607. }
  608. private String getFileType(String fullname) {
  609. String extname = fullname.substring(fullname.lastIndexOf(46) + 1, fullname.length());
  610. if (!"doc".equalsIgnoreCase(extname) && !"docx".equalsIgnoreCase(extname)) {
  611. if (!"xls".equalsIgnoreCase(extname) && !"xlsx".equalsIgnoreCase(extname) && !"xlsm".equalsIgnoreCase(extname) && !"xlsb".equalsIgnoreCase(extname)) {
  612. if (!"ppt".equalsIgnoreCase(extname) && !"pptx".equalsIgnoreCase(extname) && !"pptm".equalsIgnoreCase(extname)) {
  613. 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);
  614. } else {
  615. return SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "microsoft_ppt");
  616. }
  617. } else {
  618. return SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "microsoft_excel");
  619. }
  620. } else {
  621. return SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "microsoft_word");
  622. }
  623. }
  624. private String checkScriptAttack(String str) {
  625. if (!StringUtils.isEmpty(str)) {
  626. if (str.contains("<")) {
  627. str.replaceAll("<", "&lt;");
  628. }
  629. if (str.contains(">")) {
  630. str.replaceAll(">", "&gt;");
  631. }
  632. }
  633. return str;
  634. }
  635. private void setAttMulNameAndDesc(Context ctx, AttachmentInfo att, String name, String desc) {
  636. if (att != null && !StringUtils.isEmpty(name)) {
  637. MutilanUtils.setMultiFieldValueToBean(ctx, "name", att, name);
  638. MutilanUtils.setMultiFieldValueToBean(ctx, "description", att, desc);
  639. }
  640. }
  641. private void setAttExtMulNameAndDesc(Context ctx, SHRAttachmentExtInfo info, String name, String desc) {
  642. if (info != null && !StringUtils.isEmpty(name)) {
  643. Locale locale = ctx.getLocale();
  644. info.setName(name, LocaleUtils.locale_l1);
  645. info.setDescription(desc, LocaleUtils.locale_l1);
  646. if (LocaleUtils.locale_l1.getDisplayName().equals(LocaleUtils.getLocaleString(locale))) {
  647. info.setName(name, LocaleUtils.locale_l2);
  648. info.setName(name, LocaleUtils.locale_l3);
  649. info.setDescription(desc, LocaleUtils.locale_l2);
  650. info.setDescription(desc, LocaleUtils.locale_l3);
  651. } else if (LocaleUtils.locale_l2.getDisplayName().equals(LocaleUtils.getLocaleString(locale))) {
  652. info.setName(name, LocaleUtils.locale_l2);
  653. info.setName(STConverter.sc2tc(name), LocaleUtils.locale_l3);
  654. if (!StringUtils.isEmpty(desc)) {
  655. info.setDescription(desc, LocaleUtils.locale_l2);
  656. info.setDescription(STConverter.sc2tc(desc), LocaleUtils.locale_l3);
  657. }
  658. } else {
  659. info.setName(STConverter.tc2sc(name), LocaleUtils.locale_l2);
  660. info.setName(name, LocaleUtils.locale_l3);
  661. if (!StringUtils.isEmpty(desc)) {
  662. info.setDescription(STConverter.tc2sc(desc), LocaleUtils.locale_l2);
  663. info.setDescription(desc, LocaleUtils.locale_l3);
  664. }
  665. }
  666. }
  667. }
  668. }