ESignGlobalStatusOverviewListHandler.java 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  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. boolean isSess = false;
  177. EsignHttpResponse httpRes = EsignHttpUtil.sign_flow_rescind(this.getCtx(), info.getSignFlowId(), info.getEfileId());
  178. if (httpRes.getStatus() >= 200 && httpRes.getStatus() < 300) {
  179. JSONObject object = JSON.parseObject(httpRes.getBody());
  180. if ("0".equals(String.valueOf(object.get("code")))) {
  181. BatchMessageTipsBody body = new BatchMessageTipsBody();
  182. body.setMuitTipsState(Boolean.TRUE);
  183. body.setMuitTipsMessage(httpRes.getBody());
  184. body.setId(billId);
  185. batchMessageTipsHeader.addResult(body);
  186. info.setEsignStatus(EsignStatusEnum.REVOKED);
  187. globalStatusOverview.save(info);
  188. success++;
  189. isSess = true;
  190. } else {
  191. isSess = false;
  192. }
  193. } else {
  194. isSess = false;
  195. }
  196. if (!isSess) {
  197. httpRes = EsignHttpUtil.revoke_by_file(this.getCtx(), info.getSignFlowId(), revokeReason, info.getEfileId());
  198. if (httpRes.getStatus() >= 200 && httpRes.getStatus() < 300) {
  199. JSONObject object = JSON.parseObject(httpRes.getBody());
  200. if ("0".equals(String.valueOf(object.get("code")))) {
  201. BatchMessageTipsBody body = new BatchMessageTipsBody();
  202. body.setMuitTipsState(Boolean.TRUE);
  203. body.setMuitTipsMessage(httpRes.getBody());
  204. body.setId(billId);
  205. batchMessageTipsHeader.addResult(body);
  206. info.setEsignStatus(EsignStatusEnum.REVOKED);
  207. globalStatusOverview.save(info);
  208. success++;
  209. } else {
  210. if(httpRes.getBody().indexOf("流程不存在:")>0){
  211. BatchMessageTipsBody body = new BatchMessageTipsBody();
  212. body.setMuitTipsState(Boolean.TRUE);
  213. body.setMuitTipsMessage(httpRes.getBody());
  214. body.setId(billId);
  215. batchMessageTipsHeader.addResult(body);
  216. info.setEsignStatus(EsignStatusEnum.REVOKED);
  217. globalStatusOverview.save(info);
  218. success++;
  219. }else {
  220. BatchMessageTipsBody body = new BatchMessageTipsBody();
  221. body.setMuitTipsState(Boolean.FALSE);
  222. body.setMuitTipsMessage(httpRes.getBody());
  223. body.setId(billId);
  224. batchMessageTipsHeader.addResult(body);
  225. }
  226. }
  227. } else {
  228. BatchMessageTipsBody body = new BatchMessageTipsBody();
  229. body.setMuitTipsState(Boolean.FALSE);
  230. body.setMuitTipsMessage(httpRes.getBody());
  231. body.setId(billId);
  232. batchMessageTipsHeader.addResult(body);
  233. }
  234. }
  235. } catch (EsignException e) {
  236. e.printStackTrace();
  237. throw new ShrWebBizException(e);
  238. } catch (Exception e) {
  239. e.printStackTrace();
  240. throw new ShrWebBizException(e);
  241. }
  242. batchMessageTipsHeader.setBillId(billId);
  243. batchMessageTipsHeader.setFailureCount((success <= 0 ? 1 : 0));
  244. batchMessageTipsHeader.setSuccessCount(success);
  245. this.writeSuccessData(batchMessageTipsHeader);
  246. return null;
  247. }
  248. /**
  249. * 催签流程中签署人
  250. *
  251. * @param request
  252. * @param response
  253. * @param modelMap
  254. * @return
  255. * @throws SHRWebException
  256. */
  257. public String urge_by_fileAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  258. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  259. String billId = this.getBillId(request);
  260. int failure = 0;
  261. int success = 0;
  262. try {
  263. if (billId.indexOf(",") >= 0) {
  264. throw new EsignException("请选择一行记录发起签署");
  265. }
  266. IESignGlobalStatusOverview globalStatusOverview = ESignGlobalStatusOverviewFactory.getLocalInstance(this.getCtx());
  267. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  268. selectorItemCollection.add(new SelectorItemInfo("*"));
  269. selectorItemCollection.add(new SelectorItemInfo("person.id"));
  270. selectorItemCollection.add(new SelectorItemInfo("operator.id"));
  271. ESignGlobalStatusOverviewInfo info = globalStatusOverview.getESignGlobalStatusOverviewInfo(new ObjectUuidPK(billId));
  272. PersonInfo person = info.getPerson();
  273. PersonInfo operator = info.getOperator();
  274. String personId = null;
  275. if (null != person && null != person.getId()) {
  276. personId = person.getId().toString();
  277. }
  278. String operatorId = null;
  279. if (null != operator && null != operator.getId()) {
  280. operatorId = operator.getId().toString();
  281. }
  282. if (StringUtils.isBlank(info.getSignFlowId())) {
  283. throw new EsignException("没有签署流程id");
  284. }
  285. boolean isSess=false;
  286. EsignHttpResponse httpRes = EsignHttpUtil.urge_filling(this.getCtx(), info.getSignFlowId(), null,info.getEfileId());
  287. if (httpRes.getStatus() >= 200 && httpRes.getStatus() < 300) {
  288. JSONObject object = JSON.parseObject(httpRes.getBody());
  289. if ("0".equals(String.valueOf(object.get("code")))) {
  290. BatchMessageTipsBody body = new BatchMessageTipsBody();
  291. body.setMuitTipsState(Boolean.TRUE);
  292. body.setMuitTipsMessage(httpRes.getBody());
  293. body.setId(billId);
  294. batchMessageTipsHeader.addResult(body);
  295. success++;
  296. isSess=true;
  297. } else {
  298. if("催办一次".equals(String.valueOf(object.get("message")))) {
  299. BatchMessageTipsBody body = new BatchMessageTipsBody();
  300. body.setMuitTipsState(Boolean.FALSE);
  301. body.setMuitTipsMessage(httpRes.getBody());
  302. body.setId(billId);
  303. batchMessageTipsHeader.addResult(body);
  304. //{"code":1451001,"message":"重复催办: 您刚刚催办过,发起半小时后每十分钟仅可催办一次。","data":null}
  305. isSess = true;
  306. }else {
  307. isSess = false;
  308. }
  309. }
  310. } else {
  311. isSess=false;
  312. }
  313. if(!isSess) {
  314. String json = info.getRequestParams();
  315. JSONObject params = JSON.parseObject(json);
  316. Map<String, Object> jsonMap = Maps.newHashMap();
  317. Set<String> noticeSet = Sets.newHashSet();
  318. JSONArray jsonArray = params.getJSONArray("signers");
  319. if (null != jsonArray) {
  320. for (int i = 0; i < jsonArray.size(); i++) {
  321. JSONObject param = jsonArray.getJSONObject(i);
  322. JSONObject noticeConfig = param.getJSONObject("noticeConfig");
  323. if (null != noticeConfig) {
  324. String noticeTypeStr = noticeConfig.getString("noticeTypes");
  325. if (StringUtils.isNotBlank(noticeTypeStr)) {
  326. String[] noticeTypes = noticeTypeStr.split(",");
  327. for (String nts : noticeTypes) {
  328. noticeSet.add(nts);
  329. }
  330. }
  331. }
  332. }
  333. jsonMap.put("noticeTypes", StringUtils.join(noticeSet.toArray(), ","));
  334. } else {
  335. jsonMap.put("noticeTypes", "1,2");
  336. }
  337. httpRes = EsignHttpUtil.urge_by_file(this.getCtx(), info.getSignFlowId(), JSON.toJSONString(jsonMap), info.getEfileId());
  338. if (httpRes.getStatus() >= 200 && httpRes.getStatus() < 300) {
  339. JSONObject object = JSON.parseObject(httpRes.getBody());
  340. if ("0".equals(String.valueOf(object.get("code")))) {
  341. BatchMessageTipsBody body = new BatchMessageTipsBody();
  342. body.setMuitTipsState(Boolean.TRUE);
  343. body.setMuitTipsMessage(httpRes.getBody());
  344. body.setId(billId);
  345. batchMessageTipsHeader.addResult(body);
  346. success++;
  347. } else {
  348. BatchMessageTipsBody body = new BatchMessageTipsBody();
  349. body.setMuitTipsState(Boolean.FALSE);
  350. body.setMuitTipsMessage(httpRes.getBody());
  351. body.setId(billId);
  352. batchMessageTipsHeader.addResult(body);
  353. }
  354. } else {
  355. BatchMessageTipsBody body = new BatchMessageTipsBody();
  356. body.setMuitTipsState(Boolean.FALSE);
  357. body.setMuitTipsMessage(httpRes.getBody());
  358. body.setId(billId);
  359. batchMessageTipsHeader.addResult(body);
  360. }
  361. }
  362. } catch (EsignException e) {
  363. e.printStackTrace();
  364. throw new ShrWebBizException(e);
  365. } catch (Exception e) {
  366. e.printStackTrace();
  367. throw new ShrWebBizException(e);
  368. }
  369. batchMessageTipsHeader.setBillId(billId);
  370. batchMessageTipsHeader.setFailureCount((success <= 0 ? 1 : 0));
  371. batchMessageTipsHeader.setSuccessCount(success);
  372. this.writeSuccessData(batchMessageTipsHeader);
  373. return null;
  374. }
  375. /**
  376. * 预览附件
  377. *
  378. * @param request
  379. * @param response
  380. * @param modelMap
  381. * @return
  382. * @throws SHRWebException
  383. */
  384. public String previewAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  385. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  386. String billId = this.getBillId(request);
  387. String update = request.getParameter("upd");
  388. int failure = 0;
  389. int success = 0;
  390. try {
  391. if (billId.indexOf(",") >= 0) {
  392. throw new EsignException("请选择一行记录发起签署");
  393. }
  394. ISHRAttachmentExt SHRAttchExt = SHRAttachmentExtFactory.getLocalInstance(this.getCtx());
  395. IESignGlobalStatusOverview globalStatusOverview = ESignGlobalStatusOverviewFactory.getLocalInstance(this.getCtx());
  396. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  397. selectorItemCollection.add(new SelectorItemInfo("*"));
  398. selectorItemCollection.add(new SelectorItemInfo("person.id"));
  399. selectorItemCollection.add(new SelectorItemInfo("operator.id"));
  400. ESignGlobalStatusOverviewInfo info = globalStatusOverview.getESignGlobalStatusOverviewInfo(new ObjectUuidPK(billId));
  401. if (StringUtils.isBlank(info.getSignFlowId())) {
  402. throw new EsignException("没有签署流程id");
  403. }
  404. boolean canLive = false;
  405. //更新附件
  406. if ("update".equals(update)) {
  407. this.delAttachment(this.getCtx(), info);
  408. canLive = true;
  409. } else if (EsignStatusEnum.COMPLETED.equals(info.getEsignStatus())) {
  410. //成功签署的附件
  411. FilterInfo filterInfo = new FilterInfo();
  412. filterInfo.getFilterItems().add(new FilterItemInfo("propertyName", "files"));
  413. String bunding = MessageFormat.format("{0}#{1}", EsignStatusEnum.COMPLETED_VALUE, info.getSignFlowId());
  414. filterInfo.getFilterItems().add(new FilterItemInfo("bunding", bunding));
  415. filterInfo.getFilterItems().add(new FilterItemInfo("boID", info.getId().toString()));
  416. boolean canCompleted = SHRAttchExt.exists(filterInfo);
  417. //没有成功签署的附件时,更新附件
  418. if (!canCompleted) {
  419. this.delAttachment(this.getCtx(), info);
  420. canLive = true;
  421. }
  422. } else {
  423. //预览中文件会更新所以需要删除重新下载
  424. this.delAttachment(this.getCtx(), info);
  425. canLive = true;
  426. }
  427. if (canLive) {
  428. EsignHttpResponse response1 = null;
  429. if (EsignStatusEnum.COMPLETED.equals(info.getEsignStatus())) {
  430. this.saveDocsFile(info);
  431. } else {
  432. EsignHttpResponse responsesf = EsignHttpUtil.getSign_fields(this.getCtx(), info.getSignFlowId(), info.getEfileId());
  433. JSONObject params = JSON.parseObject(responsesf.getBody());
  434. if (0 == params.getInteger("code")) {
  435. JSONObject data = params.getJSONObject("data");
  436. JSONArray docs = data.getJSONArray("docs");
  437. this.saveDocsPreviewFile(info, docs);
  438. JSONArray attachments = data.getJSONArray("attachments");
  439. this.saveDocsPreviewFile(info, attachments);
  440. }
  441. }
  442. }
  443. BatchMessageTipsBody body = new BatchMessageTipsBody();
  444. body.setMuitTipsState(Boolean.TRUE);
  445. body.setMuitTipsMessage("成功");
  446. body.setId(billId);
  447. batchMessageTipsHeader.addResult(body);
  448. success++;
  449. } catch (EsignException e) {
  450. e.printStackTrace();
  451. throw new ShrWebBizException(e);
  452. } catch (Exception e) {
  453. e.printStackTrace();
  454. throw new ShrWebBizException(e);
  455. }
  456. batchMessageTipsHeader.setBillId(billId);
  457. batchMessageTipsHeader.setFailureCount((success <= 0 ? 1 : 0));
  458. batchMessageTipsHeader.setSuccessCount(success);
  459. this.writeSuccessData(batchMessageTipsHeader);
  460. return null;
  461. }
  462. public void saveDocsFile(ESignGlobalStatusOverviewInfo info) throws EsignException, URISyntaxException, IOException, ShrWebBizException, BOSException, EASBizException {
  463. EsignHttpResponse response1;
  464. response1 = EsignHttpUtil.getFile_download_url(this.getCtx(), info.getSignFlowId(), 3600, info.getEfileId());
  465. JSONObject jsonObject = JSON.parseObject(response1.getBody());
  466. Integer code = (Integer) jsonObject.get("code");
  467. if (code == 0) {
  468. JSONObject jsonData = jsonObject.getJSONObject("data");
  469. JSONArray files = jsonData.getJSONArray("files");
  470. if (null != files) {
  471. for (int i = 0; i < files.size(); i++) {
  472. JSONObject fileMap = files.getJSONObject(i);
  473. this.saveAttachment(this.getCtx(), info, fileMap, "com.kingdee.eas.custom.esign.app.ESignGlobalStatusOverview.list", "files");
  474. }
  475. }
  476. JSONArray attachments = jsonData.getJSONArray("attachments");
  477. if (null != attachments) {
  478. for (int i = 0; i < attachments.size(); i++) {
  479. JSONObject fileMap = attachments.getJSONObject(i);
  480. this.saveAttachment(this.getCtx(), info, fileMap, "com.kingdee.eas.custom.esign.app.ESignGlobalStatusOverview.list", "attachments");
  481. }
  482. }
  483. }
  484. }
  485. public void saveDocsPreviewFile(ESignGlobalStatusOverviewInfo info, JSONArray docs) throws EsignException, URISyntaxException, IOException, ShrWebBizException, BOSException, EASBizException {
  486. EsignHttpResponse response1;
  487. for (int i = 0; i < docs.size(); i++) {
  488. JSONObject doc = docs.getJSONObject(i);
  489. String fileId = doc.getString("fileId");
  490. response1 = EsignHttpUtil.getPreview_file_download_url(this.getCtx(), info.getSignFlowId(), fileId, info.getEfileId());
  491. JSONObject jsonObject = JSON.parseObject(response1.getBody());
  492. Integer code = (Integer) jsonObject.get("code");
  493. if (code == 0) {
  494. JSONObject fileMap = jsonObject.getJSONObject("data");
  495. this.saveAttachment(this.getCtx(), info, fileMap, "com.kingdee.eas.custom.esign.app.ESignGlobalStatusOverview.list", "files");
  496. }
  497. }
  498. }
  499. /**
  500. * 同步签署状态信息
  501. *
  502. * @param request
  503. * @param response
  504. * @param modelMap
  505. * @return
  506. * @throws SHRWebException
  507. */
  508. public String detail_sign_fieldsAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  509. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  510. String billId = this.getBillId(request);
  511. int failure = 0;
  512. int success = 0;
  513. try {
  514. if (billId.indexOf(",") >= 0) {
  515. throw new EsignException("请选择一行记录发起签署");
  516. }
  517. IESignGlobalStatusOverview globalStatusOverview = ESignGlobalStatusOverviewFactory.getLocalInstance(this.getCtx());
  518. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  519. selectorItemCollection.add(new SelectorItemInfo("*"));
  520. selectorItemCollection.add(new SelectorItemInfo("person.id"));
  521. selectorItemCollection.add(new SelectorItemInfo("operator.id"));
  522. ESignGlobalStatusOverviewInfo info = globalStatusOverview.getESignGlobalStatusOverviewInfo(new ObjectUuidPK(billId));
  523. if (null != info && StringUtils.isBlank(info.getSignFlowId())) {
  524. throw new EsignException("没有签署流程id");
  525. }
  526. EsignHttpResponse res = EsignHttpUtil.getSign_fields(this.getCtx(), info.getSignFlowId(), info.getEfileId());
  527. if (res.getStatus() >= 200 && res.getStatus() < 300) {
  528. JSONObject jsonObject = JSON.parseObject(res.getBody());
  529. Integer code = (Integer) jsonObject.get("code");
  530. if (code == 0) {
  531. JSONObject jsonData = jsonObject.getJSONObject("data");
  532. String signFlowStatus = jsonData.getString("signFlowStatus");
  533. String signFlowId = jsonData.getString("signFlowId");
  534. String statusDescription = jsonData.getString("statusDescription");
  535. info.setEsignStatus(EsignStatusEnum.getEnum(Integer.parseInt(signFlowStatus)));
  536. info.setDescription(statusDescription);
  537. SelectorItemCollection selectorUpdatePartial = new SelectorItemCollection();
  538. selectorUpdatePartial.add(new SelectorItemInfo("esignStatus"));
  539. selectorUpdatePartial.add(new SelectorItemInfo("description"));
  540. globalStatusOverview.updatePartial(info, selectorUpdatePartial);
  541. }
  542. }
  543. BatchMessageTipsBody body = new BatchMessageTipsBody();
  544. body.setMuitTipsState(Boolean.TRUE);
  545. body.setMuitTipsMessage("同步状态成功");
  546. body.setId(billId);
  547. batchMessageTipsHeader.addResult(body);
  548. success++;
  549. } catch (EsignException e) {
  550. e.printStackTrace();
  551. throw new ShrWebBizException(e);
  552. } catch (Exception e) {
  553. e.printStackTrace();
  554. throw new ShrWebBizException(e);
  555. }
  556. batchMessageTipsHeader.setBillId(billId);
  557. batchMessageTipsHeader.setFailureCount((success <= 0 ? 1 : 0));
  558. batchMessageTipsHeader.setSuccessCount(success);
  559. this.writeSuccessData(batchMessageTipsHeader);
  560. return null;
  561. }
  562. /**
  563. * 同步签署完成附件
  564. *
  565. * @param request
  566. * @param response
  567. * @param modelMap
  568. * @return
  569. * @throws SHRWebException
  570. */
  571. public String syncAttachmentsAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  572. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  573. String billId = this.getBillId(request);
  574. int failure = 0;
  575. int success = 0;
  576. try {
  577. if (billId.indexOf(",") >= 0) {
  578. throw new EsignException("请选择一行记录发起签署");
  579. }
  580. IESignGlobalStatusOverview globalStatusOverview = ESignGlobalStatusOverviewFactory.getLocalInstance(this.getCtx());
  581. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  582. selectorItemCollection.add(new SelectorItemInfo("*"));
  583. selectorItemCollection.add(new SelectorItemInfo("person.id"));
  584. selectorItemCollection.add(new SelectorItemInfo("operator.id"));
  585. ESignGlobalStatusOverviewInfo info = globalStatusOverview.getESignGlobalStatusOverviewInfo(new ObjectUuidPK(billId));
  586. if (StringUtils.isBlank(info.getSignFlowId())) {
  587. throw new EsignException("没有签署流程id");
  588. }
  589. // if (!info.isFivouchered()) {
  590. // throw new EsignException("电子签全域状态总览表 [{0}],签署文件已经同步,请勿重复同步");
  591. // }
  592. SyncSignedFilesUtil.syncAttachmentsForEmpPage(this.getCtx(), billId);
  593. BatchMessageTipsBody body = new BatchMessageTipsBody();
  594. body.setMuitTipsState(Boolean.TRUE);
  595. body.setMuitTipsMessage("触发同步成功");
  596. body.setId(billId);
  597. batchMessageTipsHeader.addResult(body);
  598. success++;
  599. } catch (EsignException e) {
  600. e.printStackTrace();
  601. throw new ShrWebBizException(e);
  602. } catch (Exception e) {
  603. e.printStackTrace();
  604. throw new ShrWebBizException(e);
  605. }
  606. batchMessageTipsHeader.setBillId(billId);
  607. batchMessageTipsHeader.setFailureCount((success <= 0 ? 1 : 0));
  608. batchMessageTipsHeader.setSuccessCount(success);
  609. this.writeSuccessData(batchMessageTipsHeader);
  610. return null;
  611. }
  612. private void delAttachment(Context ctx, ESignGlobalStatusOverviewInfo info) throws BOSException, EASBizException {
  613. ISHRAttachmentExt SHRAttchExt = SHRAttachmentExtFactory.getLocalInstance(ctx);
  614. IAttachment attachment = AttachmentFactory.getLocalInstance(ctx);
  615. IBoAttchAsso attchAsso = BoAttchAssoFactory.getLocalInstance(ctx);
  616. EntityViewInfo entityViewInfo = new EntityViewInfo();
  617. FilterInfo filterInfo2 = new FilterInfo();
  618. filterInfo2.getFilterItems().add(new FilterItemInfo("boID", info.getId().toString()));
  619. entityViewInfo.setFilter(filterInfo2);
  620. SHRAttachmentExtCollection collection = SHRAttchExt.getSHRAttachmentExtCollection(entityViewInfo);
  621. for (int i = 0; i < collection.size(); i++) {
  622. String attId = collection.get(i).getAttachment().getId().toString();
  623. attchAsso.delete(MessageFormat.format(" where attachment = ''{0}''", attId));
  624. attachment.delete(new ObjectUuidPK(attId));
  625. }
  626. SHRAttchExt.delete(filterInfo2);
  627. }
  628. /**
  629. * 保存附件
  630. *
  631. * @param ctx
  632. * @param info
  633. * @param fileMap
  634. * @param uipk
  635. * @param propertyName
  636. * @throws IOException
  637. * @throws ShrWebBizException
  638. * @throws BOSException
  639. * @throws EASBizException
  640. */
  641. private void saveAttachment(Context ctx, ESignGlobalStatusOverviewInfo info, JSONObject fileMap, String uipk, String propertyName) throws IOException, ShrWebBizException, BOSException, EASBizException {
  642. String fileId = fileMap.getString("fileId");
  643. String fileName = fileMap.getString("fileName");
  644. System.out.println("saveAttachment:fileMap" + fileMap);
  645. if (StringUtils.isBlank(fileName)) {
  646. fileName = info.getFileName() + ".pdf";
  647. }
  648. String downloadUrl = fileMap.getString("downloadUrl");
  649. if (StringUtils.isBlank(downloadUrl)) {
  650. downloadUrl = fileMap.getString("fileDownloadUrl");
  651. }
  652. IAttachment attachment = AttachmentFactory.getLocalInstance(ctx);
  653. IBoAttchAsso attchAsso = BoAttchAssoFactory.getLocalInstance(ctx);
  654. ISHRAttachmentExt SHRAttchExt = SHRAttachmentExtFactory.getLocalInstance(ctx);
  655. byte[] content = DownloaderUtil.downloadFileToByteArray(downloadUrl);
  656. fileName = this.checkScriptAttack(fileName);
  657. if (fileName.lastIndexOf(46) <= 0) {
  658. fileName += ".pdf";
  659. }
  660. String mainname = fileName.substring(0, fileName.lastIndexOf(46));
  661. String extname = fileName.substring(fileName.lastIndexOf(46) + 1, fileName.length());
  662. extname = extname.toLowerCase();
  663. if ("html".equals(extname)) {
  664. extname = "pdf";
  665. }
  666. SHRAttachmentExtInfo attchExt = new SHRAttachmentExtInfo();
  667. AttachmentInfo ai = new AttachmentInfo();
  668. this.setAttMulNameAndDesc(ctx, ai, mainname, fileId);
  669. ai.setSimpleName(extname);
  670. ai.setFile(content);
  671. ai.setIsShared(false);
  672. ai.setNumber(propertyName);
  673. ai.setSharedDesc(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "false"));
  674. int size = content.length;
  675. if (size < 1024) {
  676. ai.setSize(size + SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "byte"));
  677. } else {
  678. ai.setSize(size / 1024 + "KB");
  679. }
  680. ai.setSizeInByte(size);
  681. ai.setAttachID("" + System.currentTimeMillis());
  682. ai.setType(this.getFileType(mainname + "." + extname));
  683. ai.setBeizhu(uipk);
  684. attchExt.setAttachment(ai);
  685. this.setAttExtMulNameAndDesc(ctx, attchExt, mainname + "." + extname, fileId);
  686. attchExt.setPropertyName(propertyName);
  687. attchExt.setType(AttachmentTypeEnum.PROPERTY);
  688. attchExt.setState(AttachmentState.UNSAVE);
  689. String bunding = MessageFormat.format("{0}#{1}", info.getEsignStatus().getValue(), info.getSignFlowId());
  690. attchExt.setBunding(bunding);
  691. attchExt.setBoID(info.getId().toString());
  692. try {
  693. attachment.addnew(ai);
  694. } catch (Exception var20) {
  695. throw new ShrWebBizException(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "upload_error"), var20);
  696. }
  697. attchExt.setState(AttachmentState.SAVE);
  698. BoAttchAssoInfo boAttchAssoInfo = new BoAttchAssoInfo();
  699. boAttchAssoInfo.setBoID(info.getId().toString());
  700. boAttchAssoInfo.setAssoBusObjType(String.valueOf(info.getBOSType()));
  701. boAttchAssoInfo.setAssoType("Added Accessories", LocaleUtils.locale_l1);
  702. boAttchAssoInfo.setAssoType("Added Accessories", LocaleUtils.locale_l2);
  703. boAttchAssoInfo.setAssoType("Added Accessories", LocaleUtils.locale_l3);
  704. boAttchAssoInfo.setAttachment(ai);
  705. attchAsso.addnew(boAttchAssoInfo);
  706. SHRAttchExt.addnew(attchExt);
  707. }
  708. private String getFileType(String fullname) {
  709. String extname = fullname.substring(fullname.lastIndexOf(46) + 1, fullname.length());
  710. if (!"doc".equalsIgnoreCase(extname) && !"docx".equalsIgnoreCase(extname)) {
  711. if (!"xls".equalsIgnoreCase(extname) && !"xlsx".equalsIgnoreCase(extname) && !"xlsm".equalsIgnoreCase(extname) && !"xlsb".equalsIgnoreCase(extname)) {
  712. if (!"ppt".equalsIgnoreCase(extname) && !"pptx".equalsIgnoreCase(extname) && !"pptm".equalsIgnoreCase(extname)) {
  713. 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);
  714. } else {
  715. return SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "microsoft_ppt");
  716. }
  717. } else {
  718. return SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "microsoft_excel");
  719. }
  720. } else {
  721. return SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "microsoft_word");
  722. }
  723. }
  724. private String checkScriptAttack(String str) {
  725. if (!StringUtils.isEmpty(str)) {
  726. if (str.contains("<")) {
  727. str.replaceAll("<", "&lt;");
  728. }
  729. if (str.contains(">")) {
  730. str.replaceAll(">", "&gt;");
  731. }
  732. }
  733. return str;
  734. }
  735. private void setAttMulNameAndDesc(Context ctx, AttachmentInfo att, String name, String desc) {
  736. if (att != null && !StringUtils.isEmpty(name)) {
  737. MutilanUtils.setMultiFieldValueToBean(ctx, "name", att, name);
  738. MutilanUtils.setMultiFieldValueToBean(ctx, "description", att, desc);
  739. }
  740. }
  741. private void setAttExtMulNameAndDesc(Context ctx, SHRAttachmentExtInfo info, String name, String desc) {
  742. if (info != null && !StringUtils.isEmpty(name)) {
  743. Locale locale = ctx.getLocale();
  744. info.setName(name, LocaleUtils.locale_l1);
  745. info.setDescription(desc, LocaleUtils.locale_l1);
  746. if (LocaleUtils.locale_l1.getDisplayName().equals(LocaleUtils.getLocaleString(locale))) {
  747. info.setName(name, LocaleUtils.locale_l2);
  748. info.setName(name, LocaleUtils.locale_l3);
  749. info.setDescription(desc, LocaleUtils.locale_l2);
  750. info.setDescription(desc, LocaleUtils.locale_l3);
  751. } else if (LocaleUtils.locale_l2.getDisplayName().equals(LocaleUtils.getLocaleString(locale))) {
  752. info.setName(name, LocaleUtils.locale_l2);
  753. info.setName(STConverter.sc2tc(name), LocaleUtils.locale_l3);
  754. if (!StringUtils.isEmpty(desc)) {
  755. info.setDescription(desc, LocaleUtils.locale_l2);
  756. info.setDescription(STConverter.sc2tc(desc), LocaleUtils.locale_l3);
  757. }
  758. } else {
  759. info.setName(STConverter.tc2sc(name), LocaleUtils.locale_l2);
  760. info.setName(name, LocaleUtils.locale_l3);
  761. if (!StringUtils.isEmpty(desc)) {
  762. info.setDescription(STConverter.tc2sc(desc), LocaleUtils.locale_l2);
  763. info.setDescription(desc, LocaleUtils.locale_l3);
  764. }
  765. }
  766. }
  767. }
  768. /**
  769. * 添加员工
  770. *
  771. * @param request
  772. * @param response
  773. * @param modelMap
  774. * @return
  775. * @throws SHRWebException
  776. */
  777. public String addPersonAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  778. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  779. String billId = this.getBillId(request);
  780. String personId =request.getParameter("personId");
  781. String revokeReason = request.getParameter("revokeReason");
  782. int failure = 0;
  783. int success = 0;
  784. String[] billIds = billId.split(",");
  785. try {
  786. //
  787. boolean isSess = true;
  788. IESignGlobalStatusOverview globalStatusOverview = ESignGlobalStatusOverviewFactory.getLocalInstance(this.getCtx());
  789. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  790. selectorItemCollection.add(new SelectorItemInfo("id"));
  791. selectorItemCollection.add(new SelectorItemInfo("person.id"));
  792. selectorItemCollection.add(new SelectorItemInfo("Fiesign"));
  793. for(String string : billIds){
  794. ESignGlobalStatusOverviewInfo info = globalStatusOverview.getESignGlobalStatusOverviewInfo(new ObjectUuidPK(string));
  795. boolean Fiesign = info.getBoolean("Fiesign");
  796. if (Fiesign) {
  797. PersonInfo personInfo = new PersonInfo();
  798. personInfo.setId(BOSUuid.read(personId));
  799. info.setPerson(personInfo);
  800. globalStatusOverview.save(info);
  801. BatchMessageTipsBody body = new BatchMessageTipsBody();
  802. body.setMuitTipsState(Boolean.TRUE);
  803. body.setMuitTipsMessage("成功!");
  804. body.setId(string);
  805. batchMessageTipsHeader.addResult(body);
  806. success++;
  807. }else {
  808. BatchMessageTipsBody body = new BatchMessageTipsBody();
  809. body.setMuitTipsState(Boolean.FALSE);
  810. body.setMuitTipsMessage("只能修改e签宝发起的");
  811. body.setId(string);
  812. batchMessageTipsHeader.addResult(body);
  813. isSess = false;
  814. }
  815. }
  816. } catch (Exception e) {
  817. e.printStackTrace();
  818. throw new ShrWebBizException(e);
  819. }
  820. batchMessageTipsHeader.setBillId(billId);
  821. batchMessageTipsHeader.setFailureCount((billIds.length-success));
  822. batchMessageTipsHeader.setSuccessCount(success);
  823. this.writeSuccessData(batchMessageTipsHeader);
  824. return null;
  825. }
  826. }