From 592d52309c0336b48bee0625c83fa3cf21434ae6 Mon Sep 17 00:00:00 2001 From: hz wang Date: Mon, 8 May 2023 16:22:03 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=E5=AE=8C=E6=88=90=E5=A4=A7=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mewhz/paste/constant/CodeConstant.java | 2 +- .../com/mewhz/paste/constant/LogConstant.java | 34 ++ .../com/mewhz/paste/constant/RunConstant.java | 2 + .../paste/controller/CodeController.java | 4 +- .../mewhz/paste/controller/LogController.java | 19 + .../mewhz/paste/controller/RunController.java | 15 +- .../paste/controller/UserController.java | 2 +- .../com/mewhz/paste/mapper/LogMapper.java | 14 + .../com/mewhz/paste/mapper/RunMapper.java | 12 + .../com/mewhz/paste/model/entity/Log.java | 28 ++ .../com/mewhz/paste/model/vo/CodeInfoVO.java | 1 + .../mewhz/paste/model/vo/CodeRunInfoVO.java | 19 - .../com/mewhz/paste/model/vo/ResultVO.java | 3 + .../com/mewhz/paste/model/vo/RunInfoVO.java | 29 ++ .../com/mewhz/paste/model/vo/RunSearchVO.java | 31 ++ .../com/mewhz/paste/service/CodeService.java | 40 ++ .../com/mewhz/paste/service/LogService.java | 14 + .../com/mewhz/paste/service/RunService.java | 24 +- .../mewhz/paste/service/StatusService.java | 39 ++ .../com/mewhz/paste/service/UserService.java | 85 ++++- .../src/main/resources/mapper/RunMapper.xml | 53 +++ pastecode-ui/src/router/index.js | 5 + pastecode-ui/src/views/Admin.vue | 3 + .../src/views/admin/CodeManagement.vue | 36 +- .../src/views/admin/LogManagement.vue | 297 +++++++++++++- .../src/views/admin/RunManagement.vue | 361 ++++++++++++++++++ .../src/views/admin/UserManagement.vue | 2 +- 27 files changed, 1126 insertions(+), 48 deletions(-) create mode 100644 pastecode-system/src/main/java/com/mewhz/paste/constant/LogConstant.java create mode 100644 pastecode-system/src/main/java/com/mewhz/paste/controller/LogController.java create mode 100644 pastecode-system/src/main/java/com/mewhz/paste/mapper/LogMapper.java create mode 100644 pastecode-system/src/main/java/com/mewhz/paste/model/entity/Log.java delete mode 100644 pastecode-system/src/main/java/com/mewhz/paste/model/vo/CodeRunInfoVO.java create mode 100644 pastecode-system/src/main/java/com/mewhz/paste/model/vo/RunInfoVO.java create mode 100644 pastecode-system/src/main/java/com/mewhz/paste/model/vo/RunSearchVO.java create mode 100644 pastecode-system/src/main/java/com/mewhz/paste/service/LogService.java create mode 100644 pastecode-system/src/main/resources/mapper/RunMapper.xml create mode 100644 pastecode-ui/src/views/admin/RunManagement.vue diff --git a/pastecode-system/src/main/java/com/mewhz/paste/constant/CodeConstant.java b/pastecode-system/src/main/java/com/mewhz/paste/constant/CodeConstant.java index 43801bf..bce279e 100644 --- a/pastecode-system/src/main/java/com/mewhz/paste/constant/CodeConstant.java +++ b/pastecode-system/src/main/java/com/mewhz/paste/constant/CodeConstant.java @@ -8,5 +8,5 @@ public interface CodeConstant { /** * 代码返回时每页的数量 */ - Long CODE_PAGE_NUM = 3L; + Long CODE_PAGE_NUM = 5L; } diff --git a/pastecode-system/src/main/java/com/mewhz/paste/constant/LogConstant.java b/pastecode-system/src/main/java/com/mewhz/paste/constant/LogConstant.java new file mode 100644 index 0000000..e0b412d --- /dev/null +++ b/pastecode-system/src/main/java/com/mewhz/paste/constant/LogConstant.java @@ -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; + +} diff --git a/pastecode-system/src/main/java/com/mewhz/paste/constant/RunConstant.java b/pastecode-system/src/main/java/com/mewhz/paste/constant/RunConstant.java index 7182dc6..b3ebb1c 100644 --- a/pastecode-system/src/main/java/com/mewhz/paste/constant/RunConstant.java +++ b/pastecode-system/src/main/java/com/mewhz/paste/constant/RunConstant.java @@ -26,4 +26,6 @@ public interface RunConstant { String INT_FILE_SUFFIX = "-input.txt"; String ERROR_FILE_SUFFIX = "-error.txt"; + + Long RUN_PAGE_NUM = 5L; } diff --git a/pastecode-system/src/main/java/com/mewhz/paste/controller/CodeController.java b/pastecode-system/src/main/java/com/mewhz/paste/controller/CodeController.java index a30ea40..42c4af4 100644 --- a/pastecode-system/src/main/java/com/mewhz/paste/controller/CodeController.java +++ b/pastecode-system/src/main/java/com/mewhz/paste/controller/CodeController.java @@ -66,12 +66,12 @@ public ResultVO> getPageList(CodeSearchVO codeSearchVO) @PostMapping("/delete") public ResultVO delete(@RequestBody Code code) { - return ResultVO.ok(codeService.removeById(code)); + return ResultVO.ok(codeService.deleteCode(code)); } @PostMapping("/update") public ResultVO update(@RequestBody Code code) { - return ResultVO.ok(codeService.updateById(code)); + return ResultVO.ok(codeService.updateCode(code)); } @GetMapping("/download/{codeId}") diff --git a/pastecode-system/src/main/java/com/mewhz/paste/controller/LogController.java b/pastecode-system/src/main/java/com/mewhz/paste/controller/LogController.java new file mode 100644 index 0000000..fe1fd8a --- /dev/null +++ b/pastecode-system/src/main/java/com/mewhz/paste/controller/LogController.java @@ -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; +} diff --git a/pastecode-system/src/main/java/com/mewhz/paste/controller/RunController.java b/pastecode-system/src/main/java/com/mewhz/paste/controller/RunController.java index e47f72b..a28ffe0 100644 --- a/pastecode-system/src/main/java/com/mewhz/paste/controller/RunController.java +++ b/pastecode-system/src/main/java/com/mewhz/paste/controller/RunController.java @@ -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; /** @@ -28,4 +24,9 @@ public class RunController { public ResultVO receivedCode(@RequestBody CodeRunVO codeRunVO) { return ResultVO.ok(runService.receivedCode(codeRunVO)); } + + @GetMapping("/pageList") + public ResultVO> getPageList(RunSearchVO runSearchVO) { + return ResultVO.ok(runService.getPageList(runSearchVO)); + } } diff --git a/pastecode-system/src/main/java/com/mewhz/paste/controller/UserController.java b/pastecode-system/src/main/java/com/mewhz/paste/controller/UserController.java index 812f573..da1b523 100644 --- a/pastecode-system/src/main/java/com/mewhz/paste/controller/UserController.java +++ b/pastecode-system/src/main/java/com/mewhz/paste/controller/UserController.java @@ -53,7 +53,7 @@ public ResultVO update(@RequestBody User user) { @PostMapping("/delete") public ResultVO delete(@RequestBody User user) { - return ResultVO.ok(userService.removeById(user)); + return ResultVO.ok(userService.deleteUser(user)); } @PostMapping("/upload") diff --git a/pastecode-system/src/main/java/com/mewhz/paste/mapper/LogMapper.java b/pastecode-system/src/main/java/com/mewhz/paste/mapper/LogMapper.java new file mode 100644 index 0000000..208ef21 --- /dev/null +++ b/pastecode-system/src/main/java/com/mewhz/paste/mapper/LogMapper.java @@ -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 { +} diff --git a/pastecode-system/src/main/java/com/mewhz/paste/mapper/RunMapper.java b/pastecode-system/src/main/java/com/mewhz/paste/mapper/RunMapper.java index a8864ea..2afaafa 100644 --- a/pastecode-system/src/main/java/com/mewhz/paste/mapper/RunMapper.java +++ b/pastecode-system/src/main/java/com/mewhz/paste/mapper/RunMapper.java @@ -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 { + + Integer runTotal(RunSearchVO runSearchVO); + + List runPageList(@Param("runSearchVO") RunSearchVO runSearchVO, @Param("size") Long size); + } diff --git a/pastecode-system/src/main/java/com/mewhz/paste/model/entity/Log.java b/pastecode-system/src/main/java/com/mewhz/paste/model/entity/Log.java new file mode 100644 index 0000000..fad5a87 --- /dev/null +++ b/pastecode-system/src/main/java/com/mewhz/paste/model/entity/Log.java @@ -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; +} diff --git a/pastecode-system/src/main/java/com/mewhz/paste/model/vo/CodeInfoVO.java b/pastecode-system/src/main/java/com/mewhz/paste/model/vo/CodeInfoVO.java index 29cebef..6e30806 100644 --- a/pastecode-system/src/main/java/com/mewhz/paste/model/vo/CodeInfoVO.java +++ b/pastecode-system/src/main/java/com/mewhz/paste/model/vo/CodeInfoVO.java @@ -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; diff --git a/pastecode-system/src/main/java/com/mewhz/paste/model/vo/CodeRunInfoVO.java b/pastecode-system/src/main/java/com/mewhz/paste/model/vo/CodeRunInfoVO.java deleted file mode 100644 index 428e468..0000000 --- a/pastecode-system/src/main/java/com/mewhz/paste/model/vo/CodeRunInfoVO.java +++ /dev/null @@ -1,19 +0,0 @@ -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 CodeRunInfoVO { -// -// -// -//} diff --git a/pastecode-system/src/main/java/com/mewhz/paste/model/vo/ResultVO.java b/pastecode-system/src/main/java/com/mewhz/paste/model/vo/ResultVO.java index 0d10320..dc36871 100644 --- a/pastecode-system/src/main/java/com/mewhz/paste/model/vo/ResultVO.java +++ b/pastecode-system/src/main/java/com/mewhz/paste/model/vo/ResultVO.java @@ -24,6 +24,9 @@ public class ResultVO { private T data; + public ResultVO(T data) { + this.data = data; + } public static ResultVO ok() { return resultVO(true, SUCCESS.getCode(), SUCCESS.getMessage(), null); diff --git a/pastecode-system/src/main/java/com/mewhz/paste/model/vo/RunInfoVO.java b/pastecode-system/src/main/java/com/mewhz/paste/model/vo/RunInfoVO.java new file mode 100644 index 0000000..87e3be0 --- /dev/null +++ b/pastecode-system/src/main/java/com/mewhz/paste/model/vo/RunInfoVO.java @@ -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; +} diff --git a/pastecode-system/src/main/java/com/mewhz/paste/model/vo/RunSearchVO.java b/pastecode-system/src/main/java/com/mewhz/paste/model/vo/RunSearchVO.java new file mode 100644 index 0000000..178944b --- /dev/null +++ b/pastecode-system/src/main/java/com/mewhz/paste/model/vo/RunSearchVO.java @@ -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; + } +} diff --git a/pastecode-system/src/main/java/com/mewhz/paste/service/CodeService.java b/pastecode-system/src/main/java/com/mewhz/paste/service/CodeService.java index a9fb78e..622c357 100644 --- a/pastecode-system/src/main/java/com/mewhz/paste/service/CodeService.java +++ b/pastecode-system/src/main/java/com/mewhz/paste/service/CodeService.java @@ -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.*; @@ -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 @@ -43,6 +46,9 @@ public class CodeService extends ServiceImpl { @Resource private RunMapper runMapper; + @Resource + private LogMapper logMapper; + public CodeInfoVO findByCodeId(Integer codeId) { return codeMapper.findByCodeId(codeId); } @@ -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; } @@ -165,6 +179,32 @@ public List getUserRunCodeList(Integer userId) { } return runMapper.selectList(new LambdaQueryWrapper().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); } } diff --git a/pastecode-system/src/main/java/com/mewhz/paste/service/LogService.java b/pastecode-system/src/main/java/com/mewhz/paste/service/LogService.java new file mode 100644 index 0000000..3889d93 --- /dev/null +++ b/pastecode-system/src/main/java/com/mewhz/paste/service/LogService.java @@ -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 { +} diff --git a/pastecode-system/src/main/java/com/mewhz/paste/service/RunService.java b/pastecode-system/src/main/java/com/mewhz/paste/service/RunService.java index f83872a..b2d757d 100644 --- a/pastecode-system/src/main/java/com/mewhz/paste/service/RunService.java +++ b/pastecode-system/src/main/java/com/mewhz/paste/service/RunService.java @@ -6,17 +6,21 @@ import cn.hutool.core.util.RuntimeUtil; 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.model.entity.Code; +import com.mewhz.paste.model.entity.Log; import com.mewhz.paste.model.entity.Run; -import com.mewhz.paste.model.vo.CodeRunVO; -import com.mewhz.paste.model.vo.RunResultVO; +import com.mewhz.paste.model.vo.*; import lombok.SneakyThrows; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.io.FileWriter; +import java.util.List; +import static com.mewhz.paste.constant.LogConstant.DELETE_LIKE; +import static com.mewhz.paste.constant.LogConstant.RUN_CODE; import static com.mewhz.paste.constant.RunConstant.*; /** @@ -31,6 +35,9 @@ public class RunService extends ServiceImpl { @Resource private RunMapper runMapper; + @Resource + private LogMapper logMapper; + public RunResultVO receivedCode(CodeRunVO codeRunVO) { this.mkdirCode(codeRunVO); @@ -114,7 +121,20 @@ private void saveRun(RunResultVO runResultVO, CodeRunVO codeRunVO) { run.setCodeId(code.getCodeId()); + Log log = new Log(); + + log.setLogInfo(codeRunVO.toString()); + log.setLogType(RUN_CODE); + log.setLogIsSuccess(true); + this.logMapper.insert(log); + this.save(run); } + + public ResultPageVO getPageList(RunSearchVO runSearchVO) { + Integer count = runMapper.runTotal(runSearchVO); + List runs = runMapper.runPageList(runSearchVO, RUN_PAGE_NUM); + return new ResultPageVO<>(runs, count); + } } diff --git a/pastecode-system/src/main/java/com/mewhz/paste/service/StatusService.java b/pastecode-system/src/main/java/com/mewhz/paste/service/StatusService.java index dd23fab..0f1cf62 100644 --- a/pastecode-system/src/main/java/com/mewhz/paste/service/StatusService.java +++ b/pastecode-system/src/main/java/com/mewhz/paste/service/StatusService.java @@ -2,16 +2,25 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.mewhz.paste.mapper.LogMapper; import com.mewhz.paste.mapper.StatusMapper; +import com.mewhz.paste.model.entity.Code; +import com.mewhz.paste.model.entity.Log; import com.mewhz.paste.model.entity.Status; import org.springframework.stereotype.Service; +import javax.annotation.Resource; + +import static com.mewhz.paste.constant.LogConstant.*; + /** * @author mewhz */ @Service public class StatusService extends ServiceImpl { + @Resource + private LogMapper logMapper; public boolean updateStatus(Status status) { @@ -20,12 +29,42 @@ public boolean updateStatus(Status status) { .eq(Status::getUserId, status.getUserId()) .eq(Status::getStatusType, status.getStatusType())); + Log log = new Log(); + if (statusExist == null) { + + log.setLogInfo(status.toString()); + + if (status.getStatusType() == 1) { + log.setLogType(INSERT_LIKE); + } + else { + log.setLogType(INSERT_COLLECT); + } + + log.setLogIsSuccess(true); + + this.logMapper.insert(log); + return this.save(status); } else { status.setStatusId(statusExist.getStatusId()); + + log.setLogInfo(status.toString()); + + if (status.getStatusType() == 1) { + log.setLogType(DELETE_LIKE); + } + else { + log.setLogType(DELETE_COLLECT); + } + + log.setLogIsSuccess(true); + + this.logMapper.insert(log); + return this.removeById(status); } } diff --git a/pastecode-system/src/main/java/com/mewhz/paste/service/UserService.java b/pastecode-system/src/main/java/com/mewhz/paste/service/UserService.java index 26fca76..f3ebc26 100644 --- a/pastecode-system/src/main/java/com/mewhz/paste/service/UserService.java +++ b/pastecode-system/src/main/java/com/mewhz/paste/service/UserService.java @@ -5,8 +5,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.mewhz.paste.exception.BizException; +import com.mewhz.paste.mapper.LogMapper; import com.mewhz.paste.mapper.UserMapper; import com.mewhz.paste.model.dto.UserSearchVO; +import com.mewhz.paste.model.entity.Log; import com.mewhz.paste.model.entity.User; import com.mewhz.paste.model.vo.ResultPageVO; import com.mewhz.paste.model.vo.UserInfoVO; @@ -17,12 +19,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; import java.util.Objects; -import static com.mewhz.paste.constant.UserConstant.ACCOUNT_RETRY_CYCLE; -import static com.mewhz.paste.constant.UserConstant.USER_PAGE_NUM; +import static com.mewhz.paste.constant.UserConstant.*; +import static com.mewhz.paste.constant.LogConstant.*; /** * @author mewhz @@ -30,9 +33,12 @@ @Service public class UserService extends ServiceImpl { - @Autowired + @Resource private UserMapper userMapper; + @Resource + private LogMapper logMapper; + public UserInfoVO login(UserLoginVO userLoginVO) { @@ -42,10 +48,26 @@ public UserInfoVO login(UserLoginVO userLoginVO) { User user = userMapper.selectOne(new LambdaQueryWrapper() .eq(User::getUserAccount, userAccount)); + Log log = new Log(); + if (user == null) { + + log.setLogInfo(userLoginVO.toString()); + log.setLogType(LOGIN); + log.setLogIsSuccess(false); + + this.logMapper.insert(log); + throw new BizException("用户不存在!"); } else if (!user.getUserPassword().equals(userPassword)) { + + log.setLogInfo(userLoginVO.toString()); + log.setLogType(LOGIN); + log.setLogIsSuccess(false); + + this.logMapper.insert(log); + throw new BizException("密码错误!"); } else if (user.getUserAccount().equals(userAccount) && user.getUserPassword().equals(userPassword)) { @@ -62,9 +84,22 @@ else if (user.getUserAccount().equals(userAccount) && user.getUserPassword().equ userInfoVO.setUserRoleStr("普通用户"); } + log.setLogInfo(userLoginVO.toString()); + log.setLogType(LOGIN); + log.setLogIsSuccess(true); + + this.logMapper.insert(log); + return userInfoVO; } else { + + log.setLogInfo(userLoginVO.toString()); + log.setLogType(LOGIN); + log.setLogIsSuccess(false); + + this.logMapper.insert(log); + throw new BizException("未知错误, 请联系管理员!"); } } @@ -74,7 +109,16 @@ public UserInfoVO register(UserRegisterVO userRegisterVO) { User existUser = userMapper.selectOne(new LambdaQueryWrapper() .eq(User::getUserEmail, userRegisterVO.getUserEmail())); + Log log = new Log(); + if (existUser != null) { + + log.setLogInfo(userRegisterVO.toString()); + log.setLogType(REGISTER); + log.setLogIsSuccess(false); + + this.logMapper.insert(log); + throw new BizException("邮箱已存在!"); } @@ -110,6 +154,13 @@ public UserInfoVO register(UserRegisterVO userRegisterVO) { BeanUtil.copyProperties(user, userInfoVO); + + log.setLogInfo(userRegisterVO.toString()); + log.setLogType(REGISTER); + log.setLogIsSuccess(true); + + this.logMapper.insert(log); + return userInfoVO; } @@ -171,15 +222,43 @@ public Boolean updateUser(User user) { List list = this.list(new LambdaQueryWrapper() .eq(User::getUserEmail, user.getUserEmail())); + Log log = new Log(); + for (User u : list) { if (!Objects.equals(u.getUserId(), user.getUserId())) { + + log.setLogInfo(user.toString()); + log.setLogType(UPDATE_USER); + log.setLogIsSuccess(false); + + this.logMapper.insert(log); + throw new BizException("邮箱已存在!"); } } + log.setLogInfo(user.toString()); + log.setLogType(UPDATE_USER); + log.setLogIsSuccess(true); + + this.logMapper.insert(log); + return this.updateById(user); } + public Boolean deleteUser(User user) { + + Log log = new Log(); + + log.setLogInfo(user.toString()); + log.setLogType(DELETE_USER); + log.setLogIsSuccess(true); + + this.logMapper.insert(log); + + return this.removeById(user); + } + } diff --git a/pastecode-system/src/main/resources/mapper/RunMapper.xml b/pastecode-system/src/main/resources/mapper/RunMapper.xml new file mode 100644 index 0000000..ac90e09 --- /dev/null +++ b/pastecode-system/src/main/resources/mapper/RunMapper.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pastecode-ui/src/router/index.js b/pastecode-ui/src/router/index.js index 058b667..2ef5c91 100644 --- a/pastecode-ui/src/router/index.js +++ b/pastecode-ui/src/router/index.js @@ -43,6 +43,11 @@ const routes = [ name: 'LogManagement', component: () => import('../views/admin/LogManagement') }, + { + path: '/admin/runManagement', + name: 'RunManagement', + component: () => import('../views/admin/RunManagement') + }, { path: '/admin/systemSetting', name: 'SystemSetting', diff --git a/pastecode-ui/src/views/Admin.vue b/pastecode-ui/src/views/Admin.vue index e8becb3..4779d56 100644 --- a/pastecode-ui/src/views/Admin.vue +++ b/pastecode-ui/src/views/Admin.vue @@ -20,6 +20,9 @@ 代码管理 + + 运行管理 + 日志管理 diff --git a/pastecode-ui/src/views/admin/CodeManagement.vue b/pastecode-ui/src/views/admin/CodeManagement.vue index 71f5e3e..00ef42a 100644 --- a/pastecode-ui/src/views/admin/CodeManagement.vue +++ b/pastecode-ui/src/views/admin/CodeManagement.vue @@ -25,11 +25,10 @@
+ @selection-change="handleSelectionChange"> + width="30">