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;
|
}
|
}
|