BaseStudentSchoolRollServiceImpl.java 17 KB

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