whyclj
2019-10-29 1c0469e45346d464e0c5672ee68f9ecd4fb6be7c
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
package com.fgkj.actions;
 
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
 
import com.fgkj.dto.Roles;
import com.fgkj.dto.ServiceModel;
import com.fgkj.dto.User;
import com.fgkj.dto.UserRole;
import com.fgkj.services.UserRoleService;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.opensymphony.xwork2.ActionSupport;
 
public class UserRoleAction extends ActionSupport{
    private Roles role;
    private String result;
    private ServiceModel model=new ServiceModel();
    private UserRoleService service=new UserRoleService();
    private String str;    
    
    public String findAll(){    
        model=service.findAllUserRole();
        result=ActionUtil.tojson(model);
        //System.out.println(result);
        
        return "success";
    }
    
    public String add(){
        Gson gson=new Gson();
        UserRole u=new UserRole();
        Map<Integer,UserRole> rtn = gson.fromJson(str, new TypeToken<Map<Integer,UserRole>>(){}.getType());  
        for(Entry<Integer, UserRole> entry : rtn.entrySet()){  
            UserRole ur = entry.getValue(); 
            u.setRole(new Roles(ur.getRole().getRid(),ur.getRole().getRname()));
            u.setUser(new User(ur.getUser().getUid()));
            //System.out.println(u);
            model=service.addUserRole(u);
        }  
        result=ActionUtil.tojson(model);
        //System.out.println(result+"77777");
        return "success";
    }
    
    public String del(){
        //System.out.println(str);
        model=service.del(new UserRole(Integer.parseInt(str)));
        result=ActionUtil.tojson(model);
        return "success";
    }
    
        
    public String getResult() {
        return result;
    }
    public void setResult(String result) {
        this.result = result;
    }
    public ServiceModel getModel() {
        return model;
    }
    public void setModel(ServiceModel model) {
        this.model = model;
    }
 
    public void setRole(Roles role) {
        this.role = role;
    }
    public UserRoleService getService() {
        return service;
    }
    public void setService(UserRoleService service) {
        this.service = service;
    }
 
    public String getStr() {
        return str;
    }
 
    public void setStr(String str) {
        this.str = str;
    }    
}