lxw
2020-07-11 9db52f2f2dd3665fe9da1ae5657e0167c3a34d40
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
package com.fgkj.actions;
 
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
 
import com.fgkj.dao.UinfDaoFactory;
import com.fgkj.dao.UtilityFactory;
import com.fgkj.dto.Batt_User_Permit;
import com.fgkj.dto.Battalarm_data;
import com.fgkj.dto.Page;
import com.fgkj.dto.ServiceModel;
import com.fgkj.dto.User_inf;
import com.fgkj.dto.User_log;
import com.fgkj.services.User_infService;
import com.fgkj.services.User_logService;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.opensymphony.xwork2.ActionSupport;
 
public class User_infAction extends ActionSupport{
    private User_infService service=new User_infService();
    private User_logService uservice=new User_logService();
    private Batt_User_Permit bup;
    private ServiceModel model;
    private User_inf uif;
    private String result;
    private String addjson;            //添加用户的用户json数组
    private String upjson;            //更新用户的用户json数组
    //添加用户
    public String add() {
        uif=ActionUtil.getGson("yyyy-MM-dd").fromJson(addjson, User_inf.class);
        uif.setUpassword(ActionUtil.EncryptionMD5(uif.getUpassword()).toString());
        model = service.add(uif);
        {
            String msg="添加新用户:"+uif.getUName();
            User_log ulog=UinfDaoFactory.CreateULog(UinfDaoFactory.Increase, msg);
            uservice.add(ulog);//将用户的操作记录下来
        }
        result = ActionUtil.tojson(model);
        return SUCCESS;
    }
    //修改用户信息
    public String update() {
        uif=ActionUtil.getGson("yyyy-MM-dd").fromJson(upjson, User_inf.class);
        model = service.update(uif);
        {
            String msg="修改"+uif.getUName()+"的用户信息";
            User_log ulog=UinfDaoFactory.CreateULog(UinfDaoFactory.Alter, msg);
            uservice.add(ulog);//将用户的操作记录下来
        }
        result = ActionUtil.tojson(model);
        return SUCCESS;
    }
    //删除用户信息
    public String delete() {
        model=new ServiceModel();
        if(upjson!=null && upjson.length()>0){
            Gson gson=new Gson();
            uif=gson.fromJson(upjson, User_inf.class);            
            model = service.delete(uif);
            {
                String msg="删除"+uif.getUName()+"的用户信息";
                User_log ulog=UinfDaoFactory.CreateULog(UinfDaoFactory.Delete, msg);
                uservice.add(ulog);//将用户的操作记录下来
            }
        }
        result = ActionUtil.tojson(model);
        return SUCCESS;
    }
 
    public String serchByCondition() {
        model = service.serchByCondition(uif);
        result = ActionUtil.tojson(model);
        //System.out.println(result);
        return SUCCESS;
    }
    //5.1查询所有员工信息
    public String searchAll() {
        if(bup==null){
            model=service.searchAll();
        }else{
            model = service.searchAll(bup);
        }
        result = ActionUtil.tojson(model);
        //System.out.println(result);
        return SUCCESS;
    }    
    //根据员工信息和员工编号去匹配合适的员工
    public String searchByNameOrId() {
        bup=ActionUtil.getGson("yyyy-MM-dd").fromJson(upjson, Batt_User_Permit.class);
        model = service.searchByNameOrId(bup);
        result = ActionUtil.tojson(model);
        return SUCCESS;
    }
    //重置用户密码
    public String resetPassword(){
        uif=ActionUtil.getGson("yyyy-MM-dd").fromJson(upjson, User_inf.class);
        model=service.resetPassword(uif);
        {
            String msg="重置"+uif.getUName()+"用户的密码";
            User_log ulog=UinfDaoFactory.CreateULog(UinfDaoFactory.Alter, msg);
            uservice.add(ulog);//将用户的操作记录下来
        }
        result = ActionUtil.tojson(model);
        return SUCCESS;
    }
 
    //根据用户的id查询用户所在的包机组
    public String serchByInfo(){
        //System.out.println(uif);
        ServiceModel model=service.serchByInfo(uif);
        result=ActionUtil.tojson(model);
        return SUCCESS;
    }
    
