实体类
User
public class User{
private String user_id;
private String user_name;
private String part_names;
private String part_ids;
public User(Map<String, Object> map) {
super();
this.user_id = map.get("user_id").toString();
this.user_name = map.get("user_name").toString();
this.part_names = map.get("part_names").toString();
this.part_ids = map.get("part_ids").toString();
}
public String getUser_id() {
return user_id;
}
public void setUser_id(String user_id) {
this.user_id = user_id;
}
public String getUser_name() {
return user_name;
}
public void setUser_name(String user_name) {
this.user_name = user_name;
}
public String getPart_names() {
return part_names;
}
public void setPart_names(String part_names) {
this.part_names = part_names;
}
public String getPart_ids() {
return part_ids;
}
public void setPart_ids(String part_ids) {
this.part_ids = part_ids;
}
TreeNode
public class TreeNode {
private String id;
private String name;
private Map<String, Object> attributes = new HashMap<>();
private List<TreeNode> children = new ArrayList<>();
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Map<String, Object> getAttributes() {
return attributes;
}
public void setAttributes(Map<String, Object> attributes) {
this.attributes = attributes;
}
public List<TreeNode> getChildren() {
return children;
}
public void setChildren(List<TreeNode> children) {
this.children = children;
}
public TreeNode(String id, String text, Map<String, Object> attributes, List<TreeNode> children) {
super();
this.id = id;
this.name = name;
this.attributes = attributes;
this.children = children;
}
public TreeNode() {
super();
}
@Override
public String toString() {
return "TreeNode [id=" + id + ", name=" + name + ", attributes=" + attributes + ", children=" + children + "]";
}
}
dao方法
UserDao
public class UserDao extends JsonBaseDao {
public User login(Map<String, String[]> paramMap) throws Exception {
String user_id = JsonUtils.getParamVal(paramMap, "user_id");
String sql = "select * from `user` where user_name = ? and pwd = ? and statu = 1";
List<Map<String, Object>> list = super.executeQuery(sql, new String[] {
"user_name", "pwd"}, paramMap,
null);
if (list != null && list.size() > 0) {
Map<String, Object> map = list.get(0);
bindingStr(map.get("user_id").toString(), map);
return new User(map);
}
return null;
}
private void bindingStr(String user_id, Map<String, Object> map) throws Exception {
String sql = "select a.part_id, a.part_name from part a, user_and_part b where a.part_id = b.part_id and b.user_id = "
+ user_id;
List<Map<String, Object>> list = super.executeQuery(sql, null);
String part_names = "";
String part_ids = "";
for (Map<String, Object> m : list) {
part_names += "," + m.get("part_name");
part_ids += "," + m.get("part_id");
}
if (part_names.length() > 0) {
part_ids = part_ids.substring(1);
part_names = part_names.substring(1);
}
map.put("part_names", part_names);
map.put("part_ids", part_ids);
}
public int add(Map<String, String[]> paramMap) throws Exception {
String sql = "insert into `user` (user_name, pwd, statu)values (?, ?, 1)";
int n = super.executeUpdate(sql, new String[] {
"user_name", "pwd" }, paramMap);
int maxId = executeByInteger("select max(user_id) from user ");
String[] part_ids = JsonUtils.getParamVal(paramMap, "part_ids").split(",");
bindingPart(maxId + "", part_ids);
return n;
}
public void bindingPart(String user_id, String[] part_ids) {
String sql = "delete from user_and_part where user_id = " + user_id;
super.executeUpdate(sql);
for (String part_id : part_ids) {
super.executeUpdate("insert into user_and_part values(" + user_id + "," + part_id + ")");
}
}
public int remove(Map<String, String[]> paramMap) throws Exception {
String sql = "delete from `user` WHERE user_id = ?";
super.executeUpdate("delete from user_and_part where user_id =" + JsonUtils.getParamVal(paramMap, "user_id"));
return super.executeUpdate(sql, new String[] {
"user_id" }, paramMap);
}
public int edit(Map<String, String[]> paramMap) throws Exception {
String sql = "update `user` set user_name = ?, pwd = ? where user_id = ?";
int n = super.executeUpdate(sql, new String[] {
"user_name", "pwd", "user_id" }, paramMap);
String[] part_ids = JsonUtils.getParamVal(paramMap, "part_ids").split(",");
bindingPart(JsonUtils.getParamVal(paramMap, "user_id"), part_ids);
return n;
}
public int eidtStatu(Map<String, String[]> paramMap) throws Exception {
String sql = "update `user` set statu = ? where user_id = ?";
return super.executeUpdate(sql, new String[] {
"statu", "user_id" }, paramMap);
}
public boolean isName(Map<String, String[]> paramMap) throws Exception {
List<Map<String, Object>> list = null;
if(StringUtils.isNotBlank(JsonUtils.getParamVal(paramMap, "user_id"))) {
String sql = "select user_id from user where user_id != ? and user_name = ?";
list = super.executeQuery(sql, new String[] {
"user_id", "user_name" }, paramMap, null);
}else {
String sql = "select user_id from user where user_name = ?";
list = super.executeQuery(sql, new String[] {
"user_name" }, paramMap, null);
}
return list != null && list.size() > 0