package com.kingdee.eas.custom.webbeisen.test; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.kingdee.bos.BOSException; import com.kingdee.bos.BOSObjectFactory; import com.kingdee.bos.Context; import com.kingdee.bos.bsf.service.app.IHRMsfService; import com.kingdee.bos.dao.IObjectPK; import com.kingdee.bos.dao.IObjectValue; import com.kingdee.bos.dao.ormapping.ObjectUuidPK; import com.kingdee.bos.metadata.entity.*; import com.kingdee.bos.metadata.query.util.CompareType; import com.kingdee.bos.util.BOSUuid; import com.kingdee.eas.base.attachment.AttachmentFactory; import com.kingdee.eas.base.attachment.AttachmentInfo; import com.kingdee.eas.base.attachment.BoAttchAssoFactory; import com.kingdee.eas.base.attachment.BoAttchAssoInfo; import com.kingdee.eas.base.codingrule.CodingRuleManagerFactory; import com.kingdee.eas.base.codingrule.ICodingRuleManager; import com.kingdee.eas.base.permission.UserFactory; import com.kingdee.eas.base.permission.UserInfo; import com.kingdee.eas.basedata.org.*; import com.kingdee.eas.basedata.person.PersonCollection; import com.kingdee.eas.basedata.person.PersonInfo; import com.kingdee.eas.common.EASBizException; import com.kingdee.eas.custom.beisenconfig.*; import com.kingdee.eas.custom.enumerations.ViewTypeEnum; import com.kingdee.eas.custom.webbeisen.utils.Helper; import com.kingdee.eas.framework.CoreBaseCollection; import com.kingdee.eas.framework.CoreBaseInfo; import com.kingdee.eas.framework.ICoreBase; import com.kingdee.eas.hr.affair.*; import com.kingdee.eas.hr.base.ApproveTypeEnum; import com.kingdee.eas.hr.base.HRBillStateEnum; import com.kingdee.eas.hr.emp.PersonPhotoFactory; import com.kingdee.eas.hr.emp.PersonPhotoInfo; import com.kingdee.shr.ats.web.util.NumberCodeRule; import com.kingdee.shr.attachment.AttachmentState; import com.kingdee.shr.attachment.AttachmentTypeEnum; import com.kingdee.shr.attachment.SHRAttachmentExtFactory; import com.kingdee.shr.attachment.SHRAttachmentExtInfo; import com.kingdee.shr.base.syssetting.MSFServiceFacadeFactory; import com.kingdee.shr.base.syssetting.UIType; import com.kingdee.shr.base.syssetting.UIViewFactory; import com.kingdee.shr.base.syssetting.UIViewInfo; import com.kingdee.shr.base.syssetting.app.util.XMLUtil; import com.kingdee.shr.base.syssetting.exception.SHRWebException; import com.kingdee.shr.base.syssetting.exception.ShrWebBizException; import com.kingdee.shr.base.syssetting.ml.SHRWebResource; import com.kingdee.shr.base.syssetting.util.MetaDataUtil; import com.kingdee.shr.base.syssetting.util.SysSettingUIViewUtil; import com.kingdee.shr.base.syssetting.web.dynamic.model.FieldInfo; import com.kingdee.shr.base.syssetting.web.dynamic.view.converter.IUIViewConverter; import com.kingdee.shr.base.syssetting.web.dynamic.view.converter.UIViewConverterFactory; import com.kingdee.shr.ml.MLServiceFactory; import com.kingdee.shr.ml.ResourceType; import com.kingdee.util.LocaleUtils; import com.kingdee.util.StringUtils; import org.apache.log4j.Logger; import org.jdom.Document; import org.jdom.Element; import org.jdom.output.XMLOutputter; import org.jdom.xpath.XPath; import org.json.JSONException; import java.io.IOException; import java.text.MessageFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; public class BeiSenSysTest implements IHRMsfService { Helper helper = null; Context context = null; private static Logger logger = Logger.getLogger("com.kingdee.eas.custom.beisen.synchronousorg.SynchronousEmpBillControllerBean"); @Override public Object process(Context context, Map map) throws EASBizException, BOSException { String param = map.get("param") == null ? "" : map.get("param").toString(); String number = map.get("number") == null ? "" : map.get("number").toString(); empBill(context, param, number); return null; } public void empBill(Context ctx, String param, String viewConfigId) throws BOSException { helper = new Helper(ctx); this.context = ctx; EntityViewInfo entityViewInfo = new EntityViewInfo(); FilterInfo filterInfo = new FilterInfo(); filterInfo.getFilterItems().add(new FilterItemInfo("isEnabled", true, CompareType.EQUALS)); filterInfo.getFilterItems().add(new FilterItemInfo("number", viewConfigId, CompareType.EQUALS)); entityViewInfo.setFilter(filterInfo); //获取北森视图配置信息 BSViewConfigCollection bsViewConfigCollection = BSViewConfigFactory.getLocalInstance(ctx).getBSViewConfigCollection(entityViewInfo); if (bsViewConfigCollection.size() <= 0) { throw new RuntimeException("配置未启用或者不存在"); } BSViewConfigInfo bsViewConfigInfo = bsViewConfigCollection.get(0); String osfParam = bsViewConfigInfo.getOsfParam(); String osfSericeName = bsViewConfigInfo.getOsfSericeName(); Map serviceParam = new HashMap(); if (param != null && !param.equals("")) { JSONObject jsonObject = JSONObject.parseObject(osfParam); jsonObject.put("staffId", param); osfParam = jsonObject.toJSONString(); } serviceParam.put("param", osfParam); JSONArray beiSenData = null; try { SelectorItemCollection selectorItemCollection = new SelectorItemCollection(); selectorItemCollection.add("*"); selectorItemCollection.add("view.*"); Object o = MSFServiceFacadeFactory.getLocalInstance(ctx).processService(osfSericeName, serviceParam); beiSenData = JSONArray.parseArray(o.toString()); //查询头部视图配置 头部视图配置只能有一个 EntityViewInfo entryHeadEntityViewInfo = new EntityViewInfo(); FilterInfo entryHeadFilterInfo = new FilterInfo(); entryHeadFilterInfo.getFilterItems().add(new FilterItemInfo("parent", bsViewConfigInfo.getId().toString(), CompareType.EQUALS)); entryHeadFilterInfo.getFilterItems().add(new FilterItemInfo("boy", ViewTypeEnum.HEAD_VALUE, CompareType.EQUALS)); entryHeadEntityViewInfo.setSelector(selectorItemCollection); entryHeadEntityViewInfo.setFilter(entryHeadFilterInfo); BSViewConfigEntryCollection headBsViewConfigEntryCollection = BSViewConfigEntryFactory .getLocalInstance(ctx).getBSViewConfigEntryCollection(entryHeadEntityViewInfo); if (headBsViewConfigEntryCollection.size() != 1) { throw new RuntimeException("头部配置有且只能有一个"); } BSViewConfigEntryInfo bsViewConfigEntryInfo = headBsViewConfigEntryCollection.get(0); UIViewInfo view = bsViewConfigEntryInfo.getView(); String file = bsViewConfigEntryInfo.getFile(); for (int i = 0; i < beiSenData.size(); i++) { JSONObject jsonObject1 = beiSenData.getJSONObject(i); JSONArray fileArray = jsonObject1.getJSONArray(file); boolean isCreateData = bsViewConfigEntryInfo.isIsCreateData(); String headId = null; if (isCreateData) { String headDataEntry = bsViewConfigEntryInfo.getHeadDataEntry(); if (headDataEntry!=null&&!headDataEntry.equals("")){ Class objectValueClass = MetaDataUtil.getObjectValueClass(headDataEntry); // 创建对应的实体对象 CoreBaseInfo coreBaseInfo = (CoreBaseInfo) MetaDataUtil.newInstance(objectValueClass, headDataEntry); if (coreBaseInfo instanceof EmpEnrollBizBillInfo) { System.out.println("针对入职单处理"); String string = jsonObject1.getJSONObject("staffInfos").getString("id"); EmpEnrollBizBillCollection collection = EmpEnrollBizBillFactory.getLocalInstance(ctx) .getEmpEnrollBizBillCollection("select *,entrys.*,entrys.person.* where beisenid='" + string + "'"); if (collection.size() > 0) { System.out.println("=======入职单已存在=============");//0044610 continue; } } } headId = headProcessing(view, jsonObject1, fileArray, file); } else { String headDataEntry = bsViewConfigEntryInfo.getHeadDataEntry(); Class objectValueClass = MetaDataUtil.getObjectValueClass(headDataEntry); // 创建对应的实体对象 CoreBaseInfo coreBaseInfo = (CoreBaseInfo) MetaDataUtil.newInstance(objectValueClass, headDataEntry); if (coreBaseInfo instanceof EmpEnrollBizBillInfo) { System.out.println("针对入职单处理"); String string = jsonObject1.getJSONObject("staffInfos").getString("id"); EmpEnrollBizBillCollection collection = EmpEnrollBizBillFactory.getLocalInstance(ctx) .getEmpEnrollBizBillCollection("select *,entrys.*,entrys.person.* where beisenid='" + string + "'"); if (collection.size() > 0) { EmpEnrollBizBillInfo empEnrollBizBillInfo = collection.get(0); EmpEnrollBizBillEntryCollection entrys = empEnrollBizBillInfo.getEntrys(); if (entrys.size() > 0) { PersonInfo person = entrys.get(0).getPerson(); if (view != null) { System.out.println("======修改信息========="); headProcessing(view, jsonObject1, person, fileArray, file); } headId = person.getId().toString(); } } } else { //其他处理 还没想好怎么做 暂时满足需求 后续有想法在填入 } } if (headId == null) { continue; } EntityViewInfo entryBoyEntityViewInfo = new EntityViewInfo(); FilterInfo entryBoyFilterInfo = new FilterInfo(); entryBoyFilterInfo.getFilterItems().add(new FilterItemInfo("parent", bsViewConfigInfo.getId().toString(), CompareType.EQUALS)); entryBoyFilterInfo.getFilterItems().add(new FilterItemInfo("boy", ViewTypeEnum.BOY_VALUE, CompareType.EQUALS)); entryBoyEntityViewInfo.setSelector(selectorItemCollection); entryBoyEntityViewInfo.setFilter(entryBoyFilterInfo); BSViewConfigEntryCollection boyBsViewConfigEntryCollection = BSViewConfigEntryFactory .getLocalInstance(ctx).getBSViewConfigEntryCollection(entryBoyEntityViewInfo); for (int j = 0; j < boyBsViewConfigEntryCollection.size(); j++) { BSViewConfigEntryInfo boybsViewConfigEntryInfo = boyBsViewConfigEntryCollection.get(j); UIViewInfo view1 = boybsViewConfigEntryInfo.getView(); String beiSenData1 = boybsViewConfigEntryInfo.getBeiSenData(); UIType type = view1.getType(); boolean isCreateData1 = boybsViewConfigEntryInfo.isIsCreateData(); if (type.getValue().equals("list")) { boyProcessing(view1, headId, jsonObject1.getJSONArray(beiSenData1), null, "fileInfos", beiSenData1); } else { boyProcessing(view1, isCreateData1, headId, jsonObject1.getJSONObject(beiSenData1), null, "fileInfos", beiSenData1); } } } } catch (EASBizException e) { //获取北森数据失败 throw new RuntimeException(e); } catch (JSONException e) { throw new RuntimeException(e); } catch (ParseException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } catch (SHRWebException e) { throw new RuntimeException(e); } } /** * 处理表单类型的主体信息 * * @param id 关联的 ID * @param jsonObject 主体信息的 JSON 对象 * @param fileJSON 文件信息的 JSON 数组 * @return 保存后的对象主键 * @throws JSONException JSON 处理异常 * @throws SHRWebException SHR 网页异常 * @throws BOSException BOS 异常 * @throws EASBizException EAS 业务异常 * @throws ParseException 解析异常 * @throws IOException 输入输出异常 */ public String boyProcessing(UIViewInfo uiViewInfo, boolean isCreateData1, String id, JSONObject jsonObject, JSONArray fileJSON, String fileName, String beiSenData1) throws JSONException, SHRWebException, BOSException, EASBizException, ParseException, IOException { // 根据 UI 视图的主键生成动态 UI 视图信息 com.kingdee.shr.base.syssetting.web.dynamic.model.UIViewInfo uiViewInfo1 = generateUIView(context, uiViewInfo.getUipk()); // 获取实体名称 String entityName = uiViewInfo1.getEntityName(); // 获取字段列表 List fields = uiViewInfo1.getFields(); // 根据实体名称获取对应的对象值类 Class objectValueClass = MetaDataUtil.getObjectValueClass(entityName); // 创建对应的实体对象 CoreBaseInfo coreBaseInfo = (CoreBaseInfo) MetaDataUtil.newInstance(objectValueClass, entityName); // 处理字段信息 JSONObject jsonObject2 = new JSONObject(); jsonObject2.put(beiSenData1, jsonObject); // 创建对应的业务对象 ICoreBase bosObject = (ICoreBase) (BOSObjectFactory.createBOSObject(context, coreBaseInfo.getBOSType())); // 获取关联字段 String relateField = uiViewInfo1.getRelatedField(); if (!isCreateData1) { System.out.println("=============查询不需要同步数据============"+"where " + relateField + " = '" + id+"'"); CoreBaseCollection collection = bosObject.getCollection("where " + relateField + " = '" + id+"'"); if (collection.size()>0){ coreBaseInfo = collection.get(0); System.out.println("=========同步修改数据ID======="+coreBaseInfo.getId()); } } JSONArray jsonArray = this.fieldProcessing(fields, coreBaseInfo, jsonObject2, fileName); // 根据 ID 获取对应的实体对象信息 EntityObjectInfo entityObject = MetaDataUtil.getEntityObject(id); // 获取实体对象的全名称 String fullName = entityObject.getFullName(); // 根据全名称获取对应的对象值类 Class objectValueClass1 = MetaDataUtil.getObjectValueClass(fullName); // 创建对应的实体对象 CoreBaseInfo coreBaseInfo1 = (CoreBaseInfo) MetaDataUtil.newInstance(objectValueClass1, fullName); // 设置实体对象的 ID coreBaseInfo1.setId(BOSUuid.read(id)); // 将关联的实体对象设置到当前实体对象中 coreBaseInfo.put(relateField, coreBaseInfo1); IObjectPK save=null; // 保存实体对象 if (coreBaseInfo instanceof EmpEnrollBizBillInfo){ System.out.println("========submit==========="); coreBaseInfo.put("billState", HRBillStateEnum.SUBMITED ); coreBaseInfo.put("approveType",ApproveTypeEnum.WORKFLOW); coreBaseInfo.setExtendedProperty("isAddNew", "isAddNew"); save = bosObject.submit(coreBaseInfo); }else { System.out.println("========save==========="); save = bosObject.save(coreBaseInfo); } // 处理文件信息 fileProcessor(save.toString(), null, jsonArray); if (fileJSON != null) { // 获取文件信息的第一个 JSON 对象 JSONObject jsonObject1 = fileJSON.getJSONObject(0); if (!save.toString().equals("")) { // 遍历字段列表 for (int i = 0; i < fields.size(); i++) { // 获取单个字段信息 FieldInfo fieldInfo = fields.get(i); // 获取字段的别名 String alias = fieldInfo.getAlias();//CertificateNu // 获取字段的名称 String name = fieldInfo.getName();//idCardNO if (!name.equals("attachments")) { continue; } // 分割字段别名 String[] split = alias.split("#"); // 获取字段的属性 Map attributes = fieldInfo.getAttributes(); // 获取数据的 UI 主键 String dataUipk = attributes.get("data-uipk"); // 获取文件信息 JSONObject data = jsonObject1.getJSONObject(split[1]); if (data != null) { // 获取下载链接 String downloadUrl = data.getString("downloadUrl"); // 分割下载链接 String[] split1 = downloadUrl.split(","); // 获取文件名 String text = data.getString("text"); // 分割文件名 String[] split2 = text.split(","); for (int k = 0; k < split1.length; k++) { byte[] dataImg = new byte[0]; // 拼接完整的下载链接 String URL = "http:" + split1[k]; System.out.println("===========" + URL + "=========="); // 从网络下载文件数据 dataImg = helper.getBytesByNetURL(URL); // 插入人员附件信息 insertPersonAttachment(split2[k], dataUipk, save.toString(), dataImg); } } } } } // 返回保存后的对象主键 return save.toString(); } /** * 处理列表类型的主体信息 * * @param id 关联的 ID * @param jsonArray 主体信息的 JSON 数组 * @param fileJSON 文件信息的 JSON 数组 * @return 保存后的对象主键 * @throws JSONException JSON 处理异常 * @throws SHRWebException SHR 网页异常 * @throws BOSException BOS 异常 * @throws EASBizException EAS 业务异常 * @throws ParseException 解析异常 * @throws IOException 输入输出异常 */ public String boyProcessing(UIViewInfo uiViewInfo, String id, JSONArray jsonArray, JSONArray fileJSON, String fileName, String beiSenData1) throws JSONException, SHRWebException, BOSException, EASBizException, ParseException, IOException { // 根据 UI 视图的主键生成动态 UI 视图信息 com.kingdee.shr.base.syssetting.web.dynamic.model.UIViewInfo uiViewInfo1 = generateUIView(context, uiViewInfo.getUipk()); String fileId = ""; // 获取实体名称 String entityName = uiViewInfo1.getEntityName(); // 获取字段列表 List fields = uiViewInfo1.getFields(); // 获取关联字段 String relateField = uiViewInfo1.getRelatedField(); // 根据 ID 获取对应的实体对象信息 EntityObjectInfo entityObject = MetaDataUtil.getEntityObject(id); // 获取实体对象的全名称 String fullName = entityObject.getFullName(); // 根据全名称获取对应的对象值类 Class objectValueClass1 = MetaDataUtil.getObjectValueClass(fullName); // 创建对应的实体对象 CoreBaseInfo coreBaseInfo1 = (CoreBaseInfo) MetaDataUtil.newInstance(objectValueClass1, fullName); // 设置实体对象的 ID coreBaseInfo1.setId(BOSUuid.read(id)); // 获取排序方法 String sorterMethod = uiViewInfo1.getOrderBy(); // 遍历主体信息的 JSON 数组 for (int i = 0; i < jsonArray.size(); i++) { // 根据实体名称获取对应的对象值类 Class objectValueClass = MetaDataUtil.getObjectValueClass(entityName); // 创建对应的实体对象 CoreBaseInfo coreBaseInfo = (CoreBaseInfo) MetaDataUtil.newInstance(objectValueClass, entityName); // 处理字段信息 JSONObject jsonObject = new JSONObject(); jsonObject.put(beiSenData1, jsonArray.getJSONObject(i)); JSONArray jsonArray1 = this.fieldProcessing(fields, coreBaseInfo, jsonObject, fileName); // 创建对应的业务对象 ICoreBase bosObject = (ICoreBase) (BOSObjectFactory.createBOSObject(context, coreBaseInfo.getBOSType())); // 将关联的实体对象设置到当前实体对象中 coreBaseInfo.put(relateField, coreBaseInfo1); // 设置是否最高的标志 coreBaseInfo.put("IsHighest", "1"); // 设置是否单个的标志 coreBaseInfo.put("isSingle", "1"); IObjectPK save=null; // 保存实体对象 if (coreBaseInfo instanceof EmpEnrollBizBillInfo){ System.out.println("=======submit======="); coreBaseInfo.put("billState", HRBillStateEnum.SUBMITED ); coreBaseInfo.put("approveType",ApproveTypeEnum.WORKFLOW); coreBaseInfo.setExtendedProperty("isAddNew", "isAddNew"); save = bosObject.submit(coreBaseInfo); }else { System.out.println("=======save======="); save = bosObject.save(coreBaseInfo); } if (sorterMethod != null && !sorterMethod.equals("")) { // 根据关联字段和排序方法查询实体对象集合 CoreBaseCollection collection = bosObject.getCollection(" where " + relateField + " = '" + id + "' order by " + sorterMethod); if (collection.size() > 1) { // 获取第一个实体对象 CoreBaseInfo coreBaseInfo2 = collection.get(0); // 设置是否最高的标志 coreBaseInfo2.put("IsHighest", "1"); // 设置是否单个的标志 coreBaseInfo2.put("isSingle", "1"); // 保存实体对象 IObjectPK save1 = bosObject.save(coreBaseInfo2); // 获取保存后的对象主键 fileId = save1.toString(); for (int j = 1; j < collection.size(); j++) { // 获取其他实体对象 CoreBaseInfo coreBaseInfo3 = collection.get(j); // 设置是否最高的标志 coreBaseInfo3.put("IsHighest", "0"); // 设置是否单个的标志 coreBaseInfo3.put("isSingle", "0"); // 保存实体对象 bosObject.save(coreBaseInfo3); } } } // 处理文件信息 fileProcessor(save.toString(), null, jsonArray1); } if (fileJSON != null) { // 获取文件信息的第一个 JSON 对象 JSONObject jsonObject = fileJSON.getJSONObject(0); if (!fileId.equals("")) { // 遍历字段列表 for (int i = 0; i < fields.size(); i++) { // 获取单个字段信息 FieldInfo fieldInfo = fields.get(i); // 获取字段的别名 String alias = fieldInfo.getAlias();//CertificateNu // 获取字段的名称 String name = fieldInfo.getName();//idCardNO if (!name.equals("attachments")) { continue; } // 分割字段别名 String[] split = alias.split("#"); // 获取字段的属性 Map attributes = fieldInfo.getAttributes(); // 获取数据的 UI 主键 String dataUipk = attributes.get("data-uipk"); // 获取文件信息 JSONObject data = jsonObject.getJSONObject(split[1]); if (data != null) { // 获取下载链接 String downloadUrl = data.getString("downloadUrl"); // 分割下载链接 String[] split1 = downloadUrl.split(","); // 获取文件名 String text = data.getString("text"); // 分割文件名 String[] split2 = text.split(","); for (int k = 0; k < split1.length; k++) { byte[] dataImg = new byte[0]; // 拼接完整的下载链接 String URL = "http:" + split1[k]; System.out.println("===========" + URL + "=========="); // 从网络下载文件数据 dataImg = helper.getBytesByNetURL(URL); // 插入人员附件信息 insertPersonAttachment(split2[k], dataUipk, fileId, dataImg); } } } } } return null; } /** * 处理字段信息 * * @param fields 字段列表 * @param coreBaseInfo 实体对象 * @param jsonObject 数据的 JSON 对象 * @return 处理后的文件信息的 JSON 数组 * @throws JSONException JSON 处理异常 * @throws ShrWebBizException SHR 网页业务异常 * @throws BOSException BOS 异常 * @throws ParseException 解析异常 */ public JSONArray fieldProcessing(List fields, CoreBaseInfo coreBaseInfo, JSONObject jsonObject, String fileName) throws JSONException, ShrWebBizException, BOSException, ParseException { System.out.println("===============+" + jsonObject); // 用于存储处理后的文件信息的 JSON 数组 JSONArray files = new JSONArray(); // 用于存储单个文件信息的 JSON 对象 JSONObject file = null; // 遍历字段列表 for (int i = 0; i < fields.size(); i++) { // 获取单个字段信息 FieldInfo fieldInfo = fields.get(i); // 获取字段的属性信息 PropertyInfo property = fieldInfo.getProperty(); // 获取字段的数据类型 DataType dataType = fieldInfo.getDataType(); // 获取字段的别名 String alias = fieldInfo.getAlias();//CertificateNumber.value // 获取字段的名称 String name = fieldInfo.getName();//idCardNO // 分割字段别名 String[] split = alias.split("#"); Object value = null; // 获取字段的属性 Map attributes = fieldInfo.getAttributes(); System.out.println("===============alias:" + alias); Object dataObject = jsonObject.get(split[0]); String s1 = attributes.get("data-valueType"); if (s1 != null && s1.equals("url")) { if (dataObject instanceof JSONObject) { JSONObject data = jsonObject.getJSONObject(split[0]); if (data != null) { value = data.get(split[1]); if (value instanceof JSONObject) { value = data.getJSONObject(split[1]).get(split[2]); if (value instanceof JSONArray) { JSONArray jsonArray = data.getJSONObject(split[1]).getJSONArray(split[2]); String tempValue = ""; for (int j = 0; j < jsonArray.size(); j++) { file = new JSONObject(); String string = jsonArray.getString(j); // 将数据的 UI 主键、下载链接和文件名添加到文件信息的 JSON 对象中 file.put("uipk", attributes.get("data-uipk")); file.put("url", string); file.put("name", data.getString("text")); // 将文件信息的 JSON 对象添加到文件信息的 JSON 数组中 files.add(file); } continue; } } if (value == null || value.equals("null") || value.equals("{}") || value.equals("")) { continue; } // // 将数据的 UI 主键、下载链接和文件名添加到文件信息的 JSON 对象中 // file.put("uipk", attributes.get("data-uipk")); // file.put("url", value); // file.put("name", data.getString("text")); // // 将文件信息的 JSON 对象添加到文件信息的 JSON 数组中 // files.add(file); } } else if (dataObject instanceof JSONArray) { JSONArray jsonArray1 = jsonObject.getJSONArray(split[0]); for (int j = 0; j < jsonArray1.size(); j++) { JSONObject data = jsonArray1.getJSONObject(j); if (data != null) { value = data.get(split[1]); if (value instanceof JSONObject) { value = data.getJSONObject(split[1]).get(split[2]); if (value instanceof JSONArray) { JSONArray jsonArray = data.getJSONObject(split[1]).getJSONArray(split[2]); System.out.println("===========" + jsonArray); String tempValue = ""; for (int k = 0; k < jsonArray.size(); k++) { file = new JSONObject(); String string = jsonArray.getString(k); // 将数据的 UI 主键、下载链接和文件名添加到文件信息的 JSON 对象中 file.put("uipk", attributes.get("data-uipk")); file.put("url", string); file.put("name", data.getString("text")); // 将文件信息的 JSON 对象添加到文件信息的 JSON 数组中 files.add(file); } //continue; } } // if (value == null || value.equals("null") || value.equals("{}") || value.equals("")) { // continue; // } // // 将数据的 UI 主键、下载链接和文件名添加到文件信息的 JSON 对象中 // file.put("uipk", attributes.get("data-uipk")); // file.put("url", value); // file.put("name", data.getString("text")); // // 将文件信息的 JSON 对象添加到文件信息的 JSON 数组中 // files.add(file); } } continue; } } Object data = jsonObject.get(split[0]); // 获取数据的 JSON 对象 if (data == null) { // 如果数据为空,获取默认值 value = attributes.get("data-defaultValue"); } else { JSONObject data1 = null; // 获取数据的值 if (data instanceof JSONArray) { if (jsonObject.getJSONArray(split[0]).size() == 0) { value = attributes.get("data-defaultValue"); } else { JSONArray jsonArray = jsonObject.getJSONArray(split[0]); data1 = jsonArray.getJSONObject(0); } } else { data1 = jsonObject.getJSONObject(split[0]); } value = data1.get(split[1]); if (value == null) { // 如果值为空,获取默认值 value = attributes.get("data-defaultValue"); } else { value = data1.get(split[1]); if (value instanceof JSONObject) { value = data1.getJSONObject(split[1]).get(split[2]); } else if (value instanceof JSONArray) { JSONArray jsonArray = data1.getJSONArray(split[1]); if (jsonArray.size() > 0) { Object o = jsonArray.get(0); if (o instanceof JSONObject) { Object string = jsonArray.getJSONObject(0).get(split[2]); if (string instanceof Integer) { value = jsonArray.getJSONObject(0).getInteger(split[2]); } else if (o instanceof String) { value = jsonArray.getJSONObject(0).getString(split[2]); } } } } else { value = data1.getString(split[1]); } // 获取自定义映射值 String s = attributes.get("data-mappingValue"); if (s != null && !s.equals("")) { // 解析自定义映射值的 JSON 对象 JSONObject jsonObject1 = JSONObject.parseObject(s); if (jsonObject1 != null) { // 根据值获取映射后的值 String string = jsonObject1.getString(value.toString()); if (string != null) { value = string; } } } if (value == null || value.equals("")){ value = attributes.get("data-defaultValue"); } } } System.out.println("=========attributes.get(\"data-defaultValue\")"+attributes.get("data-defaultValue")); if (value == null || value.equals("")) { // 如果值为空,打印日志并跳过处理 System.out.println("+++++++++" + value); continue; } if (dataType != null && dataType.getName().equals("ObjectValue")) { if (property instanceof LinkPropertyInfo) { // 获取关联对象的全名称 String businessImplName = ((LinkPropertyInfo) property).getRelationship().getSupplierObject().getFullName(); // 根据全名称获取对应的对象值类 Class objectValueClass1 = MetaDataUtil.getObjectValueClass(businessImplName); // 创建对应的实体对象 CoreBaseInfo coreBaseInfo1 = (CoreBaseInfo) MetaDataUtil.newInstance(objectValueClass1, businessImplName); // 创建对应的业务对象 ICoreBase bosObject = (ICoreBase) (BOSObjectFactory.createBOSObject(context, coreBaseInfo1.getBOSType())); String where = "where name like '%" + value + "%' or number = '" + value + "'"; if (coreBaseInfo1 instanceof PersonInfo) { where += " or beisenid = '" + value + "'"; } else if (coreBaseInfo1 instanceof AdminOrgUnitInfo) { where += " or originalId = '" + value + "'"; } else if (coreBaseInfo1 instanceof PositionInfo) { where += " or OriginalId = '" + value + "'"; } // 根据名称或编号查询实体对象集合 CoreBaseCollection dataBaseCollection = bosObject.getCollection(where); if (dataBaseCollection.size() <= 0) { // 如果值为空,获取默认值 value = attributes.get("data-defaultValue"); System.out.println("=========默认值重新查询==="+value); // 如果集合为空,将字段的值设置为 null // coreBaseInfo.put(name, null); bosObject = (ICoreBase) (BOSObjectFactory.createBOSObject(context, coreBaseInfo1.getBOSType())); where = "where name like '%" + value + "%' or number = '" + value + "'"; if (coreBaseInfo1 instanceof PersonInfo) { where += " or beisenid = '" + value + "'"; } else if (coreBaseInfo1 instanceof AdminOrgUnitInfo) { where += " or originalId = '" + value + "'"; } else if (coreBaseInfo1 instanceof PositionInfo) { where += " or OriginalId = '" + value + "'"; } dataBaseCollection = bosObject.getCollection(where); if (dataBaseCollection.size() > 0) { setCoreBaseInfo(coreBaseInfo, name, dataBaseCollection.get(0)); } } else { // 将查询到的第一个实体对象设置到当前实体对象中 //coreBaseInfo.put(name, dataBaseCollection.get(0)); setCoreBaseInfo(coreBaseInfo, name, dataBaseCollection.get(0)); } } } else if (dataType != null && dataType.getName().equals("Enum")) { // 如果数据类型为枚举,将值设置到当前实体对象中 //coreBaseInfo.put(name, value); setCoreBaseInfo(coreBaseInfo, name, value); } else if (dataType != null && dataType.getName().equals("Date")) { // 创建日期格式化对象 SimpleDateFormat f = new SimpleDateFormat(attributes.get("dateFormat")); if (!value.equals("") || !value.equals("未知") || !value.equals("9999/12")) { // 将日期字符串解析为日期对象并设置到当前实体对象中 //coreBaseInfo.put(name, f.parse(value)); setCoreBaseInfo(coreBaseInfo, name, f.parse(value.toString())); } } else { if (name.equals("entrys.IDCardNo")) { // 获取证件类型的值 String string1 = jsonObject.getJSONObject("staffInfos").getString("idCardType"); if ("1".equals(string1)) { // 如果证件类型为 1,将值设置到身份证号码字段中 //coreBaseInfo.put(name, value); setCoreBaseInfo(coreBaseInfo, name, value); } else { // 否则,将值设置到护照号码字段中 //coreBaseInfo.put("passportNO", value); setCoreBaseInfo(coreBaseInfo, "entrys.passportNO", value); } } else { setCoreBaseInfo(coreBaseInfo, name, value); // 将值设置到当前实体对象中 //coreBaseInfo.put(name, value); } } } // 返回处理后的文件信息的 JSON 数组 return files; } public void setCoreBaseInfo(CoreBaseInfo coreBaseInfo, String name, Object value) { System.out.println("+++++++++++++++" + name + ":" + value); if (name.indexOf(".") >= 0) { String[] split = name.split("\\."); Object o = coreBaseInfo.get(split[0]); if (o instanceof EmpEnrollBizBillEntryInfo) { ((CoreBaseInfo) o).put(split[1], value); } else if (o instanceof EmpEnrollBizBillEntryCollection) { EmpEnrollBizBillEntryCollection collection = ((EmpEnrollBizBillEntryCollection) o); EmpEnrollBizBillEntryInfo objectValue = null; if (collection.size() == 0) { objectValue = new EmpEnrollBizBillEntryInfo(); //objectValue.setBizDate(new Date()); collection.add(objectValue); } else { objectValue = collection.get(0); Date bizDate = objectValue.getBizDate(); if (bizDate == null) { //objectValue.setBizDate(new Date()); } String empNumber = objectValue.getEmpNumber(); if (empNumber==null||empNumber.equals("")){ try { String billNumber = readCodeRuleNumber(context, new PersonInfo(), getMainOrgByCu(context)); System.out.println("billNumber:"+billNumber); objectValue.setEmpNumber(billNumber); } catch (SHRWebException e) { throw new RuntimeException(e); } } } objectValue.put(split[1], value); } } else { coreBaseInfo.put(name, value); } } public static String getMainOrgByCu(Context ctx) { OrgUnitInfo mainOrg = (OrgUnitInfo)ctx.get(OrgType.HRO); String orgId = mainOrg == null ? "" : mainOrg.getString("id"); if (orgId == null || orgId.trim().length() == 0) { orgId = "00000000-0000-0000-0000-000000000000CCE7AED4"; } return orgId; } public static String readCodeRuleNumber(Context ctx, IObjectValue model, String mainOrgID) throws SHRWebException { boolean hasCodingRule = hasCodingRule(ctx, model, mainOrgID); if (hasCodingRule) { try { ICodingRuleManager iCodingRuleManager = CodingRuleManagerFactory.getLocalInstance(ctx); return iCodingRuleManager.readNumber(model, mainOrgID); } catch (BOSException var5) { throw new SHRWebException(var5); } catch (EASBizException var6) { throw new SHRWebException(var6); } } else { return null; } } public static boolean hasCodingRule(Context ctx, IObjectValue model, String orgId) { try { ICodingRuleManager iCodingRuleManager = CodingRuleManagerFactory.getLocalInstance(ctx); if (orgId != null && orgId.trim().length() > 0 && iCodingRuleManager.isExist(model, orgId)) { return true; } else { String companyId = getNextCompanyId(ctx); return companyId != null && companyId.trim().length() > 0 && iCodingRuleManager.isExist(model, companyId); } } catch (Exception var5) { var5.printStackTrace(); return false; } } public static String getNextCompanyId(Context ctx) throws Exception { ICtrlUnit iCtrlUnit = CtrlUnitFactory.getRemoteInstance(); IObjectPK pk = new ObjectUuidPK("00000000-0000-0000-0000-000000000000CCE7AED4"); OrgUnitInfo rootCU = iCtrlUnit.getCtrlUnitInfo(pk); return rootCU != null ? rootCU.getId().toString() : null; } public String headProcessing(UIViewInfo uiViewInfo, JSONObject jsonObject , CoreBaseInfo coreBaseInfo, JSONArray fileJSON, String fileName) throws BOSException, SHRWebException, EASBizException, JSONException, ParseException, IOException { // 根据 UI 视图的主键生成动态 UI 视图信息 com.kingdee.shr.base.syssetting.web.dynamic.model.UIViewInfo uiViewInfo1 = generateUIView(context, uiViewInfo.getUipk()); // 获取实体名称 String entityName = uiViewInfo1.getEntityName(); // 获取字段列表 List fields = uiViewInfo1.getFields(); // 处理字段信息 JSONArray jsonArray = this.fieldProcessing(fields, coreBaseInfo, jsonObject, fileName); // 创建对应的业务对象 ICoreBase bosObject = (ICoreBase) (BOSObjectFactory.createBOSObject(context, coreBaseInfo.getBOSType())); IObjectPK save=null; // 保存实体对象 if (coreBaseInfo instanceof EmpEnrollBizBillInfo){ System.out.println("===========submit=============="); coreBaseInfo.put("billState", HRBillStateEnum.SUBMITED ); coreBaseInfo.put("approveType",ApproveTypeEnum.WORKFLOW); coreBaseInfo.setExtendedProperty("isAddNew", "isAddNew"); save = bosObject.submit(coreBaseInfo); }else { System.out.println("===========save=============="); save = bosObject.save(coreBaseInfo); } PersonInfo personInfo = null; if (coreBaseInfo instanceof PersonInfo) { personInfo = (PersonInfo) coreBaseInfo; } else { personInfo = (PersonInfo) (coreBaseInfo.get("person")); } // 处理文件信息 fileProcessor(save.toString(), personInfo, jsonArray); // 获取文件信息的第一个 JSON 对象 if (fileJSON != null) { JSONObject jsonObject1 = fileJSON.getJSONObject(0); if (!save.toString().equals("")) { // 遍历字段列表 for (int i = 0; i < fields.size(); i++) { // 获取单个字段信息 FieldInfo fieldInfo = fields.get(i); // 获取字段的别名 String alias = fieldInfo.getAlias();//CertificateNu // 获取字段的名称 String name = fieldInfo.getName();//idCardNO if (!name.equals(fileName)) { continue; } // 分割字段别名 String[] split = alias.split("#"); // 获取字段的属性 Map attributes = fieldInfo.getAttributes(); // 获取数据的 UI 主键 String uipk = attributes.get("data-uipk"); // 获取文件信息 JSONObject data = jsonObject1.getJSONObject(split[1]); if (data != null) { // 获取下载链接 JSONArray downloadUrl = data.getJSONArray("downloadUrls"); // 分割下载链接 // 获取文件名 //String text = data.getString("text"); // 分割文件名 //String[] split2 = text.split(","); for (int k = 0; k < downloadUrl.size(); k++) { byte[] dataImg = new byte[0]; // 拼接完整的下载链接 String URL = "http:" + downloadUrl.get(k); System.out.println("===========" + URL + "=========="); // 从网络下载文件数据 dataImg = helper.getBytesByNetURL(URL); // 插入人员附件信息 //insertPersonAttachment(split2[k], uipk, save.toString(), dataImg); } } } } } // 返回保存后的人员信息实体对象的主键 return save.toString(); } /** * 处理头部信息 * * @param uiViewInfo 头部 UI 视图信息 * @param jsonObject 人员信息的 JSON 对象 * @param fileJSON 文件信息的 JSON 数组 * @return 保存后的对象主键 * @throws BOSException BOS 异常 * @throws SHRWebException SHR 网页异常 * @throws EASBizException EAS 业务异常 * @throws JSONException JSON 处理异常 * @throws ParseException 解析异常 * @throws IOException 输入输出异常 */ public String headProcessing(UIViewInfo uiViewInfo, JSONObject jsonObject , JSONArray fileJSON, String fileName) throws BOSException, SHRWebException, EASBizException, JSONException, ParseException, IOException { // 根据 UI 视图的主键生成动态 UI 视图信息 com.kingdee.shr.base.syssetting.web.dynamic.model.UIViewInfo uiViewInfo1 = generateUIView(context, uiViewInfo.getUipk()); // 获取实体名称 String entityName = uiViewInfo1.getEntityName(); // 获取字段列表 List fields = uiViewInfo1.getFields(); // 根据实体名称获取对应的对象值类 Class objectValueClass = MetaDataUtil.getObjectValueClass(entityName); // 创建对应的实体对象 CoreBaseInfo coreBaseInfo = (CoreBaseInfo) MetaDataUtil.newInstance(objectValueClass, entityName); coreBaseInfo.getBOSType(); // 处理字段信息 JSONArray jsonArray = this.fieldProcessing(fields, coreBaseInfo, jsonObject, fileName); // 创建对应的业务对象 ICoreBase bosObject = (ICoreBase) (BOSObjectFactory.createBOSObject(context, coreBaseInfo.getBOSType())); IObjectPK save=null; // 保存实体对象 if (coreBaseInfo instanceof EmpEnrollBizBillInfo){ System.out.println("=====submit========="); coreBaseInfo.put("billState", HRBillStateEnum.SUBMITED ); coreBaseInfo.put("approveType",ApproveTypeEnum.WORKFLOW); coreBaseInfo.setExtendedProperty("isAddNew", "isAddNew"); save = bosObject.submit(coreBaseInfo); }else { System.out.println("=====save========="); save = bosObject.save(coreBaseInfo); } PersonInfo personInfo = (PersonInfo) coreBaseInfo.get("person"); // 处理文件信息 fileProcessor(save.toString(), personInfo, jsonArray); // 获取文件信息的第一个 JSON 对象 if (fileJSON != null) { JSONObject jsonObject1 = fileJSON.getJSONObject(0); if (!save.toString().equals("")) { // 遍历字段列表 for (int i = 0; i < fields.size(); i++) { // 获取单个字段信息 FieldInfo fieldInfo = fields.get(i); // 获取字段的别名 String alias = fieldInfo.getAlias();//CertificateNu // 获取字段的名称 String name = fieldInfo.getName();//idCardNO if (!name.equals(fileName)) { continue; } // 分割字段别名 String[] split = alias.split("#"); // 获取字段的属性 Map attributes = fieldInfo.getAttributes(); // 获取数据的 UI 主键 String uipk = attributes.get("data-uipk"); // 获取文件信息 JSONObject data = jsonObject1.getJSONObject(split[1]); if (data != null) { // 获取下载链接 JSONArray downloadUrl = data.getJSONArray("downloadUrls"); // 分割下载链接 // 获取文件名 //String text = data.getString("text"); // 分割文件名 //String[] split2 = text.split(","); for (int k = 0; k < downloadUrl.size(); k++) { byte[] dataImg = new byte[0]; // 拼接完整的下载链接 String URL = "http:" + downloadUrl.get(k); System.out.println("===========" + URL + "=========="); // 从网络下载文件数据 dataImg = helper.getBytesByNetURL(URL); // 插入人员附件信息 //insertPersonAttachment(split2[k], uipk, save.toString(), dataImg); } } } } } // 返回保存后的人员信息实体对象的主键 return save.toString(); } /** * 处理文件信息 * * @param id 关联的 ID * @param personInfo 人员信息对象 * @param jsonArray 文件信息的 JSON 数组 * @throws JSONException JSON 处理异常 */ public void fileProcessor(String id, PersonInfo personInfo, JSONArray jsonArray) throws JSONException { // 遍历文件信息的 JSON 数组 for (int i = 0; i < jsonArray.size(); i++) { // 获取单个文件信息 JSONObject jsonObject1 = jsonArray.getJSONObject(i); // 获取数据的 UI 主键 String uipk = jsonObject1.getString("uipk"); // 获取文件的下载链接 String url = jsonObject1.getString("url"); // 获取文件的名称 String name = jsonObject1.getString("name"); if (url == null || url.toString().equals("") || url.toString().equals("[]")) { continue; } if (uipk.equals("PersonPhoto")) { try { if (personInfo != null) { // 保存人员照片信息 savePersonPhoto(personInfo, url); } } catch (IOException e) { // 抛出运行时异常,表示保存人员照片信息失败 throw new RuntimeException(e); } } else { try { // 从网络下载文件数据 byte[] dataImg = null; if (url.indexOf("http:") >= 0 || url.indexOf("https:") >= 0) { dataImg = helper.getBytesByNetURL(url); } else { dataImg = helper.getBytesByNetURL("http:" + url); } // 插入人员附件信息 if (name == null) { name = extractFileNameFromUrl(url); } insertPersonAttachment(name, uipk, id, dataImg); } catch (IOException e) { // 抛出运行时异常,表示下载文件数据失败 throw new RuntimeException(e); } catch (BOSException e) { // 抛出运行时异常,表示插入人员附件信息失败 throw new RuntimeException(e); } catch (EASBizException e) { // 抛出运行时异常,表示插入人员附件信息失败 throw new RuntimeException(e); } } } } public static void main(String[] args) { 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"); System.out.println(name); } // 从URL中提取文件名 private static String extractFileNameFromUrl(String url) { if (url == null || url.isEmpty()) { return null; } int lastSlash = url.lastIndexOf('/'); if (lastSlash != -1 && lastSlash < url.length() - 1) { String fileName = url.substring(lastSlash + 1); // 去除查询参数 int queryIndex = fileName.indexOf('?'); if (queryIndex != -1) { fileName = fileName.substring(0, queryIndex); } return fileName; } return null; } /** * 保存人员照片信息 * * @param personInfo 人员信息对象 * @param iDPhotoDownloadUrl 照片下载链接 * @throws IOException 输入输出异常 */ private void savePersonPhoto(PersonInfo personInfo, String iDPhotoDownloadUrl) throws IOException { if (!StringUtils.isEmpty(iDPhotoDownloadUrl)) { // 打印照片下载链接 System.out.println("iDPhotoDownloadUrl" + iDPhotoDownloadUrl); // 从网络下载照片数据 byte[] dataImg = helper.getBytesByNetURL("http:" + iDPhotoDownloadUrl); // 创建人员照片信息对象 PersonPhotoInfo personPhotoInfo = new PersonPhotoInfo(); // 设置照片数据 personPhotoInfo.setImageData(dataImg); // 设置关联的人员信息对象 personPhotoInfo.setPerson(personInfo); try { // 保存人员照片信息 PersonPhotoFactory.getLocalInstance(context) .save(personPhotoInfo); } catch (EASBizException e) { e.printStackTrace(); } catch (BOSException e) { e.printStackTrace(); } } } /** * 插入人员附件信息 * * @param filename 文件名 * @param uipk 数据的 UI 主键 * @param boId 业务对象的 ID * @param data 文件数据 * @return 附件的 ID * @throws BOSException BOS 异常 * @throws EASBizException EAS 业务异常 */ public String insertPersonAttachment(String filename, String uipk, String boId, byte[] data) throws BOSException, EASBizException { if (data.length > 20971520) { // 如果文件大小超过 20MB,抛出 BOS 异常 throw new BOSException("文件上传失败,文件大小超过20MB!"); } else if (!org.apache.commons.lang3.StringUtils.isBlank(filename) && !org.apache.commons.lang3.StringUtils.isBlank(boId) && data.length > 0) { // 创建 SHR 附件扩展信息对象 SHRAttachmentExtInfo attchExt = new SHRAttachmentExtInfo(); // 创建附件信息对象 AttachmentInfo ai = new AttachmentInfo(); // 获取管理员用户信息 UserInfo userInfo = UserFactory.getLocalInstance(context).getUserInfo("where number = 'administrator'"); // 获取用户 ID String userId = userInfo.getId().toString(); // 设置附件名称 ai.setName(filename.substring(0, filename.lastIndexOf(46))); // 设置附件简单名称 ai.setSimpleName(filename.substring(filename.lastIndexOf(".") + 1)); // 设置附件描述 ai.setDescription(""); // 设置附件文件数据 ai.setFile(data); // 设置附件是否共享 ai.setIsShared(false); // 设置附件共享描述 ai.setSharedDesc("否"); // 设置附件 ID ai.setAttachID("" + System.currentTimeMillis()); // 设置附件类型 ai.setType(this.getFileType(filename)); // 将附件信息对象设置到 SHR 附件扩展信息对象中 attchExt.setAttachment(ai); // 设置 SHR 附件扩展信息对象的名称 attchExt.setName(filename); // 设置 SHR 附件扩展信息对象的属性名称 attchExt.setPropertyName("null0"); // 设置 SHR 附件扩展信息对象的类型 attchExt.setType(AttachmentTypeEnum.FORM); // 设置 SHR 附件扩展信息对象的状态 attchExt.setState(AttachmentState.UNSAVE); // 设置 SHR 附件扩展信息对象的绑定信息 attchExt.setBunding(userId + "#" + uipk); // 设置 SHR 附件扩展信息对象关联的业务对象 ID attchExt.setBoID(boId); // 设置 SHR 附件扩展信息对象的状态 attchExt.setState(AttachmentState.SAVE); // 保存附件信息对象 AttachmentFactory.getLocalInstance(context).save(ai); // 设置 SHR 附件扩展信息对象的状态 attchExt.setState(AttachmentState.SAVE); // 创建业务对象与附件关联信息对象 BoAttchAssoInfo boAttchAssoInfo = new BoAttchAssoInfo(); // 设置业务对象与附件关联信息对象关联的业务对象 ID boAttchAssoInfo.setBoID(boId); // 设置业务对象与附件关联信息对象关联的业务对象类型 boAttchAssoInfo.setAssoBusObjType(String.valueOf(BOSUuid.getBOSObjectType(boId, true))); // 设置业务对象与附件关联信息对象的关联类型 boAttchAssoInfo.setAssoType("Added Accessories"); // 将附件信息对象设置到业务对象与附件关联信息对象中 boAttchAssoInfo.setAttachment(ai); // 保存业务对象与附件关联信息对象 BoAttchAssoFactory.getLocalInstance(context).save(boAttchAssoInfo); // 保存 SHR 附件扩展信息对象 SHRAttachmentExtFactory.getLocalInstance(context).save(attchExt); // 返回附件的 ID return ai.getId().toString(); } else { // 如果文件名、业务对象 ID 或文件数据为空,抛出 BOS 异常 throw new BOSException("文件上传失败,请确认信息无误!"); } } /** * 根据文件名获取文件类型 * * @param fullname 文件名 * @return 文件类型 */ private String getFileType(String fullname) { // 获取文件扩展名 String extname = fullname.substring(fullname.lastIndexOf(".") + 1, fullname.length()); if (!"doc".equalsIgnoreCase(extname) && !"docx".equalsIgnoreCase(extname)) { if (!"xls".equalsIgnoreCase(extname) && !"xlsx".equalsIgnoreCase(extname) && !"xlsm".equalsIgnoreCase(extname) && !"xlsb".equalsIgnoreCase(extname)) { if (!"ppt".equalsIgnoreCase(extname) && !"pptx".equalsIgnoreCase(extname) && !"pptm".equalsIgnoreCase(extname)) { return "txt".equalsIgnoreCase(extname) ? "TEXT 文本文件" : "未知文件类型(." + extname + ")"; } else { return "Microsoft PowerPoint 幻灯片"; } } else { return "Microsoft Excel 表格"; } } else { return "Microsoft Word 文档"; } } /** * 根据 UI 视图的主键生成动态 UI 视图信息 * * @param ctx 上下文对象 * @param uipk UI 视图的主键 * @return 动态 UI 视图信息 * @throws SHRWebException SHR 网页异常 */ private com.kingdee.shr.base.syssetting.web.dynamic.model.UIViewInfo generateUIView(Context ctx, String uipk) throws SHRWebException { // 从数据库中获取 UI 视图信息 com.kingdee.shr.base.syssetting.UIViewInfo dbUIViewInfo = getUIViewFromDB(ctx, uipk); if (dbUIViewInfo == null) { if (uipk.contains(" ")) { // 如果 UI 视图主键包含空格,抛出 SHR 网页业务异常 throw new ShrWebBizException(MessageFormat.format(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "view_contain_blank"), uipk)); } else { // 如果 UI 视图信息为空,抛出 SHR 网页业务异常 throw new ShrWebBizException(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "view_not_found")); } } else { // 处理树导航元素 dealTreeNavigationElement(dbUIViewInfo); // 获取 UI 视图转换器 IUIViewConverter converter = UIViewConverterFactory.getUIViewConverter(dbUIViewInfo, ctx); // 执行转换操作 return converter.exec(); } } /** * 处理树导航元素 * * @param dbUIViewInfo UI 视图信息 */ private void dealTreeNavigationElement(com.kingdee.shr.base.syssetting.UIViewInfo dbUIViewInfo) { // 处理配置信息 String content = dealConfig(dbUIViewInfo.getContent()); // 处理扩展配置信息 String extend = dealConfig(dbUIViewInfo.getExtend()); if (!StringUtils.isEmpty(content)) { // 如果处理后的配置信息不为空,设置到 UI 视图信息中 dbUIViewInfo.setContent(content); } if (!StringUtils.isEmpty(extend)) { // 如果处理后的扩展配置信息不为空,设置到 UI 视图信息中 dbUIViewInfo.setExtend(extend); } } /** * 从数据库中获取 UI 视图信息 * * @param ctx 上下文对象 * @param uipk UI 视图的主键 * @return UI 视图信息 * @throws SHRWebException SHR 网页异常 */ public com.kingdee.shr.base.syssetting.UIViewInfo getUIViewFromDB(Context ctx, String uipk) throws SHRWebException { try { if (LocaleUtils.locale_zh_CN.toString().equals(LocaleUtils.getLocaleString(LocaleUtils.getFirstOriginLocale(ctx.getLocale())))) { // 如果是中文环境,根据 UI 视图主键和选择器从数据库中获取 UI 视图信息 return UIViewFactory.getLocalInstance(ctx).getValueByUipk(uipk, SysSettingUIViewUtil.getUIViewSelector()); } else { // 如果不是中文环境,使用多语言服务进行转换 Map params = new HashMap(); params.put("uipks", uipk); params.put("isConvert", true); Object obj = MLServiceFactory.getLocalInstance(ctx).convert(ResourceType.UIView, params); return null == obj ? null : (com.kingdee.shr.base.syssetting.UIViewInfo) obj; } } catch (BOSException var4) { // 抛出 SHR 网页业务异常 throw new ShrWebBizException(var4.getMessage(), var4); } catch (EASBizException var5) { // 抛出 SHR 网页业务异常 throw new ShrWebBizException(var5.getMessage(), var5); } } /** * 处理配置信息 * * @param text 配置信息文本 * @return 处理后的配置信息 */ private String dealConfig(String text) { if (StringUtils.isEmpty(text)) { return null; } else { try { // 获取 XML 输出器 XMLOutputter output = XMLUtil.getXMLOutputter(); // 解析 XML 文本 Document doc = XMLUtil.parseXML(text); // 获取根元素 Element rootElement = doc.getRootElement(); // 创建树导航 XPath 对象 XPath xPathTreeNavigation = XPath.newInstance("//treeNavigation"); // 创建过滤器项 XPath 对象 XPath xPathFilterItem = XPath.newInstance("//filterItem[@isAdminOrg='true']"); // 获取树导航元素列表 List treeNavigations = xPathTreeNavigation.selectNodes(rootElement); // 获取过滤器项元素列表 List filterItems = xPathFilterItem.selectNodes(rootElement); if (null != treeNavigations && treeNavigations.size() > 0) { if (null != filterItems && filterItems.size() > 0) { // 遍历树导航元素列表 Iterator i$ = treeNavigations.iterator(); while (i$.hasNext()) { // 获取单个树导航元素 Element e = (Element) i$.next(); // 获取父元素 Element parent = e.getParent(); // 从父元素中移除树导航元素 parent.removeContent(e); } // 输出处理后的 XML 文本 String r = output.outputString(doc); return r; } else { return null; } } else { return null; } } catch (Exception var11) { return null; } } } }