Skip to content

Commit

Permalink
✨完成大部分功能
Browse files Browse the repository at this point in the history
  • Loading branch information
hz wang committed May 8, 2023
1 parent 7b3a885 commit 592d523
Show file tree
Hide file tree
Showing 27 changed files with 1,126 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public interface CodeConstant {
/**
* 代码返回时每页的数量
*/
Long CODE_PAGE_NUM = 3L;
Long CODE_PAGE_NUM = 5L;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.mewhz.paste.constant;

/**
* @author mewhz
*/
public interface LogConstant {

String LOGIN = "登录";

String REGISTER = "注册";

String UPDATE_USER = "更新用户";

String DELETE_USER = "删除用户";

String INSERT_CODE = "分享代码";

String UPDATE_CODE = "更新代码";

String DELETE_CODE = "删除代码";

String INSERT_LIKE = "点赞";

String DELETE_LIKE = "取消赞";

String INSERT_COLLECT = "收藏";

String DELETE_COLLECT = "取消收藏";

String RUN_CODE = "运行代码";

Long LOG_PAGE_NUM = 5L;

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public interface RunConstant {
String INT_FILE_SUFFIX = "-input.txt";

String ERROR_FILE_SUFFIX = "-error.txt";

Long RUN_PAGE_NUM = 5L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ public ResultVO<ResultPageVO<CodeInfoVO>> getPageList(CodeSearchVO codeSearchVO)

@PostMapping("/delete")
public ResultVO<Boolean> delete(@RequestBody Code code) {
return ResultVO.ok(codeService.removeById(code));
return ResultVO.ok(codeService.deleteCode(code));
}

@PostMapping("/update")
public ResultVO<Boolean> update(@RequestBody Code code) {
return ResultVO.ok(codeService.updateById(code));
return ResultVO.ok(codeService.updateCode(code));
}

@GetMapping("/download/{codeId}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mewhz.paste.controller;

import com.mewhz.paste.service.LogService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.Resources;

/**
* @author mewhz
*/
@RestController
@RequestMapping("/log")
public class LogController {

@Resource
private LogService logService;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@

import com.mewhz.paste.model.entity.Code;
import com.mewhz.paste.model.entity.Run;
import com.mewhz.paste.model.vo.CodeRunVO;
import com.mewhz.paste.model.vo.ResultVO;
import com.mewhz.paste.model.vo.RunResultVO;
import com.mewhz.paste.model.vo.*;
import com.mewhz.paste.service.RunService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
Expand All @@ -28,4 +24,9 @@ public class RunController {
public ResultVO<RunResultVO> receivedCode(@RequestBody CodeRunVO codeRunVO) {
return ResultVO.ok(runService.receivedCode(codeRunVO));
}

@GetMapping("/pageList")
public ResultVO<ResultPageVO<RunInfoVO>> getPageList(RunSearchVO runSearchVO) {
return ResultVO.ok(runService.getPageList(runSearchVO));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ResultVO<Boolean> update(@RequestBody User user) {

@PostMapping("/delete")
public ResultVO<Boolean> delete(@RequestBody User user) {
return ResultVO.ok(userService.removeById(user));
return ResultVO.ok(userService.deleteUser(user));
}

@PostMapping("/upload")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.mewhz.paste.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mewhz.paste.model.entity.Log;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
* @author mewhz
*/
@Repository
public interface LogMapper extends BaseMapper<Log> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mewhz.paste.model.entity.Run;
import com.mewhz.paste.model.vo.CodeInfoVO;
import com.mewhz.paste.model.vo.CodeSearchVO;
import com.mewhz.paste.model.vo.RunInfoVO;
import com.mewhz.paste.model.vo.RunSearchVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* @author mewhz
*/
@Repository
public interface RunMapper extends BaseMapper<Run> {

Integer runTotal(RunSearchVO runSearchVO);

List<RunInfoVO> runPageList(@Param("runSearchVO") RunSearchVO runSearchVO, @Param("size") Long size);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.mewhz.paste.model.entity;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
* @author mewhz
*/
@Data
@ToString
@TableName("log")
@AllArgsConstructor
@NoArgsConstructor
public class Log {

@TableId(value = "log_id", type = IdType.AUTO)
private Integer logId;
private String logType;
private String logInfo;
private Boolean logIsSuccess;
private String logCreateDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class CodeInfoVO {
private String codeText;
private String codeType;
private String codeTitle;
private String codeStatus;
private String codeCreateDate;
private Integer codeAuthorId;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class ResultVO<T> {

private T data;

public ResultVO(T data) {
this.data = data;
}

public static <T> ResultVO<T> ok() {
return resultVO(true, SUCCESS.getCode(), SUCCESS.getMessage(), null);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.mewhz.paste.model.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
* @author mewhz
*/
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class RunInfoVO {

private Integer codeId;
private String codeText;
private String codeType;

private Integer runId;
private String runInput;
private String runOutput;
private String runError;
private String runCreateDate;

private String userAccount;
private String userName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.mewhz.paste.model.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import static com.mewhz.paste.constant.RunConstant.RUN_PAGE_NUM;

/**
* @author mewhz
*/
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class RunSearchVO {

private String codeType;

private String userAccount;

private String startDate;
private String endDate;

private Long current;

public Long getCurrent() {
return current * RUN_PAGE_NUM;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mewhz.paste.mapper.CodeMapper;
import com.mewhz.paste.mapper.LogMapper;
import com.mewhz.paste.mapper.RunMapper;
import com.mewhz.paste.mapper.UserMapper;
import com.mewhz.paste.model.entity.Code;
import com.mewhz.paste.model.entity.Log;
import com.mewhz.paste.model.entity.Run;
import com.mewhz.paste.model.entity.User;
import com.mewhz.paste.model.vo.*;
Expand All @@ -27,6 +29,7 @@
import java.util.stream.Collectors;

import static com.mewhz.paste.constant.CodeConstant.CODE_PAGE_NUM;
import static com.mewhz.paste.constant.LogConstant.*;

/**
* @author mewhz
Expand All @@ -43,6 +46,9 @@ public class CodeService extends ServiceImpl<CodeMapper, Code> {
@Resource
private RunMapper runMapper;

@Resource
private LogMapper logMapper;

public CodeInfoVO findByCodeId(Integer codeId) {
return codeMapper.findByCodeId(codeId);
}
Expand All @@ -67,6 +73,14 @@ public CodeInfoVO saveCode(CodeSubmitVO codeSubmitVO) {

BeanUtil.copyProperties(code, codeInfoVO);

Log log = new Log();

log.setLogInfo(codeSubmitVO.toString());
log.setLogType(INSERT_CODE);
log.setLogIsSuccess(true);

this.logMapper.insert(log);


return codeInfoVO;
}
Expand Down Expand Up @@ -165,6 +179,32 @@ public List<Run> getUserRunCodeList(Integer userId) {
}

return runMapper.selectList(new LambdaQueryWrapper<Run>().in(Run::getCodeId, codeIds));
}

public Boolean deleteCode(Code code){

Log log = new Log();

log.setLogInfo(code.toString());
log.setLogType(DELETE_CODE);
log.setLogIsSuccess(true);

this.logMapper.insert(log);

return this.removeById(code);
}


public Boolean updateCode(Code code){

Log log = new Log();

log.setLogInfo(code.toString());
log.setLogType(UPDATE_CODE);
log.setLogIsSuccess(true);

this.logMapper.insert(log);

return this.updateById(code);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.mewhz.paste.service;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mewhz.paste.mapper.LogMapper;
import com.mewhz.paste.model.entity.Log;
import org.springframework.stereotype.Service;

/**
* @author mewhz
*/
@Service
public class LogService extends ServiceImpl<LogMapper, Log> {
}
Loading

0 comments on commit 592d523

Please sign in to comment.