BaseStudentSchoolRollServiceImpl.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. package com.xjrsoft.module.student.service.impl;
  2. import cn.dev33.satoken.stp.StpUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import com.github.yulichang.base.MPJBaseServiceImpl;
  8. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  9. import com.xjrsoft.common.enums.*;
  10. import com.xjrsoft.common.utils.VoToColumnUtil;
  11. import com.xjrsoft.module.base.entity.BaseClass;
  12. import com.xjrsoft.module.base.mapper.BaseClassMapper;
  13. import com.xjrsoft.module.organization.entity.User;
  14. import com.xjrsoft.module.organization.mapper.UserMapper;
  15. import com.xjrsoft.module.room.mapper.RoomBedMapper;
  16. import com.xjrsoft.module.room.vo.RoomBedInfoVo;
  17. import com.xjrsoft.module.student.dto.*;
  18. import com.xjrsoft.module.student.entity.BaseStudent;
  19. import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
  20. import com.xjrsoft.module.student.mapper.BaseStudentMapper;
  21. import com.xjrsoft.module.student.mapper.BaseStudentSchoolRollMapper;
  22. import com.xjrsoft.module.student.mapper.PbSemesterConfigMapper;
  23. import com.xjrsoft.module.student.mapper.PbVXsxxsfytbMapper;
  24. import com.xjrsoft.module.student.service.IBaseStudentSchoolRollService;
  25. import com.xjrsoft.module.student.service.IStudentChangeRecordService;
  26. import com.xjrsoft.module.student.vo.*;
  27. import lombok.AllArgsConstructor;
  28. import org.springframework.stereotype.Service;
  29. import org.springframework.transaction.annotation.Transactional;
  30. import java.time.LocalDateTime;
  31. import java.util.ArrayList;
  32. import java.util.HashMap;
  33. import java.util.List;
  34. import java.util.Map;
  35. /**
  36. * @title: 助学金申请
  37. * @Author dzx
  38. * @Date: 2023-11-24
  39. * @Version 1.0
  40. */
  41. @Service
  42. @AllArgsConstructor
  43. public class BaseStudentSchoolRollServiceImpl extends MPJBaseServiceImpl<BaseStudentSchoolRollMapper, BaseStudentSchoolRoll> implements IBaseStudentSchoolRollService {
  44. private final BaseStudentSchoolRollMapper baseStudentSchoolRollMapper;
  45. private final RoomBedMapper roomBedMapper;
  46. private final BaseClassMapper baseClassMapper;
  47. private final PbSemesterConfigMapper pbSemesterConfigMapper;
  48. private final PbVXsxxsfytbMapper pbVXsxxsfytbMapper;
  49. private final UserMapper userMapper;
  50. private final IStudentChangeRecordService recordService;
  51. private final BaseStudentMapper baseStudentMapper;
  52. @Override
  53. public Page<BaseStudentInfoPageVo> getMobilePage(Page<BaseStudentInfoPageVo> page, BaseStudentInfoPageDto dto) {
  54. List<String> roleList = StpUtil.getRoleList();
  55. long teacherId = StpUtil.getLoginIdAsLong();
  56. List<BaseClass> classList = baseClassMapper.selectList(
  57. new QueryWrapper<BaseClass>().lambda().eq(BaseClass::getTeacherId, teacherId)
  58. .eq(BaseClass::getDeleteMark, DeleteMark.NODELETE.getCode())
  59. );
  60. if (roleList.size() == 1 && roleList.contains("CLASSTE")) {
  61. if (classList != null && !classList.isEmpty()) {
  62. dto.setTeacherId(teacherId);
  63. }
  64. } else {
  65. if (classList != null && !classList.isEmpty() && dto.getClassId() == null) {
  66. dto.setClassId(classList.get(0).getId());
  67. }
  68. }
  69. String lastBeltcode = pbSemesterConfigMapper.getLastBeltcode();
  70. dto.setBeltcode(lastBeltcode);
  71. Page<BaseStudentInfoPageVo> mobilePage = baseStudentSchoolRollMapper.getMobilePage(page, dto);
  72. List<String> studentCodes = new ArrayList<>();
  73. for (BaseStudentInfoPageVo record : mobilePage.getRecords()) {
  74. studentCodes.add(record.getStudentId());
  75. }
  76. PbVXsxxsfytbDto dto2 = new PbVXsxxsfytbDto();
  77. dto2.setStudentCodes(studentCodes);
  78. dto2.setBeltcode(lastBeltcode);
  79. List<PbVXsxxsfytbVo> list = pbVXsxxsfytbMapper.getList(dto2);
  80. Map<String, String> jfztMaps = new HashMap<>();
  81. for (PbVXsxxsfytbVo pbVXsxxsfytb : list) {
  82. jfztMaps.put(pbVXsxxsfytb.getStudentcode() + pbVXsxxsfytb.getFeeitemcode(), pbVXsxxsfytb.getJfzt().replaceAll("未缴费", "欠费"));
  83. }
  84. for (BaseStudentInfoPageVo record : mobilePage.getRecords()) {
  85. record.setSsf(jfztMaps.get(record.getStudentId() + "103042766003001") == null ? "欠费" : jfztMaps.get(record.getStudentId() + "103042766003001"));
  86. record.setJxf(jfztMaps.get(record.getStudentId() + "999010604") == null ? "欠费" : jfztMaps.get(record.getStudentId() + "999010604"));
  87. record.setJcf(jfztMaps.get(record.getStudentId() + "999010603") == null ? "欠费" : jfztMaps.get(record.getStudentId() + "999010603"));
  88. }
  89. return mobilePage;
  90. }
  91. @Override
  92. public Boolean updateInfo(UpdateBaseStudentInfoDto dto) {
  93. for (Long id : dto.getUserIds()) {
  94. BaseStudentSchoolRoll schoolRoll = this.getOne(new QueryWrapper<BaseStudentSchoolRoll>().lambda().eq(BaseStudentSchoolRoll::getUserId, id));
  95. if (!dto.getStduyStatus().equals(schoolRoll.getStduyStatus())) {
  96. recordService.insertData(
  97. StudyStatusEnum.fromCode(schoolRoll.getStduyStatus()),
  98. schoolRoll.getStduyStatus(),
  99. StudyStatusEnum.fromCode(dto.getStduyStatus()),
  100. dto.getStduyStatus(),
  101. id,
  102. StpUtil.getLoginIdAsLong(),
  103. StudentChangeTypeEnum.StduyStatus.getCode(),
  104. 2
  105. );
  106. }
  107. if (!dto.getRollModality().equals(schoolRoll.getLearnStatus())) {
  108. recordService.insertData(
  109. RollModalityEnum.fromCode(schoolRoll.getLearnStatus()),
  110. schoolRoll.getLearnStatus(),
  111. RollModalityEnum.fromCode(dto.getRollModality()),
  112. dto.getRollModality(),
  113. id,
  114. StpUtil.getLoginIdAsLong(),
  115. StudentChangeTypeEnum.LearnStatus.getCode(),
  116. 2
  117. );
  118. }
  119. if (schoolRoll.getArchivesStatus() != null && !schoolRoll.getArchivesStatus().equals(dto.getArchivesStatus())) {
  120. recordService.insertData(
  121. ArchivesStatusEnum.fromCode(schoolRoll.getArchivesStatus()),
  122. schoolRoll.getArchivesStatus(),
  123. ArchivesStatusEnum.fromCode(dto.getArchivesStatus()),
  124. dto.getArchivesStatus(),
  125. id,
  126. StpUtil.getLoginIdAsLong(),
  127. StudentChangeTypeEnum.ArchivesStatus.getCode(),
  128. 2
  129. );
  130. }
  131. baseStudentSchoolRollMapper.updateInfoByUserId(dto, id);
  132. }
  133. return true;
  134. }
  135. @Override
  136. public BaseStudentInfoDetailVo getInfoById(BaseStudentInfoDetailDto dto) {
  137. String lastBeltcode = pbSemesterConfigMapper.getLastBeltcode();
  138. dto.setBeltcode(lastBeltcode);
  139. BaseStudentInfoDetailVo info = baseStudentSchoolRollMapper.getInfoById(dto);
  140. RoomBedInfoVo bedInfoByUserId = roomBedMapper.getBedInfoByUserId(info.getId());
  141. if (bedInfoByUserId != null) {
  142. info.setBedInfo(bedInfoByUserId.getBuildName() + " " + bedInfoByUserId.getRoomName() + " " + bedInfoByUserId.getBedNumber());
  143. }
  144. return info;
  145. }
  146. @Override
  147. public BaseStudentInfoPageDataVo getMobilePageStatistics(BaseStudentInfoPageDto dto) {
  148. List<String> roleList = StpUtil.getRoleList();
  149. long teacherId = StpUtil.getLoginIdAsLong();
  150. List<BaseClass> classList = baseClassMapper.selectList(
  151. new QueryWrapper<BaseClass>().lambda()
  152. .eq(BaseClass::getTeacherId, teacherId)
  153. .eq(BaseClass::getDeleteMark, DeleteMark.NODELETE.getCode())
  154. );
  155. if (roleList.size() == 1 && roleList.contains("CLASSTE")) {
  156. if (classList != null && !classList.isEmpty()) {
  157. dto.setTeacherId(teacherId);
  158. }
  159. } else {
  160. if (classList != null && !classList.isEmpty() && dto.getClassId() == null) {
  161. dto.setClassId(classList.get(0).getId());
  162. }
  163. }
  164. List<BaseStudentInfoCategoryVo> genderCount = baseStudentSchoolRollMapper.getGenderCount(dto);
  165. int totalCount = 0;
  166. BaseStudentInfoPageDataVo result = new BaseStudentInfoPageDataVo();
  167. for (BaseStudentInfoCategoryVo categoryVo : genderCount) {
  168. totalCount = totalCount + categoryVo.getNumber();
  169. if ("男".equals(GenderDictionaryEnum.getValue(categoryVo.getCategory()))) {
  170. result.setMaleCount(categoryVo.getNumber());
  171. } else if ("女".equals(GenderDictionaryEnum.getValue(categoryVo.getCategory()))) {
  172. result.setFemaleCount(categoryVo.getNumber());
  173. }
  174. }
  175. result.setTotalCount(totalCount);
  176. List<BaseStudentInfoCategoryVo> studyStatusCount = baseStudentSchoolRollMapper.getStudyStatusCount(dto);
  177. int stayCount = 0;
  178. int notStayCount = 0;
  179. for (BaseStudentInfoCategoryVo categoryVo : studyStatusCount) {
  180. if (StudyStatusEnum.InResidence.getCode().equals(categoryVo.getCategory())) {
  181. stayCount = stayCount + categoryVo.getNumber();
  182. if ("男".equals(GenderDictionaryEnum.getValue(categoryVo.getGender()))) {
  183. result.setMaleStayCount(categoryVo.getNumber());
  184. } else if ("女".equals(GenderDictionaryEnum.getValue(categoryVo.getGender()))) {
  185. result.setFemaleStayCount(categoryVo.getNumber());
  186. }
  187. } else if (StudyStatusEnum.AttendDaySchool.getCode().equals(categoryVo.getCategory())) {
  188. notStayCount = notStayCount + categoryVo.getNumber();
  189. if ("男".equals(GenderDictionaryEnum.getValue(categoryVo.getGender()))) {
  190. result.setMaleNotStayCount(categoryVo.getNumber());
  191. } else if ("女".equals(GenderDictionaryEnum.getValue(categoryVo.getGender()))) {
  192. result.setFemaleNotStayCount(categoryVo.getNumber());
  193. }
  194. }
  195. }
  196. result.setStayCount(stayCount);
  197. result.setNotStayCount(notStayCount);
  198. return result;
  199. }
  200. @Override
  201. public MobileClassStatisticsVo getMobileClassStatistics(BaseStudentInfoPageDto dto) {
  202. //获取当前用户的班级
  203. LambdaQueryWrapper<BaseClass> baseClassLambdaQueryWrapper = new LambdaQueryWrapper<>();
  204. baseClassLambdaQueryWrapper
  205. .eq(BaseClass::getTeacherId, StpUtil.getLoginIdAsLong());
  206. List<BaseClass> baseClassList = baseClassMapper.selectList(baseClassLambdaQueryWrapper);
  207. //如果集合不为空,表示该登录用户是班主任
  208. if (baseClassList != null && !baseClassList.isEmpty()) {
  209. for (BaseClass baseClass : baseClassList) {
  210. }
  211. } else {
  212. }
  213. return null;
  214. }
  215. @Override
  216. @Transactional(rollbackFor = Exception.class)
  217. public Boolean updateStudentClass(Long classId, Long majorSetId, Long userId) {
  218. return baseStudentSchoolRollMapper.updateStudentClass1(classId, majorSetId, userId);
  219. }
  220. @Override
  221. public Boolean updateStudentClassGradeMajorStduyStatus(Long classId, Long gradeId, Long majorSetId, String stduyStatus, Long userId) {
  222. return this.baseMapper.updateStudentClassGradeMajorStduyStatus(classId, gradeId, majorSetId, stduyStatus, userId);
  223. }
  224. @Override
  225. @Transactional(rollbackFor = Exception.class)
  226. public Boolean updateStudentClass(Long classId, Long userId) {
  227. return baseStudentSchoolRollMapper.updateStudentClass(classId, userId);
  228. }
  229. @Override
  230. public List<BaseStudentSompleInfoVo> getInfosByParam(BaseStudentSimpleInfoDto dto) {
  231. List<BaseStudentSompleInfoVo> userList = userMapper.getInfosByParam(dto);
  232. return userList;
  233. }
  234. public String getClassNameByUserId(Long userId) {
  235. return baseStudentSchoolRollMapper.getClassNameByUserId(userId);
  236. }
  237. public Long getClassIdByUserId(Long userId) {
  238. return baseStudentSchoolRollMapper.getClassIdByUserId(userId);
  239. }
  240. /**
  241. * 激活学生信息
  242. *
  243. * @param userId 学生用户信息
  244. */
  245. @Override
  246. @Transactional(rollbackFor = Exception.class)
  247. public Boolean activateStudent(Long userId) {
  248. //激活用户信息
  249. User user = userMapper.selectById(userId);
  250. user.setDeleteMark(DeleteMark.NODELETE.getCode());
  251. user.setEnabledMark(EnabledMark.ENABLED.getCode());
  252. user.setModifyUserId(StpUtil.getLoginIdAsLong());
  253. user.setModifyDate(LocalDateTime.now());
  254. userMapper.updateById(user);
  255. //将学籍信息改为在读
  256. BaseStudentSchoolRoll schoolRoll = this.baseMapper.selectOne(
  257. new MPJLambdaWrapper<BaseStudentSchoolRoll>()
  258. .disableLogicDel()
  259. .select(BaseStudentSchoolRoll::getId)
  260. .select(BaseStudentSchoolRoll.class, x -> VoToColumnUtil.fieldsToColumns(BaseStudentSchoolRoll.class).contains(x.getProperty()))
  261. .eq(BaseStudentSchoolRoll::getUserId, userId)
  262. );
  263. schoolRoll.setDeleteMark(DeleteMark.NODELETE.getCode());
  264. schoolRoll.setEnabledMark(EnabledMark.ENABLED.getCode());
  265. schoolRoll.setArchivesStatus(ArchivesStatusEnum.FB2901.getCode());
  266. schoolRoll.setModifyUserId(StpUtil.getLoginIdAsLong());
  267. schoolRoll.setModifyDate(LocalDateTime.now());
  268. this.updateById(schoolRoll);
  269. //将学生基本信息中状态改为正常
  270. BaseStudent baseStudent = baseStudentMapper.selectOne(
  271. new QueryWrapper<BaseStudent>().lambda()
  272. .eq(BaseStudent::getUserId, userId)
  273. );
  274. baseStudent.setIsNormal(1);
  275. baseStudent.setModifyUserId(StpUtil.getLoginIdAsLong());
  276. baseStudent.setModifyDate(LocalDateTime.now());
  277. baseStudentMapper.updateById(baseStudent);
  278. return true;
  279. }
  280. @Override
  281. @Transactional(rollbackFor = Exception.class)
  282. public Boolean disableStudent(Long userId) {
  283. return disableStudent(userId, StpUtil.getLoginIdAsLong());
  284. }
  285. /**
  286. * 禁用学生
  287. *
  288. * @param userId
  289. * @return
  290. */
  291. @Override
  292. @Transactional(rollbackFor = Exception.class)
  293. public Boolean disableStudent(Long userId, Long modifyUserId) {
  294. //激活用户信息
  295. User user = userMapper.selectById(userId);
  296. user.setDeleteMark(DeleteMark.DELETED.getCode());
  297. user.setEnabledMark(EnabledMark.DISABLED.getCode());
  298. user.setModifyUserId(modifyUserId);
  299. user.setModifyDate(LocalDateTime.now());
  300. userMapper.updateById(user);
  301. //将学籍信息改为在读
  302. BaseStudentSchoolRoll schoolRoll = this.getOne(
  303. new MPJLambdaWrapper<BaseStudentSchoolRoll>()
  304. .disableLogicDel()
  305. .select(BaseStudentSchoolRoll::getId)
  306. .select(BaseStudentSchoolRoll.class, x -> VoToColumnUtil.fieldsToColumns(BaseStudentSchoolRoll.class).contains(x.getProperty()))
  307. .eq(BaseStudentSchoolRoll::getUserId, userId)
  308. );
  309. UpdateWrapper<BaseStudentSchoolRoll> updateRoll = new UpdateWrapper<>();
  310. updateRoll.eq("id", schoolRoll.getId());
  311. updateRoll.setSql("delete_mark = 1");
  312. updateRoll.setSql("enabled_mark = 0");
  313. // updateRoll.setSql("class_id = null");
  314. updateRoll.setSql("modify_user_id = " + modifyUserId);
  315. updateRoll.setSql("modify_date = now()");
  316. this.update(schoolRoll, updateRoll);
  317. //将学生基本信息中状态改为正常
  318. BaseStudent baseStudent = baseStudentMapper.selectOne(
  319. new QueryWrapper<BaseStudent>().lambda()
  320. .eq(BaseStudent::getUserId, userId)
  321. );
  322. baseStudent.setIsNormal(0);
  323. baseStudent.setModifyUserId(modifyUserId);
  324. baseStudent.setModifyDate(LocalDateTime.now());
  325. baseStudentMapper.updateById(baseStudent);
  326. return true;
  327. }
  328. }