BeiSenSysTest.java 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  1. package com.kingdee.eas.custom.webbeisen.test;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.kingdee.bos.BOSException;
  5. import com.kingdee.bos.BOSObjectFactory;
  6. import com.kingdee.bos.Context;
  7. import com.kingdee.bos.bsf.service.app.IHRMsfService;
  8. import com.kingdee.bos.dao.IObjectPK;
  9. import com.kingdee.bos.metadata.entity.*;
  10. import com.kingdee.bos.metadata.query.util.CompareType;
  11. import com.kingdee.bos.util.BOSUuid;
  12. import com.kingdee.eas.base.attachment.AttachmentFactory;
  13. import com.kingdee.eas.base.attachment.AttachmentInfo;
  14. import com.kingdee.eas.base.attachment.BoAttchAssoFactory;
  15. import com.kingdee.eas.base.attachment.BoAttchAssoInfo;
  16. import com.kingdee.eas.base.permission.UserFactory;
  17. import com.kingdee.eas.base.permission.UserInfo;
  18. import com.kingdee.eas.basedata.person.PersonInfo;
  19. import com.kingdee.eas.common.EASBizException;
  20. import com.kingdee.eas.custom.beisenconfig.*;
  21. import com.kingdee.eas.custom.enumerations.ViewTypeEnum;
  22. import com.kingdee.eas.custom.webbeisen.utils.Helper;
  23. import com.kingdee.eas.framework.CoreBaseCollection;
  24. import com.kingdee.eas.framework.CoreBaseInfo;
  25. import com.kingdee.eas.framework.ICoreBase;
  26. import com.kingdee.eas.hr.affair.EmpEnrollBizBillEntryCollection;
  27. import com.kingdee.eas.hr.affair.EmpEnrollBizBillEntryInfo;
  28. import com.kingdee.eas.hr.emp.PersonPhotoFactory;
  29. import com.kingdee.eas.hr.emp.PersonPhotoInfo;
  30. import com.kingdee.shr.attachment.AttachmentState;
  31. import com.kingdee.shr.attachment.AttachmentTypeEnum;
  32. import com.kingdee.shr.attachment.SHRAttachmentExtFactory;
  33. import com.kingdee.shr.attachment.SHRAttachmentExtInfo;
  34. import com.kingdee.shr.base.syssetting.MSFServiceFacadeFactory;
  35. import com.kingdee.shr.base.syssetting.UIType;
  36. import com.kingdee.shr.base.syssetting.UIViewFactory;
  37. import com.kingdee.shr.base.syssetting.UIViewInfo;
  38. import com.kingdee.shr.base.syssetting.app.util.XMLUtil;
  39. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  40. import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
  41. import com.kingdee.shr.base.syssetting.ml.SHRWebResource;
  42. import com.kingdee.shr.base.syssetting.util.MetaDataUtil;
  43. import com.kingdee.shr.base.syssetting.util.SysSettingUIViewUtil;
  44. import com.kingdee.shr.base.syssetting.web.dynamic.model.FieldInfo;
  45. import com.kingdee.shr.base.syssetting.web.dynamic.view.converter.IUIViewConverter;
  46. import com.kingdee.shr.base.syssetting.web.dynamic.view.converter.UIViewConverterFactory;
  47. import com.kingdee.shr.ml.MLServiceFactory;
  48. import com.kingdee.shr.ml.ResourceType;
  49. import com.kingdee.util.LocaleUtils;
  50. import com.kingdee.util.StringUtils;
  51. import org.apache.log4j.Logger;
  52. import org.jdom.Document;
  53. import org.jdom.Element;
  54. import org.jdom.output.XMLOutputter;
  55. import org.jdom.xpath.XPath;
  56. import org.json.JSONException;
  57. import java.io.IOException;
  58. import java.text.MessageFormat;
  59. import java.text.ParseException;
  60. import java.text.SimpleDateFormat;
  61. import java.util.*;
  62. public class BeiSenSysTest implements IHRMsfService {
  63. Helper helper = null;
  64. Context context = null;
  65. private static Logger logger =
  66. Logger.getLogger("com.kingdee.eas.custom.beisen.synchronousorg.SynchronousEmpBillControllerBean");
  67. @Override
  68. public Object process(Context context, Map map) throws EASBizException, BOSException {
  69. String param = map.get("param") == null ? "" : map.get("param").toString();
  70. empBill(context,param,"i6MAAAABB+gL9cGD" );
  71. return null;
  72. }
  73. public void empBill(Context ctx, String param, String viewConfigId) throws BOSException {
  74. helper = new Helper(ctx);
  75. this.context = ctx;
  76. EntityViewInfo entityViewInfo = new EntityViewInfo();
  77. FilterInfo filterInfo = new FilterInfo();
  78. filterInfo.getFilterItems().add(new FilterItemInfo("isEnabled", true, CompareType.EQUALS));
  79. filterInfo.getFilterItems().add(new FilterItemInfo("id", viewConfigId, CompareType.EQUALS));
  80. entityViewInfo.setFilter(filterInfo);
  81. //获取北森视图配置信息
  82. BSViewConfigCollection bsViewConfigCollection = BSViewConfigFactory.getLocalInstance(ctx).getBSViewConfigCollection(entityViewInfo);
  83. if (bsViewConfigCollection.size() <= 0) {
  84. throw new RuntimeException("配置未启用或者不存在");
  85. }
  86. BSViewConfigInfo bsViewConfigInfo = bsViewConfigCollection.get(0);
  87. String osfParam = bsViewConfigInfo.getOsfParam();
  88. String osfSericeName = bsViewConfigInfo.getOsfSericeName();
  89. Map<String, Object> serviceParam = new HashMap<String,Object>();
  90. if (param!=null&&!param.equals("")){
  91. JSONObject jsonObject = JSONObject.parseObject(osfParam);
  92. jsonObject.put("staffId",param);
  93. osfParam= jsonObject.toJSONString();
  94. }
  95. serviceParam.put("param", osfParam);
  96. JSONArray beiSenData = null;
  97. try {
  98. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  99. selectorItemCollection.add("*");
  100. selectorItemCollection.add("view.*");
  101. Object o = MSFServiceFacadeFactory.getLocalInstance(ctx).processService(osfSericeName, serviceParam);
  102. beiSenData = JSONArray.parseArray(o.toString());
  103. //查询头部视图配置 头部视图配置只能有一个
  104. EntityViewInfo entryHeadEntityViewInfo = new EntityViewInfo();
  105. FilterInfo entryHeadFilterInfo = new FilterInfo();
  106. entryHeadFilterInfo.getFilterItems().add(new FilterItemInfo("parent", bsViewConfigInfo.getId().toString(), CompareType.EQUALS));
  107. entryHeadFilterInfo.getFilterItems().add(new FilterItemInfo("boy", ViewTypeEnum.HEAD_VALUE, CompareType.EQUALS));
  108. entryHeadEntityViewInfo.setSelector(selectorItemCollection);
  109. entryHeadEntityViewInfo.setFilter(entryHeadFilterInfo);
  110. BSViewConfigEntryCollection headBsViewConfigEntryCollection = BSViewConfigEntryFactory
  111. .getLocalInstance(ctx).getBSViewConfigEntryCollection(entryHeadEntityViewInfo);
  112. if (headBsViewConfigEntryCollection.size() != 1) {
  113. throw new RuntimeException("头部配置有且只能有一个");
  114. }
  115. BSViewConfigEntryInfo bsViewConfigEntryInfo = headBsViewConfigEntryCollection.get(0);
  116. UIViewInfo view = bsViewConfigEntryInfo.getView();
  117. String file = bsViewConfigEntryInfo.getFile();
  118. for (int i = 0; i < beiSenData.size(); i++) {
  119. JSONObject jsonObject1 = beiSenData.getJSONObject(i);
  120. JSONArray fileArray = jsonObject1.getJSONArray(file);
  121. boolean isCreateData = bsViewConfigEntryInfo.isIsCreateData();
  122. String headId = null;
  123. if (isCreateData){
  124. headId = headProcessing(view, jsonObject1, fileArray, file);
  125. }else {
  126. String headDataEntry = bsViewConfigEntryInfo.getHeadDataEntry();
  127. String headWhere = bsViewConfigEntryInfo.getHeadWhere();
  128. Class objectValueClass = MetaDataUtil.getObjectValueClass(headDataEntry);
  129. // 创建对应的实体对象
  130. CoreBaseInfo coreBaseInfo = (CoreBaseInfo) MetaDataUtil.newInstance(objectValueClass, headDataEntry);
  131. // 创建对应的业务对象
  132. ICoreBase bosObject = (ICoreBase) (BOSObjectFactory.createBOSObject(context, coreBaseInfo.getBOSType()));
  133. String string = jsonObject1.getJSONObject("staffInfos").getString("id");
  134. CoreBaseCollection collection = bosObject.getCollection("where beisenId='" + string + "'");
  135. if (collection.size()>0){
  136. headId = collection.get(0).getId().toString();
  137. }
  138. }
  139. if (headId == null){
  140. continue;
  141. }
  142. EntityViewInfo entryBoyEntityViewInfo = new EntityViewInfo();
  143. FilterInfo entryBoyFilterInfo = new FilterInfo();
  144. entryBoyFilterInfo.getFilterItems().add(new FilterItemInfo("parent", bsViewConfigInfo.getId().toString(), CompareType.EQUALS));
  145. entryBoyFilterInfo.getFilterItems().add(new FilterItemInfo("boy", ViewTypeEnum.BOY_VALUE, CompareType.EQUALS));
  146. entryBoyEntityViewInfo.setSelector(selectorItemCollection);
  147. entryBoyEntityViewInfo.setFilter(entryBoyFilterInfo);
  148. BSViewConfigEntryCollection boyBsViewConfigEntryCollection = BSViewConfigEntryFactory
  149. .getLocalInstance(ctx).getBSViewConfigEntryCollection(entryBoyEntityViewInfo);
  150. for (int j = 0; j < boyBsViewConfigEntryCollection.size(); j++) {
  151. BSViewConfigEntryInfo boybsViewConfigEntryInfo = boyBsViewConfigEntryCollection.get(j);
  152. UIViewInfo view1 = boybsViewConfigEntryInfo.getView();
  153. String beiSenData1 = boybsViewConfigEntryInfo.getBeiSenData();
  154. UIType type = view1.getType();
  155. if(type.getValue().equals("list")){
  156. boyProcessing(view1,headId,jsonObject1.getJSONArray(beiSenData1),null,"fileInfos",beiSenData1);
  157. }else {
  158. boyProcessing(view1,headId,jsonObject1.getJSONObject(beiSenData1),null,"fileInfos",beiSenData1);
  159. }
  160. }
  161. }
  162. } catch (EASBizException e) {
  163. //获取北森数据失败
  164. throw new RuntimeException(e);
  165. } catch (JSONException e) {
  166. throw new RuntimeException(e);
  167. } catch (ParseException e) {
  168. throw new RuntimeException(e);
  169. } catch (IOException e) {
  170. throw new RuntimeException(e);
  171. } catch (SHRWebException e) {
  172. throw new RuntimeException(e);
  173. }
  174. }
  175. /**
  176. * 处理表单类型的主体信息
  177. *
  178. * @param id 关联的 ID
  179. * @param jsonObject 主体信息的 JSON 对象
  180. * @param fileJSON 文件信息的 JSON 数组
  181. * @return 保存后的对象主键
  182. * @throws JSONException JSON 处理异常
  183. * @throws SHRWebException SHR 网页异常
  184. * @throws BOSException BOS 异常
  185. * @throws EASBizException EAS 业务异常
  186. * @throws ParseException 解析异常
  187. * @throws IOException 输入输出异常
  188. */
  189. public String boyProcessing(UIViewInfo uiViewInfo, String id, JSONObject jsonObject, JSONArray fileJSON, String fileName,String beiSenData1)
  190. throws JSONException, SHRWebException, BOSException, EASBizException, ParseException, IOException {
  191. // 根据 UI 视图的主键生成动态 UI 视图信息
  192. com.kingdee.shr.base.syssetting.web.dynamic.model.UIViewInfo uiViewInfo1 =
  193. generateUIView(context, uiViewInfo.getUipk());
  194. // 获取实体名称
  195. String entityName = uiViewInfo1.getEntityName();
  196. // 获取字段列表
  197. List<FieldInfo> fields = uiViewInfo1.getFields();
  198. // 根据实体名称获取对应的对象值类
  199. Class objectValueClass = MetaDataUtil.getObjectValueClass(entityName);
  200. // 创建对应的实体对象
  201. CoreBaseInfo coreBaseInfo = (CoreBaseInfo) MetaDataUtil.newInstance(objectValueClass, entityName);
  202. // 处理字段信息
  203. JSONObject jsonObject2 = new JSONObject();
  204. jsonObject2.put(beiSenData1,jsonObject2);
  205. JSONArray jsonArray = this.fieldProcessing(fields, coreBaseInfo, jsonObject2, fileName);
  206. // 创建对应的业务对象
  207. ICoreBase bosObject = (ICoreBase) (BOSObjectFactory.createBOSObject(context, coreBaseInfo.getBOSType()));
  208. // 获取关联字段
  209. String relateField = uiViewInfo1.getRelatedField();
  210. // 根据 ID 获取对应的实体对象信息
  211. EntityObjectInfo entityObject = MetaDataUtil.getEntityObject(id);
  212. // 获取实体对象的全名称
  213. String fullName = entityObject.getFullName();
  214. // 根据全名称获取对应的对象值类
  215. Class objectValueClass1 = MetaDataUtil.getObjectValueClass(fullName);
  216. // 创建对应的实体对象
  217. CoreBaseInfo coreBaseInfo1 = (CoreBaseInfo) MetaDataUtil.newInstance(objectValueClass1, fullName);
  218. // 设置实体对象的 ID
  219. coreBaseInfo1.setId(BOSUuid.read(id));
  220. // 将关联的实体对象设置到当前实体对象中
  221. coreBaseInfo.put(relateField, coreBaseInfo1);
  222. // 保存实体对象
  223. IObjectPK save = bosObject.save(coreBaseInfo);
  224. // 处理文件信息
  225. fileProcessor(save.toString(), null, jsonArray);
  226. // 获取文件信息的第一个 JSON 对象
  227. JSONObject jsonObject1 = fileJSON.getJSONObject(0);
  228. if (!save.toString().equals("")) {
  229. // 遍历字段列表
  230. for (int i = 0; i < fields.size(); i++) {
  231. // 获取单个字段信息
  232. FieldInfo fieldInfo = fields.get(i);
  233. // 获取字段的别名
  234. String alias = fieldInfo.getAlias();//CertificateNu
  235. // 获取字段的名称
  236. String name = fieldInfo.getName();//idCardNO
  237. if (!name.equals("attachments")) {
  238. continue;
  239. }
  240. // 分割字段别名
  241. String[] split = alias.split("#");
  242. // 获取字段的属性
  243. Map<String, String> attributes = fieldInfo.getAttributes();
  244. // 获取数据的 UI 主键
  245. String uipk = attributes.get("data-uipk");
  246. // 获取文件信息
  247. JSONObject data = jsonObject1.getJSONObject(split[1]);
  248. if (data != null) {
  249. // 获取下载链接
  250. String downloadUrl = data.getString("downloadUrl");
  251. // 分割下载链接
  252. String[] split1 = downloadUrl.split(",");
  253. // 获取文件名
  254. String text = data.getString("text");
  255. // 分割文件名
  256. String[] split2 = text.split(",");
  257. for (int k = 0; k < split1.length; k++) {
  258. byte[] dataImg = new byte[0];
  259. // 拼接完整的下载链接
  260. String URL = "http:" + split1[k];
  261. System.out.println("===========" + URL + "==========");
  262. // 从网络下载文件数据
  263. dataImg = helper.getBytesByNetURL(URL);
  264. // 插入人员附件信息
  265. insertPersonAttachment(split2[k], uipk, save.toString(), dataImg);
  266. }
  267. }
  268. }
  269. }
  270. // 返回保存后的对象主键
  271. return save.toString();
  272. }
  273. /**
  274. * 处理列表类型的主体信息
  275. *
  276. * @param id 关联的 ID
  277. * @param jsonArray 主体信息的 JSON 数组
  278. * @param fileJSON 文件信息的 JSON 数组
  279. * @return 保存后的对象主键
  280. * @throws JSONException JSON 处理异常
  281. * @throws SHRWebException SHR 网页异常
  282. * @throws BOSException BOS 异常
  283. * @throws EASBizException EAS 业务异常
  284. * @throws ParseException 解析异常
  285. * @throws IOException 输入输出异常
  286. */
  287. public String boyProcessing(UIViewInfo uiViewInfo, String id, JSONArray jsonArray, JSONArray fileJSON, String fileName,String beiSenData1)
  288. throws JSONException, SHRWebException, BOSException, EASBizException, ParseException, IOException {
  289. // 根据 UI 视图的主键生成动态 UI 视图信息
  290. com.kingdee.shr.base.syssetting.web.dynamic.model.UIViewInfo uiViewInfo1 =
  291. generateUIView(context, uiViewInfo.getUipk());
  292. String fileId = "";
  293. // 获取实体名称
  294. String entityName = uiViewInfo1.getEntityName();
  295. // 获取字段列表
  296. List<FieldInfo> fields = uiViewInfo1.getFields();
  297. // 获取关联字段
  298. String relateField = uiViewInfo1.getRelatedField();
  299. // 根据 ID 获取对应的实体对象信息
  300. EntityObjectInfo entityObject = MetaDataUtil.getEntityObject(id);
  301. // 获取实体对象的全名称
  302. String fullName = entityObject.getFullName();
  303. // 根据全名称获取对应的对象值类
  304. Class objectValueClass1 = MetaDataUtil.getObjectValueClass(fullName);
  305. // 创建对应的实体对象
  306. CoreBaseInfo coreBaseInfo1 = (CoreBaseInfo) MetaDataUtil.newInstance(objectValueClass1, fullName);
  307. // 设置实体对象的 ID
  308. coreBaseInfo1.setId(BOSUuid.read(id));
  309. // 获取排序方法
  310. String sorterMethod = uiViewInfo1.getOrderBy();
  311. // 遍历主体信息的 JSON 数组
  312. for (int i = 0; i < jsonArray.size(); i++) {
  313. // 根据实体名称获取对应的对象值类
  314. Class objectValueClass = MetaDataUtil.getObjectValueClass(entityName);
  315. // 创建对应的实体对象
  316. CoreBaseInfo coreBaseInfo = (CoreBaseInfo) MetaDataUtil.newInstance(objectValueClass, entityName);
  317. // 处理字段信息
  318. JSONObject jsonObject = new JSONObject();
  319. jsonObject.put(beiSenData1, jsonArray.getJSONObject(i));
  320. JSONArray jsonArray1 = this.fieldProcessing(fields, coreBaseInfo,jsonObject , fileName);
  321. // 创建对应的业务对象
  322. ICoreBase bosObject = (ICoreBase) (BOSObjectFactory.createBOSObject(context, coreBaseInfo.getBOSType()));
  323. // 将关联的实体对象设置到当前实体对象中
  324. coreBaseInfo.put(relateField, coreBaseInfo1);
  325. // 设置是否最高的标志
  326. coreBaseInfo.put("IsHighest", "1");
  327. // 设置是否单个的标志
  328. coreBaseInfo.put("isSingle", "1");
  329. // 保存实体对象
  330. IObjectPK save = bosObject.save(coreBaseInfo);
  331. if (sorterMethod != null && !sorterMethod.equals("")) {
  332. // 根据关联字段和排序方法查询实体对象集合
  333. CoreBaseCollection collection = bosObject.getCollection(" where " + relateField + " = '" + id + "' order by " + sorterMethod);
  334. if (collection.size() > 1) {
  335. // 获取第一个实体对象
  336. CoreBaseInfo coreBaseInfo2 = collection.get(0);
  337. // 设置是否最高的标志
  338. coreBaseInfo2.put("IsHighest", "1");
  339. // 设置是否单个的标志
  340. coreBaseInfo2.put("isSingle", "1");
  341. // 保存实体对象
  342. IObjectPK save1 = bosObject.save(coreBaseInfo2);
  343. // 获取保存后的对象主键
  344. fileId = save1.toString();
  345. for (int j = 1; j < collection.size(); j++) {
  346. // 获取其他实体对象
  347. CoreBaseInfo coreBaseInfo3 = collection.get(j);
  348. // 设置是否最高的标志
  349. coreBaseInfo3.put("IsHighest", "0");
  350. // 设置是否单个的标志
  351. coreBaseInfo3.put("isSingle", "0");
  352. // 保存实体对象
  353. bosObject.save(coreBaseInfo3);
  354. }
  355. }
  356. }
  357. // 处理文件信息
  358. fileProcessor(save.toString(), null, jsonArray1);
  359. }
  360. if (fileJSON!=null){
  361. // 获取文件信息的第一个 JSON 对象
  362. JSONObject jsonObject = fileJSON.getJSONObject(0);
  363. if (!fileId.equals("")) {
  364. // 遍历字段列表
  365. for (int i = 0; i < fields.size(); i++) {
  366. // 获取单个字段信息
  367. FieldInfo fieldInfo = fields.get(i);
  368. // 获取字段的别名
  369. String alias = fieldInfo.getAlias();//CertificateNu
  370. // 获取字段的名称
  371. String name = fieldInfo.getName();//idCardNO
  372. if (!name.equals("attachments")) {
  373. continue;
  374. }
  375. // 分割字段别名
  376. String[] split = alias.split("#");
  377. // 获取字段的属性
  378. Map<String, String> attributes = fieldInfo.getAttributes();
  379. // 获取数据的 UI 主键
  380. String dataUipk = attributes.get("data-uipk");
  381. // 获取文件信息
  382. JSONObject data = jsonObject.getJSONObject(split[1]);
  383. if (data != null) {
  384. // 获取下载链接
  385. String downloadUrl = data.getString("downloadUrl");
  386. // 分割下载链接
  387. String[] split1 = downloadUrl.split(",");
  388. // 获取文件名
  389. String text = data.getString("text");
  390. // 分割文件名
  391. String[] split2 = text.split(",");
  392. for (int k = 0; k < split1.length; k++) {
  393. byte[] dataImg = new byte[0];
  394. // 拼接完整的下载链接
  395. String URL = "http:" + split1[k];
  396. System.out.println("===========" + URL + "==========");
  397. // 从网络下载文件数据
  398. dataImg = helper.getBytesByNetURL(URL);
  399. // 插入人员附件信息
  400. insertPersonAttachment(split2[k], dataUipk, fileId, dataImg);
  401. }
  402. }
  403. }
  404. }
  405. }
  406. return null;
  407. }
  408. /**
  409. * 处理字段信息
  410. *
  411. * @param fields 字段列表
  412. * @param coreBaseInfo 实体对象
  413. * @param jsonObject 数据的 JSON 对象
  414. * @return 处理后的文件信息的 JSON 数组
  415. * @throws JSONException JSON 处理异常
  416. * @throws ShrWebBizException SHR 网页业务异常
  417. * @throws BOSException BOS 异常
  418. * @throws ParseException 解析异常
  419. */
  420. public JSONArray fieldProcessing(List<FieldInfo> fields, CoreBaseInfo coreBaseInfo, JSONObject jsonObject, String fileName) throws JSONException, ShrWebBizException, BOSException, ParseException {
  421. System.out.println("===============+"+jsonObject);
  422. // 用于存储处理后的文件信息的 JSON 数组
  423. JSONArray files = new JSONArray();
  424. // 用于存储单个文件信息的 JSON 对象
  425. JSONObject file = null;
  426. // 遍历字段列表
  427. for (int i = 0; i < fields.size(); i++) {
  428. // 获取单个字段信息
  429. FieldInfo fieldInfo = fields.get(i);
  430. // 获取字段的属性信息
  431. PropertyInfo property = fieldInfo.getProperty();
  432. // 获取字段的数据类型
  433. DataType dataType = fieldInfo.getDataType();
  434. // 获取字段的别名
  435. String alias = fieldInfo.getAlias();//CertificateNumber.value
  436. // 获取字段的名称
  437. String name = fieldInfo.getName();//idCardNO
  438. // 分割字段别名
  439. String[] split = alias.split("#");
  440. Object value = null;
  441. // 获取字段的属性
  442. Map<String, String> attributes = fieldInfo.getAttributes();
  443. ;
  444. Object dataObject = jsonObject.get(split[0]);
  445. String s1 = attributes.get("data-valueType");
  446. if (s1!=null&&s1.equals("url")) {
  447. if (dataObject instanceof JSONObject){
  448. JSONObject data = jsonObject.getJSONObject(split[0]);
  449. if (data!=null){
  450. file = new JSONObject();
  451. value = data.get(split[1]);
  452. if (value instanceof JSONObject){
  453. value = data.getJSONObject(split[1]).get(split[2]);
  454. if (value instanceof JSONArray){
  455. JSONArray jsonArray = data.getJSONObject(split[1]).getJSONArray(split[2]);
  456. String tempValue="";
  457. for (int j = 0; j < jsonArray.size(); j++) {
  458. String string = jsonArray.getString(j);
  459. // 将数据的 UI 主键、下载链接和文件名添加到文件信息的 JSON 对象中
  460. file.put("uipk", attributes.get("data-uipk"));
  461. file.put("url", string);
  462. file.put("name", data.getString("text"));
  463. // 将文件信息的 JSON 对象添加到文件信息的 JSON 数组中
  464. files.add(file);
  465. }
  466. continue;
  467. }
  468. }
  469. if (value == null || value.equals("null") || value.equals("{}")||value.equals("")) {
  470. continue;
  471. }
  472. // 将数据的 UI 主键、下载链接和文件名添加到文件信息的 JSON 对象中
  473. file.put("uipk", attributes.get("data-uipk"));
  474. file.put("url", value);
  475. file.put("name", data.getString("text"));
  476. // 将文件信息的 JSON 对象添加到文件信息的 JSON 数组中
  477. files.add(file);
  478. }
  479. }else if(dataObject instanceof JSONArray){
  480. JSONArray jsonArray1 = jsonObject.getJSONArray(split[0]);
  481. for (int j = 0; j < jsonArray1.size(); j++) {
  482. JSONObject data = jsonArray1.getJSONObject(j);
  483. if (data!=null){
  484. file = new JSONObject();
  485. value = data.get(split[1]);
  486. if (value instanceof JSONObject){
  487. value = data.getJSONObject(split[1]).get(split[2]);
  488. if (value instanceof JSONArray){
  489. JSONArray jsonArray = data.getJSONObject(split[1]).getJSONArray(split[2]);
  490. String tempValue="";
  491. for (int k = 0; k < jsonArray.size(); k++) {
  492. String string = jsonArray.getString(k);
  493. // 将数据的 UI 主键、下载链接和文件名添加到文件信息的 JSON 对象中
  494. file.put("uipk", attributes.get("data-uipk"));
  495. file.put("url", string);
  496. file.put("name", data.getString("text"));
  497. // 将文件信息的 JSON 对象添加到文件信息的 JSON 数组中
  498. files.add(file);
  499. }
  500. continue;
  501. }
  502. }
  503. if (value == null || value.equals("null") || value.equals("{}")||value.equals("")) {
  504. continue;
  505. }
  506. // 将数据的 UI 主键、下载链接和文件名添加到文件信息的 JSON 对象中
  507. file.put("uipk", attributes.get("data-uipk"));
  508. file.put("url", value);
  509. file.put("name", data.getString("text"));
  510. // 将文件信息的 JSON 对象添加到文件信息的 JSON 数组中
  511. files.add(file);
  512. }
  513. }
  514. continue;
  515. }
  516. }
  517. JSONObject data = jsonObject.getJSONObject(split[0]);
  518. // 获取数据的 JSON 对象
  519. if (data == null) {
  520. // 如果数据为空,获取默认值
  521. value = attributes.get("data-defaultValue");
  522. } else {
  523. // 获取数据的值
  524. value = data.get(split[1]);
  525. if (value == null) {
  526. // 如果值为空,获取默认值
  527. value = attributes.get("data-defaultValue");
  528. } else {
  529. value = data.get(split[1]);
  530. if (value instanceof JSONObject){
  531. value = data.getJSONObject(split[1]).get(split[2]);
  532. // if (value instanceof JSONArray){
  533. // JSONArray jsonArray = data.getJSONObject(split[1]).getJSONArray(split[2]);
  534. // String tempValue="";
  535. // if (jsonArray.size()>0) {
  536. // String string = jsonArray.getString(0);
  537. // value
  538. // }
  539. // if (!tempValue.equals("")){
  540. // value = tempValue.substring(0,tempValue.length()-1);
  541. // }
  542. // }
  543. }else if (value instanceof JSONArray){
  544. JSONArray jsonArray = data.getJSONArray(split[1]);
  545. if (jsonArray.size()>0){
  546. Object o = jsonArray.get(0);
  547. if (o instanceof JSONObject){
  548. Object string = jsonArray.getJSONObject(0).get(split[2]);
  549. if (string instanceof Integer){
  550. value = jsonArray.getJSONObject(0).getInteger(split[2]);
  551. }else if (o instanceof String){
  552. value = jsonArray.getJSONObject(0).getString(split[2]);
  553. }
  554. }
  555. }
  556. }else {
  557. value = data.getString(split[1]);
  558. }
  559. // 获取自定义映射值
  560. String s = attributes.get("data-mappingValue");
  561. if (s != null && !s.equals("")) {
  562. // 解析自定义映射值的 JSON 对象
  563. JSONObject jsonObject1 = JSONObject.parseObject(s);
  564. if (jsonObject1 != null) {
  565. // 根据值获取映射后的值
  566. String string = jsonObject1.getString(value.toString());
  567. if (string != null) {
  568. value = string;
  569. }
  570. }
  571. }
  572. }
  573. }
  574. if (value == null || value.equals("")) {
  575. // 如果值为空,打印日志并跳过处理
  576. System.out.println("+++++++++" + value);
  577. continue;
  578. }
  579. if (dataType != null && dataType.getName().equals("ObjectValue")) {
  580. if (property instanceof LinkPropertyInfo) {
  581. // 获取关联对象的全名称
  582. String businessImplName = ((LinkPropertyInfo) property).getRelationship().getSupplierObject().getFullName();
  583. // 根据全名称获取对应的对象值类
  584. Class objectValueClass1 = MetaDataUtil.getObjectValueClass(businessImplName);
  585. // 创建对应的实体对象
  586. CoreBaseInfo coreBaseInfo1 = (CoreBaseInfo) MetaDataUtil.newInstance(objectValueClass1, businessImplName);
  587. // 创建对应的业务对象
  588. ICoreBase bosObject = (ICoreBase) (BOSObjectFactory.createBOSObject(context, coreBaseInfo1.getBOSType()));
  589. // 根据名称或编号查询实体对象集合
  590. CoreBaseCollection dataBaseCollection = bosObject.getCollection("where name like '%" + value + "%' or number = '" + value + "'");
  591. if (dataBaseCollection.size() <= 0) {
  592. // 如果集合为空,将字段的值设置为 null
  593. // coreBaseInfo.put(name, null);
  594. } else {
  595. // 将查询到的第一个实体对象设置到当前实体对象中
  596. //coreBaseInfo.put(name, dataBaseCollection.get(0));
  597. setCoreBaseInfo(coreBaseInfo,name, dataBaseCollection.get(0));
  598. }
  599. }
  600. } else if (dataType != null && dataType.getName().equals("Enum")) {
  601. // 如果数据类型为枚举,将值设置到当前实体对象中
  602. //coreBaseInfo.put(name, value);
  603. setCoreBaseInfo(coreBaseInfo,name,value);
  604. } else if (dataType != null && dataType.getName().equals("Date")) {
  605. // 创建日期格式化对象
  606. SimpleDateFormat f = new SimpleDateFormat(attributes.get("dateFormat"));
  607. if (!value.equals("") || !value.equals("未知") || !value.equals("9999/12")) {
  608. // 将日期字符串解析为日期对象并设置到当前实体对象中
  609. //coreBaseInfo.put(name, f.parse(value));
  610. setCoreBaseInfo(coreBaseInfo,name, f.parse(value.toString()));
  611. }
  612. } else {
  613. if (jsonObject.getJSONObject("staffInfos").getString("idCardType") != null
  614. && name.equals("entrys.IDCardNo")) {
  615. // 获取证件类型的 JSON 对象
  616. JSONObject string = jsonObject.getJSONObject("CertificateType");
  617. // 获取证件类型的值
  618. String string1 = jsonObject.getJSONObject("staffInfos").getString("idCardType");
  619. if ("1".equals(string1)) {
  620. // 如果证件类型为 1,将值设置到身份证号码字段中
  621. //coreBaseInfo.put(name, value);
  622. setCoreBaseInfo(coreBaseInfo,name,value);
  623. } else {
  624. // 否则,将值设置到护照号码字段中
  625. //coreBaseInfo.put("passportNO", value);
  626. setCoreBaseInfo(coreBaseInfo,"entrys.passportNO", value);
  627. }
  628. } else {
  629. setCoreBaseInfo(coreBaseInfo,name,value);
  630. // 将值设置到当前实体对象中
  631. //coreBaseInfo.put(name, value);
  632. }
  633. }
  634. }
  635. // 返回处理后的文件信息的 JSON 数组
  636. return files;
  637. }
  638. public void setCoreBaseInfo(CoreBaseInfo coreBaseInfo,String name,Object value){
  639. if (name.indexOf(".")>=0){
  640. String[] split = name.split("\\.");
  641. Object o = coreBaseInfo.get(split[0]);
  642. if (o instanceof EmpEnrollBizBillEntryInfo){
  643. ((CoreBaseInfo) o).put(split[1],value);
  644. }else if (o instanceof EmpEnrollBizBillEntryCollection){
  645. EmpEnrollBizBillEntryCollection collection = ((EmpEnrollBizBillEntryCollection) o);
  646. EmpEnrollBizBillEntryInfo objectValue=null;
  647. if (collection.size()==0){
  648. objectValue= new EmpEnrollBizBillEntryInfo();
  649. collection.add(objectValue);
  650. }else {
  651. objectValue = collection.get(0);
  652. }
  653. objectValue.put(split[1],value);
  654. //collection.add(objectValue);
  655. }
  656. }else {
  657. coreBaseInfo.put(name,value);
  658. }
  659. }
  660. /**
  661. * 处理头部信息
  662. *
  663. * @param uiViewInfo 头部 UI 视图信息
  664. * @param jsonObject 人员信息的 JSON 对象
  665. * @param fileJSON 文件信息的 JSON 数组
  666. * @return 保存后的对象主键
  667. * @throws BOSException BOS 异常
  668. * @throws SHRWebException SHR 网页异常
  669. * @throws EASBizException EAS 业务异常
  670. * @throws JSONException JSON 处理异常
  671. * @throws ParseException 解析异常
  672. * @throws IOException 输入输出异常
  673. */
  674. public String headProcessing(UIViewInfo uiViewInfo, JSONObject jsonObject
  675. , JSONArray fileJSON, String fileName) throws BOSException, SHRWebException,
  676. EASBizException, JSONException, ParseException, IOException {
  677. // 根据 UI 视图的主键生成动态 UI 视图信息
  678. com.kingdee.shr.base.syssetting.web.dynamic.model.UIViewInfo uiViewInfo1 =
  679. generateUIView(context, uiViewInfo.getUipk());
  680. // 获取实体名称
  681. String entityName = uiViewInfo1.getEntityName();
  682. // 获取字段列表
  683. List<FieldInfo> fields = uiViewInfo1.getFields();
  684. // 根据实体名称获取对应的对象值类
  685. Class objectValueClass = MetaDataUtil.getObjectValueClass(entityName);
  686. // 创建对应的实体对象
  687. CoreBaseInfo coreBaseInfo = (CoreBaseInfo) MetaDataUtil.newInstance(objectValueClass, entityName);
  688. coreBaseInfo.getBOSType();
  689. // 处理字段信息
  690. JSONArray jsonArray = this.fieldProcessing(fields, coreBaseInfo, jsonObject, fileName);
  691. // 创建对应的业务对象
  692. ICoreBase bosObject = (ICoreBase) (BOSObjectFactory.createBOSObject(context, coreBaseInfo.getBOSType()));
  693. // 保存实体对象
  694. IObjectPK save = bosObject.save(coreBaseInfo);
  695. PersonInfo personInfo = (PersonInfo) coreBaseInfo.get("person");
  696. // 处理文件信息
  697. fileProcessor(save.toString(), personInfo, jsonArray);
  698. // 获取文件信息的第一个 JSON 对象
  699. if (fileJSON!=null){
  700. JSONObject jsonObject1 = fileJSON.getJSONObject(0);
  701. if (!save.toString().equals("")) {
  702. // 遍历字段列表
  703. for (int i = 0; i < fields.size(); i++) {
  704. // 获取单个字段信息
  705. FieldInfo fieldInfo = fields.get(i);
  706. // 获取字段的别名
  707. String alias = fieldInfo.getAlias();//CertificateNu
  708. // 获取字段的名称
  709. String name = fieldInfo.getName();//idCardNO
  710. if (!name.equals(fileName)) {
  711. continue;
  712. }
  713. // 分割字段别名
  714. String[] split = alias.split("#");
  715. // 获取字段的属性
  716. Map<String, String> attributes = fieldInfo.getAttributes();
  717. // 获取数据的 UI 主键
  718. String uipk = attributes.get("data-uipk");
  719. // 获取文件信息
  720. JSONObject data = jsonObject1.getJSONObject(split[1]);
  721. if (data != null) {
  722. // 获取下载链接
  723. JSONArray downloadUrl = data.getJSONArray("downloadUrls");
  724. // 分割下载链接
  725. // 获取文件名
  726. //String text = data.getString("text");
  727. // 分割文件名
  728. //String[] split2 = text.split(",");
  729. for (int k = 0; k < downloadUrl.size(); k++) {
  730. byte[] dataImg = new byte[0];
  731. // 拼接完整的下载链接
  732. String URL = "http:" + downloadUrl.get(k);
  733. System.out.println("===========" + URL + "==========");
  734. // 从网络下载文件数据
  735. dataImg = helper.getBytesByNetURL(URL);
  736. // 插入人员附件信息
  737. //insertPersonAttachment(split2[k], uipk, save.toString(), dataImg);
  738. }
  739. }
  740. }
  741. }
  742. }
  743. // 返回保存后的人员信息实体对象的主键
  744. return save.toString();
  745. }
  746. /**
  747. * 处理文件信息
  748. *
  749. * @param id 关联的 ID
  750. * @param personInfo 人员信息对象
  751. * @param jsonArray 文件信息的 JSON 数组
  752. * @throws JSONException JSON 处理异常
  753. */
  754. public void fileProcessor(String id, PersonInfo personInfo, JSONArray jsonArray) throws JSONException {
  755. // 遍历文件信息的 JSON 数组
  756. for (int i = 0; i < jsonArray.size(); i++) {
  757. // 获取单个文件信息
  758. JSONObject jsonObject1 = jsonArray.getJSONObject(i);
  759. // 获取数据的 UI 主键
  760. String uipk = jsonObject1.getString("uipk");
  761. // 获取文件的下载链接
  762. String url = jsonObject1.getString("url");
  763. // 获取文件的名称
  764. String name = jsonObject1.getString("name");
  765. if (url==null||url.toString().equals("")||url.toString().equals("[]")){
  766. continue;
  767. }
  768. if (uipk.equals("PersonPhoto")) {
  769. try {
  770. if (personInfo != null) {
  771. // 保存人员照片信息
  772. savePersonPhoto(personInfo, url);
  773. }
  774. } catch (IOException e) {
  775. // 抛出运行时异常,表示保存人员照片信息失败
  776. throw new RuntimeException(e);
  777. }
  778. } else {
  779. try {
  780. // 从网络下载文件数据
  781. byte[] dataImg = null;
  782. if (url.indexOf("http:")>=0||url.indexOf("https:")>=0){
  783. dataImg= helper.getBytesByNetURL(url);
  784. }else {
  785. dataImg= helper.getBytesByNetURL("http:" + url);
  786. }
  787. // 插入人员附件信息
  788. if (name==null){
  789. name = extractFileNameFromUrl(url);
  790. }
  791. insertPersonAttachment(name, uipk, id, dataImg);
  792. } catch (IOException e) {
  793. // 抛出运行时异常,表示下载文件数据失败
  794. throw new RuntimeException(e);
  795. } catch (BOSException e) {
  796. // 抛出运行时异常,表示插入人员附件信息失败
  797. throw new RuntimeException(e);
  798. } catch (EASBizException e) {
  799. // 抛出运行时异常,表示插入人员附件信息失败
  800. throw new RuntimeException(e);
  801. }
  802. }
  803. }
  804. }
  805. public static void main(String[] args) {
  806. String name = extractFileNameFromUrl("https://dfiles.italent.cn/download/recruitonboardingfile/433107/1753067254/3/66304e3e5cb7431f9fb1900ba675cee3.jpg?sig_t=1753070295&sig_exp=2592000&sig_a=recruitonboarding&sig_pm=8&sig_npm=2&sig_v=1&sig=41d7e3c49cef36421ff8c4c4bd4ff6b145810ca3");
  807. System.out.println(name);
  808. }
  809. // 从URL中提取文件名
  810. private static String extractFileNameFromUrl(String url) {
  811. if (url == null || url.isEmpty()) {
  812. return null;
  813. }
  814. int lastSlash = url.lastIndexOf('/');
  815. if (lastSlash != -1 && lastSlash < url.length() - 1) {
  816. String fileName = url.substring(lastSlash + 1);
  817. // 去除查询参数
  818. int queryIndex = fileName.indexOf('?');
  819. if (queryIndex != -1) {
  820. fileName = fileName.substring(0, queryIndex);
  821. }
  822. return fileName;
  823. }
  824. return null;
  825. }
  826. /**
  827. * 保存人员照片信息
  828. *
  829. * @param personInfo 人员信息对象
  830. * @param iDPhotoDownloadUrl 照片下载链接
  831. * @throws IOException 输入输出异常
  832. */
  833. private void savePersonPhoto(PersonInfo personInfo, String iDPhotoDownloadUrl) throws IOException {
  834. if (!StringUtils.isEmpty(iDPhotoDownloadUrl)) {
  835. // 打印照片下载链接
  836. System.out.println("iDPhotoDownloadUrl" + iDPhotoDownloadUrl);
  837. // 从网络下载照片数据
  838. byte[] dataImg = helper.getBytesByNetURL("http:" + iDPhotoDownloadUrl);
  839. // 创建人员照片信息对象
  840. PersonPhotoInfo personPhotoInfo = new PersonPhotoInfo();
  841. // 设置照片数据
  842. personPhotoInfo.setImageData(dataImg);
  843. // 设置关联的人员信息对象
  844. personPhotoInfo.setPerson(personInfo);
  845. try {
  846. // 保存人员照片信息
  847. PersonPhotoFactory.getLocalInstance(context)
  848. .save(personPhotoInfo);
  849. } catch (EASBizException e) {
  850. e.printStackTrace();
  851. } catch (BOSException e) {
  852. e.printStackTrace();
  853. }
  854. }
  855. }
  856. /**
  857. * 插入人员附件信息
  858. *
  859. * @param filename 文件名
  860. * @param uipk 数据的 UI 主键
  861. * @param boId 业务对象的 ID
  862. * @param data 文件数据
  863. * @return 附件的 ID
  864. * @throws BOSException BOS 异常
  865. * @throws EASBizException EAS 业务异常
  866. */
  867. public String insertPersonAttachment(String filename, String uipk, String boId, byte[] data) throws BOSException, EASBizException {
  868. if (data.length > 20971520) {
  869. // 如果文件大小超过 20MB,抛出 BOS 异常
  870. throw new BOSException("文件上传失败,文件大小超过20MB!");
  871. } else if (!org.apache.commons.lang3.StringUtils.isBlank(filename) && !org.apache.commons.lang3.StringUtils.isBlank(boId) && data.length > 0) {
  872. // 创建 SHR 附件扩展信息对象
  873. SHRAttachmentExtInfo attchExt = new SHRAttachmentExtInfo();
  874. // 创建附件信息对象
  875. AttachmentInfo ai = new AttachmentInfo();
  876. // 获取管理员用户信息
  877. UserInfo userInfo = UserFactory.getLocalInstance(context).getUserInfo("where number = 'administrator'");
  878. // 获取用户 ID
  879. String userId = userInfo.getId().toString();
  880. // 设置附件名称
  881. ai.setName(filename.substring(0, filename.lastIndexOf(46)));
  882. // 设置附件简单名称
  883. ai.setSimpleName(filename.substring(filename.lastIndexOf(".") + 1));
  884. // 设置附件描述
  885. ai.setDescription("");
  886. // 设置附件文件数据
  887. ai.setFile(data);
  888. // 设置附件是否共享
  889. ai.setIsShared(false);
  890. // 设置附件共享描述
  891. ai.setSharedDesc("否");
  892. // 设置附件 ID
  893. ai.setAttachID("" + System.currentTimeMillis());
  894. // 设置附件类型
  895. ai.setType(this.getFileType(filename));
  896. // 将附件信息对象设置到 SHR 附件扩展信息对象中
  897. attchExt.setAttachment(ai);
  898. // 设置 SHR 附件扩展信息对象的名称
  899. attchExt.setName(filename);
  900. // 设置 SHR 附件扩展信息对象的属性名称
  901. attchExt.setPropertyName("null0");
  902. // 设置 SHR 附件扩展信息对象的类型
  903. attchExt.setType(AttachmentTypeEnum.FORM);
  904. // 设置 SHR 附件扩展信息对象的状态
  905. attchExt.setState(AttachmentState.UNSAVE);
  906. // 设置 SHR 附件扩展信息对象的绑定信息
  907. attchExt.setBunding(userId + "#" + uipk);
  908. // 设置 SHR 附件扩展信息对象关联的业务对象 ID
  909. attchExt.setBoID(boId);
  910. // 设置 SHR 附件扩展信息对象的状态
  911. attchExt.setState(AttachmentState.SAVE);
  912. // 保存附件信息对象
  913. AttachmentFactory.getLocalInstance(context).save(ai);
  914. // 设置 SHR 附件扩展信息对象的状态
  915. attchExt.setState(AttachmentState.SAVE);
  916. // 创建业务对象与附件关联信息对象
  917. BoAttchAssoInfo boAttchAssoInfo = new BoAttchAssoInfo();
  918. // 设置业务对象与附件关联信息对象关联的业务对象 ID
  919. boAttchAssoInfo.setBoID(boId);
  920. // 设置业务对象与附件关联信息对象关联的业务对象类型
  921. boAttchAssoInfo.setAssoBusObjType(String.valueOf(BOSUuid.getBOSObjectType(boId, true)));
  922. // 设置业务对象与附件关联信息对象的关联类型
  923. boAttchAssoInfo.setAssoType("Added Accessories");
  924. // 将附件信息对象设置到业务对象与附件关联信息对象中
  925. boAttchAssoInfo.setAttachment(ai);
  926. // 保存业务对象与附件关联信息对象
  927. BoAttchAssoFactory.getLocalInstance(context).save(boAttchAssoInfo);
  928. // 保存 SHR 附件扩展信息对象
  929. SHRAttachmentExtFactory.getLocalInstance(context).save(attchExt);
  930. // 返回附件的 ID
  931. return ai.getId().toString();
  932. } else {
  933. // 如果文件名、业务对象 ID 或文件数据为空,抛出 BOS 异常
  934. throw new BOSException("文件上传失败,请确认信息无误!");
  935. }
  936. }
  937. /**
  938. * 根据文件名获取文件类型
  939. *
  940. * @param fullname 文件名
  941. * @return 文件类型
  942. */
  943. private String getFileType(String fullname) {
  944. // 获取文件扩展名
  945. String extname = fullname.substring(fullname.lastIndexOf(".") + 1, fullname.length());
  946. if (!"doc".equalsIgnoreCase(extname) && !"docx".equalsIgnoreCase(extname)) {
  947. if (!"xls".equalsIgnoreCase(extname) && !"xlsx".equalsIgnoreCase(extname) && !"xlsm".equalsIgnoreCase(extname) && !"xlsb".equalsIgnoreCase(extname)) {
  948. if (!"ppt".equalsIgnoreCase(extname) && !"pptx".equalsIgnoreCase(extname) && !"pptm".equalsIgnoreCase(extname)) {
  949. return "txt".equalsIgnoreCase(extname) ? "TEXT 文本文件" : "未知文件类型(." + extname + ")";
  950. } else {
  951. return "Microsoft PowerPoint 幻灯片";
  952. }
  953. } else {
  954. return "Microsoft Excel 表格";
  955. }
  956. } else {
  957. return "Microsoft Word 文档";
  958. }
  959. }
  960. /**
  961. * 根据 UI 视图的主键生成动态 UI 视图信息
  962. *
  963. * @param ctx 上下文对象
  964. * @param uipk UI 视图的主键
  965. * @return 动态 UI 视图信息
  966. * @throws SHRWebException SHR 网页异常
  967. */
  968. private com.kingdee.shr.base.syssetting.web.dynamic.model.UIViewInfo generateUIView(Context ctx, String uipk) throws SHRWebException {
  969. // 从数据库中获取 UI 视图信息
  970. com.kingdee.shr.base.syssetting.UIViewInfo dbUIViewInfo = getUIViewFromDB(ctx, uipk);
  971. if (dbUIViewInfo == null) {
  972. if (uipk.contains(" ")) {
  973. // 如果 UI 视图主键包含空格,抛出 SHR 网页业务异常
  974. throw new ShrWebBizException(MessageFormat.format(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "view_contain_blank"), uipk));
  975. } else {
  976. // 如果 UI 视图信息为空,抛出 SHR 网页业务异常
  977. throw new ShrWebBizException(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "view_not_found"));
  978. }
  979. } else {
  980. // 处理树导航元素
  981. dealTreeNavigationElement(dbUIViewInfo);
  982. // 获取 UI 视图转换器
  983. IUIViewConverter converter = UIViewConverterFactory.getUIViewConverter(dbUIViewInfo, ctx);
  984. // 执行转换操作
  985. return converter.exec();
  986. }
  987. }
  988. /**
  989. * 处理树导航元素
  990. *
  991. * @param dbUIViewInfo UI 视图信息
  992. */
  993. private void dealTreeNavigationElement(com.kingdee.shr.base.syssetting.UIViewInfo dbUIViewInfo) {
  994. // 处理配置信息
  995. String content = dealConfig(dbUIViewInfo.getContent());
  996. // 处理扩展配置信息
  997. String extend = dealConfig(dbUIViewInfo.getExtend());
  998. if (!StringUtils.isEmpty(content)) {
  999. // 如果处理后的配置信息不为空,设置到 UI 视图信息中
  1000. dbUIViewInfo.setContent(content);
  1001. }
  1002. if (!StringUtils.isEmpty(extend)) {
  1003. // 如果处理后的扩展配置信息不为空,设置到 UI 视图信息中
  1004. dbUIViewInfo.setExtend(extend);
  1005. }
  1006. }
  1007. /**
  1008. * 从数据库中获取 UI 视图信息
  1009. *
  1010. * @param ctx 上下文对象
  1011. * @param uipk UI 视图的主键
  1012. * @return UI 视图信息
  1013. * @throws SHRWebException SHR 网页异常
  1014. */
  1015. public com.kingdee.shr.base.syssetting.UIViewInfo getUIViewFromDB(Context ctx, String uipk) throws SHRWebException {
  1016. try {
  1017. if (LocaleUtils.locale_zh_CN.toString().equals(LocaleUtils.getLocaleString(LocaleUtils.getFirstOriginLocale(ctx.getLocale())))) {
  1018. // 如果是中文环境,根据 UI 视图主键和选择器从数据库中获取 UI 视图信息
  1019. return UIViewFactory.getLocalInstance(ctx).getValueByUipk(uipk, SysSettingUIViewUtil.getUIViewSelector());
  1020. } else {
  1021. // 如果不是中文环境,使用多语言服务进行转换
  1022. Map<String, Object> params = new HashMap();
  1023. params.put("uipks", uipk);
  1024. params.put("isConvert", true);
  1025. Object obj = MLServiceFactory.getLocalInstance(ctx).convert(ResourceType.UIView, params);
  1026. return null == obj ? null : (com.kingdee.shr.base.syssetting.UIViewInfo) obj;
  1027. }
  1028. } catch (BOSException var4) {
  1029. // 抛出 SHR 网页业务异常
  1030. throw new ShrWebBizException(var4.getMessage(), var4);
  1031. } catch (EASBizException var5) {
  1032. // 抛出 SHR 网页业务异常
  1033. throw new ShrWebBizException(var5.getMessage(), var5);
  1034. }
  1035. }
  1036. /**
  1037. * 处理配置信息
  1038. *
  1039. * @param text 配置信息文本
  1040. * @return 处理后的配置信息
  1041. */
  1042. private String dealConfig(String text) {
  1043. if (StringUtils.isEmpty(text)) {
  1044. return null;
  1045. } else {
  1046. try {
  1047. // 获取 XML 输出器
  1048. XMLOutputter output = XMLUtil.getXMLOutputter();
  1049. // 解析 XML 文本
  1050. Document doc = XMLUtil.parseXML(text);
  1051. // 获取根元素
  1052. Element rootElement = doc.getRootElement();
  1053. // 创建树导航 XPath 对象
  1054. XPath xPathTreeNavigation = XPath.newInstance("//treeNavigation");
  1055. // 创建过滤器项 XPath 对象
  1056. XPath xPathFilterItem = XPath.newInstance("//filterItem[@isAdminOrg='true']");
  1057. // 获取树导航元素列表
  1058. List<Element> treeNavigations = xPathTreeNavigation.selectNodes(rootElement);
  1059. // 获取过滤器项元素列表
  1060. List<Element> filterItems = xPathFilterItem.selectNodes(rootElement);
  1061. if (null != treeNavigations && treeNavigations.size() > 0) {
  1062. if (null != filterItems && filterItems.size() > 0) {
  1063. // 遍历树导航元素列表
  1064. Iterator i$ = treeNavigations.iterator();
  1065. while (i$.hasNext()) {
  1066. // 获取单个树导航元素
  1067. Element e = (Element) i$.next();
  1068. // 获取父元素
  1069. Element parent = e.getParent();
  1070. // 从父元素中移除树导航元素
  1071. parent.removeContent(e);
  1072. }
  1073. // 输出处理后的 XML 文本
  1074. String r = output.outputString(doc);
  1075. return r;
  1076. } else {
  1077. return null;
  1078. }
  1079. } else {
  1080. return null;
  1081. }
  1082. } catch (Exception var11) {
  1083. return null;
  1084. }
  1085. }
  1086. }
  1087. }