You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
5.4 KiB
162 lines
5.4 KiB
package com.gxwebsoft.hjm.controller;
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.gxwebsoft.common.core.web.BaseController;
|
|
import com.gxwebsoft.hjm.service.HjmExamLogService;
|
|
import com.gxwebsoft.hjm.entity.HjmExamLog;
|
|
import com.gxwebsoft.hjm.param.HjmExamLogParam;
|
|
import com.gxwebsoft.common.core.web.ApiResult;
|
|
import com.gxwebsoft.common.core.web.PageResult;
|
|
import com.gxwebsoft.common.core.web.BatchParam;
|
|
import com.gxwebsoft.common.core.annotation.OperationLog;
|
|
import com.gxwebsoft.common.system.entity.User;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 黄家明_学习记录控制器
|
|
*
|
|
* @author 科技小王子
|
|
* @since 2025-06-05 14:32:03
|
|
*/
|
|
@Api(tags = "黄家明_学习记录管理")
|
|
@RestController
|
|
@RequestMapping("/api/hjm/hjm-exam-log")
|
|
public class HjmExamLogController extends BaseController {
|
|
@Resource
|
|
private HjmExamLogService hjmExamLogService;
|
|
|
|
@ApiOperation("分页查询黄家明_学习记录")
|
|
@GetMapping("/page")
|
|
public ApiResult<PageResult<HjmExamLog>> page(HjmExamLogParam param) {
|
|
// 使用关联查询
|
|
return success(hjmExamLogService.pageRel(param));
|
|
}
|
|
|
|
@ApiOperation("查询全部黄家明_学习记录")
|
|
@GetMapping()
|
|
public ApiResult<List<HjmExamLog>> list(HjmExamLogParam param) {
|
|
// 使用关联查询
|
|
return success(hjmExamLogService.listRel(param));
|
|
}
|
|
|
|
@ApiOperation("根据id查询黄家明_学习记录")
|
|
@GetMapping("/{id}")
|
|
public ApiResult<HjmExamLog> get(@PathVariable("id") Integer id) {
|
|
// 使用关联查询
|
|
return success(hjmExamLogService.getByIdRel(id));
|
|
}
|
|
|
|
@ApiOperation("添加黄家明_学习记录")
|
|
@PostMapping()
|
|
public ApiResult<?> save(@RequestBody HjmExamLog hjmExamLog) {
|
|
// 记录当前登录用户id
|
|
User loginUser = getLoginUser();
|
|
if (loginUser != null) {
|
|
hjmExamLog.setUserId(loginUser.getUserId());
|
|
}
|
|
if (hjmExamLogService.save(hjmExamLog)) {
|
|
return success("添加成功");
|
|
}
|
|
return fail("添加失败");
|
|
}
|
|
|
|
@PreAuthorize("hasAuthority('hjm:hjmExamLog:update')")
|
|
@OperationLog
|
|
@ApiOperation("修改黄家明_学习记录")
|
|
@PutMapping()
|
|
public ApiResult<?> update(@RequestBody HjmExamLog hjmExamLog) {
|
|
if (hjmExamLogService.updateById(hjmExamLog)) {
|
|
return success("修改成功");
|
|
}
|
|
return fail("修改失败");
|
|
}
|
|
|
|
@PreAuthorize("hasAuthority('hjm:hjmExamLog:remove')")
|
|
@OperationLog
|
|
@ApiOperation("删除黄家明_学习记录")
|
|
@DeleteMapping("/{id}")
|
|
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
|
if (hjmExamLogService.removeById(id)) {
|
|
return success("删除成功");
|
|
}
|
|
return fail("删除失败");
|
|
}
|
|
|
|
@PreAuthorize("hasAuthority('hjm:hjmExamLog:save')")
|
|
@OperationLog
|
|
@ApiOperation("批量添加黄家明_学习记录")
|
|
@PostMapping("/batch")
|
|
public ApiResult<?> saveBatch(@RequestBody List<HjmExamLog> list) {
|
|
if (hjmExamLogService.saveBatch(list)) {
|
|
return success("添加成功");
|
|
}
|
|
return fail("添加失败");
|
|
}
|
|
|
|
@PreAuthorize("hasAuthority('hjm:hjmExamLog:update')")
|
|
@OperationLog
|
|
@ApiOperation("批量修改黄家明_学习记录")
|
|
@PutMapping("/batch")
|
|
public ApiResult<?> removeBatch(@RequestBody BatchParam<HjmExamLog> batchParam) {
|
|
if (batchParam.update(hjmExamLogService, "id")) {
|
|
return success("修改成功");
|
|
}
|
|
return fail("修改失败");
|
|
}
|
|
|
|
@PreAuthorize("hasAuthority('hjm:hjmExamLog:remove')")
|
|
@OperationLog
|
|
@ApiOperation("批量删除黄家明_学习记录")
|
|
@DeleteMapping("/batch")
|
|
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
|
if (hjmExamLogService.removeByIds(ids)) {
|
|
return success("删除成功");
|
|
}
|
|
return fail("删除失败");
|
|
}
|
|
|
|
@ApiOperation("查询本月是否已完成学习任务")
|
|
@GetMapping("/getMyMonthExamLog")
|
|
public ApiResult<List<HjmExamLog>> getMyMonthExamLog() {
|
|
User loginUser = getLoginUser();
|
|
if (loginUser == null) {
|
|
return fail("请先登录",null);
|
|
}
|
|
|
|
// 查询当前月份的记录
|
|
List<HjmExamLog> list = hjmExamLogService.list(new LambdaQueryWrapper<HjmExamLog>()
|
|
.eq(HjmExamLog::getStatus, 1)
|
|
.eq(HjmExamLog::getUserId, loginUser.getUserId())
|
|
.ge(HjmExamLog::getCreateTime, DateUtil.beginOfMonth(DateUtil.date()))
|
|
.le(HjmExamLog::getCreateTime, DateUtil.endOfMonth(DateUtil.date())));
|
|
|
|
return success("查询成功", list);
|
|
}
|
|
|
|
@ApiOperation("检查本月是否已完成学习任务")
|
|
@GetMapping("/checkMonthTaskCompleted")
|
|
public ApiResult<Boolean> checkMonthTaskCompleted() {
|
|
User loginUser = getLoginUser();
|
|
if (loginUser == null) {
|
|
return fail("请先登录",null);
|
|
}
|
|
|
|
// 查询本月是否有完成的学习记录
|
|
long count = hjmExamLogService.count(new LambdaQueryWrapper<HjmExamLog>()
|
|
.eq(HjmExamLog::getStatus, 1)
|
|
.eq(HjmExamLog::getUserId, loginUser.getUserId())
|
|
.ge(HjmExamLog::getCreateTime, DateUtil.beginOfMonth(DateUtil.date()))
|
|
.le(HjmExamLog::getCreateTime, DateUtil.endOfMonth(DateUtil.date())));
|
|
|
|
boolean isCompleted = count > 0;
|
|
return success(isCompleted ? "本月已完成学习任务" : "本月尚未完成学习任务", isCompleted);
|
|
}
|
|
|
|
}
|