diff --git a/src/com/engine/organization/entity/extend/bo/ExtendInfoBO.java b/src/com/engine/organization/entity/extend/bo/ExtendInfoBO.java index e9650393..6fb569c6 100644 --- a/src/com/engine/organization/entity/extend/bo/ExtendInfoBO.java +++ b/src/com/engine/organization/entity/extend/bo/ExtendInfoBO.java @@ -33,7 +33,6 @@ import weaver.systeminfo.SystemEnv; import java.util.*; /** - * @description: * @author:dxfeng * @createTime: 2022/05/19 * @version: 1.0 @@ -52,15 +51,14 @@ public class ExtendInfoBO { Map col; int width = 100 / infoPOList.size(); - for (int i = 0; infoPOList != null && i < infoPOList.size(); i++) { - ExtendInfoPO extendInfoPO = infoPOList.get(i); + for (ExtendInfoPO extendInfoPO : infoPOList) { String tmpkey = extendInfoPO.getFieldName(); col = new HashMap<>(); col.put("title", extendInfoPO.getFieldNameDesc()); col.put("key", tmpkey); col.put("dataIndex", tmpkey); - col.put("com", getFieldDetialInfo(user, extendInfoPO, viewAttr, showLabel, width)); + col.put("com", getFieldDetailInfo(user, extendInfoPO, viewAttr, showLabel, width)); col.put("width", width + "%"); @@ -73,12 +71,11 @@ public class ExtendInfoBO { /** * 新增自定义字段时,对象转换 * - * @param user - * @param infoFieldParam - * @param extendGroupPO - * @param extendGroupId - * @param showOrder - * @return + * @param user 当前用户 + * @param infoFieldParam 拓展字段 + * @param extendGroupPO 分组实体 + * @param extendGroupId 分组ID + * @param showOrder 展示顺序 */ public static ExtendInfoPO convertFieldParam2ExtendInfo(User user, ExtendInfoFieldParam infoFieldParam, ExtendGroupPO extendGroupPO, Long extendGroupId, Integer showOrder) { if (null == infoFieldParam) { @@ -146,9 +143,8 @@ public class ExtendInfoBO { /** * 当前自定义字段是否已使用 * - * @param tableName - * @param fieldName - * @return + * @param tableName 表名 + * @param fieldName 字段名 */ public static boolean fieldIsUsed(String tableName, String fieldName) { if (StringUtils.isAnyEmpty(tableName, fieldName)) { @@ -162,13 +158,12 @@ public class ExtendInfoBO { /** * 明细表字段 * - * @param user - * @param extendInfoPO - * @param viewAttr - * @return + * @param user 当前用户 + * @param extendInfoPO 名字表字段实体 + * @param viewAttr 操作类型 */ - private static List getFieldDetialInfo(User user, ExtendInfoPO extendInfoPO, int viewAttr, boolean showLabel, int width) { - List ls = new ArrayList(); + private static List getFieldDetailInfo(User user, ExtendInfoPO extendInfoPO, int viewAttr, boolean showLabel, int width) { + List ls = new ArrayList<>(); FieldItem fieldItem = createField(user, extendInfoPO, viewAttr, showLabel, width); ls.add(fieldItem); return ls; @@ -177,12 +172,11 @@ public class ExtendInfoBO { /** * 创建列表字段信息 * - * @param user - * @param extendInfoPO - * @param viewAttr - * @param showLabel - * @param width - * @return + * @param user 当前用户 + * @param extendInfoPO 字段信息 + * @param viewAttr 操作类型 + * @param showLabel 展示名字 + * @param width 宽度 */ private static FieldItem createField(User user, ExtendInfoPO extendInfoPO, int viewAttr, boolean showLabel, int width) { FieldItem fieldItem = new FieldItem(); @@ -192,7 +186,7 @@ public class ExtendInfoBO { fieldItem.setLabel(""); } - fieldItem.setType(getFieldhtmltype(extendInfoPO.getControlType() + "")); + fieldItem.setType(getFieldHtmlType(extendInfoPO.getControlType() + "")); fieldItem.setKey(extendInfoPO.getFieldName()); // 查看操作 全部设置为只读 if (1 == viewAttr) { @@ -221,25 +215,32 @@ public class ExtendInfoBO { /** * 获取对应的控件类型 * - * @param fieldhtmltype - * @return + * @param fieldHtmlType 控件类型 */ - private static FieldType getFieldhtmltype(String fieldhtmltype) { + private static FieldType getFieldHtmlType(String fieldHtmlType) { FieldType fieldtype = null; - if (fieldhtmltype.equals("1")) { - fieldtype = FieldType.INPUT; - } else if (fieldhtmltype.equals("2")) { - fieldtype = FieldType.TEXTAREA; - } else if (fieldhtmltype.equals("3")) { - fieldtype = FieldType.BROWSER; - } else if (fieldhtmltype.equals("4")) { - fieldtype = FieldType.CHECKBOX; - } else if (fieldhtmltype.equals("5")) { - fieldtype = FieldType.SELECT; - } else if (fieldhtmltype.equals("6")) { - fieldtype = FieldType.FILEUPLOAD; - } else if (fieldhtmltype.equals("7")) { - fieldtype = FieldType.TEXT; + switch (fieldHtmlType) { + case "1": + fieldtype = FieldType.INPUT; + break; + case "2": + fieldtype = FieldType.TEXTAREA; + break; + case "3": + fieldtype = FieldType.BROWSER; + break; + case "4": + fieldtype = FieldType.CHECKBOX; + break; + case "5": + fieldtype = FieldType.SELECT; + break; + case "6": + fieldtype = FieldType.FILEUPLOAD; + break; + case "7": + fieldtype = FieldType.TEXT; + break; } return fieldtype; } @@ -256,208 +257,228 @@ public class ExtendInfoBO { HrmFieldManager hrmFieldManager = new HrmFieldManager(); String fieldid = Util.null2String(extendInfoPO.getId());//字段id String fieldname = Util.null2String(extendInfoPO.getFieldName());//字段名 - String fieldlabel = Util.null2String(extendInfoPO.getFieldNameDesc());//字段显示名 + // String fieldlabel = Util.null2String(extendInfoPO.getFieldNameDesc());//字段显示名 + String fieldlabel = "502327";//字段显示名 String fieldhtmltype = Util.null2String(extendInfoPO.getControlType());//字段类型 String detailtype = Util.null2String(extendInfoPO.getBrowserType());//字段二级类型(浏览框--单人力) String customValue = Util.null2String(extendInfoPO.getCustomValue()); boolean isQuickSearch = true; - boolean isScope = false; - if (fieldhtmltype.equals("1")) {//单行文本框 - if (isScope) {//范围 - if (Util.null2String(fieldvalue).length() == 0) { - fieldvalue = new HashMap(); - } - searchConditionItem = conditionFactory.createCondition(ConditionType.SCOPE, fieldlabel, new String[]{fieldname, fieldname + "to"}); - } else if (detailtype.equals("2")) {//数字 - searchConditionItem = conditionFactory.createCondition(ConditionType.INPUTNUMBER, fieldlabel, fieldname, isQuickSearch); - } else { - searchConditionItem = conditionFactory.createCondition(ConditionType.INPUT, "25034", fieldname, isQuickSearch); - } - } else if (fieldhtmltype.equals("2")) {//多行文本框 - searchConditionItem = conditionFactory.createCondition(ConditionType.TEXTAREA, fieldlabel, fieldname); - } else if (fieldhtmltype.equals("3")) {//浏览按钮 - customValue = SelectOptionParam.getCustomBrowserId(customValue); - if (detailtype.equals("2")) { - if (!extendInfoPO.getTableName().toLowerCase().contains("_dt")) { - searchConditionItem = conditionFactory.createCondition(ConditionType.DATEPICKER, fieldlabel, fieldname); - } else { - searchConditionItem = conditionFactory.createCondition(ConditionType.DATE, fieldlabel, fieldname, detailtype); - searchConditionItem.setDomkey(new String[]{fieldname + DATE_SELECT, fieldname + DATE_FROM, fieldname + DATE_TO}); - searchConditionItem.setOptions(ServiceUtil.getDateSelectFromTo(user.getLanguage())); - } - } else if (detailtype.equals("19")) { - searchConditionItem = conditionFactory.createCondition(ConditionType.TIMEPICKER, fieldlabel, fieldname, detailtype); - } else if (detailtype.equals("402")) { // 年 - searchConditionItem = conditionFactory.createCondition(ConditionType.DATEPICKER, fieldlabel, fieldname, detailtype); - searchConditionItem.setFormat("yyyy"); - searchConditionItem.setMode("year"); - searchConditionItem.setPlaceholder(SystemEnv.getHtmlLabelNames("526306", user.getLanguage())); - searchConditionItem.setShowTime(false); - } else if (detailtype.equals("403")) { - searchConditionItem = conditionFactory.createCondition(ConditionType.DATEPICKER, fieldlabel, fieldname, detailtype); - searchConditionItem.setFormat("yyyy-MM"); - searchConditionItem.setMode("month"); - searchConditionItem.setPlaceholder(SystemEnv.getHtmlLabelNames("126137", user.getLanguage())); - searchConditionItem.setShowTime(false); - } else if (detailtype.equals("RANGEPICKER")) {//日期区间 - String[] domkey = new String[]{DATE_FROM + fieldname, DATE_TO + fieldname}; - searchConditionItem = conditionFactory.createCondition(ConditionType.RANGEPICKER, fieldlabel, domkey); - searchConditionItem.setValue(fieldvalue); - } else if (detailtype.equals("TIMERANGEPICKER")) {//时间区间 - String[] domkey = new String[]{fieldname + DATE_Time_FROM, fieldname + DATE_Time_TO}; - searchConditionItem = conditionFactory.createCondition(ConditionType.TIMERANGEPICKER, fieldlabel, domkey); - searchConditionItem.setValue(fieldvalue); - } else { - if (detailtype.equals("161") || detailtype.equals("162") || detailtype.equals("256") || detailtype.equals("257")) { - BrowserBean browserbean = new BrowserBean(detailtype + ""); - BrowserInitUtil browserInitUtil = new BrowserInitUtil(); - String fielddbtype = customValue; - if (!customValue.startsWith("browser.")) { - fielddbtype = "browser." + customValue; - } - if (detailtype.equals("161") || detailtype.equals("162")) { - browserInitUtil.initCustomizeBrow(browserbean, fielddbtype, Util.getIntValue(detailtype), user.getUID()); - } else { - browserbean.getDataParams().put("cube_treeid", customValue); - browserbean.getDataParams().put("currenttime", System.currentTimeMillis()); - browserInitUtil.initBrowser(browserbean, user.getLanguage()); - } - searchConditionItem = new SearchConditionItem(ConditionType.BROWSER, fieldlabel, new String[]{fieldname}, browserbean); + switch (fieldhtmltype) { + case "1": //单行文本框 + if (detailtype.equals("2")) {//数字 + searchConditionItem = conditionFactory.createCondition(ConditionType.INPUTNUMBER, fieldlabel, fieldname, isQuickSearch); } else { - searchConditionItem = conditionFactory.createCondition(ConditionType.BROWSER, fieldlabel, fieldname, detailtype); + searchConditionItem = conditionFactory.createCondition(ConditionType.INPUT, "25034", fieldname, isQuickSearch); } - //searchConditionItem.getBrowserConditionParam().setHideVirtualOrg(hrmFieldBean.getHideVirtualOrg()); - List> replaceDatas = new ArrayList>(); - String tmpFieldValue = Util.null2String(fieldvalue); - if (detailtype.equals("mkqshift")) { - ShiftManagementToolKit shiftManagementToolKit = new ShiftManagementToolKit(); - String[] fieldvalues = Util.splitString(tmpFieldValue, ","); - for (int i = 0; fieldvalues != null && i < fieldvalues.length; i++) { - String fieldshowname = Util.null2String(shiftManagementToolKit.getShiftOnOffWorkSections(fieldvalues[i], user.getLanguage())); - if (fieldshowname.length() == 0) continue; - Map replaceData = new HashMap(); - replaceData.put("id", fieldvalues[i]); - replaceData.put("name", fieldshowname); - replaceDatas.add(replaceData); - } - } else if (detailtype.equals("sensitivewordstype")) { - SensitiveWordTypeComInfo sensitiveWordTypeComInfo = new SensitiveWordTypeComInfo(); - String[] fieldvalues = Util.splitString(tmpFieldValue, ","); - for (int i = 0; fieldvalues != null && i < fieldvalues.length; i++) { - String fieldshowname = Util.null2String(sensitiveWordTypeComInfo.getName(fieldvalues[i])); - if (fieldshowname.length() == 0) continue; - Map replaceData = new HashMap(); - replaceData.put("id", fieldvalues[i]); - replaceData.put("name", fieldshowname); - replaceDatas.add(replaceData); - } - } else if (detailtype.equals("doccategory")) { - List fieldvalues = new BrowserValueInfoService().getBrowserValueInfo(detailtype, Util.null2String(fieldvalue)); - for (int i = 0; fieldvalues != null && i < fieldvalues.size(); i++) { - BrowserValueInfo valueInfo = fieldvalues.get(i); - String fieldshowname = valueInfo.getName(); - if (fieldshowname.length() == 0) { - continue; + break; + case "2": //多行文本框 + searchConditionItem = conditionFactory.createCondition(ConditionType.TEXTAREA, fieldlabel, fieldname); + break; + case "3": //浏览按钮 + customValue = SelectOptionParam.getCustomBrowserId(customValue); + switch (detailtype) { + case "2": + if (!extendInfoPO.getTableName().toLowerCase().contains("_dt")) { + searchConditionItem = conditionFactory.createCondition(ConditionType.DATEPICKER, fieldlabel, fieldname); + } else { + searchConditionItem = conditionFactory.createCondition(ConditionType.DATE, fieldlabel, fieldname, detailtype); + searchConditionItem.setDomkey(new String[]{fieldname + DATE_SELECT, fieldname + DATE_FROM, fieldname + DATE_TO}); + searchConditionItem.setOptions(ServiceUtil.getDateSelectFromTo(user.getLanguage())); } - Map replaceData = new HashMap(); - replaceData.put("id", valueInfo.getId()); - replaceData.put("name", fieldshowname); - replaceDatas.add(replaceData); + break; + case "19": + searchConditionItem = conditionFactory.createCondition(ConditionType.TIMEPICKER, fieldlabel, fieldname, detailtype); + break; + case "402": // 年 + searchConditionItem = conditionFactory.createCondition(ConditionType.DATEPICKER, fieldlabel, fieldname, detailtype); + searchConditionItem.setFormat("yyyy"); + searchConditionItem.setMode("year"); + searchConditionItem.setPlaceholder(SystemEnv.getHtmlLabelNames("526306", user.getLanguage())); + searchConditionItem.setShowTime(false); + break; + case "403": + searchConditionItem = conditionFactory.createCondition(ConditionType.DATEPICKER, fieldlabel, fieldname, detailtype); + searchConditionItem.setFormat("yyyy-MM"); + searchConditionItem.setMode("month"); + searchConditionItem.setPlaceholder(SystemEnv.getHtmlLabelNames("126137", user.getLanguage())); + searchConditionItem.setShowTime(false); + break; + case "RANGEPICKER": {//日期区间 + String[] domkey = new String[]{DATE_FROM + fieldname, DATE_TO + fieldname}; + searchConditionItem = conditionFactory.createCondition(ConditionType.RANGEPICKER, fieldlabel, domkey); + searchConditionItem.setValue(fieldvalue); + break; } - } else { - if (tmpFieldValue.length() > 0) { - String fieldshowname = hrmFieldManager.getFieldvalue(user, customValue, Util.getIntValue(fieldid), Util.getIntValue(fieldhtmltype), Util.getIntValue(detailtype), tmpFieldValue, 0); - String[] fieldvalues = Util.splitString(tmpFieldValue, ","); - String[] fieldshownames = Util.splitString(fieldshowname, ","); - if (detailtype.equals("257")) { - if (fieldshowname.endsWith(" ")) { - fieldshowname = fieldshowname.substring(0, fieldshowname.length() - 5); + case "TIMERANGEPICKER": {//时间区间 + String[] domkey = new String[]{fieldname + DATE_Time_FROM, fieldname + DATE_Time_TO}; + searchConditionItem = conditionFactory.createCondition(ConditionType.TIMERANGEPICKER, fieldlabel, domkey); + searchConditionItem.setValue(fieldvalue); + break; + } + default: + if (detailtype.equals("161") || detailtype.equals("162") || detailtype.equals("256") || detailtype.equals("257")) { + BrowserBean browserbean = new BrowserBean(detailtype + ""); + BrowserInitUtil browserInitUtil = new BrowserInitUtil(); + String fielddbtype = customValue; + if (!customValue.startsWith("browser.")) { + fielddbtype = "browser." + customValue; + } + if (detailtype.equals("161") || detailtype.equals("162")) { + browserInitUtil.initCustomizeBrow(browserbean, fielddbtype, Util.getIntValue(detailtype), user.getUID()); + } else { + browserbean.getDataParams().put("cube_treeid", customValue); + browserbean.getDataParams().put("currenttime", System.currentTimeMillis()); + browserInitUtil.initBrowser(browserbean, user.getLanguage()); } - fieldshownames = Util.splitString(fieldshowname, " "); + searchConditionItem = new SearchConditionItem(ConditionType.BROWSER, fieldlabel, new String[]{fieldname}, browserbean); + } else { + searchConditionItem = conditionFactory.createCondition(ConditionType.BROWSER, fieldlabel, fieldname, detailtype); } - for (int i = 0; fieldvalues != null && i < fieldvalues.length; i++) { - if (fieldvalues.length != fieldshownames.length) { + List> replaceDatas = new ArrayList<>(); + String tmpFieldValue = Util.null2String(fieldvalue); + switch (detailtype) { + case "mkqshift": { + ShiftManagementToolKit shiftManagementToolKit = new ShiftManagementToolKit(); + String[] fieldvalues = Util.splitString(tmpFieldValue, ","); + for (int i = 0; fieldvalues != null && i < fieldvalues.length; i++) { + String fieldshowname = Util.null2String(shiftManagementToolKit.getShiftOnOffWorkSections(fieldvalues[i], user.getLanguage())); + if (fieldshowname.length() == 0) continue; + Map replaceData = new HashMap<>(); + replaceData.put("id", fieldvalues[i]); + replaceData.put("name", fieldshowname); + replaceDatas.add(replaceData); + } + break; + } + case "sensitivewordstype": { + SensitiveWordTypeComInfo sensitiveWordTypeComInfo = new SensitiveWordTypeComInfo(); + String[] fieldvalues = Util.splitString(tmpFieldValue, ","); + for (int i = 0; fieldvalues != null && i < fieldvalues.length; i++) { + String fieldshowname = Util.null2String(sensitiveWordTypeComInfo.getName(fieldvalues[i])); + if (fieldshowname.length() == 0) continue; + Map replaceData = new HashMap<>(); + replaceData.put("id", fieldvalues[i]); + replaceData.put("name", fieldshowname); + replaceDatas.add(replaceData); + } break; } - if (Util.null2String(fieldshownames[i]).length() == 0) { - continue; + case "doccategory": { + List fieldvalues = new BrowserValueInfoService().getBrowserValueInfo(detailtype, Util.null2String(fieldvalue)); + for (int i = 0; fieldvalues != null && i < fieldvalues.size(); i++) { + BrowserValueInfo valueInfo = fieldvalues.get(i); + String fieldshowname = valueInfo.getName(); + if (fieldshowname.length() == 0) { + continue; + } + Map replaceData = new HashMap<>(); + replaceData.put("id", valueInfo.getId()); + replaceData.put("name", fieldshowname); + replaceDatas.add(replaceData); + } + break; } - Map replaceData = new HashMap(); - replaceData.put("id", fieldvalues[i]); - replaceData.put("name", fieldshownames[i]); - replaceDatas.add(replaceData); + default: + if (tmpFieldValue.length() > 0) { + String fieldshowname = hrmFieldManager.getFieldvalue(user, customValue, Util.getIntValue(fieldid), Util.getIntValue(fieldhtmltype), Util.getIntValue(detailtype), tmpFieldValue, 0); + String[] fieldvalues = Util.splitString(tmpFieldValue, ","); + String[] fieldshownames = Util.splitString(fieldshowname, ","); + if (detailtype.equals("257")) { + if (fieldshowname.endsWith(" ")) { + fieldshowname = fieldshowname.substring(0, fieldshowname.length() - 5); + } + fieldshownames = Util.splitString(fieldshowname, " "); + } + for (int i = 0; fieldvalues != null && i < fieldvalues.length; i++) { + if (fieldvalues.length != fieldshownames.length) { + break; + } + if (Util.null2String(fieldshownames[i]).length() == 0) { + continue; + } + Map replaceData = new HashMap<>(); + replaceData.put("id", fieldvalues[i]); + replaceData.put("name", fieldshownames[i]); + replaceDatas.add(replaceData); + } + } + break; } - } + fieldvalue = replaceDatas; + break; + } + break; + case "4": //Check框 + searchConditionItem = conditionFactory.createCondition(ConditionType.CHECKBOX, fieldlabel, fieldname); + if (detailtype.equals("2")) { + searchConditionItem.setConditionType(ConditionType.SWITCH); } - fieldvalue = replaceDatas; - } - } else if (fieldhtmltype.equals("4")) {//Check框 - searchConditionItem = conditionFactory.createCondition(ConditionType.CHECKBOX, fieldlabel, fieldname); - if (detailtype.equals("2")) { - searchConditionItem.setConditionType(ConditionType.SWITCH); - } - } else if (fieldhtmltype.equals("5")) { //选择框 + break; + case "5": //选择框 - List searchConditionOptions = SelectOptionParam.convertJsonToListOption(customValue); - searchConditionItem = conditionFactory.createCondition(ConditionType.SELECT, fieldlabel, fieldname, searchConditionOptions); - if (detailtype.equals("") || detailtype.equals("0")) { - detailtype = "1"; - } - searchConditionItem.setKey(Util.null2String(fieldvalue)); - searchConditionItem.setValue(fieldvalue + ""); - searchConditionItem.setDetailtype(Util.getIntValue(detailtype, 3)); - } else if (fieldhtmltype.equals("6")) {//附件 - if (fieldname.equals("resourceimageid")) { - searchConditionItem = conditionFactory.createCondition(ConditionType.RESOURCEIMG, fieldlabel, fieldname, isQuickSearch); - } else { - searchConditionItem = conditionFactory.createCondition(ConditionType.UPLOAD, fieldlabel, fieldname, isQuickSearch); - searchConditionItem.setUploadUrl("/api/doc/upload/uploadFile"); - searchConditionItem.setCategory("category"); - searchConditionItem.setMaxFilesNumber(10); - searchConditionItem.setMultiSelection(true); - Map otherParamsMap = new HashMap<>(); - otherParamsMap.put("showClearAll", false); - otherParamsMap.put("showOrder", true); - searchConditionItem.setOtherParams(otherParamsMap); - if (Util.null2String(fieldvalue).length() > 0) { - List datas = new ArrayList(); - Map data = null; - String[] tmpIds = Util.splitString(Util.null2String(fieldvalue), ","); - for (int i = 0; i < tmpIds.length; i++) { - String fileid = tmpIds[i]; - ImageFileManager manager = new ImageFileManager(); - manager.getImageFileInfoById(Util.getIntValue(fileid)); - String filename = manager.getImageFileName(); - String extname = filename.contains(".") ? filename.substring(filename.lastIndexOf(".") + 1) : ""; - data = new HashMap(); - data.put("acclink", "/weaver/weaver.file.FileDownload?fileid=" + fileid); - data.put("fileExtendName", extname); - data.put("fileid", fileid); - //if (Util.null2String(this.isMobile).equals("1")) { - // data.put("filelink", "/spa/document/static4mobile/index.html#/attach/" + fileid); - //} else { - data.put("filelink", "/spa/document/index2file.jsp?imagefileId=" + fileid + "#/main/document/fileView"); - //} - data.put("filename", filename); - data.put("filesize", manager.getImgsize()); - data.put("imgSrc", ""); - data.put("isImg", ""); - data.put("loadlink", "/weaver/weaver.file.FileDownload?fileid=" + fileid + "&download=1"); - data.put("showDelete", "true"); - data.put("showLoad", "true"); - datas.add(data); + List searchConditionOptions = SelectOptionParam.convertJsonToListOption(customValue); + searchConditionItem = conditionFactory.createCondition(ConditionType.SELECT, fieldlabel, fieldname, searchConditionOptions); + if (detailtype.equals("") || detailtype.equals("0")) { + detailtype = "1"; + } + searchConditionItem.setKey(Util.null2String(fieldvalue)); + searchConditionItem.setValue(fieldvalue + ""); + searchConditionItem.setDetailtype(Util.getIntValue(detailtype, 3)); + break; + case "6": //附件 + if (fieldname.equals("resourceimageid")) { + searchConditionItem = conditionFactory.createCondition(ConditionType.RESOURCEIMG, fieldlabel, fieldname, isQuickSearch); + } else { + searchConditionItem = conditionFactory.createCondition(ConditionType.UPLOAD, fieldlabel, fieldname, isQuickSearch); + searchConditionItem.setUploadUrl("/api/doc/upload/uploadFile"); + searchConditionItem.setCategory("category"); + searchConditionItem.setMaxFilesNumber(10); + searchConditionItem.setMultiSelection(true); + Map otherParamsMap = new HashMap<>(); + otherParamsMap.put("showClearAll", false); + otherParamsMap.put("showOrder", true); + searchConditionItem.setOtherParams(otherParamsMap); + if (Util.null2String(fieldvalue).length() > 0) { + List datas = new ArrayList<>(); + Map data; + String[] tmpIds = Util.splitString(Util.null2String(fieldvalue), ","); + for (String fileid : tmpIds) { + ImageFileManager manager = new ImageFileManager(); + manager.getImageFileInfoById(Util.getIntValue(fileid)); + String filename = manager.getImageFileName(); + String extname = filename.contains(".") ? filename.substring(filename.lastIndexOf(".") + 1) : ""; + data = new HashMap<>(); + data.put("acclink", "/weaver/weaver.file.FileDownload?fileid=" + fileid); + data.put("fileExtendName", extname); + data.put("fileid", fileid); + //if (Util.null2String(this.isMobile).equals("1")) { + // data.put("filelink", "/spa/document/static4mobile/index.html#/attach/" + fileid); + //} else { + data.put("filelink", "/spa/document/index2file.jsp?imagefileId=" + fileid + "#/main/document/fileView"); + //} + data.put("filename", filename); + data.put("filesize", manager.getImgsize()); + data.put("imgSrc", ""); + data.put("isImg", ""); + data.put("loadlink", "/weaver/weaver.file.FileDownload?fileid=" + fileid + "&download=1"); + data.put("showDelete", "true"); + data.put("showLoad", "true"); + datas.add(data); + } + searchConditionItem.setDatas(datas); } - searchConditionItem.setDatas(datas); } - } - } else if (fieldhtmltype.equals("7")) {//颜色选择 - searchConditionItem = conditionFactory.createCondition(ConditionType.COLORPICKER, fieldlabel, fieldname, true); - searchConditionItem.setValue(fieldvalue); - } else if (fieldhtmltype.equals("8")) {//DESCRIPTION - searchConditionItem = conditionFactory.createCondition(ConditionType.DESCRIPTION, fieldlabel, fieldname); - searchConditionItem.setValue(fieldvalue); + break; + case "7": //颜色选择 + searchConditionItem = conditionFactory.createCondition(ConditionType.COLORPICKER, fieldlabel, fieldname, true); + searchConditionItem.setValue(fieldvalue); + break; + case "8": //DESCRIPTION + searchConditionItem = conditionFactory.createCondition(ConditionType.DESCRIPTION, fieldlabel, fieldname); + searchConditionItem.setValue(fieldvalue); + break; } if (searchConditionItem != null) { BrowserInitUtil.setConditionItemDefaultValue(searchConditionItem, fieldvalue, 2); diff --git a/src/com/engine/organization/service/HrmResourceImportAdaptService.java b/src/com/engine/organization/service/HrmResourceImportAdaptService.java deleted file mode 100644 index eec22608..00000000 --- a/src/com/engine/organization/service/HrmResourceImportAdaptService.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.engine.organization.service; - -import weaver.file.FileUploadToPath; - -import java.util.List; -import java.util.Map; - -/** - * @author:dxfeng - * @createTime: 2022/06/27 - * @version: 1.0 - */ -public interface HrmResourceImportAdaptService { - /** - * 用于生成需要导入系统的人员与组织架构数据并放入Map中,同时包含参数和数据有效性验证 - * 其格式是: - * - * @return 返回错误提示 - */ - List creatImportMap(FileUploadToPath fu); - - /** - * 获得HrmImportMap - * - * @return - */ - Map getHrmImportMap(); - - /** - * 传递同步的人员语言id - */ - void setUserlanguage(int userlanguage); -} diff --git a/src/com/engine/organization/service/HrmResourceImportProcessService.java b/src/com/engine/organization/service/HrmResourceImportProcessService.java deleted file mode 100644 index b91db640..00000000 --- a/src/com/engine/organization/service/HrmResourceImportProcessService.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.engine.organization.service; - -import com.engine.organization.entity.hrmresource.param.HrmResourceImportParam; - -import javax.servlet.http.HttpServletRequest; -import java.util.Map; - -/** - * @author:dxfeng - * @createTime: 2022/06/27 - * @version: 1.0 - */ -public interface HrmResourceImportProcessService { - /** - * 初始化数据 - * - * @param request - */ - Map init(HttpServletRequest request); - - /** - * 用于处理把所得到的组织和人员结构信息放入系统 - * - * @param map - * @return - */ - void processMap(Map map); -} diff --git a/src/com/engine/organization/service/ImportCommonService.java b/src/com/engine/organization/service/ImportCommonService.java index 7925b451..feaa1c58 100644 --- a/src/com/engine/organization/service/ImportCommonService.java +++ b/src/com/engine/organization/service/ImportCommonService.java @@ -1,5 +1,7 @@ package com.engine.organization.service; +import weaver.hrm.User; + import javax.servlet.http.HttpServletRequest; import java.util.Map; @@ -17,4 +19,15 @@ public interface ImportCommonService { * @return */ Map saveImportResource(Map params, HttpServletRequest request); + + + /** + * 通用导入 + * + * @param params + * @param request + * @param user + * @return + */ + Map saveImport(Map params, HttpServletRequest request, User user); } diff --git a/src/com/engine/organization/service/impl/ImportCommonServiceImpl.java b/src/com/engine/organization/service/impl/ImportCommonServiceImpl.java index 45767118..e463b776 100644 --- a/src/com/engine/organization/service/impl/ImportCommonServiceImpl.java +++ b/src/com/engine/organization/service/impl/ImportCommonServiceImpl.java @@ -2,11 +2,15 @@ package com.engine.organization.service.impl; import com.engine.core.impl.Service; import com.engine.organization.entity.hrmresource.param.HrmResourceImportParam; -import com.engine.organization.service.HrmResourceImportAdaptService; -import com.engine.organization.service.HrmResourceImportProcessService; import com.engine.organization.service.ImportCommonService; +import com.engine.organization.util.saveimport.HrmResourceImportAdaptUtil; +import com.engine.organization.util.saveimport.HrmResourceImportProcessUtil; +import com.engine.organization.util.saveimport.SaveImportProcessUtil; import weaver.file.FileUploadToPath; +import weaver.general.BaseBean; import weaver.general.Util; +import weaver.hrm.User; +import weaver.systeminfo.SystemEnv; import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; @@ -24,41 +28,63 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ @Override public Map saveImportResource(Map params, HttpServletRequest request) { - Map retmap = new HashMap(); + Map returnMap = new HashMap<>(); try { /*综合考虑多数据源后,实现通过配置文件配置适配器和解析类*/ - List lsErrorInfo = new ArrayList(); - - HrmResourceImportAdaptService importAdapt = (HrmResourceImportAdaptService) Class.forName("com.engine.organization.service.impl.HrmResourceImportAdaptServiceImpl").newInstance(); - + List lsErrorInfo = new ArrayList<>(); + HrmResourceImportAdaptUtil importAdaptUtil = new HrmResourceImportAdaptUtil(); FileUploadToPath fu = new FileUploadToPath(request); - int language = this.user.getLanguage(); - importAdapt.setUserlanguage(language); - List errorInfo = importAdapt.creatImportMap(fu); - + importAdaptUtil.setUserlanguage(language); + List errorInfo = importAdaptUtil.creatImportMap(fu); //如果读取数据和验证模板没有发生错误 if (errorInfo.isEmpty()) { - Map hrMap = importAdapt.getHrmImportMap(); - HrmResourceImportProcessService importProcess = (HrmResourceImportProcessService) Class.forName("com.engine.organization.service.impl.HrmResourceImportProcessServiceImpl").newInstance(); - importProcess.init(request); - importProcess.processMap(hrMap); + Map hrMap = importAdaptUtil.getHrmImportMap(); + HrmResourceImportProcessUtil importProcessUtil = new HrmResourceImportProcessUtil(); + importProcessUtil.init(request); + importProcessUtil.processMap(hrMap); } else { - if (errorInfo != null && !errorInfo.isEmpty()) { - Map error; - for (int i = 0; i < errorInfo.size(); i++) { - error = new HashMap<>(); - error.put("message", Util.null2String(errorInfo.get(i))); - lsErrorInfo.add(error); - } + Map error; + for (String s : errorInfo) { + error = new HashMap<>(); + error.put("message", Util.null2String(s)); + lsErrorInfo.add(error); + } + } + returnMap.put("errorInfo", lsErrorInfo); + returnMap.put("status", "1"); + } catch (Exception e) { + returnMap.put("status", "-1"); + returnMap.put("message", e.getMessage()); + } + return returnMap; + } + + @Override + public Map saveImport(Map params, HttpServletRequest request, User user) { + Map returnMap = new HashMap<>(); + request.getSession(true).setAttribute("importBaseCreater", user); + try { + List lsErrorInfo = new ArrayList<>(); + SaveImportProcessUtil importProcessUtil = new SaveImportProcessUtil(); + List errorInfo = importProcessUtil.importXls(request); + if (errorInfo != null && !errorInfo.isEmpty()) { + Map error; + for (String s : errorInfo) { + error = new HashMap<>(); + error.put("message", Util.null2String(s)); + lsErrorInfo.add(error); } } - retmap.put("errorInfo", lsErrorInfo); - retmap.put("status", "1"); + returnMap.put("errorInfo", lsErrorInfo); + returnMap.put("status", "1"); + returnMap.put("message", SystemEnv.getHtmlLabelName(24645, user.getLanguage())); } catch (Exception e) { - retmap.put("status", "-1"); - retmap.put("message", e.getMessage()); + new BaseBean().writeLog("导入基础数据失败:" + e); + returnMap.put("status", "-1"); + returnMap.put("message", e.getMessage()); } - return retmap; + returnMap.put("pid", request.getSession(true).getAttribute("importExcelPid")); + return returnMap; } } diff --git a/src/com/engine/organization/util/saveimport/CompanyImportUtil.java b/src/com/engine/organization/util/saveimport/CompanyImportUtil.java new file mode 100644 index 00000000..fca164f0 --- /dev/null +++ b/src/com/engine/organization/util/saveimport/CompanyImportUtil.java @@ -0,0 +1,522 @@ +package com.engine.organization.util.saveimport; + +import com.engine.hrm.entity.RuleCodeType; +import com.engine.hrm.util.CodeRuleManager; +import com.engine.hrm.util.HrmTriggerUtil; +import com.engine.hrm.util.face.HrmFaceCheckManager; +import com.engine.organization.entity.company.po.CompPO; +import com.engine.organization.entity.department.po.DepartmentPO; +import com.engine.organization.mapper.comp.CompMapper; +import com.engine.organization.mapper.department.DepartmentMapper; +import com.engine.organization.util.db.MapperProxyFactory; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.Util; +import weaver.hrm.common.AjaxManager; +import weaver.hrm.common.DbFunctionUtil; +import weaver.hrm.company.DepartmentComInfo; +import weaver.hrm.company.SubCompanyComInfo; +import weaver.matrix.MatrixUtil; +import weaver.rtx.OrganisationCom; +import weaver.systeminfo.SysMaintenanceLog; +import weaver.systeminfo.SystemEnv; + +import java.util.List; + +/** + * @author:dxfeng + * @createTime: 2022/06/30 + * @version: 1.0 + */ +public class CompanyImportUtil { + private final RecordSet recordSet = new RecordSet(); + private final OrganisationCom rtxService = new OrganisationCom(); //添加到rtx + private int id; + private String subcompanyname = ""; + private String departmentname = ""; + private String subcompanycode = ""; + private Integer subcompanyshoworder; + private String departmentcode = ""; + private Float departmentshoworder; + private int userlanguage = 7; + private int pid; + private String operateType; + private String message = ""; + + private CompMapper getCompMapper() { + return MapperProxyFactory.getProxy(CompMapper.class); + } + + private DepartmentMapper getDepartmentMapper() { + return MapperProxyFactory.getProxy(DepartmentMapper.class); + } + + public void setPid(int pid) { + this.pid = pid; + } + + public void setUserLanguage(String userlanguage) { + this.userlanguage = Util.getIntValue(userlanguage); + } + + /** + * 校验数据有效性 + */ + public String valExcelData() { + String errorInfo = ""; + if (Util.null2String(this.subcompanyname).length() == 0) { + errorInfo = SystemEnv.getHtmlLabelName(125704, userlanguage); + return errorInfo; + } + if (StringUtils.isNotEmpty(operateType) && operateType.equals("add")) { + if (!verifySubCompanyCode(subcompanycode)) return subcompanycode + "编号重复"; + if (!verifyDeptCode(departmentcode)) return departmentcode + "编号重复"; + } + return errorInfo; + } + + /** + * 保存数据 + */ + public String save() { + boolean flag = false; + try { + if (StringUtils.isNotEmpty(operateType)) { + if (operateType.equals("add")) { + int subcompanyid = 0; + int departmentid; + if (Util.null2String(this.subcompanyname).length() > 0) { + //取分部 + subcompanyid = getCompanyId(this.subcompanyname); + } + departmentid = getDeptId(this.departmentname, subcompanyid); + if (Util.null2String(this.departmentname).length() > 0) { + if (departmentid != 0) flag = true; + } else { + if (subcompanyid != 0) flag = true; + } + } else if (operateType.equals("update")) { + int subcompanyid = updateSubCompany(); + if (subcompanyid == -1) return String.valueOf(flag); + int deptid = updateDept(subcompanyid); + if (deptid == -1) return String.valueOf(flag); + flag = true; + } + } + } catch (Exception e) { + new BaseBean().writeLog(e); + } + + return String.valueOf(flag); + } + + /** + * 校验分部编号是否重复 + * + * @param code + * @return + */ + private boolean verifySubCompanyCode(String code) { + if (StringUtils.isEmpty(code)) { + return true; + } + List compPOS = getCompMapper().listByNo(code); + return CollectionUtils.isEmpty(compPOS); + } + + /** + * @param code + * @param name + * @param supsubcomid + * @return + */ + private boolean verifySubCompanyCode(String code, String name, int supsubcomid) { + if (StringUtils.isEmpty(code)) { + return true; + } + // TODO 部门重复编号验证 + RecordSet recordSet = new RecordSet(); + String sql = "select id from HrmSubCompany where subcompanyname = ? and supsubcomid = ?"; + recordSet.executeQuery(sql, name, supsubcomid); + if (recordSet.next()) { + String id = recordSet.getString("id"); + sql = "select id from HrmSubCompany where subcompanycode = ? and id != ?"; + recordSet.executeQuery(sql, code, id); + return recordSet.getCounts() <= 0; + } + return verifySubCompanyCode(code); + } + + /** + * 校验部门编号是否重复 + * + * @param code + * @return + */ + private boolean verifyDeptCode(String code) { + if (StringUtils.isEmpty(code)) { + return true; + } + List departmentPOS = getDepartmentMapper().listByNo(code); + return CollectionUtils.isEmpty(departmentPOS); + } + + private boolean verifyDeptCode(String code, String name, int subcompanyid, int supdepid) { + // TODO 部门编号校验 + if (StringUtils.isEmpty(code)) return true; + RecordSet recordSet = new RecordSet(); + String sql = "select id from HrmDepartment where departmentname = ? and subcompanyid1 = ? and supdepid = ?"; + recordSet.executeQuery(sql, name, subcompanyid, supdepid); + if (recordSet.next()) { + String id = recordSet.getString("id"); + sql = "select id from HrmDepartment where departmentcode = ? and id != ?"; + recordSet.executeQuery(sql, code, id); + return recordSet.getCounts() <= 0; + } + return verifyDeptCode(code); + } + + private int updateDept(int subcompanyid) { + String[] deptNames = departmentname.split(">"); + int currentId = 0; + int parentId = 0; + String departmentcode = ""; + Float departmentshoworder = null; + for (int i = 0; i < deptNames.length; i++) { + if (StringUtils.isEmpty(deptNames[i])) continue; + String sql = "select * from HrmDepartment where subcompanyid1=" + subcompanyid + " and departmentname='" + deptNames[i].trim() + "' and supdepid=" + parentId + " and (canceled !=1 or canceled is null)"; + currentId = getResultSetId(sql); + if (currentId == 0) { + // 部门不存在 + // 不存在 + this.setMessage("," + deptNames[i] + "部门不存在"); + return -1; + } + if (i == deptNames.length - 1) { + // 最后一层级 赋值编码和顺序 + departmentcode = this.departmentcode; + departmentshoworder = this.departmentshoworder; + } + if (StringUtils.isNotEmpty(departmentcode) || departmentshoworder != null) { + recordSet.executeQuery(sql); + recordSet.next(); + if (departmentshoworder == null) + departmentshoworder = Float.valueOf(Util.null2s(recordSet.getString("showorder"), "0")); + if (StringUtils.isEmpty(departmentcode)) + departmentcode = Util.null2String(recordSet.getString("departmentcode"), ""); + if (verifyDeptCode(departmentcode, deptNames[i], subcompanyid, parentId)) { + sql = "update hrmdepartment set departmentcode = ? , showorder = ? where departmentname = ? and subcompanyid1 = ? and supdepid = ? and (canceled !=1 or canceled is null)"; + recordSet.executeUpdate(sql, departmentcode, departmentshoworder, deptNames[i], subcompanyid, parentId); + } else { + setMessage("," + departmentcode + "编号重复"); + return -1; + } + } + parentId = currentId; + } + return currentId; + } + + private int updateSubCompany() { + String[] subcompanynames = subcompanyname.split(">"); + int parentId = 0; + int currentId = 0; + String subcompanycode = ""; + Integer subcompanyshoworder = null; + for (int i = 0; i < subcompanynames.length; i++) { + if (StringUtils.isEmpty(subcompanynames[i])) continue; + String sql = "select * from HrmSubCompany where subcompanyname='" + + subcompanynames[i].trim() + "' and supsubcomid=" + parentId; + currentId = getResultSetId(sql); + if (currentId == 0) { + // 不存在 + this.setMessage("," + subcompanynames[i] + "分部不存在"); + return -1; + } + if (i == subcompanynames.length - 1) { + // 最后一层级 赋值编码和顺序 + subcompanycode = this.subcompanycode; + subcompanyshoworder = this.subcompanyshoworder; + } + // 如果编码和顺序不存在则不更新 + if (StringUtils.isNotEmpty(subcompanycode) || subcompanyshoworder != null) { + recordSet.executeQuery(sql); + recordSet.next(); + if (subcompanyshoworder == null) + subcompanyshoworder = Integer.valueOf(Util.null2s(recordSet.getString("showorder"), "0")); + if (StringUtils.isEmpty(subcompanycode)) + subcompanycode = Util.null2String(recordSet.getString("subcompanycode"), ""); + if (verifySubCompanyCode(subcompanycode, subcompanynames[i], parentId)) { + sql = "update HrmSubCompany set subcompanycode= ? , showorder = ? where subcompanyname = ? and supsubcomid = ?"; + recordSet.executeUpdate(sql, subcompanycode, subcompanyshoworder, subcompanynames[i], parentId); + } else { + setMessage("," + subcompanycode + "编号重复"); + return -1; + } + } + parentId = currentId; + } + return currentId; + } + + /** + * 根据分部名称获取分部Id,不存在就创建 + * + * @param companyName 分部名称 eg:泛微广东>泛微深圳 + */ + public int getCompanyId(String companyName) { + String[] companyNames = companyName.split(">"); + int currentId = 0; + int parentId = 0; + String sql; + String sqlInsert; + String companyCode = ""; + Integer companyShowOrder = null; + for (int i = 0; i < companyNames.length; i++) { + if (companyNames[i] == null && companyNames[i].equals("")) { + continue; + } + sql = "select id from HrmSubCompany where subcompanyname='" + + companyNames[i].trim() + "' and supsubcomid=" + parentId; + + currentId = getResultSetId(sql); + + //added by wcd 2015-02-06 [限制分部数] + if (currentId == 0) { + if (i == companyNames.length - 1) { + // 最后一层级 赋值编码和顺序 + companyCode = this.subcompanycode; + companyShowOrder = this.subcompanyshoworder; + if (companyShowOrder == null) { + companyShowOrder = 0; + } + } + if (AjaxManager.getData("", "getLnScCount;mf").equals("true")) { + // 如果编码为空 自动生成编码 + try { + companyCode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.SUBCOMPANY, companyCode); + } catch (Exception e) { + setMessage("," + e.getMessage()); + new BaseBean().writeLog(e); + return -1; + } + sqlInsert = "insert into HrmSubCompany(subcompanyname,subcompanydesc,companyid,supsubcomid,subcompanycode,showorder," + DbFunctionUtil.getInsertColumnSql() + ") values('" + + companyNames[i] + "','" + companyNames[i] + "',1" + "," + parentId + ",'" + companyCode + "'," + companyShowOrder + "," + DbFunctionUtil.getInsertColumnValueSql(new RecordSet().getDBType(), 1) + ")"; // 创建 + boolean isSuccess = execSql(sqlInsert); + HrmTriggerUtil.generateSubcompanyPinyin(companyNames[i], null); + currentId = getResultSetId(sql); + HrmTriggerUtil.Tri_I_SubComKPICheckFlow(String.valueOf(currentId)); + sql = "insert into leftmenuconfig (userid,infoid,visible,viewindex,resourceid,resourcetype,locked,lockedbyid,usecustomname,customname,customname_e) select distinct userid,infoid,visible,viewindex," + currentId + ",2,locked,lockedbyid,usecustomname,customname,customname_e from leftmenuconfig where resourcetype=1 and resourceid=1"; + execSql(sql); + sql = "insert into mainmenuconfig (userid,infoid,visible,viewindex,resourceid,resourcetype,locked,lockedbyid,usecustomname,customname,customname_e) select distinct userid,infoid,visible,viewindex," + currentId + ",2,locked,lockedbyid,usecustomname,customname,customname_e from mainmenuconfig where resourcetype=1 and resourceid=1"; + execSql(sql); + + if (isSuccess) { + //同步分部数据到矩阵 + MatrixUtil.updateSubcompayData("" + currentId); + HrmFaceCheckManager.sync(currentId + "", HrmFaceCheckManager.getOptInsert(), "hrm_import_subcompany", HrmFaceCheckManager.getOaSubcompany()); + } + + insertSysLog(companyNames[i]); + } else { + currentId = -1; + } + } + parentId = currentId; + if (currentId != -1) + rtxService.addSubCompany(parentId); //同步RTX + } + return currentId; + } + + /** + * 获取部门id,不存在就创建 + * + * @param deptNames 部门名称 + * @param subCompanyId 所属分部id + */ + public int getDeptId(String deptNames, int subCompanyId) { + String[] deptName = deptNames.split(">"); + int currentId = 0; + int parentId = 0; + + String sql; + String sqlInsert; + String departmentcode = ""; + Float departmentshoworder = null; + for (int i = 0; i < deptName.length; i++) { + if (deptName[i] == null || deptName[i].equals("")) { + continue; + } + sql = "select id from HrmDepartment where subcompanyid1=" + subCompanyId + " and departmentname='" + deptName[i].trim() + "' and supdepid=" + parentId + " and (canceled !=1 or canceled is null)"; + currentId = getResultSetId(sql); + + if (currentId == 0) { + if (i == deptName.length - 1) { + departmentcode = this.departmentcode; + departmentshoworder = this.departmentshoworder; + if (departmentshoworder == null) departmentshoworder = 0.00F; + } + // 如果编码为空 自动生成编码 + try { + departmentcode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.DEPARTMENT, String.valueOf(subCompanyId), departmentcode); + } catch (Exception e) { + setMessage("," + e.getMessage()); + new BaseBean().writeLog(e); + return -1; + } + sqlInsert = "insert into HrmDepartment (departmentname,Departmentmark,subcompanyid1,supdepid,departmentcode,showorder," + DbFunctionUtil.getInsertColumnSql() + ") values('" + + deptName[i] + "','" + deptName[i] + "'," + subCompanyId + "," + parentId + ",'" + departmentcode + "'," + departmentshoworder + "," + DbFunctionUtil.getInsertColumnValueSql(new RecordSet().getDBType(), 1) + ")"; // 创建 + boolean isSuccess = execSql(sqlInsert); + HrmTriggerUtil.generateDepartmentPinyin(deptName[i], null); + currentId = getResultSetId(sql); + HrmTriggerUtil.Tri_I_DeptKPICheckFlow(String.valueOf(currentId)); + if (isSuccess) { + //同步部门数据到矩阵 + MatrixUtil.updateDepartmentData("" + currentId); + HrmFaceCheckManager.sync(currentId + "", HrmFaceCheckManager.getOptInsert(), "hrm_import_deptment", HrmFaceCheckManager.getOaDepartment()); + } + + insertSysLog(deptName[i]); + rtxService.addDepartment(currentId); //同步RTX + } + parentId = currentId; + } + return currentId; + } + + /** + * 获得查询结果Id + * + * @param sql 查询语句 + */ + public int getResultSetId(String sql) { + int currentId = 0; + recordSet.execute(sql); + try { + while (recordSet.next()) { + currentId = recordSet.getInt("id"); + } + } catch (Exception e) { + e.printStackTrace(); + } + return currentId; + } + + /** + * 执行插入操作 + * + * @param sql + */ + public boolean execSql(String sql) { + return recordSet.execute(sql); + } + + public void removeCache() { + try { + + weaver.matrix.MatrixUtil.sysSubcompayData(); + weaver.matrix.MatrixUtil.sysDepartmentData(); + + SubCompanyComInfo SubCompanyComInfo = new SubCompanyComInfo(); + SubCompanyComInfo.removeCompanyCache(); + + DepartmentComInfo DepartmentComInfo = new DepartmentComInfo(); + DepartmentComInfo.removeCompanyCache(); + //初始化应用分权 + new weaver.hrm.appdetach.AppDetachComInfo().initSubDepAppData(); + } catch (Exception e) { + new BaseBean().writeLog(e); + } + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getSubcompanyname() { + return subcompanyname; + } + + public void setSubcompanyname(String subcompanyname) { + this.subcompanyname = subcompanyname; + } + + public String getDepartmentname() { + return departmentname; + } + + public void setDepartmentname(String departmentname) { + this.departmentname = departmentname; + } + + public String getSubcompanycode() { + return subcompanycode; + } + + public void setSubcompanycode(String subcompanycode) { + this.subcompanycode = subcompanycode; + } + + public Integer getSubcompanyshoworder() { + return subcompanyshoworder; + } + + public void setSubcompanyshoworder(Integer subcompanyshoworder) { + this.subcompanyshoworder = subcompanyshoworder; + } + + public String getDepartmentcode() { + return departmentcode; + } + + public void setDepartmentcode(String departmentcode) { + this.departmentcode = departmentcode; + } + + public Float getDepartmentshoworder() { + return departmentshoworder; + } + + public void setDepartmentshoworder(Float departmentshoworder) { + this.departmentshoworder = departmentshoworder; + } + + public String getOperateType() { + return operateType; + } + + public void setOperateType(String operateType) { + this.operateType = operateType; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + private void insertSysLog(String name) { + SysMaintenanceLog syslog = new SysMaintenanceLog(); + syslog.resetParameter(); + syslog.setRelatedId(pid); + syslog.setOperateType("-1"); + syslog.setOperateItem("12"); + syslog.setOperateUserid(0); + syslog.setRelatedName(name); + try { + syslog.setSysLogInfo(); + } catch (Exception e) { + new BaseBean().writeLog(e); + } + } + +} diff --git a/src/com/engine/organization/service/impl/HrmResourceImportAdaptServiceImpl.java b/src/com/engine/organization/util/saveimport/HrmResourceImportAdaptUtil.java similarity index 97% rename from src/com/engine/organization/service/impl/HrmResourceImportAdaptServiceImpl.java rename to src/com/engine/organization/util/saveimport/HrmResourceImportAdaptUtil.java index 8e81c05d..dde271a5 100644 --- a/src/com/engine/organization/service/impl/HrmResourceImportAdaptServiceImpl.java +++ b/src/com/engine/organization/util/saveimport/HrmResourceImportAdaptUtil.java @@ -1,11 +1,9 @@ -package com.engine.organization.service.impl; +package com.engine.organization.util.saveimport; -import com.engine.core.impl.Service; import com.engine.hrm.util.HrmWeakPasswordUtil; import com.engine.organization.entity.extend.po.ExtendInfoPO; import com.engine.organization.entity.hrmresource.param.HrmResourceImportParam; import com.engine.organization.mapper.extend.ExtendInfoMapper; -import com.engine.organization.service.HrmResourceImportAdaptService; import com.engine.organization.util.db.MapperProxyFactory; import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.ss.usermodel.*; @@ -33,7 +31,7 @@ import java.util.regex.Pattern; * @createTime: 2022/06/27 * @version: 1.0 */ -public class HrmResourceImportAdaptServiceImpl extends Service implements HrmResourceImportAdaptService { +public class HrmResourceImportAdaptUtil { private String fileName; @@ -109,7 +107,7 @@ public class HrmResourceImportAdaptServiceImpl extends Service implements HrmRes Map> checkInfos = new HashMap<>(); - private final String[] checkKeys = new String[]{"login_id", "work_code"}; + private final String[] checkKeys = new String[]{"loginid", "workcode"}; private int accountTypeIndex = 50; private int accountTypeColumn = -1; @@ -141,7 +139,6 @@ public class HrmResourceImportAdaptServiceImpl extends Service implements HrmRes * @param fu 上传参数 * @return List */ - @Override public List creatImportMap(FileUploadToPath fu) { try { new BaseBean().writeLog("lxr2018>>>language2=" + userlanguage); @@ -196,9 +193,7 @@ public class HrmResourceImportAdaptServiceImpl extends Service implements HrmRes /** * 获取人员map */ - @Override public Map getHrmImportMap() { - return hrmResourceMap; } @@ -443,9 +438,9 @@ public class HrmResourceImportAdaptServiceImpl extends Service implements HrmRes } } - String currentDate = weaver.common.DateUtil.getCurrentDate(); + String currentDate = DateUtil.getCurrentDate(); if (Util.null2String(importParam.getWork_start_date()).length() > 0 && Util.null2String(importParam.getWork_year()).length() == 0) {//计算工龄 - int day = weaver.common.DateUtil.dayDiff(importParam.getWork_start_date(), currentDate); + int day = DateUtil.dayDiff(importParam.getWork_start_date(), currentDate); DecimalFormat df = new DecimalFormat("0.0"); importParam.setWork_year(df.format(day / 365.0)); } @@ -480,13 +475,13 @@ public class HrmResourceImportAdaptServiceImpl extends Service implements HrmRes } String val = ""; switch (key) { - case "login_id": + case "loginid": val = importParam.getLogin_id(); break; - case "work_code": + case "workcode": val = importParam.getWork_code(); break; - case "certificate_num": + case "certificatenum": val = importParam.getCertificate_num(); break; } @@ -539,15 +534,15 @@ public class HrmResourceImportAdaptServiceImpl extends Service implements HrmRes String val = ""; String errorMsg = ""; switch (key) { - case "login_id": + case "loginid": val = Util.null2String(importParam.getLogin_id()).trim(); errorMsg = SystemEnv.getHtmlLabelName(520127, userlanguage); break; - case "work_code": + case "workcode": val = Util.null2String(importParam.getWork_code()).trim(); errorMsg = SystemEnv.getHtmlLabelName(520128, userlanguage); break; - case "certificate_num": + case "certificatenum": val = Util.null2String(importParam.getCertificate_num()).trim(); errorMsg = SystemEnv.getHtmlLabelName(83623, userlanguage); break; @@ -973,14 +968,7 @@ public class HrmResourceImportAdaptServiceImpl extends Service implements HrmRes cellValue = String.valueOf(cell.getBooleanCellValue()); break; case NUMERIC: - if (HSSFDateUtil.isCellDateFormatted(cell)) {//先看是否是日期格式 - SimpleDateFormat sft = new SimpleDateFormat("yyyy-MM-dd"); - cellValue = sft.format(cell.getDateCellValue()); //读取日期格式 - } else { - cellValue = String.valueOf(new Double(cell.getNumericCellValue())); //读取数字 - if (cellValue.endsWith(".0")) - cellValue = cellValue.substring(0, cellValue.indexOf(".")); - } + cellValue = SaveImportProcessUtil.getString(HSSFDateUtil.isCellDateFormatted(cell), cell.getDateCellValue(), cell.getNumericCellValue()); break; case FORMULA: //读取公式 cellValue = cell.getCellFormula(); @@ -1065,7 +1053,6 @@ public class HrmResourceImportAdaptServiceImpl extends Service implements HrmRes } } - @Override public void setUserlanguage(int userlanguage) { this.userlanguage = userlanguage; } diff --git a/src/com/engine/organization/service/impl/HrmResourceImportProcessServiceImpl.java b/src/com/engine/organization/util/saveimport/HrmResourceImportProcessUtil.java similarity index 99% rename from src/com/engine/organization/service/impl/HrmResourceImportProcessServiceImpl.java rename to src/com/engine/organization/util/saveimport/HrmResourceImportProcessUtil.java index 74dd4211..66b0b2f4 100644 --- a/src/com/engine/organization/service/impl/HrmResourceImportProcessServiceImpl.java +++ b/src/com/engine/organization/util/saveimport/HrmResourceImportProcessUtil.java @@ -1,9 +1,8 @@ -package com.engine.organization.service.impl; +package com.engine.organization.util.saveimport; import com.engine.common.entity.EncryptFieldEntity; import com.engine.common.util.ParamUtil; import com.engine.common.util.ServiceUtil; -import com.engine.core.impl.Service; import com.engine.encrypt.biz.EncryptFieldConfigComInfo; import com.engine.hrm.entity.RuleCodeType; import com.engine.hrm.service.ImportLogService; @@ -26,7 +25,6 @@ import com.engine.organization.mapper.hrmresource.HrmResourceMapper; import com.engine.organization.mapper.job.JobMapper; import com.engine.organization.mapper.post.PostInfoMapper; import com.engine.organization.mapper.post.PostMapper; -import com.engine.organization.service.HrmResourceImportProcessService; import com.engine.organization.util.PageInfoSortUtil; import com.engine.organization.util.db.MapperProxyFactory; import ln.LN; @@ -61,10 +59,10 @@ import java.util.regex.Pattern; /** * @author:dxfeng - * @createTime: 2022/06/27 + * @createTime: 2022/06/30 * @version: 1.0 */ -public class HrmResourceImportProcessServiceImpl extends Service implements HrmResourceImportProcessService { +public class HrmResourceImportProcessUtil { private final Map keyMap = new HashMap<>(); //看数据库是否有重复,将数据库现有的数据查出 @@ -73,7 +71,7 @@ public class HrmResourceImportProcessServiceImpl extends Service implements HrmR Map> checkInfos = new HashMap<>(); - private final String[] checkKeys = new String[]{"login_id", "work_code"}; + private final String[] checkKeys = new String[]{"loginid", "workcode"}; private Map baseTypeMap; //基础信息自定义字段数据库类型与字段名称映射 @@ -133,12 +131,10 @@ public class HrmResourceImportProcessServiceImpl extends Service implements HrmR return MapperProxyFactory.getProxy(PostMapper.class); } - @Override public void setUser(User user) { this.user = user; } - @Override public Map init(HttpServletRequest request) { Map retmap = new HashMap<>(); try { @@ -231,7 +227,6 @@ public class HrmResourceImportProcessServiceImpl extends Service implements HrmR * * @param hrMap 人员数据Map集合 */ - @Override public void processMap(Map hrMap) {//增加同步锁,防止同时多次调用 List resultList = new ArrayList<>(); //导入结果 RecordSet recordSet = new RecordSet(); @@ -1974,13 +1969,13 @@ public class HrmResourceImportProcessServiceImpl extends Service implements HrmR ImportLogService importLogService = ServiceUtil.getService(ImportLogServiceImpl.class, user); String relatedName = ""; switch (this.keyField) { - case "work_code": + case "workcode": relatedName = log.getWorkCode(); break; - case "login_id": + case "loginid": relatedName = log.getLoginid(); break; - case "last_name": + case "lastname": relatedName = log.getLastname(); break; } @@ -2014,15 +2009,15 @@ public class HrmResourceImportProcessServiceImpl extends Service implements HrmR String val = ""; String errorMsg = ""; switch (key) { - case "login_id": + case "loginid": val = Util.null2String(importParam.getLogin_id()).trim(); errorMsg = SystemEnv.getHtmlLabelName(522076, userlanguage); break; - case "work_code": + case "workcode": val = Util.null2String(importParam.getWork_code()).trim(); errorMsg = SystemEnv.getHtmlLabelName(520197, userlanguage); break; - case "certificate_num": + case "certificatenum": val = Util.null2String(importParam.getCertificate_num()).trim(); errorMsg = SystemEnv.getHtmlLabelName(83521, userlanguage); break; diff --git a/src/com/engine/organization/util/saveimport/SaveImportProcessUtil.java b/src/com/engine/organization/util/saveimport/SaveImportProcessUtil.java new file mode 100644 index 00000000..534c101e --- /dev/null +++ b/src/com/engine/organization/util/saveimport/SaveImportProcessUtil.java @@ -0,0 +1,628 @@ +package com.engine.organization.util.saveimport; + +import com.engine.common.util.ParamUtil; +import com.engine.common.util.ServiceUtil; +import com.engine.hrm.service.ImportLogService; +import com.engine.hrm.service.impl.ImportLogServiceImpl; +import org.apache.poi.hssf.usermodel.*; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.jetbrains.annotations.NotNull; +import weaver.file.ImageFileManager; +import weaver.general.BaseBean; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.hrm.excelimport.*; +import weaver.systeminfo.SystemEnv; + +import javax.servlet.http.HttpServletRequest; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.text.SimpleDateFormat; +import java.util.*; + +/** + * @author:dxfeng + * @createTime: 2022/06/30 + * @version: 1.0 + */ +public class SaveImportProcessUtil { + /** + * 导入类型 + */ + private String importType; + + /** + * excel页签 + */ + private HSSFSheet sheet; + /** + * 存储报错信息位置 + */ + private final List lsImportSourceMap = new ArrayList<>(); + /** + * 存储报错信息 + */ + private final List errorInfo = new ArrayList<>(); + /** + * 存储参数类型名称 + */ + private final Map parameterTypes = new HashMap<>(); + /** + * 字段类型 + */ + private final Map fieldTypes = new HashMap<>(); + /** + * 类名 + */ + private final Map mapImportSource = new HashMap<>(); + /** + * 导入类型名称 + */ + private final Map mapImportSourceName = new HashMap<>(); + /** + * excel文件中对应的字段别名 + */ + private final Map mapImportSourceField = new HashMap<>(); + /** + * excel文件中对应的字段名称 + */ + private final Map mapImportSourceFieldName = new HashMap<>(); + /** + * 多语言--中文 + */ + private int userLanguage = 7; + /** + * 字段名 + */ + private String[] voFields; + /** + * 类 + */ + private Class importSourceClass; + /** + * 字段标识 + */ + private String keyField = ""; + /** + * 操作人 + */ + private String creator = ""; + /** + * 导入类型 + */ + private String operateType = ""; + /** + * 常用组成员导入为覆盖时,清除旧数据只需要执行一次。false--还未清除旧数据、true--旧数据已经清除 + */ + private boolean isDeleted = false; + + private User user; + private int pId = 0; + + /** + * 客户端操作IP + */ + + public SaveImportProcessUtil() { + // TODO 组织导入类 + mapImportSource.put("company", new String[]{CompanyImportUtil.class.getName()}); + + mapImportSource.put("jobtitle", new String[]{HrmJobTitle.class.getName()}); + mapImportSource.put("group", new String[]{HrmGroup.class.getName()}); + mapImportSource.put("groupMember", new String[]{HrmGroupMember.class.getName()}); + mapImportSource.put("resourcedetial", new String[]{HrmFamilyInfo.class.getName(), + HrmLanguageAbility.class.getName(), + HrmEducationInfo.class.getName(), + HrmWorkResume.class.getName(), + HrmTrainBeforeWork.class.getName(), + HrmCertification.class.getName(), + HrmRewardBeforeWork.class.getName()}); + mapImportSource.put("city", new String[]{HrmCity.class.getName()}); + mapImportSource.put("location", new String[]{HrmLoaction.class.getName()}); + mapImportSource.put("special", new String[]{HrmSpeciality.class.getName()}); + mapImportSource.put("area", new String[]{HrmArea.class.getName()}); + mapImportSource.put("sensitiveword", new String[]{SensitiveWord.class.getName()}); + + mapImportSourceName.put("company", "分部、部门导入"); + mapImportSourceName.put("jobtitle", "岗位体系导入"); + mapImportSourceName.put("group", "常用组信息导入"); + mapImportSourceName.put("groupMember", "常用组成员导入"); + mapImportSourceName.put("resourcedetial", "个人数据导入"); + mapImportSourceName.put("city", "位置信息导入"); + mapImportSourceName.put("location", "办公地点信息导入"); + mapImportSourceName.put("special", "专业信息导入"); + mapImportSourceName.put("area", "行政区域导入"); + mapImportSourceName.put("sensitiveword", "敏感词"); + + mapImportSourceField.put("company", new String[]{"subcompanyname,departmentname,subcompanyshoworder,subcompanycode,departmentshoworder,departmentcode"}); + mapImportSourceField.put("jobtitle", new String[]{"jobtitlemark,jobtitlename,jobtitlecode,jobactivityname,jobgroupname,jobresponsibility,jobcompetency,jobtitleremark"}); + mapImportSourceField.put("group", new String[]{"typename,groupname,username,keycode"}); + mapImportSourceField.put("groupMember", new String[]{"workCode,lastName,loginId"}); + mapImportSourceField.put("resourcedetial", new String[]{"lastname,loginid,member,title,company,jobtitle,address", + "lastname,loginid,language,level_n,memo", + "lastname,loginid,school,speciality,startdate,enddate,educationlevel,studydesc", + "lastname,loginid,company,startdate,enddate,jobtitle,workdesc,leavereason", + "lastname,loginid,trainname,trainstartdate,trainenddate,trainresource,trainmemo", + "lastname,loginid,certname,datefrom,dateto,awardfrom", + "lastname,loginid,rewardname,rewarddate,rewardmemo"}); + mapImportSourceField.put("city", new String[]{"位置信息导入"}); + mapImportSourceField.put("location", new String[]{"locationname,locationdesc,locationcityname,countryname,showorder"}); + mapImportSourceField.put("special", new String[]{"name,description"}); + mapImportSourceField.put("area", new String[]{"countryname,provincename,cityname,citytwoname,longitude,latitude"}); + mapImportSourceField.put("sensitiveword", new String[]{"word,description,wordtype,handleway"}); + + + mapImportSourceFieldName.put("company", new String[]{"分部[必填],部门,分部显示顺序,分部编号,部门显示顺序,部门编号"}); + mapImportSourceFieldName.put("jobtitle", new String[]{"岗位简称[必填],岗位全称[必填],岗位编号,所属职务[必填],职务类别[必填],岗位职责,任职资格,备注"}); + mapImportSourceFieldName.put("group", new String[]{"类型[必填],名称[必填],成员姓名[必填],成员登录名[必填]"}); + mapImportSourceFieldName.put("groupMember", new String[]{"编号,姓名,登录名"}); + mapImportSourceFieldName.put("resourcedetial", new String[]{"员工姓名[必填],员工登录名[必填],成员,称谓,工作单位,职务,地址", + "员工姓名[必填],员工登录名[必填],语言,水平,备注", + "员工姓名[必填],员工登录名[必填],学校名称,专业,开始日期,结束日期,学历,详细描述", + "员工姓名[必填],员工登录名[必填],公司名称,开始日期,结束日期,职务,工作描述,离开原因", + "员工姓名[必填],员工登录名[必填],培训名称,开始日期,结束日期,培训单位,备注", + "员工姓名[必填],员工登录名[必填],名称,开始日期,结束日期,颁发单位", + "员工姓名[必填],员工登录名[必填],奖惩名称,奖惩日期,备注"}); + mapImportSourceFieldName.put("city", new String[]{"位置信息导入"}); + mapImportSourceFieldName.put("location", new String[]{"办公地点简称[必填],办公地点全称[必填],城市[必填],国家,顺序"}); + mapImportSourceFieldName.put("special", new String[]{"专业名称[必填],专业描述[必填]"}); + mapImportSourceFieldName.put("area", new String[]{"国家[必填],省份,城市,区县,经度,纬度"}); + mapImportSourceFieldName.put("sensitiveword", new String[]{"敏感词[必填],详细描述,所属分类[必填],处理方式[必填]"}); + } + + /** + * 读取数据 + * + * @param request 请求 + */ + public List importXls(HttpServletRequest request) { + ImportLogService importLogService = ServiceUtil.getService(ImportLogServiceImpl.class, user); + Map params; + try { + this.user = (User) request.getSession(true).getAttribute("weaver_user@bean"); + String filename = request.getParameter("excelfile"); + this.importType = Util.null2String(request.getParameter("importType")); + this.keyField = Util.null2String(request.getParameter("keyField")); + this.creator = "" + user.getUID(); + this.userLanguage = Util.getIntValue(request.getParameter("userlanguage"), 7); + this.operateType = Util.null2String(request.getParameter("operateType")); + // 常用组导入为覆盖时,已经清除掉旧数据的常用组ID集合(暂时只用于常用组的导入) + List deletedGroupId = new ArrayList<>(); + + ImageFileManager manager = new ImageFileManager(); + manager.getImageFileInfoById(Util.getIntValue(filename)); + HSSFWorkbook workbook = new HSSFWorkbook(new POIFSFileSystem(manager.getInputStream())); + + params = ParamUtil.request2Map(request); + Map retmap = importLogService.saveImportLog(params, request, user); + if (Util.null2String(retmap.get("status")).equals("1")) { + this.pId = Util.getIntValue(Util.null2String(retmap.get("pId"))); + String pIdName = "hrm" + this.importType + "PId"; + request.getSession(true).setAttribute(pIdName, this.pId); + } + + String[] tmpMapImportSource = mapImportSource.get(this.importType); + int idx = 0; + for (String tmpImportSource : tmpMapImportSource) { + idx++; + this.sheet = workbook.getSheetAt(idx); + importSourceClass = Class.forName(tmpImportSource); + voFields = mapImportSourceField.get(this.importType)[idx - 1].split(","); + initReflectParam(); + /*校验模板有效性 */ + if (idx == 1) { + String[] importSourceFieldName = mapImportSourceFieldName.get(this.importType); + String valExcelTempInfo = valExcelTemp(importSourceFieldName[idx - 1]); + if (valExcelTempInfo.length() > 0) { + this.errorInfo.add(valExcelTempInfo); + break; + } + } + readexcel(); + String importSourceName; + if (tmpImportSource.equals(HrmFamilyInfo.class.getName())) { + importSourceName = SystemEnv.getHtmlLabelName(814, userLanguage); + } else if (tmpImportSource.equals(HrmLanguageAbility.class.getName())) { + importSourceName = SystemEnv.getHtmlLabelName(815, userLanguage); + } else if (tmpImportSource.equals(HrmEducationInfo.class.getName())) { + importSourceName = SystemEnv.getHtmlLabelName(813, userLanguage); + } else if (tmpImportSource.equals(HrmWorkResume.class.getName())) { + importSourceName = SystemEnv.getHtmlLabelName(15716, userLanguage); + } else if (tmpImportSource.equals(HrmTrainBeforeWork.class.getName())) { + importSourceName = SystemEnv.getHtmlLabelName(15717, userLanguage); + } else if (tmpImportSource.equals(HrmCertification.class.getName())) { + importSourceName = SystemEnv.getHtmlLabelName(1502, userLanguage); + } else if (tmpImportSource.equals(HrmRewardBeforeWork.class.getName())) { + importSourceName = SystemEnv.getHtmlLabelName(15718, userLanguage); + } else { + importSourceName = mapImportSourceName.get(this.importType); + } + Object obj = null; + Method method; + String flag; + String valErrorInfo; + if (lsImportSourceMap.size() == 0) { + this.errorInfo.add("【" + importSourceName + "】" + SystemEnv.getHtmlLabelName(34195, userLanguage) + "!"); + } + if ("area".equals(importType)) { + //如果是行政区域导入,先删除脏数据 + HrmArea.deleteDirtyData(); + } + for (int i = 0; i < lsImportSourceMap.size(); i++) { + obj = lsImportSourceMap.get(i); + if (importType.equals("groupMember")) { + String groupId = Util.null2String(request.getParameter("groupid")); + + method = importSourceClass.getMethod("setGroupid", String.class); + method.invoke(obj, groupId); + } + + method = importSourceClass.getMethod("setUserLanguage", String.class); + method.invoke(obj, "" + userLanguage); + if (this.importType.equals("company")) { + method = importSourceClass.getMethod("setOperateType", String.class); + method.invoke(obj, this.operateType); + } + method = importSourceClass.getMethod("valExcelData"); + try { + valErrorInfo = (String) method.invoke(obj); + } catch (Exception e) { + //验证出错返回错误信息 + params = new HashMap<>(); + params.put("pId", this.pId); + params.put("lineNum", (i + 2)); + params.put("relatedName", this.getRelatedName(obj)); + params.put("msg", importSourceName + "第" + (i + 2) + "行数据,验证失败!"); + params.put("status", "0"); + importLogService.saveImportDeitalLog(params, user); + continue; + } + if (valErrorInfo.length() == 0) { + /*如果是常用组的导入,并且导入类型是覆盖,则需要先删除原有的数据*/ + if (this.importType.equals("group") && this.operateType.equals("cover")) { + method = importSourceClass.getMethod("setOperateType", String.class); + method.invoke(obj, this.operateType); + method = importSourceClass.getMethod("getId"); + int temp = (int) method.invoke(obj); + + if (!deletedGroupId.contains(temp)) { + method = importSourceClass.getMethod("deleteOldData"); + method.invoke(obj); + + deletedGroupId.add(temp); + } + } else if (this.importType.equals("groupMember") && this.operateType.equals("cover")) { + /*如果是常用组成员的导入,并且导入类型是覆盖,则需要先删除原有的数据*/ + method = importSourceClass.getMethod("setOperateType", String.class); + method.invoke(obj, this.operateType); + if (!this.isDeleted) { + method = importSourceClass.getMethod("deleteOldData"); + method.invoke(obj); + this.isDeleted = true; + } + } + method = importSourceClass.getMethod("save"); + flag = (String) method.invoke(obj); + params = new HashMap<>(); + params.put("pId", this.pId); + params.put("lineNum", (i + 2)); + params.put("relatedName", this.getRelatedName(obj)); + String msg = importSourceName + "第" + (i + 2) + "行数据," + this.getRelatedName(obj); + if (this.importType.equals("company")) { + method = importSourceClass.getMethod("getMessage"); + msg += (String) method.invoke(obj); + } + params.put("msg", flag.equals("true") ? msg + "导入成功" : msg + "导入失败"); + params.put("status", flag.equals("true") ? "1" : "0"); + importLogService.saveImportDeitalLog(params, user); + } else { + //验证出错返回错误信息 + params = new HashMap<>(); + params.put("pId", this.pId); + params.put("lineNum", (i + 2)); + params.put("relatedName", this.getRelatedName(obj)); + params.put("msg", importSourceName + "第" + (i + 2) + "行数据," + valErrorInfo); + params.put("status", "0"); + importLogService.saveImportDeitalLog(params, user); + } + } + //加载缓存 + method = importSourceClass.getMethod("removeCache"); + if (obj != null) method.invoke(obj); + + if (!this.importType.equals("resourcedetial")) { + params = new HashMap<>(); + params.put("pId", this.pId); + params.put("status", "over"); + importLogService.saveImportLogStatus(params, user); + } + } + + if (this.importType.equals("resourcedetial")) { + //导入基本信息自定义明细字段 + HrmResourceDefineDetialE9 HrmResourceDefineDetialE9 = new HrmResourceDefineDetialE9(); + HrmResourceDefineDetialE9.importXls(workbook, this.pId, user); + params = new HashMap<>(); + params.put("pId", this.pId); + params.put("status", "over"); + importLogService.saveImportLogStatus(params, user); + } + + } catch (FileNotFoundException e) { + params = new HashMap<>(); + params.put("pId", this.pId); + params.put("status", "error"); + importLogService.saveImportLogStatus(params, user); + } catch (IOException e) { + this.errorInfo.add(SystemEnv.getHtmlLabelName(83618, userLanguage)); + new BaseBean().writeLog(e); + params = new HashMap<>(); + params.put("pId", this.pId); + params.put("status", "error"); + importLogService.saveImportLogStatus(params, user); + } catch (IndexOutOfBoundsException e) { + new BaseBean().writeLog("岗位导入的报错1。。。。"); + this.errorInfo.add(SystemEnv.getHtmlLabelName(125871, userLanguage)); + new BaseBean().writeLog(e); + params = new HashMap<>(); + params.put("pId", this.pId); + params.put("status", "error"); + importLogService.saveImportLogStatus(params, user); + } catch (Exception e) { + new BaseBean().writeLog("岗位导入的报错2。。。。"); + new BaseBean().writeLog(e); + this.errorInfo.add(SystemEnv.getHtmlLabelName(125871, userLanguage)); + params = new HashMap<>(); + params.put("pId", this.pId); + params.put("status", "error"); + importLogService.saveImportLogStatus(params, user); + } + return this.errorInfo; + } + + /** + * 校验模板有效性 + * + * @param importSourceFieldName 导入文件名称 + */ + public String valExcelTemp(String importSourceFieldName) { + String valExcelTempInfo = ""; + HSSFRow row; + HSSFCell cell; + String cellValue; + try { + String[] fieldname = importSourceFieldName.split(","); + if (this.importType.equals("group")) { + if (this.keyField.equals("workcode")) { + fieldname[3] = "成员编号[必填]"; + } + } + row = sheet.getRow(0); + for (int cellIndex = 0; cellIndex < row.getLastCellNum(); cellIndex++) { + cell = row.getCell((short) cellIndex); + if (cell == null) continue; + cellValue = getCellValue(cell).trim(); + if (!fieldname[cellIndex].equals(cellValue)) { + valExcelTempInfo = SystemEnv.getHtmlLabelName(387156, user.getLanguage()); + break; + } + } + } catch (Exception e) { + new BaseBean().writeLog(e); + valExcelTempInfo = SystemEnv.getHtmlLabelName(387156, user.getLanguage()) + "1"; + } + + return valExcelTempInfo; + } + + /** + * 读excel文件内容 + */ + public void readexcel() { + try { + HSSFRow row; + HSSFCell cell; + String cellValue; + // 行号 + // 列号 + int firstRow = 1; + lsImportSourceMap.clear(); + int lastRow = sheet.getLastRowNum(); + for (int i = firstRow; i <= lastRow; i++) { + row = sheet.getRow(i); + if (row == null) { + errorInfo.add(SystemEnv.getHtmlLabelName(15323, userLanguage) + " " + (i + 1) + " " + SystemEnv.getHtmlLabelName(83622, userLanguage)); + continue; + } + + Object obj = importSourceClass.newInstance(); + for (int cellIndex = 0; cellIndex < row.getLastCellNum(); cellIndex++) { + cell = row.getCell((short) cellIndex); + if (cell == null) continue; + cellValue = getCellValue(cell).trim(); + setImportSourceValue(cellIndex, cellValue, obj, null); + } + switch (this.importType) { + case "group": + ((HrmGroup) obj).setKeyField(this.keyField); + ((HrmGroup) obj).setOwner(this.creator); + ((HrmGroup) obj).setOperateType(this.operateType); + break; + case "groupMember": + ((HrmGroupMember) obj).setKeyField(this.keyField); + break; + case "sensitiveword": + ((SensitiveWord) obj).setCreater(this.creator); + break; + } + lsImportSourceMap.add(obj); + } + } catch (Exception e) { + new BaseBean().writeLog(e); + } + } + + /** + * 获取excel单元格值 + * + * @param cell 要读取的单元格对象 + */ + public String getCellValue(HSSFCell cell) { + String cellValue = ""; + if (cell == null) + return ""; + switch (cell.getCellType()) { + case BOOLEAN: // 得到Boolean对象的方法 + cellValue = String.valueOf(cell.getBooleanCellValue()); + break; + case NUMERIC: + cellValue = getString(HSSFDateUtil.isCellDateFormatted(cell), cell.getDateCellValue(), cell.getNumericCellValue()); + break; + case FORMULA: // 读取公式 + cellValue = cell.getCellFormula(); + break; + case STRING: // 读取String + cellValue = cell.getStringCellValue(); + break; + } + cellValue = Util.toHtmlForHrm(cellValue); + return cellValue; + } + + @NotNull + public static String getString(boolean cellDateFormatted, Date dateCellValue, double numericCellValue) { + String cellValue; + if (cellDateFormatted) {// 先看是否是日期格式 + SimpleDateFormat sft = new SimpleDateFormat("yyyy-MM-dd"); + cellValue = sft.format(dateCellValue); // 读取日期格式 + } else { + cellValue = String.valueOf(new Double(numericCellValue)); // 读取数字 + if (cellValue.endsWith(".0")) + cellValue = cellValue.substring(0, cellValue.indexOf(".")); + } + return cellValue; + } + + /** + * 通过反射为对象赋值 + * + * @param cellNum 列号 + * @param cellValue 单元格值 + * @param importSourceObj 需要赋值的 + */ + public void setImportSourceValue(int cellNum, String cellValue, Object importSourceObj, String field) { + if (field == null) { + String excelField = voFields[cellNum]; + String methodName = "set" + excelField.substring(0, 1).toUpperCase() + excelField.substring(1); + Method method = parameterTypes.get(methodName); + try { + String fieldType = fieldTypes.get(excelField); + if (fieldType.equals("java.lang.String")) + method.invoke(importSourceObj, cellValue); + else if (fieldType.equals("java.lang.Integer") && !cellValue.equals("")) { + method.invoke(importSourceObj, Integer.parseInt(cellValue)); + } else if (fieldType.equals("java.lang.Float") && !cellValue.equals("")) + method.invoke(importSourceObj, Float.parseFloat(cellValue)); + else if (fieldType.equals("java.lang.Short") && !cellValue.equals("")) { + method.invoke(importSourceObj, Short.parseShort(cellValue)); + } + } catch (Exception e) { + new BaseBean().writeLog(e); + } + } else { + String methodName = "set" + field.substring(0, 1).toUpperCase() + field.substring(1); + Method method = parameterTypes.get(methodName); + try { + method.invoke(importSourceObj, cellValue); + } catch (Exception e) { + new BaseBean().writeLog(e); + } + } + } + + /** + * 初始化反射所需要的方法和字段Map,parameterTypes,fieldTypes + */ + public void initReflectParam() { + try { + parameterTypes.clear(); + fieldTypes.clear(); + Method[] hrmResourceMethods = importSourceClass.getDeclaredMethods(); + for (Method hrmResourceMethod : hrmResourceMethods) { + parameterTypes.put(hrmResourceMethod.getName(), hrmResourceMethod); + } + Field[] importSourceFields = importSourceClass.getDeclaredFields(); + for (Field importSourceField : importSourceFields) { + Class fieldTypeClass = importSourceField.getType(); + if (fieldTypeClass == Integer.TYPE) { + fieldTypeClass = Integer.class; + } + fieldTypes.put(importSourceField.getName(), fieldTypeClass.getName()); + } + } catch (Exception e) { + new BaseBean().writeLog(e); + } + } + + + private String getRelatedName(Object obj) { + String relatedName = ""; + try { + switch (this.importType) { + case "company": { + Method method = importSourceClass.getMethod("getSubcompanyname"); + relatedName = Util.null2String(method.invoke(obj)); + method = importSourceClass.getMethod("getDepartmentname"); + String departmentname = Util.null2String(method.invoke(obj)); + if (departmentname.length() > 0) { + relatedName += ">"; + } + relatedName += departmentname; + break; + } + case "loaction": { + Method method = importSourceClass.getMethod("getLocationname"); + relatedName = Util.null2String(method.invoke(obj)); + break; + } + case "jobtitle": { + Method method = importSourceClass.getMethod("setJobtitlemark"); + relatedName = Util.null2String(method.invoke(obj)); + break; + } + case "group": { + Method method = importSourceClass.getMethod("getGroupname"); + relatedName = Util.null2String(method.invoke(obj)); + break; + } + case "city": + case "special": { + Method method = importSourceClass.getMethod("getName"); + relatedName = Util.null2String(method.invoke(obj)); + break; + } + case "area": { + Method method = importSourceClass.getMethod("getCountryname"); + relatedName = Util.null2String(method.invoke(obj)); + break; + } + case "resourcedetial": { + Method method = importSourceClass.getMethod("getLastname"); + relatedName = Util.null2String(method.invoke(obj)); + break; + } + case "sensitiveword": { + Method method = importSourceClass.getMethod("getWord"); + relatedName = Util.null2String(method.invoke(obj)); + break; + } + } + + } catch (Exception e) { + new BaseBean().writeLog(e); + } + return relatedName; + } +}