package com.xjrsoft.module.student.controller; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.support.ExcelTypeEnum; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.yulichang.toolkit.MPJWrappers; import com.xjrsoft.common.annotation.XjrLog; 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.student.dto.AddBaseStudentPostDto; import com.xjrsoft.module.student.dto.BaseStudentPostListDto; import com.xjrsoft.module.student.dto.BaseStudentPostPageDto; import com.xjrsoft.module.student.dto.UpdateBaseStudentPostDto; import com.xjrsoft.module.student.entity.BaseStudentPost; import com.xjrsoft.module.student.service.IBaseStudentPostService; import com.xjrsoft.module.student.vo.BaseStudentPostListVo; import com.xjrsoft.module.student.vo.BaseStudentPostPageVo; import com.xjrsoft.module.student.vo.BaseStudentPostVo; import com.xjrsoft.module.system.entity.DictionaryDetail; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.List; /** * @title: 学生职务设置 * @Author dzx * @Date: 2023-11-13 * @Version 1.0 */ @RestController @RequestMapping("/student" + "/basestudentpost") @Api(value = "/student" + "/basestudentpost", tags = "学生职务设置代码") @AllArgsConstructor public class BaseStudentPostController { private final IBaseStudentPostService baseStudentPostService; @GetMapping(value = "/list") @ApiOperation(value = "学生职务设置列表(不分页)") @SaCheckPermission("basestudentpost:list") @XjrLog(value = "学生职务设置列表(不分页)") public RT> list(@Valid BaseStudentPostListDto dto) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper .select(BaseStudentPost::getId) .eq(ObjectUtil.isNotNull(dto.getLevel()), BaseStudentPost::getLevel, dto.getLevel()) .eq(BaseStudentPost::getStatus, 1) .orderByDesc(BaseStudentPost::getId) .select(BaseStudentPost.class, x -> VoToColumnUtil.fieldsToColumns(BaseStudentPostListVo.class).contains(x.getProperty())); List list = baseStudentPostService.list(queryWrapper); List listVos = BeanUtil.copyToList(list, BaseStudentPostListVo.class); return RT.ok(listVos); } @GetMapping(value = "/page") @ApiOperation(value = "学生职务设置列表(分页)") @SaCheckPermission("basestudentpost:page") @XjrLog(value = "学生职务设置列表(分页)") public RT> page(@Valid BaseStudentPostPageDto dto) { IPage page = baseStudentPostService.selectJoinListPage(ConventPage.getPage(dto), BaseStudentPostPageVo.class, MPJWrappers.lambdaJoin() .orderByAsc(BaseStudentPost::getSortCode) .selectAs(DictionaryDetail::getName, BaseStudentPostPageVo::getLevelCn) .select(BaseStudentPost.class, x -> VoToColumnUtil.fieldsToColumns(BaseStudentPostPageVo.class).contains(x.getProperty())) .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, BaseStudentPost::getLevel) .select(BaseStudentPost::getId) .eq(ObjectUtil.isNotNull(dto.getLevel()), BaseStudentPost::getLevel, dto.getLevel()) ); PageOutput pageOutput = ConventPage.getPageOutput(page, BaseStudentPostPageVo.class); return RT.ok(pageOutput); } @GetMapping(value = "/info") @ApiOperation(value = "根据id查询学生职务设置信息") @SaCheckPermission("basestudentpost:info") @XjrLog(value = "根据id查询学生职务设置信息", saveResponseData = true) public RT info(@RequestParam Long id) { BaseStudentPost baseStudentPost = baseStudentPostService.getById(id); if (baseStudentPost == null) { return RT.error("找不到此数据!"); } return RT.ok(BeanUtil.toBean(baseStudentPost, BaseStudentPostVo.class)); } @PostMapping @ApiOperation(value = "新增学生职务设置") @SaCheckPermission("basestudentpost:add") @XjrLog(value = "新增学生职务设置", saveResponseData = true) public RT add(@Valid @RequestBody AddBaseStudentPostDto dto) { BaseStudentPost baseStudentPost = BeanUtil.toBean(dto, BaseStudentPost.class); boolean isSuccess = baseStudentPostService.save(baseStudentPost); return RT.ok(isSuccess); } @PutMapping @ApiOperation(value = "修改学生职务设置") @SaCheckPermission("basestudentpost:edit") @XjrLog(value = "修改学生职务设置", saveResponseData = true) public RT update(@Valid @RequestBody UpdateBaseStudentPostDto dto) { BaseStudentPost baseStudentPost = BeanUtil.toBean(dto, BaseStudentPost.class); return RT.ok(baseStudentPostService.updateById(baseStudentPost)); } @DeleteMapping @ApiOperation(value = "删除学生职务设置") @SaCheckPermission("basestudentpost:delete") @XjrLog(value = "删除学生职务设置", saveResponseData = true) public RT delete(@Valid @RequestBody List ids) { return RT.ok(baseStudentPostService.deleteLogicallyBatchByIds(ids)); } @GetMapping("/export") @ApiOperation(value = "导出") @SaCheckPermission("basestudentpost:export") @XjrLog(value = "导出") public ResponseEntity exportData(@Valid BaseStudentPostPageDto dto, @RequestParam(defaultValue = "false") Boolean isTemplate) { List customerList = isTemplate != null && isTemplate ? new ArrayList<>() : page(dto).getData().getList(); ByteArrayOutputStream bot = new ByteArrayOutputStream(); EasyExcel.write(bot, BaseStudentPostPageVo.class).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(customerList); return RT.fileStream(bot.toByteArray(), "BaseStudentPost" + ExcelTypeEnum.XLSX.getValue()); } }