package com.vci.server.framework.utils; import java.text.ParseException; import java.text.SimpleDateFormat; import com.vci.common.objects.UserEntity; 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.server.common.ThreeDES; import com.vci.server.framework.systemConfig.stafforgmanage.dept.Department; import com.vci.server.framework.systemConfig.stafforgmanage.passwordStrategy.PasswordStrategy; import com.vci.server.framework.systemConfig.stafforgmanage.role.Role; import com.vci.server.framework.systemConfig.stafforgmanage.user.User; import com.vci.server.framework.systemConfig.stafforgmanage.user.UserLogon; public final class ObjectConvert { public static UserInfo changeUserToUserInfo(User user) { UserInfo userInfo = new UserInfo(); userInfo.id = user.getId() == null ? "" : user.getId(); userInfo.userName = user.getUserName() == null ? "" : user.getUserName(); // 密码解密 String desPwd = user.getPassword() == null ? "" : user.getPassword(); ThreeDES des = new ThreeDES();// 实例化一个对�? des.getKey("daliantan0v0");// 生成密匙 String pwd = des.getDesString(desPwd);// 把String 类型的密文解�? userInfo.pwd = pwd; userInfo.email = user.getEmail() == null ? "" : user.getEmail(); userInfo.trueName = user.getTrueName() == null ? "" : user.getTrueName(); userInfo.specialties = user.getSpecialties() == null ? "" : user.getSpecialties(); userInfo.desc = user.getDesc() == null ? "" : user.getDesc(); userInfo.userType = user.getUserType(); userInfo.status = user.getStatus(); userInfo.createTime = user.getCreateTime() == null ? 0 : user.getCreateTime().getTime(); userInfo.createUser = user.getCreateUser() == null ? "" : user.getCreateUser(); userInfo.updateTime = user.getUpdateTime() == null ? 0 : user.getUpdateTime().getTime(); userInfo.updateUser = user.getUpdateUser() == null ? "" : user.getUpdateUser(); userInfo.pwdUpdateTime = user.getPwdUpdateTime() == null ? 0 : user.getPwdUpdateTime().getTime(); userInfo.grantor = user.getGrantor() == null ? "" : user.getGrantor(); userInfo.secretGrade = user.getSecretGrade() == null ? "" : user.getSecretGrade(); userInfo.isDeptLeader = user.getIsDeptLeader() == null ? "0" : user.getIsDeptLeader(); return userInfo; } public static Department changeDepartmentInfoToDepartment(DeptInfo departmentInfo) { Department department = new Department(); department.setId(departmentInfo.id == "" ? null : departmentInfo.id); department.setDesc(departmentInfo.description == "" ? null : departmentInfo.description); department.setName(departmentInfo.name == "" ? null : departmentInfo.name); department.setNum(departmentInfo.num == "" ? null : departmentInfo.num); department.setCode(departmentInfo.code == "" ? null : departmentInfo.code); department.setSpecialties(departmentInfo.specialties == null ? "" : departmentInfo.specialties); department.setStatus(departmentInfo.status == 0 ? 0 : departmentInfo.status); department.setParentId(departmentInfo.parentId == "" ? null : departmentInfo.parentId); department.setCreateTime( departmentInfo.createTime == 0 ? null : new java.sql.Timestamp(System.currentTimeMillis())); department.setCreateUser(departmentInfo.createUser == "" ? null : departmentInfo.createUser); department.setUpdateTime( departmentInfo.updateTime == 0 ? null : new java.sql.Timestamp(System.currentTimeMillis())); department.setUpdateUser(departmentInfo.updateUser == "" ? null : departmentInfo.updateUser); department.setGrantor(departmentInfo.grantor == "" ? null : departmentInfo.grantor); return department; } /*** *
* Description:部门从应用对象到corba对象 *
* * @param department * @return */ public static DeptInfo changeDepartmentToDepartmentInfo(Department department) { DeptInfo departmentInfo = new DeptInfo(); departmentInfo.id = department.getId(); departmentInfo.name = department.getName() == null ? "" : department.getName(); departmentInfo.num = department.getNum() == null ? "" : department.getNum(); departmentInfo.code = department.getCode() == null ? "" : department.getCode(); departmentInfo.specialties = department.getSpecialties() == null ? "" : department.getSpecialties(); departmentInfo.status = department.getStatus() == 0 ? 0 : department.getStatus(); departmentInfo.description = department.getDesc() == null ? "" : department.getDesc(); departmentInfo.parentId = department.getParentId() == null ? "" : department.getParentId(); departmentInfo.createTime = department.getCreateTime() == null ? 0 : department.getCreateTime().getTime(); departmentInfo.createUser = department.getCreateUser() == null ? "" : department.getCreateUser(); departmentInfo.updateTime = department.getUpdateTime() == null ? 0 : department.getUpdateTime().getTime(); departmentInfo.updateUser = department.getUpdateUser() == null ? "" : department.getUpdateUser(); departmentInfo.grantor = department.getGrantor() == null ? "" : department.getGrantor(); return departmentInfo; } public static Role changeRoleInfoToRole(RoleInfo roleInfo) { Role role = new Role(); role.setId(roleInfo.id == "" ? null : roleInfo.id); role.setDesc(roleInfo.description == "" ? null : roleInfo.description); role.setName(roleInfo.name == "" ? null : roleInfo.name); short a = roleInfo.type; if (a < 2) { a = (short)(a + 1); } role.setType(a); role.setCreateTime(roleInfo.createTime == 0 ? null : new java.sql.Timestamp(System.currentTimeMillis())); role.setCreateUser(roleInfo.createUser == "" ? null : roleInfo.createUser); role.setUpdateTime(roleInfo.updateTime == 0 ? null : new java.sql.Timestamp(System.currentTimeMillis())); role.setUpdateUser(roleInfo.updateUser == "" ? null : roleInfo.updateUser); role.setGrantor(roleInfo.grantor == "" ? null : roleInfo.grantor); return role; } public static RoleInfo changeRoleToRoleInfo(Role role) { RoleInfo roleInfo = new RoleInfo(); if (role != null) { roleInfo.id = role.getId(); roleInfo.name = role.getName() == null ? "" : role.getName(); roleInfo.description = role.getDesc() == null ? "" : role.getDesc(); roleInfo.type = role.getType(); roleInfo.createTime = role.getCreateTime() == null ? 0 : role.getCreateTime().getTime(); roleInfo.createUser = role.getCreateUser() == null ? "" : role.getCreateUser(); roleInfo.updateTime = role.getUpdateTime() == null ? 0 : role.getUpdateTime().getTime(); roleInfo.updateUser = role.getUpdateUser() == null ? "" : role.getUpdateUser(); roleInfo.grantor = role.getGrantor() == null ? "" : role.getGrantor(); } return roleInfo; } public static User changeUserInfoToUser(UserInfo userInfo) { User user = new User(); user.setId(userInfo.id == "" ? null : userInfo.id); user.setUserName(userInfo.userName == "" ? null : userInfo.userName); // 密码加密 String pwd = userInfo.pwd == "" ? null : userInfo.pwd; ThreeDES des = new ThreeDES();// 实例化一个对�? des.getKey("daliantan0v0");// 生成密匙 String desPwd = des.getEncString(pwd); user.setPassword(desPwd); user.setEmail(userInfo.email == "" ? null : userInfo.email); user.setTrueName(userInfo.trueName == "" ? null : userInfo.trueName); user.setSpecialties(userInfo.specialties == "" ? null : userInfo.specialties); user.setDesc(userInfo.desc == "" ? null : userInfo.desc); short a = userInfo.userType; if (a < 2) { a = (short)(a + 1); } user.setUserType(a); user.setStatus(userInfo.status); user.setCreateTime(userInfo.createTime == 0 ? null : new java.sql.Timestamp(System.currentTimeMillis())); user.setCreateUser(userInfo.createUser == "" ? null : userInfo.createUser); user.setUpdateTime(userInfo.updateTime == 0 ? null : new java.sql.Timestamp(System.currentTimeMillis())); user.setUpdateUser(userInfo.updateUser == "" ? null : userInfo.updateUser); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");// 设定格式 if (userInfo.pwdUpdateTime != 0) { // java.util.Date timeDate = dateFormat.parse(userInfo.pwdUpdateTime); // java.sql.Timestamp dateTime = new java.sql.Timestamp(timeDate.getTime());// Timestamp类型,timeDate.getTime()返回一个long�? user.setPwdUpdateTime(new java.sql.Timestamp(userInfo.pwdUpdateTime)); } user.setGrantor(userInfo.grantor == "" ? null : userInfo.grantor); user.setSecretGrade(userInfo.secretGrade); user.setIsDeptLeader(userInfo.isDeptLeader); return user; } public static PasswordStrategyInfo changePasswordStrategyToInfo(PasswordStrategy pwdStg) { PasswordStrategyInfo info = new PasswordStrategyInfo(); info.id = pwdStg.getId(); info.name = pwdStg.getName(); info.passwordLen = pwdStg.getPasswordLen(); info.passwordMaxLen = pwdStg.getPasswordMaxLen(); info.charTypes = pwdStg.getCharTypes(); info.requiredType = pwdStg.getRequiredType(); //info.requiredType = pwdStg.getRequiredType(); info.overdueDay = pwdStg.getOverdueDay(); info.remideDay = pwdStg.getRemideDay(); info.retryTime = pwdStg.getRetryTime(); info.lockTime = pwdStg.getLockTime(); info.isDefault = pwdStg.getIsDefault(); info.desc = pwdStg.getDesc() == null ? "" : pwdStg.getDesc(); info.createTime = pwdStg.getCreateTime().getTime(); info.createUser = pwdStg.getCreateUser(); info.updateTime = pwdStg.getUpdateTime().getTime(); info.updateUser = pwdStg.getUpdateUser(); info.grantor = pwdStg.getGrantor() == null ? "" : pwdStg.getGrantor(); return info; } public static PasswordStrategy changePassStrategyInfoToEntity(PasswordStrategyInfo info) { PasswordStrategy entity = new PasswordStrategy(); entity.setId(info.id); entity.setName(info.name); entity.setPasswordLen(info.passwordLen); entity.setPasswordMaxLen(info.passwordMaxLen); entity.setCharTypes(info.charTypes); entity.setRequiredType(info.requiredType); entity.setOverdueDay(info.overdueDay); entity.setRemideDay(info.remideDay); entity.setRetryTime(info.retryTime); entity.setLockTime(info.lockTime); entity.setDesc(info.desc); entity.setIsDefault(info.isDefault); entity.setCreateUser(info.createUser); entity.setCreateTime(new java.sql.Timestamp(System.currentTimeMillis())); entity.setUpdateUser(info.updateUser); entity.setUpdateTime(new java.sql.Timestamp(System.currentTimeMillis())); entity.setGrantor(info.grantor); return entity; } public static UserLogonInfo changeUserLogonToUserLogonInfo(UserLogon userLogon) { UserLogonInfo info = new UserLogonInfo(); if (userLogon != null) { info.pluserOid = userLogon.getPluserOid(); info.plLogonTime = userLogon.getPlLogonTime().getTime(); info.plWrongNum = userLogon.getPlWrongNum(); } return info; } public static UserEntity changeUserEntityInfoToUserEntity(UserEntityInfo info) { UserEntity entity = new UserEntity(); entity.setModule(info.modules); entity.setIp(info.ip); entity.setUserName(info.userName); return entity; } }