package com.vci.server.framework.delegate; import java.text.Collator; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import org.apache.commons.lang3.StringUtils; import com.vci.corba.common.VCIError; import com.vci.corba.framework.data.CombinationInfo; import com.vci.corba.framework.data.CombinationValueInfo; import com.vci.corba.framework.data.DeptInfo; import com.vci.corba.framework.data.PasswordStrategyInfo; import com.vci.corba.framework.data.RoleInfo; import com.vci.corba.common.data.UserEntityInfo; import com.vci.corba.framework.data.UserInfo; import com.vci.corba.framework.data.UserLogonInfo; import com.vci.corba.log.data.LogType; import com.vci.server.base.delegate.BaseDelegate; import com.vci.server.base.delegate.UserEntityDelegate; import com.vci.server.base.utility.LogHelper; import com.vci.server.base.utility.LogRecordUtil; import com.vci.server.cache.OrgCacheProvider; import com.vci.server.common.ThreeDES; import com.vci.server.framework.Logon.SessionInfo; import com.vci.server.framework.cache.DeptCacheUtil; import com.vci.server.framework.cache.RoleCacheUtil; import com.vci.server.framework.cache.UserCacheUtil; import com.vci.server.framework.interfac.SingleLogonInterface; import com.vci.server.framework.interfac.TokenLogonInterface; import com.vci.server.framework.systemConfig.stafforgmanage.combination.Combination; import com.vci.server.framework.systemConfig.stafforgmanage.combination.CombinationService; import com.vci.server.framework.systemConfig.stafforgmanage.combination.CombinationValue; import com.vci.server.framework.systemConfig.stafforgmanage.combination.CombinationValueService; import com.vci.server.framework.systemConfig.stafforgmanage.dept.Department; import com.vci.server.framework.systemConfig.stafforgmanage.dept.DepartmentService; import com.vci.server.framework.systemConfig.stafforgmanage.passwordStrategy.PasswordStrategy; import com.vci.server.framework.systemConfig.stafforgmanage.passwordStrategy.PasswordStrategyService; import com.vci.server.framework.systemConfig.stafforgmanage.role.Role; import com.vci.server.framework.systemConfig.stafforgmanage.role.RoleService; import com.vci.server.framework.systemConfig.stafforgmanage.session.VciSessionInfoDAOImpl; import com.vci.server.framework.systemConfig.stafforgmanage.session.VciSessionInfoDO; import com.vci.server.framework.systemConfig.stafforgmanage.user.User; import com.vci.server.framework.systemConfig.stafforgmanage.user.UserLogon; import com.vci.server.framework.systemConfig.stafforgmanage.user.UserService; import com.vci.server.framework.utils.ObjectConvert; import com.vci.common.log.ServerWithLog4j; import com.vci.common.utility.ObjectUtility; /** *

* Title:RightManagementDelegate *

*

* Description: 基础模块服务端delegate *

*

* Copyright: Copyright (c) 2012 *

*

* Company: VCI *

* * @author wangxl * @time 2012-5-9 * @version 1.0 */ public class RightManagementDelegate extends BaseDelegate { public RightManagementDelegate() { } public RightManagementDelegate(UserEntityInfo userEntityInfo) { super(userEntityInfo); } public UserInfo getUserObjectByUserName(String userName) throws VCIError { return OrgCacheProvider.getUser(userName); // UserInfo res = new UserInfo(); // try { // User user = new UserService().getUserObjectByUserName(userName); // // if (user != null) { // res = ObjectConvert.changeUserToUserInfo(user); // } // } catch (Exception e) { // throw new VCIError("120406", new String[0]); // } // // return res; } /** * 通过token验证登录,token的解密根据企业提供的算法进行自定义 * * @param token * @return * @throws VCIError */ public UserInfo loginByToken(String token) throws VCIError { String tokenClass = new SystemCfgDelegate().getConfigValue("tokenLogonClass"); UserInfo res = new UserInfo(); try { if (tokenClass != null && !tokenClass.equals("")) { Class cls = Class.forName(tokenClass); if (cls == null) return new UserInfo(); TokenLogonInterface logon = (TokenLogonInterface) cls.getConstructor().newInstance(); if (logon == null) return new UserInfo(); String userName = logon.verifyToken(token); if (userName == null || userName.isEmpty()) { return new UserInfo(); } res = fetchUserInfoByName(userName); } } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("120406", new String[0]); } catch (Throwable e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("120406", new String[0]); } return res; } /** *

* Description: 验证用户登录 *

* * @author wangxl * @time 2012-5-21 * @param userName * @param password * @return * @throws VCIError */ public UserInfo checkLogin(String userName, String password) throws VCIError { UserInfo res = new UserInfo(); try { //if (!isSuperUser(userName)) { String logonClass = new SystemCfgDelegate().getConfigValue("logonClass"); if (logonClass != null && !logonClass.equals("")) { Class cls = Class.forName(logonClass); SingleLogonInterface logon = (SingleLogonInterface) cls.getConstructor().newInstance(); boolean rs = logon.verifyUserExist(userName, password); if (rs == true) { res = fetchUserInfoByName(userName); } return res; } else { // ThreeDES des = new ThreeDES();// 实例化一个对�? // des.getKey("daliantan0v0");// 生成密匙 // password = des.getEncString(password); } //} // User user = new UserService().checkLogin(userName, password); // if (user != null) { // res = ObjectConvert.changeUserToUserInfo(user); // // // LogRecordUtil.writeLog(userEntity, "登陆", "登陆成功", LogType.Login, ""); // } UserInfo ui = fetchUserInfoByName(userName); if (ui != null && ui.status == 0 && ui.pwd.equals(password)) { res = ui; LogRecordUtil.saveLoginLog(true, "登陆成功", userEntityInfo); } else { //System.out.println("===========用户=" + res.userName + "; 状态=" + res.status); // else LogRecordUtil.saveLogoutLog("登陆失败", userEntityInfo); } } catch (Exception e) { ServerWithLog4j.logger.error(e); throw new VCIError("120406", new String[0]); } catch (Throwable e) { ServerWithLog4j.logger.error(e); throw new VCIError("120406", new String[0]); } return res; } /** * 校验是否可以登录,并且返回token的信息 * * @param userName 用户名 * @param password 密码 * @param checkPassword 是否校验密码 * @return token的信息 */ // public String checkLoginForToken(LoginInfoDTO loginDTO) throws VCIError { // if (StringUtils.isBlank(loginDTO.getUserId())) { // throw new VCIError("用户名为空", new String[0]); // } // if (loginDTO.isCheckPassword() && StringUtils.isBlank(loginDTO.getPassword())) { // throw new VCIError("密码为空", new String[0]); // } // try { // boolean success = false; // if (!isSuperUser(loginDTO.getUserId())) { // String logonClass = new SystemCfgDelegate().getConfigValue("logonClass"); // if (logonClass != null && !logonClass.equals("")) { // Class cls = Class.forName(logonClass); // SingleLogonInterface logon = (SingleLogonInterface) cls.getConstructor().newInstance(); // success = logon.verifyUserExist(loginDTO.getUserId(), loginDTO.getPassword()); // } else { // if (loginDTO.isCheckPassword()) { // ThreeDES des = new ThreeDES();// 实例化一个对�? // des.getKey("daliantan0v0");// 生成密匙 // loginDTO.setPassword(des.getEncString(loginDTO.getPassword())); // } // } // } // if (!success) { // User user = null; // PasswordStrategy pwdStrategy = null; // if (loginDTO.isCheckPassword()) { // user = new UserService().checkLogin(loginDTO.getUserId(), loginDTO.getPassword()); // } else { // // 单点登录的时候 // user = new UserService().getUserObjectByUserName(loginDTO.getUserId()); // } // if (user == null || StringUtils.isBlank(user.getId())) { // if (loginDTO.isCheckPassword()) { // // 要记录密码错误次数 // user = new UserService().getUserObjectByUserName(loginDTO.getUserId()); // if (user == null || StringUtils.isBlank(user.getId())) { // throw new VCIError("用户名不存在", new String[0]); // } // pwdStrategy = new PasswordStrategyService().getPasswordObjByUserId(user.getId()); // if (pwdStrategy == null) { // throw new VCIError("密码安全策略为空", new String[0]); // } // // 查询用户错误信息的信息 // updateLogonInfo(loginDTO.getUserId().trim(), false); // } // throw new VCIError("用户的密码不正确", new String[0]); // } // // 查询密码安全策略 // if (pwdStrategy == null) { // pwdStrategy = new PasswordStrategyService().getPasswordObjByUserId(user.getId()); // } // if (pwdStrategy == null) { // throw new VCIError("密码安全策略为空", new String[0]); // } // // 看看用户是否被锁定着的 // if (!"0".equals(user.getStatus())) { // throw new VCIError("用户已经停用", new String[0]); // } // // 通过登录信息看看现在是否已经超过要求了 // UserService userSrv = new UserService(); // UserLogon userLogon = userSrv.getUserLogonObj(user.getId()); // if (userLogon.getPlWrongNum() >= pwdStrategy.getRetryTime()) { // throw new VCIError("用户已经停用", new String[0]); // } // // 密码正确的时候,需要更新密码错误的次数 // userLogon.setPlWrongNum((short)0); // // SessionInfo sessionInfo = new SessionInfo(); // // 拷贝信息到 // copyUser2SessionInfo(user, sessionInfo, loginDTO.getLangCode()); // copyRequest2SessionInfo(loginDTO, sessionInfo); // // 查询所有的角色 // RoleInfo[] roleInfos = fetchRoleInfoByUserId(user.getId()); // // if (roleInfos != null && roleInfos.length > 0) { // Map roleOidNameMap = new HashMap(); // for (RoleInfo role : roleInfos) { // roleOidNameMap.put(role.id, role.name); // } // sessionInfo.setRolesName(roleOidNameMap); // // } else { // sessionInfo.setRolesName(new HashMap()); // } // List roleRights = new RoleRightService() // .getFunctionRoleRightByUserName(loginDTO.getUserId()); // if (roleRights != null && roleRights.size() > 0) { // // List functionOidList = new ArrayList(); // for (RoleRight roleRight : roleRights) { // functionOidList.add(roleRight.getFuncId()); // } // sessionInfo.setFunctionOids(functionOidList); // } else { // sessionInfo.setFunctionOids(new ArrayList()); // } // // // 检查是否该修改密码 // if (!loginDTO.isSso() && loginDTO.isCheckPassword()) { // // 最后修改时间+ 失效时间,大于等于当前日期,则需要马上修改密码 // Timestamp lastUpdateTime = user.getPwdUpdateTime(); // if (lastUpdateTime == null) { // // 重来没有登录过 // sessionInfo.setMustChangePassword(true); // sessionInfo.setPasswordTips("您是首次登录系统,请修改密码"); // } // int remindDay = pwdStrategy.getOverdueDay() - pwdStrategy.getRemideDay(); // long oneDay = 24 * 60 * 60 * 1000; // Long needRemindTime = lastUpdateTime.getTime() + remindDay * oneDay; // Long invalidTime = lastUpdateTime.getTime() + pwdStrategy.getOverdueDay() * oneDay; // Long currentTime = System.currentTimeMillis(); // if (currentTime > needRemindTime && currentTime < invalidTime) { // Long balanceTime = invalidTime - currentTime; // Long balanceDay = ((balanceTime - balanceTime % oneDay) / oneDay) + 1; // sessionInfo.setPasswordTips("您的密码还有" + balanceDay + "天过期"); // } // if (currentTime >= invalidTime) { // sessionInfo.setMustChangePassword(true); // sessionInfo.setPasswordTips("您的密码已经过期,请立即修改"); // } // } // // userLogon.setPlLogonTime(Timestamp.valueOf(System.currentTimeMillis() + "")); // ThreeDES des = new ThreeDES();// 实例化一个对�? // des.getKey(UUID.randomUUID().toString());// 生成密匙 // sessionInfo.setToken(des.getEncString(user.getId())); // updateLogonInfo(loginDTO.getUserId().trim(), true); // VciSessionInfoDO sessionInfoDO = new VciSessionInfoDO(); // sessionInfoDO.setToken(sessionInfo.getToken()); // sessionInfoDO.setLastRequestTime(System.currentTimeMillis()); // sessionInfoDO.setUserId(loginDTO.getUserId()); // sessionInfoDO.setJsonString(JSON.toJSONString(sessionInfo)); // sessionInfoDao.save(sessionInfoDO); // return sessionInfo.getToken(); // } // // else // // LogRecordUtil.writeLog(userEntity, "登陆", "登陆失败", LogType.Login, ""); // // } catch (Exception e) { // //e.printStackTrace(); // ServerWithLog4j.logger.error(e); // throw new VCIError("120406", new String[0]); // } catch (Throwable e) { // //e.printStackTrace(); // ServerWithLog4j.logger.error(e); // throw new VCIError("120406", new String[0]); // } // return null; // } /** * 拷贝用户的信息到 会话信息 * * @param user 用户对象 * @param sessionInfo 会话对象 * @param langCode 语言编码 */ private void copyUser2SessionInfo(User user, SessionInfo sessionInfo, String langCode) { sessionInfo.setUserOid(user.getId()); sessionInfo.setUserId(user.getUserName()); sessionInfo.setUserName(user.getTrueName()); sessionInfo.setUsertype(user.getUserType() + ""); sessionInfo.setUsertypeText(""); sessionInfo.setUserSecret(user.getSecretGrade() == null ? "" : (user.getSecretGrade() + "")); sessionInfo.setUserSecretText(""); sessionInfo.setSex(""); sessionInfo.setSexText(""); // sessionInfo.setPhotoUrl(user.getPhoto()); sessionInfo.setLanguage(""); if (StringUtils.isNotBlank(langCode)) { // 传递了要显示的语言 sessionInfo.setLanguage(langCode); } DeptInfo deptInfo = null; try { deptInfo = fetchDeptByUserId(user.getId()); } catch (VCIError e) { // TODO Auto-generated catch block //e.printStackTrace(); ServerWithLog4j.logger.error(e); } // sessionInfo.setPersonOid(user.getPkPerson()); // sessionInfo.setPersonName(user.getPkPersonName()); if (deptInfo != null) { sessionInfo.setDeptOid(deptInfo.id); sessionInfo.setDeptName(deptInfo.name); } // sessionInfo.setDutyOid(user.getPkDuty()); // sessionInfo.setDutyName(user.getPkDutyName()); sessionInfo.setEmail(user.getEmail()); // sessionInfo.setPhoneNo(user.getTel()); // sessionInfo.setRtxNo(user.getRtxNo()); // sessionInfo.setIMId(user.getIMNo()); sessionInfo.setPortalId(user.getId()); // sessionInfo.setWorkNo(user.getWorkNo()); // sessionInfo.setWorkTypeOid(user.getPkWorkType()); // sessionInfo.setWorkTypeName(user.getPkWorkTypeText()); } /** * 拷贝请求的信息到会话信息中 * * @param clientInfo 请求信息 * @param sessionInfo 会话信息 */ // private void copyRequest2SessionInfo(LoginInfoDTO loginInfoDTO, SessionInfo sessionInfo) { // sessionInfo.setIp(loginInfoDTO.getIpAddress()); // // ip的地址在controller里设置 // sessionInfo.setOs(loginInfoDTO.getOsVersion()); // sessionInfo.setBrowser(loginInfoDTO.getBrowserVersion()); // sessionInfo.setSso(loginInfoDTO.isSso()); // sessionInfo.setSsoServiceName(loginInfoDTO.getSsoSystemName()); // } /** * 判断用户是否为超级用户 * * @param userName * @return */ private boolean isSuperUser(String userName) { try { SystemCfgDelegate conf = new SystemCfgDelegate(); String userNameAdmin = conf.getConfigValue("user.admin"); String userNameDeveloper = conf.getConfigValue("user.developer"); String userNameRoot = conf.getConfigValue("user.rooter"); if (userName.equals(userNameAdmin) || userName.equals(userNameDeveloper) || userName.equals(userNameRoot)) { return true; } } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); } return false; } /** *

* Description: 验证用户登录 *

* * @param userName * @param password * @return * @throws VCIError */ public UserInfo checkLoginForBS(String userName, String password) throws VCIError { return checkLogin(userName, password); } /** *

* Description:用于验证角色是否被引�? *

* * @author wangxl * @time 2012-5-10 * @param id * @return * @throws VCIError */ public int checkRoleIsquotedCount(String id) throws VCIError { int count = 0; try { count = new RoleService().checkRoleIsquotedCount(id); } catch (Exception e) { throw new VCIError("120307", new String[0]); } return count; } /** *

* Description: 获取所有部�?/p> * * @author wangxl * @time 2012-5-10 * @return * @throws VCIError */ public DeptInfo[] fetchDepartmentInfo() throws VCIError { return OrgCacheProvider.getDepts(); // List list = null; // try { // list = new DepartmentService().getDepartmentList(); // } catch (Exception e) { // throw new VCIError("120101", new String[0]); // } // return changeDepartmentToDepartmentInfos(list); } public DeptInfo[] fetchDeptByUserNames(String[] userNames) throws VCIError { List list = null; try { list = new DepartmentService().fetchDeptByUserNames(userNames); } catch (Exception e) { throw new VCIError("120101", new String[0]); } return changeDepartmentToDepartmentInfos(list); } /** *

* Description:根据Id获取部门 *

* * @author wangxl * @time 2012-5-10 * @param id * @return * @throws VCIError */ public DeptInfo fetchDepartmentInfoById(String id) throws VCIError { return OrgCacheProvider.getDepartment(id); // Department depart = null; // try { // depart = new DepartmentService().selectDepartmentById(id); // } catch (Exception e) { // throw new VCIError("120104", new String[0]); // } // return ObjectConvert.changeDepartmentToDepartmentInfo(depart); } public DeptInfo fetchManageDept(String rmTypeId) throws VCIError { DeptInfo info = new DeptInfo(); Department depart = null; try { depart = new DepartmentService().fetchManageDept(rmTypeId); if (depart != null) { info = ObjectConvert.changeDepartmentToDepartmentInfo(depart); } } catch (Exception e) { throw new VCIError("120104", new String[0]); } return info; } public DeptInfo fetchManageOfMaterialsDept(String rmTypeId) throws VCIError { DeptInfo info = new DeptInfo(); Department depart = null; try { depart = new DepartmentService().fetchManageOfMaterialsDept(rmTypeId); if (depart != null) { info = ObjectConvert.changeDepartmentToDepartmentInfo(depart); } } catch (Exception e) { throw new VCIError("120104", new String[0]); } return info; } public DeptInfo fetchDeptByUserId(String userId) throws VCIError { Department depart = null; DeptInfo info = new DeptInfo(); try { depart = new DepartmentService().fetchDeptByUserId(userId); if (depart != null) { info = ObjectConvert.changeDepartmentToDepartmentInfo(depart); } } catch (Exception e) { throw new VCIError("120104", new String[0]); } return info; } public DeptInfo fetchDeptByDeptName(String deptName) throws VCIError { Department depart = null; DeptInfo info = new DeptInfo(); try { depart = new DepartmentService().selectDepartmentByName(deptName); if (depart != null) { info = ObjectConvert.changeDepartmentToDepartmentInfo(depart); } } catch (Exception e) { throw new VCIError("120104", new String[0]); } return info; } public DeptInfo fetchDeptByParentIdAndName(String parentId, String deptName) throws VCIError { Department depart = null; DeptInfo info = new DeptInfo(); try { depart = new DepartmentService().fetchDeptByParentIdAndName(parentId, deptName); if (depart != null) { info = ObjectConvert.changeDepartmentToDepartmentInfo(depart); } } catch (Exception e) { throw new VCIError("120104", new String[0]); } return info; } /** *

* Description:获取根节点部�? *

* * @author wangxl * @time 2012-5-10 * @return * @throws VCIError */ public DeptInfo[] fetchDepartmentInfoRoot() throws VCIError { List list = null; try { list = new DepartmentService().getDepartmentListByFilter(true, ""); Collections.sort(list, new DeptNameComparator()); } catch (Exception e) { throw new VCIError("120105", new String[0]); } return changeDepartmentToDepartmentInfos(list); } /** *

* Description: 返回下级部门 *

* * @author wangxl * @time 2012-5-10 * @param prtoid * @return * @throws VCIError */ public DeptInfo[] fetchDepartmentInfoByParentId(String prtoid) throws VCIError { List list = null; try { list = new DepartmentService().getDepartmentListByFilter(false, prtoid); } catch (Exception e) { throw new VCIError("120106", new String[0]); } return changeDepartmentToDepartmentInfos(list); } /** *

* Description:根据Id返回部门及其子部�? *

* * @author wangxl * @time 2012-5-10 * @param id * @return * @throws VCIError */ public DeptInfo[] fetchDepartmentInfosById(String id) throws VCIError { List list = null; try { list = new DepartmentService().getDepartmentListById(id); } catch (Exception e) { throw new VCIError("120107", new String[0]); } return changeDepartmentToDepartmentInfos(list); } public DeptInfo[] fetchDepartmentInfosBySonId(String id) throws VCIError { List list = null; try { list = new DepartmentService().getDepartmentListBySonId(id); } catch (Exception e) { throw new VCIError("120107", new String[0]); } return changeDepartmentToDepartmentInfos(list); } public RoleInfo fetchRoleInfoById(String roleId) throws VCIError { return OrgCacheProvider.getRole(roleId); // Role role = new RoleService().selectRole(roleId); // return ObjectConvert.changeRoleToRoleInfo(role); } public RoleInfo fetchRoleByName(String name) throws VCIError { return OrgCacheProvider.getRoleByName(name); // Role role = new RoleService().selectRoleByName(name); // return ObjectConvert.changeRoleToRoleInfo(role); } /** *

* Description:获取所有角�? *

* * @author wangxl * @time 2012-5-10 * @return * @throws VCIError */ public RoleInfo[] fetchRoleInfo() throws VCIError { return OrgCacheProvider.getRoles(); // List list = null; // try { // list = new RoleService().getRoleList(); // } catch (Exception e) { // throw new VCIError("120301", new String[0]); // } // int size = list.size(); // RoleInfo[] roleInfo = new RoleInfo[size]; // for (int i = 0; i < size; i++) { // roleInfo[i] = ObjectConvert.changeRoleToRoleInfo(list.get(i)); // } // return roleInfo; } /** *

* Description:根据类型获取角色 *

* * @author wangxl * @time 2012-5-10 * @param type * @return * @throws VCIError */ public RoleInfo[] fetchRoleInfoByType(int type) throws VCIError { List list = null; try { list = new RoleService().getRoleListByType(type); } catch (Exception e) { throw new VCIError("120302", new String[0]); } int size = list.size(); RoleInfo[] roleInfo = new RoleInfo[size]; for (int i = 0; i < size; i++) { roleInfo[i] = ObjectConvert.changeRoleToRoleInfo((Role)list.get(i)); } return roleInfo; } /** *

* Description:根据角色类型获取角色 *

* * @author liujw * @time 2013-5-20 * @param type * @return * @throws VCIError */ public RoleInfo[] fetchRoleInfoByRoleType(int type) throws VCIError { List list = null; try { list = new RoleService().getRoleByRoleType(type); } catch (Exception e) { throw new VCIError("120302", new String[0]); } int size = list.size(); RoleInfo[] roleInfo = new RoleInfo[size]; for (int i = 0; i < size; i++) { roleInfo[i] = ObjectConvert.changeRoleToRoleInfo((Role)list.get(i)); } return roleInfo; } /** * 设备送检角色查询 * * @param type * @return * @throws VCIError */ public RoleInfo[] getRoleListByTypeForMeasure(int type) throws VCIError { List list = null; try { list = new RoleService().getRoleListByTypeForMeasure(type); } catch (Exception e) { throw new VCIError("120302", new String[0]); } int size = list.size(); RoleInfo[] roleInfo = new RoleInfo[size]; for (int i = 0; i < size; i++) { roleInfo[i] = ObjectConvert.changeRoleToRoleInfo((Role)list.get(i)); } return roleInfo; } /** *

* Description: 获取用户的角�?/p> * * @author wangxl * @time 2012-5-11 * @param userId * @return * @throws VCIError */ public RoleInfo[] fetchRoleInfoByUserId(String userId) throws VCIError { List list = null; try { list = new RoleService().getRoleListByUserId(userId); } catch (Exception e) { throw new VCIError("120302", new String[0]); } int size = list.size(); RoleInfo[] roleInfo = new RoleInfo[size]; for (int i = 0; i < size; i++) { roleInfo[i] = ObjectConvert.changeRoleToRoleInfo((Role)list.get(i)); } return roleInfo; } public RoleInfo[] fetchRoleInfoByUserName(String userName) throws VCIError { List list = null; try { list = new RoleService().getRoleListByUserName(userName); } catch (Exception e) { throw new VCIError("120302", new String[0]); } int size = list.size(); RoleInfo[] roleInfo = new RoleInfo[size]; for (int i = 0; i < size; i++) { roleInfo[i] = ObjectConvert.changeRoleToRoleInfo((Role)list.get(i)); } return roleInfo; } public RoleInfo[] fetchRoleInfoByUserType(String userType) throws VCIError { List list = null; try { list = new RoleService().getRoleListByUserType(userType); } catch (Exception e) { throw new VCIError("120302", new String[0]); } int size = list.size(); RoleInfo[] roleInfo = new RoleInfo[size]; for (int i = 0; i < size; i++) { roleInfo[i] = ObjectConvert.changeRoleToRoleInfo((Role)list.get(i)); } return roleInfo; } @SuppressWarnings("unchecked") public RoleInfo[] fetchRoleInfoByUserName(int pageNo, int pageSize, String userName) throws VCIError { List list = null; try { list = new RoleService().getRoleListByUserName(pageNo, pageSize, userName); } catch (Exception e) { throw new VCIError("120302", new String[0]); } int size = list.size(); RoleInfo[] roleInfo = new RoleInfo[size]; for (int i = 0; i < size; i++) { roleInfo[i] = ObjectConvert.changeRoleToRoleInfo(list.get(i)); } return roleInfo; } public int getRoleTotalByUserName(String userName) throws VCIError { int total = 0; try { total = new RoleService().getRoleTotalByUserName(userName); } catch (Exception e) { throw new VCIError("120308", new String[0]); } return total; } /** *

* Description:获取所有人�? *

* * @author wangxl * @time 2012-5-10 * @return * @throws VCIError */ //@SuppressWarnings("unchecked") public UserInfo[] fetchUserInfo() throws VCIError { return OrgCacheProvider.getUsers(); // List list = null; // try { // list = new UserService().getUserList(); // } catch (Exception e) { // throw new VCIError("120401", new String[0]); // } // int size = list.size(); // UserInfo[] userInfo = new UserInfo[size]; // for (int i = 0; i < size; i++) { // userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i)); // } // return userInfo; } /** *

* Description:获取除admin,developer,三员外的所有普通人�? *

* * @author liujw * @time 2013-5-7 * @return * @throws VCIError */ //@SuppressWarnings("unchecked") public UserInfo[] fetchUserInfoWithOutSanYuan() throws VCIError { List list = null; try { list = new UserService().getUserListWithOutSanYuan(); } catch (Exception e) { throw new VCIError("120401", new String[0]); } int size = list.size(); UserInfo[] userInfo = new UserInfo[size]; for (int i = 0; i < size; i++) { userInfo[i] = ObjectConvert.changeUserToUserInfo((User)list.get(i)); } return userInfo; } /** *

* Description:根据条件查询人员 *

* * @author wangxl * @time 2012-5-10 * @param name * @param userName * @param companyId * @param roleId * @param userType * @param empNo * @return * @throws VCIError */ public UserInfo[] fetchUserInfoByCondition(String searchName, String searchUserName, String deptId, String roleId, String userName, int pageNo, int pageSize) throws VCIError { List list = null; try { boolean bSuper = isSuperUser(userName); //System.out.print("=============bSuper=" + bSuper); list = new UserService().getUserListByCondition(searchName, searchUserName, deptId, roleId, userName, pageNo, pageSize, !bSuper); } catch (Exception e) { throw new VCIError("120401", new String[0]); } int size = list.size(); UserInfo[] userInfo = new UserInfo[size]; for (int i = 0; i < size; i++) { userInfo[i] = ObjectConvert.changeUserToUserInfo((User)list.get(i)); } return userInfo; } // add by caill start 2016.9.26 public UserInfo[] fetchUserInfoByConditionUnited(String searchName, String searchUserName, String deptId, String roleId, String userName, int pageNo, int pageSize) throws VCIError { List list = null; try { boolean bSuper = isSuperUser(userName); list = new UserService().getUserListByConditionUnited(searchName, searchUserName, deptId, roleId, userName, pageNo, pageSize, !bSuper); } catch (Exception e) { throw new VCIError("120401", new String[0]); } int size = list.size(); UserInfo[] userInfo = new UserInfo[size]; for (int i = 0; i < size; i++) { userInfo[i] = ObjectConvert.changeUserToUserInfo((User)list.get(i)); } return userInfo; } // add by caill end public int getUserTotalByCondition(String searchName, String searchUserName, String deptId, String roleId, String userName) throws VCIError { int total = 0; try { total = new UserService().getUserTotalByCondition(searchName, searchUserName, deptId, roleId, userName, false); } catch (Exception e) { throw new VCIError("120413", new String[0]); } return total; } /** *

* Description:根据类型获取人员 *

* * @author wangxl * @time 2012-5-10 * @param type * @return * @throws VCIError */ public UserInfo[] fetchUserInfoByType(int type) throws VCIError { List list = null; try { list = new UserService().getUserListByType(type); } catch (Exception e) { throw new VCIError("120402", new String[0]); } int size = list.size(); UserInfo[] userInfo = new UserInfo[size]; for (int i = 0; i < size; i++) { userInfo[i] = ObjectConvert.changeUserToUserInfo((User)list.get(i)); } return userInfo; } /** *

* Description:根据用户名查找人�? *

* * @author wangxl * @time 2012-5-10 * @param userName * @return * @throws VCIError */ public UserInfo fetchUserInfoByName(String userName) throws VCIError { return OrgCacheProvider.getUser(userName); // UserInfo res = new UserInfo(); // try { // User user = new UserService().selectUserByName(userName); // if (user == null) { // user = new User(); // } // res = ObjectConvert.changeUserToUserInfo(user); // // } catch (Exception e) { // throw new VCIError("120401", new String[0]); // } // return res; } /** *

* Description: 根据角色和类型查找人�?/p> * * @author wangxl * @time 2012-5-10 * @param roleId * @param type * @return * @throws VCIError */ public UserInfo[] fetchUserInfoByRoleId(String roleId, int type) throws VCIError { List list = null; try { list = new UserService().fetchUserInfoByRoleId(roleId, type); } catch (Exception e) { throw new VCIError("120401", new String[0]); } int size = list.size(); UserInfo[] userInfo = new UserInfo[size]; for (int i = 0; i < size; i++) { userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i)); } return userInfo; } public UserInfo[] fetchUsersByRoleId(String roleId) throws VCIError { List list = null; try { list = new UserService().fetchUsersByRoleId(roleId); } catch (Exception e) { throw new VCIError("120401", new String[0]); } int size = list.size(); UserInfo[] userInfo = new UserInfo[size]; for (int i = 0; i < size; i++) { userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i)); } return userInfo; } public UserInfo[] fetchUserInfoByDeptAndRole(String[] deptIds, String[] roleIds) throws VCIError { List list = null; try { list = new UserService().fetchUserInfoByDeptAndRole(deptIds, roleIds); } catch (Exception e) { throw new VCIError("120401", new String[0]); } int size = list.size(); UserInfo[] userInfo = new UserInfo[size]; for (int i = 0; i < size; i++) { userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i)); } return userInfo; } /** *

* Description: 根据角色Id获取人员 *

* * @author wangxl * @time 2012-5-11 * @param roleId * @return */ public UserInfo[] selectUserByRoleId(String roleId) throws VCIError { List list = null; try { list = new UserService().selectUserByRoleId(roleId); } catch (Exception e) { throw new VCIError("120401", new String[0]); } int size = list.size(); UserInfo[] userInfo = new UserInfo[size]; for (int i = 0; i < size; i++) { userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i)); } return userInfo; } /** *

* Description:保存人员与文件柜的关�? *

* * @author wangxl * @time 2012-5-11 * @param roleId * @param userIds * @param userEntityInfo * @return * @throws VCIError */ // public boolean savePvolumeUser(String pvolumeId, String[] userIds, UserEntityInfo userEntityInfo) throws VCIError { // boolean rs = true; // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); // try { // PvolumeService pvolumeService = new PvolumeService(); // UserService userService = new UserService(); // UserEntityDelegate.setUserEntityToService(pvolumeService, userEntityInfo); // rs = pvolumeService.savePvolumUser(pvolumeId, userIds); // StringBuilder log = null; // Pvolume pvolume = pvolumeService.selectPvolume(pvolumeId); // for (String id : userIds) { // log = new StringBuilder(); // log.append(pvolume.getLogInfo() + "->"); // log.append("用户名:"); // User user = (User) userService.getUserInfoList(id).get(0); // log.append("[" + user.getUserName() + "]"); // LogRecordUtil.writeLog(userEntity, "向文件柜分配成员", "成功", log.toString(), LogType.General, // pvolume.getId()); // } // } catch (Exception e) { // throw new VCIError("120306", new String[0]); // } // // return rs; // } /** *

* Description:保存人员与角色的关系 *

* * @author wangxl * @time 2012-5-11 * @param roleId * @param userIds * @param userEntityInfo * @return * @throws VCIError */ public boolean saveRight(String roleId, String[] userIds, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; //UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { RoleService roleService = new RoleService(); UserService userService = new UserService(); // UserService userService = new UserService(); UserEntityDelegate.setUserEntityToService(roleService, userEntityInfo); List lstUser = userService.fetchUserInfoByRoleId(roleId, 1); rs = roleService.saveRight(roleId, userIds); Role role = roleService.selectRole(roleId); // List lstUserID = Arrays.asList(userIds); List lstUserID = new ArrayList(); for (String id : userIds) { lstUserID.add(id); } List lstDel = new ArrayList(); for (int i = 0; i < lstUser.size(); i++) { User user = (User) lstUser.get(i); if (lstUserID.contains(user.getId())) lstUserID.remove(user.getId()); else lstDel.add(user); } StringBuilder log = null; // 增加的人员 for (String id : lstUserID) { log = new StringBuilder(); log.append(role.getLogInfo() + "->[增加用户]->"); // log.append("用户:"); User user = (User) userService.getUserInfoList(id).get(0); log.append("[" + user.getUserName() + "(" + user.getTrueName() + ")]"); LogRecordUtil.writeLog(userEntityInfo, "角色增加成员", "成功", log.toString(), LogType.General, role.getId()); } // 删除的人员 for (User u : lstDel) { log = new StringBuilder(); log.append(role.getLogInfo() + "->[减少用户]->"); // log.append("用户:"); log.append("[" + u.getUserName() + "(" + u.getTrueName() + ")]"); LogRecordUtil.writeLog(userEntityInfo, "角色减少成员", "成功", log.toString(), LogType.General, role.getId()); } // for(String id : userIds){ // log = new StringBuilder(); // log.append(role.getLogInfo()+"->"); // log.append("用户名:"); // User user = (User)userService.getUserInfoList(id).get(0); // log.append("["+user.getUserName()+"]"); // LogRecordUtil.writeLog(userEntity, "向角色分配成员", log.toString(), LogType.General, role.getId()); // } // LogRecordUtil.writeLog(userEntity, "向角色分配成员", role.getLogInfo() + ",角色发生变化", // LogType.General, role.getId()); } catch (Exception e) { throw new VCIError("120306", new String[0]); } return rs; } /** * 保存三员与成员之间的关系 * * @param roleId * @param userIds * @param userEntityInfo * @return * @throws VCIError */ public boolean saveSpecialRole(String roleId, String[] userIds, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { RoleService roleService = new RoleService(); UserService userService = new UserService(); UserEntityDelegate.setUserEntityToService(roleService, userEntityInfo); List lstUser = userService.fetchUserInfoByRoleId(roleId, 1); rs = roleService.saveSpecialRole(roleId, userIds); Role role = roleService.selectRole(roleId); // List lstUserID = Arrays.asList(userIds); List lstUserID = Arrays.asList(userIds);// ArrayList(); List lstDel = new ArrayList(); for (int i = 0; i < lstUser.size(); i++) { User user = (User) lstUser.get(i); if (lstUserID.contains(user.getId())) lstUserID.remove(user.getId()); } StringBuilder log = null; // 增加的人员 for (String id : lstUserID) { log = new StringBuilder(); log.append(role.getLogInfo() + "->[增加用户]->"); // log.append("用户:"); User user = (User) userService.getUserInfoList(id).get(0); log.append("[" + user.getUserName() + "(" + user.getTrueName() + ")]"); LogRecordUtil.writeLog(userEntityInfo, "角色增加成员", "成功", log.toString(), LogType.General, role.getId()); } // for(String id : userIds){ // log = new StringBuilder(); // log.append(role.getLogInfo()+"->"); // log.append("用户名:"); // User user = (User)userService.getUserInfoList(id).get(0); // log.append("["+user.getUserName()+"]"); // LogRecordUtil.writeLog(userEntity, "角色分配成员", log.toString(), LogType.General,role.getId()); // } } catch (Exception e) { throw new VCIError("120306", new String[0]); } return rs; } /** *

* Description:保存部门和人员的关系 *

* * @author wangxl * @time 2012-5-15 * @param deptId * @param userIds * @param userEntityInfo * @return * @throws VCIError */ public boolean saveRighForDept(String deptId, String[] userIds, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { DepartmentService deptService = new DepartmentService(); UserService userService = new UserService(); List lstUser = userService.getUserByDeptId(deptId); UserEntityDelegate.setUserEntityToService(deptService, userEntityInfo); rs = deptService.saveRight(deptId, userIds); // Department depart = deptService.selectDepartmentById(deptId); List lstUserID = new ArrayList(); for (String id : userIds) { lstUserID.add(id); } List lstDel = new ArrayList(); for (int i = 0; i < lstUser.size(); i++) { User user = (User) lstUser.get(i); if (lstUserID.contains(user.getId())) lstUserID.remove(user.getId()); else lstDel.add(user); } String deptPath = this.getDepartmentPath(deptId); StringBuilder log = null; // 增加的人员 for (String id : lstUserID) { log = new StringBuilder(); log.append("[").append(deptPath).append("]->[增加用户]->"); // log.append("用户:"); User user = (User) userService.getUserInfoList(id).get(0); log.append("[" + user.getUserName() + "(" + user.getTrueName() + ")]"); LogRecordUtil.writeLog(userEntityInfo, "部门增加成员", "成功", log.toString(), LogType.General, deptId); } // 删除的人员 for (User u : lstDel) { log = new StringBuilder(); log.append("[").append(deptPath).append("]->[减少用户]->"); // log.append("用户:"); log.append("[" + u.getUserName() + "(" + u.getTrueName() + ")]"); LogRecordUtil.writeLog(userEntityInfo, "部门减少成员", "成功", log.toString(), LogType.General, deptId); } } catch (Exception e) { throw new VCIError("120111", new String[0]); } return rs; } public boolean saveRights(String[] roleIds, String[] userIds, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { UserService userService = new UserService(); RoleService roleService = new RoleService(); UserEntityDelegate.setUserEntityToService(userService, userEntityInfo); StringBuilder log = null; for (String userId : userIds) { log = new StringBuilder(); log.append("用户名:"); rs = userService.saveRights(roleIds, userId); List list = userService.getUserInfoList(userId); if (list != null) { log.append(((User) list.get(0)).getUserName() + ""); } log.append("->"); for (String roleId : roleIds) { Role role = roleService.selectRole(roleId); LogRecordUtil.writeLog(userEntityInfo, "成员分配角色", "成功", log.toString() + "[" + role.getName() + "]", LogType.General, "角色ID:" + roleId + " 用户ID:" + userId); } } } catch (Exception e) { throw new VCIError("120111", new String[0]); } return rs; } public boolean saveUserDept(String[] userIds, String deptId, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { UserService userService = new UserService(); DepartmentService departmentService = new DepartmentService(); UserEntityDelegate.setUserEntityToService(userService, userEntityInfo); StringBuilder log = null; // Department dept = departmentService.selectDepartmentById(deptId); String deptPath = getDepartmentPath(deptId); log = new StringBuilder(); for (String userId : userIds) { log.setLength(0); List list = userService.getUserInfoList(userId); if (list != null && list.size() >= 1) { Department old = departmentService.fetchDeptByUserId(userId); if (old != null && old.getId().equalsIgnoreCase(deptId)) continue; User user = (User) list.get(0); rs = userService.saveUserDept(userId, deptId); log.append("用户").append("[" + user.getUserName() + "(" + user.getTrueName() + ")]:"); if (old != null) { log.append("[" + getDepartmentPath(old.getId()) + "]->"); } log.append("[").append(deptPath).append("]"); // log.append("["+user.getUserName()+"]"); } LogRecordUtil.writeLog(userEntityInfo, "用户分配部门", "成功", log.toString(), LogType.General, "部门ID:" + deptId + " 用户id:" + userId); } } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("120111", new String[0]); } return rs; } /** * 获取指定部门的全路径 * * @param deptId * @return */ private String getDepartmentPath(String deptId) { StringBuilder sbDepName = new StringBuilder(); try { DeptInfo[] depts = fetchDepartmentInfosBySonId(deptId); for (int i = depts.length - 1; i >= 0; i--) { if (sbDepName.length() > 0) sbDepName.append("-"); sbDepName.append(depts[i].name); } } catch (VCIError e) { // TODO Auto-generated catch block //e.printStackTrace(); ServerWithLog4j.logger.error(e); } return sbDepName.toString(); } /** *

* Description: 保存部门 *

* * @author wangxl * @time 2012-5-10 * @param departmentInfo * @param userEntityInfo * @return * @throws VCIError */ public String saveDepartment(DeptInfo departmentInfo, UserEntityInfo userEntityInfo) throws VCIError { Department department = ObjectConvert.changeDepartmentInfoToDepartment(departmentInfo); if (StringUtils.isBlank(department.getId())) { String id = ObjectUtility.getNewObjectID36(); department.setId(id); } // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { DepartmentService departmentService = new DepartmentService(); UserEntityDelegate.setUserEntityToService(departmentService, userEntityInfo); departmentService.saveDepartment(department); // LogRecordUtil.writeLog(userEntity, "添加", department.getLogInfo(), // LogType.General,department.getId()); DeptCacheUtil.getInstance().setObject(departmentInfo); String log = String.format("添加部门:%s [%s]", department.getName(), LogHelper.toNewLogString(department)); LogRecordUtil.writeLog(userEntityInfo, "添加", "成功", log, LogType.General, department.getId()); } catch (Exception e) { throw new VCIError("120109", new String[0]); } return department.getId(); } /** * 批量保存部门信息 * * @param deptInfo,部门信息 * @param userEntityInfo,用户信息 * @return * @throws VCIError */ public boolean batchSaveDepart(DeptInfo[] deptInfos, UserEntityInfo userEntityInfo) throws VCIError { Department[] depts = new Department[deptInfos.length]; for (int i = 0; i < deptInfos.length; i++) { depts[i] = ObjectConvert.changeDepartmentInfoToDepartment(deptInfos[i]); } try { DepartmentService departmentService = new DepartmentService(); UserEntityDelegate.setUserEntityToService(departmentService, userEntityInfo); departmentService.batchSaveDepart(depts); for (DeptInfo dept : deptInfos) { DeptCacheUtil.getInstance().setObject(dept); } } catch (Throwable e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("120112", new String[0]); } return true; } /** *

* Description:保存角色 *

* * @author wangxl * @time 2012-5-10 * @param roleInfo * @param userEntityInfo * @return * @throws VCIError */ public String saveRole(RoleInfo roleInfo, UserEntityInfo userEntityInfo) throws VCIError { Role role = ObjectConvert.changeRoleInfoToRole(roleInfo); String id = ObjectUtility.getNewObjectID36(); role.setId(id); // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { RoleService roleService = new RoleService(); UserEntityDelegate.setUserEntityToService(roleService, userEntityInfo); roleService.saveRole(role); RoleCacheUtil.getInstance().setObject(role); String log = String.format("添加角色:%s [%s]", role.getName(), LogHelper.toNewLogString(role)); LogRecordUtil.writeLog(userEntityInfo, "添加", "成功", log, LogType.General, role.getId()); // LogRecordUtil.writeLog(userEntity, "添加", role.getLogInfo(), // LogType.General,role.getId()); } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("120304", new String[0]); } return id; } /** *

* Description:根据Id获取角色 *

* * @author wangxl * @time 2012-5-10 * @param id * @return */ public RoleInfo selectRole(String id) { RoleService roleService = new RoleService(); Role role = roleService.selectRole(id); return ObjectConvert.changeRoleToRoleInfo(role); } /** *

* Description: 保存人员 *

* * @author wangxl * @time 2012-5-10 * @param userInfo * @param userEntityInfo * @return * @throws VCIError */ public String saveUser(UserInfo userInfo, UserEntityInfo userEntityInfo) throws VCIError { User user = ObjectConvert.changeUserInfoToUser(userInfo); String id = ""; if (user.getId() == null || user.getId().equals("")) { id = ObjectUtility.getNewObjectID36(); user.setId(id); } else { id = user.getId(); } // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { UserService userService = new UserService(); UserEntityDelegate.setUserEntityToService(userService, userEntityInfo); userService.saveUser(user); UserCacheUtil.getInstance().setObject(userInfo); String log = String.format("添加用户:%s [%s]", user.getUserName(), LogHelper.toNewLogString(user)); LogRecordUtil.writeLog(userEntityInfo, "添加", "成功", log, LogType.General, user.getId()); // LogRecordUtil.writeLog(userEntity, "添加", user.getLogInfo(), // LogType.General,user.getId()); } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("120404", new String[0]); } return id; } /** *

* Description: 修改部门 *

* * @author wangxl * @time 2012-5-10 * @param deptInfo * @param userEntityInfo * @return * @throws VCIError */ public boolean updateDepartment(DeptInfo deptInfo, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; Department departmentAfter = ObjectConvert.changeDepartmentInfoToDepartment(deptInfo); // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { DepartmentService departmentService = new DepartmentService(); UserEntityDelegate.setUserEntityToService(departmentService, userEntityInfo); Department departBefore = departmentService.selectDepartmentById(departmentAfter.getId()); // StringBuilder logres = new StringBuilder(); // logres.append("更新前:"+departBefore.getLogInfo()); // logres.append(" 更新后:"+departmentAfter.getLogInfo()); String log = ""; log = String.format("更改部门:%s; %s", departmentAfter.getName(), LogHelper.toUpdataLogString(departBefore, departmentAfter)); rs = departmentService.updateDepartment(departmentAfter); DeptCacheUtil.getInstance().setObject(deptInfo); if (rs) LogRecordUtil.writeLog(userEntityInfo, "更新", "成功", log, LogType.General, departmentAfter.getId()); else LogRecordUtil.writeLog(userEntityInfo, "更新", "失败", log, LogType.General, departmentAfter.getId()); } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("120110", new String[0]); } return rs; } /** *

* Description:修改角色 *

* * @author wangxlou * @time 2012-5-10 * @param roleInfo * @param userEntityInfo * @return * @throws VCIError */ public boolean updateRole(RoleInfo roleInfo, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; Role role = ObjectConvert.changeRoleInfoToRole(roleInfo); // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { RoleService roleService = new RoleService(); UserEntityDelegate.setUserEntityToService(roleService, userEntityInfo); Role roleBefroe = roleService.selectRole(role.getId()); String log = ""; log = String.format("更改角色:%s; %s", role.getName(), LogHelper.toUpdataLogString(roleBefroe, role)); rs = roleService.updateRole(role); RoleCacheUtil.getInstance().setObject(roleInfo); // StringBuilder log = new StringBuilder(); // log.append("更新前:"+roleBefroe.getLogInfo()); // log.append(" 更新后:"+role.getLogInfo()); LogRecordUtil.writeLog(userEntityInfo, "更新", "成功", log, LogType.General, role.getId()); } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("120305", new String[0]); } return rs; } /** *

* Description:修改人员 *

* * @author wangxl * @time 2012-5-10 * @param userInfo * @param userEntityInfo * @return * @throws VCIError */ public boolean saveOrUpdateUser(UserInfo userInfo, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; User user = ObjectConvert.changeUserInfoToUser(userInfo); try { UserService userService = new UserService(); UserEntityDelegate.setUserEntityToService(userService, userEntityInfo); User sysUser = userService.selectUserByName(userInfo.userName); if (sysUser == null) { String id = ObjectUtility.getNewObjectID36(); user.setId(id); userService.saveUser(user); } else { user.setId(sysUser.getId()); userService.updateUser(user); } UserCacheUtil.getInstance().setObject(userInfo); } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("120405", new String[0]); } return rs; } /** *

* Description:修改人员 *

* * @author wangxl * @time 2012-5-10 * @param userInfo * @param userEntityInfo * @return * @throws VCIError */ public boolean updateUser(UserInfo userInfo, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; User user = ObjectConvert.changeUserInfoToUser(userInfo); // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { UserService userService = new UserService(); UserEntityDelegate.setUserEntityToService(userService, userEntityInfo); User userBefroe = userService.getUserObjectByoid(user.getId()); String log = ""; log = String.format("更改用户:%s;%s", user.getUserName(), LogHelper.toUpdataLogString(userBefroe, user)); // log.append("更新前:"+userBefroe.getLogInfo()); // log.append(" 更新后:"+user.getLogInfo()); userService.updateUser(user); UserCacheUtil.getInstance().setObject(userInfo); LogRecordUtil.writeLog(userEntityInfo, "更新", "成功", log, LogType.General, user.getId()); } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("120405", new String[0]); } return rs; } public String checkPasswordStrategyByUserId(String userId, String password) throws VCIError { try { PasswordStrategyInfo psi = fetchPasswordStrategyByUserId(userId); if (psi == null) return "没有配置密码策略"; return checkPasswordStrategy(psi, password); } catch (Exception e) { throw new VCIError("检查密码策略符合性异常", new String[] {e.getMessage()}); } } public String modifyUserPassword(String idUser, String oldPW, String newPW, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; String error = ""; // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { UserService userService = new UserService(); UserEntityDelegate.setUserEntityToService(userService, userEntityInfo); User user = userService.getUserObjectByoid(idUser); if (StringUtils.isEmpty(user.getId())) { error = String.format("用户ID无效:", idUser); LogRecordUtil.writeLog(userEntityInfo, "修改密码", "失败", error, LogType.General, user.getId()); return error; } ThreeDES des = new ThreeDES();// 实例化一个对�? des.getKey("daliantan0v0");// 生成密匙 String log = "更改密码"; oldPW = des.getEncString(oldPW); if (!user.getPassword().equals(oldPW)) { error = String.format("更改[%s]密码失败,输入旧密码不正确!", user.getUserName()); LogRecordUtil.writeLog(userEntityInfo, "修改密码", "失败", error, LogType.General, user.getId()); return error; //throw new VCIError("120405", new String[] {"旧密码输入不正确!"}); } error = checkPasswordStrategyByUserId(idUser, newPW); if (!StringUtils.isEmpty(error)) { LogRecordUtil.writeLog(userEntityInfo, "修改密码", "失败", "更改用户密码:" + user.getUserName() + "; " + error, LogType.General, user.getId()); return error; } String desPwd = des.getEncString(newPW); rs = userService.chanageUserPassword(idUser, desPwd); if (!rs) { error = "修改用户密码失败"; LogRecordUtil.writeLog(userEntityInfo, "修改密码", "失败", "更改用户密码:%s" + user.getUserName() +"; " + error, LogType.General, user.getId()); return error; } user.setPassword(desPwd); UserCacheUtil.getInstance().setObject(user); log = String.format("更改用户密码:%s", user.getUserName()); LogRecordUtil.writeLog(userEntityInfo, "修改密码", "成功", log, LogType.General, user.getId()); } catch (VCIError e) { throw e; } catch (Exception e) { throw new VCIError("120405", new String[0]); } return ""; } private String checkPasswordStrategy(PasswordStrategyInfo psi, String pw) throws VCIError { //int cts = psi.charTypes; long temp = psi.requiredType; long cts = temp & 0x0000ffff; long pasLen = psi.passwordLen; //最小长度 long pasMaxLen = psi.passwordMaxLen;//最大长度 //int requiredType = psi.requiredType; // 必填种类 long requiredType = (temp >> 16) & 0x0000ffff; // 必填种类 String names= ""; if ((cts & 0x01) == 0x01) { names += "数字,"; } if ((cts & 0x02) == 0x02) { names += "小写字母,"; } if ((cts & 0x04) == 0x04) { names += "大写字母,"; } if ((cts & 0x08) == 0x08) { names += "符号,"; } if (names.length() > 1) names = names.substring(0, names.length() - 1); String error = "密码必须中必须含有【"+names+"】中的【"+requiredType+"】种密码组合方式,且密码长度必须在【" + pasLen + "-" + pasMaxLen + "】范围内。"; if (pw.length() < psi.passwordLen || pw.length() > psi.passwordMaxLen) { return error; } // 校验密码长度是否符合密码策略的最小长度 if(pw.length() < pasLen){ error = "密码长度不能小于"+pasLen+",且密码必须包含‘"+names+"’中的"+requiredType+"种组合! 请重新输入密码!"; return error; } // 校验密码长度是否符合密码策略的最大长度 if(pw.length() > pasMaxLen){ error = "密码长度不能大于"+pasMaxLen+",且密码必须包含‘"+names+"’中的"+requiredType+"种组合! 请重新输入密码!"; return error; } // 校验密码包含的字符是否符合密码策略限定的字符类型 String symbol = "[ _`~!@#$%^&*()-+={[}]|\\'\":;,.<>/?"; int[] types = new int[4]; types[0] = 0; types[1] = 0; types[2] = 0; types[3] = 0; boolean coincident = true; for (int i = 0 ; i < pw.length() ;i ++){ char c = pw.charAt(i); if (Character.isDigit(c)) { if ((cts & 0x01) != 0x01) { coincident = false; break; } else { types[0] = 1; } } else if (Character.isLowerCase(c)) { if ((cts & 0x02) != 0x02) { coincident = false; break; } else { types[1] = 1; } } else if (Character.isUpperCase(c)) { if ((cts & 0x04) != 0x04) { coincident = false; break; } else { types[2] = 1; } } else if (symbol.indexOf(c) > -1) { if ((cts & 0x08) != 0x08) { coincident = false; break; } else { types[3] = 1; } } } // 校验密码包含的字符种类是否符合密码策略要求的包含字符种类数 int typeCount = 0; for (int i : types) { if (i == 1) typeCount++; } if (typeCount < requiredType) { error = "密码必须包含["+names+"]中的"+requiredType+"种类型,请重新输入密码!"; return error; } if (!coincident){ error = "您输入的密码不正确,密码必须中必须含有‘"+names+"’中的"+requiredType+"种密码组合方式,\n" + "或密码组合方式取值范围中不含有您输入的字符,请确认!"; return error; } return ""; } /** *

* Description:删除部门 *

* * @author wangxl * @time 2012-5-10 * @param id * @param userEntityInfo * @return * @throws VCIError */ public boolean deleteDepartment(String[] id, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; // List list = new ArrayList(); // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { DepartmentService departmentService = new DepartmentService(); UserEntityDelegate.setUserEntityToService(departmentService, userEntityInfo); int size = id.length; LinkedHashMap map = new LinkedHashMap(); for (int i = 0; i < size; i++) { Department department = departmentService.selectDepartmentById(id[i]); map.put(department.getLogInfo(), department.getId()); // list = departmentService.deleteDepartment(id[i]); DeptCacheUtil.getInstance().delObject(id[i]); } Iterator it = map.keySet().iterator(); while (it.hasNext()) { String deptId = it.next(); LogRecordUtil.writeLog(userEntityInfo, "删除", "成功", deptId, LogType.General, map.get(deptId)); } } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("120108", new String[0]); } return rs; } public boolean updateDeptParentId(String id, String parentId, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { DepartmentService departmentService = new DepartmentService(); UserEntityDelegate.setUserEntityToService(departmentService, userEntityInfo); DeptInfo dept = OrgCacheProvider.getDepartment(parentId); dept.parentId = parentId; rs = departmentService.updateDeptParentId(id, parentId); DeptCacheUtil.getInstance().setObject(dept); if (rs) { LogRecordUtil.writeLog(userEntityInfo, "更新", "成功", parentId, LogType.General, id); } } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("120110", new String[0]); } return rs; } /** *

* Description: 删除角色 *

* * @author wangxl * @time 2012-5-10 * @param id * @param userEntityInfo * @return * @throws VCIError */ public boolean deleteRole(String[] ids, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { RoleService roleService = new RoleService(); UserEntityDelegate.setUserEntityToService(roleService, userEntityInfo); LinkedHashMap map = new LinkedHashMap(); for (String id : ids) { Role role = roleService.selectRole(id); map.put(role.getId(), role.getLogInfo()); } rs = roleService.deleteRoleByMQL(ids); Iterator it = map.keySet().iterator(); while (it.hasNext()) { String id = it.next(); RoleCacheUtil.getInstance().delObject(id); LogRecordUtil.writeLog(userEntityInfo, "删除", "成功", map.get(id), LogType.General, id); } } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("120303", new String[0]); } return rs; } /** *

* Description: 删除人员 *

* * @author wangxl * @time 2012-5-10 * @param id * @param userEntityInfo * @return * @throws VCIError */ public boolean deleteUser(String[] ids, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { UserService userService = new UserService(); UserEntityDelegate.setUserEntityToService(userService, userEntityInfo); int size = ids.length; LinkedHashMap map = new LinkedHashMap(); for (int i = 0; i < size; i++) { User user = (User) userService.getUserInfoList(ids[i]).get(0); map.put(user.getId(), user.getLogInfo()); rs = userService.deleteUser(ids[i]); UserCacheUtil.getInstance().delObjectById(ids[i]); userService.deleteRights(ids[i]); } Iterator it = map.keySet().iterator(); while (it.hasNext()) { String id = it.next(); LogRecordUtil.writeLog(userEntityInfo, "删除", "成功", map.get(id), LogType.General, id); } } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("120403", new String[0]); } return rs; } /** *

* Description: 停用/启用 *

* * @author wangxl * @time 2012-5-14 * @param id * @param flag * @param userEntityInfo * @return * @throws VCIError */ public boolean stopUsers(String[] id, boolean flag, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { UserService userService = new UserService(); UserEntityDelegate.setUserEntityToService(userService, userEntityInfo); int size = id.length; StringBuilder log = null; for (int i = 0; i < size; i++) { log = new StringBuilder(); log.append("用户名:"); User user = (User) userService.getUserInfoList(id[i]).get(0); log.append(user.getLogInfo()); rs = userService.stopUsers(id[i], flag); user.setStatus(flag ? (short)1 : (short)0); UserCacheUtil.getInstance().setObject(user); LogRecordUtil.writeLog(userEntityInfo, "停用、启用", rs ? "成功" : "失败", log.toString(), LogType.General, user.getId()); } } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("120412", new String[0]); } return rs; } /** *

* Description:根据部门ID获取人员 *

* * @author wangxl * @time 2012-5-11 * @param deptId * @return * @throws VCIError */ public UserInfo[] getUserByDeptId(String deptId) throws VCIError { List list = new ArrayList(); try { list = new UserService().getUserByDeptId(deptId); } catch (Exception e) { throw new VCIError("120411", new String[0]); } int size = list.size(); UserInfo[] userInfo = new UserInfo[size]; for (int i = 0; i < size; i++) { userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i)); } return userInfo; } /** * *

* 获取该型号下的型号总师: *

* * @time 2013-3-28 * @param modelId 型号ID * @return * @throws VCIError */ public UserInfo[] fetchUserInfoByModelId(String modelId) throws VCIError { List list = new ArrayList(); try { list = new UserService().fetchUserInfoByModelId(modelId); } catch (Exception e) { throw new VCIError("120411", new String[0]); } int size = list.size(); UserInfo[] userInfo = new UserInfo[size]; for (int i = 0; i < size; i++) { userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i)); } return userInfo; } /** * 通过型号获取型号总师 *

* Description: *

* * @author wangxl * @time 2013-3-30 * @param model * @return * @throws VCIError */ public UserInfo[] fetchUserInfoByModel(String model) throws VCIError { List list = new ArrayList(); try { list = new UserService().fetchUserInfoByModel(model); } catch (Exception e) { throw new VCIError("120411", new String[0]); } int size = list.size(); UserInfo[] userInfo = new UserInfo[size]; for (int i = 0; i < size; i++) { userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i)); } return userInfo; } public PasswordStrategyInfo[] fetchAllPasswordStrategy() throws VCIError { List list = new ArrayList(); try { list = new PasswordStrategyService().getPasswordStrategyList(); } catch (Exception e) { throw new VCIError("555555", new String[0]); } int size = list.size(); PasswordStrategyInfo[] infos = new PasswordStrategyInfo[size]; for (int i = 0; i < size; i++) { infos[i] = ObjectConvert.changePasswordStrategyToInfo(list.get(i)); } return infos; } public PasswordStrategyInfo[] fetchAllPasswordStrategy(int pageNo, int pageSize) throws VCIError { List list = new ArrayList(); try { list = new PasswordStrategyService().getPasswordStrategyList(pageNo, pageSize); } catch (Exception e) { throw new VCIError("555555", new String[0]); } int size = list.size(); PasswordStrategyInfo[] infos = new PasswordStrategyInfo[size]; for (int i = 0; i < size; i++) { infos[i] = ObjectConvert.changePasswordStrategyToInfo(list.get(i)); } return infos; } public int getPasswordStrategyTotal() throws VCIError { int count = 0; try { count = new PasswordStrategyService().getPasswordStrategyTotal(); } catch (Exception e) { throw new VCIError("555572", new String[0]); } return count; } public boolean savePasswordStrategy(PasswordStrategyInfo info, //String[] combinationIds, UserEntityInfo userEntityInfo) throws VCIError { boolean res = false; // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { PasswordStrategyService srv = new PasswordStrategyService(); UserEntityDelegate.setUserEntityToService(srv, userEntityInfo); PasswordStrategy passwordStrategy = ObjectConvert.changePassStrategyInfoToEntity(info); res = srv.savePasswordStrategy(passwordStrategy); LogRecordUtil.writeLog(userEntityInfo, "添加", "成功", passwordStrategy.getLogInfo(), LogType.General, passwordStrategy.getId()); } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("555556", new String[0]); } return res; } public boolean editPasswordStrategy(PasswordStrategyInfo info, UserEntityInfo userEntityInfo) throws VCIError { boolean res = true; // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { PasswordStrategyService srv = new PasswordStrategyService(); UserEntityDelegate.setUserEntityToService(srv, userEntityInfo); PasswordStrategy passwordStrategy = ObjectConvert.changePassStrategyInfoToEntity(info); PasswordStrategy passwordStrategyBefore = (PasswordStrategy) srv .getPasswordObjById(passwordStrategy.getId()).get(0); StringBuilder log = new StringBuilder(); log.append("更新前:" + passwordStrategyBefore.getLogInfo()); log.append(" 更新后:" + passwordStrategy.getLogInfo()); res = srv.updatePasswordStrategy(passwordStrategy); LogRecordUtil.writeLog(userEntityInfo, "更新", "成功", log.toString(), LogType.General, passwordStrategyBefore.getId()); } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("555557", new String[0]); } return res; } public boolean deletePasswordStrategy(String[] ids, UserEntityInfo userEntityInfo) throws VCIError { boolean res = true; // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { PasswordStrategyService srv = new PasswordStrategyService(); UserEntityDelegate.setUserEntityToService(srv, userEntityInfo); LinkedHashMap map = new LinkedHashMap(); for (String id : ids) { PasswordStrategy pass = (PasswordStrategy) srv.getPasswordObjById(id).get(0); map.put(pass.getLogInfo(), pass.getId()); res = srv.deletePasswordStrategyById(id); } Iterator it = map.keySet().iterator(); while (it.hasNext()) { String logKey = it.next(); LogRecordUtil.writeLog(userEntityInfo, "删除", "成功", logKey, LogType.General, map.get(logKey)); } } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("555558", new String[0]); } return res; } public int checkPasswordStrategyIsquotedCount(String id) throws VCIError { int count = 0; try { count = new PasswordStrategyService().checkPasswordStrategyIsquotedCount(id); } catch (Exception e) { throw new VCIError("555565", new String[0]); } return count; } public PasswordStrategyInfo fetchPasswordStrategyByUserId(String userId) throws VCIError { PasswordStrategyInfo info = new PasswordStrategyInfo(); PasswordStrategy entity; try { entity = new PasswordStrategyService().getPasswordObjByUserId(userId); } catch (Exception e) { throw new VCIError("555555", new String[0]); } if (entity != null) { info = ObjectConvert.changePasswordStrategyToInfo(entity); } return info; } public boolean saveUserPasswordStrateg(String[] userIds, String passwordStrategId, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { UserService userService = new UserService(); PasswordStrategyService srv = new PasswordStrategyService(); UserEntityDelegate.setUserEntityToService(userService, userEntityInfo); List list = srv.getPasswordObjById(passwordStrategId); PasswordStrategy passwordStrategy = (PasswordStrategy) list.get(0); StringBuilder log = null; for (String userId : userIds) { log = new StringBuilder(); log.append("用户名:"); User user = (User) userService.getUserInfoList(userId).get(0); log.append("[" + user.getUserName() + "]"); rs = userService.saveUserPasswordStrateg(userId, passwordStrategId); log.append("->"); log.append(passwordStrategy.getLogInfo()); LogRecordUtil.writeLog(userEntityInfo, "为成员分配密码策略", "成功", log.toString(), LogType.General, userId + "密码策略ID:" + passwordStrategId); } } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("555567", new String[0]); } return rs; } public UserLogonInfo fetchUserLogonObj(String userId) throws VCIError { UserLogonInfo res = new UserLogonInfo(); UserLogon userLogon = null; try { UserService userSrv = new UserService(); userLogon = userSrv.getUserLogonObj(userId); if (userLogon == null) { res = new UserLogonInfo(); res.pluserOid = userId; res.plWrongNum = 0; //SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.fff");// 设置日期格式 res.plLogonTime = System.currentTimeMillis(); } else { res = ObjectConvert.changeUserLogonToUserLogonInfo(userLogon); } } catch (Exception ex) { //e.printStackTrace(); ServerWithLog4j.logger.error(ex); throw new VCIError("555568", new String[0]); } return res; } public long getSystemTime() throws VCIError { long sysTime = 0; try { UserService userSrv = new UserService(); sysTime = userSrv.getSystemTime(); } catch (Exception ex) { //e.printStackTrace(); ServerWithLog4j.logger.error(ex); throw new VCIError("555569", new String[0]); } return sysTime; } public void updateLogonInfo(String userId, boolean flag) throws VCIError { try { UserService userSrv = new UserService(); userSrv.updateLogonInfo(userId, flag); } catch (Exception ex) { //e.printStackTrace(); ServerWithLog4j.logger.error(ex); throw new VCIError("555570", new String[0]); } } public void deblock(String[] ids, UserEntityInfo userEntityInfo) throws VCIError { // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { UserService userSrv = new UserService(); UserEntityDelegate.setUserEntityToService(userSrv, userEntityInfo); userSrv.deblock(ids); for (String userId : ids) { User user = (User) userSrv.getUserObjectByoid(userId); // LogRecordUtil.writeLog(userEntity, "账户解锁", "["+user.getLogInfo()+"]", // LogType.General, userId); // add by caill 2016.9.13 LogRecordUtil.writeLog(userEntityInfo, "解锁用户", "解锁成功", "[" + user.getLogInfo() + "]", LogType.UnlockUser, userId); } } catch (Exception ex) { //e.printStackTrace(); ServerWithLog4j.logger.error(ex); throw new VCIError("555571", new String[0]); } } // /** // * 简单记录系统登入、登出日�? // *

// * Description: // *

// * // * @author wangxl // * @time 2012-12-27 // * @param message // * @param userEntityInfo // * @throws VCIError // */ // public void savelog(String message, UserEntityInfo userEntityInfo) throws VCIError { // userEntityInfo.modules = "登录模块";// add by liujw // // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); // User user = ObjectConvert.changeUserInfoToUser(fetchUserInfoByName(userEntity.getUserName())); // LogRecordUtil.writeLog(userEntityInfo, message, "登录成功", message, // "登入".equals(message) ? LogType.Login : LogType.Logout, user.getId()); // } // // public void saveLogV2(String result, String message, String type, int logTypeIntVal, String dataObjOid, // UserEntityInfo userEntityInfo) throws VCIError { // // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); // LogType logType = LogType.getByIntVal(logTypeIntVal); // LogRecordUtil.writeLog(userEntityInfo, type, result, message, logType, dataObjOid); // } // // public void savelogfail(String message, UserEntityInfo userEntityInfo) throws VCIError { // userEntityInfo.modules = "登录模块"; // // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); // User user = ObjectConvert.changeUserInfoToUser(fetchUserInfoByName(userEntity.getUserName())); // LogRecordUtil.writeLog(userEntityInfo, "登入", "登录失败", message, LogType.Login, user.getId()); // } // // // add by caill start 2016.9.13简单记录用户被锁定的日志 // public void blocklog(String userId, UserEntityInfo userEntityInfo) throws VCIError { // // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); // User user = ObjectConvert.changeUserInfoToUser(fetchUserInfoByName(userEntity.getUserName())); // LogRecordUtil.writeLog(userEntityInfo, LogType.LockUser.getLabel(), "用户锁定", // "[" + user.getLogInfo() + "]" + "在连续输入多次密码错误后导致账户被锁定", LogType.LockUser, userId); // } /** * 获取所有密码组合方�? *

* Description: *

* * @author wangxl * @time 2013-1-3 * @return * @throws VCIError */ @SuppressWarnings("unchecked") public CombinationInfo[] fetchAllCombinations() throws VCIError { List list = null; try { list = new CombinationService().getAllList(); } catch (Exception e) { throw new VCIError("120501", new String[0]); } int size = list.size(); CombinationInfo[] info = new CombinationInfo[size]; for (int i = 0; i < size; i++) { info[i] = changeCombinationToInfo(list.get(i)); } return info; } /** * 分页查询组合方式 *

* Description: *

* * @author llb * @time 2013-1-4 * @return * @throws VCIError */ @SuppressWarnings("unchecked") public CombinationInfo[] fetchCombinationsToPage(int pageIndex, int pageSize) throws VCIError { List list = null; try { list = new CombinationService().fetchCombinationsToPage(pageIndex, pageSize); } catch (Exception e) { throw new VCIError("120501", new String[0]); } int size = list.size(); CombinationInfo[] info = new CombinationInfo[size]; for (int i = 0; i < size; i++) { info[i] = changeCombinationToInfo(list.get(i)); } return info; } public String saveCombination(CombinationInfo info, UserEntityInfo userEntityInfo) throws VCIError { Combination comb = changeCombinationInfoToCombination(info); String id = ObjectUtility.getNewObjectID36(); comb.setId(id); // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { CombinationService service = new CombinationService(); UserEntityDelegate.setUserEntityToService(service, userEntityInfo); service.saveCombination(comb); LogRecordUtil.writeLog(userEntityInfo, "添加", "成功", comb.getLogInfo(), LogType.General, comb.getId()); } catch (Exception e) { throw new VCIError("120502", new String[0]); } return id; } public boolean updateCombination(CombinationInfo info, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; Combination comb = changeCombinationInfoToCombination(info); // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { CombinationService service = new CombinationService(); UserEntityDelegate.setUserEntityToService(service, userEntityInfo); Combination combinationBefore = (Combination) service.getCombinationsObjById(comb.getId()).get(0); rs = service.updateCombination(comb); StringBuilder log = new StringBuilder(); log.append("更新前:" + combinationBefore.getLogInfo()); log.append(" 更新后:" + comb.getLogInfo()); LogRecordUtil.writeLog(userEntityInfo, "更新", "成功", log.toString(), LogType.General, comb.getId()); } catch (Exception e) { throw new VCIError("120503", new String[0]); } return rs; } public boolean deleteCombination(String[] id, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { CombinationService service = new CombinationService(); UserEntityDelegate.setUserEntityToService(service, userEntityInfo); LinkedHashMap map = new LinkedHashMap(); for (String Id : id) { Combination combin = (Combination) service.getCombinationsObjById(Id).get(0); map.put(combin.getLogInfo(), combin.getId()); } rs = service.deleteCombinationByMQL(id); Iterator it = map.keySet().iterator(); while (it.hasNext()) { String logKey = it.next(); LogRecordUtil.writeLog(userEntityInfo, "删除", "成功", logKey, LogType.General, map.get(logKey)); } } catch (Exception e) { throw new VCIError("120504", new String[0]); } return rs; } @SuppressWarnings("unchecked") public CombinationValueInfo[] fetchCombinationValuesByParentId(String parentId) throws VCIError { List list = null; try { list = new CombinationValueService().getCombinationValuesByParentId(parentId); } catch (Exception e) { throw new VCIError("120505", new String[0]); } int size = list.size(); CombinationValueInfo[] info = new CombinationValueInfo[size]; for (int i = 0; i < size; i++) { info[i] = changeCombinationValueToInfo(list.get(i)); } return info; } @SuppressWarnings("unchecked") public String saveCombinationValue(CombinationValueInfo[] valueInfos, UserEntityInfo userEntityInfo) throws VCIError { // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); CombinationValueService service = new CombinationValueService(); int length = valueInfos.length; for (int i = 0; i < length; i++) { List combVal = service.getCombValByClsfIdAndVal(valueInfos[i].parentId, valueInfos[i].value); if (combVal.size() > 0) { throw new VCIError("120507 ", new String[] { "" }); } } try { CombinationValue[] combinationValues = new CombinationValue[length]; for (int i = 0; i < length; i++) { String id = ObjectUtility.getNewObjectID36(); combinationValues[i] = changeCombinationValueInfoToVal(valueInfos[i]); combinationValues[i].setId(id); } UserEntityDelegate.setUserEntityToService(service, userEntityInfo); service.saveCombinationValue(combinationValues); for (CombinationValue value : combinationValues) { LogRecordUtil.writeLog(userEntityInfo, "添加", "成功", value.getLogInfo(), LogType.General, value.getId()); } ; } catch (Exception e) { throw new VCIError("120506", new String[0]); } return ""; } public boolean updateCombinationValue(CombinationValueInfo valueInfo, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; CombinationValue combVal = changeCombinationValueInfoToVal(valueInfo); // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); CombinationValueService service = new CombinationValueService(); // add by liujw List combValSame = service.getCombValByClsfIdAndVal(valueInfo.parentId, valueInfo.value); if (combValSame.size() > 0) { throw new VCIError("120507 ", new String[] { "" }); } try { UserEntityDelegate.setUserEntityToService(service, userEntityInfo); CombinationValue combinationValueBefroe = (CombinationValue) service .getCombinationValueObjById(combVal.getId()).get(0); StringBuilder log = new StringBuilder(); log.append("更新前:" + combinationValueBefroe.getLogInfo()); log.append(" 更新后:" + combVal.getLogInfo()); rs = service.updateCombinationValue(combVal); LogRecordUtil.writeLog(userEntityInfo, "更新", "成功", log.toString(), LogType.General, combVal.getId()); } catch (Exception e) { throw new VCIError("120508", new String[0]); } return rs; } public boolean deletCombinationValues(String[] id, UserEntityInfo userEntityInfo) throws VCIError { boolean rs = true; // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); try { CombinationValueService service = new CombinationValueService(); CombinationService combinService = new CombinationService(); Combination combin = null; UserEntityDelegate.setUserEntityToService(service, userEntityInfo); StringBuilder log = new StringBuilder(); StringBuilder combinIds = new StringBuilder(); StringBuilder valuesIds = new StringBuilder(); combinIds.append("密码组合方式ID:"); valuesIds.append("值ID: "); for (String ID : id) { List list = service.getCombinationValueObjById(ID); if (list.size() > 0) { CombinationValue value = (CombinationValue) list.get(0); if (combin == null) { combin = (Combination) combinService.getCombinationsObjById(value.getParentId()).get(0); log.append(combin.getLogInfo() + "->"); combinIds.append(combin.getId()); } log.append(value.getLogInfo() + " "); valuesIds.append(value.getId() + " "); } } rs = service.deleteCombinationValueByMQL(id); LogRecordUtil.writeLog(userEntityInfo, "删除", "成功", log.toString(), LogType.General, combinIds.toString() + valuesIds.toString()); } catch (Exception e) { e.printStackTrace(); throw new VCIError("120509", new String[0]); } return rs; } @SuppressWarnings("unchecked") public CombinationInfo[] fetchCombinationsByPstId(String pstId) throws VCIError { List list = null; try { list = new CombinationService().fetchCombinationsByPstId(pstId); } catch (Exception e) { throw new VCIError("120501", new String[0]); } int size = list.size(); CombinationInfo[] info = new CombinationInfo[size]; for (int i = 0; i < size; i++) { info[i] = changeCombinationToInfo(list.get(i)); } return info; } /** * 验证密码组合方式是否被密码策略引�? *

* Description: *

* * @author wangxl * @time 2013-1-4 * @param id * @return * @throws VCIError */ public int checkCombinationIsquotedCount(String combinationd) throws VCIError { int count = 0; try { count = new CombinationService().checkCombinationIsquotedCount(combinationd); } catch (Exception e) { throw new VCIError("120510", new String[0]); } return count; } private CombinationValueInfo changeCombinationValueToInfo(CombinationValue combValue) { CombinationValueInfo info = new CombinationValueInfo(); info.id = combValue.getId(); info.parentId = combValue.getParentId(); info.value = combValue.getValue(); return info; } private CombinationValue changeCombinationValueInfoToVal(CombinationValueInfo info) { CombinationValue val = new CombinationValue(); val.setId(info.id == "" ? null : info.id); val.setParentId(info.parentId == "" ? null : info.parentId); val.setValue(info.value == "" ? null : info.value); return val; } private CombinationInfo changeCombinationToInfo(Combination comb) { CombinationInfo info = new CombinationInfo(); info.id = comb.getId(); info.name = comb.getName() == null ? "" : comb.getName(); info.description = comb.getDesc() == null ? "" : comb.getDesc(); info.createTime = comb.getCreateTime() == null ? System.currentTimeMillis() : comb.getCreateTime().getTime(); info.createUser = comb.getCreateUser() == null ? "" : comb.getCreateUser(); info.updateTime = comb.getUpdateTime() == null ? System.currentTimeMillis() : comb.getUpdateTime().getTime(); info.updateUser = comb.getUpdateUser() == null ? "" : comb.getUpdateUser(); info.grantor = comb.getGrantor() == null ? "" : comb.getGrantor(); return info; } public Combination changeCombinationInfoToCombination(CombinationInfo info) { Combination comb = new Combination(); comb.setId(info.id == "" ? null : info.id); comb.setDesc(info.description == "" ? null : info.description); comb.setName(info.name == "" ? null : info.name); comb.setCreateTime(info.createTime == 0 ? new java.sql.Timestamp(System.currentTimeMillis()) : new java.sql.Timestamp(info.createTime)); comb.setCreateUser(info.createUser == "" ? null : info.createUser); comb.setUpdateTime(info.updateTime == 0 ? new java.sql.Timestamp(System.currentTimeMillis()) : new java.sql.Timestamp(info.createTime)); comb.setUpdateUser(info.updateUser == "" ? null : info.updateUser); comb.setGrantor(info.grantor == "" ? null : info.grantor); return comb; } public DeptInfo[] changeDepartmentToDepartmentInfos(List list) { int size = list.size(); DeptInfo[] departmentInfo = new DeptInfo[size]; for (int i = 0; i < size; i++) { departmentInfo[i] = ObjectConvert.changeDepartmentToDepartmentInfo((Department)list.get(i)); } return departmentInfo; } /** *

* Description: 根据部门唯一编码和部门名称获取部门信�?/p> * * @author sunbo * @time 2013-3-26 * @param 部门编码 * @param 部门名称 * @return * @throws VCIError */ public DeptInfo fetchDeptByNum(String num) throws VCIError { List list = null; try { list = new DepartmentService().fetchDeptByNum(num); } catch (Exception e) { throw new VCIError("120101", new String[0]); } int size = list.size(); DeptInfo deptInfo = new DeptInfo(); if (size > 0) { deptInfo = ObjectConvert.changeDepartmentToDepartmentInfo(list.get(0)); } return deptInfo; } /** *

* Description: 根据文件柜和类型查找人员 *

* * @author wangxl * @time 2012-5-10 * @param roleId * @param type * @return * @throws VCIError */ public UserInfo[] fetchUserInfoByPvolumeId(String pvolumeId, int type) throws VCIError { List list = null; try { list = new UserService().fetchUserInfoByPvolumeId(pvolumeId, type); } catch (Exception e) { throw new VCIError("120401", new String[0]); } int size = list.size(); UserInfo[] userInfo = new UserInfo[size]; for (int i = 0; i < size; i++) { userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i)); } return userInfo; } static class DeptNameComparator implements Comparator { private final Collator collator = Collator.getInstance(); @Override public int compare(Object arg0, Object arg1) { Department di1 = (Department) arg0; Department di2 = (Department) arg1; return collator.compare(di1.getName(), di2.getName()); } } /** * 简单记录一般操作日志 * * @author liyp * @time 2016-9-27 * @param message * @param userEntityInfo * @throws VCIError */ public void savelogGeneralOperation(String result, String message, UserEntityInfo userEntityInfo, String dataId, String plType) throws VCIError { // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo); LogRecordUtil.writeLog(userEntityInfo, plType, result, message, LogType.General, dataId); } /**** * 查询条件 * * @param otherFiterString * @return * @throws VCIError */ public DeptInfo[] fetchDepartmentInfoByIds(String[] ids) throws VCIError { return OrgCacheProvider.getDepts(ids); // List list = null; // try { // list = new DepartmentService().fetchDepartmentInfoByIds(otherFiterString); // } catch (Exception e) { // throw new VCIError("120107", new String[0]); // } // return changeDepartmentToDepartmentInfos(list); } public DeptInfo[] fetchChildrenDeptByParentOid(String prtoid, boolean iscontains, String otherFiterString) throws VCIError { List list = null; try { list = new DepartmentService().fetchChildrenDeptByParentOid(prtoid, iscontains, otherFiterString); } catch (Exception e) { throw new VCIError("120106", new String[0]); } return changeDepartmentToDepartmentInfos(list); } public DeptInfo[] gridDeptDataGrids(String filter, int pageNo, int pageSize) throws VCIError { List list = null; try { list = new DepartmentService().gridDeptDataGrids(filter, pageNo, pageSize); } catch (Exception e) { throw new VCIError("120107", new String[0]); } return changeDepartmentToDepartmentInfos(list); } public int gridDeptDataGridsCount(String filter) throws VCIError { int count = 0; try { count = new DepartmentService().gridDeptDataGridsCount(filter); } catch (Exception e) { throw new VCIError("120307", new String[0]); } return count; } public RoleInfo[] queryRoleInfos(String filter, int pageNo, int pageSize) throws VCIError { List list = null; try { list = new RoleService().queryRoleInfos(filter, pageNo, pageSize); } catch (Exception e) { throw new VCIError("120301", new String[0]); } int size = list.size(); RoleInfo[] roleInfo = new RoleInfo[size]; for (int i = 0; i < size; i++) { roleInfo[i] = ObjectConvert.changeRoleToRoleInfo(list.get(i)); } return roleInfo; } public int queryRoleInfosCount(String filter) throws VCIError { int count = 0; try { count = new RoleService().queryRoleInfosCount(filter); } catch (Exception e) { throw new VCIError("120307", new String[0]); } return count; } public UserInfo[] fetchUserInfoByFilterString(String filterString, int pageNo, int pageSize) throws VCIError { // TODO Auto-generated method stub List list = null; try { list = new UserService().fetchUserInfoByFilterString(filterString, pageNo, pageSize); int size = list.size(); UserInfo[] userInfos = new UserInfo[size]; for (int i = 0; i < size; i++) { userInfos[i] = ObjectConvert.changeUserToUserInfo(list.get(i)); } return userInfos; } catch (Exception e) { throw new VCIError("120401", new String[0]); } } public int fetchUserInfoByFilterStringCount(String filterString) throws VCIError { try { return new UserService().fetchUserInfoByFilterStringCount(filterString); } catch (Exception e) { throw new VCIError("120401", new String[0]); } } public UserInfo[] fetchUserInfosByFilterStringsql(String filterString) throws VCIError { List list = null; try { list = new UserService().fetchUserInfosByFilterStringsql(filterString); int size = list.size(); UserInfo[] userInfos = new UserInfo[size]; for (int i = 0; i < size; i++) { userInfos[i] = ObjectConvert.changeUserToUserInfo(list.get(i)); } return userInfos; } catch (Exception e) { throw new VCIError("120401", new String[0]); } } public UserInfo[] fetchUserInfoByNames(String[] userNames) throws VCIError { return OrgCacheProvider.getUsers(userNames); // List list = null; // try { // list = new UserService().fetchUserInfoByNames(userNames); // int size = list.size(); // UserInfo[] userInfos = new UserInfo[size]; // for (int i = 0; i < size; i++) { // userInfos[i] = ObjectConvert.changeUserToUserInfo(list.get(i)); // } // return userInfos; // } catch (Exception e) { // throw new VCIError("120401", new String[0]); // } } public UserInfo getUserObjectByoid(String userOid) throws VCIError { UserInfo res = new UserInfo(); try { User user = new UserService().getUserObjectByoid(userOid); if (user == null) { user = new User(); } res = ObjectConvert.changeUserToUserInfo(user); } catch (Exception e) { throw new VCIError("120401", new String[0]); } return res; } public UserInfo[] getUserObjectByoids(String[] userOids) throws VCIError { List list = null; try { list = new UserService().getUserObjectByoids(userOids); int size = list.size(); UserInfo[] userInfos = new UserInfo[size]; for (int i = 0; i < size; i++) { userInfos[i] = ObjectConvert.changeUserToUserInfo(list.get(i)); } return userInfos; } catch (Exception e) { throw new VCIError("120401", new String[0]); } } public String getSessionInfo(String token) { VciSessionInfoDAOImpl sessionDao = new VciSessionInfoDAOImpl(); VciSessionInfoDO sessionInfoDO = sessionDao.getById(token); if (sessionInfoDO != null) { return sessionInfoDO.getJsonString(); } return ""; } public UserInfo[] fetchNormalUserInfoByConditionUnited(String searchName, String searchUserName, String deptId, String roleId, String userName, int pageNo, int pageSize) throws VCIError { List list = null; try { list = new UserService().getUserListByConditionUnited(searchName, searchUserName, deptId, roleId, userName, pageNo, pageSize, true); } catch (Exception e) { throw new VCIError("120401", new String[0]); } int size = list.size(); UserInfo[] userInfo = new UserInfo[size]; for (int i = 0; i < size; i++) { userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i)); } return userInfo; } public int getNormalUserTotalByCondition(String searchName, String searchUserName, String deptId, String roleId, String userName) throws VCIError { int total = 0; try { boolean bSuper = isSuperUser(userName); //System.out.print("=============bSuper=" + bSuper); total = new UserService().getUserTotalByCondition(searchName, searchUserName, deptId, roleId, userName, !bSuper); } catch (Exception e) { throw new VCIError("120413", new String[0]); } return total; } public UserInfo[] fetchNormalUserInfoByCondition(String searchName, String searchUserName, String deptId, String roleId, String userName, int pageNo, int pageSize) throws VCIError { List list = null; try { boolean bSuper = isSuperUser(userName); list = new UserService().getUserListByCondition(searchName, searchUserName, deptId, roleId, userName, pageNo, pageSize, !bSuper); } catch (Exception e) { throw new VCIError("120401", new String[0]); } int size = list.size(); UserInfo[] userInfo = new UserInfo[size]; for (int i = 0; i < size; i++) { userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i)); } return userInfo; } }