You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
weaver-develop/src/com/api/hrm/util/ServiceUtil.java

758 lines
30 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.api.hrm.util;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.api.hrm.bean.HrmFieldBean;
import com.cloudstore.dev.api.util.APPManager;
import com.cloudstore.dev.api.util.EMManager;
import com.cloudstore.dev.api.util.TextUtil;
import com.engine.common.constant.ParamConstant;
import com.engine.hrm.biz.HrmClassifiedProtectionBiz;
import net.coobird.thumbnailator.Thumbnails;
import sun.misc.BASE64Decoder;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.docs.docs.CustomFieldManager;
import weaver.encrypt.EncryptUtil;
import weaver.file.ImageFileManager;
import weaver.general.BaseBean;
import weaver.general.GCONST;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.common.DbFunctionUtil;
import weaver.hrm.common.database.dialect.DbDialectFactory;
import weaver.hrm.common.database.dialect.DialectUtil;
import weaver.hrm.definedfield.HrmDeptFieldManagerE9;
import weaver.hrm.definedfield.HrmFieldComInfo;
import weaver.hrm.definedfield.HrmFieldManager;
import weaver.hrm.online.HrmUserOnlineMap;
import weaver.hrm.resource.ResourceComInfo;
import weaver.login.LicenseCheckLogin;
import weaver.systeminfo.SysMaintenanceLog;
import weaver.systeminfo.SystemEnv;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
import com.engine.integration.util.StringUtils;
import java.util.concurrent.ConcurrentHashMap;
public class ServiceUtil extends BaseBean {
static final boolean isMultilang = true; //人力资源模块是否启用多语言
public String tempHrmSubCompany_table = "tempHrmSubCompany_table";
public String tempHrmDepartment_table = "tempHrmDepartment_table";
public static boolean isAdmin(String id){
if(StringUtils.isBlank(id)) return false ;
boolean isAdmin = false;
String sql = "select count(1) from hrmresourcemanager where id="+id;
RecordSet rs = new RecordSet();
rs.executeSql(sql);
if(rs.next()){
if(rs.getInt(1)>0){
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<SearchConditionOption> getDateSelectFromTo(int language){
return getDateSelectFromTo(language,"0");
}
/**
* 0-全部1-今天2-本周3-本月7-上个月4-本季5-本年8-上一年6-指定日期范围
* */
public static List<SearchConditionOption> getDateSelectFromTo(int language, String defaultValue){
if(Util.null2String(defaultValue).length()==0){
defaultValue = "0";
}
List<SearchConditionOption> options = new ArrayList<SearchConditionOption>();
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<String, Object> otherParams = item.getOtherParams();
if(otherParams == null){
otherParams = new HashMap<String, Object>();
}
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<String, Object> otherParams = hrmFieldBean.getOtherparam();
if(otherParams == null){
otherParams = new HashMap<String, Object>();
}
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<String, String> userid_resourceid2time = new ConcurrentHashMap<String, String>();
public void writeHrmResourceViewLog(Map<String,Object> 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<String> 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<String,Object> requestJson2Map(HttpServletRequest request){
Map<String, Object> returnMap = new HashMap<String, Object>();
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<Map<String, Object>>(){});
}
}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<String, Object> 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<HttpSession> slist = (userSessions != null && userSessions.containsKey(uid)) ? (List<HttpSession>) 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<Map<String,String>> getCusFieldsData(String cmd,String fielddesc,int userlanguage){
Map<String,String> fieldMaps = null;
List<Map<String,String>> 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<String,String> 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;
}
public boolean needCheckDismiss(String fieldname){
RecordSet rs = new RecordSet();
String neekCheck = Util.null2String(rs.getPropValue("Others",fieldname),"1");
return "1".equals(neekCheck);
}
}