2025年3月5日17:17:01
parent
19b40a8c9d
commit
bebf64ed58
|
|
@ -0,0 +1,83 @@
|
||||||
|
package com.zhangmeng.online.exam.controller;
|
||||||
|
|
||||||
|
import com.zhangmeng.online.exam.dao.PermissionDao;
|
||||||
|
import com.zhangmeng.online.exam.dao.RoleDao;
|
||||||
|
import com.zhangmeng.online.exam.dao.UserDao;
|
||||||
|
import com.zhangmeng.online.exam.dto.Result;
|
||||||
|
import com.zhangmeng.online.exam.entity.*;
|
||||||
|
import com.zhangmeng.online.exam.entity.User;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.TypedQuery;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zm
|
||||||
|
* @date 2025/3/5 15:45
|
||||||
|
* @version: 1.0
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/user")
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserDao userDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RoleDao roleDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PermissionDao permissionDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/menu")
|
||||||
|
public Result menuList() {
|
||||||
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
|
|
||||||
|
TypedQuery<User> query = entityManager.createQuery("select obj from User obj where obj.id = 1", User.class);
|
||||||
|
User root = query.getResultList().get(0);
|
||||||
|
|
||||||
|
// Set<Role> roles = root.getRoles();
|
||||||
|
// for (Role role : roles) {
|
||||||
|
// Set<Permission> permissions = role.getPermissions();
|
||||||
|
// for (Permission permission : permissions) {
|
||||||
|
// if (permission.getParent() == null) {//一级菜单
|
||||||
|
// Map<String, Object> map = new HashMap<>();
|
||||||
|
// map.put("id", permission.getId());
|
||||||
|
// map.put("name", permission.getName());
|
||||||
|
// map.put("icon", permission.getIcon());
|
||||||
|
// map.put("url", permission.getUrl());
|
||||||
|
// map.put("description", permission.getDescription());
|
||||||
|
// map.put("sort", permission.getSort());
|
||||||
|
// map.put("children", new ArrayList<>());
|
||||||
|
// list.add(map);
|
||||||
|
// } else {
|
||||||
|
// if (list.isEmpty()) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// for (Map<String, Object> map : list) {
|
||||||
|
// if (map.get("id").equals(permission.getParent().getId())) {
|
||||||
|
// List<Map<String, Object>> children = (List<Map<String, Object>>) map.get("children");
|
||||||
|
// Map<String, Object> childMap = new HashMap<>();
|
||||||
|
// childMap.put("id", permission.getId());
|
||||||
|
// childMap.put("name", permission.getName());
|
||||||
|
// childMap.put("icon", permission.getIcon());
|
||||||
|
// childMap.put("url", permission.getUrl());
|
||||||
|
// childMap.put("description", permission.getDescription());
|
||||||
|
// childMap.put("sort", permission.getSort());
|
||||||
|
// children.add(childMap);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.zhangmeng.online.exam.dao;
|
package com.zhangmeng.online.exam.dao;
|
||||||
|
|
||||||
import com.zhangmeng.online.exam.entity.Option;
|
import com.zhangmeng.online.exam.entity.QuestionOption;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -8,5 +8,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
* @date 2025/2/28 16:14
|
* @date 2025/2/28 16:14
|
||||||
* @version: 1.0
|
* @version: 1.0
|
||||||
*/
|
*/
|
||||||
public interface OptionDao extends JpaRepository<Option, Long> {
|
public interface QuestionOptionDao extends JpaRepository<QuestionOption, Long> {
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
package com.zhangmeng.online.exam.dto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zm
|
||||||
|
* @date 2025/3/5 15:47
|
||||||
|
* @version: 1.0
|
||||||
|
*/
|
||||||
|
public class Result {
|
||||||
|
|
||||||
|
|
||||||
|
public static final int SUCCESS = 200;
|
||||||
|
|
||||||
|
public static final int ERROR = 500;
|
||||||
|
|
||||||
|
private int code;
|
||||||
|
|
||||||
|
private int pageNum;
|
||||||
|
|
||||||
|
private int pageSize;
|
||||||
|
|
||||||
|
private long total;
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
private Object data;
|
||||||
|
|
||||||
|
public Result() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result(int code, String message, Object data) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result success(List<Map<String, Object>> list) {
|
||||||
|
Result result = new Result();
|
||||||
|
result.setCode(SUCCESS);
|
||||||
|
result.setMessage("success");
|
||||||
|
result.setData(list);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(int code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(Object data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPageNum() {
|
||||||
|
return pageNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPageNum(int pageNum) {
|
||||||
|
this.pageNum = pageNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPageSize() {
|
||||||
|
return pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPageSize(int pageSize) {
|
||||||
|
this.pageSize = pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTotal() {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotal(long total) {
|
||||||
|
this.total = total;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -37,7 +37,7 @@ public class Question extends BaseEntity<Long> {
|
||||||
private Type type;
|
private Type type;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "question")
|
@OneToMany(mappedBy = "question")
|
||||||
private List<Option> options = new ArrayList<>();
|
private List<QuestionOption> options = new ArrayList<>();
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
private Subject subject;
|
private Subject subject;
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ import javax.persistence.Table;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Entity
|
@Entity
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@Table(name = "option")
|
@Table(name = "question_option")
|
||||||
public class Option extends BaseEntity<Long> {
|
public class QuestionOption extends BaseEntity<Long> {
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
private Question question;
|
private Question question;
|
||||||
|
|
@ -31,8 +31,8 @@ public class User extends BaseEntity<Long> {
|
||||||
|
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
|
@ManyToMany(targetEntity = Role.class)
|
||||||
@JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "role_id", referencedColumnName = "id"))
|
@JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
|
||||||
private Set<Role> roles = new HashSet<>();
|
private Set<Role> roles = new HashSet<>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ spring:
|
||||||
properties:
|
properties:
|
||||||
hibernate:
|
hibernate:
|
||||||
dialect: org.hibernate.dialect.MySQL5Dialect
|
dialect: org.hibernate.dialect.MySQL5Dialect
|
||||||
format_sql: true
|
# format_sql: true
|
||||||
freemarker:
|
freemarker:
|
||||||
suffix: .ftl
|
suffix: .ftl
|
||||||
check-template-location: true
|
check-template-location: true
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue