1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
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;
    }
    
    /***
     * <p>
     * Description:部门从应用对象到corba对象
     * </p>
     * 
     * @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;
    }
}