package com.xjrsoft.module.xycxedu.controller; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.xjrsoft.common.model.result.RT; import com.xjrsoft.common.page.ConventPage; import com.xjrsoft.common.page.PageOutput; import com.xjrsoft.common.utils.VoToColumnUtil; import com.xjrsoft.module.xycxedu.dto.AddExamPlanDto; import com.xjrsoft.module.xycxedu.dto.ExamPlanPageDto; import com.xjrsoft.module.xycxedu.dto.UpdateExamPlanDto; import com.xjrsoft.module.xycxedu.entity.ExamPlan; import com.xjrsoft.module.xycxedu.entity.XycxeduExamList; import com.xjrsoft.module.xycxedu.service.IExamPlanService; import com.xjrsoft.module.xycxedu.service.IXycxeduExamListService; import com.xjrsoft.module.xycxedu.vo.ExamPlanPageVo; import com.xjrsoft.module.xycxedu.vo.ExamPlanVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import javax.validation.Valid; import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; /** * @title: 考试计划维护 * @Author dzx * @Date: 2024-07-18 * @Version 1.0 */ @RestController @RequestMapping("/xycxedu" + "/examPlan") @Api(value = "/xycxedu" + "/examPlan",tags = "考试计划维护代码") @AllArgsConstructor public class ExamPlanController { private final IExamPlanService examPlanService; private final IXycxeduExamListService examListService; @GetMapping(value = "/page") @ApiOperation(value="考试计划维护列表(分页)") @SaCheckPermission("examplan:detail") public RT> page(@Valid ExamPlanPageDto dto){ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.orderByDesc(ExamPlan::getId) .eq(ExamPlan::getSemesterId, dto.getSemesterId()) .like(ExamPlan::getName, dto.getName()) .select(ExamPlan.class,x -> VoToColumnUtil.fieldsToColumns(ExamPlanPageVo.class).contains(x.getProperty())); IPage page = examPlanService.page(ConventPage.getPage(dto), queryWrapper); PageOutput pageOutput = ConventPage.getPageOutput(page, ExamPlanPageVo.class); for (ExamPlanPageVo record : pageOutput.getList()) { String[] split = record.getMilexamids().split(","); List milexamids = Arrays.asList(split).stream() .map(Long::parseLong) .collect(Collectors.toList()); examListService.list(new QueryWrapper().lambda().in(XycxeduExamList::getMilexamid, milexamids)); } return RT.ok(pageOutput); } @GetMapping(value = "/info") @ApiOperation(value="根据id查询考试计划维护信息") @SaCheckPermission("examplan:detail") public RT info(@RequestParam Long id){ ExamPlan examPlan = examPlanService.getById(id); if (examPlan == null) { return RT.error("找不到此数据!"); } return RT.ok(BeanUtil.toBean(examPlan, ExamPlanVo.class)); } @PostMapping @ApiOperation(value = "新增考试计划维护") @SaCheckPermission("examplan:add") public RT add(@Valid @RequestBody AddExamPlanDto dto){ ExamPlan examPlan = BeanUtil.toBean(dto, ExamPlan.class); boolean isSuccess = examPlanService.save(examPlan); return RT.ok(isSuccess); } @PutMapping @ApiOperation(value = "修改考试计划维护") @SaCheckPermission("examplan:edit") public RT update(@Valid @RequestBody UpdateExamPlanDto dto){ ExamPlan examPlan = BeanUtil.toBean(dto, ExamPlan.class); return RT.ok(examPlanService.updateById(examPlan)); } @DeleteMapping @ApiOperation(value = "删除考试计划维护") @SaCheckPermission("examplan:delete") public RT delete(@Valid @RequestBody List ids){ return RT.ok(examPlanService.removeBatchByIds(ids)); } }