diff --git a/src/com/engine/hrm/cmd/organization/AddDepartmentCmd.java b/src/com/engine/hrm/cmd/organization/AddDepartmentCmd.java new file mode 100644 index 0000000..2e55dfe --- /dev/null +++ b/src/com/engine/hrm/cmd/organization/AddDepartmentCmd.java @@ -0,0 +1,226 @@ +package com.engine.hrm.cmd.organization; + +import com.api.hrm.util.ServiceUtil; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.biz.SimpleBizLogger; +import com.engine.common.constant.BizLogOperateAuditType; +import com.engine.common.constant.BizLogSmallType4Hrm; +import com.engine.common.constant.BizLogType; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.hrm.cmd.matrix.biz.MatrixMaintComInfo; +import com.engine.hrm.entity.RuleCodeType; +import com.engine.hrm.util.CodeRuleManager; +import com.engine.hrm.util.HrmOrganizationUtil; +import com.engine.hrm.util.face.HrmFaceCheckManager; +import org.apache.commons.lang3.StringUtils; +import weaver.conn.RecordSet; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.hrm.common.DbFunctionUtil; +import weaver.hrm.company.DepartmentComInfo; +import weaver.hrm.definedfield.HrmDeptFieldManagerE9; +import weaver.interfaces.email.CoreMailAPI; +import weaver.interfaces.hrm.HrmServiceManager; +import weaver.matrix.MatrixUtil; +import weaver.rtx.OrganisationCom; +import weaver.rtx.OrganisationComRunnable; +import weaver.systeminfo.SystemEnv; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class AddDepartmentCmd extends AbstractCommonCommand>{ + + private SimpleBizLogger logger; + + public AddDepartmentCmd(Map params, User user) { + this.user = user; + this.params = params; + + String departmentname = Util.fromScreen((String)params.get("departmentname"),user.getLanguage()); + + this.logger = new SimpleBizLogger(); + BizLogContext bizLogContext = new BizLogContext(); + bizLogContext.setLogType(BizLogType.HRM_ENGINE);//模块类型 + bizLogContext.setBelongType(BizLogSmallType4Hrm.HRM_ENGINE_ORGANIZATION); + bizLogContext.setLogSmallType(BizLogSmallType4Hrm.HRM_ENGINE_ORGANIZATION_DPEARTMENT);//当前小类型 + bizLogContext.setOperateAuditType(BizLogOperateAuditType.WARNING);//警告 + bizLogContext.setParams(params);//当前request请求参数 + logger.setUser(user);//当前操作人 + String mainSql = "select * from HrmDepartment where 1=2 "; + logger.setMainSql(mainSql,"id");//主表sql + logger.setMainPrimarykey("id");//主日志表唯一key + logger.setMainTargetNameColumn("departmentname");//当前targetName对应的列(对应日志中的对象名) + logger.before(bizLogContext); + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + RecordSet rs = new RecordSet(); + try { + + if (!HrmUserVarify.checkUserRight("HrmDepartmentAdd:Add", user)) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage())); + return retmap; + } + + DepartmentComInfo DepartmentComInfo = new DepartmentComInfo(); + //OrganisationCom OrganisationCom = new OrganisationCom(); + HrmServiceManager HrmServiceManager = new HrmServiceManager(); + + String departmentmark = Util.fromScreen((String)params.get("departmentmark"),user.getLanguage()); + String departmentname = Util.fromScreen((String)params.get("departmentname"),user.getLanguage()); + String subcompanyid1 = Util.fromScreen((String)params.get("subcompanyid1"),user.getLanguage()); + int supdepid = Util.getIntValue((String)params.get("supdepid"),0); + String showorder = Util.fromScreen(Util.null2s((String)params.get("showorder"),"0"),user.getLanguage()); + + if(Util.getIntValue(subcompanyid1,0)<=0){ + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382647, user.getLanguage())); + return retmap; + } + + String allsupdepid = "0"; + String departmentcode = Util.fromScreen((String)params.get("departmentcode"),user.getLanguage()); + int coadjutant=Util.getIntValue((String)params.get("coadjutant"),0); + + /* + * Added by Charoes Huang + * 判断是否10级部门 + */ + int supdepartmentid = supdepid; + if(supdepartmentid > 0){ + Map supMap = new HashMap(); + supMap.put(""+supdepid, "1"); + int supdepidtemp = Util.getIntValue(DepartmentComInfo.getDepartmentsupdepid(""+supdepid), 0); + while(supdepidtemp>0){ + if(supMap.get(""+supdepidtemp)==null){ + supMap.put(""+supdepidtemp, "1"); + supdepidtemp = Util.getIntValue(DepartmentComInfo.getDepartmentsupdepid(""+supdepidtemp), 0); + }else{ + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382650,user.getLanguage())); + return retmap; + } + } + if(HrmOrganizationUtil.ifDeptLevelEquals10(supdepartmentid)){ + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382650, user.getLanguage())); + return retmap; + } + } + + // 如果编码为空 自动生成编码 + departmentcode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.DEPARTMENT, subcompanyid1, departmentcode,String.valueOf(supdepid)); + + if(!"".equals(departmentcode)){ + String sql2="select id from hrmdepartment where departmentcode = '" + departmentcode + "' "; + rs.executeSql(sql2); + if(rs.next()){ + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382653, user.getLanguage())); + return retmap; + } + } + + + char separator = Util.getSeparator() ; + if(supdepid > 0){//当选择了上级部门的时候,需要更改当前部门的上级分部 + subcompanyid1 = DepartmentComInfo.getSubcompanyid1(supdepid+""); + } + + String para = departmentmark + separator + departmentname + separator + + supdepid+separator+allsupdepid+separator+subcompanyid1 + separator+ showorder+separator+coadjutant; + rs.executeProc("HrmDepartment_Insert",para); + int flag=rs.getFlag(); + if(flag==2){ + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382655, user.getLanguage())); + return retmap; + }else if(flag==3){ + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382657, user.getLanguage())); + return retmap; + } + + int id=0; + if(rs.next()){ + id = rs.getInt(1); + } + + weaver.hrm.company.OrgOperationUtil OrgOperationUtil = new weaver.hrm.company.OrgOperationUtil(); + OrgOperationUtil.updateDepartmentLevel(""+id,"0"); + String sql3="update hrmdepartment set departmentcode = '" + departmentcode + "' "; + sql3 += ","+ DbFunctionUtil.getInsertUpdateSetSql(rs.getDBType(),user.getUID()) ; + sql3+=" where id = "+id; + rs.executeSql(sql3); + HrmDeptFieldManagerE9 hrmDeptFieldManager = new HrmDeptFieldManagerE9(5); + hrmDeptFieldManager.editCustomData(params,id); + + + DepartmentComInfo.removeCompanyCache(); + rs.executeSql("update orgchartstate set needupdate=1"); + + //add by wjy + //同步RTX端部门信息 + //OrganisationCom.addDepartment(id);//执行速度过慢,改为另起线程执行 + new Thread(new OrganisationComRunnable("department", "add", String.valueOf(id))).start(); + + //同步到CoreMail邮件系统开始 + if(supdepid == 0) { + CoreMailAPI.synOrg(""+id, departmentname, "parent_org_unit_id=com_"+subcompanyid1+"&org_unit_name="+departmentname, "0"); + //testapi.synOrg(""+id, departmentname, "com_"+subcompanyid1, "0"); + } else { + CoreMailAPI.synOrg(""+id, departmentname, "parent_org_unit_id="+supdepid+"&org_unit_name="+departmentname, "0"); + //testapi.synOrg(""+id, departmentname, ""+supdepid, "0"); + } + //同步到CoreMail邮件系统结束 + + //OA与第三方接口单条数据同步方法开始 + HrmServiceManager.SynInstantDepartment(""+id,"1"); + //OA与第三方接口单条数据同步方法结束 + + HrmFaceCheckManager.sync(id+"",HrmFaceCheckManager.getOptInsert(),this.getClass().getName(),HrmFaceCheckManager.getOaDepartment()); + + + //同步部门数据到矩阵 + MatrixUtil.updateDepartmentData(""+id); + //同步矩阵维护范围 + MatrixMaintComInfo maintComInfo = new MatrixMaintComInfo(); + maintComInfo.removeCache(); + //初始化应用分权 + new weaver.hrm.appdetach.AppDetachComInfo().initSubDepAppData(); + + String mainSql = "select a.* from HrmDepartment a left join HrmDepartmentdefined b on a.id=b.deptid where a.id in(" + id + ")"; + String tableColumns = new ServiceUtil().getTableColumns("select * from HrmDepartmentdefined", "b", "id"); + if (!tableColumns.equals("")) { + mainSql = "select a.*," + tableColumns + " from HrmDepartment a left join HrmDepartmentdefined b on a.id=b.deptid where a.id in(" + id + ")"; + } + logger.setMainSql(mainSql, "id");//主表sql + + retmap.put("id", id); + retmap.put("status", "1"); + retmap.put("message", SystemEnv.getHtmlLabelName(18758, user.getLanguage())); + } catch (Exception e) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage())); + writeLog(e); + } + return retmap; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + @Override + public List getLogContexts() { + return logger.getBizLogContexts(); + } +} diff --git a/src/com/engine/hrm/util/CodeRuleManager.java b/src/com/engine/hrm/util/CodeRuleManager.java new file mode 100644 index 0000000..c7cbafa --- /dev/null +++ b/src/com/engine/hrm/util/CodeRuleManager.java @@ -0,0 +1,314 @@ +package com.engine.hrm.util; + +import com.engine.hrm.entity.RuleCodeType; +import com.engine.xmgsecond.util.DepartmentCodeUtil; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.Util; +import weaver.hrm.company.DepartmentComInfo; +import weaver.hrm.company.SubCompanyComInfo; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CodeRuleManager extends BaseBean { + + private static CodeRuleManager codeRuleManager = new CodeRuleManager(); + + private SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo(); + private DepartmentComInfo departmentComInfo = new DepartmentComInfo(); + + public static String NULL = "NULL"; + public static String SEPARATOR = "-"; + + public static CodeRuleManager getCodeRuleManager() { + return codeRuleManager; + } + + private CodeRuleManager() { + + } + + /** + * + * @param serialtype SUBCOMPANY("SUBCOMPANY"), DEPARTMENT("DEPARTMENT"), JOBTITLES("JOBTITLES"), USER("USER") + * @return + * @throws Exception + */ + public String generateRuleCode(RuleCodeType serialtype, String inputCode) throws Exception { + return this.generateRuleCode(serialtype, null, null, null, inputCode); + } + + /** + * + * @param serialtype SUBCOMPANY("SUBCOMPANY"), DEPARTMENT("DEPARTMENT"), JOBTITLES("JOBTITLES"), USER("USER") + * @param subcompanyCode 分部编号 + * @return 部门 + * @throws Exception + */ + public String generateRuleCode(RuleCodeType serialtype, String subcompanyid, String inputCode,String supDeptid) throws Exception { + + if (StringUtils.isNotEmpty(inputCode)) { + checkReservedIfDel(serialtype.getValue(), inputCode); + return inputCode; + } + RecordSet recordSet = new RecordSet(); + // 查询启用的编码规则 + String sql = "select * from hrm_coderule where serialtype = ? and serialenable = 1"; + recordSet.executeQuery(sql, serialtype.getValue()); + if (recordSet.getCounts() <=0) { + return ""; + } + + //QC3600738 新美光HR项目 部门自定义编码 新建(卡片 导入等) + if("DEPARTMENT".equals(serialtype.getValue())) { + DepartmentCodeUtil departmentCodeUtil = new DepartmentCodeUtil(); + return departmentCodeUtil.generateRuleCode(subcompanyid,"",supDeptid); + } + + + return ""; + } + + /** + * + * @param serialtype SUBCOMPANY("SUBCOMPANY"), DEPARTMENT("DEPARTMENT"), JOBTITLES("JOBTITLES"), USER("USER") + * @param subcompanyid 分部id + * @param deptid 部门id + * @return 返回编码规则生成的编码 + * @throws Exception + */ + public String generateRuleCode(RuleCodeType serialtype, String subcompanyid, String deptid, String jobtitlesid, String inputCode) throws Exception { + if (StringUtils.isNotEmpty(inputCode)) { + checkReservedIfDel(serialtype.getValue(), inputCode); + return inputCode; + } + RecordSet recordSet = new RecordSet(); + // 查询启用的编码规则 + String sql = "select * from hrm_coderule where serialtype = ? and serialenable = 1"; + recordSet.executeQuery(sql, serialtype.getValue()); + if (recordSet.getCounts() <=0) { + return ""; + } + recordSet.next(); + + //QC3600738 新美光HR项目 部门自定义编码 重新生成编号 + if("DEPARTMENT".equals(serialtype.getValue())) { + DepartmentCodeUtil departmentCodeUtil = new DepartmentCodeUtil(); + return departmentCodeUtil.generateRuleCode(subcompanyid,deptid,""); + } + + // 先匹配到规则的唯一编码 + String oneselftype = recordSet.getString("oneselftype"); + String id = recordSet.getString("id"); + String[] oneselftypeList = StringUtils.isEmpty(oneselftype) ? new String[]{} : oneselftype.split(","); + Map map = new HashMap<>(); + LocalDate now = LocalDate.now(); + for (String type : oneselftypeList) { + switch (RuleCodeType.getByValue(type)) { + case DAY: + map.put(RuleCodeType.DAY.getValue(), String.format("%02d", now.getDayOfMonth())); + case MONTH: + map.put(RuleCodeType.MONTH.getValue(), String.format("%02d", now.getMonthValue())); + case YEAR: + map.put(RuleCodeType.YEAR.getValue(), String.valueOf(now.getYear())); + break; + case SUBCOMPANY: + map.put("subcompanyid", subcompanyid); + break; + case DEPARTMENT: + map.put("deptid", deptid); + break; + case JOBTITLES: + map.put("jobtitlesid", jobtitlesid); + break; + } + } + String uniqueconstitute = map.isEmpty() ? CodeRuleManager.buildUniqueconstituteNULL() : CodeRuleManager.buildUniqueconstitute(map.get(RuleCodeType.YEAR.getValue()), map.get(RuleCodeType.MONTH.getValue()), + map.get(RuleCodeType.DAY.getValue()), map.get("subcompanyid"), map.get("deptid"), map.get("jobtitlesid")); +// int index = 0; + while (true) { +// index ++; + String code = this.buildCode(id, subcompanyid, deptid, jobtitlesid, uniqueconstitute); + sql = "select * from hrm_coderulereserved where reservedcode = ? and coderuleid = ?"; + recordSet.executeQuery(sql, code, id); + if (recordSet.getCounts() <= 0 && !checkIsExist(code, serialtype.getValue())) { + return code; + } + } +// throw new Exception("自动创建编码失败!"); + } + + /** + * 检验预留编号是否存在 存在就删除 + * @param serialtype + * @param inputCode + */ + public void checkReservedIfDel(String serialtype, String inputCode) { + try { + RecordSet rs = new RecordSet(); + String sql = "select hcr.id from hrm_coderulereserved hcr left join hrm_coderule hc ON hcr.coderuleid = hc.id where hc.serialtype = ? and reservedcode = ?"; + rs.executeQuery(sql, serialtype, inputCode); + List ids = new ArrayList<>(); + while (rs.next()) { + ids.add(rs.getString("id")); + } + if (CollectionUtils.isNotEmpty(ids)) { + sql = "delete from hrm_coderulereserved where id in("+StringUtils.strip(ids.toString(),"[]")+")"; + rs.executeUpdate(sql); + } + } catch (Exception e) { + writeLog(e); + } + } + + private boolean checkIsExist(String code, String serialtype) { + RecordSet rs = new RecordSet(); + String sql = ""; + // 判断该字段是否已经被试用 + switch (RuleCodeType.getByValue(serialtype)) { + case SUBCOMPANY: + sql = "select id from HrmSubCompany where subcompanycode = ?"; + break; + case DEPARTMENT: + sql = "select id from HrmDepartment where departmentcode = ?"; + break; + case JOBTITLES: + sql = "select id from HrmJobTitles where jobtitlecode = ?"; + break; + case USER: + sql = "select id from hrmresource where workcode = ?"; + break; + } + rs.executeQuery(sql, code); + if (rs.getCounts() > 0) { + return true; + } + return false; + } + + private String buildCode(String id, String subcompanyid, String deptid,String jobtitlesid, String uniqueconstitute) throws Exception { + LocalDate localDate = LocalDate.now(); + // 生成编号 + RecordSet recordSet = new RecordSet(); + String sql = "select * from hrm_coderuledetail where coderuleid = ? ORDER BY showorder"; + StringBuilder sb = new StringBuilder(); + recordSet.executeQuery(sql, id); + while (recordSet.next()) { + String ruletype = recordSet.getString("ruletype"); + String rulevalue = Util.null2String(recordSet.getString("rulevalue")).trim(); + switch (RuleCodeType.getByValue(ruletype)) { + case STRING: + sb.append(rulevalue); + break; + case YEAR: + sb.append(localDate.getYear()); + break; + case MONTH: + sb.append(String.format("%02d", localDate.getMonthValue())); + break; + case DAY: + sb.append(String.format("%02d", localDate.getDayOfMonth())); + break; + case SUBCOMPANY: + sb.append(subCompanyComInfo.getSubCompanyCode(subcompanyid)); + break; + case DEPARTMENT: + sb.append(departmentComInfo.getDepartmentCode(deptid)); + break; + case JOBTITLES: + sb.append(getJobtitlesCode(jobtitlesid)); + break; + case NUMBER: + int number = this.getNumber(id, 0, uniqueconstitute); +// if ((number+ "").length() > Integer.parseInt(rulevalue) - 1) { +// throw new Exception("流水号超出定义位数!"); +// } + sb.append(String.format("%0"+rulevalue+"d", number)); + break; + } + } + return sb.toString(); + } + + private String getJobtitlesCode(String jobtitlesid) { + RecordSet rs = new RecordSet(); + String sql = "select jobtitlecode from hrmjobtitles where id = ?"; + rs.executeQuery(sql, jobtitlesid); + while (rs.next()) { + return rs.getString("jobtitlecode"); + } + return ""; + } + + /** + * 获取流水号 + * @param id + */ + private int getNumber(String id, int index, String uniqueconstitute) throws Exception { + if (index == 5) { + throw new Exception("编号重复!"); + } + RecordSet rs = new RecordSet(); + String sql = "select * from hrm_coderulerecord where coderuleid = ? and uniqueconstitute = ?"; + rs.executeQuery(sql, id, uniqueconstitute); + int currentnumber = -1; + int version = -1; + if (rs.next()) { + currentnumber = Integer.parseInt(rs.getString("currentnumber")); + version = Integer.parseInt(rs.getString("version")); + } else { + // 不存在 插入默认起始编号 + sql = "insert into hrm_coderulerecord (coderuleid, uniqueconstitute, startnumber, currentnumber, version) values (? ,? ,? ,?, ?)"; + if (rs.executeUpdate(sql, id, uniqueconstitute, 1, 1, 1)) { + currentnumber = 1; + version = 1; + } + } + + sql = "update hrm_coderulerecord set version = ?, currentnumber = ? where coderuleid = ? and version = ? and uniqueconstitute = ?"; + // 通过乐观锁的实现方式处理集群下的并发可能 + rs.executeUpdate(sql, version + 1, currentnumber + 1, id, version, uniqueconstitute); + if (rs.next() && rs.getInt(0) <= 0) { + // 说明存在并发 未执行成功 重新获取 + index ++; + return getNumber(id, index, uniqueconstitute); + } + return currentnumber; + } + + /** + * 重置编码规则中的流水号 + * @param id + * @param startnumber + */ + private void resetRuleCode(String id, String startnumber) { + RecordSet rs = new RecordSet(); + String sql = "update hrm_coderule set resetdate = ?, currentnumber = ? where id = ?"; + rs.executeUpdate(sql, LocalDate.now().toString(), startnumber, id); + } + + /** + * 组成起始编号表唯一性的编号 + * @return + */ + public static String buildUniqueconstitute(String year, String month, String day, String subcompanyid, String deptid, String jobtitlesid) { + return Util.null2String(year, NULL) + SEPARATOR + Util.null2String(month, NULL) + SEPARATOR + + Util.null2String(day, NULL) + SEPARATOR + Util.null2String(subcompanyid, NULL) + + SEPARATOR + Util.null2String(deptid, NULL) + SEPARATOR + Util.null2String(jobtitlesid, NULL); + } + + /** + * 组成起始编号表唯一性的编号 + * @return + */ + public static String buildUniqueconstituteNULL() { + return NULL + SEPARATOR + NULL + SEPARATOR + + NULL + SEPARATOR + NULL + + SEPARATOR + NULL + SEPARATOR + NULL; + } +} diff --git a/src/com/engine/xmgsecond/entity/DeptCodeRule.java b/src/com/engine/xmgsecond/entity/DeptCodeRule.java new file mode 100644 index 0000000..d33b3c3 --- /dev/null +++ b/src/com/engine/xmgsecond/entity/DeptCodeRule.java @@ -0,0 +1,33 @@ +package com.engine.xmgsecond.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +/** + * @Author liang.cheng + * @Date 2025/3/25 14:50 + * @Description: + * @Version 1.0 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DeptCodeRule { + + private Integer id; + + private Integer subcompany; + + private String code; + + private String firstNum; + + private String secondNum; + + private String threeNum; + + private String remark; + +} diff --git a/src/com/engine/xmgsecond/util/DepartmentCodeUtil.java b/src/com/engine/xmgsecond/util/DepartmentCodeUtil.java new file mode 100644 index 0000000..4296303 --- /dev/null +++ b/src/com/engine/xmgsecond/util/DepartmentCodeUtil.java @@ -0,0 +1,167 @@ +package com.engine.xmgsecond.util; + +import com.engine.xmgsecond.entity.DeptCodeRule; +import weaver.conn.RecordSet; +import weaver.general.StringUtil; +import weaver.general.Util; +import weaver.hrm.company.DepartmentComInfo; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +/** + * @Author liang.cheng + * @Date 2025/3/25 14:48 + * @Description: 新部门编号 + * @Version 1.0 + */ +public class DepartmentCodeUtil { + + private static final Map DEPT_LABEL_MAP = new HashMap<>(); + + static { + DEPT_LABEL_MAP.put("1", new int[]{1, 3}); + DEPT_LABEL_MAP.put("2", new int[]{3, 5}); + DEPT_LABEL_MAP.put("3", new int[]{5, 7}); + } + + public String generateRuleCode(String subcompanyId,String deptId, String lastSupdepid) { + + RecordSet rs = new RecordSet(); + + //1.根据分部获取新部门编码规则表信息 + DeptCodeRule deptCodeRule = null; + rs.executeQuery("select id,fb,bs,yjbmls,ejbmls,sjbmls,bz from uf_departmentcode_rules where fb = ?",subcompanyId); + if (rs.next()) { + deptCodeRule = DeptCodeRule.builder() + .id(Util.getIntValue(rs.getString("id"))) + .subcompany(Util.getIntValue(rs.getString("fb"))) + .code(Util.null2String(rs.getString("bs"))) + .firstNum(Util.null2String(rs.getString("yjbmls"))) + .secondNum(Util.null2String(rs.getString("ejbmls"))) + .threeNum(Util.null2String(rs.getString("sjbmls"))) + .build(); + } + + if (deptCodeRule == null) { + //新部门编码规则表未设置规则情况下 不进行编码直接返回 + return ""; + } + + //2.获取该部门所有上级部门 (需求确认中 部门层级最多只有3级),并获取对应的流水号,若不存在为 00 + DepartmentComInfo deptInfo = new DepartmentComInfo(); + + //上级部门id + if (StringUtil.isEmpty(lastSupdepid)) { + lastSupdepid = deptInfo.getDepartmentsupdepid(deptId); + } + String lastSupCode = deptInfo.getDepartmentCode(lastSupdepid); + lastSupdepid = lastSupdepid == null || lastSupdepid.isEmpty() ? "0" : lastSupdepid; + + //上上级部门id + String lastTopSupdepid = deptInfo.getDepartmentsupdepid(lastSupdepid); + lastTopSupdepid = lastTopSupdepid == null || lastTopSupdepid.isEmpty() ? "0" : lastTopSupdepid; + String lastTopSupCode = deptInfo.getDepartmentCode(lastTopSupdepid); + + // 例如一级部门 lastSupdepid="0",lastTopSupdepid="0" + // 例如二级部门 lastSupdepid="2726",lastTopSupdepid="0" + // 例如三级部门 lastSupdepid="2730",lastTopSupdepid="2726" + + String deptLevel = ""; + String serialnum = ""; + String departmentCode; + if ("0".equals(lastSupdepid)) { + // 一级部门 + serialnum = deptCodeRule.getFirstNum(); + deptLevel = "1"; + departmentCode = deptCodeRule.getCode() + "%s0000"; + } else if ("0".equals(lastTopSupdepid)) { + // 二级部门 + serialnum = deptCodeRule.getSecondNum(); + deptLevel = "2"; + String firstSerial = getSubstringByLevel(lastSupCode, "1"); + departmentCode = deptCodeRule.getCode() + firstSerial + "%s00"; + } else { + // 三级部门 + serialnum = deptCodeRule.getThreeNum(); + deptLevel = "3"; + String secondSerial = getSubstringByLevel(lastSupCode, "2"); + String firstSerial = getSubstringByLevel(lastTopSupCode,"1"); + departmentCode = deptCodeRule.getCode() + firstSerial + secondSerial + "%s"; + } + + + //3.获取当前部门序列号(1.截取该层级所有部门的流水号比较 ) + List departmentSerial = getDepartmentSerial(subcompanyId, deptCodeRule.getCode(), deptLevel); + if ("00".equals(serialnum)) { + departmentSerial.add(serialnum); + } + + + //List中元素 ["01","02","03","06","05","24","08"] 如 01 - 24,若是连续且存在 则当前部门流水号 24+1;2.若不连续则使用跳号中最小的数字作为当前部门流水号 + List sortedNumbers = departmentSerial.stream() + .map(Integer::parseInt) + .sorted() + .collect(Collectors.toList()); + + // 查找跳号 + int nextNumber = IntStream.rangeClosed(1, sortedNumbers.isEmpty() ? 1 : sortedNumbers.get(sortedNumbers.size() - 1) + 1) + .filter(num ->!sortedNumbers.contains(num)) + .findFirst() + .orElseGet(() -> sortedNumbers.isEmpty() ? 1 : sortedNumbers.get(sortedNumbers.size() - 1) + 1); + + // 格式化结果 + String newSerialnum = String.format("%02d", nextNumber); + + //4.更新部门规则表流水号 + //检查是否存在跳号 如果是跳号则不更新 + boolean isJump = nextNumber > Integer.parseInt(serialnum); + + if (isJump) { + Map fieldMap = new HashMap<>(); + fieldMap.put("1", "yjbmls"); + fieldMap.put("2", "ejbmls"); + fieldMap.put("3", "sjbmls"); + String field = fieldMap.get(deptLevel); + rs.executeUpdate("update uf_departmentcode_rules set "+field+" = ?",newSerialnum); + } + + return String.format(departmentCode,newSerialnum); + } + + + + public List getDepartmentSerial(String subcompanyId,String code,String deptLevel) { + RecordSet rs = new RecordSet(); + List deptSerial = new ArrayList<>(); + rs.executeQuery("select departmentcode from hrmdepartment where subcompanyid1 = ? and departmentcode like '"+code+"%'",subcompanyId); + while (rs.next()) { + String departmentcode = Util.null2String(rs.getString("departmentcode")); + + //D010000 deptLevel="1" 截取23位 deptLevel="2" 截取45位 deptLevel="3" 截取67位 + String serialNumber = getSubstringByLevel(departmentcode, deptLevel); + deptSerial.add(serialNumber); + } + + //去除List中 为 00 的元素 ["00","01","02","03","06","05","00"] + return deptSerial.stream() + .filter(element -> !"00".equals(element)) + .collect(Collectors.toList()); + + } + + + public String getSubstringByLevel(String str, String deptLevel) { + // 根据 deptLevel 获取对应的索引范围 + int[] indices = DEPT_LABEL_MAP.get(deptLevel); + if (indices != null && str.length() >= indices[1]) { + // 若存在对应的索引范围且字符串长度足够,则进行截取 + return str.substring(indices[0], indices[1]); + } + return "00"; + } +} diff --git a/src/weaver/hrm/excelimport/HrmCompany.java b/src/weaver/hrm/excelimport/HrmCompany.java new file mode 100644 index 0000000..95a4357 --- /dev/null +++ b/src/weaver/hrm/excelimport/HrmCompany.java @@ -0,0 +1,514 @@ +package weaver.hrm.excelimport; + +import com.engine.common.service.impl.HrmCommonServiceImpl; +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 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.company.DepartmentComInfo; +import weaver.hrm.company.SubCompanyComInfo; +import weaver.matrix.MatrixUtil; +import weaver.rtx.OrganisationCom; +import weaver.systeminfo.SysMaintenanceLog; +import weaver.systeminfo.SystemEnv; +import weaver.hrm.common.DbFunctionUtil; + +/** + * 分部部门信息类 + * @author lvyi + * + */ +public class HrmCompany extends BaseBean { + private RecordSet recordSet=new RecordSet(); + private OrganisationCom rtxService=new OrganisationCom();; //添加到rtx + private int id; + private String subcompanyname=""; + private String departmentname=""; + private String subcompanycode = ""; + private Float subcompanyshoworder; + private String departmentcode = ""; + private Float departmentshoworder; + private int userlanguage = 7; + private int pid; + private String operateType; + private String message = ""; + + public void setPid(int pid) { + this.pid = pid; + } + + public void setUserLanguage(String userlanguage){ + this.userlanguage = Util.getIntValue((String)userlanguage); + } + /** + * 校验数据有效性 + * @return + */ + 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 = 0; + if(Util.null2String(this.subcompanyname).length()>0){ + //取分部 + subcompanyid = getSubCompanyId(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){ + writeLog(e); + } + + return String.valueOf(flag); +} + + private boolean verifySubCompanyCode(String code) { + if (StringUtils.isEmpty(code)) return true; + RecordSet recordSet = new RecordSet(); + String sql = "select id from HrmSubCompany where subcompanycode = ?"; + recordSet.executeQuery(sql, code); + if (recordSet.getCounts() > 0) return false; + return true; + } + + private boolean verifySubCompanyCode(String code, String name, int supsubcomid) { + if (StringUtils.isEmpty(code)) return true; + RecordSet recordSet = new RecordSet(); + String sql = "select id from HrmSubCompany where ltrim(rtrim(convToMultiLang(ltrim(rtrim(subcompanyname)),"+userlanguage+"))) = ? and supsubcomid = ?"; + if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){ + sql = "select id from HrmSubCompany where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(subcompanyname)),"+userlanguage+"))) = ? 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); + if (recordSet.getCounts() > 0) return false; + return true; + } + return verifySubCompanyCode(code); + } + + private boolean verifyDeptCode(String code) { + if (StringUtils.isEmpty(code)) return true; + RecordSet recordSet = new RecordSet(); + String sql = "select id from HrmDepartment where departmentcode = ?"; + recordSet.executeQuery(sql, code); + if (recordSet.getCounts() > 0) return false; + return true; + } + + private boolean verifyDeptCode(String code, String name, int subcompanyid, int supdepid) { + if (StringUtils.isEmpty(code)) return true; + RecordSet recordSet = new RecordSet(); + String sql = "select id from HrmDepartment where ltrim(rtrim(convToMultiLang(ltrim(rtrim(departmentname)),"+userlanguage+"))) = ? and subcompanyid1 = ? and supdepid = ?"; + if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){ + sql = "select id from HrmDepartment where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(departmentname)),"+userlanguage+"))) = ? 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); + if (recordSet.getCounts() > 0) return false; + return true; + } + 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 ltrim(rtrim(convToMultiLang(ltrim(rtrim(departmentname)),"+userlanguage+")))='"+ deptNames[i].trim() + "' and supdepid=" + parentId +" and (canceled !=1 or canceled is null)"; + if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){ + sql = "select * from HrmDepartment where subcompanyid1="+ subcompanyid + " and ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(departmentname)),"+userlanguage+")))='"+ 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 ltrim(rtrim(convToMultiLang(ltrim(rtrim(departmentname)),"+userlanguage+"))) = ? and subcompanyid1 = ? and supdepid = ? and (canceled !=1 or canceled is null)"; + if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){ + sql = "update hrmdepartment set departmentcode = ? , showorder = ? where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(departmentname)),"+userlanguage+"))) = ? 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 = ""; + Float subcompanyshoworder = null; + for (int i = 0; i < subcompanynames.length; i++) { + if (StringUtils.isEmpty(subcompanynames[i])) continue; + String sql = "select * from HrmSubCompany where ltrim(rtrim(convToMultiLang(ltrim(rtrim(subcompanyname)),"+userlanguage+")))='" + + subcompanynames[i].trim() + "' and supsubcomid=" + parentId; + if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){ + sql = "select * from HrmSubCompany where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(subcompanyname)),"+userlanguage+")))='" + + 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 = Float.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 ltrim(rtrim(convToMultiLang(ltrim(rtrim(subcompanyname)),"+userlanguage+"))) = ? and supsubcomid = ?"; + if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){ + sql = "update HrmSubCompany set subcompanycode= ? , showorder = ? where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(subcompanyname)),"+userlanguage+"))) = ? and supsubcomid = ?"; + } + recordSet.executeUpdate(sql, subcompanycode, subcompanyshoworder, subcompanynames[i], parentId); + } else { + setMessage("," + subcompanycode + "编号重复"); + return -1; + } + } + parentId = currentId; + } + return currentId; + } + +/** + * 根据分部名称获取分部Id,不存在就创建 + * @param subCompanyName 分部名称 eg:泛微广东>泛微深圳 + * @return + */ +public int getSubCompanyId(String subcompanyname) { + String subcompanynames[] = subcompanyname.split(">"); + int currentId = 0; + int parentId = 0; + String sql = ""; + String sqlInsert = ""; + String subcompanycode = ""; + Float subcompanyshoworder = null; + for (int i = 0; i < subcompanynames.length; i++) { + if(subcompanynames[i] ==null && subcompanynames[i].equals("")){ + continue; + } + sql = "select id from HrmSubCompany where ltrim(rtrim(convToMultiLang(ltrim(rtrim(subcompanyname)),"+userlanguage+")))='" + + subcompanynames[i].trim() + "' and supsubcomid=" + parentId; + if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){ + sql = "select id from HrmSubCompany where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(subcompanyname)),"+userlanguage+")))='" + + subcompanynames[i].trim() + "' and supsubcomid=" + parentId; + } + + currentId = getResultSetId(sql); + + //added by wcd 2015-02-06 [限制分部数] + if (currentId == 0) { + if (i == subcompanynames.length - 1) { + // 最后一层级 赋值编码和顺序 + subcompanycode = this.subcompanycode; + subcompanyshoworder = this.subcompanyshoworder; + if (subcompanyshoworder == null) subcompanyshoworder = 0.00F; + } + if(AjaxManager.getData("", "getLnScCount;mf").equals("true")){ + // 如果编码为空 自动生成编码 + try { + subcompanycode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.SUBCOMPANY, subcompanycode); + } catch (Exception e) { + setMessage("," + e.getMessage()); + writeLog(e); + return -1; + } + sqlInsert = "insert into HrmSubCompany(subcompanyname,subcompanydesc,companyid,supsubcomid,subcompanycode,showorder,"+DbFunctionUtil.getInsertColumnSql()+") values('" + + subcompanynames[i] +"','"+subcompanynames[i]+"',1" + "," + parentId + ",'" + subcompanycode+ "'," + subcompanyshoworder + ","+DbFunctionUtil.getInsertColumnValueSql(new RecordSet().getDBType(), 1)+")"; // 创建 + boolean isSuccess = execSql(sqlInsert); + HrmTriggerUtil.generateSubcompanyPinyin(subcompanynames[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(subcompanynames[i],"12"); + } else { + currentId = -1; + } + } + parentId = currentId; + if(currentId != -1) + rtxService.addSubCompany(parentId); //同步RTX + } + return currentId; +} + +/** + * 获取部门id,不存在就创建 + * @param deptNames 部门名称 + * @param subCompanyId 所属分部id + * @return + */ +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 ltrim(rtrim(convToMultiLang(ltrim(rtrim(departmentname)),"+userlanguage+")))='"+ deptName[i].trim() + "' and supdepid=" + parentId +" and (canceled !=1 or canceled is null)"; + if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){ + sql = "select id from HrmDepartment where subcompanyid1="+ subCompanyId + " and ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(departmentname)),"+userlanguage+")))='"+ 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,String.valueOf(parentId)); + } catch (Exception e) { + setMessage("," + e.getMessage()); + 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],"12"); + rtxService.addDepartment(currentId); //同步RTX + } + parentId = currentId; + } + return currentId; +} + +/** + * 获得查询结果Id + * @param sql 查询语句 + * @return + */ +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 + * @return + */ + +public boolean execSql(String sql) { + if(recordSet.execute(sql)){ + return true; + } + else{ + return false; + } +} + +public void removeCache(){ + try{ + + MatrixUtil.sysSubcompayData(); + MatrixUtil.sysDepartmentData(); + + SubCompanyComInfo SubCompanyComInfo = new SubCompanyComInfo(); + SubCompanyComInfo.removeCompanyCache(); + + DepartmentComInfo DepartmentComInfo = new DepartmentComInfo(); + DepartmentComInfo.removeCompanyCache(); + //初始化应用分权 + new weaver.hrm.appdetach.AppDetachComInfo().initSubDepAppData(); + }catch (Exception e) { + 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 Float getSubcompanyshoworder() { + return subcompanyshoworder; + } + + public void setSubcompanyshoworder(Float 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, String operateItem) { + SysMaintenanceLog syslog = new SysMaintenanceLog(); + syslog.resetParameter(); + syslog.setRelatedId(pid); + syslog.setOperateType("-1"); + syslog.setOperateItem(operateItem); + syslog.setOperateUserid(0); + syslog.setRelatedName(name); + try { + syslog.setSysLogInfo(); + } catch (Exception e) { + writeLog(e); + } +} + +} diff --git a/src/weaver/join/hrm/in/processImpl/HrmImportProcessE9.java b/src/weaver/join/hrm/in/processImpl/HrmImportProcessE9.java new file mode 100644 index 0000000..2334864 --- /dev/null +++ b/src/weaver/join/hrm/in/processImpl/HrmImportProcessE9.java @@ -0,0 +1,2942 @@ +/** + * Title: 人员数据解析适配器 + * Company: 泛微软件 + * + * @author: 冯拥兵 + * @version: 1.0 + * create date : 2010-6-2 + * modify log: + * Description: 对人员数据Map集合进行解析,并添加到数据库 + */ + +package weaver.join.hrm.in.processImpl; +import com.engine.common.entity.EncryptFieldEntity; +import com.engine.common.service.HrmCommonService; +import com.engine.common.service.ThemeService; +import com.engine.common.service.impl.ThemeServiceImpl; +import com.engine.encrypt.biz.EncryptFieldConfigComInfo; +import com.engine.hrm.entity.RuleCodeType; +import com.engine.hrm.util.CodeRuleManager; +import com.engine.hrm.util.HrmTriggerUtil; +import com.weaver.integration.ldap.sync.oa.OaSync; +import com.weaver.integration.ldap.util.AuthenticUtil; +import org.apache.commons.lang3.StringUtils; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.reflect.Field; +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.engine.common.service.impl.HrmCommonServiceImpl; +import com.engine.hrm.util.HrmWeakPasswordUtil; +import com.engine.hrm.util.face.HrmFaceCheckManager; +import com.engine.hrm.util.face.ValidateFieldManager; +import com.engine.hrm.util.face.bean.CheckItemBean; +import weaver.encrypt.EncryptUtil; +import weaver.general.PasswordUtil; +import weaver.hrm.common.DbFunctionUtil; + +import javax.servlet.http.HttpServletRequest; + +import ln.LN; +import org.json.JSONObject; +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 weaver.common.StringUtil; +import weaver.conn.RecordSet; +import weaver.conn.RecordSetTrans; +import weaver.general.BaseBean; +import weaver.general.GCONST; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.hrm.common.database.dialect.DbDialectFactory; +import weaver.hrm.common.database.dialect.DialectUtil; +import weaver.hrm.company.DepartmentComInfo; +import weaver.hrm.company.SubCompanyComInfo; +import weaver.hrm.definedfield.HrmFieldManager; +import weaver.hrm.job.JobActivitiesComInfo; +import weaver.hrm.job.JobGroupsComInfo; +import weaver.hrm.job.JobTitlesComInfo; +import weaver.hrm.job.UseKindComInfo; +import weaver.hrm.location.LocationComInfo; +import weaver.hrm.passwordprotection.manager.HrmResourceManager; +import weaver.hrm.resource.ResourceComInfo; +import weaver.hrm.settings.ChgPasswdReminder; +import weaver.hrm.settings.RemindSettings; +import weaver.hrm.tools.HrmDateCheck; +import weaver.interfaces.hrm.HrmServiceManager; +import weaver.join.hrm.in.HrmResource; +import weaver.join.hrm.in.HrmResourceVo; +import weaver.join.hrm.in.IHrmImportProcessE9; +import weaver.join.hrm.in.ImportLog; +import weaver.matrix.MatrixUtil; +import weaver.rtx.OrganisationCom; +import weaver.rtx.OrganisationComRunnable; +import weaver.systeminfo.SystemEnv; +//import weaver.systeminfo.setting.HrmUserSettingManager; + +public class HrmImportProcessE9 extends BaseBean implements IHrmImportProcessE9 { + + //private RecordSet recordSet=new RecordSet(); + + private Map keyMap = new HashMap(); //看数据库是否有重复,将数据库现有的数据查出 + + private Map isADAccountMap = new HashMap(); + + private Map certificateNums = new HashMap();//已存在的身份证 + + Map checkInfos = new HashMap(); + + private String[] checkKeys = new String[]{"loginid","workcode"}; + + private Map baseTypeMap; //基础信息自定义字段数据库类型与字段名称映射 + + private Map personTypeMap; //个人信息自定义字段数据库类型与字段名称映射 + + private Map workTypeMap; //工作信息自定义字段数据库类型与字段名称映射 + + private String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); + + private String logFile = ""; //日志文件名 + + //private StaticObj staticObj=StaticObj.getInstance(); + + private OrganisationCom rtxService = null; //添加到rtx + + private int userlanguage = 7; //登录语言 + + char separator = Util.getSeparator(); + + LN license = new LN(); //license + + String keyField = ""; + String operateType = ""; + + private int scCount = 0; + + private HrmResourceVo vo = null; + + private String multilanguage; + + private Map sysLanguage = null; + + private Map jobcallMap = null; + private Map locationMap = null; + private Map usekindMap = null; + private Map educationlevelMap = null; + + private int cnLanguageId = 7; + + private User user; + private int pId = 0; + private int rowNum = 0; + + //是否启用初始密码:false-不启用初始密码、true-启用初始密码 + private boolean defaultPasswordEnable = false; + //初始密码 + private String defaultPassword = ""; + //弱密码禁止保存:false-允许保存弱密码、true-不允许保存弱密码 + private boolean weakPasswordDisable = false; + //判断弱密码 + private HrmWeakPasswordUtil hrmWeakPasswordUtil; + + public void setUser(User user) { + this.user = user; + } + + public Map init(HttpServletRequest request) { + Map retmap = new HashMap(); + try { + this.user = (User) request.getSession(true).getAttribute("weaver_user@bean"); + this.keyField = Util.null2String(request.getParameter("keyField")); + this.operateType = Util.null2String(request.getParameter("operateType")); + + ImportLogService importLogService = (ImportLogServiceImpl) ServiceUtil.getService(ImportLogServiceImpl.class, user); + Map params = ParamUtil.request2Map(request); + params.put("operateType", this.operateType); + retmap = importLogService.saveImportLog(params, request, user); + if (Util.null2String(retmap.get("status")).equals("1")) { + this.pId = Util.getIntValue(Util.null2String(retmap.get("pId"))); + request.getSession(true).setAttribute("hrmresourcePId", this.pId); + } + + final int F_Y = 0; + final int F_N = 1; + int type = F_N; + LN license = new LN(); + license.InLicense(); + type = StringUtil.parseToInt(license.getScType(), F_N); + scCount = StringUtil.parseToInt(license.getScCount(), 0); + scCount = type == F_Y ? (scCount < 0 ? 0 : scCount) : 0; + RecordSet recordSet = new RecordSet(); + + + String sql = "select multilanguage,(select id from syslanguage where language='简体中文' or language='中文') as cnLanguageId from license "; + recordSet.execute(sql); + recordSet.next(); + multilanguage = recordSet.getString("multilanguage"); + cnLanguageId = recordSet.getInt(2); + + sysLanguage = new HashMap(); + recordSet.execute("select id,language from syslanguage where activable=1"); + while (recordSet.next()) { + sysLanguage.put(recordSet.getString(2), recordSet.getInt(1)); + } + + educationlevelMap = new HashMap(); + + String educationName = "convToMultiLang(name,7)" ; + if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){ + educationName = "dbo.convToMultiLang(name,7)" ; + } + + + recordSet.execute(String.format("select id,%s from HrmEducationLevel",educationName)); + + while (recordSet.next()) { + educationlevelMap.put(recordSet.getString(2), recordSet.getInt(1)); + } + +// jobcallMap = new HashMap(); +// recordSet.execute("select id,name from HrmJobCall"); +// while (recordSet.next()) { +// jobcallMap.put(recordSet.getString(2), recordSet.getInt(1)); +// } +// +// locationMap = new HashMap(); +// recordSet.execute("select id,locationname from HrmLocations where countryid=1"); +// while (recordSet.next()) { +// locationMap.put(recordSet.getString(2), recordSet.getInt(1)); +// } +// +// usekindMap = new HashMap(); +// recordSet.execute("select id,name from HrmUseKind"); +// while (recordSet.next()) { +// usekindMap.put(recordSet.getString(2), recordSet.getInt(1)); +// } + + jobcallMap = new HashMap(); + if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){ + recordSet.execute("select id,dbo.convToMultiLang(name,7) from HrmJobCall"); + }else{ + recordSet.execute("select id,convToMultiLang(name,7) from HrmJobCall"); + } + while (recordSet.next()) { + jobcallMap.put(recordSet.getString(2), recordSet.getInt(1)); + } + + locationMap = new HashMap(); + if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){ + recordSet.execute("select id,dbo.convToMultiLang(locationname,7) from HrmLocations where countryid=1"); + }else{ + recordSet.execute("select id,convToMultiLang(locationname,7) from HrmLocations where countryid=1"); + } + while (recordSet.next()) { + locationMap.put(recordSet.getString(2), recordSet.getInt(1)); + } + + usekindMap = new HashMap(); + if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){ + recordSet.execute("select id,dbo.convToMultiLang(name,7) from HrmUseKind"); + }else{ + recordSet.execute("select id,convToMultiLang(name,7) from HrmUseKind"); + } + while (recordSet.next()) { + usekindMap.put(recordSet.getString(2), recordSet.getInt(1)); + } + + } catch (Exception e) { + writeLog(e); + } + return retmap; + } + + /** + * 对人员数据进行解析,并添加到数据库 + * + * @param keyField 重复性验证字段 + * @param hrMap 人员数据Map集合 + * @param operateType 导入类型 添加|更新 add|update + * @return List + */ + public void processMap(Map hrMap) {//增加同步锁,防止同时多次调用 + List resultList = new ArrayList(); //导入结果 + RecordSet recordSet = new RecordSet(); + ImportLogService importLogService = (ImportLogServiceImpl) ServiceUtil.getService(ImportLogServiceImpl.class, user); + try { + String subCompanyName = ""; //分部名称 + String departmentName = ""; //部门名称 + int subcompanyid1 = 0; // 分部Id + int departmentid = 0; // 部门id + String key = ""; // workcode_lastname 组合 + getKeyMap(keyField); //获取重复性验证字段Map + this.keyField = keyField; + int id = 0; + rtxService = new OrganisationCom(); + + final ResourceComInfo resourcecominfo = new ResourceComInfo(); + DepartmentComInfo departmentComInfo = new DepartmentComInfo(); + SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo(); + JobActivitiesComInfo jobActivitiesComInfo = new JobActivitiesComInfo(); + JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo(); + JobGroupsComInfo jobGroupsComInfo = new JobGroupsComInfo(); + LocationComInfo locationComInfo = new LocationComInfo(); + UseKindComInfo useKindComInfo = new UseKindComInfo(); + + Set keySet = hrMap.keySet(); + Object keyArray[] = keySet.toArray(); + + Class hrmClass = HrmResource.class; + Class voClass = HrmResourceVo.class; + + String field = "id,subcompanyid1,departmentid,workcode,lastname," + + "loginid,password,seclevel,sex,jobtitle,jobcall,joblevel," + + "jobactivitydesc,managerid,assistantid,status,locationid,workroom," + + "telephone,mobile,mobilecall,fax,email," + + "systemlanguage,birthday,folk,nativeplace,regresidentplace," + + "certificatenum,maritalstatus,policy,bememberdate,bepartydate," + + "islabouunion,educationlevel,degree,healthinfo,height,weight," + + "usekind,startdate,enddate,probationenddate,"//add by lvyi + + "residentplace,homeaddress,tempresidentnumber," + + "datefield1,datefield2,datefield3,datefield4,datefield5," + + "textfield1,textfield2,textfield3,textfield4,textfield5," + + "numberfield1,numberfield2,numberfield3,numberfield4,numberfield5," + + "tinyintfield1,tinyintfield2,tinyintfield3,tinyintfield4,tinyintfield5," + + "companystartdate,workstartdate," + + "accumfundaccount,accounttype,belongto,accountname,bankid1,accountid1,dsporder,classification"; + + String fields[] = field.split(","); + + int createrid = 1; // 创建者id + int lastmodid = 1; // 最后修改者id + if (user != null) { + createrid = user.getUID(); + lastmodid = user.getUID(); + } + + String createdate = date; // 创建时间 + String lastmoddate = date; // 最后修改时间 + String lastlogindate = date; // 最后登录时间 + + ChgPasswdReminder reminder = new ChgPasswdReminder(); + RemindSettings settings = reminder.getRemindSettings(); + //判断是否启用【启用初始密码】 + this.defaultPasswordEnable = Util.null2String(settings.getDefaultPasswordEnable()).equals("1"); + //初始密码 + this.defaultPassword = Util.null2String(settings.getDefaultPassword()); + //判断是否启用【弱密码禁止保存】 + this.weakPasswordDisable = Util.null2String(settings.getWeakPasswordDisable()).equals("1"); + try { + //判断是否为弱密码 + hrmWeakPasswordUtil = new HrmWeakPasswordUtil(); + } catch (Exception e) { + writeLog(e); + } + + Object obj = null; + HrmResource hrm = null; + for (int i = 0; i < keyArray.length; i++) { + obj = keyArray[i]; + vo = (HrmResourceVo) hrMap.get(obj); + key = (String) obj; + hrm = new HrmResource(); + this.rowNum++; + //TimeUnit.SECONDS.sleep(1); + try { // 异常处理 + + if (operateType.equals("add")) { + + if (keyMap.get(key) != null) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83520, userlanguage))); + continue; + } + + if(this.checkInfo(vo,resultList)){ + continue; + } + if(vo.getAccounttype() == null || "".equalsIgnoreCase(Util.null2String(vo.getAccounttype()))){ + if (StringUtil.isNotNull(vo.getCertificatenum()) && certificateNums.get(StringUtil.vString(vo.getCertificatenum())) != null) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83521, userlanguage))); + continue; + } + }else { + if (vo.getAccounttype() != null && !"".equals(vo.getAccounttype())) { + if ("主账号".equals(vo.getAccounttype())) { + if (StringUtil.isNotNull(vo.getCertificatenum()) && certificateNums.get(StringUtil.vString(vo.getCertificatenum())) != null) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83521, userlanguage))); + continue; + } + } + } + } + + //添加人员信息 license 人员上限判断 + + if (keyMap.get(key) == null && StringUtils.isNotBlank(vo.getLoginid()) + && ("主账号".equals(vo.getAccounttype()) ||StringUtils.isBlank(vo.getAccounttype())) + && "正式,试用,临时,试用延期".indexOf(Util.null2String(vo.getStatus()))>-1 ) { + license.reloadLicenseInfo(); + if (license.CkHrmnum() >= 0) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83522, userlanguage))); + continue; + } + } + // 分部Id + String subCompanyNames = vo.getSubcompanyid1(); + String tempSubCompanyName = ""; + int isCanceled = 0; + if (subCompanyNames != null) { + if (!subCompanyNames.equals(subCompanyName)) { + tempSubCompanyName = subCompanyName; + subCompanyName = subCompanyNames; + subcompanyid1 = getSubCompanyId(subCompanyName); + } + if (subcompanyid1 == -9) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getErrorMsgName(56, userlanguage))); + continue; + } + if (subcompanyid1 == -2) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(126274, userlanguage))); + continue; + } + if (subcompanyid1 == -1) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83524, userlanguage))); + continue; + } + if (StringUtil.parseToInt(license.getConcurrentFlag(), 0) != 1) { + if (new HrmResourceManager().noMore(String.valueOf(subcompanyid1))) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83525, userlanguage))); + continue; + } + } + hrm.setSubcompanyid1(new Integer(subcompanyid1)); + } else { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83526, userlanguage))); + continue; + } + + // 部门id + String departmentNames = vo.getDepartmentid(); + if (departmentNames != null) { + if (!subCompanyNames.equals(tempSubCompanyName) || !departmentNames.equals(departmentName)) { + departmentName = departmentNames; + departmentid = getDeptId(departmentName, subcompanyid1); + } + if (departmentid == -2) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(126275, userlanguage))); + continue; + } + hrm.setDepartmentid(new Integer(departmentid)); + } else { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83527, userlanguage))); + continue; + } + + if (vo.getLastname() == null) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83529, userlanguage))); + continue; + } + + //主账号id-sunjsh + if (vo.getAccounttype() != null && !"".equals(vo.getAccounttype())) { + if ("主账号".equals(vo.getAccounttype())) { + hrm.setBelongto(new Integer(-1)); + hrm.setAccounttype(new Integer(0)); + } else if ("次账号".equals(vo.getAccounttype())) { + if (vo.getBelongto() != null && !"".equals(vo.getBelongto().trim())) { + int belongto = getBelongId(vo.getBelongto(), keyField); + hrm.setBelongto(new Integer(belongto)); + if (!vo.getBelongto().equals("") && belongto == 0) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } else { + hrm.setAccounttype(new Integer(1)); + } + } else { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } + } else { + hrm.setBelongto(new Integer(-1)); + hrm.setAccounttype(new Integer(0)); + } + } else if (vo.getBelongto() != null && !"".equals(vo.getBelongto().trim())) { + int belongto = getBelongId(vo.getBelongto(), keyField); + hrm.setBelongto(new Integer(belongto)); + if (!vo.getBelongto().equals("") && belongto == 0) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } else { + hrm.setAccounttype(new Integer(1)); + } + }else { + hrm.setBelongto(new Integer(-1)); + hrm.setAccounttype(new Integer(0)); + } + + // 岗位id + if (vo.getJobtitle() != null && vo.getJobactivityid() != null && vo.getJobgroupid() != null) { + int jobtitle = getJobTitles(vo.getJobtitle(), vo + .getJobactivityid(), vo.getJobgroupid()); + hrm.setJobtitle(new Integer(jobtitle)); + } else { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83531, userlanguage))); + continue; + } + + //上级id + if (vo.getManagerid() != null) { + int managerid = 0; // 上级Id + String managerstr = ""; //所有上级 + Map managerInfo = getManagerIdAndStr("", vo.getManagerid(), keyField); + if (managerInfo != null) { + managerid = managerInfo.get("managerid") != null ? ((Integer) managerInfo.get("managerid")).intValue() : 0; + managerstr = (String) (managerInfo.get("managerstr") != null ? managerInfo.get("managerstr") : ""); + } + hrm.setManagerid(new Integer(managerid)); + hrm.setManagerstr(managerstr); + + //如果vo.getManagerid()有值,但manageid未找到,说明填写有误 + if (!vo.getManagerid().equals("") && managerid == 0) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83532, userlanguage))); + continue; + } + } else { + + hrm.setManagerid(new Integer(0)); + hrm.setManagerstr(""); + } + + // 助理id + if (vo.getAssistantid() != null) { + int assistantid = 0; + assistantid = getAssistantid(vo.getAssistantid(), keyField); + hrm.setAssistantid(new Integer(assistantid)); + if (!vo.getAssistantid().equals("") && assistantid == 0) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(24678, userlanguage))); + continue; + } + } + + // 办公地点 + if (vo.getLocationid() != null) { + int locationid = getLocationid(vo.getLocationid()); + hrm.setLocationid(new Integer(locationid)); + } else { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83533, userlanguage))); + continue; + } + + //邮箱-sunjsh + if (vo.getEmail() != null) { + if (!"".equals(vo.getEmail().trim()) && vo.getEmail().indexOf("*") > -1) { + vo.setEmail(null); + } else if("".equals(vo.getEmail().trim())){ + hrm.setEmail(""); + } else { + Pattern pattern = Pattern.compile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"); + Matcher matcher = pattern.matcher(vo.getEmail()); + if (!matcher.matches()) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(24570, userlanguage))); + continue; + } else { + hrm.setEmail(vo.getEmail()); + } + } + } + + //mobile-sunjsh + if (vo.getMobile() != null) { + if ("".equals(vo.getMobile().trim()) || (!"".equals(vo.getMobile().trim()) && vo.getMobile().indexOf("*") > -1)) + vo.setMobile(null); + }else + hrm.setMobile(""); + + //工资银行-sunjsh + if (vo.getBankid1() != null && !"".equals(vo.getBankid1())) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fieldid", 0); + jsonObject.put("fieldhtmltype", 3); + jsonObject.put("type", 284); + jsonObject.put("dmlurl", ""); + jsonObject.put("fieldvalue", vo.getBankid1()); + + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + if (!"".equals(fieldvalue)) { + hrm.setBankid1(new Integer(fieldvalue)); + } else { +// vo.setBankid1(null); + hrm.setBankid1(this.getBankId(vo.getBankid1())); + } + } + + //sunjsh-入职日期 + if(vo.getCompanystartdate() != null && !"".equals(vo.getCompanystartdate())){ + hrm.setCompanystartdate(vo.getCompanystartdate()); +// hrm.setCompanyworkyear(this.calculateDate(vo.getCompanystartdate())); + } + + //sunjsh-参加工作日期 + if(vo.getWorkstartdate() != null && !"".equals(vo.getWorkstartdate())){ + hrm.setWorkstartdate(vo.getWorkstartdate()); +// hrm.setWorkyear(this.calculateDate(vo.getWorkstartdate())); + } + // 性别,为空或其他情况统一为0(男) + String sex = "女".equals(vo.getSex()) ? "1" : "0"; + hrm.setSex(sex); + + // 职称 + if (vo.getJobcall() != null) { + int jobcall = getJobcall(vo.getJobcall()); + hrm.setJobcall(new Integer(jobcall)); + } + // 系统语言,默认简体中文 + if (vo.getSystemlanguage() != null) { + int systemlanguage = getSystemlanguage(vo.getSystemlanguage()); + + if (systemlanguage == -1) { //只能选择简体中文|Englisth|繁体中文 + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(518929, userlanguage))); + continue; + } + if (systemlanguage == 0) { //系统不支持多语言 + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(84810, userlanguage))); + continue; + } + hrm.setSystemlanguage(new Integer(systemlanguage)); + } else { + hrm.setSystemlanguage(new Integer(7)); + } + + // 婚姻状况,如果不是以下选项,则默认为未婚 + String maritalstatus = "已婚".equals(vo.getMaritalstatus()) ? "1" + : "离异".equals(vo.getMaritalstatus()) ? "2" : "0"; + hrm.setMaritalstatus(maritalstatus); + + // 员工状态 + if (!"".equals(Util.null2String(vo.getStatus()))) { + int status = getStatus(vo.getStatus()); + hrm.setStatus(new Integer(status)); + } else { + hrm.setStatus(new Integer(1)); + } + + // 人员密级 + if (!"".equals(Util.null2String(vo.getClassification()))) { + int classification = getClassification(vo.getClassification()); + hrm.setClassification(new Integer(classification)); + } + // 学历 + if (vo.getEducationlevel() != null) { + int educationlevel = getEducationlevel(vo + .getEducationlevel()); + hrm.setEducationlevel(new Integer(educationlevel)); + } + + // 工会会员,默认为是 + String islabouunion = "是".equals(vo.getIslabouunion()) ? "1" : "0"; + hrm.setIslabouunion(islabouunion); + + // 健康状况 + if (vo.getHealthinfo() != null) { + String healthinfo = getHealthinfo(vo.getHealthinfo()); + hrm.setHealthinfo(healthinfo); + } else { + hrm.setHealthinfo("0"); + } + + //安全级别不能大于999 + if (Util.getIntValue(vo.getSeclevel(), 0) > 999) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(515522, userlanguage))); + continue; + } + //安全级别不能小于-999 + if (Util.getIntValue(vo.getSeclevel(), 0) < -999) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(515523, userlanguage))); + continue; + } + //安全级别必须是数字 + if (!Util.null2String(vo.getSeclevel()).equals("")) { + if (Util.getIntValue(vo.getSeclevel(), -1000) == -1000) { + resultList.add(createLog(vo, "创建", "失败", "安全级别必须是数字")); + continue; + } else { + hrm.setSeclevel((short) Util.getIntValue(vo.getSeclevel())); + } + } else { + //安全级别为空时取缓存类中的安全级别 + hrm.setSeclevel(new Short((short) (0))); + } + + //职级 + if (isInteger(vo.getJoblevel())) { + int joblevel = vo.getJoblevel().equals("") ? 0 : Integer.parseInt(vo.getJoblevel()); + hrm.setJoblevel(new Short((short) joblevel)); + } else { + hrm.setJoblevel(new Short((short) 0)); + } + //用工性质 + if (vo.getUsekind() != null) { + int usekind = getUseKind(vo.getUsekind()); + hrm.setUsekind(usekind); + } else { + hrm.setUsekind(0); + } + //如果新增导入的时候,登陆名不为空,需要校验一下当前的license + + + // 手机 办公电话 + CheckItemBean mobileBean = new CheckItemBean("mobile",vo.getMobile()) ; + ValidateFieldManager.validate(mobileBean); + if(!mobileBean.isPass()){ + resultList.add(createLog(vo,"创建","失败",mobileBean.getCheckMsg())) ; + continue; + } + CheckItemBean telephoneBean = new CheckItemBean("telephone",vo.getTelephone()) ; + ValidateFieldManager.validate(telephoneBean); + if(!telephoneBean.isPass()){ + resultList.add(createLog(vo,"创建","失败",telephoneBean.getCheckMsg())) ; + continue; + } + + + //id,非自动增长 + recordSet.executeProc("HrmResourceMaxId_Get", ""); + recordSet.next(); + id = recordSet.getInt(1); + hrm.setId(new Integer(id)); + + + //密码 加密 + String password_tmp = Util.null2String(vo.getPassword()).trim(); + if ("".equals(password_tmp)) { + password_tmp = "1"; + //人员导入文件中,将密码这一列删除或者密码这一列存在,但是不填写都默认为初始密码 + if (this.defaultPasswordEnable) { + if (!this.defaultPassword.equals("")) { + if (this.weakPasswordDisable && this.hrmWeakPasswordUtil.isWeakPsd(this.defaultPassword)) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(515436, userlanguage))); + continue; + } else { + password_tmp = this.defaultPassword; + } + } else { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(516347, userlanguage))); + continue; + } + } + } + + String[] encrypts = PasswordUtil.encrypt(password_tmp); + String password = encrypts[0]; + String salt = encrypts[1]; + hrm.setPassword(password); + + boolean flag = true; + + /*添加人员信息*/ + String insertStr = "insert into hrmResource("; + String insertFields = ""; + String insertValues = ""; + + String workcode = vo.getWorkcode(); + workcode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.USER, String.valueOf(hrm.getSubcompanyid1()), String.valueOf(hrm.getDepartmentid()), String.valueOf(hrm.getJobtitle()), workcode); + vo.setWorkcode(workcode); + vo.setMobile(translateToPlainStr(vo.getMobile())); + vo.setCertificatenum(translateToPlainStr(vo.getCertificatenum())); + + for (int k = 0; k < fields.length; k++) { + Field hrmField = hrmClass.getDeclaredField(fields[k]); + Field voField = voClass.getDeclaredField(fields[k]); + + String hrmFieldType = hrmField.getType().getName(); + String voFieldType = voField.getType().getName(); + + hrmField.setAccessible(true); + voField.setAccessible(true); + + //首先取hrm对象中的数据,没有去vo中的 + if (hrmField.get(hrm) != null) { + if (hrmFieldType.endsWith("String")) { + insertFields = insertFields + fields[k] + ","; + insertValues = insertValues + "'" + hrmField.get(hrm) + "',"; + } else if (hrmFieldType.endsWith("Integer") || hrmFieldType.endsWith("Short") || hrmFieldType.endsWith("Float")) { + insertFields = insertFields + fields[k] + ","; + String insertValueStr = Util.null2String(hrmField.get(hrm)); + if("".equals(insertValueStr) && recordSet.getDBType().equalsIgnoreCase("postgresql")){ + insertValues = insertValues + "null,"; + }else{ + insertValues = insertValues + "" + hrmField.get(hrm) + ","; + } + } + } else if (voField.get(vo) != null) { + if (voFieldType.endsWith("String")) { + if (recordSet.getDBType().equalsIgnoreCase("mysql") || recordSet.getDBType().equalsIgnoreCase("postgresql")) { + if (Util.null2String(voField.get(vo)).equals("")) { + insertFields = insertFields + fields[k] + ","; + insertValues = insertValues + "null,"; + } else { + insertFields = insertFields + fields[k] + ","; + insertValues = insertValues + "'" + voField.get(vo) + "',"; + } + } else { + insertFields = insertFields + fields[k] + ","; + insertValues = insertValues + "'" + voField.get(vo) + "',"; + } + } else if (hrmFieldType.endsWith("Integer") || hrmFieldType.endsWith("Short") || hrmFieldType.endsWith("Float")) { + insertFields = insertFields + fields[k] + ","; + String insertValueStr = Util.null2String(voField.get(vo)); + if("".equals(insertValueStr) && recordSet.getDBType().equalsIgnoreCase("postgresql")){ + insertValues = insertValues + "null,"; + }else{ + insertValues = insertValues + "" + voField.get(vo) + ","; + } + + } + } + } + ChgPasswdReminder cpr = new ChgPasswdReminder(); + RemindSettings hrmsettings = cpr.getRemindSettings(); + insertStr = insertStr + insertFields + "createrid,createdate,lastmodid,lastmoddate,lastlogindate,managerstr,mobileshowtype ," + DbFunctionUtil.getInsertColumnSql() + ") values(" + + insertValues + createrid + ",'" + createdate + "'," + lastmodid + ",'" + lastmoddate + "','" + lastlogindate + "','" + hrm.getManagerstr() + "'," + Util.getIntValue(hrmsettings.getMobileShowTypeDefault(), 0) + " ," + DbFunctionUtil.getInsertColumnValueSql(recordSet.getDBType(), lastmodid) + ")"; + + + boolean resourceInsertFlag = true; + if (!execSql(insertStr)) {//添加人员信息 + flag = false; + resourceInsertFlag = false; + } + if (resourceInsertFlag) {// 仅当人员插入成功后才进行自定义字段操作 + PasswordUtil.updateResourceSalt(id + "", salt); + + if (!updateBaseData(vo.getBaseFields(), vo.getBaseFieldsValue(), id)) //添加基础字段信息 + flag = false; + if (!updatePersonData(vo.getPersonFields(), vo.getPersonFieldsValue(), id)) //添加个人字段信息 + flag = false; + if (!updateWorkData(vo.getWorkFields(), vo.getWorkFieldsValue(), id)) //添加工作字段信息 + flag = false; + } + + /*添加人员缓存,人员默认按id显示顺序,HrmResource_Trigger_Insert 人员共享 入职维护项目状态*/ + if (flag) { + try{ + //登录信息签名 + PasswordUtil.saveSign(""+id); + }catch (Exception e){ + writeLog(e); + } + //HrmUserSettingManager.checkUserSettingInit(id) ; + HrmFaceCheckManager.setUserPassowrd(id+"",password_tmp); + //人员显示顺序 + if(vo.getDsporder() == null) { + String taxissql = ("update HrmResource set dsporder = " + id + " where id = " + id); + recordSet.executeSql(taxissql); + } + //构建pinyin快速搜索 + if(vo.getLastname() != null){ + String quickSearchStr = new HrmCommonServiceImpl().generateQuickSearchStr(vo.getLastname()); + String sqlStr = "update HrmResource set pinyinlastname = ?, ecology_pinyin_search = ? where id = ?"; + recordSet.executeUpdate(sqlStr, quickSearchStr, quickSearchStr, id); + } + + //触发器 + String para = "" + id + separator + hrm.getManagerid() + separator + hrm.getDepartmentid() + separator + hrm.getSubcompanyid1() + separator + hrm.getSeclevel() + separator + hrm.getManagerstr(); + recordSet.executeProc("HrmResource_Trigger_Insert", para); + + //共享信息 + /*String p_para = "" + id + separator + hrm.getDepartmentid() + separator + hrm.getSubcompanyid1() + separator + hrm.getManagerid() + separator + hrm.getSeclevel() + separator + hrm.getManagerstr() + separator + "0" + separator + "0" + separator + "0" + separator + "0" + separator + "0" + separator + "0"; + recordSet.executeProc("HrmResourceShare", p_para);*/ + + //入职维护状态 + String sql_1 = ("insert into HrmInfoStatus (itemid,hrmid,status) values(1," + id + ",1)"); + recordSet.executeSql(sql_1); + String sql_2 = ("insert into HrmInfoStatus (itemid,hrmid) values(2," + id + ")"); + recordSet.executeSql(sql_2); + String sql_3 = ("insert into HrmInfoStatus (itemid,hrmid) values(3," + id + ")"); + recordSet.executeSql(sql_3); + + String sql_10 = ("insert into HrmInfoStatus (itemid,hrmid) values(10," + id + ")"); + recordSet.executeSql(sql_10); + + new Thread(new OrganisationComRunnable("user", "add", "" + id)).start(); + HrmFaceCheckManager.sync(id+"",HrmFaceCheckManager.getOptInsert(),"hrm_e9_import_resource",HrmFaceCheckManager.getOaResource()); + + new HrmDateCheck().calWorkInfo(""+id); + + } + + /*写日志*/ + if (flag) { + resultList.add(createLog(vo, "创建", "成功", "")); + if (!"".equals(vo.getLoginid())) { + rtxService.addUser(id);//添加到rtx + } + } else { + resultList.add(createLog(vo, "创建", "失败", "系统错误,请联系管理员")); + } + + } else { //更新人员 + if (keyMap.get(key) == null) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83535, userlanguage))); + continue; + } + + vo.setId(Util.getIntValue(keyMap.get(key)));//设置id + if(this.checkInfo(vo,resultList)){ + continue; + } + + if(vo.getAccounttype() == null || "".equalsIgnoreCase(Util.null2String(vo.getAccounttype()))){ + if (StringUtil.isNotNull(vo.getCertificatenum()) && certificateNums.get(StringUtil.vString(vo.getCertificatenum())) != null) { + if (StringUtil.parseToInt(String.valueOf(keyMap.get(key))) != StringUtil.parseToInt(String.valueOf(certificateNums.get(StringUtil.vString(vo.getCertificatenum()))))) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83521, userlanguage))); + continue; + } + } + }else { + if (vo.getAccounttype() != null && !"".equals(vo.getAccounttype())) { + if ("主账号".equals(vo.getAccounttype())) { + if (StringUtil.isNotNull(vo.getCertificatenum()) && certificateNums.get(StringUtil.vString(vo.getCertificatenum())) != null) { + if (StringUtil.parseToInt(String.valueOf(keyMap.get(key))) != StringUtil.parseToInt(String.valueOf(certificateNums.get(StringUtil.vString(vo.getCertificatenum()))))) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83521, userlanguage))); + continue; + } + } + } + } + } + + final String hrmId = String.valueOf(keyMap.get(key)); + + //分部id + String subCompanyNames = vo.getSubcompanyid1(); + boolean issameSub = true; + if (!"".equals(Util.null2String(subCompanyNames))) { + if (!subCompanyNames.equals(subCompanyName)) { + subCompanyName = subCompanyNames; + subcompanyid1 = getSubCompanyId(subCompanyName); + issameSub = false; + + } + + if (subcompanyid1 == -9) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getErrorMsgName(56, userlanguage))); + continue; + } + if (subcompanyid1 == -2) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(126274, userlanguage))); + continue; + } + if (subcompanyid1 == 0 || subcompanyid1 == -1) { + resultList.add(createLog(vo, "更新", "失败", subcompanyid1 == 0 ? SystemEnv.getHtmlLabelName(83536, userlanguage) : SystemEnv.getHtmlLabelName(83524, userlanguage))); + continue; + } + + //qc139575 在验证并发非并发之前需要先CkHrmnum + license.CkHrmnum(); + if (StringUtil.parseToInt(license.getConcurrentFlag(), 0) != 1) { + if (!issameSub && new HrmResourceManager().noMore(String.valueOf(subcompanyid1))) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83525, userlanguage))); + continue; + } + } + hrm.setSubcompanyid1(new Integer(subcompanyid1)); + } else { + +// String subCompanyID = resourcecominfo.getSubCompanyID(hrmId); +// +// int intSubcompanyid1 = new Integer(Integer.parseInt(subCompanyID)); +// if (intSubcompanyid1 == -9) { +// resultList.add(createLog(vo, "更新", "失败", SystemEnv.getErrorMsgName(56, userlanguage))); +// continue; +// } +// +// if (intSubcompanyid1 == -2) { +// resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(126274, userlanguage))); +// continue; +// } +// +// if (intSubcompanyid1 == 0 || intSubcompanyid1 == -1) { +// resultList.add(createLog(vo, "更新", "失败", intSubcompanyid1 == 0 ? SystemEnv.getHtmlLabelName(83536, userlanguage) : SystemEnv.getHtmlLabelName(83524, userlanguage))); +// continue; +// } +// +// hrm.setSubcompanyid1(intSubcompanyid1); +// +// +// String subIdStr = subCompanyComInfo.getAllSupCompany(subCompanyID); +// subCompanyNames = ""; +// if (!subIdStr.equals("")) { +// String subIds[] = subIdStr.split(","); +// for (int n = 0; n < subIds.length; n++) +// subCompanyNames = subCompanyNames + subCompanyComInfo.getSubCompanyname(subIds[n]) + ">"; +// } +// vo.setSubcompanyid1(subCompanyNames + subCompanyComInfo.getSubCompanyname(subCompanyID)); + + } + + // 部门id + String departmentNames = vo.getDepartmentid(); + if (!"".equals(Util.null2String(departmentNames))) { //部门存在时 + if (!issameSub || !departmentNames.equals(departmentName)) { + departmentName = departmentNames; + departmentid = getDeptId(departmentName, subcompanyid1); + + if (departmentid == 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83537, userlanguage))); + continue; + } + if (departmentid == -2) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(126275, userlanguage))); + continue; + } + } else { //add sjh 50102需要考虑不同公司名称相同部门架构情况 此时部门ID是不同的 + departmentid = getDeptId(departmentName, subcompanyid1); + if (departmentid == 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83537, userlanguage))); + continue; + } + if (departmentid == -2) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(126275, userlanguage))); + continue; + } + } + hrm.setDepartmentid(new Integer(departmentid)); + } else { //部门不存在 + +// String departmentID = resourcecominfo.getDepartmentID(hrmId); +// hrm.setDepartmentid(new Integer(Integer.parseInt(departmentID))); +// departmentNames = ""; +// String supdeptid = departmentComInfo.getDepartmentsupdepid(departmentID); +// while (!supdeptid.equals("")) { +// departmentNames = departmentNames + departmentComInfo.getDepartmentname(supdeptid) + ","; +// supdeptid = departmentComInfo.getDepartmentsupdepid(supdeptid); +// } +// String deptNamesArray[] = departmentNames.split(","); +// departmentNames = ""; +// for (int n = deptNamesArray.length - 1; n >= 0; n--) { +// departmentNames = departmentNames + deptNamesArray[n] + ">"; +// } +// departmentNames = departmentNames + departmentComInfo.getDepartmentname(departmentID); +// vo.setDepartmentid(departmentNames); + } + + //主账号id-sunjsh + if (vo.getAccounttype() != null && !"".equals(vo.getAccounttype())) { + if ("主账号".equals(vo.getAccounttype())) { + hrm.setBelongto(new Integer(-1)); + hrm.setAccounttype(new Integer(0)); + } else if ("次账号".equals(vo.getAccounttype())) { + if (vo.getBelongto() != null && !"".equals(vo.getBelongto().trim())) { + int belongto = getBelongId(vo.getBelongto(), keyField); + hrm.setBelongto(new Integer(belongto)); + if (!vo.getBelongto().equals("") && belongto == 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } else { + hrm.setAccounttype(new Integer(1)); + } + } else { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } + } else { + hrm.setBelongto(new Integer(-1)); + hrm.setAccounttype(new Integer(0)); + } + } else if (vo.getBelongto() != null && !"".equals(vo.getBelongto().trim())) { + int belongto = getBelongId(vo.getBelongto(), keyField); + hrm.setBelongto(new Integer(belongto)); + if (!vo.getBelongto().equals("") && belongto == 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } else { + hrm.setAccounttype(new Integer(1)); + } + } + + // 岗位id + if ("".equals(Util.null2String(vo.getJobtitle())) && (!"".equals(Util.null2String(vo.getJobactivityid())) || !"".equals(Util.null2String(vo.getJobgroupid())))) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83544, userlanguage))); + continue; + } + if (!"".equals(Util.null2String(vo.getJobtitle()))) { + String jobtitle = ""; + String jobactivityid = ""; + String jobactivityname = ""; + String jobgroupid = ""; + String jobgroupname = ""; + if (vo.getJobactivityid() == null) { + jobtitle = resourcecominfo.getJobTitle(hrmId); + jobactivityid = jobTitlesComInfo.getJobactivityid(jobtitle); + jobactivityname = jobActivitiesComInfo.getJobActivitiesname(jobactivityid); + } else + jobactivityname = vo.getJobactivityid(); + if (vo.getJobgroupid() == null) { + jobtitle = resourcecominfo.getJobTitle(hrmId); + jobactivityid = jobTitlesComInfo.getJobactivityid(jobtitle); + jobgroupid = jobActivitiesComInfo.getJobgroupid(jobactivityid); + jobgroupname = jobGroupsComInfo.getJobGroupsname(jobgroupid); + } else { + jobgroupname = vo.getJobgroupid(); + } + int jobtitleid = getJobTitles(vo.getJobtitle(), jobactivityname, jobgroupname); + hrm.setJobtitle(new Integer(jobtitleid)); + } + + if(Util.getIntValue(hrmId)<0)continue; + + //上级id + String managerstr = ""; //所有上级 + String oldmanagerstr = resourcecominfo.getManagersIDs(hrmId);//原来的所有上sex + // 级序列 + if (!"".equals(Util.null2String(vo.getManagerid()))) { + int managerid = 0; // 上级Id + + Map managerInfo = getManagerIdAndStr(hrmId, vo.getManagerid(), keyField); + if (managerInfo != null) { + managerid = managerInfo.get("managerid") != null ? ((Integer) managerInfo.get("managerid")).intValue() : 0; + managerstr = (String) (managerInfo.get("managerstr") != null ? managerInfo.get("managerstr") : ""); + } + + //如果vo.getManagerid()有值,但manageid未找到,说明填写有误 + if (vo.getManagerid() != null && !vo.getManagerid().equals("") && managerid == 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83532, userlanguage))); + continue; + } + hrm.setManagerid(new Integer(managerid)); + hrm.setManagerstr(managerstr); + } else { + if (vo.getManagerid() == null) { + hrm.setManagerid(new Integer(StringUtil.parseToInt(resourcecominfo.getManagerID(hrmId), 0))); + hrm.setManagerstr(resourcecominfo.getManagersIDs(hrmId)); + managerstr = resourcecominfo.getManagersIDs(hrmId); + vo.setManagerid(resourcecominfo.getManagerID(hrmId)); + } else { + hrm.setManagerid(new Integer(0)); + hrm.setManagerstr(""); + } + } + // 助理id + if (!"".equals(Util.null2String(vo.getAssistantid()))) { + int assistantid = 0; + assistantid = getAssistantid(vo.getAssistantid(), keyField); + if (vo.getAssistantid() != null && !vo.getAssistantid().equals("") && assistantid == 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(24678, userlanguage))); + continue; + } + hrm.setAssistantid(new Integer(assistantid)); + } + // 办公地点 + if (!"".equals(Util.null2String(vo.getLocationid()))) { + int locationid = getLocationid(vo.getLocationid()); + hrm.setLocationid(new Integer(locationid)); + } + + //邮箱-sunjsh + if (vo.getEmail() != null) { + if (!"".equals(vo.getEmail().trim()) && vo.getEmail().indexOf("*") > -1) { + vo.setEmail(null); + } else if("".equals(vo.getEmail().trim())){ + hrm.setEmail(""); + } else { + Pattern pattern = Pattern.compile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"); + Matcher matcher = pattern.matcher(vo.getEmail()); + if (!matcher.matches()) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(24570, userlanguage))); + continue; + } else { + hrm.setEmail(vo.getEmail()); + } + } + } + + //mobile-sunjsh + if (vo.getMobile() != null) { + if("".equals(vo.getMobile().trim())) + hrm.setMobile(""); + else if (!"".equals(vo.getMobile().trim()) && vo.getMobile().indexOf("*") > -1) + vo.setMobile(null); + } + + //工资银行-sunjsh + if (vo.getBankid1() != null && !"".equals(vo.getBankid1())) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fieldid", 0); + jsonObject.put("fieldhtmltype", 3); + jsonObject.put("type", 284); + jsonObject.put("dmlurl", ""); + jsonObject.put("fieldvalue", vo.getBankid1()); + + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + if (!"".equals(fieldvalue)) { + hrm.setBankid1(new Integer(fieldvalue)); + } else { +// vo.setBankid1(null); + hrm.setBankid1(this.getBankId(vo.getBankid1())); + } + } + + //sunjsh-入职日期 + if(vo.getCompanystartdate() != null && !"".equals(vo.getCompanystartdate())){ + hrm.setCompanystartdate(vo.getCompanystartdate()); +// hrm.setCompanyworkyear(this.calculateDate(vo.getCompanystartdate())); + }else{ + vo.setCompanystartdate(null); + } + + //sunjsh-参加工作日期 + if(vo.getWorkstartdate() != null && !"".equals(vo.getWorkstartdate())){ + hrm.setWorkstartdate(vo.getWorkstartdate()); +// hrm.setWorkyear(this.calculateDate(vo.getWorkstartdate())); + }else{ + vo.setWorkstartdate(null); + } + // 职称 + if (!"".equals(Util.null2String(vo.getJobcall()))) { + int jobcall = getJobcall(vo.getJobcall()); + hrm.setJobcall(new Integer(jobcall)); + } + // 系统语言,默认简体中文 + if (!"".equals(Util.null2String(vo.getSystemlanguage()))) { + int systemlanguage = getSystemlanguage(vo.getSystemlanguage()); + + if (systemlanguage == -1) { //只能选择简体中文|Englisth|繁体中文 + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(518929, userlanguage))); + continue; + } + //系统不支持多语言 + if (systemlanguage == 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(84810, userlanguage))); + continue; + } + hrm.setSystemlanguage(new Integer(systemlanguage)); + } + + // 性别,为空或其他情况统一为0(男) + if(vo.getSex() == null){ + + }else if (!"".equals(Util.null2String(vo.getSex()))) { + String sex = vo.getSex().equals("女") ? "1" : "0"; + hrm.setSex(sex); + } + + // 婚姻状况,如果不是以下选项,则默认为未婚 + if (!"".equals(Util.null2String(vo.getMaritalstatus()))) { + String maritalstatus = vo.getMaritalstatus().equals("已婚") ? "1" + : vo.getMaritalstatus().equals("离异") ? "2" : "0"; + hrm.setMaritalstatus(maritalstatus); + } + + // 员工状态 + if (!"".equals(Util.null2String(vo.getStatus()))) { + int status = getStatus(vo.getStatus()); + hrm.setStatus(new Integer(status)); + }else{ +// hrm.setStatus(new Integer(0)); + } + + // 人员密级 + if (!"".equals(Util.null2String(vo.getClassification()))) { + int classification = getClassification(vo.getClassification()); + hrm.setClassification(new Integer(classification)); + } + + // 学历 + if (!"".equals(Util.null2String(vo.getEducationlevel()))) { + int educationlevel = getEducationlevel(vo + .getEducationlevel()); + hrm.setEducationlevel(new Integer(educationlevel)); + } + + // 工会会员,默认为是 + if (!"".equals(Util.null2String(vo.getIslabouunion()))) { + String islabouunion = vo.getIslabouunion().equals("是") ? "1" + : "0"; + hrm.setIslabouunion(islabouunion); + } + + // 健康状况 + if (!"".equals(Util.null2String(vo.getHealthinfo()))) { + String healthinfo = getHealthinfo(vo.getHealthinfo()); + hrm.setHealthinfo(healthinfo); + } + + //安全级别不能大于999 + if (Util.getIntValue(vo.getSeclevel(), 0) > 999) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(515522, userlanguage))); + continue; + } + //安全级别不能小于-999 + if (Util.getIntValue(vo.getSeclevel(), 0) < -999) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(515523, userlanguage))); + continue; + } + //安全级别必须是数字 + if (!Util.null2String(vo.getSeclevel()).equals("")) { + if (Util.getIntValue(vo.getSeclevel(), -1000) == -1000) { + resultList.add(createLog(vo, "更新", "失败", "安全级别必须是数字")); + continue; + } else { + hrm.setSeclevel((short) Util.getIntValue(vo.getSeclevel())); + } + } else { + //安全级别为空时取缓存类中的安全级别 + hrm.setSeclevel(new Short(Short.parseShort(resourcecominfo.getSeclevel(hrmId)))); + } + + //职级 + if (isInteger(vo.getJoblevel())) { + int joblevel = vo.getJoblevel().equals("") ? 0 : Integer.parseInt(vo.getJoblevel()); + hrm.setJoblevel(new Short((short) joblevel)); + } + + //用工性质 + if (vo.getUsekind() != null) { + int usekind = getUseKind(vo.getUsekind()); + hrm.setUsekind(usekind); + } + + + //更新导入的时候,如果登录名不为空,需要校验一下当前的license + String acoutttypeOfOld = resourcecominfo.getAccountType(hrmId) ; + String oldLoginid = resourcecominfo.getLoginID(hrmId) ; + if(needCheckLicenseForUpdate(resourcecominfo,hrmId,vo)){ + license.reloadLicenseInfo(); + if (license.CkHrmnum() >= 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83522, userlanguage))); + continue; + } + } + + // 手机 办公电话 + CheckItemBean mobileBean = new CheckItemBean("mobile",vo.getMobile()) ; + ValidateFieldManager.validate(mobileBean); + if(!mobileBean.isPass()){ + resultList.add(createLog(vo,"更新","失败",mobileBean.getCheckMsg())) ; + continue; + } + CheckItemBean telephoneBean = new CheckItemBean("telephone",vo.getTelephone()) ; + ValidateFieldManager.validate(telephoneBean); + if(!telephoneBean.isPass()){ + resultList.add(createLog(vo,"更新","失败",telephoneBean.getCheckMsg())) ; + continue; + } + + + //密码 加密 + if (!"".equals(Util.null2String(vo.getPassword()))) { + + String orgPwd = "1"; + if (!"".equals(vo.getPassword())) orgPwd = vo.getPassword(); + String[] pwdArr = PasswordUtil.encrypt(orgPwd); + String salt = pwdArr[1]; + hrm.setPassword(pwdArr[0]); + + PasswordUtil.updateResourceSalt(keyMap.get(key) + "", salt); + HrmFaceCheckManager.setUserPassowrd(keyMap.get(key) + "",orgPwd); + + } + boolean flag = true; + + String updateStr = "update hrmresource set "; + + String tmpstatus = ""; + //k从1开始,id不是update字段 +// String workcode = vo.getWorkcode(); +// workcode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.USER, String.valueOf(hrm.getSubcompanyid1()), String.valueOf(hrm.getDepartmentid()), String.valueOf(hrm.getJobtitle()), workcode); +// vo.setWorkcode(workcode); + for (int k = 1; k < fields.length; k++) { + Field hrmField = hrmClass.getDeclaredField(fields[k]); + Field voField = voClass.getDeclaredField(fields[k]); + + String hrmFieldType = hrmField.getType().getName(); + String voFieldType = voField.getType().getName(); + vo.setMobile(translateToPlainStr(vo.getMobile())); + vo.setCertificatenum(translateToPlainStr(vo.getCertificatenum())); + + hrmField.setAccessible(true); + voField.setAccessible(true); + + if (Util.null2String(hrmField.get(hrm)).trim().length()>0) { + if (hrmFieldType.endsWith("String")) + updateStr = updateStr + fields[k] + "='" + hrmField.get(hrm) + "',"; + else if (hrmFieldType.endsWith("Integer") || hrmFieldType.endsWith("Short") || hrmFieldType.endsWith("Float")) + if(hrmField.get(hrm).equals(new Integer(0)) && false){ + //0数据的这个临时改回去 + + }else { + updateStr = updateStr + fields[k] + "=" + hrmField.get(hrm) + ","; + } + if (fields[k].equals("status")) tmpstatus = Util.null2String(hrmField.get(hrm)); + } else if (Util.null2String(voField.get(vo)).trim().length()>0) { + if (voFieldType.endsWith("String")) { + if (recordSet.getDBType().equalsIgnoreCase("mysql") || recordSet.getDBType().equalsIgnoreCase("postgresql")) { + if (Util.null2String(voField.get(vo)).equals("")) { + updateStr = updateStr + fields[k] + "=null,"; + } else { + updateStr = updateStr + fields[k] + "='" + voField.get(vo) + "',"; + } + } else { + updateStr = updateStr + fields[k] + "='" + voField.get(vo) + "',"; + } + } else if (voFieldType.endsWith("Integer") || voFieldType.endsWith("Short") || voFieldType.endsWith("Float")) { + if(voField.get(vo).equals(new Integer(0)) && false){ + + }else{ + if(voFieldType.endsWith("Integer") && (voField.get(vo).equals(new Integer(0x7fffffff)))) + { + updateStr = updateStr + fields[k] + "=null,"; + }else{ + updateStr = updateStr + fields[k] + "=" + voField.get(vo) + ","; + } + } + } + if (fields[k].equals("status")) tmpstatus = Util.null2String(voField.get(vo)); + } + } + + updateStr = updateStr + " lastmodid=" + lastmodid + ",lastmoddate='" + lastmoddate + "',managerstr='" + hrm.getManagerstr() + "'," + DbFunctionUtil.getUpdateSetSql(new RecordSet().getDBType(), lastmodid) + " where id=" + keyMap.get(key); + + if (!execSql(updateStr)) + flag = false; + + //同步密码到AD + if(flag && !"".equals(Util.null2String(vo.getPassword()))){ + String userid = Util.null2String(keyMap.get(key)); + String loginid = Util.null2String(resourcecominfo.getLoginID(userid)); + String isADAccount = Util.null2String(isADAccountMap.get(userid)); + try { + if ("1".equals(isADAccount)&& !"1".equals(userid) && new AuthenticUtil().checkType(loginid)) { + Map map = new HashMap<>(); + map.put("userid", userid);//OA人员id + map.put("loginid", loginid);//人员帐号 + map.put("password", Util.null2String(vo.getPassword()));//新密码 + map.put("issysadmin", "true");//是否需要检验旧密码。0,是检验。1,不需要检验。 + String optype="4"; //1,强制修改密码操作。2,首次登录密码操作,3,忘记密码找回。其它,系统修改ad操作。 + map.put("optype", optype); + Map retInfo = new OaSync("", "").modifyADPWDNew(map); + if (Util.null2String(retInfo.get("code")).equals("0")){ + //更新修改密码时间 + String passwdchgdate = Util.null2String(TimeUtil.getCurrentDateString()); + flag = recordSet.executeUpdate("update hrmresource set passwdchgdate=?, haschangepwd='y' where id = ?", passwdchgdate, userid); + } else { + //flag = false; + writeLog("人员导入,更新人员密码,同步至AD失败___retInfo___"+ com.alibaba.fastjson.JSONObject.toJSONString(retInfo)); + } + } + } catch (Exception e) { + writeLog(e); + } + } + + //如果更新为解聘、离职、退休,处理相关数据 + if (("4".equals(tmpstatus) || "5".equals(tmpstatus) || "6".equals(tmpstatus)) && !tmpstatus.equals(resourcecominfo.getStatus("" + keyMap.get(key)))) { + OrganisationCom orgCom = new OrganisationCom(); + HrmServiceManager hrmaction = new HrmServiceManager(); + String tmpid = ""; + String type = "5"; + String procType = "HrmResource_Dismiss"; + String statusType = "5"; + if ("4".equals(tmpstatus)) { + type = "1"; + procType = "HrmResource_Fire"; + statusType = "4"; + } else if ("6".equals(tmpstatus)) { + type = "6"; + procType = "HrmResource_Retire"; + statusType = "6"; + } + int resourceid = keyMap.get(key); + String changedate = TimeUtil.getCurrentDateString(); + String changereason = SystemEnv.getHtmlLabelName(17887, userlanguage); + String changecontractid = ""; + String infoman = ""; + String oldjobtitleid = resourcecominfo.getJobTitle("" + resourceid); + String para = "" + resourceid + separator + changedate + separator + changereason + separator + changecontractid + separator + infoman + separator + oldjobtitleid + separator + type + separator + "1"; + recordSet.executeProc(procType, para); + recordSet.executeSql("select max(id) from HrmStatusHistory"); + recordSet.next(); + tmpid = recordSet.getString(1); + + //删除角色成员 + recordSet.executeSql("delete from hrmrolemembers where resourcetype =1 and resourceid=" + resourceid); + //删除手机版中设置的登录人员 + recordSet.executeSql("delete from PluginLicenseUser where plugintype='mobile' and sharetype='0' and sharevalue='" + resourceid + "'"); + //更新人员未离职,清空账号 + recordSet.executeSql("update HrmResource set status = " + statusType + " ,loginid='',password='',account='', tokenkey='', lastmoddate='" + changedate + "' where id = " + resourceid); + //删除自定义组成员 + recordSet.executeSql("delete hrmgroupmembers where userid=" + resourceid); + //更新变更记录状态为已处理 + recordSet.executeSql("update HrmStatusHistory set isdispose = 1 where id=" + tmpid); + boolean exist = orgCom.checkUser(resourceid); + if (exist) { + orgCom.deleteUser2(resourceid); + } + //OA与第三方接口单条数据同步方法开始 + hrmaction.SynInstantHrmResource("" + resourceid, "3"); + //OA与第三方接口单条数据同步方法结束 + + try{ + //离职注销发票云 + HrmCommonService hcs = new HrmCommonServiceImpl(); + hcs.unbindInvoiceCloud(resourceid); + }catch (Exception e){ + writeLog(e); + } + } + + if (!updateBaseData(vo.getBaseFields(), vo.getBaseFieldsValue().trim(), ((Integer) keyMap.get(key)).intValue())) + flag = false; + + if (!updatePersonData(vo.getPersonFields(), vo.getPersonFieldsValue().trim(), ((Integer) keyMap.get(key)).intValue())) + flag = false; + + if (!updateWorkData(vo.getWorkFields().trim(), vo.getWorkFieldsValue(), ((Integer) keyMap.get(key)).intValue())) + flag = false; + + /*update HrmResource_Trigger */ + if (flag) { + recordSet.executeSql("select id from HrmResource_Trigger where id=" + hrmId); + if (recordSet.next()) { + recordSet.executeSql("update HrmResource_Trigger set managerid=" + hrm.getManagerid() + ",departmentid=" + hrm.getDepartmentid() + ",subcompanyid1=" + hrm.getSubcompanyid1() + ",seclevel=" + hrm.getSeclevel() + ",managerstr='" + hrm.getManagerstr() + "' where id=" + hrmId); + } else { + String para = "" + hrmId + separator + hrm.getManagerid() + separator + hrm.getDepartmentid() + separator + hrm.getSubcompanyid1() + separator + hrm.getSeclevel() + separator + hrm.getManagerstr(); + recordSet.executeProc("HrmResource_Trigger_Insert", para); + } + + //构建pinyin快速搜索 + if(vo.getLastname() != null){ + String quickSearchStr = new HrmCommonServiceImpl().generateQuickSearchStr(vo.getLastname()); + String sqlStr = "update HrmResource set pinyinlastname = ?, ecology_pinyin_search = ? where id = ?"; + recordSet.executeUpdate(sqlStr, quickSearchStr, quickSearchStr, hrmId); + } + } + + //更新下级managerstr + if (flag && !"".equals(Util.null2String(vo.getManagerid()))) { + String temOldmanagerstr = "," + hrmId + oldmanagerstr; + temOldmanagerstr = temOldmanagerstr.endsWith(",") ? temOldmanagerstr : (temOldmanagerstr + ","); + String sql = "select id,departmentid,subcompanyid1,managerid,seclevel,managerstr from HrmResource where managerstr like '%" + temOldmanagerstr + "'"; + recordSet.executeSql(sql); + while (recordSet.next()) { + String nowmanagerstr = Util.null2String(recordSet.getString("managerstr")); + String resourceid = recordSet.getString("id"); + //指定上级为自身的情况,不更新自身上级 + if (hrmId.equals(resourceid)) + continue; + String nowmanagerstr2 = ""; + int index = nowmanagerstr.lastIndexOf(oldmanagerstr); + if (index != -1) { + if (!"".equals(managerstr)) { + nowmanagerstr2 = nowmanagerstr.substring(0, index) + ("".equals(oldmanagerstr) ? managerstr.substring(1) : managerstr); + } else { + nowmanagerstr2 = nowmanagerstr.substring(0, index) + ("".equals(oldmanagerstr) ? "" : ","); + } + + } + RecordSetTrans rst = new RecordSetTrans(); + rst.setAutoCommit(false); + try { + String para = resourceid + separator + nowmanagerstr2; + rst.executeProc("HrmResource_UpdateManagerStr", para); + rst.commit(); + } catch (Exception e) { + rst.rollback(); + writeLog(e); + } + + } + } + if (flag) { + new Thread(new OrganisationComRunnable("user", "edit", "" + hrmId)).start(); + try{ + //登录信息签名 + PasswordUtil.saveSign(""+hrmId); + }catch (Exception e){ + writeLog(e); + } + HrmFaceCheckManager.sync(keyMap.get(key)+"",HrmFaceCheckManager.getOptUpdate(),"hrm_e9_import_resource",HrmFaceCheckManager.getOaResource()); + new HrmDateCheck().calWorkInfo(hrmId); + resultList.add(createLog(vo, "更新", "成功", "")); + //qc313055 [80][90][缺陷]IM集成-解决人员导入更新人员信息时,无账号列时,IM同步会进行删除操作的问题 ---start + RecordSet rst = new RecordSet(); + if (vo.getLoginid() != null) { + + //此时resourcecominfo对象还没有更新,可以直接取 + if (!"".equals(vo.getLoginid())) { + if (!rtxService.checkUser(Integer.parseInt(hrmId))) { + rtxService.addUser(Integer.parseInt(hrmId));//更新人员rtx + } + } else { + rst.executeSql("select * from hrmresource where id='" + hrmId + "'"); + String loginid = ""; + if (rst.next()) { + loginid = rst.getString("loginid"); + } + if (loginid != null && !loginid.equals("")) { + if (!rtxService.checkUser(Integer.parseInt(hrmId))) { + rtxService.addUser(Integer.parseInt(hrmId));//更新人员rtx + } + } else { + rtxService.deleteUser2(Integer.parseInt(hrmId)); + } + + } + } else { + rst.executeSql("select * from hrmresource where id='" + hrmId + "'"); + String loginid = ""; + if (rst.next()) { + loginid = rst.getString("loginid"); + } + if (loginid != null && !loginid.equals("")) { + if (!rtxService.checkUser(Integer.parseInt(hrmId))) { + rtxService.addUser(Integer.parseInt(hrmId));//更新人员rtx + } + } else { + rtxService.deleteUser2(Integer.parseInt(hrmId)); + } + //qc313055 [80][90][缺陷]IM集成-解决人员导入更新人员信息时,无账号列时,IM同步会进行删除操作的问题 ---end + } + } else { + resultList.add(createLog(vo, "更新", "失败", "系统错误,请联系管理员")); + } + } + } catch (Exception e) { + //数据异常 + writeLog(e); + } + } + try { + HrmTlevelManager.setUpdate(); + } catch (Exception e) { + writeLog(e); + } + + +// endTime = System.currentTimeMillis(); +// System.out.println("---分部、部门层级更新结束,用时:"+(endTime - startTime)); +// startTime = endTime; + //更新人员、分部、部门、职位、岗位、职位类型缓存 + + resourcecominfo.removeResourceCache(); + departmentComInfo.removeCompanyCache(); + subCompanyComInfo.removeCompanyCache(); + jobActivitiesComInfo.removeJobActivitiesCache(); + jobTitlesComInfo.removeJobTitlesCache(); + jobGroupsComInfo.removeCompanyCache(); + locationComInfo.removeLocationCache(); + useKindComInfo.removeUseKindCache(); + //初始化应用分权 + new weaver.hrm.appdetach.AppDetachComInfo().initSubDepAppData(); + + Map params = new HashMap(); + params.put("pId", this.pId); + params.put("status", "over"); + importLogService.saveImportLogStatus(params, user); + +// endTime = System.currentTimeMillis(); +// System.out.println("---数据缓存清空结束,用时:"+(endTime - startTime)); +// startTime = endTime; + } catch (Exception e) { + writeLog(e); + Map params = new HashMap(); + params.put("pId", this.pId); + params.put("status", "error"); + importLogService.saveImportLogStatus(params, user); + } + } + + /** + * 将科学计数法文本转换成字符文本 + * @param number + * @return + */ + public String translateToPlainStr(String number) { + if (StringUtil.isNull(number)) { + return number; + } + String regEx="^([\\+|-]?\\d+(.{0}|.\\d+))[Ee]{1}([\\+|-]?\\d+)$"; + // 编译正则表达式 + Pattern pattern = Pattern.compile(regEx); + // 忽略大小写的写法 + // Pattern pat = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(number); + // 字符串是否与正则表达式相匹配 + boolean rs = matcher.matches(); + // 判断是否为字符串的科学计数法 + if(rs){ + // 科学计数法转数字 + BigDecimal originValue = new BigDecimal(number); + // 数字转字符串 + return originValue.toPlainString(); + } + return number; + } + + /** + * 插入基础自定义字段信息 + * + * @param baseFild 存储人员自定义数据的字段 + * @param baseValue 自定义数据值 + * @param id 需要添加自定义信息的人员id + * @return + */ + public boolean addBaseData(String baseFild, String baseValue, int id) { + if (baseFild == null || baseFild.equals("")) return true; + String baseValues[] = baseValue.split(";"); + String baseFields[] = baseFild.split(","); + String fielddbType = ""; + String sql = ""; + String scopeId = "-1"; + EncryptUtil encryptUtil = new EncryptUtil(); + RecordSet recordSet = new RecordSet(); + try { + if (baseTypeMap == null) { + baseTypeMap = new HashMap(); + String baseSql = "select t1.fieldid,t1.hrm_fieldlable,t1.ismand,t2.fielddbtype,t2.fieldhtmltype,t2.type,t1.dmlurl from cus_formfield t1, cus_formdict t2 where t1.scope='HrmCustomFieldByInfoType' and t1.scopeid=-1 and t1.fieldid=t2.id order by t1.fieldorder"; + recordSet.execute(baseSql); + while (recordSet.next()) { + String fieldid = Util.null2String(recordSet.getString("fieldid")); + String fielddbtype = Util.null2String(recordSet.getString("fielddbtype")); + String fieldhtmltype = Util.null2String(recordSet.getString("fieldhtmltype")); + String type = Util.null2String(recordSet.getString("type")); + String dmlurl = Util.null2String(recordSet.getString("dmlurl")); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fieldid", fieldid); + jsonObject.put("fielddbtype", fielddbtype); + jsonObject.put("fieldhtmltype", fieldhtmltype); + jsonObject.put("type", type); + jsonObject.put("dmlurl", dmlurl); + baseTypeMap.put("field" + recordSet.getInt("fieldid"), jsonObject); + } + } + + sql = "insert into cus_fielddata "; + String valueStr = ""; + for (int i = 0; i < baseFields.length; i++) { + String fieldname = baseFields[i]; + JSONObject jsonObject = baseTypeMap.get(baseFields[i]); + fielddbType = jsonObject.getString("fielddbtype"); + jsonObject.put("fieldvalue", baseValues[i]); + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + + EncryptFieldEntity encryptFieldEntity = new EncryptFieldConfigComInfo().getFieldEncryptConfig("cus_fielddata", fieldname,"HrmCustomFieldByInfoType", scopeId); + if(encryptFieldEntity!=null && encryptFieldEntity.getIsEncrypt().equals("1")){ + //是否需要加密 + fieldvalue = Util.null2String(encryptUtil.encryt("cus_fielddata", fieldname,"HrmCustomFieldByInfoType", scopeId,fieldvalue, fieldvalue)); + } + + if (fielddbType.toLowerCase().startsWith("char") || fielddbType.toLowerCase().startsWith("varchar") || fielddbType.toLowerCase().startsWith("text")) + valueStr = valueStr + "," + "'" + (!fieldvalue.equals("") ? fieldvalue : "") + "'"; + else + valueStr = valueStr + "," + (!fieldvalue.equals("") ? fieldvalue : "NULL"); + } + valueStr = valueStr.substring(1); + sql += "(scope,scopeid,id," + baseFild + ") values('HrmCustomFieldByInfoType'," + -1 + "," + id + "," + valueStr + ")"; + } catch (Exception e) { + writeLog(e); + } + recordSet.setNoAutoEncrypt(true); + return recordSet.execute(sql); + } + + + /** + * 更新基础自定义字段 + * + * @param baseFild 存储人员自定义数据的字段 + * @param baseValue 自定义数据值 + * @param id 需要添加自定义信息的人员id + * @return + */ + public boolean updateBaseData(String baseFild, String baseValue, int id) { + if (baseFild == null || baseFild.equals("")) return true; + + //检查cus_fielddata表中是否存在,对应id人员的基础自定义信息,如果不存在则向数据库添加 + RecordSet recordSet = new RecordSet(); + String checkbaseInfo = "select id from cus_fielddata where scope='HrmCustomFieldByInfoType' and scopeid=-1 and id=" + id; + recordSet.execute(checkbaseInfo); + if (!recordSet.next()) { + return addBaseData(baseFild, baseValue, id); + } + + String baseValues[] = baseValue.split(";"); + String baseFields[] = baseFild.split(","); + String fielddbType = ""; + String sql = ""; + String scopeId = "-1"; + EncryptUtil encryptUtil = new EncryptUtil(); + boolean flag = false; + try { + if (baseTypeMap == null) { + baseTypeMap = new HashMap(); + String personSql = "select t1.fieldid,t1.hrm_fieldlable,t1.ismand,t2.fielddbtype,t2.fieldhtmltype,t2.type,t1.dmlurl from cus_formfield t1, cus_formdict t2 where t1.scope='HrmCustomFieldByInfoType' and t1.scopeid=-1 and t1.fieldid=t2.id order by t1.fieldorder"; + recordSet.execute(personSql); + while (recordSet.next()) { + String fieldid = Util.null2String(recordSet.getString("fieldid")); + String fielddbtype = Util.null2String(recordSet.getString("fielddbtype")); + String fieldhtmltype = Util.null2String(recordSet.getString("fieldhtmltype")); + String type = Util.null2String(recordSet.getString("type")); + String dmlurl = Util.null2String(recordSet.getString("dmlurl")); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fieldid", fieldid); + jsonObject.put("fielddbtype", fielddbtype); + jsonObject.put("fieldhtmltype", fieldhtmltype); + jsonObject.put("type", type); + jsonObject.put("dmlurl", dmlurl); + baseTypeMap.put("field" + recordSet.getInt("fieldid"), jsonObject); + } + } + + sql = "update cus_fielddata set "; + String setStr = ""; + flag = false; + for (int i = 0; i < baseFields.length; i++) { + String fieldname = baseFields[i]; + JSONObject jsonObject = baseTypeMap.get(baseFields[i]); + fielddbType = jsonObject.getString("fielddbtype"); + jsonObject.put("fieldvalue", baseValues[i]); + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + EncryptFieldEntity encryptFieldEntity = new EncryptFieldConfigComInfo().getFieldEncryptConfig("cus_fielddata", fieldname, "HrmCustomFieldByInfoType",scopeId); + if(encryptFieldEntity!=null && encryptFieldEntity.getIsEncrypt().equals("1")){ + //是否需要加密 + fieldvalue = Util.null2String(encryptUtil.encryt("cus_fielddata", fieldname, "HrmCustomFieldByInfoType",scopeId,fieldvalue, fieldvalue)); + } + if (fieldvalue.startsWith(",")) fieldvalue = fieldvalue.substring(1, fieldvalue.length()); + if (fieldvalue.endsWith(",")) fieldvalue = fieldvalue.substring(0, fieldvalue.length() - 1); + if (!fieldvalue.equals("")){ + flag = true; + if (fielddbType.toLowerCase().startsWith("char") || fielddbType.toLowerCase().startsWith("varchar") || fielddbType.toLowerCase().startsWith("text")) + setStr = setStr + "," + baseFields[i] + "='" + (!fieldvalue.equals("") ? fieldvalue : "") + "'"; + else + setStr = setStr + "," + baseFields[i] + "=" + (!fieldvalue.equals("") ? fieldvalue : "NULL"); + } + } + sql += setStr.substring(1) + " where scope='HrmCustomFieldByInfoType' and scopeid=-1 and id=" + id; + } catch (Exception e) { + writeLog(e); + } + recordSet.setNoAutoEncrypt(true); + return (flag?recordSet.execute(sql):true); + } + + + + + /** + * 插入个人自定义字段信息 + * + * @param personFild 存储人员自定义数据的字段 + * @param personValue 自定义数据值 + * @param id 需要添加自定义信息的人员id + * @return + */ + public boolean addPersonData(String personFild, String personValue, int id) { + if (personFild == null || personFild.equals("")) return true; + String personValues[] = personValue.split(";"); + String personFields[] = personFild.split(","); + String fielddbType = ""; + String sql = ""; + String scopeId = "1"; + EncryptUtil encryptUtil = new EncryptUtil(); + RecordSet recordSet = new RecordSet(); + try { + if (personTypeMap == null) { + personTypeMap = new HashMap(); + String personSql = "select t1.fieldid,t1.hrm_fieldlable,t1.ismand,t2.fielddbtype,t2.fieldhtmltype,t2.type,t1.dmlurl from cus_formfield t1, cus_formdict t2 where t1.scope='HrmCustomFieldByInfoType' and t1.scopeid=1 and t1.fieldid=t2.id order by t1.fieldorder"; + recordSet.execute(personSql); + while (recordSet.next()) { + String fieldid = Util.null2String(recordSet.getString("fieldid")); + String fielddbtype = Util.null2String(recordSet.getString("fielddbtype")); + String fieldhtmltype = Util.null2String(recordSet.getString("fieldhtmltype")); + String type = Util.null2String(recordSet.getString("type")); + String dmlurl = Util.null2String(recordSet.getString("dmlurl")); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fieldid", fieldid); + jsonObject.put("fielddbtype", fielddbtype); + jsonObject.put("fieldhtmltype", fieldhtmltype); + jsonObject.put("type", type); + jsonObject.put("dmlurl", dmlurl); + personTypeMap.put("field" + recordSet.getInt("fieldid"), jsonObject); + } + } + + sql = "insert into cus_fielddata "; + String valueStr = ""; + for (int i = 0; i < personFields.length; i++) { + String fieldname = personFields[i]; + JSONObject jsonObject = personTypeMap.get(personFields[i]); + fielddbType = jsonObject.getString("fielddbtype"); + jsonObject.put("fieldvalue", personValues[i]); + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + EncryptFieldEntity encryptFieldEntity = new EncryptFieldConfigComInfo().getFieldEncryptConfig("cus_fielddata", fieldname, "HrmCustomFieldByInfoType",scopeId); + if(encryptFieldEntity!=null && encryptFieldEntity.getIsEncrypt().equals("1")){ + //是否需要加密 + fieldvalue = Util.null2String(encryptUtil.encryt("cus_fielddata", fieldname, "HrmCustomFieldByInfoType",scopeId,fieldvalue, fieldvalue)); + } + if (fielddbType.toLowerCase().startsWith("char") || fielddbType.toLowerCase().startsWith("varchar") || fielddbType.toLowerCase().startsWith("text")) + valueStr = valueStr + "," + "'" + (!fieldvalue.equals("") ? fieldvalue : "") + "'"; + else + valueStr = valueStr + "," + (!fieldvalue.equals("") ? fieldvalue : "NULL"); + } + valueStr = valueStr.substring(1); + sql += "(scope,scopeid,id," + personFild + ") values('HrmCustomFieldByInfoType'," + 1 + "," + id + "," + valueStr + ")"; + } catch (Exception e) { + writeLog(e); + } + recordSet.setNoAutoEncrypt(true); + return recordSet.execute(sql); + } + + + /** + * 更新个人自定义字段 + * + * @param personFild 存储人员自定义数据的字段 + * @param personValue 自定义数据值 + * @param id 需要添加自定义信息的人员id + * @return + */ + public boolean updatePersonData(String personFild, String personValue, int id) { + if (personFild == null || personFild.equals("")) return true; + //检查cus_fielddata表中是否存在,对应id人员的个人自定义信息,如果不存在则向数据库添加 + String checkWorkInfo = "select id from cus_fielddata where scope='HrmCustomFieldByInfoType' and scopeid=1 and id=" + id; + RecordSet recordSet = new RecordSet(); + recordSet.execute(checkWorkInfo); + if (!recordSet.next()) { + return addPersonData(personFild, personValue, id); + } + + String personValues[] = personValue.split(";"); + String personFields[] = personFild.split(","); + String fielddbType = ""; + String sql = ""; + String scopeId = "1"; + EncryptUtil encryptUtil = new EncryptUtil(); + boolean flag = false; + try { + if (personTypeMap == null) { + personTypeMap = new HashMap(); + String personSql = "select t1.fieldid,t1.hrm_fieldlable,t1.ismand,t2.fielddbtype,t2.fieldhtmltype,t2.type,t1.dmlurl from cus_formfield t1, cus_formdict t2 where t1.scope='HrmCustomFieldByInfoType' and t1.scopeid=1 and t1.fieldid=t2.id order by t1.fieldorder"; + recordSet.execute(personSql); + while (recordSet.next()) { + String fieldid = Util.null2String(recordSet.getString("fieldid")); + String fielddbtype = Util.null2String(recordSet.getString("fielddbtype")); + String fieldhtmltype = Util.null2String(recordSet.getString("fieldhtmltype")); + String type = Util.null2String(recordSet.getString("type")); + String dmlurl = Util.null2String(recordSet.getString("dmlurl")); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fieldid", fieldid); + jsonObject.put("fielddbtype", fielddbtype); + jsonObject.put("fieldhtmltype", fieldhtmltype); + jsonObject.put("type", type); + jsonObject.put("dmlurl", dmlurl); + personTypeMap.put("field" + recordSet.getInt("fieldid"), jsonObject); + } + } + + sql = "update cus_fielddata set "; + String setStr = ""; + flag = false; + for (int i = 0; i < personFields.length; i++) { + String fieldname = personFields[i]; + JSONObject jsonObject = personTypeMap.get(personFields[i]); + fielddbType = jsonObject.getString("fielddbtype"); + jsonObject.put("fieldvalue", personValues[i]); + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + EncryptFieldEntity encryptFieldEntity = new EncryptFieldConfigComInfo().getFieldEncryptConfig("cus_fielddata", fieldname, "HrmCustomFieldByInfoType",scopeId); + if(encryptFieldEntity!=null && encryptFieldEntity.getIsEncrypt().equals("1")){ + //是否需要加密 + fieldvalue = Util.null2String(encryptUtil.encryt("cus_fielddata", fieldname, "HrmCustomFieldByInfoType",scopeId,fieldvalue, fieldvalue)); + } + if (fieldvalue.startsWith(",")) fieldvalue = fieldvalue.substring(1, fieldvalue.length()); + if (fieldvalue.endsWith(",")) fieldvalue = fieldvalue.substring(0, fieldvalue.length() - 1); + if(!fieldvalue.equals("")){ + flag = true; + if (fielddbType.toLowerCase().startsWith("char") || fielddbType.toLowerCase().startsWith("varchar") || fielddbType.toLowerCase().startsWith("text")) + setStr = setStr + "," + personFields[i] + "='" + (!fieldvalue.equals("") ? fieldvalue : "") + "'"; + else + setStr = setStr + "," + personFields[i] + "=" + (!fieldvalue.equals("") ? fieldvalue : "NULL"); + } + } + sql += setStr.substring(1) + " where scope='HrmCustomFieldByInfoType' and scopeid=1 and id=" + id; + } catch (Exception e) { + writeLog(e); + } + recordSet.setNoAutoEncrypt(true); + return (flag?recordSet.execute(sql):true); + } + + + /** + * 插入工作自定义字段 + * + * @param workField 存储工作信息自定义数据的字段 + * @param workValue 自定义数据值 + * @param id 需要添加自定义信息的人员id + * @return + */ + public boolean addWorkData(String workField, String workValue, int id) { + if (workField == null || workField.equals("")) { + return true; + } + String workValues[] = workValue.split(";"); + String workFields[] = workField.split(","); + String fielddbType = ""; + String sql = ""; + String scopeId = "3"; + EncryptUtil encryptUtil = new EncryptUtil(); + RecordSet recordSet = new RecordSet(); + try { + if (workTypeMap == null) { + workTypeMap = new HashMap(); + String workSql = "select t1.fieldid,t1.hrm_fieldlable,t1.ismand,t2.fielddbtype,t2.fieldhtmltype,t2.type,t1.dmlurl from cus_formfield t1, cus_formdict t2 where t1.scope='HrmCustomFieldByInfoType' and t1.scopeid=3 and t1.fieldid=t2.id order by t1.fieldorder"; + recordSet.execute(workSql); + while (recordSet.next()) { + String fieldid = Util.null2String(recordSet.getString("fieldid")); + String fielddbtype = Util.null2String(recordSet.getString("fielddbtype")); + String fieldhtmltype = Util.null2String(recordSet.getString("fieldhtmltype")); + String type = Util.null2String(recordSet.getString("type")); + String dmlurl = Util.null2String(recordSet.getString("dmlurl")); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fieldid", fieldid); + jsonObject.put("fielddbtype", fielddbtype); + jsonObject.put("fieldhtmltype", fieldhtmltype); + jsonObject.put("type", type); + jsonObject.put("dmlurl", dmlurl); + workTypeMap.put("field" + recordSet.getInt("fieldid"), jsonObject); + } + } + sql = "insert into cus_fielddata "; + String valueStr = ""; + for (int i = 0; i < workFields.length; i++) { + String fieldname = workFields[i]; + JSONObject jsonObject = workTypeMap.get(workFields[i]); + fielddbType = jsonObject.getString("fielddbtype"); + jsonObject.put("fieldvalue", workValues[i]); + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + EncryptFieldEntity encryptFieldEntity = new EncryptFieldConfigComInfo().getFieldEncryptConfig("cus_fielddata", fieldname, "HrmCustomFieldByInfoType",scopeId); + if(encryptFieldEntity!=null && encryptFieldEntity.getIsEncrypt().equals("1")){ + //是否需要加密 + fieldvalue = Util.null2String(encryptUtil.encryt("cus_fielddata", fieldname, "HrmCustomFieldByInfoType",scopeId,fieldvalue, fieldvalue)); + } + if (fielddbType.toLowerCase().startsWith("char") || fielddbType.toLowerCase().startsWith("varchar") || fielddbType.toLowerCase().startsWith("text")) + valueStr = valueStr + "," + "'" + (!fieldvalue.equals("") ? fieldvalue : "") + "'"; + else + valueStr = valueStr + "," + (!fieldvalue.equals("") ? fieldvalue : "NULL"); + } + valueStr = valueStr.substring(1); + sql += "(scope,scopeid,id," + workField + ") values('HrmCustomFieldByInfoType'," + 3 + "," + id + "," + valueStr + ")"; + } catch (Exception e) { + writeLog(e); + } + recordSet.setNoAutoEncrypt(true); + return recordSet.execute(sql); + } + + + /** + * 更新工作自定义字段 + * + * @param workField 存储工作信息自定义数据的字段 + * @param workValue 自定义数据值 + * @param id 需要添加自定义信息的人员id + * @return + */ + public boolean updateWorkData(String workField, String workValue, int id) { + if (workField == null || workField.equals("")) return true; + + //检查cus_fielddata表中是否存在,对应id人员的工作自定义信息,如果不存在则向数据库添加 + String checkWorkInfo = "select id from cus_fielddata where scope='HrmCustomFieldByInfoType' and scopeid=3 and id=" + id; + RecordSet recordSet = new RecordSet(); + recordSet.execute(checkWorkInfo); + if (!recordSet.next()) { + return addWorkData(workField, workValue, id); + } + + String workValues[] = workValue.split(";"); + String workFields[] = workField.split(","); + String fielddbType = ""; + String sql = ""; + String scopeId = "3"; + EncryptUtil encryptUtil = new EncryptUtil(); + boolean flag = false; + try { + if (workTypeMap == null) { + workTypeMap = new HashMap(); + String workSql = "select t1.fieldid,t1.hrm_fieldlable,t1.ismand,t2.fielddbtype,t2.fieldhtmltype,t2.type,t1.dmlurl from cus_formfield t1, cus_formdict t2 where t1.scope='HrmCustomFieldByInfoType' and t1.scopeid=3 and t1.fieldid=t2.id order by t1.fieldorder"; + recordSet.execute(workSql); + while (recordSet.next()) { + String fieldid = Util.null2String(recordSet.getString("fieldid")); + String fielddbtype = Util.null2String(recordSet.getString("fielddbtype")); + String fieldhtmltype = Util.null2String(recordSet.getString("fieldhtmltype")); + String type = Util.null2String(recordSet.getString("type")); + String dmlurl = Util.null2String(recordSet.getString("dmlurl")); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fieldid", fieldid); + jsonObject.put("fielddbtype", fielddbtype); + jsonObject.put("fieldhtmltype", fieldhtmltype); + jsonObject.put("type", type); + jsonObject.put("dmlurl", dmlurl); + workTypeMap.put("field" + recordSet.getInt("fieldid"), jsonObject); + } + } + + sql = "update cus_fielddata set "; + String setStr = ""; + flag = false; + for (int i = 0; i < workFields.length; i++) { + String fieldname = workFields[i]; + JSONObject jsonObject = workTypeMap.get(workFields[i]); + fielddbType = jsonObject.getString("fielddbtype"); + jsonObject.put("fieldvalue", workValues[i]); + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + EncryptFieldEntity encryptFieldEntity = new EncryptFieldConfigComInfo().getFieldEncryptConfig("cus_fielddata", fieldname, "HrmCustomFieldByInfoType",scopeId); + if(encryptFieldEntity!=null && encryptFieldEntity.getIsEncrypt().equals("1")){ + //是否需要加密 + fieldvalue = Util.null2String(encryptUtil.encryt("cus_fielddata", fieldname, "HrmCustomFieldByInfoType",scopeId,fieldvalue, fieldvalue)); + } + if (fieldvalue.startsWith(",")) fieldvalue = fieldvalue.substring(1, fieldvalue.length()); + if (fieldvalue.endsWith(",")) fieldvalue = fieldvalue.substring(0, fieldvalue.length() - 1); + if(!fieldvalue.equals("")) { + flag = true; + if (fielddbType.toLowerCase().startsWith("char") || fielddbType.toLowerCase().startsWith("varchar") || fielddbType.toLowerCase().startsWith("text")) + setStr = setStr + "," + workFields[i] + "='" + (!fieldvalue.equals("") ? fieldvalue : "") + "'"; + else + setStr = setStr + "," + workFields[i] + "=" + (!fieldvalue.equals("") ? fieldvalue : "NULL"); + } + } + + sql += setStr.substring(1) + " where scope='HrmCustomFieldByInfoType' and scopeid=3 and id=" + id; + } catch (Exception e) { + writeLog(e); + } + recordSet.setNoAutoEncrypt(true); + return (flag?recordSet.execute(sql):true); + } + + /** + * 根据分部名称获取分部Id,不存在就创建 + * + * @param subCompanyName 分部名称 eg:泛微广东>泛微深圳 + * @return + */ + public int getSubCompanyId(String subCompanyName) { + + String subCompanyNames[] = subCompanyName.split(">"); + if (subCompanyNames != null && subCompanyNames.length >= 10) { + return -9; + } + int currentId = 0; + int parentId = 0; + int curCount = 0; + int iscanceled = 0; + + String currentidsql = ""; + String canceledsql = ""; + String sql = ""; + String sqlInsert = ""; + RecordSet recordSet = new RecordSet(); + + String supsubcomidConditon = DbDialectFactory.get(recordSet.getDBType()).isNull("supsubcomid",0) ; + + for (int i = 0; i < subCompanyNames.length; i++) { + if (StringUtil.isNull(subCompanyNames[i])) continue; + + sql = "select id from HrmSubCompany where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(subcompanyname))," + userlanguage + ")))='" + + subCompanyNames[i].trim() + "' and "+supsubcomidConditon+"=" + parentId; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType())||recordSet.getDBType().equalsIgnoreCase("postgresql")) { + sql = "select id from HrmSubCompany where ltrim(rtrim(convToMultiLang(ltrim(rtrim(subcompanyname))," + userlanguage + ")))='" + + subCompanyNames[i].trim() + "' and "+supsubcomidConditon+"=" + parentId; + } + currentidsql = sql + " and (canceled is null or canceled != 1)"; + currentId = getResultSetId(currentidsql); + + if (parentId == 0 && currentId == 0) { + recordSet.executeSql("select COUNT(id) from HrmSubCompany where supsubcomid = 0 and (canceled is null or canceled != '1')"); + if (recordSet.next()) { + curCount = recordSet.getInt(1); + } + } + + //added by wcd 2015-02-06 [限制分部数] + if (currentId == 0) { + canceledsql = sql + " and canceled='1' "; + iscanceled = getResultSetId(canceledsql); + if (iscanceled == 0) { + } else { + currentId = -2; + break; + } + if (scCount == 0 || curCount < scCount) { + // 如果编码为空 自动生成编码 + String subcompanycode = ""; + try { + subcompanycode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.SUBCOMPANY, subcompanycode); + } catch (Exception e) { + writeLog(e); + } + sqlInsert = "insert into HrmSubCompany(subcompanyname,subcompanydesc,companyid,supsubcomid ," + DbFunctionUtil.getInsertColumnSql() + " , subcompanycode) values('" + subCompanyNames[i].trim() + "','" + subCompanyNames[i].trim() + "',1" + "," + parentId + " ," + DbFunctionUtil.getInsertColumnValueSql(recordSet.getDBType(), 1) + ",'"+subcompanycode+"')"; // 创建 + execSql(sqlInsert); + HrmTriggerUtil.generateSubcompanyPinyinNew("", null); + currentId = getResultSetId(sql); + HrmTriggerUtil.Tri_I_SubComKPICheckFlow(String.valueOf(currentId)); + MatrixUtil.updateSubcompayData(currentId+""); + //新增分部,統一调用门户接口创建门户菜单 + ThemeService themService = new ThemeServiceImpl(); + themService.createSubCompanyMenu(currentId,parentId); +// 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); + + HrmFaceCheckManager.sync(currentId+"",HrmFaceCheckManager.getOptInsert(),"HRM_E9_IMPORT",HrmFaceCheckManager.getOaSubcompany()); + } else { + currentId = -1; + } + } + parentId = currentId; + if (currentId != -1) + rtxService.addSubCompany(parentId); //同步RTX + } + return currentId; + } + + /** + * 获取部门id,不存在就创建 + * + * @param deptNames 部门名称 + * @param subCompanyId 所属分部id + * @return + */ + public int getDeptId(String deptNames, int subCompanyId) { + + String deptName[] = deptNames.split(">"); + int currentId = 0; + int parentId = 0; + int iscanceled = 0; + + String currentidsql = ""; + String canceledsql = ""; + String sql = ""; + String sqlInsert = ""; + + RecordSet recordSet = new RecordSet(); + + String supdepidConditon = DbDialectFactory.get(recordSet.getDBType()).isNull("supdepid",0) ; + + 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 ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(departmentname))," + userlanguage + ")))='" + + deptName[i].trim() + "' and "+supdepidConditon+"=" + parentId; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType())||recordSet.getDBType().equalsIgnoreCase("postgresql")) { + sql = "select id from HrmDepartment where subcompanyid1=" + subCompanyId + " and ltrim(rtrim(convToMultiLang(ltrim(rtrim(departmentname))," + userlanguage + ")))='" + + deptName[i].trim() + "' and "+supdepidConditon+"=" + parentId; + } + currentidsql = sql + " and (canceled !=1 or canceled is null)"; + currentId = getResultSetId(currentidsql); + + if (currentId == 0) { + canceledsql = sql + " and canceled='1' "; + iscanceled = getResultSetId(canceledsql); + if (iscanceled == 0) { + } else { + currentId = -2; + break; + } + // 如果编码为空 自动生成编码 + String departmentcode = ""; + try { + departmentcode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.DEPARTMENT, String.valueOf(subCompanyId), departmentcode,String.valueOf(parentId)); + } catch (Exception e) { + writeLog(e); + } + sqlInsert = "insert into HrmDepartment (departmentname,Departmentmark,subcompanyid1,supdepid ," + DbFunctionUtil.getInsertColumnSql() + ", departmentcode) values('" + deptName[i].trim() + "','" + deptName[i].trim() + "'," + subCompanyId + "," + parentId + " ," + DbFunctionUtil.getInsertColumnValueSql(recordSet.getDBType(), 1) + ", '"+departmentcode+"')"; // 创建 + execSql(sqlInsert); + HrmTriggerUtil.generateDepartmentPinyinNew("", null); + currentId = getResultSetId(sql); + HrmTriggerUtil.Tri_I_DeptKPICheckFlow(String.valueOf(currentId)); + MatrixUtil.updateDepartmentData(currentId+""); + HrmFaceCheckManager.sync(currentId+"",HrmFaceCheckManager.getOptInsert(),"HRM_E9_IMPORT_getDeptId",HrmFaceCheckManager.getOaDepartment()); + + rtxService.addDepartment(currentId); //同步RTX + } + parentId = currentId; + } + return currentId; + } + + /** + * 获取岗位id + * + * @param jobtitlename 岗位名称 + * @param jobactivityname 职务 + * @param jobgroupname 职务类型 + * @return + */ + public int getJobTitles(String jobtitlename, String jobactivityname, + String jobgroupname) { + RecordSet rs = new RecordSet(); + RecordSet recordSet = new RecordSet(); + String sqlInsert = ""; + + jobgroupname = Util.convertInput2DB4(jobgroupname); + jobactivityname = Util.convertInput2DB4(jobactivityname); + + /* 获取jobgroupid 职务类别 */ + String selSql = "select id from HrmJobGroups where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(jobgroupname))," + userlanguage + ")))='" + jobgroupname + "'"; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType())||recordSet.getDBType().equalsIgnoreCase("postgresql")) { + selSql = "select id from HrmJobGroups where ltrim(rtrim(convToMultiLang(ltrim(rtrim(jobgroupname))," + userlanguage + ")))='" + jobgroupname + "'"; + } + + int jobgroupid = getResultSetId(selSql); + + if (jobgroupid == 0) { + if (jobgroupname.length() == 0) { + selSql = "select max(id) as id from HrmJobGroups"; + jobgroupid = getResultSetId(selSql); + } else { + sqlInsert = "insert into HrmJobGroups (jobgroupname,jobgroupremark ," + DbFunctionUtil.getInsertColumnSql() + ") values('" + + jobgroupname + "','" + jobgroupname + "'," + DbFunctionUtil.getInsertColumnValueSql(recordSet.getDBType(), 1) + ")"; // 创建 + execSql(sqlInsert); + jobgroupid = getResultSetId(selSql); + } + } + + /* 获取jobactivityid 职务 */ + selSql = "select id from HrmJobActivities where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(jobactivityname))," + userlanguage + ")))='" + jobactivityname + "' and jobgroupid=" + jobgroupid; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType())||recordSet.getDBType().equalsIgnoreCase("postgresql")) { + selSql = "select id from HrmJobActivities where ltrim(rtrim(convToMultiLang(ltrim(rtrim(jobactivityname))," + userlanguage + ")))='" + jobactivityname + "' and jobgroupid=" + jobgroupid; + } + + int jobactivityid = getResultSetId(selSql); + + if (jobactivityid == 0) { + sqlInsert = "insert into HrmJobActivities (jobactivityname,Jobactivitymark,jobgroupid ," + DbFunctionUtil.getInsertColumnSql() + ") values('" + + jobactivityname + "','" + jobactivityname + "'," + jobgroupid + " ," + DbFunctionUtil.getInsertColumnValueSql(recordSet.getDBType(), 1) + ")"; // 创建 + execSql(sqlInsert); + jobactivityid = getResultSetId(selSql); + } + + /*获取岗位id*/ + selSql = "select id from HrmJobTitles where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(jobtitlemark))," + userlanguage + ")))='" + jobtitlename + "' and jobactivityid=" + jobactivityid; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType())||recordSet.getDBType().equalsIgnoreCase("postgresql")) { + selSql = "select id from HrmJobTitles where ltrim(rtrim(convToMultiLang(ltrim(rtrim(jobtitlemark))," + userlanguage + ")))='" + jobtitlename + "' and jobactivityid=" + jobactivityid; + } + + int jobtitle = getResultSetId(selSql); + + if (jobtitle == 0) { + String jobtitlecode = ""; + try { + jobtitlecode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.JOBTITLES, jobtitlecode); + } catch (Exception e) { + writeLog(e); + } + sqlInsert = "insert into HrmJobTitles (jobtitlename,Jobtitlemark,jobactivityid ," + DbFunctionUtil.getInsertColumnSql() + ", jobtitlecode) values('" + + jobtitlename + "','" + jobtitlename + "'," + jobactivityid + " ," + DbFunctionUtil.getInsertColumnValueSql(recordSet.getDBType(), 1) + ", '"+jobtitlecode+"')"; // 创建 + execSql(sqlInsert); + HrmTriggerUtil.generateJobtitlesPinyinNew("", null); + jobtitle = getResultSetId(selSql); + + HrmFaceCheckManager.sync(jobtitle+"",HrmFaceCheckManager.getOptInsert(),"hrm_e9_import_getJobtitles",HrmFaceCheckManager.getOaJobtitle()); + + } else { + selSql = "select * from HrmJobTitles where id = '" + jobtitle + "' and jobactivityid = '" + jobactivityid + "' "; + recordSet.executeSql(selSql); + if (!recordSet.next()) {//查询这个名称已存在的岗位,对应的职务是否存在。如果对应职务的岗位不存在,则说明岗位对应的职务和职务类别有更新 + sqlInsert = "update HrmJobTitles set jobactivityid = '" + jobactivityid + "'," + DbFunctionUtil.getUpdateSetSql(rs.getDBType(), 1) + " where id = '" + jobtitle + "' "; + rs.executeSql(sqlInsert); + } + } + return jobtitle; + } + + + public static boolean needCheckLicenseForUpdate(ResourceComInfo resourceComInfo,String hrmId,HrmResourceVo vo){ + String statusOfHrmId = resourceComInfo.getStatus(hrmId) ; + String loginidOfHrmId = resourceComInfo.getLoginID(hrmId) ; + String accouttypeOfHrmId = resourceComInfo.getAccountType(hrmId) ; + + String statusOfExcel = vo.getStatus() ; + String loginidOfExcel = vo.getLoginid() ; + String accouttypeOfExcel = vo.getAccounttype() ; + + // 1. 历史状态算license 不检查 + if( "0,1,2,3".indexOf(statusOfHrmId)>-1 && StringUtils.isNotBlank(loginidOfHrmId) && !"1".equals(accouttypeOfHrmId)){ + return false ; + } + boolean isStatus = false ; + if(StringUtils.isBlank(statusOfExcel)){ + isStatus = "0,1,2,3".indexOf(statusOfHrmId)>-1 ; + }else{ + isStatus = "正式,试用,临时,试用延期".indexOf(statusOfExcel)>-1 ; + } + boolean isLoginid = false ; + if(StringUtils.isBlank(loginidOfExcel)){ + isLoginid = StringUtils.isNotBlank(loginidOfHrmId) ; + }else{ + isLoginid = StringUtils.isNotBlank(loginidOfExcel) ; + } + boolean isAccouttype = false ; + if(StringUtils.isBlank(accouttypeOfExcel)){ + isAccouttype = !"1".equals(accouttypeOfHrmId) ; + }else{ + isAccouttype = "主账号".equals(accouttypeOfExcel) ; + } + + return isStatus && isLoginid && isAccouttype ; + + } + + /** + * 获取直接上级Id和所有上级 + * + * @param keyFieldValue 上级标记值,eg:编号 + * @param keyField 关键字段 + * @return + */ + public Map getManagerIdAndStr(String hrmid, String keyFieldValue, String keyField) { + + int managerId = 0; + String managerstr = ""; + RecordSet recordSet = new RecordSet(); + Map managerInfo = new HashMap(); + if (!keyFieldValue.equals("")) { +// String selSql = "select id,managerstr from hrmResource where " + keyField + "='" + keyFieldValue + "'"; + String selSql = "select id,managerstr from hrmResource where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + ")))= '" + keyFieldValue + "'"; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType())||recordSet.getDBType().equalsIgnoreCase("postgresql")) { + selSql = "select id,managerstr from hrmResource where ltrim(rtrim(convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + ")))= '" + keyFieldValue + "'"; + } + recordSet.execute(selSql); + while (recordSet.next()) { + managerId = recordSet.getInt("id"); + managerstr = recordSet.getString("managerstr"); + if (!hrmid.equals("" + managerId)) { //设置上级为自身的情况 + managerstr = "," + managerId + managerstr; + } else { + managerstr = "," + managerId + ","; + } + + managerstr = managerstr.endsWith(",") ? managerstr : (managerstr + ","); + managerInfo.put("managerid", new Integer(managerId)); + managerInfo.put("managerstr", managerstr); + } + } + return managerInfo; + } + + /** + * 获取助理id + * + * @param keyFieldValue 助理标记 + * @param keyField 关键字段 + * @return + */ + public int getAssistantid(String keyFieldValue, String keyField) { + + int getAssistantid = 0; + RecordSet recordSet = new RecordSet(); + if (!keyFieldValue.equals("")) { +// String selSql = "select id from hrmResource where " + keyField + "='" + keyFieldValue + "'"; + String selSql = "select id from hrmResource where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + ")))= '" + keyFieldValue + "'"; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType())||recordSet.getDBType().equalsIgnoreCase("postgresql")) { + selSql = "select id from hrmResource where ltrim(rtrim(convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + ")))= '" + keyFieldValue + "'"; + } + getAssistantid = getResultSetId(selSql); + } + return getAssistantid; + } + + /** + * 获取主账号id + * + * @param keyFieldValue 主账号标记 + * @param keyField 关键字段 + * @return + */ + public int getBelongId(String keyFieldValue, String keyField) { + int getAssistantid = -1; + RecordSet recordSet = new RecordSet(); + if (!keyFieldValue.equals("")) { +// String selSql = "select id from hrmResource where " + keyField + "='" + keyFieldValue + "'"; + String selSql = "select id from hrmResource where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + ")))= '" + keyFieldValue + "'"; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType())||recordSet.getDBType().equalsIgnoreCase("postgresql")) { + selSql = "select id from hrmResource where ltrim(rtrim(convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + ")))= '" + keyFieldValue + "'"; + } + getAssistantid = getResultSetId(selSql); + } + return getAssistantid; + } + + /** + * 办公地点id + * + * @param locationname 办公地点名称 + * @return + */ + public int getLocationid(String locationname) { + int locationid = 0; + if (!locationname.equals("")) { + locationid = locationMap.containsKey(locationname) ? locationMap.get(locationname) : 0; + if (locationid == 0) { + String insertSql = "insert into HrmLocations(locationname,locationdesc,countryid) values('" + locationname + "','" + locationname + "',1)"; + execSql(insertSql); + String selSql = "select id from HrmLocations where countryid=1 and locationname='" + locationname + "'"; + locationid = getResultSetId(selSql); + locationMap.put(locationname, locationid); + } + } + return locationid; + } + + /** + * 用工性质id + * + * @param usekindname 用工性质名称 + * @return + */ + public int getUseKind(String usekindname) { + int usekindid = 0; + if (!usekindname.equals("")) { + usekindid = usekindMap.containsKey(usekindname) ? usekindMap.get(usekindname) : 0; + if (usekindid == 0) { + String insertSql = "insert into HrmUseKind(name,description) values('" + usekindname + "','" + usekindname + "')"; + execSql(insertSql); + String selSql = "select id from HrmUseKind where name='" + usekindname + "'"; + usekindid = getResultSetId(selSql); + usekindMap.put(usekindname, usekindid); + } + } + return usekindid; + } + + /** + * 职称 + * + * @param jobcall 职称名称 + * @return + */ + public int getJobcall(String jobcall) { + + int jobcalld = 0; + if (!jobcall.equals("")) { + jobcalld = jobcallMap.containsKey(jobcall) ? jobcallMap.get(jobcall) : 0; + if (jobcalld == 0) { + String insertSql = "insert into HrmJobCall(name) values('" + jobcall + "')"; + execSql(insertSql); + String selSql = "select id from HrmJobCall where name='" + jobcall + "'"; + jobcalld = getResultSetId(selSql); + jobcallMap.put(jobcall, jobcalld); + } + } + return jobcalld; + } + + /** + * 系统语言 + * + * @param language 语言 eg:简体中文,English,繁體中文 + * @return + */ + public int getSystemlanguage(String language) { + int systemlanguageid = 7; //系统语言默认为中文 + + //系统只支持三种语言,如果是其他语言,提示输入有误 + //if (!(language.equals("English") || language.equals("繁體中文") || language.equals("简体中文")) && language != "") + //return -1; + + //如果系统不支持多语言,则返回0 + if ((language.equals("English") || language.equals("繁體中文")) && !multilanguage.toLowerCase().equals("y")) + return 0; + + if (!language.equals("")) { + if (language.equals("简体中文")) + systemlanguageid = cnLanguageId; + else { + if (sysLanguage.containsKey(language)) { + systemlanguageid = sysLanguage.get(language); + } else { + systemlanguageid = -1; + } + } + } + return systemlanguageid; + } + + /** + * 工资银行id + * + * @param bank1 办公地点名称 + * @return + */ + public int getBankId(String bank1) { + int id = 0; + if (!bank1.equals("")) { + String insertSql = "insert into hrmbank(bankname,bankdesc) values('" + bank1 + "','" + bank1 + "')"; + execSql(insertSql); + String selSql = "select id from hrmbank where bankname='" + bank1 + "'"; + id = getResultSetId(selSql); + } + return id; + } + + /** + * 获取员工状态 + * + * @param status 员工状态值 + * @return + */ + public int getStatus(String status) { + + int statusid = 1; + if (status.equals("试用")) + statusid = 0; + else if (status.equals("正式")) + statusid = 1; + else if (status.equals("临时")) + statusid = 2; + else if (status.equals("试用延期")) + statusid = 3; + else if (status.equals("解聘")) + statusid = 4; + else if (status.equals("离职")) + statusid = 5; + else if (status.equals("退休")) + statusid = 6; + else if (status.equals("无效")) + statusid = 7; + else + statusid = 1; + return statusid; + } + + /** + * 获取人员密级 + * + * @param status 员工状态值 + * @return + */ + public int getClassification(String classification) { + + int classificationid = 3; + if (classification.equals("核心")) + classificationid = 0; + else if (classification.equals("重要")) + classificationid = 1; + else if (classification.equals("一般")) + classificationid = 2; + else + classificationid = 3; + return classificationid; + } + + /** + * 获取学历Id + * + * @param educationlevel 学历值 + * @return + */ + public int getEducationlevel(String educationlevel) { + int educationlevelid = 0; + if (!educationlevel.equals("")) { + educationlevelid = educationlevelMap.containsKey(educationlevel) ? educationlevelMap.get(educationlevel) : 0; + if (educationlevelid == 0) { + String insertSql = "insert into HrmEducationLevel(name,description) values('" + educationlevel + "','" + educationlevel + "')"; + execSql(insertSql); + String selSql = "select id from HrmEducationLevel where name='" + educationlevel + "'"; + educationlevelid = getResultSetId(selSql); + educationlevelMap.put(educationlevel, educationlevelid); + } + } + return educationlevelid; + } + + /** + * 获取身体状况 + * + * @param healthinfo + * @return + */ + public String getHealthinfo(String healthinfo) { + + String healthinfoid = "0"; + + if (healthinfo.equals("良好")) + healthinfoid = "1"; + else if (healthinfo.equals("一般")) + healthinfoid = "2"; + else if (healthinfo.equals("较差")) + healthinfoid = "3"; + else + healthinfoid = "0"; + + return healthinfoid; + } + + /** + * 获取id与workcode_lastname 键值对,用于对导入数据重复性判断 + * + * @param keyField key值,重复性验证字段 + */ + public void getKeyMap(String keyField) { + RecordSet recordSet = new RecordSet(); + String sql = ""; + sql = "select id, accounttype,isADAccount,certificatenum,loginid,workcode, ltrim(rtrim(convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + "))) as " + keyField + " from hrmResource"; + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sql = "select id, accounttype,isADAccount,certificatenum,loginid,workcode, ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + "))) as " + keyField + " from hrmResource"; + } + recordSet.execute(sql); + String cerNum = ""; + while (recordSet.next()) { + for(String key : checkKeys){ + Map checkInfo = checkInfos.get(key); + if(checkInfo==null){ + checkInfo = new HashMap<>(); + checkInfos.put(key,checkInfo); + }else{ + checkInfo = checkInfos.get(key); + } + String val = Util.null2String(recordSet.getString(key)); + checkInfo.put(val, recordSet.getString("id")); + checkInfos.put(key,checkInfo); + } + + cerNum = recordSet.getString("certificatenum"); + keyMap.put(recordSet.getString(keyField), new Integer(recordSet.getInt("id"))); + isADAccountMap.put(Util.null2String(recordSet.getString("id")), Util.null2String(recordSet.getString("isADAccount"))); + String accounttype = recordSet.getString("accounttype"); + if(!"1".equalsIgnoreCase(accounttype)){ + if (StringUtil.isNotNull(cerNum)) { + certificateNums.put(StringUtil.vString(cerNum), new Integer(recordSet.getInt("id"))); + } + } + } + + } + + /** + * 写入导入日志 + * + * @param resultList 导入结果集 + */ + public void writeImportLog(List resultList) { + + if (logFile.equals("")) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + + String logFile1 = GCONST.getRootPath() + "/log/hrmImportLog"; + logFile1 = logFile1.replace("\\", "/"); + File logFile2 = new File(logFile1); + if (!logFile2.exists()) { + logFile2.mkdir(); + } + + logFile = GCONST.getRootPath() + "log" + File.separator + "hrmImportLog" + File.separator + "人员导入_" + + dateFormat.format(new Date()) + ".txt"; + logFile = logFile.replace("\\", "/"); + File file = new File(logFile); + + try { + file.createNewFile(); + } catch (IOException e) { + writeLog(e); + } + } + try { + BufferedWriter out = new BufferedWriter(new FileWriter(logFile, + true)); + ImportLog log = new ImportLog(); + + SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String logRecord = "导入时间 " + timeFormat.format(new Date()) + "\r\n"; + out.write(logRecord); + // 优先输出失败结果 + for (int i = 0; i < resultList.size(); i++) { + log = (ImportLog) resultList.get(i); + + if (log.getStatus().equals("失败")) { + if (this.keyField.equals("workcode")) + logRecord = log.getWorkCode(); + else if (this.keyField.equals("loginid")) + logRecord = log.getLoginid(); + else if (this.keyField.equals("lastname")) + logRecord = log.getLastname(); + logRecord = logRecord + "|" + log.getDepartment() + "|" + log.getOperation() + "|" + log.getStatus() + "|" + log.getReason() + "\r\n"; + out.write(logRecord); + } + } + + // 输出成功结果 + for (int i = 0; i < resultList.size(); i++) { + log = (ImportLog) resultList.get(i); + if (log.getStatus().equals("成功")) { + + if (this.keyField.equals("workcode")) + logRecord = log.getWorkCode(); + else if (this.keyField.equals("loginid")) + logRecord = log.getLoginid(); + else if (this.keyField.equals("lastname")) + logRecord = log.getLastname(); + logRecord = logRecord + "|" + log.getDepartment() + "|" + log.getOperation() + "|" + log.getStatus() + "|" + log.getReason() + "\r\n"; + out.write(logRecord); + } + } + out.close(); + } catch (IOException e) { + writeLog(e); + } + } + + /** + * 执行插入操作 + * + * @param sql + * @return + */ + + public boolean execSql(String sql) { + RecordSet recordSet = new RecordSet(); + if (recordSet.execute(sql)) { + return true; + } else { + return false; + } + } + + /** + * 获得查询结果Id + * + * @param sql 查询语句 + * @return + */ + public int getResultSetId(String sql) { + int currentId = 0; + RecordSet recordSet = new RecordSet(); + recordSet.execute(sql); + try { + while (recordSet.next()) { + currentId = recordSet.getInt("id"); + } + } catch (Exception e) { + e.printStackTrace(); + } + return currentId; + } + + /** + * 创建日志对象 + * + * @param vo HrmResourceVo 人员信息对象 + * @param operation 操作类型 验证|创建|更新 + * @param status 状态 成功|失败 + * @param reason 失败原因 + * @return ImportLog对象 + */ + public ImportLog createLog(HrmResourceVo vo, String operation, String status, String reason) { + ImportLog log = new ImportLog(); + + log.setWorkCode(vo.getWorkcode()); //编号 + log.setLastname(vo.getLastname()); //用户名 + log.setLoginid(vo.getLoginid()); //登录名 + log.setOperation(operation); //操作类型 + if (vo.getSubcompanyid1() != null && vo.getDepartmentid() != null) + log.setDepartment(vo.getSubcompanyid1() + ">" + vo.getDepartmentid()); //分部部门 + else + log.setDepartment(""); + log.setStatus(status); //状态,成功、失败 + log.setReason(reason); //原因 + + try { + ImportLogService importLogService = (ImportLogServiceImpl) ServiceUtil.getService(ImportLogServiceImpl.class, user); + String relatedName = ""; + if (this.keyField.equals("workcode")) + relatedName = log.getWorkCode(); + else if (this.keyField.equals("loginid")) + relatedName = log.getLoginid(); + else if (this.keyField.equals("lastname")) + relatedName = log.getLastname(); + + Map params = new HashMap(); + params.put("pId", this.pId); + params.put("lineNum", this.rowNum+2);//修正偏移量错误 + params.put("relatedName", relatedName); + params.put("msg", log.getStatus().equals("成功") ? relatedName + "导入成功!" : log.getReason()); + params.put("status", log.getStatus().equals("成功") ? "1" : "0"); + importLogService.saveImportDeitalLog(params, user); + } catch (Exception e) { + writeLog(e); + } + return log; + } + + //整数判断 + public static boolean isInteger(String str) { + if (str == null) + return false; + Pattern pattern = Pattern.compile("[0-9]+"); + return pattern.matcher(str).matches(); + } + + + private boolean checkInfo(HrmResourceVo hrmResourceVo, List resultList){ + //新增账号、工号唯一性校验 + for(String key : checkKeys){ + Map checkInfo = checkInfos.get(key); + if(checkInfo!=null && !checkInfo.isEmpty()){ + String val = ""; + String errorMsg = ""; + if(key.equals("loginid")){ + val = Util.null2String(hrmResourceVo.getLoginid()).trim(); + errorMsg = SystemEnv.getHtmlLabelName(522076, userlanguage); + }else if(key.equals("workcode")){ + val = Util.null2String(hrmResourceVo.getWorkcode()).trim(); + errorMsg = SystemEnv.getHtmlLabelName(520197, userlanguage); + }else if(key.equals("certificatenum")){ + val = Util.null2String(hrmResourceVo.getCertificatenum()).trim(); + errorMsg = SystemEnv.getHtmlLabelName(83521, userlanguage); + } + int reosurceid = Util.getIntValue(checkInfo.get(val)); + if(hrmResourceVo.getId()!=null && hrmResourceVo.getId()==reosurceid){ + //如果是当前记录,不需要校验 + continue; + } + + if (reosurceid>0 && val .length() > 0) { + resultList.add(createLog(vo, this.operateType.equals("add")?"创建":"更新", "失败", errorMsg)); + return true; + } + } + } + return false; + } + + + public int getUserlanguage() { + return userlanguage; + } + + + public void setUserlanguage(int userlanguage) { + this.userlanguage = userlanguage; + } +}