소스 검색

zhurui 添加ope_record实体类、连接新门户

Leonezhurui 5 년 전
부모
커밋
0d2c840313

+ 2 - 1
seecoder-bok-common/src/main/java/cn/seecoder/bok/common/QuestionState.java

@@ -11,7 +11,8 @@ import com.fasterxml.jackson.annotation.JsonValue;
 public enum QuestionState {
     APPROVED("APPROVED"),
     CHECKING("CHECKING"),
-    REFUSED("REFUSED");
+    REFUSED("REFUSED"),
+    DELETED("DELETED");
 
     private final String name;
 

+ 92 - 0
seecoder-bok-common/src/main/java/cn/seecoder/bok/common/vo/OperationRecordVO.java

@@ -0,0 +1,92 @@
+package cn.seecoder.bok.common.vo;
+
+import lombok.Data;
+
+import java.time.Instant;
+
+/**
+ * @author: Leonezhurui
+ * @Date: 2021/9/27 - 10:04 下午
+ * @Package: SEEC-BOK
+ */
+
+public class OperationRecordVO {
+    private Integer id;
+    private Integer userId;
+    private String questionId;
+    private String operationType;
+    private String remark;
+    private Instant time;
+
+    public OperationRecordVO() {
+    }
+
+    public OperationRecordVO(Integer id, Integer userId, String questionId, String operationType, String remark, Instant time) {
+        this.id = id;
+        this.userId = userId;
+        this.questionId = questionId;
+        this.operationType = operationType;
+        this.remark = remark;
+        this.time = time;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Integer userId) {
+        this.userId = userId;
+    }
+
+    public String getQuestionId() {
+        return questionId;
+    }
+
+    public void setQuestionId(String questionId) {
+        this.questionId = questionId;
+    }
+
+    public String getOperationType() {
+        return operationType;
+    }
+
+    public void setOperationType(String operationType) {
+        this.operationType = operationType;
+    }
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+
+    public Instant getTime() {
+        return time;
+    }
+
+    public void setTime(Instant time) {
+        this.time = time;
+    }
+
+    @Override
+    public String toString() {
+        return "OperationRecordVO{" +
+                "id=" + id +
+                ", userId=" + userId +
+                ", questionId='" + questionId + '\'' +
+                ", operationType='" + operationType + '\'' +
+                ", remark='" + remark + '\'' +
+                ", time=" + time +
+                '}';
+    }
+}

+ 145 - 0
seecoder-bok-common/src/main/java/cn/seecoder/bok/common/vo/user/PortalUserVO.java

@@ -0,0 +1,145 @@
+package cn.seecoder.bok.common.vo.user;
+
+import cn.seecoder.bok.common.UserRole;
+import lombok.Data;
+import lombok.ToString;
+
+/**
+ * @author: Leonezhurui
+ * @Date: 2021/10/2 - 10:17 上午
+ * @Package: SEEC-BOK
+ */
+
+public class PortalUserVO {
+    private Integer id;
+
+    private String phone;
+
+    private String username;
+
+    private String name;
+
+    private String email;
+
+    private String photo;
+
+    private UserRole role = UserRole.STUDENT;
+
+    private String signature = "无";
+
+    private String createdTime;
+
+    private Boolean valid = true;
+
+    public PortalUserVO() {
+    }
+
+    public PortalUserVO(Integer id, String phone, String username, String name, String email, String photo, UserRole role, String signature, String createdTime, Boolean valid) {
+        this.id = id;
+        this.phone = phone;
+        this.username = username;
+        this.name = name;
+        this.email = email;
+        this.photo = photo;
+        this.role = role;
+        this.signature = signature;
+        this.createdTime = createdTime;
+        this.valid = valid;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getPhone() {
+        return phone;
+    }
+
+    public void setPhone(String phone) {
+        this.phone = phone;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getEmail() {
+        return email;
+    }
+
+    public void setEmail(String email) {
+        this.email = email;
+    }
+
+    public String getPhoto() {
+        return photo;
+    }
+
+    public void setPhoto(String photo) {
+        this.photo = photo;
+    }
+
+    public UserRole getRole() {
+        return role;
+    }
+
+    public void setRole(UserRole role) {
+        this.role = role;
+    }
+
+    public String getSignature() {
+        return signature;
+    }
+
+    public void setSignature(String signature) {
+        this.signature = signature;
+    }
+
+    public String getCreatedTime() {
+        return createdTime;
+    }
+
+    public void setCreatedTime(String createdTime) {
+        this.createdTime = createdTime;
+    }
+
+    public Boolean getValid() {
+        return valid;
+    }
+
+    public void setValid(Boolean valid) {
+        this.valid = valid;
+    }
+
+    @Override
+    public String toString() {
+        return "PortalUserVO{" +
+                "id=" + id +
+                ", phone='" + phone + '\'' +
+                ", username='" + username + '\'' +
+                ", name='" + name + '\'' +
+                ", email='" + email + '\'' +
+                ", photo='" + photo + '\'' +
+                ", role=" + role +
+                ", signature='" + signature + '\'' +
+                ", createdTime='" + createdTime + '\'' +
+                ", valid=" + valid +
+                '}';
+    }
+}

+ 5 - 1
seecoder-bok-server/src/main/java/cn/seecoder/seecoderbokserver/aspect/auth/AuthAspect.java

@@ -1,5 +1,6 @@
 package cn.seecoder.seecoderbokserver.aspect.auth;
 
+import cn.seecoder.bok.common.vo.user.PortalUserVO;
 import cn.seecoder.bok.common.vo.user.UpdateUserVO;
 import cn.seecoder.seecoderbokserver.domain.User;
 import cn.seecoder.seecoderbokserver.exception.MyServiceException;
@@ -20,6 +21,7 @@ import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
 import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Objects;
 import java.util.Optional;
@@ -42,7 +44,8 @@ public class AuthAspect {
     private User getUserByToken(String token) throws JWTVerificationException {
         try {
             Claim claim = JwtUtil.parseJwt(token);
-            return claim.as(User.class);
+            PortalUserVO userVO = claim.as(PortalUserVO.class);
+            return new User(userVO.getId(), userVO.getRole(), userVO.getName(), userVO.getEmail(), userVO.getPhone());
         } catch (MyServiceException e) {
             throw new  MyServiceException(e.getCode(), "myTag"+e.getMessage());
         }
@@ -55,6 +58,7 @@ public class AuthAspect {
                 orElseThrow(() -> new MyServiceException("A0223", "用户未获得第三方登录授权"));
 
         User user = getUserByToken(token);
+//        System.out.println(user);
         // 创建或者更新用户
         if (userService.existsById(user.getId())) {
             userService.updateUser(new UpdateUserVO(user.getId(), user.getName(), user.getEmail()));

+ 106 - 0
seecoder-bok-server/src/main/java/cn/seecoder/seecoderbokserver/domain/OperationRecord.java

@@ -0,0 +1,106 @@
+package cn.seecoder.seecoderbokserver.domain;
+
+import javax.persistence.*;
+import java.time.Instant;
+
+/**
+ * @author: Leonezhurui
+ * @Date: 2021/9/27 - 9:43 下午
+ * @Package: SEEC-BOK
+ */
+
+@Entity
+@Table(name = "operationRecord")
+public class OperationRecord {
+    @Id
+    @GeneratedValue
+    @Column(name = "id")
+    private Integer id;
+
+    @Column(name = "user_id")
+    private Integer userId;
+
+    @Column(name = "question_id")
+    private String questionId;
+
+    @Column(name = "operation_type")
+    private String operationType;
+
+    @Column(name = "remark")
+    private String remark;
+
+    @Column(name = "time")
+    private Instant time;
+
+    public OperationRecord() {
+    }
+
+    public OperationRecord(Integer id, Integer userId, String questionId, String operationType, String remark, Instant time) {
+        this.id = id;
+        this.userId = userId;
+        this.questionId = questionId;
+        this.operationType = operationType;
+        this.remark = remark;
+        this.time = time;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Integer userId) {
+        this.userId = userId;
+    }
+
+    public String getQuestionId() {
+        return questionId;
+    }
+
+    public void setQuestionId(String questionId) {
+        this.questionId = questionId;
+    }
+
+    public String getOperationType() {
+        return operationType;
+    }
+
+    public void setOperationType(String operationType) {
+        this.operationType = operationType;
+    }
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+
+    public Instant getTime() {
+        return time;
+    }
+
+    public void setTime(Instant time) {
+        this.time = time;
+    }
+
+    @Override
+    public String toString() {
+        return "OperationRecord{" +
+                "id=" + id +
+                ", userId=" + userId +
+                ", questionId='" + questionId + '\'' +
+                ", operationType='" + operationType + '\'' +
+                ", remark='" + remark + '\'' +
+                ", time=" + time +
+                '}';
+    }
+}

+ 27 - 0
seecoder-bok-server/src/main/java/cn/seecoder/seecoderbokserver/mapper/OperationRecordConvertor.java

@@ -0,0 +1,27 @@
+package cn.seecoder.seecoderbokserver.mapper;
+
+import cn.seecoder.bok.common.vo.OperationRecordVO;
+import cn.seecoder.bok.common.vo.user.UserVO;
+import cn.seecoder.seecoderbokserver.domain.OperationRecord;
+import cn.seecoder.seecoderbokserver.domain.User;
+import org.springframework.beans.BeanUtils;
+
+/**
+ * @author: Leonezhurui
+ * @Date: 2021/9/27 - 10:06 下午
+ * @Package: SEEC-BOK
+ */
+
+public class OperationRecordConvertor {
+    public static OperationRecord convertToEntity(OperationRecordVO operationRecordVO) {
+        OperationRecord operationRecord = new OperationRecord();
+        BeanUtils.copyProperties(operationRecordVO, operationRecord);
+        return operationRecord;
+    }
+
+    public static OperationRecordVO convertToVO(OperationRecord operationRecord) {
+        OperationRecordVO operationRecordVO = new OperationRecordVO();
+        BeanUtils.copyProperties(operationRecord, operationRecordVO);
+        return operationRecordVO;
+    }
+}

+ 32 - 0
seecoder-bok-server/src/main/java/cn/seecoder/seecoderbokserver/repository/OperationRecordRepository.java

@@ -0,0 +1,32 @@
+package cn.seecoder.seecoderbokserver.repository;
+
+import cn.seecoder.seecoderbokserver.domain.OperationRecord;
+import cn.seecoder.seecoderbokserver.domain.OperationRecord_;
+import cn.seecoder.seecoderbokserver.domain.Record;
+import cn.seecoder.seecoderbokserver.domain.Record_;
+import cn.seecoder.seecoderbokserver.utility.EmptyCheck;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+import java.util.Collection;
+
+/**
+ * @author: Leonezhurui
+ * @Date: 2021/9/27 - 9:58 下午
+ * @Package: SEEC-BOK
+ */
+
+public interface OperationRecordRepository  extends JpaRepository<OperationRecord, Long>, JpaSpecificationExecutor<OperationRecord> {
+
+    /**
+     * 在题目中
+     *
+     * @param questionIds 题目id列表
+     * @return specification
+     */
+    default Specification<OperationRecord> inQuestions(Collection<String> questionIds) {
+        return (root, query, cb) -> EmptyCheck.instance.isEmpty(questionIds) ? null
+                : root.get(OperationRecord_.questionId).in(questionIds);
+    }
+}

+ 39 - 0
seecoder-bok-server/src/main/java/cn/seecoder/seecoderbokserver/service/OperationRecordService.java

@@ -0,0 +1,39 @@
+package cn.seecoder.seecoderbokserver.service;
+
+import cn.seecoder.seecoderbokserver.domain.OperationRecord;
+import cn.seecoder.seecoderbokserver.domain.Record;
+import cn.seecoder.seecoderbokserver.repository.OperationRecordRepository;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+import static org.springframework.data.jpa.domain.Specification.where;
+
+/**
+ * @author: Leonezhurui
+ * @Date: 2021/9/27 - 10:00 下午
+ * @Package: SEEC-BOK
+ */
+
+@Service
+public class OperationRecordService {
+    private final OperationRecordRepository operationRecordRepository;
+
+    public OperationRecordService(OperationRecordRepository operationRecordRepository) {
+        this.operationRecordRepository = operationRecordRepository;
+    }
+
+    public OperationRecord createOpeRecord(OperationRecord operationRecord){
+        return operationRecordRepository.save(operationRecord);
+    }
+
+    public Page<OperationRecord> findRecordQidIn(
+            List<String> questionIdList,
+            Pageable of) {
+        return operationRecordRepository.findAll(
+                where(operationRecordRepository.inQuestions(questionIdList)), of);
+    }
+
+}

+ 1 - 21
seecoder-bok-server/src/main/java/cn/seecoder/seecoderbokserver/util/JwtUtil.java

@@ -17,17 +17,6 @@ import org.springframework.stereotype.Component;
 @Component
 public class JwtUtil {
     private static String jwtSecret;
-    private static String jpa;
-    private static String debug;
-
-    public static String getDebug() {
-        return debug;
-    }
-
-    @Value("${debug}")
-    public void setDebug(String debug) {
-        JwtUtil.debug = debug;
-    }
 
     @Value("${jwt.secret}")
     public void setJwtSecret(String jwtSecret) { //通过set让static方法读取配置文件中的值
@@ -38,18 +27,9 @@ public class JwtUtil {
         return JwtUtil.jwtSecret;
     }
 
-    public static String getJpa() {
-        return JwtUtil.jpa;
-    }
-
-    @Value("${spring.jpa.database}")
-    public void setJpa(String jpa){
-        JwtUtil.jpa = jpa;
-    }
-
     public static Claim parseJwt(String token) {
 //        jwtSecret
-        JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256("SEEC-1919810-OIDC-114514")).build();
+        JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(jwtSecret)).build();
         DecodedJWT decodedjwt;
         try {
             decodedjwt = jwtVerifier.verify(token);

+ 45 - 0
seecoder-bok-server/src/main/java/cn/seecoder/seecoderbokserver/web/rest/OperationRecordController.java

@@ -0,0 +1,45 @@
+package cn.seecoder.seecoderbokserver.web.rest;
+
+
+import cn.seecoder.bok.common.vo.OperationRecordVO;
+import cn.seecoder.seecoderbokserver.domain.OperationRecord;
+import cn.seecoder.seecoderbokserver.mapper.OperationRecordConvertor;
+import cn.seecoder.seecoderbokserver.service.OperationRecordService;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * @author: Leonezhurui
+ * @Date: 2021/9/27 - 10:01 下午
+ * @Package: SEEC-BOK
+ */
+
+@RestController
+@RequestMapping("/api/ope_record")
+public class OperationRecordController {
+
+    private final OperationRecordService operationRecordService;
+
+    public OperationRecordController(OperationRecordService operationRecordService) {
+        this.operationRecordService = operationRecordService;
+    }
+
+    @PostMapping("")
+    public Response createOpeRecord(@RequestBody OperationRecordVO operationRecordVO){
+        OperationRecord operationRecord = OperationRecordConvertor.convertToEntity(operationRecordVO);
+        return Response.buildSuccess(OperationRecordConvertor.convertToVO(operationRecordService.createOpeRecord(operationRecord)));
+    }
+
+    @GetMapping("/{id}")
+    public Response getOpeRecordByQid(
+            @PathVariable(name = "id") List<String> qid,
+            @RequestParam(name = "offset") Integer offset,
+            @RequestParam(name = "pageSize") Integer pageSize
+    ){
+        Pageable pageable = PageRequest.of(offset, pageSize);
+        return Response.buildSuccess(operationRecordService.findRecordQidIn(qid, pageable));
+    }
+}

+ 0 - 6
seecoder-bok-server/src/main/java/cn/seecoder/seecoderbokserver/web/rest/QuestionController.java

@@ -120,12 +120,6 @@ public class QuestionController implements SeecoderBokQuestionApi, SeecoderBokQu
                 .map(questionMapper::questionToQuestionVO).collect(Collectors.toList());
     }
 
-//    @GetMapping("/test")
-//
-//    public String testQuestionController() {
-//        return "OK!";
-//    }
-
 
     @GetMapping("/state")
     @Authorized(roles = {UserRole.ADMIN, UserRole.HR, UserRole.TEACHER})

+ 2 - 1
seecoder-bok-server/src/main/resources/application-dev.yml

@@ -28,4 +28,5 @@ spring:
 
 jwt:
   header: Authorization
-  secret: SEEC-1919810-OIDC-114514
+  secret: UenM4KGb6DskRWUenM4KGb6DskRWUenM4KGb6DskRWUenM4KGb6DskRWUenM4KGb6DskRWUenM4KGb6DskRWUenM4KGb6DskRWUenM4KGb6DskRWUenM4KGb6DskRW
+