| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- 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<BaseStudentPostListVo>> list(@Valid BaseStudentPostListDto dto) {
- LambdaQueryWrapper<BaseStudentPost> 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<BaseStudentPost> list = baseStudentPostService.list(queryWrapper);
- List<BaseStudentPostListVo> listVos = BeanUtil.copyToList(list, BaseStudentPostListVo.class);
- return RT.ok(listVos);
- }
- @GetMapping(value = "/page")
- @ApiOperation(value = "学生职务设置列表(分页)")
- @SaCheckPermission("basestudentpost:page")
- @XjrLog(value = "学生职务设置列表(分页)")
- public RT<PageOutput<BaseStudentPostPageVo>> page(@Valid BaseStudentPostPageDto dto) {
- IPage<BaseStudentPostPageVo> page = baseStudentPostService.selectJoinListPage(ConventPage.getPage(dto), BaseStudentPostPageVo.class,
- MPJWrappers.<BaseStudentPost>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<BaseStudentPostPageVo> 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<BaseStudentPostVo> 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<Boolean> 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<Boolean> 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<Boolean> delete(@Valid @RequestBody List<Long> ids) {
- return RT.ok(baseStudentPostService.deleteLogicallyBatchByIds(ids));
- }
- @GetMapping("/export")
- @ApiOperation(value = "导出")
- @SaCheckPermission("basestudentpost:export")
- @XjrLog(value = "导出")
- public ResponseEntity<byte[]> exportData(@Valid BaseStudentPostPageDto dto, @RequestParam(defaultValue = "false") Boolean isTemplate) {
- List<BaseStudentPostPageVo> 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());
- }
- }
|