From 85705c5f603cfab2e7cc24b532e25f81bc624326 Mon Sep 17 00:00:00 2001 From: Chengliang <1546584672@qq.com> Date: Thu, 26 Dec 2024 18:27:34 +0800 Subject: [PATCH] =?UTF-8?q?=20QC3454501=20=E6=B7=B1=E5=9C=B3=E5=85=89?= =?UTF-8?q?=E8=BE=BE=E9=A1=BA=E7=A7=91=E6=8A=80=E6=9C=89=E9=99=90=E5=85=AC?= =?UTF-8?q?=E5=8F=B8=20=E8=BA=AB=E4=BB=BD=E8=AF=81=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E6=BA=90=E7=A0=81=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hrm/service/HrmResourceBaseService.java | 3628 +++++++++++++++++ .../service/HrmResourcePersonalService.java | 763 ++++ src/com/api/hrm/util/ServiceUtil.java | 751 ++++ .../pm/action/HrmResourceEntrantAction.java | 953 +++++ .../hrm/in/processImpl/HrmImportProcess.java | 2879 +++++++++++++ .../in/processImpl/HrmImportProcessE9.java | 2942 +++++++++++++ 6 files changed, 11916 insertions(+) create mode 100644 src/com/api/hrm/service/HrmResourceBaseService.java create mode 100644 src/com/api/hrm/service/HrmResourcePersonalService.java create mode 100644 src/com/api/hrm/util/ServiceUtil.java create mode 100644 src/weaver/hrm/pm/action/HrmResourceEntrantAction.java create mode 100644 src/weaver/join/hrm/in/processImpl/HrmImportProcess.java create mode 100644 src/weaver/join/hrm/in/processImpl/HrmImportProcessE9.java diff --git a/src/com/api/hrm/service/HrmResourceBaseService.java b/src/com/api/hrm/service/HrmResourceBaseService.java new file mode 100644 index 0000000..5abcc88 --- /dev/null +++ b/src/com/api/hrm/service/HrmResourceBaseService.java @@ -0,0 +1,3628 @@ +package com.api.hrm.service; + +import java.io.File; +import java.lang.reflect.Method; +import java.text.SimpleDateFormat; +import java.util.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import javax.ws.rs.core.Context; + +import com.alibaba.fastjson.JSONObject; +import com.api.doc.detail.util.DocDownloadCheckUtil; +import com.api.hrm.bean.HrmFieldBean; +import com.api.hrm.bean.RightMenu; +import com.api.hrm.bean.RightMenuType; +import com.api.hrm.util.HrmFieldSearchConditionComInfo; +import com.api.hrm.util.HrmFieldUtil; +import com.api.hrm.util.ServiceUtil; +import com.api.browser.bean.SearchConditionItem; +import com.api.browser.bean.SearchConditionOption; + +import com.cloudstore.dev.api.util.TextUtil; +import com.engine.common.biz.SimpleBizLogger; +import com.engine.common.constant.BizLogOperateType; +import com.engine.common.constant.BizLogSmallType4Hrm; +import com.engine.common.constant.BizLogType; +import com.engine.common.entity.BizLogContext; +import com.engine.common.service.HrmCommonService; +import com.engine.common.service.impl.HrmCommonServiceImpl; +import com.engine.common.util.LogUtil; +import com.engine.common.util.ParamUtil; +import com.engine.hrm.biz.HrmFieldManager; +import com.engine.hrm.entity.RuleCodeType; +import com.engine.hrm.util.CodeRuleManager; +import com.engine.hrm.util.face.HrmFaceCheckManager; +import com.engine.kq.wfset.util.KQ122Util; +import com.engine.portal.biz.constants.ModuleConstants; +import com.engine.portal.biz.nonstandardfunction.SysModuleInfoBiz; +import com.engine.hrm.util.face.ValidateFieldManager; +import com.engine.hrm.util.face.bean.CheckItemBean; +import ln.LN; +import org.apache.commons.lang3.StringUtils; +import weaver.hrm.definedfield.HrmFieldComInfo; +import weaver.hrm.job.JobCallComInfo; +import weaver.blog.BlogShareManager; +import weaver.common.DateUtil; +import weaver.common.StringUtil; +import weaver.conn.RecordSet; +import weaver.conn.RecordSetTrans; +import weaver.cowork.CoworkShareManager; +import weaver.cpt.search.CptSearchComInfo; +import weaver.crm.CrmShareBase; +import weaver.docs.docs.CustomFieldManager; +import weaver.docs.search.DocSearchComInfo; +import weaver.file.FileUpload; +import weaver.file.ImageFileManager; +import weaver.file.Prop; +import weaver.filter.XssUtil; +import weaver.formmode.cuspage.cpt.Cpt4modeUtil; +import weaver.general.BaseBean; +import weaver.general.GCONST; +import weaver.general.StaticObj; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.hrm.appdetach.AppDetachComInfo; +import weaver.hrm.common.DbFunctionUtil; +import weaver.hrm.company.DepartmentComInfo; +import weaver.hrm.company.SubCompanyComInfo; +import weaver.hrm.companyvirtual.DepartmentVirtualComInfo; +import weaver.hrm.definedfield.HrmFieldGroupComInfo; +import weaver.hrm.finance.SalaryManager; +import weaver.hrm.job.JobActivitiesComInfo; +import weaver.hrm.job.JobTitlesComInfo; +import weaver.hrm.location.LocationComInfo; +import weaver.hrm.moduledetach.ManageDetachComInfo; +import weaver.hrm.privacy.PrivacyBaseComInfo; +import weaver.hrm.privacy.PrivacyComInfo; +import weaver.hrm.privacy.PrivacyUtil; +import weaver.hrm.privacy.UserPrivacyComInfo; +import weaver.hrm.resource.*; +import weaver.hrm.settings.ChgPasswdReminder; +import weaver.hrm.settings.RemindSettings; +import weaver.hrm.tools.HrmResourceFile; +import weaver.hrm.tools.HrmValidate; +//import weaver.interfaces.email.CoreMailAPI; +import weaver.interfaces.hrm.HrmServiceManager; +import weaver.license.PluginUserCheck; +import weaver.login.Account; +import weaver.login.VerifyLogin; +import weaver.proj.search.SearchComInfo; +import weaver.rtx.OrganisationCom; +import weaver.rtx.OrganisationComRunnable; +import weaver.system.SysRemindWorkflow; +import weaver.systeminfo.MouldStatusCominfo; +import weaver.systeminfo.SysMaintenanceLog; +import weaver.systeminfo.SystemEnv; +import weaver.systeminfo.language.LanguageComInfo; +import weaver.systeminfo.setting.HrmUserSettingComInfo; +import weaver.systeminfo.systemright.CheckSubCompanyRight; +import weaver.wechat.util.Utils; +import weaver.workflow.search.WorkflowRequestUtil; +import weaver.encrypt.EncryptUtil; + +/*** + * 人员卡片 + * @author lvyi + * + */ +public class HrmResourceBaseService extends BaseBean { + private static final char separator = Util.getSeparator(); + private String today = DateUtil.getCurrentDate(); + + private boolean isMobx = false; + private String id = ""; + + /** + * 人员卡片头部信息 + * + * @param request + * @param response + * @return + */ + public String getResourceBaseTitle(HttpServletRequest request, HttpServletResponse response) { + Map retmap = new HashMap(); + try { + User user = HrmUserVarify.getUser(request, response); + AppDetachComInfo adci = new AppDetachComInfo(); + HrmListValidate hrmListValidate = new HrmListValidate(); + boolean hasRight = false; + String id = Util.null2String(request.getParameter("id")); + if (id.equals("") || id.equals(Util.null2String(user.getUID() + ""))) { + id = String.valueOf(user.getUID()); + hasRight = true; + } else { + hasRight = adci.checkUserAppDetach(id, "1", user) == 1; + } + retmap.put("hasRight", hasRight); + if(!hasRight){ + return JSONObject.toJSONString(retmap); + } + ResourceComInfo ResourceComInfo = new ResourceComInfo(); + DepartmentComInfo DepartmentComInfo = new DepartmentComInfo(); + Map jsondata = new HashMap(); + + RecordSet rs = new RecordSet(); + String sql = "select * from hrmresource where id=" + id; + rs.executeSql(sql); + if (rs.next()) { + String lastname = Util.toScreen(rs.getString("lastname"), user.getLanguage()); + String workcode = Util.toScreen(rs.getString("workcode"), user.getLanguage()); + String sex = Util.null2String(rs.getString("sex")).trim(); + if(sex.length()==0) sex = "0"; + String departmentid = Util.toScreen(rs.getString("departmentid"), user.getLanguage()); + String subcompanyid = Util.toScreen(rs.getString("subcompanyid1"), user.getLanguage()); + lastname = lastname.endsWith("\\") && !lastname.endsWith("\\\\") == true ? lastname + "\\" : lastname; + lastname = StringUtil.replace(lastname, "'", "\\\\'"); + + String messagerUrls = Util.toScreen(rs.getString("messagerurl"), user.getLanguage()); + String resourceimageid = ResourceComInfo.getResourceimageid(id); + if (messagerUrls.length() == 0 && !resourceimageid.equals("0") && resourceimageid.length() > 0) { + messagerUrls = ServiceUtil.saveMessagerUrl(Util.getIntValue(resourceimageid), id); + } else { + messagerUrls = ResourceComInfo.getMessagerUrls(id); + } +// String filePath = GCONST.getRootPath() + messagerUrls; +// File file = new File(filePath); +// if (!file.exists() || !hrmListValidate.isValidate(36)) { +// if (resourceimageid > 0) { +// String mainControlHost = Util.null2String(Prop.getInstance().getPropValue("Others", "MAINCONTROLHOST")); +// messagerUrls = mainControlHost + "/weaver/weaver.file.FileDownload?fileid=" + resourceimageid; +// } else { +// if (sex.equals("0")) { +// messagerUrls = "/messager/images/icon_m_wev8.jpg"; +// } else if (sex.equals("1")) { +// messagerUrls = "/messager/images/icon_w_wev8.jpg"; +// } +// } +// } +// +// boolean USERICONLASTNAME = Util.null2String(new BaseBean().getPropValue("Others", "USERICONLASTNAME")).equals("1"); +// if (USERICONLASTNAME && (messagerUrls.indexOf("icon_w_wev8.jpg") > -1 || messagerUrls.indexOf("icon_m_wev8.jpg") > -1 || messagerUrls.indexOf("dummyContact.png") > -1)) { +// jsondata.put("shortname", User.getLastname(Util.null2String(Util.formatMultiLang(lastname, "" + user.getLanguage())))); +// } + jsondata.put("lastname", lastname); + jsondata.put("messagerurl", messagerUrls); + jsondata.put("requestParams", ResourceComInfo.getUserIconInfoStr(id,user)); + jsondata.put("workcode", workcode); + HrmFieldComInfo hrmFieldComInfo = new HrmFieldComInfo(); + String isused = Util.null2String(hrmFieldComInfo.getBaseFieldMap("sex").getString("isused")); + if ("1".equals(isused)) { + Map sexdata = new HashMap(); + jsondata.put("sex", sexdata);//0:男性,1:女性 + sexdata.put("value", sex); + if (sex.equals("0")) { + sexdata.put("name", SystemEnv.getHtmlLabelName(28473, user.getLanguage())); + } else if (sex.equals("1")) { + sexdata.put("name", SystemEnv.getHtmlLabelName(28474, user.getLanguage())); + } + } + if (Util.null2String(Prop.getInstance().getPropValue("Others", "showDepartmentFullName")).equals("1")) { + jsondata.put("orginfo", DepartmentComInfo.getAllParentDepartmentNames(departmentid, subcompanyid)); + } else { + jsondata.put("orginfo", DepartmentComInfo.getAllParentDepartmentMarks(departmentid, subcompanyid)); + } + } + retmap.put("result", jsondata); + retmap.put("id", id); + } catch (Exception e) { + writeLog(e); + } + + return JSONObject.toJSONString(retmap); + } + + /** + * 查询人员列表右键菜单 + * + * @param request + * @param response + * @return + * @throws Exception + */ + public String getRightMenu(HttpServletRequest request, HttpServletResponse response) { + Map apidatas = new HashMap(); + try { + ChgPasswdReminder reminder = new ChgPasswdReminder(); + RemindSettings settings = reminder.getRemindSettings(); + User user = HrmUserVarify.getUser(request, response); + String id = Util.null2String(request.getParameter("id")); + if (id.equals("")) id = String.valueOf(user.getUID()); + + HrmListValidate HrmListValidate = new HrmListValidate(); + List rightMenus = new ArrayList(); + int language = user.getLanguage(); + int hrmdetachable = 0; + HttpSession session = request.getSession(true); + String status = ""; + String subcompanyid = ""; + String departmentid = ""; + + String textMessageSql = "select dataValue from ecology_message_valve_config where dataKey = 'emSwitch'"; + RecordSet textRs = new RecordSet(); + textRs.execute(textMessageSql); + textRs.next(); + //dataValue为0代表关闭发消息选项 + String dataValue = textRs.getString("dataValue"); + + RecordSet rs = new RecordSet(); + rs.executeSql("select subcompanyid1,departmentid, status from hrmresource where id = " + id); + if (rs.next()) { + status = Util.toScreen(rs.getString("status"), user.getLanguage()); + subcompanyid = Util.toScreen(rs.getString("subcompanyid1"), user.getLanguage()); + departmentid = Util.toScreen(rs.getString("departmentid"), user.getLanguage()); + if (subcompanyid == null || subcompanyid.equals("") || subcompanyid.equalsIgnoreCase("null")) + subcompanyid = "-1"; + session.setAttribute("hrm_subCompanyId", subcompanyid); + } + + boolean isSelf = false; + if (id.equals("" + user.getUID())) { + isSelf = true; + } + //人力资源模块是否开启了管理分权,如不是,则不显示框架,直接转向到列表页面(新的分权管理) + if (session.getAttribute("hrmdetachable") != null) { + hrmdetachable = Util.getIntValue(String.valueOf(session.getAttribute("hrmdetachable")), 0); + } else { + boolean isUseHrmManageDetach = new ManageDetachComInfo().isUseHrmManageDetach(); + if (isUseHrmManageDetach) { + hrmdetachable = 1; + session.setAttribute("detachable", "1"); + session.setAttribute("hrmdetachable", String.valueOf(hrmdetachable)); + } else { + hrmdetachable = 0; + session.setAttribute("detachable", "0"); + session.setAttribute("hrmdetachable", String.valueOf(hrmdetachable)); + } + } + int operatelevel = -1; + if (hrmdetachable == 1) { + operatelevel = new CheckSubCompanyRight().ChkComRightByUserRightCompanyId(user.getUID(), "HrmResourceEdit:Edit", Integer.parseInt(subcompanyid)); + } else { + if (HrmUserVarify.checkUserRight("HrmResourceEdit:Edit", user, departmentid)) + operatelevel = 2; + } + + + if (((isSelf && isHasModify(-1)) || operatelevel > 0) && !status.equals("10")) {//编辑 + rightMenus.add(new RightMenu(language, RightMenuType.BTN_EDIT, "editCard")); + } + + if (HrmListValidate.isValidate(33) && !isSelf && "1".equals(Utils.null2String(dataValue))) {//发送消息 + rightMenus.add(new RightMenu(language, RightMenuType.BTN_SENDMESAGE, "sendEmessage")); + } + + if (HrmListValidate.isValidate(31) && !isSelf) {//发送短信 + rightMenus.add(new RightMenu(language, RightMenuType.BTN_SENDSMSMESSAGE, "sendSmsMessage")); + } + + if (HrmListValidate.isValidate(19) && !isSelf) {//发送邮件 + rightMenus.add(new RightMenu(language, RightMenuType.BTN_SENDMAIL, "sendMail")); + } + + if (HrmListValidate.isValidate(32) && !isSelf) {//新建日程 + rightMenus.add(new RightMenu(language, RightMenuType.BTN_DOADDWORKPLANBYHRM, "doAddWorkPlanByHrm")); + } + + if (((isSelf && canEditUserIcon()) || operatelevel > 0) && !status.equals("10")) {//设置个人头像 + rightMenus.add(new RightMenu(language, RightMenuType.BTN_SetUserIcon, "showPortraitSetting")); + } + + Map params = new HashMap<>(); + params.put("logSmallType", BizLogSmallType4Hrm.HRM_RSOURCE_CARD_BASE.getCode()); + params.put("targetId", id); + rightMenus.add(new RightMenu(language, RightMenuType.BTN_log, "showLog", params)); + + apidatas.put("rightMenus", rightMenus); + } catch (Exception e) { + writeLog(e); + apidatas.put("api_status", false); + apidatas.put("api_errormsg", "catch exception : " + e.getMessage()); + } + return JSONObject.toJSONString(apidatas); + } + + public String isAdmin(HttpServletRequest request, HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + Map result = new HashMap(); + String id = Util.null2String(request.getParameter("id")); + if (id.length() == 0) { + id = "" + user.getUID(); + } + result.put("isAdmin", ServiceUtil.isAdmin(id)); + return JSONObject.toJSONString(result); + } + + public String getQRCode(HttpServletRequest request, HttpServletResponse response) { + Map jsondata = new HashMap(); + Map options = new HashMap(); + User user = HrmUserVarify.getUser(request, response); + String id = Util.null2String(request.getParameter("id")); + if (id.equals("")) id = String.valueOf(user.getUID()); + + if(!"".equals(id) && !id.equals(""+user.getUID())){ + AppDetachComInfo adci = new AppDetachComInfo(); + if(adci.isUseAppDetach()){ + if(!adci.getScopeIds(user, "resource", id)) { + jsondata.put("status", "-1"); + jsondata.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage())); + return JSONObject.toJSONString(jsondata); + } + } + } + + try { + //var data = { "lastname": "吕益", "mobile": "13899998888","telephone":"021-99998888","email":"lvyi@weaver.com","jobtitle":"开发工程师","department":"人力资源组","locationname":"上海"}; + RecordSet rs = new RecordSet(); + DepartmentComInfo DepartmentComInfo = new DepartmentComInfo(); + JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo(); + LocationComInfo locationComInfo = new LocationComInfo(); + JobCallComInfo jobCallComInfo = new JobCallComInfo(); + HrmListValidate HrmListValidate = new HrmListValidate(); + + String sql = "select * from hrmresource where id=" + id; + rs.executeSql(sql); + if (rs.next()) { + String lastname = Util.toScreen(rs.getString("lastname"), user.getLanguage()); + String departmentid = Util.toScreen(rs.getString("departmentid"), user.getLanguage()); + String jobtitle = Util.toScreen(rs.getString("jobtitle"), user.getLanguage()); + String mobile = Util.toScreen(rs.getString("mobile"), user.getLanguage()); + String telephone = Util.toScreen(rs.getString("telephone"), user.getLanguage()); + String email = Util.toScreen(rs.getString("email"), user.getLanguage()); + String locationid = Util.toScreen(rs.getString("locationid"), user.getLanguage()); + String jobcallid = Util.toScreen(rs.getString("jobcall"), user.getLanguage()); + lastname = lastname.endsWith("\\") && !lastname.endsWith("\\\\") == true ? lastname + "\\" : lastname; + lastname = StringUtil.replace(lastname, "'", "\\\\'"); + boolean hasQRCode = HrmListValidate.isValidate(37); + + //隐私设置部分 + PrivacyComInfo pc = new PrivacyComInfo(); + Map mapShowSets = pc.getMapShowSets(); + Map mapShowTypeDefaults = pc.getMapShowTypeDefaults(); + mobile = PrivacyUtil.checkByPrivacy(id, user, "mobile", mobile, mapShowSets, mapShowTypeDefaults, pc); + telephone = PrivacyUtil.checkByPrivacy(id, user, "telephone", telephone, mapShowSets, mapShowTypeDefaults, pc); + email = PrivacyUtil.checkByPrivacy(id, user, "email", email, mapShowSets, mapShowTypeDefaults, pc); + + jsondata.put("hasQRCode", hasQRCode); + jsondata.put("options", options); + if (hasQRCode) { + options.put("lastname", lastname); + options.put("mobile", mobile); + options.put("telephone", telephone); + options.put("email", email); + options.put("jobtitle", jobTitlesComInfo.getJobTitlesname(jobtitle)); //对应的应该是岗位 + options.put("department", DepartmentComInfo.getDepartmentname(departmentid)); //对应的应该是职称 + //options.put("locationname", locationComInfo.getLocationname(departmentid)); + options.put("locationname", locationComInfo.getLocationname(locationid)); //对应的应该是工作地点 + } + } + } catch (Exception e) { + writeLog(e); + } + return JSONObject.toJSONString(jsondata); + } + + public String getHrmResourceItem(HttpServletRequest request, HttpServletResponse response) { + List> tablist = new ArrayList>(); + Map itemdata = new HashMap(); + User user = HrmUserVarify.getUser(request, response); + String resourceid = request.getParameter("id"); + boolean noLoadData = Util.null2String(request.getParameter("noLoadData")).equals("1");//不加载数据 + if (resourceid.equals("")) resourceid = String.valueOf(user.getUID()); + String currentUserId = "" + user.getUID(); + try { + boolean workflowshow = SysModuleInfoBiz.checkModuleStatus(ModuleConstants.Workflow); + boolean docshow = SysModuleInfoBiz.checkModuleStatus(ModuleConstants.Doc); + boolean customshow = SysModuleInfoBiz.checkModuleStatus(ModuleConstants.Crm); + boolean projectshow = SysModuleInfoBiz.checkModuleStatus(ModuleConstants.Project); + boolean cptshow = SysModuleInfoBiz.checkModuleStatus(ModuleConstants.Fa); + boolean coworkshow = SysModuleInfoBiz.checkModuleStatus(ModuleConstants.Cowork); + boolean weiboshow = SysModuleInfoBiz.checkModuleStatus(ModuleConstants.Blog); + + //流程 + if (workflowshow) { + int wf_count = 0; + if (!noLoadData) { + wf_count = new WorkflowRequestUtil().getRequestCount(user, resourceid); + } + itemdata = new HashMap(); + itemdata.put("name", "item_workflow"); + itemdata.put("label", SystemEnv.getHtmlLabelName(18015, user.getLanguage())); + itemdata.put("num", wf_count); + itemdata.put("icon", "/hrm/hrm_e9/image/workflow.png"); + itemdata.put("font-color", "#1ab7f4"); + itemdata.put("url", "/spa/workflow/static/index.html#/main/workflow/listDoing?resourceid=" + resourceid); + tablist.add(itemdata); + } + + //文档 + if (docshow) { + Object[] docInfo = new Object[]{"/spa/document/static/index.html#/main/document/search?viewcondition=2&doccreaterid=" + resourceid, "0"}; + if (!noLoadData) { + docInfo = new DocSearchComInfo().getDocCount4Hrm(resourceid, user); + } + itemdata = new HashMap(); + itemdata.put("name", "item_doc"); + itemdata.put("label", SystemEnv.getHtmlLabelName(58, user.getLanguage())); + itemdata.put("num", docInfo[1]); + itemdata.put("icon", "/hrm/hrm_e9/image/doc.png"); + itemdata.put("font-color", "#68c12c"); + itemdata.put("url", "/spa/document/static/index.html#/main/document/search?viewcondition=2&doccreaterid=" + resourceid); + tablist.add(itemdata); + } + + //客户 + if (customshow) { + String[] crmInfo = new String[]{"", "0"}; + if (!noLoadData) { + crmInfo = new CrmShareBase().getCrmCount4Hrm(resourceid, currentUserId); + } + itemdata = new HashMap(); + itemdata.put("name", "item_custom"); + itemdata.put("label", SystemEnv.getHtmlLabelName(136, user.getLanguage())); + itemdata.put("num", crmInfo[1]); + itemdata.put("icon", "/hrm/hrm_e9/image/custom.png"); + itemdata.put("font-color", "#558de4"); + itemdata.put("url", "/spa/crm/static/index.html#/main/crm/customer/hrmView?searchHrmId=" + resourceid); + tablist.add(itemdata); + } + + //项目 + if (projectshow) { + String[] prjInfo = new String[]{"/spa/prj/index.html#/main/prj/mineProject?search_resourceid=" + resourceid, "0"}; + if (!noLoadData) { + prjInfo = new SearchComInfo().getPrjCount4Hrm(resourceid, user); + } + itemdata = new HashMap(); + itemdata.put("name", "item_project"); + itemdata.put("label", SystemEnv.getHtmlLabelName(101, user.getLanguage())); + itemdata.put("num", prjInfo[1]); + itemdata.put("icon", "/hrm/hrm_e9/image/project.png"); + itemdata.put("font-color", "#29cf87"); + itemdata.put("url", "/spa/prj/index.html#/main/prj/mineProject?search_resourceid=" + resourceid); + tablist.add(itemdata); + } + + //资产 + if (cptshow) { + String url = "/spa/cpt/index.html#/main/cpt/mycapital?hrmid=" + resourceid; + String[] cptInfo = new String[]{url, "0"}; + if (!noLoadData) { + cptInfo = new CptSearchComInfo().getCptCount4Hrm(resourceid, user); + } + itemdata = new HashMap(); + itemdata.put("name", "item_cpt"); + itemdata.put("label", SystemEnv.getHtmlLabelName(535, user.getLanguage())); + itemdata.put("num", cptInfo[1]); + itemdata.put("icon", "/hrm/hrm_e9/image/cpt.png"); + itemdata.put("font-color", "#f6ae40"); + itemdata.put("url", url); + tablist.add(itemdata); + } + + //协作 + if (coworkshow) { + String[] coworkInfo = new String[]{"", "0"}; + if (!noLoadData) { + coworkInfo = new CoworkShareManager().getCoworkCount4Hrm(resourceid, currentUserId); + } + itemdata = new HashMap(); + itemdata.put("name", "item_cowork"); + itemdata.put("label", SystemEnv.getHtmlLabelName(17855, user.getLanguage())); + itemdata.put("num", coworkInfo[1]); + itemdata.put("icon", "/hrm/hrm_e9/image/cowork.png"); + itemdata.put("font-color", "#826efd"); + itemdata.put("url", "/spa/cowork/static/index.html#/main/cowork/hrmview?searchHrmid=" + resourceid); + tablist.add(itemdata); + } + + //微博 + if (weiboshow) { + String[] weiboInfo = new String[]{"", "0"}; + if (!noLoadData) { + weiboInfo = new BlogShareManager().getBlogCount4Hrm(resourceid); + } + itemdata = new HashMap(); + itemdata.put("name", "item_weibo"); + itemdata.put("label", SystemEnv.getHtmlLabelName(26467, user.getLanguage())); + itemdata.put("num", weiboInfo[1]); + itemdata.put("icon", "/hrm/hrm_e9/image/weibo.png"); + itemdata.put("font-color", "#fb6f47"); + itemdata.put("url", "/spa/blog/static/index.html#/user/" + resourceid); + tablist.add(itemdata); + } + } catch (Exception e) { + writeLog(e); + } + + return JSONObject.toJSONString(tablist); + } + + public String getHrmResourceTab(HttpServletRequest request, HttpServletResponse response) { + int isgoveproj = 0; + User user = HrmUserVarify.getUser(request, response); + String id = Util.null2String(request.getParameter("id")); + this.id = id; + this.isMobx = Util.null2String(request.getParameter("isMobx")).equals("1"); + if (id.equals("")) id = String.valueOf(user.getUID()); + List> tablist = new ArrayList>(); + try { + AppDetachComInfo AppDetachComInfo = new AppDetachComInfo(); + ResourceComInfo ResourceComInfo = new ResourceComInfo(); + AllManagers AllManagers = new AllManagers(); + HrmListValidate HrmListValidate = new HrmListValidate(); + CheckSubCompanyRight CheckSubCompanyRight = new CheckSubCompanyRight(); + MouldStatusCominfo MouldStatusCominfo = new MouldStatusCominfo(); + HrmResourceBaseTabComInfo HrmResourceBaseTabComInfo = new HrmResourceBaseTabComInfo(); + RecordSet rs = new RecordSet(); + + //人力资源模块是否开启了管理分权 + int hrmdetachable = 0; + HttpSession session = request.getSession(true); + ManageDetachComInfo ManageDetachComInfo = new ManageDetachComInfo(); + if (session.getAttribute("hrmdetachable") != null) { + hrmdetachable = Util.getIntValue(String.valueOf(session.getAttribute("hrmdetachable")), 0); + } else { + boolean isUseHrmManageDetach = ManageDetachComInfo.isUseHrmManageDetach(); + if (isUseHrmManageDetach) { + hrmdetachable = 1; + session.setAttribute("detachable", "1"); + session.setAttribute("hrmdetachable", String.valueOf(hrmdetachable)); + } else { + hrmdetachable = 0; + session.setAttribute("detachable", "0"); + session.setAttribute("hrmdetachable", String.valueOf(hrmdetachable)); + } + } + if (AppDetachComInfo.isUseAppDetach()) { + boolean isApp = true; + if(!AppDetachComInfo.getScopeIds(user, "resource",id)) { + isApp = false; + } + if (!isApp) { + String errMsg = SystemEnv.getHtmlLabelName(2012, user.getLanguage()); + HashMap jsondata = new HashMap(); + jsondata.put("errMsg", errMsg); + jsondata.put("status", "-1"); + return jsondata.toString(); + } + } + String departmentid = ""; + String subcompanyid = ""; + rs.executeProc("HrmResource_SelectByID", id); + if (rs.next()) { + departmentid = Util.toScreen(rs.getString("departmentid"), user.getLanguage()); /*所属部门*/ + subcompanyid = Util.toScreen(rs.getString("subcompanyid1"), user.getLanguage()); + } + + /*显示权限判断*/ + int userid = user.getUID(); + boolean isSelf = false; + boolean isManager = false; +// boolean isSys = ResourceComInfo.isSysInfoView(userid,id); +// boolean isCap = ResourceComInfo.isCapInfoView(userid,id); +// boolean ishasF =HrmUserVarify.checkUserRight("HrmResourceWelfareEdit:Edit",user); + boolean isSys = ResourceComInfo.isSysInfoView2(userid, id); + boolean isCap = ResourceComInfo.isCapInfoView2(userid, id); + boolean ishasF = HrmUserVarify.checkUserRight("HrmResourceWelfareEdit:Edit", user,departmentid) || ResourceComInfo.isFinInfoView2(userid, id); + ; + + + AllManagers.getAll(id); + if (id.equals("" + user.getUID())) { + isSelf = true; + } + while (AllManagers.next()) { + String tempmanagerid = AllManagers.getManagerID(); + if (tempmanagerid.equals("" + user.getUID())) { + isManager = true; + } + } + int idx = 0; + //tabInfo.put(SystemEnv.getHtmlLabelName(,user.getLanguage()), "/hrm/resource/HrmResourceBase.jsp?isfromtab=true&id="+id); + tablist.add(setTabInfo("HrmResourceBase", 1361, GCONST.getContextPath()+"/hrm/resource/HrmResourceBase.jsp?isfromtab=true&id=" + id, "/main/hrm/resource/HrmResourceBase/" + id, user)); + idx++; + + //原工作历程变为其他 + if (HrmListValidate.isValidate(29)) { + //tabInfo.put(SystemEnv.getHtmlLabelName(30804,user.getLanguage()), "/hrm/resource/HrmResourceTotal.jsp?isfromtab=true&id="+id); + tablist.add(setTabInfo("HrmResourceTotal", 30804, GCONST.getContextPath()+"/wui/index.html#/main/hrm/HrmResourceTotal" + id, "/main/hrm/HrmResourceTotal" + id, user)); + idx++; + } + + //tabInfo.put(SystemEnv.getHtmlLabelName(81554,user.getLanguage()), "/hrm/resource/HrmResourceGroupView.jsp?id="+id); + if (HrmListValidate.isValidate(64)) { + tablist.add(setTabInfo("HrmResourceGroupView", 81554, GCONST.getContextPath()+"/hrm/resource/HrmResourceGroupView.jsp?id=" + id, "/main/hrm/resource/HrmResourceGroupView/" + id, user)); + idx++; + } + + int operatelevel = -1; + if (hrmdetachable == 1) { + operatelevel = CheckSubCompanyRight.ChkComRightByUserRightCompanyId(user.getUID(), "HrmResourceEdit:Edit", Integer.parseInt(subcompanyid)); + } else { + if (HrmUserVarify.checkUserRight("HrmResourceEdit:Edit", user, departmentid)) { + operatelevel = 2; + } + } + int operatelevelnew = -1; + if (hrmdetachable == 1) { + operatelevelnew = CheckSubCompanyRight.ChkComRightByUserRightCompanyId(user.getUID(), "ResourcesInformationSystem:All", Integer.parseInt(subcompanyid)); + } else { + String departmentidtmp = ResourceComInfo.getDepartmentID(id); + if (HrmUserVarify.checkUserRight("ResourcesInformationSystem:All", user, departmentidtmp)) { + operatelevelnew = 2; + } + } + + StaticObj staticobj = StaticObj.getInstance(); + String software = (String) staticobj.getObject("software"); + if (software == null) software = "ALL"; + if (software.equals("ALL") || software.equals("HRM")) { + if ((isSelf || operatelevel >= 0) && HrmListValidate.isValidate(11)) { + //tabInfo.put(SystemEnv.getHtmlLabelName(15687,user.getLanguage()), "/hrm/resource/HrmResourcePersonalView.jsp?isfromtab=true&id="+id); + tablist.add(setTabInfo("HrmResourcePersonalView", 15687, GCONST.getContextPath()+"/hrm/resource/HrmResourcePersonalView.jsp?isfromtab=true&id=" + id, "/main/hrm/resource/HrmResourcePersonalView/" + id, user)); + idx++; + } + if ((isSelf || isManager || operatelevel >= 0) && HrmListValidate.isValidate(12)) { + //tabInfo.put(SystemEnv.getHtmlLabelName(15688,user.getLanguage()), "/hrm/resource/HrmResourceWorkView.jsp?isfromtab=true&id="+id); + tablist.add(setTabInfo("HrmResourceWorkView", 15688, GCONST.getContextPath()+"/hrm/resource/HrmResourceWorkView.jsp?isfromtab=true&id=" + id, "/main/hrm/resource/HrmResourceWorkView/" + id, user)); + idx++; + } + } + + if ((isSelf || operatelevelnew >= 0 || isSys) && HrmListValidate.isValidate(15)) { + //tabInfo.put(SystemEnv.getHtmlLabelName(15804,user.getLanguage()), "/hrm/resource/HrmResourceSystemView.jsp?isfromtab=true&id="+id+"&isView=1"); + tablist.add(setTabInfo("HrmResourceSystemView", 15804, GCONST.getContextPath()+"/hrm/resource/HrmResourceSystemView1.jsp?isfromtab=true&id=" + id + "&isView=1", "/main/hrm/resource/HrmResourceSystemView/" + id, user)); + idx++; + } + + if (software.equals("ALL") || software.equals("HRM")) { + if (isgoveproj == 0) { + if ((isSelf || ishasF) && HrmListValidate.isValidate(13)) { + //tabInfo.put(SystemEnv.getHtmlLabelName(16480,user.getLanguage()), "/hrm/resource/HrmResourceFinanceView.jsp?isfromtab=true&id="+id+"&isView=1"); + tablist.add(setTabInfo("HrmResourceFinanceView", 16480, GCONST.getContextPath()+"/hrm/resource/HrmResourceFinanceView.jsp?isfromtab=true&id=" + id + "&isView=1", "/main/hrm/resource/HrmResourceFinanceView/" + id, user)); + idx++; + } + } + if ((isSelf || operatelevel >= 0 || isCap) && HrmListValidate.isValidate(14) && "1".equals(MouldStatusCominfo.getStatus("cpt"))) { + String cpturl = GCONST.getContextPath()+"/cpt/search/SearchOperation.jsp?resourceid=" + id + "&isdata=2&from=hrmResourceBase"; + if (Cpt4modeUtil.isUse()) { + cpturl = GCONST.getContextPath()+"/formmode/search/CustomSearchBySimpleIframe.jsp?customid=" + Cpt4modeUtil.getSearchid("wdzc") + "&resourceid=" + id + "&from=hrmResourceBase&mymodetype=wdzc&sqlwhere=" + new XssUtil().put("where resourceid=" + id); + } + //tabInfo.put(SystemEnv.getHtmlLabelName(15806,user.getLanguage()), cpturl); + tablist.add(setTabInfo("iframe-" + (idx++) + "-cptsearch", 15806, GCONST.getContextPath()+"/spa/cpt/index.html#/main/cpt/mycapital?from=hrm&hrmid=" + id, "/spa/cpt/index.html#/main/cptcapital/mycapitalResult", user)); + } + } + + if ((isSelf || isManager || HrmUserVarify.checkUserRight("HrmResource:Workflow", user, departmentid)) && HrmListValidate.isValidate(17)) { + //tabInfo.put(SystemEnv.getHtmlLabelName(1207,user.getLanguage()), "/workflow/search/WFSearchTemp.jsp?method=all&viewScope=doing&complete=0&viewcondition=0&resourceid="+id); + tablist.add(setTabInfo("iframe-" + (idx++) + "-workflowsearch", 1207, GCONST.getContextPath()+"/spa/workflow/static/index.html#/main/workflow/listDoing?needTop=false&needTree=false&resourceid=" + id, "/spa/workflow/index.html#/main/workflow/listDoing", user)); + //tablist.add(setTabInfo("iframe-"+(idx++)+"-workflowsearch",1207,"/workflow/search/WFSearchTemp.jsp?method=all&viewScope=doing&complete=0&viewcondition=0&resourceid="+id,"/spa/workflow/index.html#/main/workflow/listDoing",user)); + } + if ((isSelf || isManager || HrmUserVarify.checkUserRight("HrmResource:Plan", user, departmentid)) && HrmListValidate.isValidate(18)) { + //tabInfo.put(SystemEnv.getHtmlLabelName(2192,user.getLanguage()), "/workplan/data/WorkPlan.jsp?resourceid="+id); + tablist.add(setTabInfo("iframe-" + (idx++) + "-workplansearch", 2192, GCONST.getContextPath()+"/spa/workplan/static/index.html#/main/wp/myWorkPlan?fromcard=true&selectedUser=" + id, "/main/workplan/data/WorkPlan", user)); + } + + if (isgoveproj == 0) { + if (software.equals("ALL") || software.equals("HRM")) { + if (isSelf || isManager || HrmUserVarify.checkUserRight("HrmResource:Absense", user, departmentid)) { + if (HrmListValidate.isValidate(20)) { + //tabInfo.put(SystemEnv.getHtmlLabelName(20080,user.getLanguage()), "/hrm/resource/HrmResourceAbsense.jsp?resourceid="+id); + tablist.add(setTabInfo("HrmResourceAbsense", 20080, GCONST.getContextPath()+"/hrm/resource/HrmResourceAbsense.jsp?resourceid=" + id, "/main/hrm/HrmResourceAbsense", user)); + idx++; + } + } + if (isSelf || isManager || HrmUserVarify.checkUserRight("HrmResource:TrainRecord", user)) { + if (HrmListValidate.isValidate(21)) { + //tabInfo.put(SystemEnv.getHtmlLabelName(816,user.getLanguage()), "/hrm/resource/HrmResourceTrainRecord.jsp?resourceid="+id); + tablist.add(setTabInfo("HrmResourceTrainRecord", 816, GCONST.getContextPath()+"/hrm/resource/HrmResourceTrainRecord.jsp?resourceid=" + id, "/main/hrm/resource/HrmResourceTrainRecord/" + id, user)); + idx++; + } + } + if (isSelf || isManager || HrmUserVarify.checkUserRight("HrmResource:RewardsRecord", user)) { + if (HrmListValidate.isValidate(22)) { + //tabInfo.put(SystemEnv.getHtmlLabelName(16065,user.getLanguage()), "/hrm/resource/HrmResourceRewardsRecordView.jsp?id="+id); + tablist.add(setTabInfo("HrmResourceRewardsRecordView", 16065, GCONST.getContextPath()+"/hrm/resource/HrmResourceRewardsRecordView.jsp?id=" + id, "/main/hrm/resource/HrmResourceRewardsRecordView/" + id, user)); + idx++; + } + } + } + } + + //判断该用户对编辑人员机构是否具有的角色维护权限(TD19119) + boolean rolesmanage = false; + int varifylevel = -1; + if (hrmdetachable == 1) { + varifylevel = CheckSubCompanyRight.ChkComRightByUserRightCompanyId(user.getUID(), "HrmRolesEdit:Edit", Integer.parseInt(subcompanyid)); + if (varifylevel > 0) { + if (HrmUserVarify.checkUserRight("HrmRolesEdit:Edit", user)) { + varifylevel = 2; + } else { + varifylevel = -1; + } + } + } else { + if (HrmUserVarify.checkUserRight("HrmRolesEdit:Edit", user)) { + varifylevel = 2; + } + } + if (varifylevel > 0) { + rolesmanage = true; + } + + if (HrmUserVarify.checkUserRight("HrmResourceEdit:Edit", user, departmentid) && rolesmanage) { + //tabInfo.put(SystemEnv.getHtmlLabelName(16527,user.getLanguage()), "/hrm/roles/HrmResourceNewRoles.jsp?resourceid="+id ); + tablist.add(setTabInfo("HrmResourceNewRoles", 16527, GCONST.getContextPath()+"/hrm/roles/HrmResourceNewRoles.jsp?resourceid=" + id, "/main/hrm/resource/HrmResourceNewRoles/" + id, user)); + idx++; + } + + //取自定义标签页 + HrmResourceBaseTabComInfo.setTofirstRow(); + while (HrmResourceBaseTabComInfo.next()) { + if (!HrmResourceBaseTabComInfo.getIsopen().equals("1")) { + continue; + } + String tab_urlTemp = HrmResourceBaseTabComInfo.getLinkurl(); + String tab_urlTemp1 = tab_urlTemp.replaceAll("\\Q{#id}", "" + id); + if (tab_urlTemp1.indexOf("?") >= 0) { + tab_urlTemp1 += "&hrmResourceID=" + id; + } else { + tab_urlTemp1 += "?hrmResourceID=" + id; + } + String groupname = HrmResourceBaseTabComInfo.getGroupName(); + if (HrmResourceBaseTabComInfo.getTabnum().trim().length() != 0) { + try { + Class c = Class.forName(HrmResourceBaseTabComInfo.getTabnum().trim()); + Object cObject = c.newInstance(); + Method m = c.getMethod("execute"); + Method method = c.getMethod("setOwnerid", String.class); + method.invoke(cObject, "" + id); + method = c.getMethod("setUserid", String.class); + method.invoke(cObject, "" + user.getUID()); + int num = (Integer) m.invoke(cObject); + groupname += "(" + num + ")"; + } catch (Exception e) { + e.printStackTrace(); + groupname += "(error)"; + } + } + tablist.add(setTabInfo("iframe-" + (idx++) + "-DefineTab" + id, groupname, tab_urlTemp1, "", user)); + } + + List> tablist1 = new ArrayList>(); + for (Map obj : tablist) { + if (!obj.isEmpty()) { + tablist1.add(obj); + } + } + tablist = tablist1; + } catch (Exception e) { + writeLog(e); + } + return JSONObject.toJSONString(tablist); + } + + /** + * 设置tabInfo 后续可以考虑直接读取数据 + * + * @param key + * @param labelid + * @param url + * @param rotueurl + * @param user + * @return + */ + private Map setTabInfo(String key, int labelid, String url, String rotueurl, User user) { + return setTabInfo(key, "" + labelid, url, rotueurl, user); + } + + /** + * 设置tabInfo 后续可以考虑直接读取数据 + * + * @param key + * @param labelid + * @param url + * @param rotueurl + * @param user + * @return + */ + private Map setTabInfo(String key, String labelid, String url, String rotueurl, User user) { + Map tabObj = new HashMap(); + if (isMobx) { + tabObj = getTabInfo4Mobx(key, labelid, url, rotueurl, user); + } else { + tabObj.put("key", key); + if (key.indexOf("DefineTab") != -1) { + tabObj.put("value", labelid); + } else { + tabObj.put("value", SystemEnv.getHtmlLabelNames(labelid, user.getLanguage())); + } + tabObj.put("url", url); + tabObj.put("rotueurl", rotueurl); + } + return tabObj; + } + + private Map getTabInfo4Mobx(String key, String labelid, String url, String rotueurl, User user) { + Map tabObj = new HashMap(); + + if (key.equals("HrmResourceBase")) { + key = "cardInfo"; + } else if (key.equals("HrmResourcePersonalView")) { + key = "cardPersonal"; + } else if (key.equals("HrmResourceWorkView")) { + key = "cardWork"; + } else if (key.equals("HrmResourceSystemView")) { + key = "cardSystemInfo"; + } else if (key.equals("HrmResourceFinanceView")) { + key = "cardFinance"; + } else if (key.equals("HrmResourceAbsense")) { + key = "cardChecking"; + /*判断是否开启了新考勤,如果开启了,那么人员卡片上面的考勤情况也需要切换成新版考勤的路由*/ + KQ122Util kq122Util = new KQ122Util(); + if (kq122Util.is122Open()) { + key = "cardCheckingN"; + } + } else if (key.equals("HrmResourceTrainRecord")) { + key = "cardTrainRecord"; + } else if (key.equals("HrmResourceRewardsRecordView")) { + key = "cardRewardsRecord"; + } else if (key.equals("HrmResourceNewRoles")) { + key = "cardRoleSet"; + } else if (key.equals("HrmResourceTotal")) { + key = "cardTotal"; + } else if (key.equals("HrmResourceGroupView")) { + key = "addGroup"; + } + + if (key.indexOf("DefineTab") != -1) { + tabObj.put("title", labelid); + } else { + tabObj.put("title", SystemEnv.getHtmlLabelNames(labelid, user.getLanguage())); + } + tabObj.put("key", key); + tabObj.put("pathname", "main/hrm/card/" + key + "/" + this.id); + tabObj.put("isIframe", key.startsWith("iframe-")); + if (key.startsWith("iframe-")) { + tabObj.put("url", url); + } + return tabObj; + } + + + /** + * 普通人员只编辑后台开启允许个人修改的字段 + * + * @param request + * @param response + * @return + */ + public String getResourceContactForm(HttpServletRequest request, HttpServletResponse response) { + Map result = new HashMap(); + List lsGroup = new ArrayList(); + Map groupitem = null; + List itemlist = null; + try { + //基本信息 + User user = HrmUserVarify.getUser(request, response); + String id = Util.null2String(request.getParameter("id")); + int viewattr = Util.getIntValue(request.getParameter("viewattr"), 1); + if (id.length() == 0) { + id = "" + user.getUID(); + } + result.put("id", id); + + Map buttons = new Hashtable(); + if (isHasModify(-1)) { + buttons.put("hasEdit", true); + buttons.put("hasSave", true); + } + result.put("buttons", buttons); + result.put("editcontact", "1"); + + UserPrivacyComInfo upc = new UserPrivacyComInfo(); + PrivacyComInfo pc = new PrivacyComInfo(); + PrivacyBaseComInfo privacyBaseComInfo = new PrivacyBaseComInfo(); + Map mapShowSets = pc.getMapShowSets(); + Map mapShowTypes = pc.getMapShowTypes(); + Map mapShowTypeDefaults = pc.getMapShowTypeDefaults(); + //总体的大开关的默认设置 + Map mapBaseShowTypeDefaults = privacyBaseComInfo.getMapShowTypeDefaults(); + + StaticObj staticobj = StaticObj.getInstance(); + String multilanguage = (String) staticobj.getObject("multilanguage"); + if (multilanguage == null) multilanguage = "n"; + boolean isMultilanguageOK = false; + if (multilanguage.equals("y")) isMultilanguageOK = true; + boolean flagaccount = GCONST.getMOREACCOUNTLANDING(); + int scopeId = -1; + HrmFieldGroupComInfo HrmFieldGroupComInfo = new HrmFieldGroupComInfo(); + HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo(); + HrmFieldManager hfm = new HrmFieldManager("HrmCustomFieldByInfoType", scopeId); + hfm.isReturnDecryptData(true); + CustomFieldManager cfm = new CustomFieldManager("HrmCustomFieldByInfoType", scopeId); + hfm.getHrmData(Util.getIntValue(id)); + cfm.getCustomData(Util.getIntValue(id)); + + while (HrmFieldGroupComInfo.next()) { + int grouptype = Util.getIntValue(HrmFieldGroupComInfo.getType()); + if (grouptype != scopeId) continue; + int grouplabel = Util.getIntValue(HrmFieldGroupComInfo.getLabel()); + int groupid = Util.getIntValue(HrmFieldGroupComInfo.getid()); + hfm.getCustomFields(groupid); + + groupitem = new HashMap(); + itemlist = new ArrayList(); + groupitem.put("title", SystemEnv.getHtmlLabelName(grouplabel, user.getLanguage())); + groupitem.put("hide", hfm.getContactEditCount() == 0 || !Util.null2String(HrmFieldGroupComInfo.getIsShow()).equals("1")); + groupitem.put("defaultshow", true); + groupitem.put("items", itemlist); + groupitem.put("col", 1); + lsGroup.add(groupitem); + while (hfm.next()) { + int tmpviewattr = viewattr; + String fieldName = hfm.getFieldname(); + String cusFieldname = ""; + String fieldValue = ""; + if (hfm.isBaseField(fieldName)) { + fieldValue = hfm.getHrmData(fieldName); + } else { + cusFieldname = "customfield" + hfm.getFieldid(); + fieldValue = Util.null2String(new EncryptUtil().decrypt("cus_fielddata","field" + hfm.getFieldid(),"HrmCustomFieldByInfoType",""+scopeId,cfm.getData("field" + hfm.getFieldid()),true,true)); + } + + if (!hfm.isUse()||(!hfm.isModify())) { + HrmFieldBean hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname(cusFieldname.length() > 0 ? cusFieldname : fieldName); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(fieldValue); + hrmFieldBean.setIsFormField(true); + Map otherParams = new HashMap(); + otherParams.put("hide", true); + hrmFieldBean.setOtherparam(otherParams); + SearchConditionItem searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + + itemlist.add(searchConditionItem); + continue; + } + + if (fieldName.equals("systemlanguage") && !isMultilanguageOK) continue; + if (fieldName.equals("accounttype") && !flagaccount) continue; + if (fieldName.equalsIgnoreCase("jobGroupId")) { + continue; + } + + if (fieldName.equals("departmentvirtualids")||fieldName.equals("messagerurl")) + continue; + + if (fieldName.equals("resourceimageid")) { + groupitem.put("hasResourceImage", true); + if (fieldValue.equals("0")) fieldValue = ""; + if(fieldValue.length()>0){ + fieldValue = DocDownloadCheckUtil.checkPermission(fieldValue,user); + } + } + + org.json.JSONObject hrmFieldConf = hfm.getHrmFieldConf(fieldName); + HrmFieldBean hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldid((String) hrmFieldConf.get("id")); + hrmFieldBean.setFieldname(cusFieldname.length() > 0 ? cusFieldname : fieldName); + hrmFieldBean.setFieldlabel(hfm.getLable()); + hrmFieldBean.setFieldhtmltype((String) hrmFieldConf.get("fieldhtmltype")); + hrmFieldBean.setType((String) hrmFieldConf.get("type")); + hrmFieldBean.setDmlurl((String) hrmFieldConf.get("dmlurl")); + hrmFieldBean.setIssystem("" + (Integer) hrmFieldConf.get("issystem")); + if (hrmFieldBean.getFieldname().equals("departmentid")) { + hrmFieldBean.setFieldvalue(Util.null2String(request.getParameter("departmentid"))); + } + hrmFieldBean.setFieldvalue(fieldValue); + hrmFieldBean.setIsFormField(true); + + if (fieldName.equals("mobile") || fieldName.equals("email") || + fieldName.equals("fax") || fieldName.equals("telephone") || fieldName.equals("mobilecall")|| fieldName.equals("workcode")) { + hrmFieldBean.setMultilang(false); + } + + if (((String) hrmFieldConf.get("ismand")).equals("1")) { + if (hrmFieldBean.getFieldname().equals("managerid")) { + + } else { + tmpviewattr = 3; + } + } + + if (hrmFieldBean.getFieldname().equals("status")) {//状态不能编辑 + tmpviewattr = 1; + } + + if (fieldName.equals("belongto") && flagaccount) { + tmpviewattr = 3; + } + String rules = ""; + if(tmpviewattr==3){ + rules = "required|string"; + } + hrmFieldBean.setRules(rules); + SearchConditionItem searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + if (searchConditionItem == null) continue; +// if (fieldName.equals("sex")) { +// List options = new ArrayList(); +// options.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(28473, user.getLanguage()), true)); +// options.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(28474, user.getLanguage()))); +// searchConditionItem.setOptions(options); +// } +// if (fieldName.equals("accounttype")) { +// List options = new ArrayList(); +// options.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(17746, user.getLanguage()), true)); +// options.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(17747, user.getLanguage()))); +// searchConditionItem.setOptions(options); +// } + if (fieldName.equals("belongto") && flagaccount) { + XssUtil xssUtil = new XssUtil(); + String accountSql = "(accounttype=0 or accounttype is null)"; + searchConditionItem.getBrowserConditionParam().getDataParams().put("sqlwhere", xssUtil.put(accountSql)); + searchConditionItem.getBrowserConditionParam().getCompleteParams().put("sqlwhere", xssUtil.put(accountSql)); + searchConditionItem.getBrowserConditionParam().getDestDataParams().put("sqlwhere", xssUtil.put(accountSql)); + } + if (searchConditionItem.getBrowserConditionParam() != null) { + searchConditionItem.getBrowserConditionParam().setViewAttr(tmpviewattr); + if (hrmFieldBean.getFieldname().equals("departmentid")) { + searchConditionItem.getBrowserConditionParam().getDataParams().put("rightStr", "HrmResourceAdd:Add"); + searchConditionItem.getBrowserConditionParam().getCompleteParams().put("rightStr", "HrmResourceAdd:Add"); + } + } + searchConditionItem.setViewAttr(tmpviewattr); + itemlist.add(searchConditionItem); + + if (mapShowSets != null && mapShowSets.get(fieldName) != null) { + String mobileShowSet = Util.null2String(mapShowSets.get(fieldName)); + String mobileShowType = Util.null2String(mapShowTypes.get(fieldName)); + String mapShowTypeDefault = Util.null2String(mapShowTypeDefaults.get(fieldName)); + + String baseMobileShowTypeDefaults = Util.null2String(mapBaseShowTypeDefaults.get(fieldName)); + + if (mobileShowSet.equals("1")) { + String comPk = id + "__" + fieldName; + fieldValue = Util.null2String(upc.getPvalue(comPk)); + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname(fieldName + "showtype"); + hrmFieldBean.setFieldlabelname(SystemEnv.getHtmlLabelNames(hfm.getLable(), user.getLanguage()) + SystemEnv.getHtmlLabelName(385571, user.getLanguage())); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + hrmFieldBean.setIssystem("1"); + hrmFieldBean.setIsFormField(true); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + if (searchConditionItem == null) continue; + List statusOptions = new ArrayList(); + if (mobileShowType.indexOf("1") != -1) { + if (fieldValue.length() > 0) { + statusOptions.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(2161, user.getLanguage()), fieldValue.equals("1"))); + } else if (baseMobileShowTypeDefaults.indexOf("1") != -1) { + statusOptions.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(2161, user.getLanguage()), true)); + } else { + statusOptions.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(2161, user.getLanguage()))); + } + } + if (mobileShowType.indexOf("2") != -1) { + if (fieldValue.length() > 0) { + statusOptions.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(32670, user.getLanguage()), fieldValue.equals("2"))); + } else if (baseMobileShowTypeDefaults.indexOf("2") != -1) { + statusOptions.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(32670, user.getLanguage()), true)); + } else { + statusOptions.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(32670, user.getLanguage()))); + } + } + if (mobileShowType.indexOf("3") != -1) { + if (fieldValue.length() > 0) { + statusOptions.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(32671, user.getLanguage()), fieldValue.equals("3"))); + } else if (baseMobileShowTypeDefaults.indexOf("3") != -1) { + statusOptions.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(32671, user.getLanguage()), true)); + } else { + statusOptions.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(32671, user.getLanguage()))); + } + } + searchConditionItem.setValue(fieldValue); + searchConditionItem.setOptions(statusOptions); + itemlist.add(searchConditionItem); + } + } + } + if (itemlist.size()== 0) lsGroup.remove(groupitem); + } + + result.put("conditions", lsGroup); + } catch (Exception e) { + writeLog(e); + } + + Map retmap = new HashMap(); + retmap.put("result", result); + return JSONObject.toJSONString(retmap); + } + + /** + * 获取人员基本信息编辑表单 + * + * @param request + * @param response + * @return + */ + public String getResourceBaseForm(HttpServletRequest request, HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + + Map result = new HashMap(); + try { + //基本信息 + HrmListValidate HrmListValidate = new HrmListValidate(); + String id = Util.null2String(request.getParameter("id")).trim(); + if (id.length() == 0) { + id = "" + user.getUID(); + } + + AppDetachComInfo AppDetachComInfo = new AppDetachComInfo(); + if (AppDetachComInfo.isUseAppDetach()) { + boolean isApp = true; + if(!AppDetachComInfo.getScopeIds(user, "resource",id)) { + isApp = false; + } + if (!isApp) { + String errMsg = SystemEnv.getHtmlLabelName(2012, user.getLanguage()); + HashMap jsondata = new HashMap(); + jsondata.put("errMsg", errMsg); + jsondata.put("status", "-1"); + return JSONObject.toJSONString(jsondata); + } + } + + + result.put("id", id); + boolean isSelf = false; + if (id.equals("" + user.getUID())) { + isSelf = true; + } + HttpSession session = request.getSession(true); + String subcompanyid = ""; + String departmentId = ""; + String status = ""; + RecordSet rs = new RecordSet(); + rs.executeSql("select subcompanyid1,departmentid, status from hrmresource where id = " + id); + if (rs.next()) { + subcompanyid = Util.toScreen(rs.getString("subcompanyid1"), user.getLanguage()); + departmentId = Util.toScreen(rs.getString("departmentid"), user.getLanguage()); + status = Util.toScreen(rs.getString("status"), user.getLanguage()); + if (subcompanyid == null || subcompanyid.equals("") || subcompanyid.equalsIgnoreCase("null")) { + subcompanyid = "-1"; + } + session.setAttribute("hrm_subCompanyId", subcompanyid); + } + //人力资源模块是否开启了管理分权,如不是,则不显示框架,直接转向到列表页面(新的分权管理) + int hrmdetachable = 0; + if (session.getAttribute("hrmdetachable") != null) { + hrmdetachable = Util.getIntValue(String.valueOf(session.getAttribute("hrmdetachable")), 0); + } else { + boolean isUseHrmManageDetach = new ManageDetachComInfo().isUseHrmManageDetach(); + if (isUseHrmManageDetach) { + hrmdetachable = 1; + session.setAttribute("detachable", "1"); + session.setAttribute("hrmdetachable", String.valueOf(hrmdetachable)); + } else { + hrmdetachable = 0; + session.setAttribute("detachable", "0"); + session.setAttribute("hrmdetachable", String.valueOf(hrmdetachable)); + } + } + int operatelevel = -1; + if (hrmdetachable == 1) { + operatelevel = new CheckSubCompanyRight().ChkComRightByUserRightCompanyId(user.getUID(), "HrmResourceEdit:Edit", Integer.parseInt(subcompanyid)); + } else { + if (HrmUserVarify.checkUserRight("HrmResourceEdit:Edit", user, departmentId)) { + operatelevel = 2; + } + } + if (operatelevel > 0) { + } else if (isSelf) { + return getResourceContactForm(request, response); + } + + Map buttons = new Hashtable(); + if (((isSelf&&isHasModify(-1))|| operatelevel > 0) && !status.equals("10")) {//编辑 + buttons.put("hasEdit", true); + buttons.put("hasSave", true); + } + result.put("hasJobTitlesAdd", HrmUserVarify.checkUserRight("HrmJobTitlesAdd:Add", user)); + result.put("buttons", buttons); + result.put("conditions", getFormFields(request, response, false)); + result.put("validate", getValidate(user)); + } catch (Exception e) { + writeLog(e); + } + + Map retmap = new HashMap(); + retmap.put("result", result); + return JSONObject.toJSONString(retmap); + } + + /** + * 人员基本信息表单字段 + * + * @param request + * @param response + * @return + */ + public List getFormFields(HttpServletRequest request, HttpServletResponse response, boolean isAdd) { + List lsGroup = new ArrayList(); + try { + User user = HrmUserVarify.getUser(request, response); + Map groupitem = null; + List itemlist = null; + ChgPasswdReminder reminder = new ChgPasswdReminder(); + RemindSettings settings = reminder.getRemindSettings(); + + String id = Util.null2String(request.getParameter("id")); + if (id.length() == 0) { + id = "" + user.getUID(); + } + UserPrivacyComInfo upc = new UserPrivacyComInfo(); + PrivacyComInfo pc = new PrivacyComInfo(); + PrivacyBaseComInfo privacyBaseComInfo = new PrivacyBaseComInfo(); + Map mapShowSets = pc.getMapShowSets(); + Map mapShowTypes = pc.getMapShowTypes(); + Map mapShowTypeDefaults = pc.getMapShowTypeDefaults(); + //总体的大开关的默认设置 + Map mapBaseShowTypeDefaults = privacyBaseComInfo.getMapShowTypeDefaults(); + + StaticObj staticobj = StaticObj.getInstance(); + String multilanguage = (String) staticobj.getObject("multilanguage"); + if (multilanguage == null) multilanguage = "n"; + boolean isMultilanguageOK = false; + if (multilanguage.equals("y")) isMultilanguageOK = true; + boolean flagaccount = GCONST.getMOREACCOUNTLANDING(); + int viewattr = isAdd ? 2 : Util.getIntValue(request.getParameter("viewattr"), 1); + int scopeId = -1; + HrmFieldGroupComInfo HrmFieldGroupComInfo = new HrmFieldGroupComInfo(); + HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo(); + hrmFieldSearchConditionComInfo.setIsMobile(Util.null2String(request.getParameter("ismobile"))); + HrmFieldManager hfm = new HrmFieldManager("HrmCustomFieldByInfoType", scopeId); + hfm.isReturnDecryptData(true); + CustomFieldManager cfm = new CustomFieldManager("HrmCustomFieldByInfoType", scopeId); + hfm.getHrmData(Util.getIntValue(id)); + cfm.getCustomData(Util.getIntValue(id)); + + while (HrmFieldGroupComInfo.next()) { + int grouptype = Util.getIntValue(HrmFieldGroupComInfo.getType()); + if (grouptype != scopeId) continue; + int grouplabel = Util.getIntValue(HrmFieldGroupComInfo.getLabel()); + int groupid = Util.getIntValue(HrmFieldGroupComInfo.getid()); + hfm.getCustomFields(groupid); + //if(hfm.getGroupCount()==0)continue; + + groupitem = new HashMap(); + itemlist = new ArrayList(); + groupitem.put("title", SystemEnv.getHtmlLabelName(grouplabel, user.getLanguage())); + groupitem.put("defaultshow", true); + groupitem.put("hide", hfm.getGroupCount() == 0 || !Util.null2String(HrmFieldGroupComInfo.getIsShow()).equals("1")); + groupitem.put("items", itemlist); + lsGroup.add(groupitem); + while (hfm.next()) { + int tmpviewattr = viewattr; + String fieldName = hfm.getFieldname(); + String cusFieldname = ""; + String fieldValue = ""; + if (hfm.isBaseField(fieldName)) { + fieldValue = hfm.getHrmData(fieldName); + } else { + cusFieldname = "customfield" + hfm.getFieldid(); + if (isAdd) cusFieldname = "customfield_0_" + hfm.getFieldid(); + fieldValue = Util.null2String(new EncryptUtil().decrypt("cus_fielddata","field" + hfm.getFieldid(),"HrmCustomFieldByInfoType",""+scopeId,cfm.getData("field" + hfm.getFieldid()),true,true)); + } + + if (!hfm.isUse()) { + HrmFieldBean hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname(cusFieldname.length() > 0 ? cusFieldname : fieldName); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("1"); + if (!isAdd) { + hrmFieldBean.setFieldvalue(fieldValue); + } + hrmFieldBean.setIsFormField(true); + Map otherParams = new HashMap(); + otherParams.put("hide", true); + hrmFieldBean.setOtherparam(otherParams); + SearchConditionItem searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + itemlist.add(searchConditionItem); + continue; + } + if (fieldName.equals("resourceimageid")) { + groupitem.put("hasResourceImage", true); + if (fieldValue.equals("0")) fieldValue = ""; + if(fieldValue.length()>0){ + fieldValue = DocDownloadCheckUtil.checkPermission(fieldValue,user); + } + } + if (fieldName.equals("loginid") || fieldName.equals("jobactivity") || fieldName.equals("departmentvirtualids")||fieldName.equals("messagerurl")) + continue; + if (fieldName.equalsIgnoreCase("jobGroupId")) { + continue; + } + if (!isAdd && fieldName.equals("status")) { + continue; + } + if (fieldName.equals("systemlanguage") && !isMultilanguageOK) continue; + if (fieldName.equals("accounttype") && !flagaccount) continue; + org.json.JSONObject hrmFieldConf = hfm.getHrmFieldConf(fieldName); + HrmFieldBean hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldid((String) hrmFieldConf.get("id")); + hrmFieldBean.setFieldname(cusFieldname.length() > 0 ? cusFieldname : fieldName); + hrmFieldBean.setFieldlabel(hfm.getLable()); + hrmFieldBean.setFieldhtmltype((String) hrmFieldConf.get("fieldhtmltype")); + hrmFieldBean.setType((String) hrmFieldConf.get("type")); + hrmFieldBean.setDmlurl((String) hrmFieldConf.get("dmlurl")); + hrmFieldBean.setIssystem("" + (Integer) hrmFieldConf.get("issystem")); + if (hrmFieldBean.getFieldname().equals("departmentid")) { + hrmFieldBean.setFieldvalue(Util.null2String(request.getParameter("departmentid"))); + } + if (!isAdd) { + hrmFieldBean.setFieldvalue(fieldValue); + } + hrmFieldBean.setIsFormField(true); + + if (fieldName.equals("mobile") || fieldName.equals("email") || + fieldName.equals("fax") || fieldName.equals("telephone") || fieldName.equals("mobilecall")|| fieldName.equals("workcode")) { + hrmFieldBean.setMultilang(false); + } + + if (((String) hrmFieldConf.get("ismand")).equals("1")) { + if (hrmFieldBean.getFieldname().equals("managerid")) { + + } else { + tmpviewattr = 3; + } + } + + if (fieldName.equals("belongto") && flagaccount) { + tmpviewattr = 3; + } + String rules = ""; + if(tmpviewattr==3){ + rules = "required|string"; + } + hrmFieldBean.setRules(rules); + SearchConditionItem searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + + if("departmentid".equals(hrmFieldBean.getFieldname())){ + DepartmentComInfo comInfo =new DepartmentComInfo(); + List> replaceDatas = new ArrayList>(); + Map datas = new HashMap(); + if(!"".equals(fieldValue)){ + String deptname =""; + try { + deptname =comInfo.getDepartmentname(fieldValue); + } catch (Exception e) { + new BaseBean().writeLog(e); + } + datas.put("id",fieldValue); + datas.put("name",deptname); + replaceDatas.add(datas); + } + searchConditionItem.getBrowserConditionParam().setReplaceDatas(replaceDatas); + } + + if (searchConditionItem == null) continue; +// if (fieldName.equals("sex")) { +// List options = new ArrayList(); +// options.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(28473, user.getLanguage()), true)); +// options.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(28474, user.getLanguage()))); +// searchConditionItem.setOptions(options); +// } +// if (fieldName.equals("accounttype")) { +// List options = new ArrayList(); +// options.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(17746, user.getLanguage()), true)); +// options.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(17747, user.getLanguage()))); +// searchConditionItem.setOptions(options); +// } + if (fieldName.equals("belongto") && flagaccount) { + XssUtil xssUtil = new XssUtil(); + String accountSql = "(accounttype=0 or accounttype is null)"; + searchConditionItem.getBrowserConditionParam().getDataParams().put("sqlwhere", xssUtil.put(accountSql)); + searchConditionItem.getBrowserConditionParam().getCompleteParams().put("sqlwhere", xssUtil.put(accountSql)); + searchConditionItem.getBrowserConditionParam().getDestDataParams().put("sqlwhere", xssUtil.put(accountSql)); + } + if (searchConditionItem.getBrowserConditionParam() != null) { + searchConditionItem.getBrowserConditionParam().setViewAttr(tmpviewattr); + if (hrmFieldBean.getFieldname().equals("departmentid")) { + searchConditionItem.getBrowserConditionParam().getDataParams().put("rightStr", "HrmResourceAdd:Add"); + searchConditionItem.getBrowserConditionParam().getCompleteParams().put("rightStr", "HrmResourceAdd:Add"); + } + } + searchConditionItem.setViewAttr(tmpviewattr); + if (isAdd && fieldName.equals("status")) { + List statusOptions = new ArrayList(); + statusOptions.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(15710, user.getLanguage()), true)); + statusOptions.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(15711, user.getLanguage()))); + statusOptions.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(480, user.getLanguage()))); + searchConditionItem.setOptions(statusOptions); + } + itemlist.add(searchConditionItem); + + if (mapShowSets != null && mapShowSets.get(fieldName) != null) { + String mobileShowSet = Util.null2String(mapShowSets.get(fieldName)); + String mobileShowType = Util.null2String(mapShowTypes.get(fieldName)); + String mapShowTypeDefault = Util.null2String(mapShowTypeDefaults.get(fieldName)); + + String baseMobileShowTypeDefaults = Util.null2String(mapBaseShowTypeDefaults.get(fieldName)); + + if (mobileShowSet.equals("1")) { +// userid+"__"+ptype + String comPk = id + "__" + fieldName; + fieldValue = Util.null2String(upc.getPvalue(comPk)); + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname(fieldName + "showtype"); + hrmFieldBean.setFieldlabelname(SystemEnv.getHtmlLabelNames(hfm.getLable(), user.getLanguage()) + SystemEnv.getHtmlLabelName(385571, user.getLanguage())); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + hrmFieldBean.setIssystem("1"); + hrmFieldBean.setIsFormField(true); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + if (searchConditionItem == null) continue; + List statusOptions = new ArrayList(); + if (mobileShowType.indexOf("1") != -1) { + if (fieldValue.length() > 0) { + statusOptions.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(2161, user.getLanguage()), fieldValue.equals("1"))); + } else if (baseMobileShowTypeDefaults.indexOf("1") != -1) { + statusOptions.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(2161, user.getLanguage()), true)); + } else { + statusOptions.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(2161, user.getLanguage()))); + } + } + if (mobileShowType.indexOf("2") != -1) { + if (fieldValue.length() > 0) { + statusOptions.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(32670, user.getLanguage()), fieldValue.equals("2"))); + } else if (baseMobileShowTypeDefaults.indexOf("2") != -1) { + statusOptions.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(32670, user.getLanguage()), true)); + } else { + statusOptions.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(32670, user.getLanguage()))); + } + } + if (mobileShowType.indexOf("3") != -1) { + if (fieldValue.length() > 0) { + statusOptions.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(32671, user.getLanguage()), fieldValue.equals("3"))); + } else if (baseMobileShowTypeDefaults.indexOf("3") != -1) { + statusOptions.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(32671, user.getLanguage()), true)); + } else { + statusOptions.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(32671, user.getLanguage()))); + } + } + searchConditionItem.setValue(fieldValue); + searchConditionItem.setOptions(statusOptions); + itemlist.add(searchConditionItem); + } + } + +// if(fieldName.equals("mobile")){ +// String mobileShowSet = Util.null2String(settings.getMobileShowSet()); +// String mobileShowType = Util.null2String(settings.getMobileShowType()); +// if(mobileShowSet.equals("1")){ +// String sql = ""; +// RecordSet rs = new RecordSet(); +// sql = "select costcenterid,mobileshowtype from HrmResource where id = "+Util.getIntValue(id,-1); +// rs.executeSql(sql); +// if(rs.next()){ +// fieldValue = Util.null2String(rs.getString("mobileshowtype")); +// } +// if(isAdd){ +// fieldValue = Util.null2String(settings.getMobileShowTypeDefault()); +// } +// hrmFieldBean = new HrmFieldBean(); +// hrmFieldBean.setFieldname("mobileshowtype"); +// hrmFieldBean.setFieldlabel("32684"); +// hrmFieldBean.setFieldhtmltype("5"); +// hrmFieldBean.setType("1"); +// hrmFieldBean.setIssystem("1"); +// hrmFieldBean.setIsFormField(true); +// searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); +// if(searchConditionItem==null)continue; +// List statusOptions = new ArrayList(); +// if(mobileShowType.indexOf("1")!=-1){ +// statusOptions.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(2161,user.getLanguage()),fieldValue.equals("1"))); +// }if(mobileShowType.indexOf("2")!=-1){ +// statusOptions.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(32670,user.getLanguage()),fieldValue.equals("2"))); +// }if(mobileShowType.indexOf("3")!=-1){ +// statusOptions.add(new SearchConditionOption("3",SystemEnv.getHtmlLabelName(32671,user.getLanguage()),fieldValue.equals("3"))); +// } +// searchConditionItem.setOptions(statusOptions); +// itemlist.add(searchConditionItem); +// } +// } + } + if (itemlist.size() == 0) lsGroup.remove(groupitem); + } + } catch (Exception e) { + writeLog(e); + } + return lsGroup; + } + + /** + * 查看人员基本信息 + * + * @param request + * @param response + * @return + */ + public String getResourceBaseView(HttpServletRequest request, HttpServletResponse response) { + Map retmap = new HashMap(); + try { + HrmListValidate HrmListValidate = new HrmListValidate(); + User user = HrmUserVarify.getUser(request, response); + String id = Util.null2String(request.getParameter("id")); + if (id.length() == 0) { + id = "" + user.getUID(); + } + AppDetachComInfo AppDetachComInfo = new AppDetachComInfo(); + if (AppDetachComInfo.isUseAppDetach()) { + boolean isApp = true; + if(!AppDetachComInfo.getScopeIds(user, "resource",id)) { + isApp = false; + } + if (!isApp) { + String errMsg = SystemEnv.getHtmlLabelName(2012, user.getLanguage()); + HashMap jsondata = new HashMap(); + jsondata.put("errMsg", errMsg); + jsondata.put("status", "-1"); + return JSONObject.toJSONString(jsondata); + } + } + + if (id.equals("")) id = String.valueOf(user.getUID()); + String status = ""; + String subcompanyid = "", departmentId = ""; + int scopeId = -1; + RecordSet rs = new RecordSet(); + HttpSession session = request.getSession(true); + rs.executeSql("select subcompanyid1, status, departmentId from hrmresource where id = " + id); + if (rs.next()) { + status = Util.toScreen(rs.getString("status"), user.getLanguage()); + subcompanyid = Util.toScreen(rs.getString("subcompanyid1"), user.getLanguage()); + departmentId = StringUtil.vString(rs.getString("departmentId")); + if (subcompanyid == null || subcompanyid.equals("") || subcompanyid.equalsIgnoreCase("null")) + subcompanyid = "-1"; + session.setAttribute("hrm_subCompanyId", subcompanyid); + } + + boolean isSelf = false; + if (id.equals("" + user.getUID())) { + isSelf = true; + } + int operatelevel = -1; + //人力资源模块是否开启了管理分权,如不是,则不显示框架,直接转向到列表页面(新的分权管理) + int hrmdetachable = 0; + ManageDetachComInfo ManageDetachComInfo = new ManageDetachComInfo(); + if (session.getAttribute("hrmdetachable") != null) { + hrmdetachable = Util.getIntValue(String.valueOf(session.getAttribute("hrmdetachable")), 0); + } else { + boolean isUseHrmManageDetach = ManageDetachComInfo.isUseHrmManageDetach(); + if (isUseHrmManageDetach) { + hrmdetachable = 1; + session.setAttribute("detachable", "1"); + session.setAttribute("hrmdetachable", String.valueOf(hrmdetachable)); + } else { + hrmdetachable = 0; + session.setAttribute("detachable", "0"); + session.setAttribute("hrmdetachable", String.valueOf(hrmdetachable)); + } + } + if (hrmdetachable == 1) { + CheckSubCompanyRight CheckSubCompanyRight = new CheckSubCompanyRight(); + operatelevel = CheckSubCompanyRight.ChkComRightByUserRightCompanyId(user.getUID(), "HrmResourceEdit:Edit", Integer.parseInt(subcompanyid)); + } else { + if (HrmUserVarify.checkUserRight("HrmResourceEdit:Edit", user, departmentId)) { + operatelevel = 2; + } + } + Map buttons = new Hashtable(); + if (((isSelf && isHasModify(-1)) || operatelevel > 0) && !status.equals("10")) { + buttons.put("hasEdit", true); + buttons.put("hasSave", true); + } + retmap.put("buttons", buttons); + + RecordSet RecordSet = new RecordSet(); + SubCompanyComInfo SubCompanyComInfo = new SubCompanyComInfo(); + DepartmentComInfo DepartmentComInfo = new DepartmentComInfo(); + ResourceComInfo resourceComInfo = new ResourceComInfo(); + JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo(); + JobActivitiesComInfo jobActivitiesComInfo = new JobActivitiesComInfo(); + LocationComInfo locationComInfo = new LocationComInfo(); + LanguageComInfo languageComInfo = new LanguageComInfo(); + HrmResourceFile hrmResourceFile = new HrmResourceFile(); + HrmFieldGroupComInfo hrmFieldGroupComInfo = new HrmFieldGroupComInfo(); + ResourceBelongtoComInfo resourceBelongtoComInfo = new ResourceBelongtoComInfo(); + HrmFieldManager hfm = new HrmFieldManager("HrmCustomFieldByInfoType", scopeId); + CustomFieldManager cfm = new CustomFieldManager("HrmCustomFieldByInfoType", scopeId); + + String sql = ""; + + List> grouplist = new ArrayList>(); + Map jsondata = null; + + Map item1 = new HashMap();//姓名等头部信息lastname,workcode,sex,orginfo + Map item2 = new HashMap();//账号信息accounttype,accounts,managerid,subordinatescount,status,lastlogindate + Map item3 = new HashMap();//系统登录维护信息createrid,createdate,lastmoddate,lastmodid + grouplist.add(item1); + grouplist.add(item2); + grouplist.add(item3); + List itemlist1 = new ArrayList(); + List itemlist2 = new ArrayList(); + List itemlist3 = new ArrayList(); + item1.put("title", ""+ SystemEnv.getHtmlLabelName(10004508,weaver.general.ThreadVarLanguage.getLang())+""); + item1.put("id", "item1"); + item1.put("defaultshow", true); + item1.put("items", itemlist1); + + item2.put("title", ""+ SystemEnv.getHtmlLabelName(10004509,weaver.general.ThreadVarLanguage.getLang())+""); + item2.put("id", "item2"); + item2.put("defaultshow", true); + item2.put("items", itemlist2); + + item3.put("title", SystemEnv.getHtmlLabelName(2023, user.getLanguage())); + item3.put("id", "item3"); + item3.put("defaultshow", true); + item3.put("items", itemlist3); + + PrivacyComInfo pc = new PrivacyComInfo(); + Map mapShowSets = pc.getMapShowSets(); + Map mapShowTypes = pc.getMapShowTypes(); + Map mapShowTypeDefaults = pc.getMapShowTypeDefaults(); + + UserPrivacyComInfo upc = new UserPrivacyComInfo(); + //基本信息 + sql = "select * from hrmresource where id=" + id; + rs.executeSql(sql); + if (rs.next()) { + String lastname = Util.toScreen(rs.getString("lastname"), user.getLanguage()); + String workcode = Util.toScreen(rs.getString("workcode"), user.getLanguage()); + String sex = Util.toScreen(rs.getString("sex"), user.getLanguage()); + subcompanyid = Util.toScreen(rs.getString("subcompanyid1"), user.getLanguage()); + String departmentid = Util.toScreen(rs.getString("departmentid"), user.getLanguage()); + int accounttype = Util.getIntValue(rs.getString("accounttype"), 0); + String managerid = Util.toScreen(rs.getString("managerid"), user.getLanguage()); + String assistantid = Util.toScreen(rs.getString("assistantid"), user.getLanguage()); + status = Util.toScreen(rs.getString("status"), user.getLanguage()); + String lastlogindate = Util.toScreen(rs.getString("lastlogindate"), user.getLanguage()); + String createrid = Util.toScreen(rs.getString("createrid"), user.getLanguage()); + String createdate = Util.toScreen(rs.getString("createdate"), user.getLanguage()); + String lastmoddate = Util.toScreen(rs.getString("lastmoddate"), user.getLanguage()); + String lastmodid = Util.toScreen(rs.getString("lastmodid"), user.getLanguage()); + String jobtitle = Util.toScreen(rs.getString("jobtitle"), user.getLanguage()); + String jobcall = Util.toScreen(rs.getString("jobcall"), user.getLanguage()); + String joblevel = Util.toScreen(rs.getString("joblevel"), user.getLanguage()); + String jobactivitydesc = Util.toScreen(rs.getString("jobactivitydesc"), user.getLanguage()); + String locationid = Util.toScreen(rs.getString("loactionid"), user.getLanguage()); + String systemlanguage = Util.toScreen(rs.getString("systemlanguage"), user.getLanguage()); + String mobile = resourceComInfo.getMobileShow(id, user); + String fax = Util.toScreen(rs.getString("fax"), user.getLanguage()); + String telephone = Util.toScreen(rs.getString("telephone"), user.getLanguage()); + String email = Util.toScreen(rs.getString("email"), user.getLanguage()); + String mobilecall = Util.toScreen(rs.getString("mobilecall"), user.getLanguage()); + String workroom = Util.toScreen(rs.getString("workroom"), user.getLanguage()); + String resourceimageid = Util.getFileidOut(rs.getString("resourceimageid")); + String messagerurl = Util.null2String(rs.getString("messagerurl")); + String ismobile = Util.null2String(request.getParameter("ismobile")); + /*最后登录时间已存储至另一张表*/ + String lastLoginDateSql = "select * from userlastlogindate where userId=?"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(lastLoginDateSql, id); + if (recordSet.next()) { + lastlogindate = recordSet.getString("lastLoginDate"); + } + + lastname = lastname.endsWith("\\") && !lastname.endsWith("\\\\") == true ? lastname + "\\" : lastname; + lastname = StringUtil.replace(lastname, "'", "\\\\'"); + + jsondata = new HashMap(); + jsondata.put("name", "lastname"); + jsondata.put("label", SystemEnv.getHtmlLabelName(413, user.getLanguage())); + jsondata.put("value", lastname); + itemlist1.add(jsondata); + + jsondata = new HashMap(); + jsondata.put("name", "messagerurl"); + jsondata.put("label", SystemEnv.getHtmlLabelName(24513, user.getLanguage())); + jsondata.put("value", resourceComInfo.getMessagerUrls(id)); + itemlist1.add(jsondata); + + + jsondata = new HashMap(); + jsondata.put("name", "workcode"); + jsondata.put("label", SystemEnv.getHtmlLabelName(714, user.getLanguage())); + jsondata.put("value", workcode); + itemlist1.add(jsondata); + + jsondata = new HashMap(); + jsondata.put("name", "sex"); + jsondata.put("label", SystemEnv.getHtmlLabelName(416, user.getLanguage())); + jsondata.put("sex", sex);//0:男性,1:女性 + if (sex.equals("0")) { + jsondata.put("value", SystemEnv.getHtmlLabelName(28473, user.getLanguage())); + } else if (sex.equals("1")) { + jsondata.put("value", SystemEnv.getHtmlLabelName(28474, user.getLanguage())); + } + itemlist1.add(jsondata); + + jsondata = new HashMap(); + jsondata.put("name", "orginfo"); + jsondata.put("label", SystemEnv.getHtmlLabelName(376, user.getLanguage())); + jsondata.put("value", DepartmentComInfo.getAllParentDepartmentNames(departmentid, subcompanyid)); + itemlist1.add(jsondata); + + jsondata = new HashMap(); + jsondata.put("name", "resourceimageid"); + jsondata.put("label", SystemEnv.getHtmlLabelName(15707, user.getLanguage())); + String url = ""; + if (!resourceimageid.equals("0") && resourceimageid.length() > 0 && HrmListValidate.isValidate(36)) { + String mainControlHost = Util.null2String(Prop.getInstance().getPropValue("Others", "MAINCONTROLHOST")); + url = mainControlHost + "/weaver/weaver.file.FileDownload?fileid=" + resourceimageid; + } else { + if (sex.equals("") || sex.equals("0")) { + url = "/images/messageimages/temp/man_wev8.png"; + } else if (sex.equals("1")) { + url = "/images/messageimages/temp/women_wev8.png"; + } + } + jsondata.put("value", url); + itemlist2.add(jsondata); + + jsondata = new HashMap(); + Map options = new HashMap(); + jsondata.put("options", options); + itemlist2.add(jsondata); + + //var data = { "lastname": "吕益", "mobile": "13899998888","telephone":"021-99998888","email":"lvyi@weaver.com","jobtitle":"开发工程师","department":"人力资源组","locationname":"上海"}; + options.put("lastname", lastname); + options.put("mobile", mobile); + options.put("telephone", telephone); + options.put("email", email); + options.put("jobtitle", jobTitlesComInfo.getJobTitlesname(joblevel)); + options.put("department", DepartmentComInfo.getDepartmentname(departmentid)); + options.put("locationname", locationComInfo.getLocationname(departmentid)); + + + List lsOption = new ArrayList(); + jsondata = new HashMap(); + + jsondata.put("options", lsOption); + itemlist2.add(jsondata); + Map option = null; + + option = new HashMap();//发消息 + option.put("id", id); + option.put("validateId", "33"); + option.put("name", "sendEmessage"); + option.put("funname", "sendEmessage"); + option.put("title", SystemEnv.getHtmlLabelName(127379, user.getLanguage())); + lsOption.add(option); + + option = new HashMap();//发送短信 + option.put("id", id); + option.put("validateId", "31"); + option.put("name", "openmessage"); + option.put("funname", "sendSmsMessage"); + option.put("title", SystemEnv.getHtmlLabelName(16635, user.getLanguage())); + lsOption.add(option); + + option = new HashMap();//发送邮件 + option.put("id", id); + option.put("validateId", "19"); + option.put("name", "openemail"); + option.put("funname", "sendMail"); + option.put("title", SystemEnv.getHtmlLabelName(2051, user.getLanguage())); + lsOption.add(option); + + option = new HashMap();//新建日程 + option.put("id", id); + option.put("validateId", "32"); + option.put("name", "doAddWorkPlan"); + option.put("funname", "doAddWorkPlanByHrm"); + option.put("title", SystemEnv.getHtmlLabelName(18481, user.getLanguage())); + lsOption.add(option); + + List> ls = new ArrayList>(); + jsondata = new HashMap(); + jsondata.put("accountinfo", ls); + itemlist2.add(jsondata); + String value = ""; + String showName = ""; + List accounts = new VerifyLogin().getAccountsById(Integer.valueOf(id).intValue()); + Iterator iter = null; + if (accounts != null) iter = accounts.iterator(); + Account current = new Account(); + while (iter != null && iter.hasNext()) { + Account a = (Account) iter.next(); + if (("" + a.getId()).equals(id)) + current = a; + } + if (GCONST.getMOREACCOUNTLANDING()) { + jsondata = new HashMap(); + jsondata.put("name", "accounttype"); + jsondata.put("label", SystemEnv.getHtmlLabelName(17745, user.getLanguage())); + jsondata.put("value", accounttype == 0 ? SystemEnv.getHtmlLabelName(17746, user.getLanguage()) : SystemEnv.getHtmlLabelName(17747, user.getLanguage())); + ls.add(jsondata); + + List lsUser = resourceBelongtoComInfo.getBelongtousers("" + id); + if (lsUser != null && lsUser.size() > 0 && current.getType() == 0) { + jsondata = new HashMap(); + jsondata.put("name", "accounts"); + jsondata.put("label", SystemEnv.getHtmlLabelName(17747, user.getLanguage())); + jsondata.put("value", "" + lsUser.size()+""); + ls.add(jsondata); + } + + if (current.getType() == 1) { + jsondata = new HashMap(); + jsondata.put("name", "belongto"); + jsondata.put("label", SystemEnv.getHtmlLabelName(17746, Util.getIntValue(user.getLanguage()))); + jsondata.put("value", resourceComInfo.getBelongTo(id)); + jsondata.put("showName", resourceComInfo.getLastname(resourceComInfo.getBelongTo(id))); + jsondata.put("isOpenHrm", true); + ls.add(jsondata); + } + +// if(current.getType()==1){ +// jsondata = new HashMap(); +// jsondata.put("name","accounts"); +// jsondata.put("label",SystemEnv.getHtmlLabelNames("17747,141,124",user.getLanguage())); +// iter=accounts.iterator(); +// while(accounts.size()>1&&iter.hasNext()){ +// Account a=(Account)iter.next(); +// if(a.getType()==0){ +// String subcompanyname=SubCompanyComInfo.getSubCompanyname(""+a.getSubcompanyid()); +// String departmentname=DepartmentComInfo.getDepartmentname(""+a.getDepartmentid()); +// String jobtitlename=jobTitlesComInfo.getJobTitlesname(""+a.getJobtitleid()); +// //<%=subcompanyname+"/"+departmentname+"/"+jobtitlename%> +// } +// } +// jsondata.put("value",""+accounts.size()); +// ls.add(jsondata); +// } + } + + if (Util.null2String(managerid).length() > 0) { + value = managerid; + showName = resourceComInfo.getLastname(managerid); + if (showName.length() > 0) { + jsondata = new HashMap(); + jsondata.put("name", "managerid"); + jsondata.put("label", SystemEnv.getHtmlLabelName(15709, user.getLanguage())); + jsondata.put("value", value); + jsondata.put("showName", showName); + ls.add(jsondata); + } + } + + RecordSet.executeProc("HrmResource_SCountBySubordinat", id); + RecordSet.next(); + int subordinatescount = RecordSet.getInt(1); + if (subordinatescount > 0) { + jsondata = new HashMap(); + jsondata.put("name", "subordinatescount"); + jsondata.put("label", SystemEnv.getHtmlLabelName(442, user.getLanguage())); + jsondata.put("value", "" + subordinatescount + ""); + ls.add(jsondata); + } + + if (Util.null2String(assistantid).length() > 0 && hfm.isUse("assistantid")) { + value = assistantid; + showName = resourceComInfo.getLastname(assistantid); + if (showName.length() > 0) { + jsondata = new HashMap(); + jsondata.put("name", "assistantid"); + jsondata.put("label", SystemEnv.getHtmlLabelName(441, user.getLanguage())); + jsondata.put("value", value); + jsondata.put("showName", showName); + ls.add(jsondata); + } + } + + jsondata = new HashMap(); + jsondata.put("name", "status"); + jsondata.put("label", SystemEnv.getHtmlLabelName(602, user.getLanguage())); + jsondata.put("value", HrmFieldUtil.getResourceStatusName(status, user)); + ls.add(jsondata); + + jsondata = new HashMap(); + jsondata.put("name", "lastlogindate"); + jsondata.put("label", SystemEnv.getHtmlLabelName(16067, user.getLanguage())); + jsondata.put("value", lastlogindate); + ls.add(jsondata); + + jsondata = new HashMap(); + jsondata.put("name", "createrid"); + jsondata.put("label", SystemEnv.getHtmlLabelName(882, user.getLanguage())); + value = ""; + showName = ""; + if (Util.null2String(createrid).length() > 0) { + value = createrid; + showName = resourceComInfo.getLastname(createrid); + } + jsondata.put("value", value); + jsondata.put("showName", showName); + ls.add(jsondata); + + jsondata = new HashMap(); + jsondata.put("name", "createdate"); + jsondata.put("label", SystemEnv.getHtmlLabelName(1339, user.getLanguage())); + jsondata.put("value", createdate); + ls.add(jsondata); + + jsondata = new HashMap(); + jsondata.put("name", "lastmodid"); + jsondata.put("label", SystemEnv.getHtmlLabelName(3002, user.getLanguage())); + value = ""; + showName = ""; + if (Util.null2String(lastmodid).length() > 0) { + value = lastmodid; + showName = resourceComInfo.getLastname(lastmodid); + } + jsondata.put("value", value); + jsondata.put("showName", showName); + ls.add(jsondata); + + jsondata = new HashMap(); + jsondata.put("name", "lastmoddate"); + jsondata.put("label", SystemEnv.getHtmlLabelName(19521, user.getLanguage())); + jsondata.put("value", lastmoddate); + ls.add(jsondata); + + + Map item = new HashMap(); + List itemlist = new ArrayList(); + grouplist.add(item); + item.put("title", SystemEnv.getHtmlLabelName(1361, user.getLanguage())); + item.put("defaultshow", true); + item.put("items", itemlist); + + jsondata = new HashMap(); + jsondata.put("label", SystemEnv.getHtmlLabelName(6086, user.getLanguage())); + jsondata.put("type", "position"); + jsondata.put("value", "" + Util.toScreen(jobTitlesComInfo.getJobTitlesmark(jobtitle), user.getLanguage()) + ""); + itemlist.add(jsondata); + + boolean hasbaseGroup = false; + rs.executeSql(" select count(*) from hrm_formfield where fieldid = 0 and isuse =1 "); + if (rs.next()) { + if (rs.getInt(1) > 0) hasbaseGroup = true; + } + if (hasbaseGroup) { + jsondata = new HashMap(); + jsondata.put("label", SystemEnv.getHtmlLabelName(1915, user.getLanguage())); + jsondata.put("value", Util.toScreen(jobActivitiesComInfo.getJobActivitiesmarks(jobTitlesComInfo.getJobactivityid(jobtitle)), user.getLanguage())); + itemlist.add(jsondata); + } + + //其他特殊字段 + hfm.getCustomFields(1);//取得基本信息 + hfm.getHrmData(Util.getIntValue(id)); + cfm.getCustomData(Util.getIntValue(id)); + while (hfm.next()) { + if (!hfm.isUse()) continue; + int fieldlabel = Util.getIntValue(hfm.getLable()); + String fieldName = hfm.getFieldname(); + int fieldId = hfm.getFieldid(); + if (fieldName.equals("loginid") || fieldName.equals("workcode") || fieldName.equals("lastname") || fieldName.equals("sex") || + fieldName.equals("accounttype") || fieldName.equals("belongto") || fieldName.equals("departmentid") || + fieldName.equals("jobtitle") || (!ismobile.equals("1") && fieldName.equals("status")) || fieldName.equals("resourceimageid") || fieldName.equals("messagerurl") || fieldName.equals("jobactivity") || fieldName.equalsIgnoreCase("jobGroupId")) { + continue; + } + int type = hfm.getType(); + String dmlurl = hfm.getDmrUrl(); + int fieldhtmltype = Util.getIntValue(hfm.getHtmlType()); + String fieldValue = ""; + if (hfm.isBaseField(fieldName)) { + fieldValue = hfm.getHrmData(fieldName); + } else { + fieldValue = Util.null2String(new EncryptUtil().decrypt("cus_fielddata","field" + hfm.getFieldid(),"HrmCustomFieldByInfoType",""+scopeId,cfm.getData("field" + hfm.getFieldid()),false,true)); + } + + if (hfm.getHtmlType().equals("3")) { + fieldValue = hfm.getHtmlBrowserFieldvalue(user, dmlurl, fieldId, fieldhtmltype, type, fieldValue, "0"); + } else { + fieldValue = hfm.getFieldvalue(user, dmlurl, fieldId, fieldhtmltype, type, fieldValue, Util.getIntValue(request.getParameter("ismobile"))); + } + + if (mapShowSets != null && mapShowSets.get(fieldName) != null) { + String mobileShowSet = Util.null2String(mapShowSets.get(fieldName)); + String showTypeDefault = Util.null2String(mapShowTypeDefaults.get(fieldName)); + if (mobileShowSet.equals("1")) { + String comPk = id + "__" + fieldName; + String comPkValue = Util.null2String(upc.getPvalue(comPk)); + if (comPkValue.length() > 0) { + fieldValue = upc.getShow(id, user, fieldName, fieldValue, comPkValue); + } else { + fieldValue = pc.getShow(id, user, fieldName, fieldValue, showTypeDefault); + } + } else { + fieldValue = pc.getShow(id, user, fieldName, fieldValue, showTypeDefault); + } + } + + if (fieldName.equals("mobile")) {//手机号码格式化 + fieldValue = ResourceComInfo.formatMobile(fieldValue); + } + + jsondata = new HashMap(); + jsondata.put("label", SystemEnv.getHtmlLabelName(fieldlabel, user.getLanguage())); + jsondata.put("value", fieldValue); + itemlist.add(jsondata); + } + + hrmFieldGroupComInfo.setTofirstRow(); + hfm.beforeFirst(); + cfm.beforeFirst(); + while (hrmFieldGroupComInfo.next()) { + int grouptype = Util.getIntValue(hrmFieldGroupComInfo.getType()); + int groupid = Util.getIntValue(hrmFieldGroupComInfo.getid()); + if (grouptype != scopeId || groupid == 1) continue; + int grouplabel = Util.getIntValue(hrmFieldGroupComInfo.getLabel()); + + hfm.getCustomFields(groupid); + if (hfm.getGroupCount() == 0) continue; + + if (groupid == 3) { + boolean tmp_flag = false; + while (hfm.next()) { + if (!hfm.isUse()) continue; + String fieldName = hfm.getFieldname(); + if (fieldName.equals("managerid") || fieldName.equals("assistantid")) { + continue; + } + tmp_flag = true; + break; + } + if (!tmp_flag) continue; + hfm.beforeFirst(); + } + item = new HashMap(); + itemlist = new ArrayList(); + grouplist.add(item); + item.put("title", SystemEnv.getHtmlLabelName(grouplabel, user.getLanguage())); + item.put("defaultshow", true); + item.put("hide", !Util.null2String(hrmFieldGroupComInfo.getIsShow()).equals("1")); + item.put("items", itemlist); + if (grouplabel == 32946) { + item.put("SupSub", true); + } + while (hfm.next()) { + if (!hfm.isUse()) continue; + int fieldlabel = Util.getIntValue(hfm.getLable()); + String fieldName = hfm.getFieldname(); + int fieldId = hfm.getFieldid(); + int type = hfm.getType(); + String dmlurl = hfm.getDmrUrl(); + int fieldhtmltype = Util.getIntValue(hfm.getHtmlType()); + String fieldValue = ""; + + if (fieldName.equals("managerid") || fieldName.equals("assistantid")) { + continue; + } + + if (hfm.isBaseField(fieldName)) { + fieldValue = hfm.getHrmData(fieldName); + } else { + fieldValue = Util.null2String(new EncryptUtil().decrypt("cus_fielddata","field" + hfm.getFieldid(),"HrmCustomFieldByInfoType",""+scopeId,cfm.getData("field" + hfm.getFieldid()),false,true)); + } + + if (mapShowSets != null && mapShowSets.get(fieldName) != null) { + String mobileShowSet = Util.null2String(mapShowSets.get(fieldName)); + String showTypeDefault = Util.null2String(mapShowTypeDefaults.get(fieldName)); + if (mobileShowSet.equals("1")) { + String comPk = id + "__" + fieldName; + String comPkValue = Util.null2String(upc.getPvalue(comPk)); + if (comPkValue.length() > 0) { + fieldValue = upc.getShow(id, user, fieldName, fieldValue, comPkValue); + } else { + fieldValue = pc.getShow(id, user, fieldName, fieldValue, showTypeDefault); + } + } else { + fieldValue = pc.getShow(id, user, fieldName, fieldValue, showTypeDefault); + } + } + + //一些特殊处理 + if (fieldName.equals("mobile")) {//手机号码格式化 + fieldValue = ResourceComInfo.formatMobile(fieldValue); + } + + if (hfm.getHtmlType().equals("3")) { + fieldValue = hfm.getHtmlBrowserFieldvalue(user, dmlurl, fieldId, fieldhtmltype, type, fieldValue, "0"); + } else { + fieldValue = hfm.getFieldvalue(user, dmlurl, fieldId, fieldhtmltype, type, fieldValue, Util.getIntValue(request.getParameter("ismobile"))); + } + + if (fieldName.equals("email")) { + fieldValue = "" + fieldValue + ""; + } + if (fieldName.equals("locationid")) { + fieldValue = "" + fieldValue + ""; + } + + jsondata = new HashMap(); + jsondata.put("label", SystemEnv.getHtmlLabelName(fieldlabel, user.getLanguage())); + jsondata.put("value", fieldValue); + if (fieldName.equals("email")) { + jsondata.put("type", "email");//邮件(手机端标识) + } + if (fieldName.equals("mobile")) { + jsondata.put("type", "mobile");//手机号码(手机端标识) + } + if (fieldName.equals("telephone")) { + jsondata.put("type", "telephone");//电话号码(手机端标识) + } + if (fieldName.equals("mobilecall")) { + jsondata.put("type", "mobilecall");//其他电话(手机端标识) + } + itemlist.add(jsondata); + } + } + + retmap.put("validate", getValidate(user)); + retmap.put("result", grouplist); + /*手机端需要用到的分部ID和部门ID*/ + retmap.put("subcompanyId", resourceComInfo.getSubCompanyID(id));//分部ID + retmap.put("departmentId", resourceComInfo.getSubCompanyID(id));//部门ID + } + } catch (Exception e) { + writeLog(e); + } + + return JSONObject.toJSONString(retmap); + } + + public Map getValidate(User user) { + Map retmap = new LinkedHashMap(); + try { + HrmListValidate hrmListValidate = new HrmListValidate(); + Map map = null; + + /*手机端显示的顺序必须是:发送消息、发送短信、发送邮件*/ + map = new HashMap(); + map.put("isValidate", hrmListValidate.isValidate(33) && HrmValidate.hasEmessage(user)); + map.put("validateName", SystemEnv.getHtmlLabelName(513224, user.getLanguage())); + map.put("mobileUse", true); + retmap.put("33", map); + + String[] validateIds = new String[]{"31", "19", "32", "36", "37", "38"}; + String[] validateTitles = new String[]{"16635", "2051", "18481", "15707", "30184", "83704"}; + for (int i = 0; i < validateIds.length; i++) { + String validateId = validateIds[i]; + map = new HashMap(); + map.put("isValidate", hrmListValidate.isValidate(Util.getIntValue(validateIds[i]))); + map.put("validateName", SystemEnv.getHtmlLabelNames(validateTitles[i], user.getLanguage())); + if (validateId.equals("19") || validateId.equals("31") || validateId.equals("32")) { + map.put("mobileUse", true); + } + retmap.put(validateIds[i], map); + } + } catch (Exception e) { + writeLog(e); + } + return retmap; + } + + public Map addResourceBase(HttpServletRequest request, HttpServletResponse response) { + return addResourceBase(request, response, true); + } + + /** + * 新建人员基本信息 + * + * @param request + * @param response + * @return + */ + public Map addResourceBase(HttpServletRequest request, HttpServletResponse response, boolean needSync) { + Map retmap = new HashMap(); + try { + retmap.put("id", "0"); + User user = HrmUserVarify.getUser(request, response); + LN LN = new LN(); + RecordSet rs = new RecordSet(); + DepartmentComInfo DepartmentComInfo = new DepartmentComInfo(); + ResourceComInfo ResourceComInfo = new ResourceComInfo(); + SalaryManager SalaryManager = new SalaryManager(); + ChgPasswdReminder reminder = new ChgPasswdReminder(); + RemindSettings settings = reminder.getRemindSettings(); + SysRemindWorkflow SysRemindWorkflow = new SysRemindWorkflow(); + CustomFieldTreeManager CustomFieldTreeManager = new CustomFieldTreeManager(); + DepartmentVirtualComInfo DepartmentVirtualComInfo = new DepartmentVirtualComInfo(); + + String para = ""; + FileUpload fu = new FileUpload(request); + String cmd = Util.null2String(fu.getParameter("cmd")); + String id = Util.null2String(fu.getParameter("id")); + String workcode = Util.fromScreen3(fu.getParameter("workcode"), user.getLanguage()); + String lastname = Util.fromScreen3(fu.getParameter("lastname"), user.getLanguage()).trim(); + String sex = Util.fromScreen3(fu.getParameter("sex"), user.getLanguage()); + //String resourceimageid= Util.null2String(fu.uploadFiles("photoid")); + String resourceimageid = Util.null2String(fu.getParameter("resourceimageid")); + if (resourceimageid.length() > 0) { + resourceimageid = "" + DocDownloadCheckUtil.getDownloadfileidstr(resourceimageid); + if(Util.getIntValue(resourceimageid, 0)>0){ + rs.executeQuery("select imagefilename from imagefile where imagefileid=?", resourceimageid); + if(rs.next()){ + String imagefilename = Util.null2String(rs.getString("imagefilename")).trim(); + if(imagefilename.length()>0){ + String imgUrl = Util.null2String(imagefilename.substring(imagefilename.lastIndexOf(".")+1)).trim().toLowerCase(); + if(!"jpg".equals(imgUrl) && !"gif".equals(imgUrl) && !"png".equals(imgUrl)){ + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(132006, user.getLanguage())); + return retmap; + } + } + } + } + } + String departmentid = Util.fromScreen3(fu.getParameter("departmentid"), user.getLanguage()); + String costcenterid = Util.fromScreen3(fu.getParameter("costcenterid"), user.getLanguage()); + String jobtitle = Util.fromScreen3(fu.getParameter("jobtitle"), user.getLanguage()); + String joblevel = Util.fromScreen3(fu.getParameter("joblevel"), user.getLanguage()); + String jobactivitydesc = Util.fromScreen3(fu.getParameter("jobactivitydesc"), user.getLanguage()); + String managerid = Util.fromScreen3(fu.getParameter("managerid"), user.getLanguage()); + String assistantid = Util.fromScreen3(fu.getParameter("assistantid"), user.getLanguage()); + String status = Util.fromScreen3(fu.getParameter("status"), user.getLanguage()); + String locationid = Util.fromScreen3(fu.getParameter("locationid"), user.getLanguage()); + String workroom = Util.fromScreen3(fu.getParameter("workroom"), user.getLanguage()); + String telephone = Util.fromScreen3(fu.getParameter("telephone"), user.getLanguage()); + String mobile = Util.fromScreen3(fu.getParameter("mobile"), user.getLanguage()); + String mobileshowtype = Util.fromScreen3(fu.getParameter("mobileshowtype"), user.getLanguage()); + String mobilecall = Util.fromScreen3(fu.getParameter("mobilecall"), user.getLanguage()); + String fax = Util.fromScreen3(fu.getParameter("fax"), user.getLanguage()); + String jobcall = Util.fromScreen3(fu.getParameter("jobcall"), user.getLanguage()); + String email = Util.fromScreen3(fu.getParameter("email"), user.getLanguage()); + String dsporder = Util.fromScreen3(fu.getParameter("dsporder"), user.getLanguage()); + String accounttype = Util.fromScreen3(fu.getParameter("accounttype"), user.getLanguage()); + String systemlanguage = Util.null2String(fu.getParameter("systemlanguage")); + if (systemlanguage.equals("") || systemlanguage.equals("0")) systemlanguage = "7"; + String belongto = Util.fromScreen3(fu.getParameter("belongto"), user.getLanguage()); + //应聘人员id + String rcid = Util.null2String(fu.getParameter("rcId")); + + CheckItemBean mobileBean = new CheckItemBean("mobile", mobile, id); + ValidateFieldManager.validate(mobileBean); + if (!mobileBean.isPass()) { + retmap.put("status", "-1"); + retmap.put("message", mobileBean.getCheckMsg()); + return retmap; + } + + CheckItemBean telephoneBean = new CheckItemBean("telephone", telephone, id); + ValidateFieldManager.validate(telephoneBean); + if (!telephoneBean.isPass()) { + retmap.put("status", "-1"); + retmap.put("message", telephoneBean.getCheckMsg()); + return retmap; + } + + + if (dsporder.length() == 0) dsporder = id; + if (accounttype.equals("0")) { + belongto = "-1"; + } + String departmentvirtualids = Util.null2String(fu.getParameter("departmentvirtualids"));//虚拟部门id; + + //Td9325,解决多账号次账号没有登陆Id在浏览框组织结构中无法显示的问题。 + boolean falg = false; + String loginid = ""; + if (accounttype.equals("1")) { + rs.executeSql("select loginid from HrmResource where id =" + belongto); + if (rs.next()) { + loginid = rs.getString("loginid"); + } + if (!loginid.equals("")) { + String maxidsql = "select max(id) as id from HrmResource where loginid like '" + loginid + "%'"; + rs.executeSql(maxidsql); + if (rs.next()) { + loginid = loginid + (rs.getInt("id") + 1); + falg = true; + } + } + } + rs.executeProc("HrmResourceMaxId_Get", ""); + rs.next(); + id = "" + rs.getInt(1); + if (!"".equals(rcid)) { + id = rcid; + } + SimpleBizLogger logger = new SimpleBizLogger(); + Map params = ParamUtil.request2Map(request); + BizLogContext bizLogContext = new BizLogContext(); + bizLogContext.setLogType(BizLogType.HRM);//模块类型 + bizLogContext.setBelongType(BizLogSmallType4Hrm.HRM_RSOURCE_CARD);//所属大类型 + bizLogContext.setBelongTypeTargetName(SystemEnv.getHtmlLabelName(1361, user.getLanguage())); + bizLogContext.setLogSmallType(BizLogSmallType4Hrm.HRM_RSOURCE_CARD_BASE);//当前小类型 + bizLogContext.setOperateType(BizLogOperateType.ADD); + bizLogContext.setParams(params);//当前request请求参数 + logger.setUser(user);//当前操作人 + String cusFieldNames = ServiceUtil.getCusFieldNames("HrmCustomFieldByInfoType", -1, "b"); + String mainSql = "select a.*" + (cusFieldNames.length() > 0 ? "," + cusFieldNames : "") + " from hrmresource a left join cus_fielddata b on a.id=b.id and b.scope='HrmCustomFieldByInfoType' and b.scopeid=-1 where a.id=" + id; + logger.setMainSql(mainSql, "id");//主表sql + logger.setMainPrimarykey("id");//主日志表唯一key + logger.setMainTargetNameColumn("lastname");//当前targetName对应的列(对应日志中的对象名) + logger.before(bizLogContext);//写入操作前日志 + + String sql = "select managerstr, seclevel from HrmResource where id = " + Util.getIntValue(managerid); + rs.executeSql(sql); + String managerstr = ""; + String seclevel = ""; + while (rs.next()) { + String tmp_managerstr = rs.getString("managerstr"); + /*********处理managerstr 不以逗号开始或者结束的情况 形如 managerstr:8 begin***********/ + if (!tmp_managerstr.startsWith(",")) tmp_managerstr = "," + tmp_managerstr; + if (!tmp_managerstr.endsWith(",")) tmp_managerstr = tmp_managerstr + ","; + /*********处理managerstr 不以逗号开始或者结束的情况 形如 managerstr:8 end ***********/ + managerstr += tmp_managerstr; + managerstr = "," + managerid + managerstr; + managerstr = managerstr.endsWith(",") ? managerstr : (managerstr + ","); + seclevel = rs.getString("seclevel"); + } + + String subcmpanyid1 = DepartmentComInfo.getSubcompanyid1(departmentid); + RecordSetTrans rst = new RecordSetTrans(); + rst.setAutoCommit(false); + try { + if(resourceimageid.length()==0)resourceimageid="null"; + if(costcenterid.length()==0)costcenterid="null"; + if(managerid.length()==0)managerid="null"; + if(assistantid.length()==0)assistantid="null"; + if(accounttype.length()==0)accounttype="null"; + if(belongto.length()==0)belongto="null"; + if(jobcall.length()==0)jobcall="null"; + if(mobileshowtype.length()==0)mobileshowtype="null"; + if(rst.getDBType().equalsIgnoreCase("postgresql")) + { + if(joblevel.length()==0)joblevel=null; + if(dsporder.length()==0)dsporder=null; + } + workcode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.USER, subcmpanyid1, departmentid, jobtitle, workcode); + para = "" + id + separator + workcode + separator + lastname + separator + sex + separator + resourceimageid + separator + + departmentid + separator + costcenterid + separator + jobtitle + separator + joblevel + separator + jobactivitydesc + separator + + managerid + separator + assistantid + separator + status + separator + locationid + separator + workroom + separator + telephone + + separator + mobile + separator + mobilecall + separator + fax + separator + jobcall + separator + subcmpanyid1 + separator + managerstr + + separator + accounttype + separator + belongto + separator + systemlanguage + separator + email + separator + dsporder + separator + mobileshowtype; + + rst.executeProc("HrmResourceBasicInfo_Insert", para); + if(Util.null2String(locationid).length()>0) { + rst.executeSql("update hrmresource set countryid=(select countryid from HrmLocations where id=" + locationid + ")," + + DbFunctionUtil.getInsertUpdateSetSql(rst.getDBType(), user.getUID()) + " where id=" + id); + } + String logidsql = "", quickSearchStr = new HrmCommonServiceImpl().generateQuickSearchStr(lastname); + if (falg) { + logidsql = "update HrmResource set loginid = ?, pinyinlastname = ?, ecology_pinyin_search = ? where id = ?"; + rst.executeUpdate(logidsql, loginid, quickSearchStr, quickSearchStr, id); + } else { + logidsql = "update HrmResource set pinyinlastname = ?, ecology_pinyin_search = ? where id = ?"; + rst.executeUpdate(logidsql, quickSearchStr, quickSearchStr, id); + } + if (seclevel == null || "".equals(seclevel)) { + seclevel = "0"; + } + rst.commit(); + } catch (Exception e) { + rst.rollback(); + e.printStackTrace(); + } + + boolean formdefined = false; + weaver.system.CusFormSettingComInfo CusFormSettingComInfo = new weaver.system.CusFormSettingComInfo(); + weaver.system.CusFormSetting CusFormSetting = CusFormSettingComInfo.getCusFormSetting("hrm", "HrmResourceBase"); + if (CusFormSetting != null) { + if (CusFormSetting.getStatus() == 2) { + //自定义布局页面 + formdefined = true; + } + } + int userid = user.getUID(); + String userpara = "" + userid + separator + today; + para = "" + id; + for (int i = 0; i < 5; i++) { + int idx = i; + if (formdefined) idx++; + String datefield = Util.null2String(fu.getParameter("datefield" + idx)); + String numberfield = "" + Util.getDoubleValue(fu.getParameter("numberfield" + idx), 0); + String textfield = Util.null2String(fu.getParameter("textfield" + idx)); + String tinyintfield = "" + Util.getIntValue(fu.getParameter("tinyintfield" + idx), 0); + para += separator + datefield + separator + numberfield + separator + textfield + separator + tinyintfield; + } + rs.executeProc("HrmResourceDefine_Update", para); + rs.executeProc("HrmResource_CreateInfo", "" + id + separator + userpara + separator + userpara); + + //421944 用户自定义隐私设置 + + UserPrivacyComInfo upc = new UserPrivacyComInfo(); + PrivacyComInfo pc = new PrivacyComInfo(); + Map mapShowSets = pc.getMapShowSets(); + String insertSql = ""; + rs = new RecordSet(); + try { + String deletePriSql = " delete from userprivacysetting where userid= '" + id + "'"; + rs.executeSql(deletePriSql); + for (Map.Entry me : mapShowSets.entrySet()) { + String fieldName = me.getKey(); + String fieldVal = Util.null2String(mapShowSets.get(fieldName)); + if (fieldVal.equals("1")) { + String tmpPK = id + "__" + fieldName; + String tmpPvalue = Util.null2String(fu.getParameter(fieldName + "showtype")); + insertSql = "insert into userprivacysetting (combinedid,userid,ptype,pvalue) values('" + tmpPK + "','" + id + "','" + fieldName + "','" + tmpPvalue + "')"; + rs.executeSql(insertSql); + } + } + upc.removeUserPrivacyCache(); + } catch (Exception e) { + e.printStackTrace(); + } + + + // 改为只进行该人缓存信息的添加 + ResourceComInfo.addResourceInfoCache(id); + SalaryManager.initResourceSalary(id); + + para = "" + id + separator + managerid + separator + departmentid + separator + subcmpanyid1 + separator + "0" + separator + managerstr; + rs.executeProc("HrmResource_Trigger_Insert", para); + + String sql_1 = ("insert into HrmInfoStatus (itemid,hrmid) values(1," + id + ")"); + rs.executeSql(sql_1); + String sql_2 = ("insert into HrmInfoStatus (itemid,hrmid) values(2," + id + ")"); + rs.executeSql(sql_2); + String sql_3 = ("insert into HrmInfoStatus (itemid,hrmid) values(3," + id + ")"); + rs.executeSql(sql_3); + String sql_10 = ("insert into HrmInfoStatus (itemid,hrmid) values(10," + id + ")"); + rs.executeSql(sql_10); + + String name = lastname; + String CurrentUser = "" + user.getUID(); + String CurrentUserName = "" + user.getUsername(); + String SWFAccepter = ""; + String SWFTitle = ""; + String SWFRemark = ""; + String SWFSubmiter = ""; + String Subject = ""; + Subject = SystemEnv.getHtmlLabelName(15670, user.getLanguage()); + Subject += ":" + name; + + //modifier by lvyi 2013-12-31 + if (settings.getEntervalid().equals("1")) {//入职提醒 + String thesql = "select hrmids from HrmInfoMaintenance where id<4 or id = 10"; + rs.executeSql(thesql); + String members = ""; + /*while(rs.next()){ + int hrmid_tmp = Util.getIntValue(rs.getString("hrmids"));//TD9392 + if(hrmid_tmp > 0 && user.getUID() != hrmid_tmp){ + members += ","+rs.getString("hrmids"); + } + }*/ + while (rs.next()) { + String hrmid_tmp = Util.null2String(rs.getString("hrmids"));//TD9392 + if (hrmid_tmp.length() != 0) { + members += "," + rs.getString("hrmids"); + } + } + if (!members.equals("")) { + members = members.substring(1); + members = duplicateRemoval(members, user.getUID() + ""); + SWFAccepter = members; + SWFTitle = SystemEnv.getHtmlLabelName(15670, user.getLanguage()); + SWFTitle += ":" + name; + SWFTitle += "-" + CurrentUserName; + SWFTitle += "-" + today; +// SWFRemark=""+Util.fromScreen2(Subject,user.getLanguage())+"";//支持E9弹窗 + SWFRemark = "" + Util.fromScreen2(Subject, user.getLanguage()) + ""; + SWFSubmiter = CurrentUser; + SysRemindWorkflow.setPrjSysRemind(SWFTitle, 0, Util.getIntValue(SWFSubmiter), SWFAccepter, SWFRemark); + } + } + + CustomFieldTreeManager.editCustomDataE9Add("HrmCustomFieldByInfoType", -1, fu, Util.getIntValue(id, 0)); + //应聘人员的个人信息18条 + if (!"".equals(rcid)) { + sql = "select * from HrmCareerApply where id = ?"; + rs.executeQuery(sql,id); + if (rs.next()) { + String birthday = Util.null2String(rs.getString("birthday")); + String folk = Util.null2String(rs.getString("folk")); + String nativeplace = Util.null2String(rs.getString("nativeplace")); + String regresidentplace = Util.null2String(rs.getString("regresidentplace")); + + String certificatenum = Util.null2String(rs.getString("certificatenum")); + String maritalstatus = Util.null2String(rs.getString("maritalstatus")); + String policy = Util.null2String(rs.getString("policy")); + String bememberdate = Util.null2String(rs.getString("bememberdate")); + + String bepartydate = Util.null2String(rs.getString("bepartydate")); + String islabouunion = Util.null2String(rs.getString("islabouunion")); + String educationlevel = Util.null2String(rs.getString("educationlevel")); + String degree = Util.null2String(rs.getString("degree")); + + String healthinfo = Util.null2String(rs.getString("healthinfo")); + + String height = Util.null2String(rs.getString("height")); + if (height.indexOf(".") != -1) height = height.substring(0, height.indexOf(".")); + String weight = Util.null2String(rs.getString("weight")); + if (weight.indexOf(".") != -1) weight = weight.substring(0, weight.indexOf(".")); + + String residentplace = Util.null2String(rs.getString("residentplace")); + String homeaddress = Util.null2String(rs.getString("homeaddress")); + String tempresidentnumber = Util.null2String(rs.getString("tempresidentnumber")); + + para = "" + id + separator + birthday + separator + folk + separator + nativeplace + separator + regresidentplace + separator + maritalstatus + separator + policy + separator + bememberdate + separator + bepartydate + separator + islabouunion + separator + educationlevel + separator + degree + separator + healthinfo + separator + height + separator + weight + separator + residentplace + separator + homeaddress + separator + tempresidentnumber + separator + certificatenum; + RecordSet rs1 = new RecordSet(); + rs1.executeProc("HrmResourcePersonalInfo_Insert", para); + } + } + //更新虚拟组织部门id + if (departmentvirtualids.length() > 0) { + //保存前先删除需要删除的数据,因为有managerid 所以不能全部删除再保存 + sql = "delete from hrmresourcevirtual where resourceid=" + id + " and departmentid not in (" + departmentvirtualids + ")"; + rs.executeSql(sql); + + String[] departmentvirtualid = departmentvirtualids.split(","); + for (int i = 0; departmentvirtualid != null && i < departmentvirtualid.length; i++) { + rs.executeSql(" select count(*) from HrmResourceVirtual where departmentid ='" + departmentvirtualid[i] + "' and resourceid = " + id); + if (rs.next()) { + //如果已存在 无需处理 + if (rs.getInt(1) > 0) continue; + } + + //写入 + int tmpid = 0; + rs.executeSql("select max(id) from HrmResourceVirtual "); + if (rs.next()) { + tmpid = rs.getInt(1) + 1; + } + String subcompanyid = DepartmentVirtualComInfo.getSubcompanyid1(departmentvirtualid[i]); + sql = " insert into HrmResourceVirtual (id,resourceid,subcompanyid,departmentid ) " + + " values (" + tmpid + "," + id + "," + subcompanyid + "," + departmentvirtualid[i] + ")"; + rs.executeSql(sql); + } + } + + LogUtil.writeBizLog(logger.getBizLogContexts()); + + if(needSync) HrmFaceCheckManager.sync(id, HrmFaceCheckManager.getOptInsert(), "hrm_e9_HrmResourceBaseService_addResourceBase", HrmFaceCheckManager.getOaResource()); + //同步RTX端的用户信息. + new OrganisationCom().checkUser(Util.getIntValue(id)); + new Thread(new OrganisationComRunnable("user", "add", "" + id)).start(); + ResourceComInfo.updateResourceInfoCache("" + id); + new PluginUserCheck().clearPluginUserCache("messager"); + //OA与第三方接口单条数据同步方法开始 + new HrmServiceManager().SynInstantHrmResource("" + id, "1"); + //OA与第三方接口单条数据同步方法结束 + + //新增人员实时同步到CoreMail邮件系统 + //CoreMailAPI.synUser(id); + if (cmd.equals("SaveAndNew")) { + retmap.put("status", "1"); + } else if (cmd.equals("SaveAndNext")) { + retmap.put("status", "2"); + } else { + retmap.put("status", "3"); + } + retmap.put("id", id); + } catch (Exception e) { + writeLog("新建人员基本信息错误:" + e); + retmap.put("status", "-1"); + } + return retmap; + } + + /** + * 编辑人员基本信息 + * + * @param request + * @param response + * @return + */ + public Map editContactInfo(HttpServletRequest request, HttpServletResponse response) { + Map retmap = new HashMap(); + try { + User user = HrmUserVarify.getUser(request, response); + RecordSet rs = new RecordSet(); + String sql = ""; + ResourceComInfo ResourceComInfo = new ResourceComInfo(); + SysMaintenanceLog SysMaintenanceLog = new SysMaintenanceLog(); + HrmServiceManager HrmServiceManager = new HrmServiceManager(); + String para = ""; + + FileUpload fu = new FileUpload(request); + String id = Util.null2String(fu.getParameter("id")); + if (user.getUID() != Util.getIntValue(id)) {//本人才能修改 + retmap.put("status", "-1"); + retmap.put("message", ""+ SystemEnv.getHtmlLabelName(22620,weaver.general.ThreadVarLanguage.getLang())+""); + return retmap; + } + + + LN LN = new LN(); + DepartmentComInfo DepartmentComInfo = new DepartmentComInfo(); + CustomFieldTreeManager CustomFieldTreeManager = new CustomFieldTreeManager(); + CrmShareBase CrmShareBase = new CrmShareBase(); + + String resourceimageidcheck = Util.null2String(fu.getParameter("resourceimageid")); + if (resourceimageidcheck.length() > 0) { + resourceimageidcheck = "" + DocDownloadCheckUtil.getDownloadfileidstr(resourceimageidcheck); + } + String resourceimageBase64check = Util.null2String(fu.getParameter("resourceimageBase64")); + if (resourceimageBase64check.length() > 0) { + resourceimageidcheck = ServiceUtil.saveResourceImage(resourceimageBase64check); + } + String oldresourceimageidcheck = StringUtil.vString(fu.getParameter("oldresourceimage"),"0"); + if ("".equals(resourceimageidcheck)) resourceimageidcheck = oldresourceimageidcheck; + if(Util.getIntValue(resourceimageidcheck, 0)>0){ + rs.executeQuery("select imagefilename from imagefile where imagefileid=?", resourceimageidcheck); + if(rs.next()){ + String imagefilename = Util.null2String(rs.getString("imagefilename")).trim(); + if(imagefilename.length()>0){ + String imgUrl = Util.null2String(imagefilename.substring(imagefilename.lastIndexOf(".")+1)).trim().toLowerCase(); + if(!"jpg".equals(imgUrl) && !"gif".equals(imgUrl) && !"png".equals(imgUrl)){ + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(132006, user.getLanguage())); + return retmap; + } + } + } + } + + String mobile = Util.fromScreen3(fu.getParameter("mobile"), user.getLanguage()); + String telephone = Util.fromScreen3(fu.getParameter("telephone"), user.getLanguage()); + + CheckItemBean mobileBean = new CheckItemBean("mobile", mobile, id); + ValidateFieldManager.validate(mobileBean); + if (!mobileBean.isPass()) { + retmap.put("status", "-1"); + retmap.put("message", mobileBean.getCheckMsg()); + return retmap; + } + CheckItemBean telephoneBean = new CheckItemBean("telephone", telephone, id); + ValidateFieldManager.validate(telephoneBean); + if (!telephoneBean.isPass()) { + retmap.put("status", "-1"); + retmap.put("message", telephoneBean.getCheckMsg()); + return retmap; + } + + + SimpleBizLogger logger = new SimpleBizLogger(); + Map params = ParamUtil.request2Map(request); + BizLogContext bizLogContext = new BizLogContext(); + bizLogContext.setLogType(BizLogType.HRM);//模块类型 + bizLogContext.setBelongType(BizLogSmallType4Hrm.HRM_RSOURCE_CARD);//所属大类型 + bizLogContext.setBelongTypeTargetName(SystemEnv.getHtmlLabelName(1361, user.getLanguage())); + bizLogContext.setLogSmallType(BizLogSmallType4Hrm.HRM_RSOURCE_CARD_BASE);//当前小类型 + bizLogContext.setParams(params);//当前request请求参数 + logger.setUser(user);//当前操作人 + String cusFieldNames = ServiceUtil.getCusFieldNames("HrmCustomFieldByInfoType", -1, "b"); + String mainSql = "select a.*" + (cusFieldNames.length() > 0 ? "," + cusFieldNames : "") + " from hrmresource a left join cus_fielddata b on a.id=b.id and b.scope='HrmCustomFieldByInfoType' and b.scopeid=-1 where a.id=" + id; + logger.setMainSql(mainSql, "id");//主表sql + logger.setMainPrimarykey("id");//主日志表唯一key + logger.setMainTargetNameColumn("lastname");//当前targetName对应的列(对应日志中的对象名) + logger.before(bizLogContext);//吸入操作前日志 + + String updateSql = ""; + List sqlParams = new ArrayList() ; + RecordSetTrans rst = new RecordSetTrans(); + HrmFieldGroupComInfo HrmFieldGroupComInfo = new HrmFieldGroupComInfo(); + HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo(); + HrmFieldManager hfm = new HrmFieldManager("HrmCustomFieldByInfoType", -1); + boolean flagaccount = GCONST.getMOREACCOUNTLANDING(); + String accounttype = ""; + String belongto = Util.fromScreen3(fu.getParameter("belongto"), user.getLanguage()); + String oldbelongto = ""; + String dsporder = Util.fromScreen3(fu.getParameter("dsporder"), user.getLanguage());; //显示顺序为空需要和id保持一致 + if (dsporder.length() == 0) dsporder = id; + String locationid = ""; //设置了办公地点需要更新人员的国家 + String loginid = ""; //次帐号的登录名需要和主账号+id保持一致 + boolean falg = false; + while (HrmFieldGroupComInfo.next()) { + int grouptype = Util.getIntValue(HrmFieldGroupComInfo.getType()); + if (grouptype != -1) continue; + int groupid = Util.getIntValue(HrmFieldGroupComInfo.getid()); + hfm.getCustomFields(groupid); + while (hfm.next()) { + String fieldName = hfm.getFieldname(); + if (fieldName.equals("accounttype") && !flagaccount) continue; + if (fieldName.equals("belongto")) continue; + if (fieldName.equals("loginid") || fieldName.equals("jobactivity") || fieldName.equals("status") || fieldName.equals("departmentvirtualids")) continue; + if (fieldName.equals("messagerurl") || fieldName.equals("jobGroupId") || fieldName.equals("managerid") || fieldName.equals("departmentid")) continue; + //没有开启多语言即使开启了系统语言允许个人编辑也不行 + if (!hfm.isUse() || !hfm.isModify() || !hfm.isBaseField(fieldName)) { + continue; + }else{ + String updateValue = Util.fromScreen3(fu.getParameter(fieldName), user.getLanguage()); + if("accounttype".equals(fieldName)){ + accounttype = updateValue; + if (accounttype.equals("0")) { + belongto = "-1"; + } + //Td9325,解决多账号次账号没有登陆Id在浏览框组织结构中无法显示的问题。 + rs.executeQuery("select * from HrmResource where id = ? " ,id); + if (rs.next()) { + loginid = rs.getString("loginid"); + float idsporder = rs.getFloat("dsporder"); + if (idsporder <= 0) { + dsporder = rs.getString("id"); + } else { + dsporder = "" + idsporder; + } + } + + String thisAccounttype = rs.getString("accounttype"); + if (thisAccounttype.equals("1") && updateValue.equals("0")) { + oldbelongto = rs.getString("belongto"); + } + if (accounttype.equals("1") && loginid.equalsIgnoreCase("")) { + rs.executeSql("select loginid from HrmResource where id =" + belongto); + if (rs.next()) { + loginid = rs.getString(1); + } + if (LN.CkHrmnum() >= 0) { + retmap.put("status", "-1"); + return retmap; + } + if (!loginid.equals("")) { + loginid = loginid + (id + 1); + falg = true; + } + } + continue; + } + if("resourceimageid".equals(fieldName)){ + String resourceimageid = updateValue; + if (resourceimageid.length() > 0) { + resourceimageid = "" + DocDownloadCheckUtil.getDownloadfileidstr(resourceimageid); + } + String resourceimageBase64 = Util.null2String(fu.getParameter("resourceimageBase64")); + if (resourceimageBase64.length() > 0) { + resourceimageid = ServiceUtil.saveResourceImage(resourceimageBase64); + } + String oldresourceimageid = StringUtil.vString(fu.getParameter("oldresourceimage"),"0"); + if (resourceimageid.equals("")) resourceimageid = oldresourceimageid; + updateValue = resourceimageid; + } + if("locationid".equals(fieldName)){ + locationid = updateValue; + } + if("dsporder".equals(fieldName)){ + updateValue = dsporder; + } + if("systemlanguage".equals(fieldName)){ + if (updateValue.equals("") || updateValue.equals("0")) { + updateValue = "7"; + } + } + //mysql报错问题java.sql.SQLException: Incorrect integer value: '' for column 'COSTCENTERID' at row 1 + if((fieldName.equals("resourceimageid") || fieldName.equals("costcenterid") || fieldName.equals("managerid") + || fieldName.equals("assistantid") || fieldName.equals("accounttype") || fieldName.equals("belongto") + || fieldName.equals("jobcall") || fieldName.equals("mobileshowtype") || fieldName.equals("joblevel") + ) && updateValue.length()==0){ + updateValue ="null"; + } + if(updateSql.length()>0)updateSql+=","; + updateSql+=(fieldName+" = ? "); + sqlParams.add(updateValue); + } + } + } + if(accounttype.length()>0){ + if(updateSql.length()>0)updateSql+=","; + updateSql+="accounttype = ?,belongto = ?"; + sqlParams.add(accounttype); + sqlParams.add(belongto); + } + if(updateSql.length()>0){ + rst.setAutoCommit(false); + try { + String sqltemp = "update hrmresource set "+updateSql+" where id = ? "; + sqlParams.add(id); + rst.executeUpdate(sqltemp,sqlParams); + if(Util.null2String(locationid).length()>0) { + rst.executeSql("update hrmresource set countryid=(select countryid from HrmLocations where id=" + locationid + ") where id=" + id); + } + if (falg) { + String logidsql = "update HrmResource set loginid = '" + loginid + "' where id = " + id; + rst.executeSql(logidsql); + } + rst.commit(); + } catch (Exception e) { + rst.rollback(); + e.printStackTrace(); + } + } + + //421944 用户自定义隐私设置 + + UserPrivacyComInfo upc = new UserPrivacyComInfo(); + PrivacyComInfo pc = new PrivacyComInfo(); + Map mapShowSets = pc.getMapShowSets(); + String insertSql = ""; + rs = new RecordSet(); + try { + String deletePriSql = " delete from userprivacysetting where userid= '" + id + "'"; + rs.executeSql(deletePriSql); + for (Map.Entry me : mapShowSets.entrySet()) { + String fieldName = me.getKey(); + String fieldVal = Util.null2String(mapShowSets.get(fieldName)); + if (fieldVal.equals("1")) { + String tmpPK = id + "__" + fieldName; + String tmpPvalue = Util.null2String(fu.getParameter(fieldName + "showtype")); + insertSql = "insert into userprivacysetting (combinedid,userid,ptype,pvalue) values('" + tmpPK + "','" + id + "','" + fieldName + "','" + tmpPvalue + "')"; + rs.executeSql(insertSql); + } + } + upc.removeUserPrivacyCache(); + } catch (Exception e) { + e.printStackTrace(); + } + + int userid = user.getUID(); + String userpara = "" + userid + separator + today; + rs.executeProc("HrmResource_ModInfo", "" + id + separator + userpara); + + boolean formdefined = false; + weaver.system.CusFormSettingComInfo CusFormSettingComInfo = new weaver.system.CusFormSettingComInfo(); + weaver.system.CusFormSetting CusFormSetting = CusFormSettingComInfo.getCusFormSetting("hrm", "HrmResourceBase"); + if (CusFormSetting != null) { + if (CusFormSetting.getStatus() == 2) { + //自定义布局页面 + formdefined = true; + } + } + para = "" + id; + for (int i = 0; i < 5; i++) { + int idx = i; + if (formdefined) idx++; + String datefield = Util.null2String(fu.getParameter("datefield" + idx)); + String numberfield = "" + Util.getDoubleValue(fu.getParameter("numberfield" + idx), 0); + String textfield = Util.null2String(fu.getParameter("textfield" + idx)); + String tinyintfield = "" + Util.getIntValue(fu.getParameter("tinyintfield" + idx), 0); + para += separator + datefield + separator + numberfield + separator + textfield + separator + tinyintfield; + } + rs.executeProc("HrmResourceDefine_Update", para); + + new Thread(new OrganisationComRunnable("user", "editbasicinfo", id + "-" + (ResourceComInfo.getStatus(id)))).start(); + // 改为自进行修正 + ResourceComInfo.updateResourceInfoCache(id); + //OA与第三方接口单条数据同步方法开始 + HrmServiceManager.SynInstantHrmResource(id, "2"); + //OA与第三方接口单条数据同步方法结束 + + //处理自定义字段 add by wjy + CustomFieldTreeManager.editCustomData("HrmCustomFieldByInfoType", -1, fu, Util.getIntValue(id, 0)); + + //处理次账号修改为主账号时,检查次账号所属 主账号的 其他设置是否需要修改 add by kzw QC159888 + try { + if (!oldbelongto.equals("")) { + HrmUserSettingComInfo userSetting = new HrmUserSettingComInfo(); + String belongtoshow = userSetting.getBelongtoshowByUserId(oldbelongto); + if (belongtoshow.equals("1")) { + rs.executeSql("select id from hrmresource where belongto = " + oldbelongto); + if (!rs.next()) { + String setId = userSetting.getId(oldbelongto); + rs.executeSql("update HrmUserSetting set belongtoshow=0 where id=" + setId); + userSetting.removeHrmUserSettingComInfoCache(); + } + } + } + } catch (Exception e) { + writeLog(e.getMessage()); + } + + rs.execute("update HrmResource set " + DbFunctionUtil.getUpdateSetSql(rs.getDBType(), user.getUID()) + " where id=" + id); + rs.execute("update HrmResourceManager set " + DbFunctionUtil.getUpdateSetSql(rs.getDBType(), user.getUID()) + " where id=" + id); + + //写入操作后日志 + LogUtil.writeBizLog(logger.getBizLogContexts()); + + //修改人员实时同步到CoreMail邮件系统 + //CoreMailAPI.synUser(id); + + HrmFaceCheckManager.sync(id, HrmFaceCheckManager.getOptUpdate(), "hrm_e9_HrmResourceBaseService_editResourceBase", HrmFaceCheckManager.getOaResource()); + + retmap.put("status", "1"); + } catch (Exception e) { + writeLog("编辑人员信息错误:" + e); + retmap.put("status", "-1"); + } + return retmap; + } + + /** + * 编辑人员基本信息 + * + * @param request + * @param response + * @return + */ + public Map editResourceBase(HttpServletRequest request, HttpServletResponse response) { + Map retmap = new HashMap(); + try { + User user = HrmUserVarify.getUser(request, response); + if (Util.null2String(request.getParameter("editcontact")).equals("1")) { + return editContactInfo(request, response); + } + + boolean canEdit = HrmUserVarify.checkUserRight("HrmResourceEdit:Edit", user); + if (!canEdit) { + retmap.put("status", "-1"); + retmap.put("message", ""+ SystemEnv.getHtmlLabelName(22620,weaver.general.ThreadVarLanguage.getLang())+""); + return retmap; + } + LN LN = new LN(); + RecordSet rs = new RecordSet(); + DepartmentComInfo DepartmentComInfo = new DepartmentComInfo(); + ResourceComInfo ResourceComInfo = new ResourceComInfo(); + CustomFieldTreeManager CustomFieldTreeManager = new CustomFieldTreeManager(); + SysMaintenanceLog SysMaintenanceLog = new SysMaintenanceLog(); + HrmServiceManager HrmServiceManager = new HrmServiceManager(); + CrmShareBase CrmShareBase = new CrmShareBase(); + + String para = ""; + FileUpload fu = new FileUpload(request); + String id = Util.null2String(fu.getParameter("id")); + if (id.length()==0) { + retmap.put("status", "-1"); + retmap.put("message", ""+ SystemEnv.getHtmlLabelName(22620,weaver.general.ThreadVarLanguage.getLang())+""); + return retmap; + } + String workcode = Util.fromScreen3(fu.getParameter("workcode"), user.getLanguage()); + String lastname = Util.fromScreen3(fu.getParameter("lastname"), user.getLanguage()).trim(); + String sex = Util.fromScreen3(fu.getParameter("sex"), user.getLanguage()); + String resourceimageid = Util.null2String(fu.getParameter("resourceimageid")); + if(resourceimageid.length()>0) { + resourceimageid = "" + DocDownloadCheckUtil.getDownloadfileidstr(resourceimageid); + } + String resourceimageBase64 = Util.null2String(fu.getParameter("resourceimageBase64")); + if(resourceimageBase64.length()>0){ + resourceimageid = ServiceUtil.saveResourceImage(resourceimageBase64); + } + String oldresourceimageid = Util.null2String(fu.getParameter("oldresourceimage")); + if (resourceimageid.equals("")) resourceimageid = oldresourceimageid; + if(Util.getIntValue(resourceimageid, 0)>0){ + rs.executeQuery("select imagefilename from imagefile where imagefileid=?", resourceimageid); + if(rs.next()){ + String imagefilename = Util.null2String(rs.getString("imagefilename")).trim(); + if(imagefilename.length()>0){ + String imgUrl = Util.null2String(imagefilename.substring(imagefilename.lastIndexOf(".")+1)).trim().toLowerCase(); + if(!"jpg".equals(imgUrl) && !"gif".equals(imgUrl) && !"png".equals(imgUrl)){ + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(132006, user.getLanguage())); + return retmap; + } + } + } + } + String departmentid = Util.fromScreen3(fu.getParameter("departmentid"), user.getLanguage()); + String costcenterid = Util.fromScreen3(fu.getParameter("costcenterid"), user.getLanguage()); + String jobtitle = Util.fromScreen3(fu.getParameter("jobtitle"), user.getLanguage()); + String joblevel = Util.fromScreen3(fu.getParameter("joblevel"), user.getLanguage()); + String jobactivitydesc = Util.fromScreen3(fu.getParameter("jobactivitydesc"), user.getLanguage()); + String managerid = Util.fromScreen3(fu.getParameter("managerid"), user.getLanguage()); + String assistantid = Util.fromScreen3(fu.getParameter("assistantid"), user.getLanguage()); + String status = ""; + String locationid = Util.fromScreen3(fu.getParameter("locationid"), user.getLanguage()); + String workroom = Util.fromScreen3(fu.getParameter("workroom"), user.getLanguage()); + String telephone = Util.fromScreen3(fu.getParameter("telephone"), user.getLanguage()); + String mobile = Util.fromScreen3(fu.getParameter("mobile"), user.getLanguage()); + String mobileshowtype = Util.fromScreen3(fu.getParameter("mobileshowtype"), user.getLanguage()); + String mobilecall = Util.fromScreen3(fu.getParameter("mobilecall"), user.getLanguage()); + String fax = Util.fromScreen3(fu.getParameter("fax"), user.getLanguage()); + String email = Util.fromScreen3(fu.getParameter("email"), user.getLanguage()); + String dsporder = Util.fromScreen3(fu.getParameter("dsporder"), user.getLanguage()); + String jobcall = Util.fromScreen3(fu.getParameter("jobcall"), user.getLanguage()); + String systemlanguage = Util.fromScreen3(fu.getParameter("systemlanguage"), user.getLanguage()); + if (systemlanguage.equals("") || systemlanguage.equals("0")) { + systemlanguage = "7"; + } + String accounttype = Util.fromScreen3(fu.getParameter("accounttype"), user.getLanguage()); + String belongto = Util.fromScreen3(fu.getParameter("belongto"), user.getLanguage()); + if (dsporder.length() == 0) dsporder = id; + if (accounttype.equals("0")) { + belongto = "-1"; + } + + + CheckItemBean mobileBean = new CheckItemBean("mobile", mobile, id); + ValidateFieldManager.validate(mobileBean); + if (!mobileBean.isPass()) { + retmap.put("status", "-1"); + retmap.put("message", mobileBean.getCheckMsg()); + return retmap; + } + CheckItemBean telephoneBean = new CheckItemBean("telephone", telephone, id); + ValidateFieldManager.validate(telephoneBean); + if (!telephoneBean.isPass()) { + retmap.put("status", "-1"); + retmap.put("message", telephoneBean.getCheckMsg()); + return retmap; + } + + + SimpleBizLogger logger = new SimpleBizLogger(); + Map params = ParamUtil.request2Map(request); + BizLogContext bizLogContext = new BizLogContext(); + bizLogContext.setLogType(BizLogType.HRM);//模块类型 + bizLogContext.setBelongType(BizLogSmallType4Hrm.HRM_RSOURCE_CARD);//所属大类型 + bizLogContext.setBelongTypeTargetName(SystemEnv.getHtmlLabelName(1361, user.getLanguage())); + bizLogContext.setLogSmallType(BizLogSmallType4Hrm.HRM_RSOURCE_CARD_BASE);//当前小类型 + bizLogContext.setParams(params);//当前request请求参数 + logger.setUser(user);//当前操作人 + String cusFieldNames = ServiceUtil.getCusFieldNames("HrmCustomFieldByInfoType", -1, "b"); + String mainSql = "select a.*" + (cusFieldNames.length() > 0 ? "," + cusFieldNames : "") + " from hrmresource a left join cus_fielddata b on a.id=b.id and b.scope='HrmCustomFieldByInfoType' and b.scopeid=-1 where a.id=" + id; + logger.setMainSql(mainSql, "id");//主表sql + logger.setMainPrimarykey("id");//主日志表唯一key + logger.setMainTargetNameColumn("lastname");//当前targetName对应的列(对应日志中的对象名) + logger.before(bizLogContext);//吸入操作前日志 + + //Td9325,解决多账号次账号没有登陆Id在浏览框组织结构中无法显示的问题。 + String oldbelongto = ""; + boolean falg = false; + String loginid = ""; + rs.executeSql("select * from HrmResource where id =" + id); + if (rs.next()) { + status = Util.null2String(rs.getString("status")).trim(); + loginid = rs.getString("loginid"); + float idsporder = rs.getFloat("dsporder"); + if (idsporder <= 0) { + dsporder = rs.getString("id"); + } else { + dsporder = "" + idsporder; + } + + String thisAccounttype = rs.getString("accounttype"); + if (thisAccounttype.equals("1") && accounttype.equals("0")) { + oldbelongto = rs.getString("belongto"); + } + } + + if (accounttype.equals("1") && loginid.equalsIgnoreCase("")) { + rs.executeSql("select loginid from HrmResource where id =" + belongto); + if (rs.next()) { + loginid = rs.getString(1); + } + + if (!loginid.equals("")) { + loginid = loginid + (id + 1); + falg = true; + } + } + String sql = "select * from HrmResource where id = " + Util.getIntValue(id); + rs.executeSql(sql); + String oldmanagerid = ""; + String oldmanagerstr = ""; + while (rs.next()) { + oldmanagerid = rs.getString("managerid"); + oldmanagerstr = rs.getString("managerstr"); + /*********处理managerstr 不以逗号开始或者结束的情况 形如 managerstr:8 begin***********/ + if (!oldmanagerstr.startsWith(",")) oldmanagerstr = "," + oldmanagerstr; + if (!oldmanagerstr.endsWith(",")) oldmanagerstr = oldmanagerstr + ","; + /*********处理managerstr 不以逗号开始或者结束的情况 形如 managerstr:8 end ***********/ + } + //mysql报错问题java.sql.SQLException: Incorrect integer value: '' for column 'COSTCENTERID' at row 1 + if(resourceimageid.length()==0)resourceimageid="null"; + if(costcenterid.length()==0)costcenterid="null"; + if(managerid.length()==0)managerid="null"; + if(assistantid.length()==0)assistantid="null"; + if(accounttype.length()==0)accounttype="null"; + if(belongto.length()==0)belongto="null"; + if(jobcall.length()==0)jobcall="null"; + if(mobileshowtype.length()==0)mobileshowtype="null"; + DepartmentComInfo departmentComInfo = new DepartmentComInfo(); + String subcompanyid1 = departmentComInfo.getSubcompanyid1(departmentid); +// workcode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.USER, subcompanyid1, departmentid, jobtitle, workcode); + if (StringUtils.isNotEmpty(workcode)) { + CodeRuleManager.getCodeRuleManager().checkReservedIfDel(RuleCodeType.USER.getValue(), workcode); + } + para = "" + id + separator + workcode + separator + lastname + separator + sex + separator + resourceimageid + + separator + departmentid + separator + costcenterid + separator + jobtitle + separator + joblevel + + separator + jobactivitydesc + separator + managerid + separator + assistantid + separator + status + + separator + locationid + separator + workroom + separator + telephone + separator + mobile + + separator + mobilecall + separator + fax + separator + jobcall + separator + systemlanguage + + separator + accounttype + separator + belongto + separator + email + separator + dsporder + separator + mobileshowtype; + RecordSetTrans rst = new RecordSetTrans(); + rst.setAutoCommit(false); + try { + rst.executeProc("HrmResourceBasicInfo_Update", para); + if(Util.null2String(locationid).length()>0) { + rst.executeSql("update hrmresource set countryid=(select countryid from HrmLocations where id=" + locationid + ") where id=" + id); + } + String logidsql = "", quickSearchStr = new HrmCommonServiceImpl().generateQuickSearchStr(lastname); + if (falg) { + logidsql = "update HrmResource set loginid = ?, pinyinlastname = ?, ecology_pinyin_search = ? where id = ?"; + rst.executeUpdate(logidsql, loginid, quickSearchStr, quickSearchStr, id); + } else { + logidsql = "update HrmResource set pinyinlastname = ?, ecology_pinyin_search = ? where id = ?"; + rst.executeUpdate(logidsql, quickSearchStr, quickSearchStr, id); + } + rst.commit(); + } catch (Exception e) { + rst.rollback(); + e.printStackTrace(); + } + + if(!"7".equals(systemlanguage) && StringUtils.isNotBlank(systemlanguage)){ + User.setUserLang(Util.getIntValue(id),Util.getIntValue(systemlanguage, 7)); + } + + //421944 用户自定义隐私设置 + + UserPrivacyComInfo upc = new UserPrivacyComInfo(); + PrivacyComInfo pc = new PrivacyComInfo(); + Map mapShowSets = pc.getMapShowSets(); + String insertSql = ""; + rs = new RecordSet(); + try { + String deletePriSql = " delete from userprivacysetting where userid= '" + id + "'"; + rs.executeSql(deletePriSql); + for (Map.Entry me : mapShowSets.entrySet()) { + String fieldName = me.getKey(); + String fieldVal = Util.null2String(mapShowSets.get(fieldName)); + if (fieldVal.equals("1")) { + String tmpPK = id + "__" + fieldName; + String tmpPvalue = Util.null2String(fu.getParameter(fieldName + "showtype")); + insertSql = "insert into userprivacysetting (combinedid,userid,ptype,pvalue) values('" + tmpPK + "','" + id + "','" + fieldName + "','" + tmpPvalue + "')"; + rs.executeSql(insertSql); + } + } + upc.removeUserPrivacyCache(); + } catch (Exception e) { + e.printStackTrace(); + } + + int userid = user.getUID(); + String userpara = "" + userid + separator + today; + rs.executeProc("HrmResource_ModInfo", "" + id + separator + userpara); + String managerstr = ""; + if (!id.equals(managerid)) { + sql = "select managerstr from HrmResource where id = " + Util.getIntValue(managerid); + rs.executeSql(sql); + while (rs.next()) { + managerstr = rs.getString("managerstr"); + /*********处理managerstr 不以逗号开始或者结束的情况 形如 managerstr:8 begin***********/ + if (!managerstr.startsWith(",")) managerstr = "," + managerstr; + if (!managerstr.endsWith(",")) managerstr = managerstr + ","; + /*********处理managerstr 不以逗号开始或者结束的情况 形如 managerstr:8 end ***********/ + managerstr = "," + managerid + managerstr; + managerstr = managerstr.endsWith(",") ? managerstr : (managerstr + ","); + } + } else { + managerstr = "," + managerid + ","; + } + + rst = new RecordSetTrans(); + rst.setAutoCommit(false); + try { + para = "" + id + separator + managerstr; + rst.executeProc("HrmResource_UpdateManagerStr", para); + rst.commit(); + } catch (Exception e) { + rst.rollback(); + e.printStackTrace(); + } + + managerid = Util.null2String(managerid).trim(); + oldmanagerid = Util.null2String(oldmanagerid).trim(); + if(!managerid.equals(oldmanagerid) && !(("".equals(managerid) || "0".equals(managerid)) && ("".equals(oldmanagerid) || "0".equals(oldmanagerid)))){ + String temOldmanagerstr = "," + id + oldmanagerstr; + temOldmanagerstr = temOldmanagerstr.endsWith(",") ? temOldmanagerstr : (temOldmanagerstr + ","); + sql = "select id,departmentid,subcompanyid1,managerid,seclevel,managerstr from HrmResource where managerstr like '%" + temOldmanagerstr + "'"; + rs.executeSql(sql); + while (rs.next()) { + String nowmanagerstr = Util.null2String(rs.getString("managerstr")); + /*********处理managerstr 不以逗号开始或者结束的情况 形如 managerstr:8 begin***********/ + if (!nowmanagerstr.startsWith(",")) nowmanagerstr = "," + nowmanagerstr; + if (!nowmanagerstr.endsWith(",")) nowmanagerstr = nowmanagerstr + ","; + /*********处理managerstr 不以逗号开始或者结束的情况 形如 managerstr:8 end ***********/ + String resourceid = rs.getString("id"); + //指定上级为自身的情况,不更新自身上级 + if (id.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) ? "" : ","); + } + } + rst = new RecordSetTrans(); + rst.setAutoCommit(false); + try { + para = resourceid + separator + nowmanagerstr2; + rst.executeProc("HrmResource_UpdateManagerStr", para); + rst.commit(); + ResourceComInfo.updateResourceInfoCache(resourceid); //更新缓存 + } catch (Exception e) { + rst.rollback(); + e.printStackTrace(); + } + } + } + + String subcmpanyid1 = DepartmentComInfo.getSubcompanyid1(departmentid); + para = "" + id + separator + subcmpanyid1; + rst = new RecordSetTrans(); + rst.setAutoCommit(false); + try { + rst.executeProc("HrmResource_UpdateSubCom", para); + rst.commit(); + } catch (Exception e) { + rst.rollback(); + e.printStackTrace(); + } + + if(!managerid.equals(oldmanagerid) && !(("".equals(managerid) || "0".equals(managerid)) && ("".equals(oldmanagerid) || "0".equals(oldmanagerid)))){//修改人力资源经理,对客户和日程共享重新计算 + CrmShareBase.setShareForNewManager(id); + } + boolean formdefined = false; + weaver.system.CusFormSettingComInfo CusFormSettingComInfo = new weaver.system.CusFormSettingComInfo(); + weaver.system.CusFormSetting CusFormSetting = CusFormSettingComInfo.getCusFormSetting("hrm", "HrmResourceBase"); + if (CusFormSetting != null) { + if (CusFormSetting.getStatus() == 2) { + //自定义布局页面 + formdefined = true; + } + } + para = "" + id; + for (int i = 0; i < 5; i++) { + int idx = i; + if (formdefined) idx++; + String datefield = Util.null2String(fu.getParameter("datefield" + idx)); + String numberfield = "" + Util.getDoubleValue(fu.getParameter("numberfield" + idx), 0); + String textfield = Util.null2String(fu.getParameter("textfield" + idx)); + String tinyintfield = "" + Util.getIntValue(fu.getParameter("tinyintfield" + idx), 0); + para += separator + datefield + separator + numberfield + separator + textfield + separator + tinyintfield; + } + rs.executeProc("HrmResourceDefine_Update", para); + + new Thread(new OrganisationComRunnable("user", "editbasicinfo", id + "-" + status)).start(); + // 改为自进行修正 + ResourceComInfo.updateResourceInfoCache(id); + + try { + //OA与第三方接口单条数据同步方法开始 + HrmServiceManager.SynInstantHrmResource(id, "2"); + //OA与第三方接口单条数据同步方法结束 + } catch (Exception e) { + this.writeLog("OA与第三方接口单条数据同步失败" + e); + } + + //处理自定义字段 add by wjy + CustomFieldTreeManager.editCustomData("HrmCustomFieldByInfoType", -1, fu, Util.getIntValue(id, 0)); + + //处理次账号修改为主账号时,检查次账号所属 主账号的 其他设置是否需要修改 add by kzw QC159888 + try { + if (!oldbelongto.equals("")) { + HrmUserSettingComInfo userSetting = new HrmUserSettingComInfo(); + String belongtoshow = userSetting.getBelongtoshowByUserId(oldbelongto); + if (belongtoshow.equals("1")) { + rs.executeSql("select id from hrmresource where belongto = " + oldbelongto); + if (!rs.next()) { + String setId = userSetting.getId(oldbelongto); + rs.executeSql("update HrmUserSetting set belongtoshow=0 where id=" + setId); + userSetting.removeHrmUserSettingComInfoCache(); + } + } + } + } catch (Exception e) { + writeLog(e.getMessage()); + } + + rs.execute("update HrmResource set " + DbFunctionUtil.getUpdateSetSql(rs.getDBType(), user.getUID()) + " where id=" + id); + rs.execute("update HrmResourceManager set " + DbFunctionUtil.getUpdateSetSql(rs.getDBType(), user.getUID()) + " where id=" + id); + + //写入操作后日志 + LogUtil.writeBizLog(logger.getBizLogContexts()); + + //修改人员实时同步到CoreMail邮件系统 + //CoreMailAPI.synUser(id); + + HrmFaceCheckManager.sync(id, HrmFaceCheckManager.getOptUpdate(), "hrm_e9_HrmResourceBaseService_editResourceBase", HrmFaceCheckManager.getOaResource()); + + retmap.put("status", "1"); + } catch (Exception e) { + writeLog(e); + retmap.put("status", "-1"); + retmap.put("message", ""+ SystemEnv.getHtmlLabelName(22620,weaver.general.ThreadVarLanguage.getLang())+""); + } + return retmap; + } + + /** + * 校验数据合法性 + */ + public Map hrmResourceCheck(HttpServletRequest request, HttpServletResponse response) { + Map retmap = new HashMap(); + try { + User user = HrmUserVarify.getUser(request, response); + RecordSet rs = new RecordSet(); + String id = Util.null2String(request.getParameter("id")); + String temName = Util.null2String(request.getParameter("lastname")); + String temCode = Util.null2String(request.getParameter("workcode")); + String temTelephone = Util.null2String(request.getParameter("telephone")); + String temMobile = Util.null2String(request.getParameter("mobile")); + + String checkMessage = ""; + boolean isCheckHas = false; + boolean isCheckHasName = false; + boolean isCheck = false; + + String tempSql = ""; + + if (temTelephone.equals("sysadmin") || temMobile.equals("sysadmin")) { + checkMessage = SystemEnv.getHtmlLabelName(22305, user.getLanguage()); + isCheck = true; + } + + if (!temCode.equals("")) { + tempSql = "select workcode from HrmResource where workcode='" + temCode + "' "; + if (temCode.equals("sysadmin")) { + checkMessage = SystemEnv.getHtmlLabelName(510739, user.getLanguage()); //判断workcode编号是不是sysadmin + isCheck = true; + } + if (id.length() > 0) { + tempSql += " and id !=" + id; + } + rs.executeSql(tempSql); + if (rs.next()) { + String workcode = rs.getString("workcode"); + if (workcode.equals(temCode)) { + checkMessage = SystemEnv.getHtmlLabelName(21447, user.getLanguage()); + isCheckHas = true; + // 删除和编号重复的预留编号 + String sql = "delete from hrm_coderulereserved where id in(select hcr.id from hrm_coderulereserved hcr left join hrm_coderule hc ON hcr.coderuleid = hc.id where hc.serialtype = ? and reservedcode = ?)"; + rs.executeUpdate(sql, RuleCodeType.USER.getValue(), temCode); + } + } + } + if (!temName.equals("")) { + tempSql = "select lastname from HrmResource where lastname='" + temName + "' "; + if (id.length() > 0) { + tempSql += " and id !=" + id; + } + rs.executeSql(tempSql); + if (rs.next()) { + if (!isCheckHas) { + checkMessage = SystemEnv.getHtmlLabelName(21445, user.getLanguage()); + } else { + checkMessage = SystemEnv.getHtmlLabelName(21446, user.getLanguage()); + } + isCheckHasName = true; + } + } + + if ((isCheckHas && isCheckHasName) || (isCheckHas && !isCheckHasName) || (isCheck)) { + retmap.put("status", "-1"); + retmap.put("message", checkMessage); + } else if (!isCheckHas && isCheckHasName) { + retmap.put("status", "-1"); + retmap.put("messagetype", "confirm"); + retmap.put("message", checkMessage); + } else { + retmap.put("status", "1"); + } + } catch (Exception e) { + writeLog(e); + } + return retmap; + } + + + @SuppressWarnings({"unchecked", "rawtypes"}) + public String duplicateRemoval(String str, String userid) { + String[] ss = str.split(","); + List list = new ArrayList(); + for (String s : ss) { + list.add(s.trim()); + } + HashSet hs = new HashSet(list); + list.clear(); + list.addAll(hs); + if (list.contains(userid)) list.remove(userid); + str = list.toString().replace("[", "").replace("]", "").replace(" ", ""); + return str; + } + + /** + * 获取允许个人编辑的字段数量 + * @param scopeid + * @return + */ + public boolean isHasModify(int scopeid) { + int fieldNum = 0; + HrmFieldGroupComInfo HrmFieldGroupComInfo = new HrmFieldGroupComInfo(); + HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo(); + HrmFieldManager hfm = new HrmFieldManager("HrmCustomFieldByInfoType", scopeid); + + StaticObj staticobj = StaticObj.getInstance(); + String multilanguage = (String) staticobj.getObject("multilanguage"); + if (multilanguage == null) multilanguage = "n"; + boolean isMultilanguageOK = false; + if (multilanguage.equals("y")) isMultilanguageOK = true; + boolean flagaccount = GCONST.getMOREACCOUNTLANDING(); + + while (HrmFieldGroupComInfo.next()) { + int grouptype = Util.getIntValue(HrmFieldGroupComInfo.getType()); + if (grouptype != scopeid) continue; + int grouplabel = Util.getIntValue(HrmFieldGroupComInfo.getLabel()); + int groupid = Util.getIntValue(HrmFieldGroupComInfo.getid()); + hfm.getCustomFields(groupid); + while (hfm.next()) { + String fieldName = hfm.getFieldname(); + //没有开启多语言即使开启了系统语言允许个人编辑也不行 + if (fieldName.equals("systemlanguage") && !isMultilanguageOK) continue; + //没有开启主从账号,账号类型也要过滤 + if (fieldName.equals("accounttype") && !flagaccount) continue; + if (fieldName.equals("belongto") && flagaccount) continue; + if (fieldName.equals("loginid") || fieldName.equals("jobactivity") || fieldName.equals("status") || fieldName.equals("departmentvirtualids")) continue; + if (fieldName.equals("messagerurl") || fieldName.equals("jobGroupId")) continue; + if (!hfm.isUse() || !hfm.isModify()) { + continue; + } + fieldNum++; + } + + //个人信息还需要检查自定义子信息是否有允许个人修改的字段 + if (scopeid == 1) { + //自定义信息 + RecordSet RecordSet = new RecordSet(); + CustomFieldTreeManager CustomFieldTreeManager = new CustomFieldTreeManager(); + LinkedHashMap ht = new LinkedHashMap(); + RecordSet.executeSql("select id, formlabel,viewtype from cus_treeform where parentid=" + scopeid + " order by scopeorder"); + while (RecordSet.next()) { + if (RecordSet.getInt("viewtype") != 1) continue; + int subId = RecordSet.getInt("id"); + CustomFieldManager cfm2 = new CustomFieldManager("HrmCustomFieldByInfoType", subId); + cfm2.getCustomFields(); + int colcount1 = cfm2.getSize(); + if (colcount1 != 0) { + while (cfm2.next()) { + if (!cfm2.isUse() || (!cfm2.isModify())) continue; + fieldNum++; + } + } + } + } + } + if (fieldNum > 0) return true; + return false; + } + + public boolean canEditUserIcon() { + RecordSet recordSet = new RecordSet(); + int isModify = 0; + recordSet.executeQuery("select isModify from hrm_formfield where fieldname = ?", "messagerurl"); + if (recordSet.next()) { + isModify = recordSet.getInt("isModify"); + } + if (isModify == 1) { + return true; + } else { + return false; + } + } + + public Map refreshPinyin(HttpServletRequest request, HttpServletResponse response) { + Map retmap = new HashMap(); + try { + User user = HrmUserVarify.getUser(request, response); + if (user.isAdmin()) { + upgradeSearchPinyin(); + retmap.put("status", "1"); + } else { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage())); + } + } catch (Exception ex) { + ex.printStackTrace(); + writeLog(ex); + retmap.put("status", "-1"); + retmap.put("message", "failed"); + } + return retmap; + } + + public void upgradeSearchPinyin() { + try { + RecordSet rs = new RecordSet(); + rs.executeQuery("select id, lastname from hrmresource"); + while (rs.next()) { + RecordSet rs1 = new RecordSet(); + String id = Util.null2String(rs.getString("id")); + String lastname = Util.null2String(rs.getString("lastname")); + String quickSearchStr = new HrmCommonServiceImpl().generateQuickSearchStr(lastname); + + try { + rs1.executeUpdate("update hrmresource set PINYINLASTNAME = ?, ECOLOGY_PINYIN_SEARCH = ? where id = ?", quickSearchStr, quickSearchStr, id); + } catch (Exception e) { + writeLog(e); + e.printStackTrace(); + } + } + } catch (Exception ex) { + writeLog(ex); + ex.printStackTrace(); + } + } + + public void upgradeAreaSearchPinyin(){ + try{ + String id = ""; + String name = ""; + + RecordSet rs = new RecordSet(); + RecordSet rs1 = new RecordSet(); + + rs.executeQuery("select id, countryname as name from hrmcountry"); + while (rs.next()) { + id = Util.null2String(rs.getString("id")); + name = Util.null2String(rs.getString("name")); + String quickSearchStr = new HrmCommonServiceImpl().generateQuickSearchStr(name); + + try { + rs1.executeUpdate("update hrmcountry set quicksearch = ? where id = ?", quickSearchStr, id); + } catch (Exception e) { + writeLog(e); + e.printStackTrace(); + } + } + + rs.executeQuery("select id, provincename as name from hrmprovince"); + while (rs.next()) { + id = Util.null2String(rs.getString("id")); + name = Util.null2String(rs.getString("name")); + String quickSearchStr = new HrmCommonServiceImpl().generateQuickSearchStr(name); + + try { + rs1.executeUpdate("update hrmprovince set quicksearch = ? where id = ?", quickSearchStr, id); + } catch (Exception e) { + writeLog(e); + e.printStackTrace(); + } + } + + rs.executeQuery("select id, cityname as name from HRMCITY"); + while (rs.next()) { + id = Util.null2String(rs.getString("id")); + name = Util.null2String(rs.getString("name")); + String quickSearchStr = new HrmCommonServiceImpl().generateQuickSearchStr(name); + + try { + rs1.executeUpdate("update HRMCITY set quicksearch = ? where id = ?", quickSearchStr, id); + } catch (Exception e) { + writeLog(e); + e.printStackTrace(); + } + } + + rs.executeQuery("select id, cityname as name from HrmCityTwo"); + while (rs.next()) { + id = Util.null2String(rs.getString("id")); + name = Util.null2String(rs.getString("name")); + String quickSearchStr = new HrmCommonServiceImpl().generateQuickSearchStr(name); + + try { + rs1.executeUpdate("update HrmCityTwo set quicksearch = ? where id = ?", quickSearchStr, id); + } catch (Exception e) { + writeLog(e); + e.printStackTrace(); + } + } + }catch (Exception ex){ + ex.printStackTrace(); + writeLog(ex); + } + } +} diff --git a/src/com/api/hrm/service/HrmResourcePersonalService.java b/src/com/api/hrm/service/HrmResourcePersonalService.java new file mode 100644 index 0000000..57473f5 --- /dev/null +++ b/src/com/api/hrm/service/HrmResourcePersonalService.java @@ -0,0 +1,763 @@ +package com.api.hrm.service; + +import com.alibaba.fastjson.JSONObject; +import com.api.browser.bean.SearchConditionItem; +import com.api.hrm.bean.HrmFieldBean; +import com.api.hrm.util.*; +import com.cloudstore.dev.api.util.TextUtil; +import com.engine.common.biz.SimpleBizLogger; +import com.engine.common.constant.BizLogOperateType; +import com.engine.common.constant.BizLogSmallType4Hrm; +import com.engine.common.constant.BizLogType; +import com.engine.common.entity.BizLogContext; +import com.engine.common.util.LogUtil; +import com.engine.common.util.ParamUtil; +import com.engine.hrm.biz.HrmFieldManager; +import com.engine.hrm.util.face.HrmFaceCheckManager; +import weaver.common.DateUtil; +import weaver.common.StringUtil; +import weaver.conn.RecordSet; +import weaver.docs.docs.CustomFieldManager; +import weaver.encrypt.EncryptUtil; +import weaver.file.FileUpload; +import weaver.file.ImageFileManager; +import weaver.general.BaseBean; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.hrm.common.DbFunctionUtil; +import weaver.hrm.definedfield.HrmFieldGroupComInfo; +import weaver.hrm.moduledetach.ManageDetachComInfo; +import weaver.hrm.resource.AllManagers; +import weaver.hrm.resource.CustomFieldTreeManager; +import weaver.hrm.resource.HrmListValidate; +import weaver.hrm.resource.ResourceComInfo; +import weaver.hrm.settings.HrmSettingsComInfo; +import weaver.systeminfo.SysMaintenanceLog; +import weaver.systeminfo.SystemEnv; +import weaver.systeminfo.systemright.CheckSubCompanyRight; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.util.*; + +/*** + * 人员卡片 + * @author lvyi + * + */ +public class HrmResourcePersonalService extends BaseBean { + private static final char separator = Util.getSeparator() ; + private String today = DateUtil.getCurrentDate(); + + /** + * 查看人员个人信息 + * @param request + * @param response + * @return + */ + public String getResourcePesonalView(HttpServletRequest request, HttpServletResponse response){ + User user = HrmUserVarify.getUser(request, response); + HrmSettingsComInfo hrmSettingsComInfo = new HrmSettingsComInfo(); + HrmResourceBaseService hrmResourceBaseService = new HrmResourceBaseService(); + HrmFieldManager hfm = new HrmFieldManager("HrmCustomFieldByInfoType",1); + String checkIsEdit = hrmSettingsComInfo.getCheckIsEdit(); + new BaseBean().writeLog("checkIsEdit==="+checkIsEdit); + Map retmap = new HashMap(); + Map result = new HashMap(); + try{ + String id = Util.null2String(request.getParameter("id")); + if(id.length()==0){ + id = ""+user.getUID(); + } + boolean isSelf = false; + if (id.equals("" + user.getUID())) { + isSelf = true; + } + if (id.equals("")) id = String.valueOf(user.getUID()); + String status = ""; + String subcompanyid = "", departmentId = ""; + RecordSet rs = new RecordSet(); + HttpSession session = request.getSession(true); + rs.executeSql("select subcompanyid1, status, departmentId from hrmresource where id = " + id); + if (rs.next()) { + status = Util.toScreen(rs.getString("status"), user.getLanguage()); + subcompanyid = Util.toScreen(rs.getString("subcompanyid1"), user.getLanguage()); + departmentId = StringUtil.vString(rs.getString("departmentId")); + if (subcompanyid == null || subcompanyid.equals("") || subcompanyid.equalsIgnoreCase("null")) + subcompanyid = "-1"; + + } + + int operatelevel = -1; + //人力资源模块是否开启了管理分权,如不是,则不显示框架,直接转向到列表页面(新的分权管理) + int hrmdetachable = 0; + ManageDetachComInfo ManageDetachComInfo = new ManageDetachComInfo(); + boolean isUseHrmManageDetach = ManageDetachComInfo.isUseHrmManageDetach(); + if (isUseHrmManageDetach) { + hrmdetachable = 1; + } else { + hrmdetachable = 0; + } + if (hrmdetachable == 1) { + CheckSubCompanyRight CheckSubCompanyRight = new CheckSubCompanyRight(); + operatelevel = CheckSubCompanyRight.ChkComRightByUserRightCompanyId(user.getUID(), "HrmResourceEdit:Edit", Util.getIntValue(subcompanyid)); + } else { + if (HrmUserVarify.checkUserRight("HrmResourceEdit:Edit", user, departmentId)) { + operatelevel = 2; + } + } + Map buttons = new Hashtable(); + if (((isSelf&&hrmResourceBaseService.isHasModify(1)) || operatelevel > 0) && !status.equals("10")) { + buttons.put("hasEdit", true); + buttons.put("hasSave", true); + } + + HrmListValidate HrmListValidate = new HrmListValidate(); + AllManagers AllManagers = new AllManagers(); + boolean isManager = false; + AllManagers.getAll(id); + if (id.equals("" + user.getUID())) { + isSelf = true; + } + while (AllManagers.next()) { + String tempmanagerid = AllManagers.getManagerID(); + if (tempmanagerid.equals("" + user.getUID())) { + isManager = true; + } + } + if ((isSelf || operatelevel >= 0) && HrmListValidate.isValidate(11)) { + result.put("buttons", buttons); + Map tmp = getFormFields(request, response, false); + result.put("conditions", tmp.get("conditions")); + result.put("tables", tmp.get("tables")); + result.put("id", id); + }else{ + result.put("hasRight", false); + } +// +// if(HrmUserVarify.checkUserRight("HrmResourceEdit:Edit",user)||(isSelf&&hrmResourceBaseService.isHasModify(1))) { +// buttons.put("hasEdit", true); +// buttons.put("hasSave", true); +// } + + }catch (Exception e) { + writeLog(e); + } + + retmap.put("result", result); + return JSONObject.toJSONString(retmap); + } + + /** + * 人员个人信息表单字段 + * @param request + * @param response + * @return + */ + public Map getFormFields(HttpServletRequest request, HttpServletResponse response, boolean isAdd){ + User user = HrmUserVarify.getUser(request, response); + Map result = new HashMap(); + List lsGroup = new ArrayList(); + Map groupitem = null; + List itemlist = null; + try{ + String id = Util.null2String(request.getParameter("id")); + int viewAttr = Util.getIntValue(request.getParameter("viewAttr"),1); + if(isAdd)viewAttr=2; + if(id.length()==0){ + id = ""+user.getUID(); + } + boolean isSelf = false; + if (id.equals("" + user.getUID())) { + isSelf = true; + } + String subcompanyid = "", departmentId = ""; + RecordSet recordSet = new RecordSet(); + //不能直接判断是否有人力资源维护权限,也需要根据分权进行判断 + boolean canEdit = false; + recordSet.executeSql("select subcompanyid1, status, departmentId from hrmresource where id = " + id); + if (recordSet.next()) { + subcompanyid = Util.toScreen(recordSet.getString("subcompanyid1"), user.getLanguage()); + departmentId = StringUtil.vString(recordSet.getString("departmentId")); + if (subcompanyid == null || subcompanyid.equals("") || subcompanyid.equalsIgnoreCase("null")) + subcompanyid = "-1"; + } + int operatelevel = -1; + //人力资源模块是否开启了管理分权,如不是,则不显示框架,直接转向到列表页面(新的分权管理) + int hrmdetachable = 0; + ManageDetachComInfo ManageDetachComInfo = new ManageDetachComInfo(); + boolean isUseHrmManageDetach = ManageDetachComInfo.isUseHrmManageDetach(); + if (isUseHrmManageDetach) { + hrmdetachable = 1; + } else { + hrmdetachable = 0; + } + if (hrmdetachable == 1) { + CheckSubCompanyRight CheckSubCompanyRight = new CheckSubCompanyRight(); + operatelevel = CheckSubCompanyRight.ChkComRightByUserRightCompanyId(user.getUID(), "HrmResourceEdit:Edit", Util.getIntValue(subcompanyid)); + } else { + if (HrmUserVarify.checkUserRight("HrmResourceEdit:Edit", user, departmentId)) { + operatelevel = 2; + } + } + if(operatelevel>0){ + canEdit = true; + } + int scopeId = 1; + HrmFieldGroupComInfo HrmFieldGroupComInfo = new HrmFieldGroupComInfo(); + HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo(); + HrmFieldManager hfm = new HrmFieldManager("HrmCustomFieldByInfoType",scopeId); + CustomFieldManager cfm = new CustomFieldManager("HrmCustomFieldByInfoType",scopeId); + if(viewAttr!=1)hfm.isReturnDecryptData(true); + hfm.getHrmData(Util.getIntValue(id)); + cfm.getCustomData(Util.getIntValue(id)); + HrmListValidate hrmListValidate = new HrmListValidate(); + + while(HrmFieldGroupComInfo.next()){ + int grouptype = Util.getIntValue(HrmFieldGroupComInfo.getType()); + if(grouptype!=scopeId)continue; + int grouplabel = Util.getIntValue(HrmFieldGroupComInfo.getLabel()); + int groupid = Util.getIntValue(HrmFieldGroupComInfo.getid()); + hfm.getCustomFields(groupid); + + groupitem = new HashMap(); + itemlist = new ArrayList(); + groupitem.put("title", SystemEnv.getHtmlLabelName(grouplabel, user.getLanguage())); + groupitem.put("defaultshow", true); + if(groupid==4){ + groupitem.put("hide", (!isAdd&&!canEdit&&isSelf&&viewAttr==2&&hfm.getContactEditCount()==0)||!hrmListValidate.isValidate(42)); + }else{ + groupitem.put("hide", (!isAdd&&!canEdit&&isSelf&&viewAttr==2&&hfm.getContactEditCount()==0)||!Util.null2String(HrmFieldGroupComInfo.getIsShow()).equals("1")); + } + groupitem.put("items", itemlist); + lsGroup.add(groupitem); + while(hfm.next()){ + int tmpviewattr = viewAttr; + String fieldName=hfm.getFieldname(); + String cusFieldname = ""; + String fieldValue=""; + if(hfm.isBaseField(fieldName)){ + fieldValue = hfm.getHrmData(fieldName); + }else{ + fieldValue = Util.null2String(new EncryptUtil().decrypt("cus_fielddata","field" + hfm.getFieldid(),"HrmCustomFieldByInfoType",""+scopeId,cfm.getData("field" + hfm.getFieldid()),viewAttr==2,true)); + cusFieldname = "customfield"+hfm.getFieldid(); + if(isAdd) cusFieldname = "customfield_1_"+hfm.getFieldid(); + } + + if(!hfm.isUse()||(!isAdd&&viewAttr==2&&!canEdit&&isSelf&&!hfm.isModify())){ + HrmFieldBean hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname(cusFieldname.length() > 0 ? cusFieldname : fieldName); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("1"); + if(!isAdd){ + hrmFieldBean.setFieldvalue(fieldValue); + } + hrmFieldBean.setIsFormField(true); + SearchConditionItem searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + Map otherParams = new HashMap(); + otherParams.put("hide", true); + searchConditionItem.setOtherParams(otherParams); + itemlist.add(searchConditionItem); + continue; + } + org.json.JSONObject hrmFieldConf = hfm.getHrmFieldConf(fieldName); + HrmFieldBean hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldid((String)hrmFieldConf.get("id")); + hrmFieldBean.setFieldname(cusFieldname.length()>0?cusFieldname:fieldName); + hrmFieldBean.setFieldlabel(hfm.getLable()); + hrmFieldBean.setFieldhtmltype((String)hrmFieldConf.get("fieldhtmltype")); + hrmFieldBean.setType((String)hrmFieldConf.get("type")); + hrmFieldBean.setDmlurl((String)hrmFieldConf.get("dmlurl")); + hrmFieldBean.setIssystem(""+(Integer)hrmFieldConf.get("issystem")); + if(!isAdd){ + hrmFieldBean.setFieldvalue(fieldValue); + } + hrmFieldBean.setIsFormField(true); + if(viewAttr==2 && ((String)hrmFieldConf.get("ismand")).equals("1")){ + tmpviewattr=3; + if(hrmFieldBean.getFieldhtmltype().equals("3")){ + hrmFieldBean.setRules("required|string"); +// if (hrmFieldBean.getType().equals("2")||hrmFieldBean.getType().equals("161")||hrmFieldBean.getType().equals("162")) { +// hrmFieldBean.setRules("required|string"); +// }else{ +// hrmFieldBean.setRules("required|integer"); +// } + }else if(hrmFieldBean.getFieldhtmltype().equals("4")|| + hrmFieldBean.getFieldhtmltype().equals("5")){ + hrmFieldBean.setRules("required|integer"); + } else if (hrmFieldBean.getFieldhtmltype().equals("1") && hrmFieldBean.getType().equals("2")) { + hrmFieldBean.setRules("required|integer"); + }else{ + hrmFieldBean.setRules("required|string"); + } + } + + SearchConditionItem searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + if(searchConditionItem==null)continue; + if(searchConditionItem.getBrowserConditionParam()!=null){ + searchConditionItem.getBrowserConditionParam().setViewAttr(tmpviewattr); + } + searchConditionItem.setViewAttr(tmpviewattr); + itemlist.add(searchConditionItem); + } + if(itemlist.size()==0)lsGroup.remove(groupitem); + } + result.put("conditions", lsGroup); + + //明细信息 + List lsTable = new ArrayList(); + List titles = null; + Map table = null; + Map maptab = null; + HrmFieldBean hrmFieldBean = null; + List> columns = null; + List> datas = null; + Map data = null; + result.put("tables",lsTable); + + //标头信息--家庭信息 + HrmFieldDetailComInfo HrmFieldDetailComInfo = new HrmFieldDetailComInfo(); + LinkedHashMap> detialTable = HrmFieldDetailComInfo.getDetialTable(""+scopeId, viewAttr, "80%"); + Iterator>> entries = detialTable.entrySet().iterator(); + while(entries.hasNext()){ + Map.Entry> entry = entries.next(); + String tablename = entry.getKey(); + titles = entry.getValue(); + table = new HashMap(); + columns = HrmFieldUtil.getHrmDetailTable(titles, null, user); + table.put("columns", columns); + + datas = new ArrayList>(); + RecordSet rs = new RecordSet(); + String sql = "select * from "+tablename+" where resourceid = "+id; + rs.executeSql(sql); + while(rs.next()){ + data = new HashMap(); + for(HrmFieldBean fieldInfo :titles){ + if (!isAdd){ + data.put(fieldInfo.getFieldname(), TextUtil.toBase64ForMultilang(Util.null2String(rs.getString(fieldInfo.getFieldname())))); + } + } + datas.add(data); + } + table.put("datas", datas); + table.put("rownum","rownum"); + maptab = new Hashtable(); + String tablabel = HrmResourceDetailTab.HrmResourceDetailTabInfo.get(tablename.toUpperCase()); + maptab.put("tabname", SystemEnv.getHtmlLabelNames(tablabel,user.getLanguage())); + maptab.put("hide", (!hrmListValidate.isValidate(45)||(!isAdd&&!canEdit&&isSelf&&viewAttr==2))); + maptab.put("tabinfo", table); + lsTable.add(maptab); + } + + //自定义信息 + RecordSet RecordSet = new RecordSet(); + CustomFieldTreeManager CustomFieldTreeManager = new CustomFieldTreeManager(); + LinkedHashMap ht = new LinkedHashMap(); + RecordSet.executeSql("select id, formlabel,viewtype from cus_treeform where parentid="+scopeId+" order by scopeorder"); + while(RecordSet.next()){ + if(RecordSet.getInt("viewtype")!=1)continue; + titles = new ArrayList(); + int subId = RecordSet.getInt("id"); + CustomFieldManager cfm2 = new CustomFieldManager("HrmCustomFieldByInfoType",subId); + cfm2.getCustomFields(); + CustomFieldTreeManager.getMutiCustomData("HrmCustomFieldByInfoType", subId, Util.getIntValue(id,0)); + int colcount1 = 0 ; + int rowcount = 0; + int col = 0; + while(cfm2.next()){ + rowcount++; + if(!cfm2.isUse()||(!isAdd&&viewAttr==2&&!canEdit&&isSelf&&!cfm2.isModify()))continue; + col++; + } + if(rowcount==0)continue; + cfm2.beforeFirst(); + ht.put("cus_list_" + subId, RecordSet.getString("formlabel")); + cfm2.beforeFirst(); + while (cfm2.next()) { + if(!cfm2.isUse()||(!isAdd&&viewAttr==2&&!canEdit&&isSelf&&!cfm2.isModify()))continue; + int tmpviewattr = viewAttr; + //创建表头 + String fieldname = "customfield" + cfm2.getId() + "_" + subId; + if (isAdd) fieldname = "customfield_1_" + cfm2.getId() + "_" + subId; + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldid("" + cfm2.getId()); + hrmFieldBean.setFieldname(fieldname); + hrmFieldBean.setFieldlabel(cfm2.getLable()); + hrmFieldBean.setFieldhtmltype(cfm2.getHtmlType()); + hrmFieldBean.setType("" + cfm2.getType()); + hrmFieldBean.setDmlurl(cfm2.getDmrUrl()); + if (viewAttr == 2 && cfm2.isMand()) { + tmpviewattr = 3; + hrmFieldBean.setRules("required|string"); + } + hrmFieldBean.setViewAttr(tmpviewattr); + hrmFieldBean.setWidth("80%"); + titles.add(hrmFieldBean); + } + table = new HashMap(); + if(col>0){ + columns = HrmFieldUtil.getHrmDetailTable(titles, null, user); + table.put("columns", columns); + } + datas = new ArrayList>(); + cfm2.beforeFirst(); + while (CustomFieldTreeManager.nextMutiData()) { + data = new HashMap(); + while (cfm2.next()) { +// if(!cfm2.isUse()||(!isAdd&&viewAttr==2&&!canEdit&&isSelf&&!cfm2.isModify()))continue; + int fieldid = cfm2.getId(); //字段id + int type = cfm2.getType(); + String dmlurl = cfm2.getDmrUrl(); + int fieldhtmltype = Util.getIntValue(cfm2.getHtmlType()); + + String fieldname = "customfield" + cfm2.getId() + "_" + subId; + if (isAdd) fieldname = "customfield_1_" + cfm2.getId() + "_" + subId; + String fieldvalue = ""; + if (!isAdd){ + fieldvalue = Util.null2String(CustomFieldTreeManager.getMutiData("field" + fieldid)); + } + data.put(fieldname, fieldvalue); + if (cfm2.getHtmlType().equals("1") && cfm2.getType() == 1) { + data.put(fieldname, TextUtil.toBase64ForMultilang(Util.null2String(fieldvalue))); + } else if (cfm2.getHtmlType().equals("3")) { + String fieldshowname = hfm.getFieldvalue(user, dmlurl, fieldid, fieldhtmltype, type, fieldvalue, 0); + data.put(fieldname, fieldvalue); + data.put(fieldname + "span", fieldshowname); + } else if (cfm2.getHtmlType().equals("4")) { + data.put(fieldname, fieldvalue.equals("1")); + } else if(cfm2.getHtmlType().equals("6")){ + List filedatas = new ArrayList(); + if(Util.null2String(fieldvalue).length()>0) { + Map filedata = null; + String[] tmpIds = Util.splitString(Util.null2String(fieldvalue), ","); + for (int i = 0; i < tmpIds.length; i++) { + String fileid = tmpIds[i]; + ImageFileManager manager = new ImageFileManager(); + manager.getImageFileInfoById(Util.getIntValue(fileid)); + String filename = manager.getImageFileName(); + String extname = filename.contains(".") ? filename.substring(filename.lastIndexOf(".") + 1) : ""; + filedata = new HashMap(); + filedata.put("acclink", "/weaver/weaver.file.FileDownload?fileid=" + fileid); + filedata.put("fileExtendName", extname); + filedata.put("fileid", fileid); + filedata.put("filelink", "/spa/document/index2file.jsp?imagefileId=" + fileid + "#/main/document/fileView"); + filedata.put("filename", filename); + filedata.put("filesize", manager.getImgsize()); + filedata.put("imgSrc", ""); + filedata.put("isImg", ""); + filedata.put("loadlink", "/weaver/weaver.file.FileDownload?fileid=" + fileid + "&download=1"); + filedata.put("showDelete", viewAttr==2); + filedata.put("showLoad", "true"); + filedatas.add(filedata); + } + } + data.put(fieldname, filedatas); + } + //只允许有权限的人删除明细行,没有权限的人只能修改不能删除 + if (canEdit) { + data.put("viewAttr", 2); + } else { + data.put("viewAttr", 1); + } + } + cfm2.beforeFirst(); + datas.add(data); + } + table.put("datas", datas); + table.put("rownum", "nodesnum_" + subId); + maptab = new Hashtable(); + RecordSet rs = new RecordSet(); + rs.executeSql("select id, formlabel from cus_treeform where parentid=" + scopeId + " and id=" + subId + " order by scopeorder"); + if (rs.next()) { + maptab.put("tabname", rs.getString("id")); + maptab.put("tabname", rs.getString("formlabel")); + } + maptab.put("hide", col == 0); + maptab.put("tabinfo", table); + lsTable.add(maptab); + } + }catch (Exception e) { + writeLog(e); + } + return result; + } + + /*** + * 新建人员个人信息 + * @param request + * @param response + * @return + */ + public Map addResourcePersonal(String id, HttpServletRequest request, HttpServletResponse response){ + Map retmap = new HashMap(); + try{ + User user = HrmUserVarify.getUser(request, response); + RecordSet rs = new RecordSet(); + ResourceComInfo ResourceComInfo = new ResourceComInfo(); + CustomFieldTreeManager CustomFieldTreeManager = new CustomFieldTreeManager(); + + String para = ""; + FileUpload fu = new FileUpload(request); + //String id = Util.null2String(fu.getParameter("id")); + String birthday = Util.fromScreen3(fu.getParameter("birthday"),user.getLanguage()); + String folk = Util.fromScreen3(fu.getParameter("folk"),user.getLanguage()) ; /*民族*/ + String nativeplace = Util.fromScreen3(fu.getParameter("nativeplace"),user.getLanguage()) ; /*籍贯*/ + String regresidentplace = Util.fromScreen3(fu.getParameter("regresidentplace"),user.getLanguage()) ; /*户口所在地*/ + String maritalstatus = Util.fromScreen3(fu.getParameter("maritalstatus"),user.getLanguage()); + String policy = Util.fromScreen3(fu.getParameter("policy"),user.getLanguage()) ; /*政治面貌*/ + String bememberdate = Util.fromScreen3(fu.getParameter("bememberdate"),user.getLanguage()) ; /*入团日期*/ + String bepartydate = Util.fromScreen3(fu.getParameter("bepartydate"),user.getLanguage()) ; /*入党日期*/ + String islabourunion = Util.fromScreen3(fu.getParameter("islabouunion"),user.getLanguage()) ; + String educationlevel = Util.fromScreen3(fu.getParameter("educationlevel"),user.getLanguage()) ;/*学历*/ + String degree = Util.fromScreen3(fu.getParameter("degree"),user.getLanguage()) ; /*学位*/ + String healthinfo = Util.fromScreen3(fu.getParameter("healthinfo"),user.getLanguage()) ;/*健康状况*/ + String height = Util.null2o(fu.getParameter("height")) ;/*身高*/ + String weight = Util.null2o(fu.getParameter("weight")) ; + String residentplace = Util.fromScreen3(fu.getParameter("residentplace"),user.getLanguage()) ; /*现居住地*/ + String homeaddress = Util.fromScreen3(fu.getParameter("homeaddress"),user.getLanguage()) ; + String tempresidentnumber = Util.fromScreen3(fu.getParameter("tempresidentnumber"),user.getLanguage()) ; + String certificatenum = Util.fromScreen3(fu.getParameter("certificatenum"),user.getLanguage()) ;/*证件号码*/ + certificatenum=certificatenum.trim(); + String tempcertificatenum=certificatenum; + + SimpleBizLogger logger = new SimpleBizLogger(); + Map params = ParamUtil.request2Map(request); + BizLogContext bizLogContext = new BizLogContext(); + bizLogContext.setLogType(BizLogType.HRM);//模块类型 + bizLogContext.setBelongType(BizLogSmallType4Hrm.HRM_RSOURCE_CARD);//所属大类型 + bizLogContext.setBelongTypeTargetName(SystemEnv.getHtmlLabelName(15687, user.getLanguage())); + bizLogContext.setLogSmallType(BizLogSmallType4Hrm.HRM_RSOURCE_CARD_PERSONAL);//当前小类型 + bizLogContext.setOperateType(BizLogOperateType.ADD); + bizLogContext.setParams(params);//当前request请求参数 + logger.setUser(user);//当前操作人 + String cusFieldNames = ServiceUtil.getCusFieldNames("HrmCustomFieldByInfoType",1,"b"); + String mainSql = "select a.*"+(cusFieldNames.length()>0?","+cusFieldNames:"")+" from hrmresource a left join cus_fielddata b on a.id=b.id and b.scope='HrmCustomFieldByInfoType' and b.scopeid=1 where a.id="+id; + logger.setMainSql(mainSql,"id");//主表sql + logger.setMainPrimarykey("id");//主日志表唯一key + logger.setMainTargetNameColumn("lastname");//当前targetName对应的列(对应日志中的对象名) + logger.before(bizLogContext);//写入操作前日志 + + int msg=0; + if(!certificatenum.equals("")){ + rs.executeSql("select accounttype,certificatenum from HrmResource where id="+id); + String accountType = "", tempCertificatenum = ""; + if(rs.next()){ + accountType = Util.null2String(rs.getString("accounttype")); + tempCertificatenum = Util.null2String(rs.getString("certificatenum")); + } + if(!accountType.equals("1")) { + rs.executeSql("select id from HrmResource where id<>"+id+" and certificatenum='"+certificatenum+"' and accounttype != '1'"); + if(rs.next()){ + msg=1; + tempcertificatenum = tempCertificatenum; + } + } + } + para = ""+id+ separator+birthday+separator+folk+separator+nativeplace+separator+regresidentplace+separator+ + maritalstatus+ separator+policy+separator+bememberdate+separator+bepartydate+separator+islabourunion+ + separator+educationlevel+separator+degree+separator+healthinfo+separator+height+separator+weight+ + separator+residentplace+separator+homeaddress+separator+tempresidentnumber+separator+tempcertificatenum; + int userid = user.getUID(); + String userpara = ""+userid+separator+today; + rs.executeProc("HrmResourcePersonalInfo_Insert",para); + rs.executeProc("HrmResource_ModInfo",""+id+separator+userpara); + + int rownum = Util.getIntValue(fu.getParameter("rownum"),user.getLanguage()) ; + String prefix = "" ; + if(Boolean.TRUE.equals(HrmResourceAddService.saveStatusThreadLocal.get())){ + prefix="person_" ; + } + + for(int i = 0;i editResourcePersonal(HttpServletRequest request, HttpServletResponse response){ + Map retmap = new HashMap(); + HrmSettingsComInfo hrmSettingsComInfo = new HrmSettingsComInfo(); + + try{ + User user = HrmUserVarify.getUser(request, response); + RecordSet rs = new RecordSet(); + ResourceComInfo ResourceComInfo = new ResourceComInfo(); + CustomFieldTreeManager CustomFieldTreeManager = new CustomFieldTreeManager(); + SysMaintenanceLog SysMaintenanceLog = new SysMaintenanceLog(); + + String para = ""; + FileUpload fu = new FileUpload(request); + String id = Util.null2String(fu.getParameter("id")); + if (!HrmUserVarify.checkUserRight("HrmResourceEdit:Edit", user)) { + if (!id.equals(user.getUID() + "")) { + retmap.put("status", "-1"); + retmap.put("message", ""+ SystemEnv.getHtmlLabelName(22620,weaver.general.ThreadVarLanguage.getLang())+""); + return retmap; + } + } + String birthday = Util.fromScreen3(fu.getParameter("birthday"),user.getLanguage()); + String folk = Util.fromScreen3(fu.getParameter("folk"),user.getLanguage()) ; /*民族*/ + String nativeplace = Util.fromScreen3(fu.getParameter("nativeplace"),user.getLanguage()) ; /*籍贯*/ + String regresidentplace = Util.fromScreen3(fu.getParameter("regresidentplace"),user.getLanguage()) ; /*户口所在地*/ + String maritalstatus = Util.fromScreen3(fu.getParameter("maritalstatus"),user.getLanguage()); + String policy = Util.fromScreen3(fu.getParameter("policy"),user.getLanguage()) ; /*政治面貌*/ + String bememberdate = Util.fromScreen3(fu.getParameter("bememberdate"),user.getLanguage()) ; /*入团日期*/ + String bepartydate = Util.fromScreen3(fu.getParameter("bepartydate"),user.getLanguage()) ; /*入党日期*/ + String islabourunion = Util.fromScreen3(fu.getParameter("islabouunion"),user.getLanguage()) ; + String educationlevel = Util.fromScreen3(fu.getParameter("educationlevel"),user.getLanguage()) ;/*学历*/ + String degree = Util.fromScreen3(fu.getParameter("degree"),user.getLanguage()) ; /*学位*/ + String healthinfo = Util.fromScreen3(fu.getParameter("healthinfo"),user.getLanguage()) ;/*健康状况*/ + String height = Util.null2o(fu.getParameter("height")) ;/*身高*/ + String weight = Util.null2o(fu.getParameter("weight")) ; + String residentplace = Util.fromScreen3(fu.getParameter("residentplace"),user.getLanguage()) ; /*现居住地*/ + String homeaddress = Util.fromScreen3(fu.getParameter("homeaddress"),user.getLanguage()) ; + String tempresidentnumber = Util.fromScreen3(fu.getParameter("tempresidentnumber"),user.getLanguage()) ; + String certificatenum = Util.fromScreen3(fu.getParameter("certificatenum"),user.getLanguage()) ;/*证件号码*/ + certificatenum=certificatenum.trim(); + String tempcertificatenum=certificatenum; + + SimpleBizLogger logger = new SimpleBizLogger(); + Map params = ParamUtil.request2Map(request); + BizLogContext bizLogContext = new BizLogContext(); + bizLogContext.setLogType(BizLogType.HRM);//模块类型 + bizLogContext.setBelongType(BizLogSmallType4Hrm.HRM_RSOURCE_CARD);//所属大类型 + bizLogContext.setBelongTypeTargetName(SystemEnv.getHtmlLabelName(15687, user.getLanguage())); + bizLogContext.setLogSmallType(BizLogSmallType4Hrm.HRM_RSOURCE_CARD_PERSONAL);//当前小类型 + bizLogContext.setParams(params);//当前request请求参数 + logger.setUser(user);//当前操作人 + String cusFieldNames = ServiceUtil.getCusFieldNames("HrmCustomFieldByInfoType",1,"b"); + String mainSql = "select a.*"+(cusFieldNames.length()>0?","+cusFieldNames:"")+" from hrmresource a left join cus_fielddata b on a.id=b.id and b.scope='HrmCustomFieldByInfoType' and b.scopeid=1 where a.id="+id; + logger.setMainSql(mainSql,"id");//主表sql + logger.setMainPrimarykey("id");//主日志表唯一key + logger.setMainTargetNameColumn("lastname");//当前targetName对应的列(对应日志中的对象名) + logger.before(bizLogContext);//写入操作前日志 + + int msg=0; + if(!certificatenum.equals("")&&isNeedCheck(user,id,"certificatenum")){ + rs.executeSql("select accounttype,certificatenum from HrmResource where id="+id); + String accountType = "", tempCertificatenum = ""; + if(rs.next()){ + accountType = Util.null2String(rs.getString("accounttype")); + tempCertificatenum = Util.null2String(rs.getString("certificatenum")); + } + if(!accountType.equals("1")) { + rs.executeSql("select id from HrmResource where id<>"+id+" and certificatenum='"+certificatenum+"' and (accounttype != '1' or accounttype is null)"); + if(rs.next()){ + msg=1; + tempcertificatenum = tempCertificatenum; + retmap.put("status", "-1"); + retmap.put("message", ""+ SystemEnv.getHtmlLabelName(83521,weaver.general.ThreadVarLanguage.getLang())+""); + return retmap; + } + } + } + para = ""+id+ separator+birthday+separator+folk+separator+nativeplace+separator+regresidentplace+separator+ + maritalstatus+ separator+policy+separator+bememberdate+separator+bepartydate+separator+islabourunion+ + separator+educationlevel+separator+degree+separator+healthinfo+separator+height+separator+weight+ + separator+residentplace+separator+homeaddress+separator+tempresidentnumber+separator+tempcertificatenum; + + rs.executeProc("HrmResourcePersonalInfo_Insert",para); + int userid = user.getUID(); + String userpara = ""+userid+separator+today; + rs.executeProc("HrmResource_ModInfo",""+id+separator+userpara); + + int rownum = Util.getIntValue(fu.getParameter("rownum"),user.getLanguage()) ; + rs.executeProc("HrmFamilyInfo_Delete",""+id); + for(int i = 0;i0){ + isAdmin = true; + } + } + return isAdmin; + } + + /** + * 接口中文都需特殊字符转译,否则前端response.json()会报错 + */ + public static String convertChar(String str){ + str = str.replace("\t", ""); + str = str.replace("\r", ""); + str = str.replace("\n", ""); + str = str.replace("\f", ""); + return str; + } + + public static List getDateSelectFromTo(int language){ + return getDateSelectFromTo(language,"0"); + } + /** + * 0-全部,1-今天,2-本周,3-本月,7-上个月,4-本季,5-本年,8-上一年,6-指定日期范围 + * */ + public static List getDateSelectFromTo(int language, String defaultValue){ + if(Util.null2String(defaultValue).length()==0){ + defaultValue = "0"; + } + List options = new ArrayList(); + options.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(332, language),"0".equals(defaultValue))); + options.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(15537, language),"1".equals(defaultValue))); + options.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(15539, language),"2".equals(defaultValue))); + options.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(15541, language),"3".equals(defaultValue))); + options.add(new SearchConditionOption("7", SystemEnv.getHtmlLabelName(27347, language),"7".equals(defaultValue))); + options.add(new SearchConditionOption("4", SystemEnv.getHtmlLabelName(21904, language),"4".equals(defaultValue))); + options.add(new SearchConditionOption("5", SystemEnv.getHtmlLabelName(15384, language),"5".equals(defaultValue))); + options.add(new SearchConditionOption("8", SystemEnv.getHtmlLabelName(81716, language),"8".equals(defaultValue))); + options.add(new SearchConditionOption("6", SystemEnv.getHtmlLabelName(32530, language),"6".equals(defaultValue))); + return options; + } + + /** + * 为input框添加多语言选项 + * @param item + */ + public static void addMultiLanguageProperty(SearchConditionItem item){ + if(!ServiceUtil.isMultilang )return; + Map otherParams = item.getOtherParams(); + if(otherParams == null){ + otherParams = new HashMap(); + } + otherParams.put("inputType","multilang"); + otherParams.put("isBase64",true); + if(Util.null2String(item.getValue()).length()>0){ + item.setValue(TextUtil.toBase64ForMultilang(Util.null2String(item.getValue()))); + } + item.setOtherParams(otherParams); + } + + /** + * 为input框添加多语言选项(用于明细列表) + */ + public static void addMultiLanguageProperty(HrmFieldBean hrmFieldBean){ + if(!ServiceUtil.isMultilang || !hrmFieldBean.getMultilang())return; + Map otherParams = hrmFieldBean.getOtherparam(); + if(otherParams == null){ + otherParams = new HashMap(); + } + if(hrmFieldBean.getFieldhtmltype().equals("1")&&hrmFieldBean.getType().equals("1")){ + otherParams.put("inputType","multilang"); + otherParams.put("isBase64",true); + //hrmFieldBean.setFieldvalue(TextUtil.toBase64ForMultilang(Util.null2String(hrmFieldBean.getFieldvalue()))); + } + if(hrmFieldBean.getOtherparam()!=null){ + otherParams.putAll(hrmFieldBean.getOtherparam()); + } + hrmFieldBean.setOtherparam(otherParams); + } + + public synchronized boolean initOrgLevel(){ + RecordSet rs = new RecordSet(); + RecordSet rs1 = new RecordSet(); + String sql = ""; + boolean needInitOrgLevel = false;//当分部或者部门有修改时,调整tlevel + + String tlvlCondition = DbDialectFactory.get(rs.getDBType()).isNull("tlevel", 0) ; + + String lastinittime = ""; + sql =" select lastinittime from hrmcompany "; + rs.executeSql(sql); + if(rs.next()){ + lastinittime = Util.null2String(rs.getString("lastinittime")); + } + + if(lastinittime.length()==0){//首次初始化 + needInitOrgLevel = true; + }else{ + sql =" select count(1) from hrmsubcompany where modified>(select lastinittime from hrmcompany) "; + rs.executeSql(sql); + if(rs.next()){ + needInitOrgLevel = true; + }else{ + sql =" select count(1) from hrmdepartment where modified>(select lastinittime from hrmcompany) "; + rs.executeSql(sql); + if(rs.next()){ + needInitOrgLevel = true; + } + } + } + + if(needInitOrgLevel){ + if(rs.getDBType().equals("oracle")) { + //oracle的话 tempHrmSubCompanyView是视图,视图里引用了HrmSubCompany,在更新的时候,导致死循环了 改用临时表的方式来处理 + //创建临时表 + String create_tmp_table= "CREATE TABLE "+tempHrmSubCompany_table+" AS SELECT A.ID,B.templevel FROM HrmSubCompany A,tempHrmSubCompanyView B WHERE A.ID=B.ID "; + boolean isok = rs1.executeUpdate(create_tmp_table); + if(isok){ + String update_sql = "update HrmSubCompany set tlevel=(select distinct templevel from "+tempHrmSubCompany_table+" where "+tempHrmSubCompany_table+".id=HrmSubCompany.id) where nvl(tlevel,0)=0 "; + isok = rs1.executeUpdate(update_sql); + //删除临时表 + String drop_tmp_table = "drop table "+tempHrmSubCompany_table; + isok = rs1.executeUpdate(drop_tmp_table); + }else{ + rs.executeSql("update HrmSubCompany set tlevel=(select distinct templevel from tempHrmSubCompanyView where tempHrmSubCompanyView.id=HrmSubCompany.id) where nvl(tlevel,0)=0"); + } + }else if(DialectUtil.isMySql(rs.getDBType())){ + rs.executeSql("update HrmSubCompany left join (select distinct templevel,id from tempHrmSubCompanyView) t on t.id=HrmSubCompany.id set tlevel=t.templevel where "+tlvlCondition+"=0"); + }else { + rs.executeSql("update HrmSubCompany set tlevel=(select distinct level from tempHrmSubCompanyView where tempHrmSubCompanyView.id=HrmSubCompany.id) where isnull(tlevel,0)=0"); + } + + if(rs.getDBType().equals("oracle")) { + //oracle的话 tempHrmSubCompanyView是视图,视图里引用了HrmSubCompany,在更新的时候,导致死循环了 改用临时表的方式来处理 + //创建临时表 + String create_tmp_table= "CREATE TABLE "+tempHrmDepartment_table+" AS SELECT A.ID,B.templevel FROM HrmDepartment A,tempHrmDepartmentView B WHERE A.ID=B.ID "; + boolean isok = rs1.executeUpdate(create_tmp_table); + if(isok){ + String update_sql = "update HrmDepartment set tlevel=(select distinct templevel from "+tempHrmDepartment_table+" where "+tempHrmDepartment_table+".id=HrmDepartment.id) where nvl(tlevel,0)=0"; + isok = rs1.executeUpdate(update_sql); + //删除临时表 + String drop_tmp_table = "drop table "+tempHrmDepartment_table; + isok = rs1.executeUpdate(drop_tmp_table); + }else{ + rs.executeSql("update HrmDepartment set tlevel=(select distinct templevel from tempHrmDepartmentView where tempHrmDepartmentView.id=HrmDepartment.id) where nvl(tlevel,0)=0");; + } + }else if(DialectUtil.isMySql(rs.getDBType())){ + rs.executeSql("update HrmDepartment left join (select distinct templevel,id from tempHrmDepartmentView) t on t.id=HrmDepartment.id set tlevel=t.templevel where "+tlvlCondition+"=0");; + } else { + rs.executeSql("update HrmDepartment set tlevel=(select distinct level from tempHrmDepartmentView where tempHrmDepartmentView.id=HrmDepartment.id) where isnull(tlevel,0)=0"); + } + + sql =" update hrmcompany set lastinittime="+DbFunctionUtil.getCurrentFullTimeFunction(rs.getDBType()); + rs.executeUpdate(sql); + } + + //虚拟组织没有modified 保持原状 + if(rs.getDBType().equals("oracle")) { + rs.executeSql("update HrmSubCompanyVirtual set tlevel=(select distinct templevel from tempHrmSubCompanyVirtualView where tempHrmSubCompanyVirtualView.id=HrmSubCompanyVirtual.id) where nvl(tlevel,0)=0"); + }else if(DialectUtil.isMySql(rs.getDBType())){ + rs.executeSql("update HrmSubCompanyVirtual left join (select distinct templevel,id from tempHrmSubCompanyVirtualView) t on t.id=HrmSubCompanyVirtual.id set tlevel=t.templevel where "+tlvlCondition+"=0"); + } + else if(rs.getDBType().equals("postgresql")) { + rs.executeSql("update HrmSubCompanyVirtual set tlevel=(select distinct templevel from tempHrmSubCompanyVirtualView where tempHrmSubCompanyVirtualView.id=HrmSubCompanyVirtual.id) where isnull(tlevel,0)=0"); + } + else { + rs.executeSql("update HrmSubCompanyVirtual set tlevel=(select distinct level from tempHrmSubCompanyVirtualView where tempHrmSubCompanyVirtualView.id=HrmSubCompanyVirtual.id) where isnull(tlevel,0)=0"); + } + + if(rs.getDBType().equals("oracle")) { + rs.executeSql("update HrmDepartmentVirtual set tlevel=(select distinct templevel from tempHrmDepartmentVirtualView where tempHrmDepartmentVirtualView.id=HrmDepartmentVirtual.id) where nvl(tlevel,0)=0"); + }else if(DialectUtil.isMySql(rs.getDBType())){ + rs.executeSql("update HrmDepartmentVirtual left join (select distinct templevel,id from tempHrmDepartmentVirtualView) t on t.id=HrmDepartmentVirtual.id set tlevel=t.templevel where "+tlvlCondition+"=0"); + } + else if(rs.getDBType().equals("postgresql")) + { + rs.executeSql("update HrmDepartmentVirtual set tlevel=(select distinct templevel from tempHrmDepartmentVirtualView where tempHrmDepartmentVirtualView.id=HrmDepartmentVirtual.id) where isnull(tlevel,0)=0"); + } + else { + rs.executeSql("update HrmDepartmentVirtual set tlevel=(select distinct level from tempHrmDepartmentVirtualView where tempHrmDepartmentVirtualView.id=HrmDepartmentVirtual.id) where isnull(tlevel,0)=0"); + } + + return needInitOrgLevel; + } + + // 人员查看日志改造: +// 1、显示字段为:操作人员、操作时间、客户端地址、查看类型{人员小卡片、人员大卡片、查询人员列表、人员导出}、被查看对象、查看对象部门、查询对象分部、备注。 +// 2、按照查看类型记录不同日志内容: +// (1)人员小卡片:显示其被查看对象、查看对象部门、查询对象分部对应的具体值. +// (2)人员大卡片:显示其被查看对象、查看对象部门、查询对象分部对应的具体值. +// (3)查询人员列表:被查看对象给出其查询条件统计结果集的条数-即本次查询了多少人员,然后在【备注】列显示其按照什么条件进行查询的记录下来. +// (4)人员导出:需要记录其导出结果记录的条数-即本次查询导出了多少人员,然后在【备注】列显示其按照什么条件进行查询导出的记录下来. + + private static ConcurrentHashMap userid_resourceid2time = new ConcurrentHashMap(); + public void writeHrmResourceViewLog(Map params, User user){ + try { + RecordSet rs = new RecordSet(); + ResourceComInfo resourceComInfo = new ResourceComInfo(); + String sql = ""; + String resourceid = Util.null2String(params.get("resourceid")); + String subcompanyid = resourceComInfo.getSubCompanyID(resourceid); + String departmentid = resourceComInfo.getDepartmentID(resourceid); + String operatortype = Util.null2String(params.get("operatortype")); + int operator = user.getUID(); + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 + String operatetime = df.format(new Date()); + String memo = Util.null2String(params.get("memo")); + int resultcount = 0; + String ip = Util.null2String(params.get(ParamConstant.PARAM_IP)); + + if(operatortype.equals("0")){ + String key = user.getUID()+"_"+resourceid; + String time = Util.null2String(userid_resourceid2time.get(user.getUID()+"_"+resourceid)); + if( time.length()>0 && DateUtil.timeInterval(time,operatetime)<2){ + return; + } + userid_resourceid2time.put(key,operatetime); + } + + sql = Util.null2String(params.get("resultcount")); + if(sql.length()>0){ + resultcount = 0; + try{ + rs.executeQuery(sql); + if(rs.next()){ + resultcount = rs.getInt(1); + } + }catch (Exception e){ + writeLog(e); + } + } + + sql = " INSERT INTO hrmresourceviewlog(resourceid,subcompanyid,departmentid,operatortype,operator,operatetime,ip,resultcount,memo) VALUES(?,?,?,?,?,?,?,?,?)"; + rs.executeUpdate(sql,resourceid,subcompanyid,departmentid,operatortype,operator,operatetime,ip,resultcount==0?null:resultcount,memo); + }catch (Exception e){ + writeLog(e); + } + } + + public static String getCusFieldNames(String scope, int scopeid, String ext){ + String cusFieldNames = ""; + String sql = ""; + RecordSet rs = new RecordSet(); + try{ + sql = "select min(seqorder) from cus_fielddata where scope='HrmCustomFieldByInfoType' and scopeid = "+ scopeid; + rs.executeQuery(sql); + String minId = ""; + if(rs.next()){ + minId = Util.null2String(rs.getString(1)); + } + + List lsFieldNames = new ArrayList<>(); + sql = " select * from cus_fielddata where scope='HrmCustomFieldByInfoType' and scopeid="+scopeid; + // 限制数据量 + if(!"".equals(minId)){ + sql += " and seqorder="+minId; + } + + rs.executeQuery(sql); + int colcount = rs.getColCounts(); + if (rs.next()) { + for (int i=4; i<=colcount; i++) { + if(rs.getColumnName(i).toLowerCase().startsWith("field")) { + lsFieldNames.add(rs.getColumnName(i).toLowerCase()); + } + } + } + ext = Util.null2String(ext); + sql = "select fieldid from cus_formfield where scope='HrmCustomFieldByInfoType' and scopeid="+scopeid; + rs.execute(sql); + while (rs.next()){ + String fieldname = "field"+rs.getString("fieldid"); + if(lsFieldNames.contains(fieldname)){ + if(ext.length()>0){ + fieldname = ext+"."+fieldname; + } + if(cusFieldNames.length()>0)cusFieldNames+=","; + cusFieldNames+=fieldname; + } + } + }catch (Exception e){ + new BaseBean().writeLog(e); + } + return cusFieldNames; + } + + public static Map requestJson2Map(HttpServletRequest request){ + Map returnMap = new HashMap(); + try{ + InputStream inStream = request.getInputStream(); + ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + boolean var3 = false; + + int len; + while((len = inStream.read(buffer)) != -1) { + outSteam.write(buffer, 0, len); + } + outSteam.close(); + inStream.close(); + String json = new String(outSteam.toByteArray(), "UTF-8"); + if(Util.null2String(json).length()>0){ + returnMap = JSONObject.parseObject(json, new TypeReference>(){}); + } + }catch (Exception e){ + new BaseBean().writeLog(e); + } + return returnMap; + } + + /** + * 标签名称 + * @param id + * @param para2 + * @return + */ + public String getTargetName(String id, String para2){ + String[] otherParams = Util.TokenizerString2(para2, "+"); + return SystemEnv.getHtmlLabelNames(otherParams[0], Util.getIntValue(otherParams[1],7)); + } + + + public String getTableColumns(String sql, String ext, String excludeColumn){ + String tableColumns = ""; + RecordSet rs = new RecordSet(); + rs.executeQuery(sql); + int colcount = rs.getColCounts(); + for (int i=1; i<=colcount; i++) { + String fieldName = rs.getColumnName(i).toLowerCase(); + if((","+excludeColumn+",").indexOf(","+fieldName+",")==-1){ + if(tableColumns.length()>0)tableColumns+=","; + tableColumns += ext.length()>0?ext+"."+fieldName:fieldName; + } + } + return tableColumns; + } + + /** + * E9调用EM7人员下线接口 + * @param userId 需要被下线的人员id + */ + public void emOffline(String userId){ + RecordSet rs = new RecordSet(); + try { + new Thread() {//以下语句执行比较久,改为异步线程处理 + @Override + public void run() { + synchronized (this) { + try{ + //调用EM接口使人员强制下线EM + String sysid = EMManager.getEMData().get(EMManager.ec_id); //授权使用集成系统id + writeLog("sysid----"+sysid); + Map offlineParams = new HashMap<>(); + offlineParams.put("sysid",sysid); + offlineParams.put("userids",userId); //需要退出的人员ID,多个人员用逗号分隔 + offlineParams.put("client_type","1,2,3,4"); //需要退出的客户端类型:0-全部(默认) 1-EM的PC客户端 2-IOS端 3-安卓端 4-web版 多个端可以用逗号分隔 + APPManager appManager = new APPManager(); + appManager.emOffline(offlineParams); + }catch(Exception e){ + writeLog("EM强制下线失败----;;;uid="+userId+"====",e); + } + } + } + }.start(); + } catch (Exception e) { + writeLog(e); + } + + + } + + /** + * E9的PC端强制下线 + * @param uids + * @param application + */ + public void offLine4PC (String uids, ServletContext application){ + String [] userIds = Util.TokenizerString2(uids,","); + for(String uid:userIds) { + new LicenseCheckLogin().userOffline(uid); + Map userSessions = application == null ? null : (Map) application.getAttribute("userSessions"); + List slist = (userSessions != null && userSessions.containsKey(uid)) ? (List) userSessions.get(uid) : null; + int lsize = slist == null ? 0 : slist.size(); + for (int i = 0; i < lsize; i++) { + try { + slist.get(i).setAttribute("offLine4PC", "1"); + writeLog(uid + "下线成功"); + } catch (IllegalStateException e) { + writeLog("E9的PC端强制下线出现异常",e); + } + } + HrmUserOnlineMap.getInstance().userOffline(uid); + } + + + } + + public static String saveResourceImage(String imgStr){ + String fileId = ""; + try{ + if(Util.null2String(imgStr).length() == 0) { + return ""; + } + if(imgStr.startsWith("*")){ + imgStr = imgStr.substring(1,imgStr.length()); + }else{ + imgStr = Util.splitString(imgStr,",")[1]; + } + BASE64Decoder decoder = new BASE64Decoder(); + byte[] b = decoder.decodeBuffer(imgStr); + for (int i = 0; i < b.length; ++i) { + if (b[i] < 0) { + b[i] += 256; + } + } + UUID uuid = UUID.randomUUID(); + String fileName = uuid.toString().replaceAll("-", "") + ".jpg"; + ImageFileManager imageFileManager = new ImageFileManager(); + imageFileManager.setImagFileName(fileName); + imageFileManager.setData(b); + fileId = ""+imageFileManager.saveImageFile(); + }catch (Exception e){ + new BaseBean().writeLog("saveResourceImage>>>>>>>>>>>>>>>"+e); + } + return fileId; + } + + /** + * @Description 保存头像 + * @auther Murphy + * @date 2019/7/15 19:01 + * @param + * @return java.lang.String + **/ + public static String saveMessagerUrl(int imagefiledid,String userId){ + String imageFilePath = ""; + String imageFileName = UUID.randomUUID().toString() + ".jpg"; + RecordSet recordSet = new RecordSet(); + InputStream in = null; + try{ + String filePath = GCONST.getRootPath() + "messager" + File.separatorChar + "usericon" + File.separatorChar + imageFileName; + ImageFileManager imageFileManager = new ImageFileManager(); + in = imageFileManager.getInputStreamById(imagefiledid); + if(in != null){ + reduceImg(in,filePath); + imageFilePath = "/messager/usericon/" + imageFileName; + String sql = "update hrmresource set messagerurl= ? where id=?"; + recordSet.executeUpdate(sql,imageFilePath,userId); + ResourceComInfo resourceComInfo=new ResourceComInfo(); + resourceComInfo.updateResourceInfoCache(userId); + } + }catch (Exception e){ + recordSet.writeLog(e); + }finally{ + if(in != null){ + try { + in.close(); + }catch(Exception ex){ + recordSet.writeLog(ex); + } + } + } + return imageFilePath; + } + + /** + * 采用指定宽度、高度或压缩比例 的方式对图片进行压缩 + * @param imgdist 目标图片地址 + */ + public static void reduceImg(InputStream in, String imgdist){ + try { + // 开始读取文件并进行压缩 + if(in!=null){ + Thumbnails.of(in).scale(1f).outputQuality(0.8f).toFile(new File(imgdist)); + } + } catch (IOException ex) { + ex.printStackTrace(); + }finally{ + try { + in.close(); + }catch(Exception ex){ + ex.printStackTrace(); + } + } + } + + /** + * 获取图片宽度 + * + * in 图片文件 + * @return 宽度 + */ + public static int[] getImgWidth(InputStream in) { + BufferedImage src = null; + int result[] = { 0, 0 }; + try { + if(in!=null){ + src = javax.imageio.ImageIO.read(in); + result[0] = src.getWidth(null); // 得到源图宽 + result[1] = src.getHeight(null); // 得到源图高 + } + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } + + public static void updateLastDate(String id){ + String current = DateUtil.getCurrentDate() ; + RecordSet rs = new RecordSet() ; + try{ + rs.executeQuery("select 1 from userlastlogindate where userid=?",id) ; + if(rs.next()){ + rs.executeQuery("select 1 from userlastlogindate where userid=? and lastlogindate=?",id,current) ; + if(rs.next()){ + //已存在记录,不再更新 + }else{ + rs.executeUpdate("update userlastlogindate set lastlogindate=? where userid=?",current,id) ; + } + }else{ + rs.executeUpdate("insert into userlastlogindate(userid,lastlogindate) values (?,?)",id,current) ; + } + }catch (Exception e){ + rs.writeLog("ServiceUtil.updateLastDate(id) error"); + rs.writeLog(e); + } + } + /** + * 获取分部、部门、人员、岗位主表及自定义字段 + * @param cmd 分部:subcom,部门:dept,人员:hrm,岗位:jobtitle + * @param fielddesc 索引字段,根据字段显示名搜索 + * @param userlanguage 系统语言 + * @return + */ + public List> getCusFieldsData(String cmd,String fielddesc,int userlanguage){ + Map fieldMaps = null; + List> datas = new ArrayList<>(); + String labelname = ""; + try{ + if("subcom".equals(cmd) || "dept".equals(cmd)){ + HrmFieldComInfo HrmFieldComInfo = new HrmFieldComInfo(); + int scopeid = "subcom".equals(cmd)?4:5; + HrmDeptFieldManagerE9 hfm = new HrmDeptFieldManagerE9(scopeid); + hfm.isReturnDecryptData(true); + List lsGroup = hfm.getLsGroup(); + for (int tmp = 0; lsGroup != null && tmp < lsGroup.size(); tmp++) { + String groupid = (String) lsGroup.get(tmp); + List lsField = hfm.getLsField(groupid); + for (int j = 0; lsField != null && j < lsField.size(); j++) { + fieldMaps = new HashMap<>(); + String fieldid = (String) lsField.get(j); + String fieldname = HrmFieldComInfo.getFieldname(fieldid); + if(fieldname.equalsIgnoreCase("limitUsers")||fieldname.equalsIgnoreCase("subshowid") || fieldname.equalsIgnoreCase("showid"))continue; + String fieldlabel = HrmFieldComInfo.getLabel(fieldid); + labelname = SystemEnv.getHtmlLabelNames(fieldlabel,userlanguage); + if(fielddesc.length()>0 && !labelname.contains(fielddesc)) continue; + String issystem = HrmFieldComInfo.getIssystem(fieldid).equals("1") ? "1" : "2"; + fieldMaps.put("labelname",SystemEnv.getHtmlLabelNames(fieldlabel,userlanguage)); + fieldMaps.put("fieldname",fieldname); + fieldMaps.put("issystem",issystem); + fieldMaps.put("scopeid",scopeid+""); + datas.add(fieldMaps); + } + } + labelname = SystemEnv.getHtmlLabelNames("602",userlanguage); + if(fielddesc.length()==0 || labelname.contains(fielddesc)){ + fieldMaps = new HashMap<>(); + fieldMaps.put("labelname",labelname); + fieldMaps.put("fieldname","canceled"); + fieldMaps.put("issystem","1"); + datas.add(fieldMaps); + } + }else if("hrm".equals(cmd)){ + int [] scopeIds = {-1,1,3}; + HrmFieldManager hfm = null; + for(int scopeId : scopeIds) { + hfm = new HrmFieldManager("HrmCustomFieldByInfoType", scopeId); + CustomFieldManager cfm = new CustomFieldManager("HrmCustomFieldByInfoType", scopeId); + hfm.getCustomFields(); + while (hfm.next()) { + fieldMaps = new HashMap<>(); + String fieldlabel = hfm.getLable(); + String fieldName = hfm.getFieldname(); + labelname = SystemEnv.getHtmlLabelNames(fieldlabel,userlanguage); + if(fielddesc.length()>0 && !labelname.contains(fielddesc)) continue; + boolean isBaseField = hfm.isBaseField(fieldName); + if("jobactivity".equals(fieldName)){ + fieldName = "jobactivityid"; + } + String issystem = isBaseField ? "1" : "2"; + fieldMaps.put("labelname",labelname); + fieldMaps.put("fieldname",isBaseField ? fieldName:scopeId+"_"+fieldName); + fieldMaps.put("issystem",issystem); + fieldMaps.put("scopeid",scopeId+""); + datas.add(fieldMaps); + } + if(scopeId==-1){ + labelname = SystemEnv.getHtmlLabelNames("409",userlanguage); + if(fielddesc.length()==0 || labelname.contains(fielddesc)){ + fieldMaps = new HashMap<>(); + fieldMaps.put("labelname",labelname); + fieldMaps.put("fieldname","password"); + fieldMaps.put("issystem","1"); + datas.add(fieldMaps); + } + + labelname = SystemEnv.getHtmlLabelNames("519202",userlanguage); + if(fielddesc.length()==0 || labelname.contains(fielddesc)){ + fieldMaps = new HashMap<>(); + fieldMaps.put("labelname",labelname); + fieldMaps.put("fieldname","salt"); + fieldMaps.put("issystem","1"); + datas.add(fieldMaps); + } + + labelname = SystemEnv.getHtmlLabelNames("683",userlanguage); + if(fielddesc.length()==0 || labelname.contains(fielddesc)){ + fieldMaps = new HashMap<>(); + fieldMaps.put("labelname",labelname); + fieldMaps.put("fieldname","seclevel"); + fieldMaps.put("issystem","1"); + datas.add(fieldMaps); + } + + labelname = SystemEnv.getHtmlLabelNames("15513",userlanguage); + if(fielddesc.length()==0 || labelname.contains(fielddesc)){ + fieldMaps = new HashMap<>(); + fieldMaps.put("labelname",labelname); + fieldMaps.put("fieldname","dsporder"); + fieldMaps.put("issystem","1"); + datas.add(fieldMaps); + } + boolean isOpenClassification = HrmClassifiedProtectionBiz.isOpenClassification();//判断是否开启了分级保护 + if(isOpenClassification){ + labelname = SystemEnv.getHtmlLabelNames("130506",userlanguage); + if(fielddesc.length()==0 || labelname.contains(fielddesc)){ + fieldMaps = new HashMap<>(); + fieldMaps.put("labelname",labelname); + fieldMaps.put("fieldname","classification"); + fieldMaps.put("issystem","1"); + datas.add(fieldMaps); + } + } + } + } + }else if("jobtitle".equals(cmd)){ + String[] fields = new String[]{"jobtitlemark,382413", "jobtitlename,382414", "jobtitlecode,524944", "jobactivityid,15855", "jobresponsibility,15856", "jobdoc,857", "jobcompetency,895", "jobtitleremark,454","jobgroupId,805","canceled,602"}; + for (int i = 0; i < fields.length; i++) { + String[] fieldinfo = fields[i].split(","); + fieldMaps = new HashMap<>(); + String fieldlabel = fieldinfo[1]; + String fieldName = fieldinfo[0]; + String issystem = "1"; + labelname = SystemEnv.getHtmlLabelNames(fieldlabel,userlanguage); + if(fielddesc.length()>0 && !labelname.contains(fielddesc)) continue; + fieldMaps.put("labelname",labelname); + fieldMaps.put("fieldname",fieldName); + fieldMaps.put("issystem",issystem); + fieldMaps.put("scopeid","0"); + datas.add(fieldMaps); + } + } + labelname = SystemEnv.getHtmlLabelNames("126059",userlanguage); + if(fielddesc.length()==0 || labelname.contains(fielddesc)){ + fieldMaps = new HashMap<>(); + fieldMaps.put("labelname",labelname); + fieldMaps.put("fieldname","outkey"); + fieldMaps.put("issystem","1"); + datas.add(fieldMaps); + } + }catch (Exception e){ + e.printStackTrace(); + } + return datas; + } + + public boolean calClassification(String userid,String classification){ + boolean flag = false; + try{ + RecordSet rs = new RecordSet(); + classification = ""+Util.getIntValue(classification,3); + Map crcInfo = new EncryptUtil().getLevelCRC(userid,classification); + String encKey = Util.null2String(crcInfo.get("encKey")); + String crc = Util.null2String(crcInfo.get("crc")); + flag = rs.executeUpdate("update hrmresource set classification=?,encKey=?,crc=? where id=?",classification,encKey,crc,userid); + }catch (Exception e){ + writeLog(e); + e.printStackTrace(); + } + return flag; + } +} diff --git a/src/weaver/hrm/pm/action/HrmResourceEntrantAction.java b/src/weaver/hrm/pm/action/HrmResourceEntrantAction.java new file mode 100644 index 0000000..520be18 --- /dev/null +++ b/src/weaver/hrm/pm/action/HrmResourceEntrantAction.java @@ -0,0 +1,953 @@ +package weaver.hrm.pm.action; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.*; + +import com.api.hrm.bean.HrmFieldBean; +import com.api.hrm.service.HrmResourceWorkService; +import com.engine.common.service.impl.HrmCommonServiceImpl; +import com.engine.hrm.entity.RuleCodeType; +import com.engine.hrm.util.CodeRuleManager; +import com.engine.hrm.util.face.HrmFaceCheckManager; +import com.engine.hrm.util.face.ValidateFieldManager; +import com.engine.hrm.util.face.bean.CheckItemBean; +import org.apache.commons.validator.EmailValidator; +import weaver.common.DateUtil; +import weaver.common.StringUtil; +import weaver.conn.RecordSet; +import weaver.conn.RecordSetTrans; +import weaver.docs.docs.CustomFieldManager; +import weaver.file.ImageFileManager; +import weaver.general.GCONST; +import weaver.general.PasswordUtil; +import weaver.general.Util; +import weaver.hrm.common.DbFunctionUtil; +import weaver.hrm.company.DepartmentComInfo; +import weaver.hrm.companyvirtual.DepartmentVirtualComInfo; +import weaver.hrm.definedfield.HrmFieldManager; +import weaver.hrm.finance.SalaryManager; +import weaver.hrm.passwordprotection.manager.HrmResourceManager; +import weaver.hrm.resource.CustomFieldTreeManager; +import weaver.hrm.resource.ResourceComInfo; +import weaver.hrm.settings.ChgPasswdReminder; +import weaver.hrm.settings.RemindSettings; +import weaver.hrm.tools.HrmDateCheck; +import weaver.system.SysRemindWorkflow; +import weaver.systeminfo.SysMaintenanceLog; +import weaver.systeminfo.SystemEnv; + +/** + * 人员入职 + * @author wcd + * @version 1.0 2015-07-07 + */ +public class HrmResourceEntrantAction extends PmAction { + private Map baseData = new HashMap<>(); + private Map custData = new HashMap<>(); + private Map hrmSelectItem = new HashMap<>(); + private Map cusSelectItem = new HashMap<>(); + private Map fieldMap = new HashMap<>(); + + private static List donotExportFields = Arrays.asList(new String[]{"loginid", "workyear", "companyworkyear"}); + private static List parseList = new ArrayList(Arrays.asList("jobtitle", "locationid", "status", "accounttype", "managerid", "jobcall", "joblevel", "assistantid")); + + protected int todo() { + return HRM_RESOURCE_ENTRANT; + } + + protected void parse() throws Exception { + try { + writeLog("in HrmResourceEntrantAction parse " + todo()); + RecordSet rs = new RecordSet(); + + findFields(); + loadHrmSelectItem(); + loadCusSelectItem(); + + for (String key : baseData.keySet()) { + if (parseList.contains(key)) + baseData.put(key, Util.getIntValue(rsdt.getString(key), 0)); + else if (key.equals("systemlanguage")) + baseData.put(key, Util.getIntValue(rsdt.getString(key), 7)); + else + baseData.put(key, transValue(key)); + } + + for (String key : custData.keySet()) { + custData.put(key, transValue(key)); + } + + //处理人员照片 + String resourceimageid = (String) getValue("resourceimageid"); + resourceimageid = getImageIdByDocid(resourceimageid); + //考虑到流程文档权限的问题,把附件复制一份 + resourceimageid = Util.null2String(ImageFileManager.copyImageFile(Util.getIntValue(resourceimageid))); + if (resourceimageid.equals("0")) { + writeLog("resourceimageid为0,上传图片没有成功"); + } + + //处理密码 + String password = (String) getValue("password"); + ChgPasswdReminder reminder = new ChgPasswdReminder(); + RemindSettings settings = reminder.getRemindSettings(); + //判断是否开启了【启用初始密码】 + String defaultPasswordEnable = Util.null2String(settings.getDefaultPasswordEnable()); + //【初始密码】 + String defaultPassword = Util.null2String(settings.getDefaultPassword()); + //如果入职流程的密码为空。并且开启了【启用初始密码】,且初始密码不为空,则默认取初始密码作为密码 + if (password.equals("") && defaultPasswordEnable.equals("1") && !defaultPassword.equals("")) { + password = defaultPassword; + } + + //处理电话号码 + String mobile = (String) getValue("mobile"); + String telephone = (String) getValue("telephone"); + CheckItemBean mobileBean = new CheckItemBean("mobile", mobile); + ValidateFieldManager.validate(mobileBean); + if (!mobileBean.isPass()) { + this.reqManager.setMessage(mobileBean.getCheckMsg()); + throw new Exception(mobileBean.getCheckMsg()); + } + CheckItemBean telephoneBean = new CheckItemBean("telephone", telephone); + ValidateFieldManager.validate(telephoneBean); + if (!telephoneBean.isPass()) { + this.reqManager.setMessage(telephoneBean.getCheckMsg()); + throw new Exception(telephoneBean.getCheckMsg()); + } + + //处理姓名 + String belongto = (String) getValue("belongto"); + String lastname = (String) getValue("lastname"); + writeLog("in HrmResourceEntrantAction lastname " + lastname + ":" + ((lastname.length() == 0))); + if (lastname.length() == 0) { + this.reqManager.setMessage(SystemEnv.getHtmlLabelName(125311,user.getLanguage())); + throw new Exception("姓名不能为空!"); + } + + // 基本信息 + int accounttype = Util.getIntValue(Util.null2String(getValue("accounttype")), 0); + baseData.remove("accounttype"); + if (accounttype == 0) belongto = "-1"; + String departmentvirtualids = "";// 虚拟部门id; + boolean falg = false; + + //验证用户名 + String loginid = (String) getValue("loginid"); + baseData.remove("loginid"); + if ("".equals(loginid) && accounttype == 1) { + rs.executeSql("select loginid from HrmResource where id =" + belongto); + if (rs.next()) { + loginid = rs.getString("loginid"); + } + if (!loginid.equals("")) { + String maxidsql = "select max(id) as id from HrmResource where loginid like '" + loginid + "%'"; + rs.executeSql(maxidsql); + if (rs.next()) { + loginid = loginid + (rs.getInt("id") + 1); + falg = true; + } + } + } + + String seclevel = (String) getValue("seclevel"); + if(Math.abs(Util.getIntValue(seclevel)) > 999){ + seclevel = "0"; + //this.reqManager.setMessage(SystemEnv.getHtmlLabelNames("518227", user.getLanguage())); + setReqMessage(SystemEnv.getHtmlLabelName(518227, Util.getIntValue(user.getLanguage()))); + throw new Exception("安全级别区间错误!"); + } + String managerstr = ""; + + int managerid = Util.getIntValue(Util.null2String(getValue("managerid")), 0); + String sql = "select managerstr, seclevel from HrmResource where id = " + managerid; + rs.executeSql(sql); + while (rs.next()) { + String tmp_managerstr = rs.getString("managerstr"); + /*********处理managerstr 不以逗号开始或者结束的情况 形如 managerstr:8 begin***********/ + if (!tmp_managerstr.startsWith(",")) tmp_managerstr = "," + tmp_managerstr; + if (!tmp_managerstr.endsWith(",")) tmp_managerstr = tmp_managerstr + ","; + /*********处理managerstr 不以逗号开始或者结束的情况 形如 managerstr:8 end ***********/ + managerstr += tmp_managerstr; + managerstr = "," + managerid + managerstr; + managerstr = managerstr.endsWith(",") ? managerstr : (managerstr + ","); + //seclevel = "".equals(seclevel) ? rs.getString("seclevel") : seclevel; + } + + String departmentid = (String) getValue("departmentid"); + String subcmpanyid1 = new DepartmentComInfo().getSubcompanyid1(departmentid); + + if (!"".equals(loginid)) { + rs.execute("select id from HrmResource where loginid='" + loginid + "'"); + if (rs.next()) { + loginid = ""; + //this.reqManager.setMessage(SystemEnv.getHtmlLabelNames("412,18082", user.getLanguage())); + setReqMessage(SystemEnv.getHtmlLabelName(10000165, Util.getIntValue(user.getLanguage()))); + throw new Exception("人员登录名重复!"); + } else if(accounttype != 1){ + if (ln.CkHrmnum() >= 0){ + setReqMessage(SystemEnv.getHtmlLabelName(16078, Util.getIntValue(user.getLanguage()))); + throw new Exception("有效用户数已到license上限!"); + } + int limitUsers = 0; + rs.execute("select limitUsers from HrmSubCompany where id=" + subcmpanyid1); + if (rs.next()) { + limitUsers = StringUtil.parseToInt(rs.getString("limitUsers"), 0); + } + if (limitUsers > 0) { + int subIdInt = Util.getIntValue(subcmpanyid1, 0); + int cnt = new HrmResourceManager().count(0, subIdInt); + if (cnt >= limitUsers) { + loginid = ""; + setReqMessage(SystemEnv.getHtmlLabelName(10000166, Util.getIntValue(user.getLanguage()))); + + throw new Exception("人员超过分部设置的人员限制数!"); + } + } + } + } + + //处理系统字段数据 + RecordSetTrans rst = new RecordSetTrans(); + rst.setAutoCommit(false); + String para = ""; + + String email = (String) getValue("email"); + if (!"".equals(email) && !EmailValidator.getInstance().isValid(email)) { + //this.reqManager.setMessage(SystemEnv.getHtmlLabelNames("20869,24944", user.getLanguage())); + setReqMessage(SystemEnv.getHtmlLabelName(10000167, Util.getIntValue(user.getLanguage()))); + throw new Exception("邮箱格式错误!"); + } + + + String certificatenum = Util.null2String(baseData.get("certificatenum")).trim(); + if(!"".equals(certificatenum)){ + rs.executeQuery("select id from HrmResource where certificatenum = ?", certificatenum); + if (rs.next()) { + certificatenum = ""; + setReqMessage(SystemEnv.getHtmlLabelName(83521, Util.getIntValue(user.getLanguage()))); + throw new Exception("身份证重复!"); + } + } + + //验证编号 + String workcode = (String) getValue("workcode"); + int jobtitle = Util.getIntValue(Util.null2String(getValue("jobtitle")), 0); + workcode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.USER, subcmpanyid1, departmentid, jobtitle + "", workcode); + if (!workcode.equals("")) { + rs.execute("select workcode from HrmResource where workcode ='" + workcode + "'"); + if (rs.next()) { + workcode = ""; + //this.reqManager.setMessage(SystemEnv.getHtmlLabelNames("714,18082", user.getLanguage())); + setReqMessage(SystemEnv.getHtmlLabelName(503017, Util.getIntValue(user.getLanguage()))); + throw new Exception("编号重复!"); + } + } + + rs.executeProc("HrmResourceMaxId_Get", ""); + rs.next(); + String id = String.valueOf(rs.getInt(1)); + String dsporder = String.valueOf(id); + + try { + String sex = (String) getValue("sex"); + int joblevel = Util.getIntValue(Util.null2String(getValue("joblevel")), 0); + int locationid = Util.getIntValue(Util.null2String(getValue("locationid")), 0); + int status = Util.getIntValue(Util.null2String(getValue("status")), 0); + int jobcall = Util.getIntValue(Util.null2String(getValue("jobcall")), 0); + int assistantid = Util.getIntValue(Util.null2String(getValue("assistantid")), 0); + String jobactivitydesc = (String) getValue("jobactivitydesc"); + String workroom = (String) getValue("workroom"); + String mobilecall = (String) getValue("mobilecall"); + String fax = (String) getValue("fax"); + int systemlanguage = Util.getIntValue(Util.null2String(getValue("systemlanguage")), 7); + + int mobileshowtype = 0; + mobileshowtype = StringUtil.parseToInt(settings.getMobileShowTypeDefault(), 0); + String costcenterid = ""; + para = "" + id + separator + workcode + separator + lastname + separator + sex + separator + resourceimageid + + separator + departmentid + separator + costcenterid + separator + jobtitle + separator + + joblevel + separator + jobactivitydesc + separator + managerid + separator + assistantid + separator + + status + separator + locationid + separator + workroom + separator + telephone + separator + + mobile + separator + mobilecall + separator + fax + separator + jobcall + separator + + subcmpanyid1 + separator + managerstr + separator + accounttype + separator + belongto + separator + + systemlanguage + separator + email + separator + dsporder + separator + mobileshowtype; + writeLog("in HrmResourceEntrantAction HrmResourceBasicInfo_Insert : " + para); + rst.executeProc("HrmResourceBasicInfo_Insert", para); + if (locationid > 0) + rst.executeSql("update hrmresource set countryid=(select countryid from HrmLocations where id=" + locationid + ") where id=" + id); + if (!"".equals(loginid)) { + if ("".equals(password)) { + password = "1"; + } + String[] pwds = PasswordUtil.encrypt(password); + + String logidsql = "update HrmResource set loginid = ?,password =?,salt=? where id =?"; + rst.executeUpdate(logidsql, loginid, pwds[0], pwds[1], id); + } + if (seclevel == null || "".equals(seclevel)) { + seclevel = "0"; + } + rst.executeUpdate("update hrmresource set seclevel = ?, "+ DbFunctionUtil.getInsertUpdateSetSql(rs.getDBType(),creater) +" where id=? ", seclevel, id); + //String p_para = id + separator + departmentid + separator + subcmpanyid1 + separator + managerid + separator + seclevel + separator + managerstr + separator + "0" + separator + "0" + separator + "0" + separator + "0" + separator + "0" + separator + "0"; + + //System.out.println(p_para); + //rst.executeProc("HrmResourceShare", p_para); + rst.commit(); + + String messagerurl = (String) getValue("messagerurl"); + messagerurl = getImageIdByDocid(messagerurl); + //考虑到流程文档权限的问题,把附件复制一份 + messagerurl = Util.null2String(ImageFileManager.copyImageFile(Util.getIntValue(messagerurl))); + if (!"".equals(messagerurl) && !"0".equals(messagerurl)) { + messagerurl = copyFile(messagerurl); + rs.executeUpdate("update hrmresource set messagerurl = ? where id = ?", messagerurl, id); + } + + try { + HrmFaceCheckManager.setUserPassowrd(id+"",password); + new ResourceComInfo().removeResourceCache(); + } catch (Exception e) { + writeLog(e); + } + + HrmFaceCheckManager.sync(id, HrmFaceCheckManager.getOptInsert(), this.getClass().getName(), HrmFaceCheckManager.getOaResource()); + + } catch (Exception e) { + rst.rollback(); + writeLog(e); + throw e; + } + + para = "" + id; + + int userid = creater; + Calendar todaycal = Calendar.getInstance(); + String today = Util.add0(todaycal.get(Calendar.YEAR), 4) + "-" + Util.add0(todaycal.get(Calendar.MONTH) + 1, 2) + "-" + Util.add0(todaycal.get(Calendar.DAY_OF_MONTH), 2); + String userpara = "" + userid + separator + today; + + for (int i = 0; i < 5; i++) para += separator + "" + separator + "" + separator + "" + separator + ""; + rs.executeProc("HrmResourceDefine_Update", para); + + rs.executeProc("HrmResource_CreateInfo", "" + id + separator + userpara + separator + userpara); + + // 改为只进行该人缓存信息的添加 + new ResourceComInfo().addResourceInfoCache(id); + + new SalaryManager().initResourceSalary(id); + + para = "" + id + separator + managerid + separator + departmentid + separator + subcmpanyid1 + separator + "0" + separator + managerstr; + rs.executeProc("HrmResource_Trigger_Insert", para); + + String sql_1 = ("insert into HrmInfoStatus (itemid,hrmid) values(1," + id + ")"); + rs.executeSql(sql_1); + String sql_2 = ("insert into HrmInfoStatus (itemid,hrmid) values(2," + id + ")"); + rs.executeSql(sql_2); + String sql_3 = ("insert into HrmInfoStatus (itemid,hrmid) values(3," + id + ")"); + rs.executeSql(sql_3); + String sql_10 = ("insert into HrmInfoStatus (itemid,hrmid) values(10," + id + ")"); + rs.executeSql(sql_10); + + String name = lastname; + + String SWFAccepter = ""; + String SWFTitle = ""; + String SWFRemark = ""; + String Subject = ""; + Subject = SystemEnv.getHtmlLabelName(15670, user.getLanguage()); + Subject += ":" + name; + + if ("1".equals(settings.getEntervalid())) {//入职提醒 +/* String thesql="select distinct hrmid from HrmInfoMaintenance where id<4 or id = 10"; + rs.executeSql(thesql); + String members=""; + while(rs.next()){ + int hrmid_tmp = Util.getIntValue(rs.getString("hrmid"));//TD9392 + if(hrmid_tmp > 0 && creater != hrmid_tmp){ + members += ","+rs.getString("hrmid"); + } + } +if(!members.equals("")){ + members = members.substring(1); + SWFAccepter=members;*/ + + + String thesql = "select hrmids from HrmInfoMaintenance where id<4 or id = 10"; + rs.executeSql(thesql); + String members = ""; + /*while(rs.next()){ + int hrmid_tmp = Util.getIntValue(rs.getString("hrmids"));//TD9392 + if(hrmid_tmp > 0 && user.getUID() != hrmid_tmp){ + members += ","+rs.getString("hrmids"); + } + }*/ + while (rs.next()) { + String hrmid_tmp = Util.null2String(rs.getString("hrmids"));//TD9392 + if (hrmid_tmp.length() != 0) { + members += "," + rs.getString("hrmids"); + } + } + if (!members.equals("")) { + members = members.substring(1); + members = duplicateRemoval(members, user.getUID() + ""); + SWFAccepter = members; + SWFTitle = SystemEnv.getHtmlLabelName(15670, user.getLanguage()); + SWFTitle += ":" + name; + SWFTitle += "-" + createrName; + SWFTitle += "-" + today; +// SWFRemark=""+Util.fromScreen2(Subject,user.getLanguage())+""; + SWFRemark = "" + Util.fromScreen2(Subject, user.getLanguage()) + ""; + RemindWorkflowThreadUtil.remindWorkflowPool.submit(new RemindWorkflowThread(SWFTitle, 0, creater, SWFAccepter, SWFRemark)); + } + } + //更新虚拟组织部门id + if (departmentvirtualids.length() > 0) { + //保存前先删除需要删除的数据,因为有managerid 所以不能全部删除再保存 + sql = "delete from hrmresourcevirtual where resourceid=" + id + " and departmentid not in (" + departmentvirtualids + ")"; + rs.executeSql(sql); + + String[] departmentvirtualid = departmentvirtualids.split(","); + for (int i = 0; departmentvirtualid != null && i < departmentvirtualid.length; i++) { + rs.executeSql(" select count(*) from HrmResourceVirtual where departmentid ='" + departmentvirtualid[i] + "' and resourceid = " + id); + if (rs.next()) { + //如果已存在 无需处理 + if (rs.getInt(1) > 0) continue; + } + + //写入 + int tmpid = 0; + rs.executeSql("select max(id) from HrmResourceVirtual "); + if (rs.next()) { + tmpid = rs.getInt(1) + 1; + } + String subcompanyid = new DepartmentVirtualComInfo().getSubcompanyid1(departmentvirtualid[i]); + sql = " insert into HrmResourceVirtual (id,resourceid,subcompanyid,departmentid ) " + " values (" + tmpid + "," + id + "," + subcompanyid + "," + departmentvirtualid[i] + ")"; + rs.executeSql(sql); + } + } + + if (!"".equals(lastname)) { + String quickSearchStr = new HrmCommonServiceImpl().generateQuickSearchStr(lastname); + String sqlStr = "update HrmResource set pinyinlastname = ?, ecology_pinyin_search = ? where id = ?"; + rs.executeUpdate(sqlStr, quickSearchStr, quickSearchStr, id); + } + + SysMaintenanceLog log = new SysMaintenanceLog(); + log.resetParameter(); + log.setRelatedId(Util.getIntValue(id)); + log.setRelatedName(lastname); + log.setOperateItem("29"); + log.setOperateUserid(creater); + log.setClientAddress(clientIp); + log.setOperateType("1"); + log.setOperateDesc("HrmResourceBasicInfo_Insert"); + log.setSysLogInfo(); + + + //个人信息 + String tempcertificatenum = certificatenum; + if (!certificatenum.equals("")) { + rs.executeSql("select id from HrmResource where id<>" + id + " and certificatenum='" + certificatenum + "'"); + if (rs.next()) { + rs.executeSql("select certificatenum from HrmResource where id=" + id); + if (rs.next()) { + tempcertificatenum = Util.null2String(rs.getString("certificatenum")); + } + } + } + + String birthday = (String) getValue("birthday"); + String folk = (String) getValue("folk"); + String nativeplace = (String) getValue("nativeplace"); + String regresidentplace = (String) getValue("regresidentplace"); + String maritalstatus = (String) getValue("maritalstatus"); + String policy = (String) getValue("policy"); + String bememberdate = (String) getValue("bememberdate"); + String bepartydate = (String) getValue("bepartydate"); + String islabouunion = (String) getValue("islabouunion"); + String educationlevel = (String) getValue("educationlevel"); + String degree = (String) getValue("degree"); + String healthinfo = (String) getValue("healthinfo"); + String height = (String) getValue("height"); + String weight = (String) getValue("weight"); + String residentplace = (String) getValue("residentplace"); + String homeaddress = (String) getValue("homeaddress"); + String tempresidentnumber = (String) getValue("tempresidentnumber"); + para = "" + id + separator + birthday + separator + folk + separator + nativeplace + separator + + regresidentplace + separator + maritalstatus + separator + policy + separator + bememberdate + separator + + bepartydate + separator + islabouunion + separator + educationlevel + separator + degree + separator + + healthinfo + separator + height + separator + weight + separator + residentplace + separator + + homeaddress + separator + tempresidentnumber + separator + tempcertificatenum; + + rs.executeProc("HrmResourcePersonalInfo_Insert", para); + rs.executeProc("HrmResource_ModInfo", "" + id + separator + userpara); + + log.resetParameter(); + log.setRelatedId(Util.getIntValue(id)); + log.setRelatedName(new ResourceComInfo().getResourcename(id)); + log.setOperateItem("29"); + log.setOperateUserid(creater); + log.setClientAddress(clientIp); + log.setOperateType("1"); + log.setOperateDesc("HrmResourcePersonalInfo_Insert"); + log.setSysLogInfo(); + + //工作信息 + String usekind = (String) getValue("usekind"); + String startdate = (String) getValue("startdate"); + String probationenddate = (String) getValue("probationenddate"); + String enddate = (String) getValue("enddate"); + para = "" + id + separator + usekind + separator + startdate + separator + probationenddate + separator + enddate; + rs.executeProc("HrmResourceWorkInfo_Insert", para); + rs.executeProc("HrmResource_ModInfo", "" + id + separator + userpara); + + log.resetParameter(); + log.setRelatedId(Util.getIntValue(id)); + log.setRelatedName(new ResourceComInfo().getResourcename(id)); + log.setOperateItem("29"); + log.setOperateUserid(creater); + log.setClientAddress(clientIp); + log.setOperateType("1"); + log.setOperateDesc("HrmResourceWorkInfo_Insert"); + log.setSysLogInfo(); + + baseData.remove("jobactivity"); + baseData.remove("jobGroupId"); + if (baseData.keySet().size() > 0) { + sql = "update hrmresource set "; + String sqlWhere = " where id = " + id; + String setSql = ""; + for (String key : baseData.keySet()) { + setSql += ", " + key + " = "; + Map fieldConfig = fieldMap.get(key); + String fieldDbType = (String) fieldConfig.get("FieldDbType"); + String type = Util.null2String(fieldConfig.get("Type")); + String htmltype = Util.null2String(fieldConfig.get("HtmlType")); + String value = Util.null2String(baseData.get(key)); + if (htmltype.equals("6")) { + String fileid = value; + List transId = new ArrayList<>(); + List ids = Util.splitString2List(fileid, ","); + for (String fid : ids) { + String copyId = getImageIdByDocid(fid); + //考虑到流程文档权限的问题,把附件复制一份 + copyId = Util.null2String(ImageFileManager.copyImageFile(Util.getIntValue(copyId))); + if(Util.getIntValue(copyId, 0)>0) + transId.add(copyId); + } + setSql += (transId.size() == 0 ? "null" : ("'" + String.join(",", transId)) + "'"); + } else if (fieldDbType.startsWith("text") || fieldDbType.startsWith("char") || + fieldDbType.startsWith("varchar") || type.equals("161") || type.equals("162") || type.equals("257") || type.equals("256")) { + setSql += !"".equals(value) ? "'" + value + "'" : "null"; + } else { + if (value.equals("")) { + setSql += "null"; + } else { + setSql += value; + } + } + } + if (!"".equals(setSql)) { + setSql = setSql.substring(1); + sql += setSql + sqlWhere; + rs.executeUpdate(sql); + } + } + updateWorkInfo(id); + + rs.executeUpdate("update hrmresource set " + DbFunctionUtil.getInsertUpdateSetSql(rst.getDBType(), user.getUID()) + " where id=" + id); + + //保存自定义字段数据 + insertCustData(log, id); + ResourceComInfo resourceComInfo = new ResourceComInfo(); + try{ + //登录信息签名 + PasswordUtil.saveSign(""+id); + }catch (Exception e){ + writeLog(e); + } + + try{ + + String companystartdate = ""; + String formsql = "select companystartdate from HrmResource where id = " + id; + System.out.println("requestId:"+requestId+":id:"+id+":formsql:"+formsql); + rs.executeQuery(formsql); + if(rs.next()){ + companystartdate = Util.null2s(rs.getString("companystartdate"),""); + } + System.out.println("requestId:"+requestId+":id:"+id+":companystartdate:"+companystartdate); + if(companystartdate != null && companystartdate.length() > 0){ + String changefirstdate = DateUtil.getFirstDayOfMonth(companystartdate); + String endlastdate = DateUtil.getCurrentDate(); + String formInsertSql = "insert into kq_date_change_log(resourceid,changefromdate,changetodate,status) values(?,?,?,0) "; + boolean isok = rs.executeUpdate(formInsertSql, id,changefirstdate,endlastdate); + System.out.println("requestId:"+requestId+":id:"+id+":changefirstdate:"+changefirstdate+":endlastdate:"+endlastdate+":isok:"+isok); + } + }catch (Exception e){ + writeLog(e); + } + + }catch (Exception ex){ + writeLog(ex); + throw ex; + } + } + + private Object transValue(String key){ + Object value = Util.null2String(rsdt.getString(key)); +// Map optionsMap = (key.indexOf("custField_") > -1 ? cusSelectItem : hrmSelectItem); +// try{ +// if(fieldMap.containsKey(key)) { +// Map fieldConfig = fieldMap.get(key); +// String htmlType = Util.null2String(fieldConfig.get("HtmlType")); +// Integer fieldId = Util.getIntValue(Util.null2String(fieldConfig.get("id"))); +// if (!"".equals(value.toString()) && htmlType.equals("5") && hrmSelectItem.containsKey(fieldId)) { +// List options = optionsMap.get(fieldId); +// value = options.get(Integer.parseInt(value.toString())).get("selectValue"); +// } +// } +// }catch (Exception ex){ +// writeLog(key, ex); +// } + return value; + } + + private Object getValue(String key) throws Exception{ + if(baseData.containsKey(key)){ + Object value = baseData.get(key); + baseData.remove(key); + + return value; + }else + return ""; + } + + private Object getCustValue(String key) throws Exception{ + if(custData.containsKey(key)){ + Object value = custData.get(key); + custData.remove(key); + + return value; + }else + return ""; + } + + private void updateWorkInfo(String id){ + SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD"); + DecimalFormat df = new DecimalFormat("0.00"); + String companyworkyear = ""; + String workyear = ""; + + try { + String companystartdate = (String)getValue("companystartdate"); + String workstartdate = (String)getValue("workstartdate"); + + Date today = Calendar.getInstance().getTime(); + Date companyStartDate = null; + Date workStartDate = null; + + Long to = 0L; + Long from = 0L; + + if (!"".equals(companystartdate)) { + companyStartDate = sdf.parse(companystartdate); + + to = today.getTime(); + from = companyStartDate.getTime(); + + if(to > from){ + companyworkyear = df.format((float)(to - from) / (24*3600*1000*365.0)); + } + + } + if(!"".equals(workstartdate)){ + workStartDate = sdf.parse(workstartdate); + to = today.getTime(); + from = workStartDate.getTime(); + + if(to > from){ + workyear = df.format((float)(to - from) / (24*3600*1000*365.0)); + } + } + + List lsParams = new ArrayList<>(); + lsParams.add(companyworkyear.equals("") ? null : companyworkyear); + lsParams.add(workyear.equals("") ? null : workyear); + lsParams.add(id); + String sql = " update hrmresource set companyworkyear=?,workyear=? where id=?"; + new RecordSet().executeUpdate(sql, lsParams); + HrmDateCheck hrmDateCheck = new HrmDateCheck(); + hrmDateCheck.calWorkInfo(id); + }catch (Exception ex){ + ex.printStackTrace(); + } + } + + private void insertCustData(SysMaintenanceLog log, String id) throws Exception{ + editCustomDataE9Add(Util.getIntValue(id)); + + log.resetParameter(); + log.setRelatedId(Util.getIntValue(id)); + log.setRelatedName(new ResourceComInfo().getResourcename(id)); + log.setOperateItem("29"); + log.setOperateUserid(creater); + log.setClientAddress(clientIp); + log.setOperateType("1"); + log.setOperateDesc("HrmResourceCustomerInfo_Insert"); + log.setSysLogInfo(); + } + + /** + * 编辑自定义数据 + * @param dataId + */ + private void editCustomDataE9Add(int dataId) throws Exception { + String scope = "HrmCustomFieldByInfoType"; + List scopeList = new ArrayList(Arrays.asList(-1, 1, 3)); + /*RecordSet rs = new RecordSet(); + List scopeIds = new ArrayList<>(); + for(Integer parentId : scopeList){ + rs.executeQuery("select id from CUS_TREEFORM where scope = 'HrmCustomFieldByInfoType' and PARENTID = ? or id = ?", parentId, parentId); + while (rs.next()){ + scopeIds.add(rs.getInt("id")); + } + }*/ + + for(Integer scopeId : scopeList){ + addCustomDataE9Add(scope, scopeId, dataId); + } + } + + /** + * 添加自定义数据 + * @param dataId + */ + private void addCustomDataE9Add(String scope, int scopeId, int dataId) throws Exception { + RecordSet rs = new RecordSet(); + CustomFieldManager cfm = new CustomFieldManager(scope, scopeId); + cfm.getCustomFields(); + String sql = "insert into cus_fielddata"; + String nameStr = ""; + String valueStr = ""; + String prefix = "custField_" + (scopeId < 0 ? "_" : "") + Math.abs(scopeId) + "_"; + while (cfm.next()) { + nameStr += ",field" + cfm.getId(); + String value = Util.null2String(getCustValue(prefix + cfm.getFieldDBName())); + if(cfm.getHtmlType().equals("6")) { + String fileid = Util.null2String(value); + List transId = new ArrayList<>(); + List ids = Util.splitString2List(fileid, ","); + for(String fid : ids){ + String copyId = getImageIdByDocid(fid); + //考虑到流程文档权限的问题,把附件复制一份 + copyId = Util.null2String(ImageFileManager.copyImageFile(Util.getIntValue(copyId))); + if(Util.getIntValue(copyId, 0)>0) + transId.add(copyId); + } + valueStr += "," + (transId.size() == 0 ? "null" : "'" + String.join(",", transId) + "'"); + } else if (cfm.getFieldDbType().startsWith("text") || cfm.getFieldDbType().startsWith("char") || + cfm.getFieldDbType().startsWith("varchar")||cfm.getType()==161||cfm.getType()==162 || cfm.getType()==257 || cfm.getType()==256) { + valueStr += "," + (!"".equals(value) ? "'" + value + "'" : "null"); + } else { + if (value.equals("")) { + valueStr += ",null"; + } else { + valueStr += "," + value; + } + } + } + if (!nameStr.equals("")) { + nameStr = nameStr.substring(1); + valueStr = valueStr.substring(1); + + sql += "(scope,scopeid,id," + nameStr + ") values('" + scope + "'," + scopeId + "," + dataId + "," + valueStr + ")"; + + RecordSet rsSel = new RecordSet(); + rsSel.executeQuery("select id from cus_fielddata where scope=? and scopeid=? and id=?", scope, scopeId, dataId); +// rsSel.executeSql("select id from cus_fielddata where scope='" + scope + "' and scopeid=" + scopeId + " and id=" + dataId); + if (rsSel.next()) {//查询是否已存在数据 + + }else{ + rs.executeSql(sql); + } + } + } + + private void findFields() throws Exception{ + baseData.clear(); + custData.clear(); + fieldMap.clear(); + + baseData.put("loginid", ""); + baseData.put("password", ""); + baseData.put("seclevel", ""); + + List scopeList = new ArrayList(Arrays.asList(-1, 1, 3)); + RecordSet rs = new RecordSet(); + for(Integer parentId : scopeList){ + rs.executeQuery("select id from CUS_TREEFORM where scope = 'HrmCustomFieldByInfoType' and PARENTID = ? or id = ?", parentId, parentId); + while(rs.next()){ + int scopeId = rs.getInt("id"); + HrmFieldManager hfm = new HrmFieldManager("HrmCustomFieldByInfoType", scopeId); + hfm.getCustomFields(); + while (hfm.next()) { + try { + String fieldName = hfm.getFieldname(); + if (!hfm.isUse() || donotExportFields.contains(fieldName)) + continue; + if(hfm.isBaseField(fieldName)){ + baseData.put(fieldName, ""); + }else{ + fieldName = "custField_" + (scopeId < 0 ? "_" : "") + Math.abs(scopeId) + "_" + fieldName; + custData.put(fieldName, ""); + } + fieldMap.put(fieldName, new HashMap()); + fieldMap.get(fieldName).put("id", hfm.getFieldid()); + fieldMap.get(fieldName).put("FieldDbType", hfm.getFieldDbType()); + fieldMap.get(fieldName).put("Type", hfm.getType()); + fieldMap.get(fieldName).put("HtmlType", hfm.getHtmlType()); + } catch (Exception ex) { + writeLog(ex); + throw ex; + } + } + } + } + } + + + /** + * + * @param resourceimageid + * @return imageid + */ + private String getImageIdByDocid(String resourceimageid) { + String imageid = "0"; + if(Util.getIntValue(Util.null2String(resourceimageid), 0)>0){ + RecordSet rs1 = new RecordSet(); + String imageSql = "select imagefileid from DocImageFile where docid=?"; + rs1.executeQuery(imageSql, resourceimageid); + rs1.next(); + imageid = StringUtil.vString(rs1.getString("imagefileid"),"0"); + } + return imageid; + } + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public String duplicateRemoval(String str,String userid) { + String[] ss = str.split(","); + List list = new ArrayList(); + for (String s : ss) { + list.add(s.trim()); + } + HashSet hs = new HashSet(list); + list.clear(); + list.addAll(hs); + if(list.contains(userid))list.remove(userid); + str=list.toString().replace("[", "").replace("]", "").replace(" ", ""); + return str ; + } + + private String copyFile(String messagerurl){ + try { + writeLog("messagerurl:" + messagerurl); + String filePath = "messager/usericon/" + UUID.randomUUID().toString().replace("-", "").toLowerCase() + ".jpg"; + ImageFileManager imageFileManager = new ImageFileManager(); + imageFileManager.getImageFileInfoById(Util.getIntValue(messagerurl)); + InputStream inputStream = imageFileManager.getInputStream(); + String filesize = imageFileManager.getFilesize(); + + FileOutputStream out = new FileOutputStream(new File(GCONST.getRootPath() + filePath)); + + byte[] buffer = new byte[Util.getIntValue(filesize)]; + int len; + + while ((len = inputStream.read(buffer)) > 0) { + out.write(buffer, 0, len); + } + + out.close(); + inputStream.close(); + + return "/" + filePath; + }catch (Exception ex){ + writeLog(ex); + return ""; + } + } + + private void loadHrmSelectItem(){ + try{ + hrmSelectItem.clear(); + RecordSet rs = new RecordSet(); + rs.executeQuery("select fieldid, selectvalue, listorder from hrm_selectitem"); + while(rs.next()){ + int fieldId = rs.getInt("fieldid"); + String selectValue = rs.getString("selectvalue"); + String fieldOrder = Util.null2String(rs.getString("listorder")); + if("".equals(fieldOrder)) + fieldOrder = selectValue; + Map data = new HashMap<>(); + data.put("fieldId", fieldId); + data.put("selectValue", selectValue); + data.put("fieldOrder", fieldOrder); + if(!hrmSelectItem.containsKey(fieldId)) + hrmSelectItem.put(fieldId, new ArrayList()); + hrmSelectItem.get(fieldId).add(data); + } + for(Integer key : hrmSelectItem.keySet()){ + hrmSelectItem.put(key, sortData(hrmSelectItem.get(key))); + } + }catch (Exception ex){ + writeLog(ex); + } + } + + private void loadCusSelectItem(){ + try{ + cusSelectItem.clear(); + RecordSet rs = new RecordSet(); + rs.executeQuery("select fieldid, selectvalue, fieldorder from cus_selectitem"); + while(rs.next()){ + int fieldId = rs.getInt("fieldid"); + String selectValue = rs.getString("selectvalue"); + String fieldOrder = Util.null2String(rs.getString("fieldorder")); + if("".equals(fieldOrder)) + fieldOrder = selectValue; + Map data = new HashMap<>(); + data.put("fieldId", fieldId); + data.put("selectValue", selectValue); + data.put("fieldOrder", fieldOrder); + if(!cusSelectItem.containsKey(fieldId)) + cusSelectItem.put(fieldId, new ArrayList()); + cusSelectItem.get(fieldId).add(data); + } + for(Integer key : cusSelectItem.keySet()){ + cusSelectItem.put(key, sortData(cusSelectItem.get(key))); + } + }catch (Exception ex){ + writeLog(ex); + } + } + + private List sortData(List list){ + Collections.sort(list, new Comparator() { + @Override + public int compare(Map o1, Map o2) { + int a = Integer.parseInt(o1.get("fieldOrder").toString()); + int b = Integer.parseInt(o2.get("fieldOrder").toString()); + return a - b; + } + }); + return list; + } + + private void setReqMessage(String context){ + this.reqManager.setMessagecontent(context); + } +} diff --git a/src/weaver/join/hrm/in/processImpl/HrmImportProcess.java b/src/weaver/join/hrm/in/processImpl/HrmImportProcess.java new file mode 100644 index 0000000..a3f11b0 --- /dev/null +++ b/src/weaver/join/hrm/in/processImpl/HrmImportProcess.java @@ -0,0 +1,2879 @@ +/** + * Title: 人员数据解析适配器 + * Company: 泛微软件 + * + * @author: 冯拥兵 + * @version: 1.0 + * create date : 2010-6-2 + * modify log: + * Description: 对人员数据Map集合进行解析,并添加到数据库 + */ + +package weaver.join.hrm.in.processImpl; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.reflect.Field; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.*; + +import com.engine.common.entity.EncryptFieldEntity; +import com.engine.common.service.HrmCommonService; +import com.engine.common.service.ThemeService; +import com.engine.common.service.impl.HrmCommonServiceImpl; +import com.engine.common.service.impl.ThemeServiceImpl; +import com.engine.encrypt.biz.EncryptFieldConfigComInfo; +import com.engine.hrm.util.HrmTriggerUtil; +import com.engine.hrm.util.HrmWeakPasswordUtil; +import com.engine.hrm.util.face.HrmFaceCheckManager; +import com.engine.hrm.util.face.hrmrestful.service.HrmRestFulFromWebServiceManager; +import com.weaver.integration.ldap.sync.oa.OaSync; +import com.weaver.integration.ldap.util.AuthenticUtil; +import weaver.encrypt.EncryptUtil; +import weaver.hrm.common.HrmJobTitleConver; +import weaver.hrm.common.HrmDepartmentConver; +import weaver.hrm.common.HrmSubCompanyConver; +import weaver.hrm.common.database.dialect.DbDialectFactory; +import weaver.hrm.common.database.dialect.IDbDialectSql; +import weaver.hrm.tools.HrmDateCheck; +import weaver.hrm.webservice.exception.HrmWebServiceException; + +import org.apache.commons.lang3.StringUtils; + +import weaver.general.PasswordUtil; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import weaver.hrm.common.DbFunctionUtil; + +import javax.servlet.http.HttpSession; + +import ln.LN; + +import org.json.JSONObject; + +import weaver.common.StringUtil; +import weaver.conn.RecordSet; +import weaver.conn.RecordSetTrans; +import weaver.general.BaseBean; +import weaver.general.GCONST; +import weaver.general.StaticObj; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.User; +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.interfaces.hrm.HrmServiceManager; +import weaver.join.hrm.in.HrmResource; +import weaver.join.hrm.in.HrmResourceVo; +import weaver.join.hrm.in.IHrmImportProcess; +import weaver.join.hrm.in.ImportLog; +import weaver.matrix.MatrixUtil; +import weaver.rtx.OrganisationCom; +import weaver.systeminfo.SystemEnv; +import weaver.systeminfo.setting.HrmUserSettingManager; + +public class HrmImportProcess extends BaseBean implements IHrmImportProcess { + + private static final String MAIN_ACCOUNT = "主账号" ; + private static final String SUB_ACCOUNT = "次账号" ; + + //private RecordSet recordSet=new RecordSet(); + + private Map keyMap = new HashMap(); //看数据库是否有重复,将数据库现有的数据查出 + + private Map certificateNums = new HashMap();//已存在的身份证 + + private Map isADAccountMap = 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 = ""; + + 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; + //是否启用初始密码:false-不启用初始密码、true-启用初始密码 + private boolean defaultPasswordEnable = false; + //初始密码 + private String defaultPassword = ""; + //弱密码禁止保存:false-允许保存弱密码、true-不允许保存弱密码 + private boolean weakPasswordDisable = false; + //判断弱密码 + private HrmWeakPasswordUtil hrmWeakPasswordUtil; + + public HrmImportProcess() { + 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"); + 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)); + } + } + + /** + * 对人员数据进行解析,并添加到数据库 + * + * @param keyField 重复性验证字段 + * @param hrMap 人员数据Map集合 + * @param importType 导入类型 添加|更新 add|update + * @return List + */ + public List processMap(String keyField, Map hrMap, String importType) {//增加同步锁,防止同时多次调用 + return processMap(keyField, hrMap, importType, null); + } + + /** + * 计算工龄/司龄 + * @param d + * @return + */ + private String calculateDate(String d){ + String result = "0"; + try{ + SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd"); + Date date =sdf.parse(d); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + + Calendar current = Calendar.getInstance(); + calendar.setTime(new Date()); + + int fromYear = calendar.get(Calendar.YEAR); + int fromMonth = calendar.get(Calendar.MONTH); + + int toYear = current.get(Calendar.YEAR); + int toMonth = current.get(Calendar.MONTH); + + int year = toYear - fromYear; + int month = toYear * 12 + toMonth - (fromYear * 12 + fromMonth); + + DecimalFormat df = new DecimalFormat("######0.00"); + result = df.format(year + month / 12); + }catch (Exception e){ + + } + return result; + } + + /** + * 对人员数据进行解析,并添加到数据库 + * + * @param keyField 重复性验证字段 + * @param hrMap 人员数据Map集合 + * @param importType 导入类型 添加|更新 add|update + * @return List + */ + public List processMap(String keyField, Map hrMap, String importType, HttpSession session) {//增加同步锁,防止同时多次调用 + List resultList = new ArrayList(); //导入结果 + RecordSet recordSet = new RecordSet(); + RecordSet classificationRs = new RecordSet(); + + 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; + if (session != null) session.setAttribute("importStatus", "importing"); + 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,isAdAccount," + + "classification"; + + String fields[] = field.split(","); + + User user = null; + if (session != null) user = (User) session.getAttribute("weaver_user@bean"); + + 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 = Util.null2String(obj).trim(); + hrm = new HrmResource(); + + try { // 异常处理 + + if (importType.equals("add")) { + if(key.length()==0){ + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(10003645, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + + if (keyMap.get(key) != null) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83520, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + + if(this.checkInfo(vo,resultList,"创建")){ + continue; + } + + if (StringUtil.isNotNull(vo.getCertificatenum()) && MAIN_ACCOUNT.equals(vo.getAccounttype()) && certificateNums.get(StringUtil.vString(vo.getCertificatenum())) != null) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83521, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + + //添加人员信息 license 人员上限判断 + + if (keyMap.get(key) == null && StringUtils.isNotBlank(vo.getLoginid()) + && ("主账号".equals(vo.getAccounttype()) ||StringUtils.isBlank(vo.getAccounttype())) + && "正式,试用,临时,试用延期".indexOf(Util.null2String(vo.getStatus()))>-1 ) { + if (license.CkHrmnum() >= 0) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83522, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + } + // 分部Id + String subCompanyNames = vo.getSubcompanyid1(); + String tempSubCompanyName = ""; + int isCanceled = 0; + if (subCompanyNames != null) { + if (!subCompanyNames.equals(subCompanyName)) { + tempSubCompanyName = subCompanyName; + subCompanyName = subCompanyNames; + try { + subcompanyid1 = getSubCompanyId(subCompanyName); + }catch (HrmWebServiceException e){ + resultList.add(createLog(vo, "创建", "失败", e.getMsg())); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + } + if (subcompanyid1 == -9) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getErrorMsgName(56, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + if (subcompanyid1 == -2) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(126274, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + if (subcompanyid1 == -1) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83524, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + + hrm.setSubcompanyid1(new Integer(subcompanyid1)); + } else { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83526, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + + // 部门id + String departmentNames = vo.getDepartmentid(); + if (departmentNames != null) { + if (!subCompanyNames.equals(tempSubCompanyName) || !departmentNames.equals(departmentName)) { + departmentName = departmentNames; + try { + departmentid = getDeptId(departmentName, subcompanyid1); + }catch (HrmWebServiceException e){ + resultList.add(createLog(vo, "创建", "失败",e.getMsg())); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + } + if (departmentid == -2) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(126275, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + hrm.setDepartmentid(new Integer(departmentid)); + } else { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83527, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + + if (vo.getLastname() == null) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83529, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + + // 岗位id + String jobtitleid = null ; + + try { + jobtitleid = HrmJobTitleConver.getJobtitleIdFromJsonValue(vo.getJobtitle()); + }catch (HrmWebServiceException e){ + resultList.add(createLog(vo, "创建", "失败", e.getMsg())); + if(session!=null)session.setAttribute("resultList", resultList); + continue; + } + + if(StringUtils.isNotBlank(jobtitleid)){ + hrm.setJobtitle(Integer.parseInt(jobtitleid)); + }else 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))); + if (session != null) session.setAttribute("resultList", resultList); + 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))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + } else { + + hrm.setManagerid(new Integer(0)); + hrm.setManagerstr(""); + } + + //主账号id-sunjsh + if(StringUtils.isBlank(vo.getAccounttype())){ + hrm.setAccounttype(0); + hrm.setBelongto(-1); + }else{ + if(SUB_ACCOUNT.equals(vo.getAccounttype())) { + if (StringUtils.isNotBlank(vo.getBelongto())) { + int belongto = getAssistantid(vo.getBelongto(), keyField); + if (belongto <= 0) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + + hrm.setAccounttype(1); + hrm.setBelongto(belongto); + } + }else if(MAIN_ACCOUNT.equals(vo.getAccounttype())){ + hrm.setAccounttype(0); + hrm.setBelongto(-1); + }else{ + resultList.add(createLog(vo, "创建", "失败", "主次账号类型错误:只能是【主账号】|【次账号】")); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + } + + // 助理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))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + } + + + // 办公地点 + if (vo.getLocationid() != null) { + int locationid = getLocationid(vo.getLocationid()); + hrm.setLocationid(new Integer(locationid)); + } else { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83533, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + 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))); + if (session != null) session.setAttribute("resultList", resultList); + 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) { + 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(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); + } + + // 性别,为空或其他情况统一为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(83534, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + if (systemlanguage == 0) { //系统不支持多语言 + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(84810, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + 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 (vo.getEducationlevel() != null) { + int educationlevel = getEducationlevel(vo + .getEducationlevel()); + hrm.setEducationlevel(new Integer(educationlevel)); + } + + // 工会会员,默认为是 + String islabouunion = "是".equals(vo.getIslabouunion()) ? "1" : "0"; + hrm.setIslabouunion(islabouunion); + + // 是否是ad账户 + String isAdAccount = "是".equals(vo.getIsAdAccount()) || "1".equals(vo.getIsAdAccount()) ? "1" : "0"; + hrm.setIsAdAccount(isAdAccount); + + // 健康状况 + 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); + } + if (!"".equals(Util.null2String(vo.getClassification()))){ + int classification = Integer.valueOf(vo.getClassification()); + hrm.setClassification(classification); + } + //如果新增导入的时候,登陆名不为空,需要校验一下当前的license + + //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[] pwdArr = PasswordUtil.encrypt(password_tmp); + String password = pwdArr[0]; + String salt = pwdArr[1]; + hrm.setPassword(password); + + boolean flag = true; + + /*添加人员信息*/ + String insertStr = "insert into hrmResource("; + String insertFields = ""; + String insertValues = ""; + + 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] + ","; + insertValues = insertValues + "" + hrmField.get(hrm) + ","; + } + } else if (voField.get(vo) != null) { + if (voFieldType.endsWith("String")) { + insertFields = insertFields + fields[k] + ","; + insertValues = insertValues + "'" + voField.get(vo) + "',"; + } else if (hrmFieldType.endsWith("Integer") || hrmFieldType.endsWith("Short") || hrmFieldType.endsWith("Float")) { + insertFields = insertFields + fields[k] + ","; + 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(HrmRestFulFromWebServiceManager.isResourceRestful()){ + HrmRestFulFromWebServiceManager.saveResourceCustData(key,id+""); + }else { + 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; + } + + // 人员密级 + if (!"".equals(Util.null2String(vo.getClassification()))){ + String classification = vo.getClassification(); + Map crcInfo = new EncryptUtil().getLevelCRC(id+"",classification); + String classificationSql = "update HrmResource set encKey=?, crc = ? where id=?"; + String encKey = Util.null2String(crcInfo.get("encKey")); + String crc = Util.null2String(crcInfo.get("crc")); + classificationRs.executeUpdate(classificationSql,encKey,crc, id); + } + + + } + + /*添加人员缓存,人员默认按id显示顺序,HrmResource_Trigger_Insert 人员共享 入职维护项目状态*/ + if (flag) { + try{ + //登录信息签名 + PasswordUtil.saveSign(""+id); + }catch (Exception e){ + writeLog(e); + } + HrmFaceCheckManager.setUserPassowrd(id+"",password_tmp); + String loginIdTemp = Util.null2String(vo.getLoginid()).trim(); + if(loginIdTemp.length()>0){ + Map checkInfo1 = checkInfos.get("loginid"); + if(checkInfo1==null){ + checkInfo1 = new HashMap<>(); + checkInfos.put("loginid",checkInfo1); + } + if(checkInfo1.get(loginIdTemp)==null){ + checkInfo1.put(loginIdTemp, ""+id); + checkInfos.put("loginid",checkInfo1); + } + } + String workcodeTemp = Util.null2String(vo.getWorkcode()).trim(); + if(workcodeTemp.length()>0){ + Map checkInfo2 = checkInfos.get("workcode"); + if(checkInfo2==null){ + checkInfo2 = new HashMap<>(); + checkInfos.put("workcode",checkInfo2); + } + if(checkInfo2.get(workcodeTemp)==null){ + checkInfo2.put(workcodeTemp, ""+id); + checkInfos.put("workcode",checkInfo2); + } + } + String certificatenumTemp = Util.null2String(vo.getCertificatenum()).trim(); + if(certificatenumTemp.length()>0 && certificateNums.get(certificatenumTemp)==null){ + certificateNums.put(certificatenumTemp, id); + } + + HrmUserSettingManager.checkUserSettingInit(id); + + //人员显示顺序 + 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); + + HrmFaceCheckManager.sync(id+"",HrmFaceCheckManager.getOptInsert(),"hrm_e9_import_resource",HrmFaceCheckManager.getOaResource()); + + new HrmDateCheck().calWorkInfo(""+id); + } + + /*写日志*/ + if (flag) { + resultList.add(createLog(vo, "创建", "成功", "")); + if (session != null) session.setAttribute("resultList", resultList); + if (!"".equals(vo.getLoginid())) { + rtxService.addUser(id);//添加到rtx + } + } else { + resultList.add(createLog(vo, "创建", "失败", "")); + if (session != null) session.setAttribute("resultList", resultList); + } + + } else { //更新人员 + if(key.length()==0){ + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(10003645, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + + if (keyMap.get(key) == null) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83535, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + + vo.setId(Util.getIntValue(keyMap.get(key)));//设置id + if(this.checkInfo(vo,resultList,"更新")){ + continue; + } + + if (StringUtil.isNotNull(vo.getCertificatenum()) && MAIN_ACCOUNT.equals(vo.getAccounttype()) && 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))); + if (session != null) session.setAttribute("resultList", resultList); + 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; + try { + subcompanyid1 = getSubCompanyId(subCompanyName); + }catch (HrmWebServiceException e){ + resultList.add(createLog(vo, "更新", "失败",e.getMsg())); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + issameSub = false; + + } + + if (subcompanyid1 == -9) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getErrorMsgName(56, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + if (subcompanyid1 == -2) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(126274, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + if (subcompanyid1 == 0 || subcompanyid1 == -1) { + resultList.add(createLog(vo, "更新", "失败", subcompanyid1 == 0 ? SystemEnv.getHtmlLabelName(83536, userlanguage) : SystemEnv.getHtmlLabelName(83524, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + + //qc139575 在验证并发非并发之前需要先CkHrmnum + + 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))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + + if (intSubcompanyid1 == -2) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(126274, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + + if (intSubcompanyid1 == 0 || intSubcompanyid1 == -1) { + resultList.add(createLog(vo, "更新", "失败", intSubcompanyid1 == 0 ? SystemEnv.getHtmlLabelName(83536, userlanguage) : SystemEnv.getHtmlLabelName(83524, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + 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; + try { + departmentid = getDeptId(departmentName, subcompanyid1); + }catch (HrmWebServiceException e){ + resultList.add(createLog(vo, "更新", "失败", e.getMsg())); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + + if (departmentid == 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83537, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + if (departmentid == -2) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(126275, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + } else { //add sjh 50102需要考虑不同公司名称相同部门架构情况 此时部门ID是不同的 + try { + departmentid = getDeptId(departmentName, subcompanyid1); + }catch (HrmWebServiceException e){ + resultList.add(createLog(vo, "更新", "失败", e.getMsg())); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + if (departmentid == 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83537, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + if (departmentid == -2) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(126275, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + 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 + if ("".equals(Util.null2String(vo.getJobtitle())) && (!"".equals(Util.null2String(vo.getJobactivityid())) || !"".equals(Util.null2String(vo.getJobgroupid())))) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83544, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + if(!"".equals(Util.null2String(vo.getJobtitle()))){ + // 岗位id + String jobtitleidOfStr = null ; + + try { + jobtitleidOfStr = HrmJobTitleConver.getJobtitleIdFromJsonValue(vo.getJobtitle()); + }catch (HrmWebServiceException e){ + resultList.add(createLog(vo, "更新", "失败", e.getMsg())); + if(session!=null)session.setAttribute("resultList", resultList); + continue; + } + if(StringUtils.isNotBlank(jobtitleidOfStr)){ + hrm.setJobtitle(Integer.parseInt(jobtitleidOfStr)); + }else { + + 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)); + } + } + + //上级id + String managerstr = ""; //所有上级 + String oldmanagerstr = resourcecominfo.getManagersIDs(hrmId);//原来的所有上级序列 + 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))); + if (session != null) session.setAttribute("resultList", resultList); + 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-sunjsh + if(StringUtils.isNotBlank(vo.getAccounttype())){ + if(SUB_ACCOUNT.equals(vo.getAccounttype())) { + hrm.setAccounttype(1); + if (StringUtils.isNotBlank(vo.getBelongto())) { + int belongto = getAssistantid(vo.getBelongto(), keyField); + if (belongto <= 0) { + resultList.add(createLog(vo, "更新", "失败", "主账号未找到!")); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + hrm.setBelongto(belongto); + } + }else if(MAIN_ACCOUNT.equals(vo.getAccounttype())){ + hrm.setBelongto(-1); + hrm.setAccounttype(0); + }else{ + resultList.add(createLog(vo, "更新", "失败", "主次账号类型错误:只能是【主账号】|【次账号】")); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + }else{ + if("1".equals(resourcecominfo.getAccountType(hrmId))){ + if(StringUtils.isNotBlank(vo.getBelongto())){ + hrm.setBelongto(getAssistantid(vo.getBelongto(),keyField)); + } + }else{ + if(StringUtils.isNotBlank(vo.getBelongto())){ + hrm.setBelongto(-1); + } + } + } + + // 助理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))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + hrm.setAssistantid(new Integer(assistantid)); + }else{ + hrm.setAssistantid(new Integer(0)); + } + // 办公地点 + 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))); + if (session != null) session.setAttribute("resultList", resultList); + 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) { + 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(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())); + } + + // 职称 + 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(83534, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + //系统不支持多语言 + if (systemlanguage == 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(84810, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + continue; + } + hrm.setSystemlanguage(new Integer(systemlanguage)); + } else { + hrm.setSystemlanguage(new Integer(7)); + } + + // 性别,为空或其他情况统一为0(男) + if (vo.getSex() == null) { + + } else if (!"".equals(Util.null2String(vo.getSex()))) { + String sex = vo.getSex().equals("女") ? "1" : "0"; + hrm.setSex(sex); + } else { + hrm.setSex("0"); + } + + // 婚姻状况,如果不是以下选项,则默认为未婚 + 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)); + } + + // 学历 + 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); + } + + // 是否是ad账户 + if (!"".equals(Util.null2String(vo.getIsAdAccount()))) { + String isAdAccount = "是".equals(vo.getIsAdAccount()) || "1".equals(vo.getIsAdAccount()) ? "1" : "0"; + hrm.setIsAdAccount(isAdAccount); + } + + // 健康状况 + 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); + } + if (!"".equals(Util.null2String(vo.getClassification()))){ + int classification = Integer.valueOf(vo.getClassification()); + hrm.setClassification(classification); + } + + + //更新导入的时候,如果登录名不为空,需要校验一下当前的license + if (needCheckLicenseForUpdate(resourcecominfo,hrmId,vo)) { + license.reloadLicenseInfo(); + if (license.CkHrmnum() >= 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83522, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + 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字段 + 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(); + + hrmField.setAccessible(true); + voField.setAccessible(true); + + if (hrmField.get(hrm) != null) { + if (hrmFieldType.endsWith("String")) + updateStr = updateStr + fields[k] + "='" + hrmField.get(hrm) + "',"; + else if (hrmFieldType.endsWith("Integer") || hrmFieldType.endsWith("Short") || hrmFieldType.endsWith("Float")) + updateStr = updateStr + fields[k] + "=" + hrmField.get(hrm) + ","; + if (fields[k].equals("status")) tmpstatus = Util.null2String(hrmField.get(hrm)); + } else if (voField.get(vo) != null) { + if (voFieldType.endsWith("String")) + updateStr = updateStr + fields[k] + "='" + voField.get(vo) + "',"; + else if (voFieldType.endsWith("Integer") || voFieldType.endsWith("Short") || voFieldType.endsWith("Float")) + 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(hrm.getIsAdAccount()) || (vo.getIsAdAccount()==null && "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 from 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(HrmRestFulFromWebServiceManager.isResourceRestful()){ + HrmRestFulFromWebServiceManager.saveResourceCustData(key,hrmId); + }else { + 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) { + String loginIdTemp = Util.null2String(vo.getLoginid()).trim(); + if(loginIdTemp.length()>0){ + Map checkInfo1 = checkInfos.get("loginid"); + if(checkInfo1==null){ + checkInfo1 = new HashMap<>(); + checkInfos.put("loginid",checkInfo1); + } + if(checkInfo1.get(loginIdTemp)==null){ + checkInfo1.put(loginIdTemp, hrmId); + checkInfos.put("loginid",checkInfo1); + } + } + String workcodeTemp = Util.null2String(vo.getWorkcode()).trim(); + if(workcodeTemp.length()>0){ + Map checkInfo2 = checkInfos.get("workcode"); + if(checkInfo2==null){ + checkInfo2 = new HashMap<>(); + checkInfos.put("workcode",checkInfo2); + } + if(checkInfo2.get(workcodeTemp)==null){ + checkInfo2.put(workcodeTemp, hrmId); + checkInfos.put("workcode",checkInfo2); + } + } + String certificatenumTemp = Util.null2String(vo.getCertificatenum()).trim(); + if(certificatenumTemp.length()>0 && certificateNums.get(certificatenumTemp)==null){ + certificateNums.put(certificatenumTemp, Util.getIntValue(hrmId, 0)); + } + + 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, id); + } + + if (!"".equals(Util.null2String(vo.getClassification()))){ + String classification = vo.getClassification(); + String classificationSql = "update HrmResource set encKey=?, crc = ? where id=?"; + Map crcInfo = new EncryptUtil().getLevelCRC(keyMap.get(key) +"",classification +""); + String encKey = Util.null2String(crcInfo.get("encKey")); + String crc = Util.null2String(crcInfo.get("crc")); + classificationRs.executeUpdate(classificationSql,encKey,crc, keyMap.get(key)); + } + } + + //更新下级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) { + HrmFaceCheckManager.sync(keyMap.get(key)+"",HrmFaceCheckManager.getOptUpdate(),"hrm_e9_import_resource",HrmFaceCheckManager.getOaResource()); + try{ + //登录信息签名 + PasswordUtil.saveSign(""+hrmId); + }catch (Exception e){ + writeLog(e); + } + resultList.add(createLog(vo, "更新", "成功", "")); + new HrmDateCheck().calWorkInfo(hrmId); + if (session != null) session.setAttribute("resultList", resultList); + //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, "更新", "失败", "")); + if (session != null) session.setAttribute("resultList", resultList); + } + } + } catch (Exception e) { + //数据异常 + writeLog(e); + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83548, userlanguage))); + if (session != null) session.setAttribute("resultList", resultList); + } + } + 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(); + +// endTime = System.currentTimeMillis(); +// System.out.println("---数据缓存清空结束,用时:"+(endTime - startTime)); +// startTime = endTime; + writeImportLog(resultList); + if (session != null) session.setAttribute("logFile", logFile); + return resultList; + } catch (Exception e) { + writeLog(e); + return resultList; + } + + } + + /** + * 插入基础自定义字段信息 + * + * @param id 需要添加自定义信息的人员id + * @return + */ + public boolean addBaseData(String baseFild, String baseValue, int id) { + if (baseFild == null || baseFild.equals("")) return true; + String baseValues[] = baseValue.split(";",-1); + String baseFields[] = baseFild.split(",",-1); + 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.startsWith("char") || fielddbType.startsWith("varchar") || fielddbType.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 personFild 存储人员自定义数据的字段 + * @param personValue 自定义数据值 + * @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(";",-1); + String baseFields[] = baseFild.split(",",-1); + String fielddbType = ""; + String sql = ""; + String scopeId = "-1"; + EncryptUtil encryptUtil = new EncryptUtil(); + 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 = ""; + 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 (fielddbType.startsWith("char") || fielddbType.startsWith("varchar") || fielddbType.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 recordSet.execute(sql); + } + + + /** + * 插入个人自定义字段信息 + * + * @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(";",-1); + String personFields[] = personFild.split(",",-1); + 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.startsWith("char") || fielddbType.startsWith("varchar") || fielddbType.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(";",-1); + String personFields[] = personFild.split(",",-1); + String fielddbType = ""; + String sql = ""; + String scopeId = "1"; + EncryptUtil encryptUtil = new EncryptUtil(); + 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 = ""; + 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 (fielddbType.startsWith("char") || fielddbType.startsWith("varchar") || fielddbType.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 recordSet.execute(sql); + } + + + /** + * 插入工作自定义字段 + * + * @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(";",-1); + String workFields[] = workField.split(",",-1); + 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.startsWith("char") || fielddbType.startsWith("varchar") || fielddbType.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(";",-1); + String workFields[] = workField.split(",",-1); + String fielddbType = ""; + String sql = ""; + String scopeId = "3"; + EncryptUtil encryptUtil = new EncryptUtil(); + 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 = ""; + 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 (fielddbType.startsWith("char") || fielddbType.startsWith("varchar") || fielddbType.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 recordSet.execute(sql); + } + + /** + * 根据分部名称获取分部Id,不存在就创建 + * + * @param subCompanyName 分部名称 eg:泛微广东>泛微深圳 + * @return + */ + public int getSubCompanyId(String subCompanyName) { + + String idOfConver = HrmSubCompanyConver.getIdFromJsonValue(subCompanyName) ; + if(!StringUtils.isBlank(idOfConver)){ + return Util.getIntValue(idOfConver,-1) ; + } + + 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) { + sqlInsert = "insert into HrmSubCompany(subcompanyname,subcompanydesc,companyid,supsubcomid ," + DbFunctionUtil.getInsertColumnSql() + ") values('" + subCompanyNames[i].trim() + "','" + subCompanyNames[i].trim() + "',1" + "," + parentId + " ," + DbFunctionUtil.getInsertColumnValueSql(recordSet.getDBType(), 1) + ")"; // 创建 + execSql(sqlInsert); + HrmTriggerUtil.generateSubcompanyPinyin(subCompanyNames[i].trim(), null); + currentId = getResultSetId(sql); + MatrixUtil.updateSubcompayData(currentId+""); + HrmTriggerUtil.Tri_I_SubComKPICheckFlow(String.valueOf(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_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 idConver = HrmDepartmentConver.getIdFromJsonValue(deptNames,subCompanyId+"") ; + if(StringUtils.isNotBlank(idConver)){ + return Util.getIntValue(idConver,-1) ; + } + + 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; + } + sqlInsert = "insert into HrmDepartment (departmentname,Departmentmark,subcompanyid1,supdepid ," + DbFunctionUtil.getInsertColumnSql() + ") values('" + deptName[i].trim() + "','" + deptName[i].trim() + "'," + subCompanyId + "," + parentId + " ," + DbFunctionUtil.getInsertColumnValueSql(recordSet.getDBType(), 1) + ")"; // 创建 + execSql(sqlInsert); + HrmTriggerUtil.generateDepartmentPinyin(deptName[i].trim(), null); + currentId = getResultSetId(sql); + HrmTriggerUtil.Tri_I_DeptKPICheckFlow(String.valueOf(currentId)); + MatrixUtil.updateDepartmentData(currentId+""); + HrmFaceCheckManager.sync(currentId+"",HrmFaceCheckManager.getOptInsert(),"HRM_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) { + sqlInsert = "insert into HrmJobTitles (jobtitlename,Jobtitlemark,jobactivityid ," + DbFunctionUtil.getInsertColumnSql() + ") values('" + + jobtitlename + "','" + jobtitlename + "'," + jobactivityid + " ," + DbFunctionUtil.getInsertColumnValueSql(recordSet.getDBType(), 1) + ")"; // 创建 + execSql(sqlInsert); + HrmTriggerUtil.generateJobtitlesPinyin(jobtitlename, null); + jobtitle = getResultSetId(selSql); + + HrmFaceCheckManager.sync(jobtitle+"",HrmFaceCheckManager.getOptInsert(),"hrm_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; + } + + /** + * 获取主账号id + * + * @param keyFieldValue 主账号标记 + * @param keyField 关键字段 + * @return + */ + public int getBelongId(String keyFieldValue, String keyField) { + int getAssistantid = -1; + if (!keyFieldValue.equals("")) { + String selSql = "select id from hrmResource where " + keyField + "='" + keyFieldValue + "'"; + getAssistantid = getResultSetId(selSql); + } + return getAssistantid; + } + + /** + * 获取直接上级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 + "'"; + 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; + if (!keyFieldValue.equals("")) { + String selSql = "select id from hrmResource where " + keyField + "='" + 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 bank1 办公地点名称 + * @return + */ + public int getBankId(String bank1) { + int id = 0; + if (!"".equals(bank1)) { + 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; + } + + /** + * 用工性质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 + systemlanguageid = sysLanguage.get(language); + } + return systemlanguageid; + } + + /** + * 获取员工状态 + * + * @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; + } + + /** + * 获取学历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, certificatenum,isADAccount,loginid,workcode, ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + "))) as " + keyField + " from hrmResource"; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql() ||recordSet.getDBType().equalsIgnoreCase("postgresql")) { + sql = "select id, certificatenum,isADAccount,loginid,workcode, ltrim(rtrim(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"))); + if (StringUtil.isNotNull(cerNum)) { + certificateNums.put(StringUtil.vString(cerNum), new Integer(recordSet.getInt("id"))); + } + + isADAccountMap.put(Util.null2String(recordSet.getString("id")), Util.null2String(recordSet.getString("isADAccount"))); + } + + } + + /** + * 写入导入日志 + * + * @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); //原因 + + 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, String operateType){ + //新增账号、工号唯一性校验 + 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(520196, 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, operateType, "失败", errorMsg)); + return true; + } + } + } + return false; + } + + public int getUserlanguage() { + return userlanguage; + } + + + public void setUserlanguage(int userlanguage) { + this.userlanguage = userlanguage; + } + + 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 ; + + } +} 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..0bc5adf --- /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); + } 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; + } +}