    //添加新的用户模板
    public String createNewUser(){
        User_inf uinf=UtilityFactory.CreateUinf();
        ServiceModel model=new ServiceModel();
        if(uinf!=null){
            model.setCode(1);
            model.setData(uinf);
        }
        result=ActionUtil.tojson(model);
        return SUCCESS;
    }
    
    
    //更新多个用户
    public String updateUser(){
        Gson gson=ActionUtil.getGson("yyyy-MM-dd");
        String msg="";
        model=new ServiceModel();
        if(addjson!=null && addjson.length()>0){
            List<User_inf> addlist=gson.fromJson(addjson, new TypeToken<List<User_inf>>(){}.getType());
            if(addlist!=null && addlist.size()>0){
                //System.out.println(addlist);
                model=service.add(addlist);
                msg+=model.getMsg();
            }
        }
        if(upjson!=null && upjson.length()>0){
            List<User_inf> uplist=gson.fromJson(upjson, new TypeToken<List<User_inf>>(){}.getType());
            if(uplist!=null && uplist.size()>0){
                model=service.update(uplist);
                msg+=model.getMsg();
            }
        }
        model.setMsg(msg);
        result=ActionUtil.tojson(model);
        //System.out.println(result);
        return SUCCESS;
    }
    
    //修改多个用户
    public String addUser(){
        if(addjson!=null && addjson.length()>0){
            Gson gson=new Gson();
            List<Battalarm_data> list=gson.fromJson(addjson, new TypeToken<List<User_inf>>(){}.getType());
        }
        return SUCCESS;
    }
    
    
    //修改密码
    public String updatePassword(){
        User_inf uinf=(User_inf)ActionUtil.getUser();
        if(uinf!=null && uif!=null){
            uinf.setUSnId(uif.getUSnId());
            model=service.updatePassword(uinf);
        }
        result = ActionUtil.tojson(model);
        return SUCCESS;
    }
    
    //查询当前用户的信息
    public String serchUserfromSession(){
        Object obj=ActionUtil.getUser();
        result =ActionUtil.tojson(obj);
        return SUCCESS;
    }
    
    //检查用户的密码
    public String checkUserPass(){
        User_inf user = (User_inf)ActionUtil.getUser();
        ServiceModel model = new ServiceModel();
        if(user != null && user.getUpassword().equals(addjson)){
            model.setCode(1);
        }else{
            model.setCode(0);
        }
        result = ActionUtil.tojson(model);
        return SUCCESS;
    }
    
    //查询当前用户的用户名
    public String searchUname(){
        User_inf user = (User_inf)ActionUtil.getUser();
        ServiceModel model = new ServiceModel();
        if(user != null){
            model.setCode(1);
            model.setMsgN(user.getUName());
        }else{
            model.setCode(0);
            model.setMsg(getText("You are not logged in, please log in"));
        }
        result = ActionUtil.tojson(model);
        return SUCCESS;
    }
    
    //界面请求监测服务是否断开
    public String checkService(){
        return SUCCESS;
    }
    
    //获取服务器的时间
    public String searchServerTime(){
        ServiceModel model = new ServiceModel();
        model.setCode(1);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        model.setMsg(sdf.format(new Date()));
        result = ActionUtil.getGson("yyyy-MM-dd HH:mm:ss").toJson(model);
        return SUCCESS;
    }
    
    public String checkSession() {
        model = new ServiceModel();
        Object obj = ActionUtil.getUser();
        if(obj != null) {
            model.setCode(1);
        }else {
            model.setCode(0);
        }
        result = ActionUtil.tojson(model);
        return SUCCESS;
    }
    
    public String test(){
        System.out.println(upjson);
        System.out.println(uif);
        return SUCCESS;
    }
    
    public void setBup(Batt_User_Permit bup) {
        this.bup = bup;
    }
    
 
    public String getResult() {
        return result;
    }
    public void setResult(String result) {
        this.result = result;
    }
    
    public User_inf getUif() {
        return uif;
    }
 
    public void setUif(User_inf uif) {
        this.uif = uif;
    }
 
    public Batt_User_Permit getBup() {
        return bup;
    }
 
    public String getAddjson() {
        return addjson;
    }
 
    public void setAddjson(String addjson) {
        this.addjson = addjson;
    }
 
    public String getUpjson() {
        return upjson;
    }
 
    public void setUpjson(String upjson) {
        this.upjson = upjson;
    }
 
    public static void main(String[] args) {
        User_infAction ua=new User_infAction();
        //Batt_User_Permit bup=new Batt_User_Permit();
        
        ua.searchAll();
    }
}