BaseStudentCadreController.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. package com.xjrsoft.module.student.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.dev33.satoken.stp.StpUtil;
  4. import cn.hutool.core.bean.BeanUtil;
  5. import cn.hutool.core.util.ObjectUtil;
  6. import cn.hutool.core.util.StrUtil;
  7. import com.alibaba.excel.EasyExcel;
  8. import com.alibaba.excel.support.ExcelTypeEnum;
  9. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  10. import com.baomidou.mybatisplus.core.metadata.IPage;
  11. import com.baomidou.mybatisplus.core.metadata.OrderItem;
  12. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  13. import com.github.yulichang.toolkit.MPJWrappers;
  14. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  15. import com.xjrsoft.common.enums.StudentCadreLevelEnum;
  16. import com.xjrsoft.common.model.result.R;
  17. import com.xjrsoft.common.model.result.RT;
  18. import com.xjrsoft.common.page.ConventPage;
  19. import com.xjrsoft.common.page.PageOutput;
  20. import com.xjrsoft.common.utils.VoToColumnUtil;
  21. import com.xjrsoft.module.base.entity.BaseClass;
  22. import com.xjrsoft.module.base.mapper.BaseClassMapper;
  23. import com.xjrsoft.module.organization.entity.Department;
  24. import com.xjrsoft.module.student.dto.AddBaseStudentCadreDto;
  25. import com.xjrsoft.module.student.dto.BaseStudentCadrePageDto;
  26. import com.xjrsoft.module.student.dto.UpdateBaseStudentCadreDto;
  27. import com.xjrsoft.module.student.entity.BaseStudent;
  28. import com.xjrsoft.module.student.entity.BaseStudentCadre;
  29. import com.xjrsoft.module.student.entity.BaseStudentPost;
  30. import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
  31. import com.xjrsoft.module.student.mapper.BaseStudentSchoolRollMapper;
  32. import com.xjrsoft.module.student.service.IBaseStudentCadreService;
  33. import com.xjrsoft.module.student.vo.BaseStudentCadrePageVo;
  34. import com.xjrsoft.module.student.vo.BaseStudentCadreVo;
  35. import com.xjrsoft.module.teacher.entity.XjrUser;
  36. import io.swagger.annotations.Api;
  37. import io.swagger.annotations.ApiOperation;
  38. import lombok.AllArgsConstructor;
  39. import org.springframework.http.ResponseEntity;
  40. import org.springframework.web.bind.annotation.DeleteMapping;
  41. import org.springframework.web.bind.annotation.GetMapping;
  42. import org.springframework.web.bind.annotation.PostMapping;
  43. import org.springframework.web.bind.annotation.PutMapping;
  44. import org.springframework.web.bind.annotation.RequestBody;
  45. import org.springframework.web.bind.annotation.RequestMapping;
  46. import org.springframework.web.bind.annotation.RequestParam;
  47. import org.springframework.web.bind.annotation.RestController;
  48. import javax.validation.Valid;
  49. import java.io.ByteArrayOutputStream;
  50. import java.util.ArrayList;
  51. import java.util.List;
  52. /**
  53. * @title: 学生干部管理
  54. * @Author dzx
  55. * @Date: 2023-11-14
  56. * @Version 1.0
  57. */
  58. @RestController
  59. @RequestMapping("/student" + "/basestudentcadre")
  60. @Api(value = "/student" + "/basestudentcadre",tags = "学生干部管理代码")
  61. @AllArgsConstructor
  62. public class BaseStudentCadreController {
  63. private final IBaseStudentCadreService baseStudentCadreService;
  64. private final BaseStudentSchoolRollMapper baseStudentSchoolRollMapper;
  65. private final BaseClassMapper baseClassMapper;
  66. @GetMapping(value = "/classlist")
  67. @ApiOperation(value="获取班主任管理的班级")
  68. @SaCheckPermission("basestudentcadre:detail")
  69. public RT<List<BaseClass>> classList(){
  70. List<BaseClass> pageOutput = baseClassMapper.selectJoinList(BaseClass.class, new MPJLambdaWrapper<BaseClass>()
  71. .disableSubLogicDel()
  72. .eq(BaseClass::getTeacherId, StpUtil.getLoginIdAsLong())
  73. );
  74. return RT.ok(pageOutput);
  75. }
  76. @GetMapping(value = "/mobliepage")
  77. @ApiOperation(value="学生干部管理列表(移动端分页)")
  78. @SaCheckPermission("basestudentcadre:detail")
  79. public RT<PageOutput<BaseStudentCadrePageVo>> mobliepage(@Valid BaseStudentCadrePageDto dto){
  80. // 如果未传班级id和职务id,
  81. if(!StrUtil.equals(dto.getLevel(), StudentCadreLevelEnum.CLASS.getCode()) && ObjectUtil.isEmpty(dto.getPostId())){
  82. PageOutput<BaseStudentCadrePageVo> result = ConventPage.getPageOutputNull(BaseStudentCadrePageVo.class);
  83. return RT.ok(result);
  84. }
  85. IPage<BaseStudentCadrePageVo> page = baseStudentCadreService.selectJoinListPage(ConventPage.getPage(dto), BaseStudentCadrePageVo.class,
  86. MPJWrappers.<BaseStudentCadre>lambdaJoin()
  87. .like(StrUtil.isNotBlank(dto.getUserName()), XjrUser::getName, dto.getUserName())
  88. .eq(ObjectUtil.isNotEmpty(dto.getClassId()), BaseStudentCadre::getClassId, dto.getClassId())
  89. .eq(ObjectUtil.isNotEmpty(dto.getPostId()), BaseStudentCadre::getPostId, dto.getPostId())
  90. .eq(ObjectUtil.isNotEmpty(dto.getLevel()), BaseStudentPost::getLevel, dto.getLevel())
  91. .eq(ObjectUtil.isNotEmpty(dto.getPost()), BaseStudentPost::getPost, dto.getPost())
  92. .eq(StrUtil.equals(dto.getLevel(), StudentCadreLevelEnum.CLASS.getCode()), BaseClass::getTeacherId, StpUtil.getLoginIdAsLong())
  93. .between(ObjectUtil.isNotNull(dto.getStartTimeStart()) && ObjectUtil.isNotNull(dto.getStartTimeEnd()), BaseStudentCadre::getStartTime,dto.getStartTimeStart(),dto.getStartTimeEnd())
  94. .between(ObjectUtil.isNotNull(dto.getEndTimeStart()) && ObjectUtil.isNotNull(dto.getEndTimeEnd()), BaseStudentCadre::getEndTime,dto.getEndTimeStart(),dto.getEndTimeEnd())
  95. .orderByDesc(BaseStudentCadre::getId)
  96. .selectAs(BaseStudent::getStudentId, BaseStudentCadrePageVo::getStudentId)
  97. .selectAs(XjrUser::getName, BaseStudentCadrePageVo::getUserName)
  98. .selectAs(BaseClass::getName, BaseStudentCadrePageVo::getClassName)
  99. .selectAs(BaseStudentPost::getPost, BaseStudentCadrePageVo::getPost)
  100. .selectAs(BaseStudentPost::getLevel, BaseStudentCadrePageVo::getLevel)
  101. .select(BaseStudentCadre::getId)
  102. .select(BaseStudentCadre.class,x -> VoToColumnUtil.fieldsToColumns(BaseStudentCadrePageVo.class).contains(x.getProperty()))
  103. .innerJoin(XjrUser.class, XjrUser::getId, BaseStudentCadre::getUserId)
  104. .innerJoin(BaseStudent.class, BaseStudent::getUserId, BaseStudentCadre::getUserId)
  105. .innerJoin(BaseStudentPost.class, BaseStudentPost::getId, BaseStudentCadre::getPostId)
  106. .leftJoin(BaseClass.class, BaseClass::getId, BaseStudentCadre::getClassId)
  107. .leftJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, BaseStudentCadre::getUserId)).setSize(15);
  108. PageOutput<BaseStudentCadrePageVo> pageOutput = ConventPage.getPageOutput(page, BaseStudentCadrePageVo.class);
  109. return RT.ok(pageOutput);
  110. }
  111. @GetMapping(value = "/page")
  112. @ApiOperation(value="学生干部管理列表(分页)")
  113. @SaCheckPermission("basestudentcadre:detail")
  114. public RT<PageOutput<BaseStudentCadrePageVo>> page(@Valid BaseStudentCadrePageDto dto){
  115. // 如果未传班级id和职务id,
  116. if(!StrUtil.equals(dto.getLevel(), StudentCadreLevelEnum.CLASS.getCode()) && ObjectUtil.isEmpty(dto.getPostId())){
  117. PageOutput<BaseStudentCadrePageVo> result = ConventPage.getPageOutputNull(BaseStudentCadrePageVo.class);
  118. return RT.ok(result);
  119. }
  120. MPJLambdaWrapper<BaseStudentCadre> wrapper = new MPJLambdaWrapper<>();
  121. wrapper.like(StrUtil.isNotBlank(dto.getUserName()), XjrUser::getName, dto.getUserName())
  122. .eq(ObjectUtil.isNotEmpty(dto.getClassId()), BaseStudentCadre::getClassId, dto.getClassId())
  123. .eq(ObjectUtil.isNotEmpty(dto.getPostId()), BaseStudentCadre::getPostId, dto.getPostId())
  124. .eq(ObjectUtil.isNotEmpty(dto.getLevel()), BaseStudentPost::getLevel, dto.getLevel())
  125. .eq(ObjectUtil.isNotEmpty(dto.getPost()), BaseStudentPost::getPost, dto.getPost())
  126. .eq(StrUtil.equals(dto.getLevel(), StudentCadreLevelEnum.CLASS.getCode()), BaseClass::getTeacherId, StpUtil.getLoginIdAsLong())
  127. .orderByDesc(BaseStudentCadre::getId)
  128. .selectAs(BaseStudent::getStudentId, BaseStudentCadrePageVo::getStudentId)
  129. .selectAs(XjrUser::getName, BaseStudentCadrePageVo::getUserName)
  130. //.selectAs(Department::getName, BaseStudentCadrePageVo::getOrgName)
  131. .selectAs(BaseClass::getName, BaseStudentCadrePageVo::getClassName)
  132. .selectAs(BaseStudentPost::getPost, BaseStudentCadrePageVo::getPost)
  133. .selectAs(BaseStudentPost::getLevel, BaseStudentCadrePageVo::getLevel)
  134. .select(BaseStudentCadre::getId)
  135. .select(BaseStudentCadre.class,x -> VoToColumnUtil.fieldsToColumns(BaseStudentCadrePageVo.class).contains(x.getProperty()))
  136. .innerJoin(XjrUser.class, XjrUser::getId, BaseStudentCadre::getUserId)
  137. .innerJoin(BaseStudent.class, BaseStudent::getUserId, BaseStudentCadre::getUserId)
  138. .innerJoin(BaseStudentPost.class, BaseStudentPost::getId, BaseStudentCadre::getPostId)
  139. .leftJoin(BaseClass.class, BaseClass::getId, BaseStudentCadre::getClassId)
  140. //.leftJoin( Department.class, Department::getId, BaseStudentCadre::getOrgId)
  141. .leftJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, BaseStudentCadre::getUserId);
  142. // 没传ClassID 不用查部门
  143. if(ObjectUtil.isAllNotEmpty(dto.getClassId())&&dto.getClassId()>0) {
  144. wrapper.selectAs(Department::getName, BaseStudentCadrePageVo::getOrgName)
  145. .leftJoin(Department.class, Department::getId, BaseStudentCadre::getOrgId);
  146. }
  147. IPage<BaseStudentCadrePageVo> page = baseStudentCadreService.selectJoinListPage(ConventPage.getPage(dto), BaseStudentCadrePageVo.class,
  148. wrapper
  149. );
  150. PageOutput<BaseStudentCadrePageVo> pageOutput = ConventPage.getPageOutput(page, BaseStudentCadrePageVo.class);
  151. return RT.ok(pageOutput);
  152. }
  153. @GetMapping(value = "/info")
  154. @ApiOperation(value="根据id查询学生干部管理信息")
  155. @SaCheckPermission("basestudentcadre:detail")
  156. public RT<BaseStudentCadreVo> info(@RequestParam Long id){
  157. BaseStudentCadre baseStudentCadre = baseStudentCadreService.getById(id);
  158. if (baseStudentCadre == null) {
  159. return RT.error("找不到此数据!");
  160. }
  161. return RT.ok(BeanUtil.toBean(baseStudentCadre, BaseStudentCadreVo.class));
  162. }
  163. @PostMapping
  164. @ApiOperation(value = "新增学生干部管理(批量新增)")
  165. @SaCheckPermission("basestudentcadre:add")
  166. public RT<Boolean> add(@Valid @RequestBody List<AddBaseStudentCadreDto> dto){
  167. //循环判定,是否已经存在于数据库,并查询出班级id
  168. List<AddBaseStudentCadreDto> addDtoList = new ArrayList<>();
  169. for (AddBaseStudentCadreDto baseStudentCadreDto : dto) {
  170. List<BaseStudentCadre> list = baseStudentCadreService.list(
  171. Wrappers.lambdaQuery(BaseStudentCadre.class)
  172. .eq(BaseStudentCadre::getUserId, baseStudentCadreDto.getUserId())
  173. .eq(BaseStudentCadre::getPostId, baseStudentCadreDto.getPostId())
  174. );
  175. if(ObjectUtil.isNotNull(list) && list.size() == 1){
  176. continue;
  177. }
  178. BaseStudentSchoolRoll baseStudentSchoolRoll = baseStudentSchoolRollMapper.selectOne(Wrappers.lambdaQuery(BaseStudentSchoolRoll.class).eq(BaseStudentSchoolRoll::getUserId, baseStudentCadreDto.getUserId()));
  179. if(ObjectUtil.isNotNull(baseStudentSchoolRoll)){
  180. baseStudentCadreDto.setClassId(baseStudentSchoolRoll.getClassId());
  181. }
  182. addDtoList.add(baseStudentCadreDto);
  183. }
  184. List<BaseStudentCadre> baseStudentCadreList = BeanUtil.copyToList(addDtoList, BaseStudentCadre.class);
  185. boolean isSuccess = baseStudentCadreService.addAll(baseStudentCadreList);
  186. return RT.ok(isSuccess);
  187. }
  188. @PostMapping("/addone")
  189. @ApiOperation(value = "新增学生干部管理(单个添加)")
  190. @SaCheckPermission("basestudentcadre:insert")
  191. public RT<Boolean> addOne(@Valid @RequestBody AddBaseStudentCadreDto dto){
  192. //判定,是否已经存在于数据库,并查询出班级id
  193. BaseStudentCadre one = baseStudentCadreService.getOne(
  194. Wrappers.lambdaQuery(BaseStudentCadre.class)
  195. .eq(BaseStudentCadre::getUserId, dto.getUserId())
  196. .eq(BaseStudentCadre::getPostId, dto.getPostId())
  197. );
  198. if(ObjectUtil.isNotNull(one)){
  199. return RT.error("该学生已有该职务,无法重复添加");
  200. }
  201. BaseStudentSchoolRoll baseStudentSchoolRoll = baseStudentSchoolRollMapper.selectOne(Wrappers.lambdaQuery(BaseStudentSchoolRoll.class).eq(BaseStudentSchoolRoll::getUserId, dto.getUserId()));
  202. if(ObjectUtil.isNotNull(baseStudentSchoolRoll)){
  203. dto.setClassId(baseStudentSchoolRoll.getClassId());
  204. }
  205. BaseStudentCadre baseStudentCadre = BeanUtil.toBean(dto, BaseStudentCadre.class);
  206. boolean isSuccess = baseStudentCadreService.addOne(baseStudentCadre);
  207. return RT.ok(isSuccess);
  208. }
  209. @PutMapping("/editStatus")
  210. @ApiOperation(value = "修改学生干部状态(离职、复职)")
  211. @SaCheckPermission("basestudentcadre:edit")
  212. public RT<Boolean> editStatus(@Valid @RequestBody UpdateBaseStudentCadreDto dto){
  213. if(ObjectUtil.isNull(dto) || ObjectUtil.isNull(dto.getId()) || ObjectUtil.isNull(dto.getStatus()) ||
  214. (dto.getStatus() != null && dto.getStatus() == 1 && ObjectUtil.isNull(dto.getLeaveTime()))){
  215. String msg = "请传入id、status";
  216. if(dto.getStatus() != null && dto.getStatus() == 1 && ObjectUtil.isNull(dto.getLeaveTime())){
  217. msg = "请传入id、status和leaveTime";
  218. }
  219. return RT.error(msg);
  220. }
  221. BaseStudentCadre baseStudentCadre = BeanUtil.toBean(dto, BaseStudentCadre.class);
  222. return RT.ok(baseStudentCadreService.updateById(baseStudentCadre));
  223. }
  224. @PutMapping
  225. @ApiOperation(value = "修改学生干部管理")
  226. @SaCheckPermission("basestudentcadre:edit")
  227. public RT<Boolean> update(@Valid @RequestBody UpdateBaseStudentCadreDto dto){
  228. BaseStudentCadre baseStudentCadre = BeanUtil.toBean(dto, BaseStudentCadre.class);
  229. return RT.ok(baseStudentCadreService.updateById(baseStudentCadre));
  230. }
  231. @DeleteMapping
  232. @ApiOperation(value = "删除学生干部管理")
  233. @SaCheckPermission("basestudentcadre:delete")
  234. public RT<Boolean> delete(@Valid @RequestBody List<Long> ids){
  235. return RT.ok(baseStudentCadreService.removeBatchByIds(ids));
  236. }
  237. @GetMapping("/export")
  238. @ApiOperation(value = "导出")
  239. public ResponseEntity<byte[]> exportData(@Valid BaseStudentCadrePageDto dto, @RequestParam(defaultValue = "false") Boolean isTemplate) {
  240. List<BaseStudentCadrePageVo> customerList = isTemplate != null && isTemplate ? new ArrayList<>() : ((PageOutput<BaseStudentCadrePageVo>) page(dto).getData()).getList();
  241. ByteArrayOutputStream bot = new ByteArrayOutputStream();
  242. EasyExcel.write(bot, BaseStudentCadrePageVo.class).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(customerList);
  243. return RT.fileStream(bot.toByteArray(), "BaseStudentCadre" + ExcelTypeEnum.XLSX.getValue());
  244. }
  245. }