ESignGlobalStatusOverviewListHandler.java 28 KB

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