BeiSenSysTest.java 66 KB

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