ExamRegistrationServiceImpl.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. package com.keao.edu.user.service.impl;
  2. import com.keao.edu.auth.api.client.SysUserFeignService;
  3. import com.keao.edu.auth.api.entity.SysUser;
  4. import com.keao.edu.common.dal.BaseDAO;
  5. import com.keao.edu.common.entity.SysConfig;
  6. import com.keao.edu.common.enums.MessageTypeEnum;
  7. import com.keao.edu.common.exception.BizException;
  8. import com.keao.edu.common.page.PageInfo;
  9. import com.keao.edu.common.page.QueryInfo;
  10. import com.keao.edu.common.service.IdGeneratorService;
  11. import com.keao.edu.common.service.SysMessageService;
  12. import com.keao.edu.common.service.impl.BaseServiceImpl;
  13. import com.keao.edu.thirdparty.message.provider.JiguangPushPlugin;
  14. import com.keao.edu.thirdparty.message.provider.YimeiSmsPlugin;
  15. import com.keao.edu.user.dao.*;
  16. import com.keao.edu.user.dto.*;
  17. import com.keao.edu.user.entity.*;
  18. import com.keao.edu.user.enums.ExamStatusEnum;
  19. import com.keao.edu.user.enums.StudentRegistrationStatusEnum;
  20. import com.keao.edu.user.enums.TransStatusEnum;
  21. import com.keao.edu.user.page.ApplyListQueryInfo;
  22. import com.keao.edu.user.page.ExamRecordQueryInfo;
  23. import com.keao.edu.user.page.ExamRegistrationQueryInfo;
  24. import com.keao.edu.user.service.*;
  25. import com.keao.edu.util.collection.MapUtil;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.transaction.annotation.Transactional;
  29. import java.math.BigDecimal;
  30. import java.util.*;
  31. import java.util.stream.Collectors;
  32. @Service
  33. public class ExamRegistrationServiceImpl extends BaseServiceImpl<Long, ExamRegistration> implements ExamRegistrationService {
  34. @Autowired
  35. private ExamRegistrationDao examRegistrationDao;
  36. @Autowired
  37. private ExaminationBasicDao examinationBasicDao;
  38. @Autowired
  39. private OrganizationService organizationService;
  40. @Autowired
  41. private PayService payService;
  42. @Autowired
  43. private ExamSubjectSongDao examSubjectSongDao;
  44. @Autowired
  45. private ExamMusicTheoryDao examMusicTheoryDao;
  46. @Autowired
  47. private IdGeneratorService idGeneratorService;
  48. @Autowired
  49. private SysConfigDao sysConfigDao;
  50. @Autowired
  51. private ExamRegistrationPaymentService examRegistrationPaymentService;
  52. @Autowired
  53. private OrganizationDao organizationDao;
  54. @Autowired
  55. private SysMessageService sysMessageService;
  56. @Autowired
  57. private SysUserDao sysUserDao;
  58. @Autowired
  59. private SysUserFeignService sysUserFeignService;
  60. @Autowired
  61. private SysConfigService sysConfigService;
  62. @Override
  63. public BaseDAO<Long, ExamRegistration> getDAO() {
  64. return examRegistrationDao;
  65. }
  66. @Override
  67. @Transactional(rollbackFor = Exception.class)
  68. public Map<String, Object> addRegistration(ExamRegistration examRegistration) throws Exception {
  69. ExaminationBasic examinationBasic = examinationBasicDao.get(examRegistration.getExaminationBasicId());
  70. if (examinationBasic == null || !examinationBasic.getStatus().equals(ExamStatusEnum.APPLYING)) {
  71. throw new BizException("项目不在报名中,请核对");
  72. }
  73. //考试级别信息
  74. ExamSubjectSong examSubjectSong = examSubjectSongDao.get(examRegistration.getExamSubjectSongId());
  75. if (examSubjectSong == null) {
  76. throw new BizException("请选择专业级别");
  77. }
  78. if (examRegistration.getOrganId() == null) {
  79. throw new BizException("机构id不能为空");
  80. }
  81. Organization organization = organizationDao.get(examRegistration.getOrganId());
  82. if (organization == null) {
  83. throw new BizException("机构不存在");
  84. }
  85. List<StudentRegistrationStatusEnum> statusEnumList = new ArrayList<>();
  86. statusEnumList.add(StudentRegistrationStatusEnum.AUDIT_WAIT);
  87. statusEnumList.add(StudentRegistrationStatusEnum.AUDIT_REJECT);
  88. statusEnumList.add(StudentRegistrationStatusEnum.AUDIT_PASS);
  89. ExamRegistration registration = examRegistrationDao.getRegistration(examinationBasic.getId(),
  90. examRegistration.getStudentId(), examRegistration.getSubjectId(), examSubjectSong.getLevel(),
  91. statusEnumList);
  92. if (registration != null) {
  93. throw new BizException("该考级相同专业及等级您已报名,请勿重复报名");
  94. }
  95. Date nowDate = new Date();
  96. String orderNo = idGeneratorService.generatorId("payment") + "";
  97. examRegistration.setLevel(examSubjectSong.getLevel());
  98. BigDecimal amount = examSubjectSong.getRegistrationFee();
  99. //乐理考试级别
  100. ExamMusicTheory examMusicTheory = null;
  101. BigDecimal theoryLevelFee = BigDecimal.ZERO;
  102. if (examRegistration.getExamMusicTheoryId() != null) {
  103. examMusicTheory = examMusicTheoryDao.get(examRegistration.getExamMusicTheoryId());
  104. }
  105. if (examMusicTheory != null) {
  106. theoryLevelFee = examMusicTheory.getFee();
  107. examRegistration.setExamMusicTheoryLevel(examMusicTheory.getLevel());
  108. amount = amount.add(theoryLevelFee);
  109. }
  110. examRegistration.setTenantId(organization.getTenantId());
  111. examRegistration.setStatus(StudentRegistrationStatusEnum.PAY_WAIT);
  112. examRegistration.setLevelFee(examSubjectSong.getRegistrationFee());
  113. examRegistration.setTheoryLevelFee(theoryLevelFee);
  114. examRegistration.setCreateTime(nowDate);
  115. examRegistration.setUpdateTime(nowDate);
  116. examRegistrationDao.insert(examRegistration);
  117. ExamRegistrationPayment examRegistrationPayment = new ExamRegistrationPayment();
  118. examRegistrationPayment.setTenantId(examinationBasic.getTenantId());
  119. examRegistrationPayment.setOrganId(examRegistration.getOrganId());
  120. examRegistrationPayment.setExamRegistrationId(examRegistration.getId().longValue());
  121. examRegistrationPayment.setStudentId(examRegistration.getStudentId());
  122. examRegistrationPayment.setExaminationBasicId(examRegistration.getExaminationBasicId());
  123. examRegistrationPayment.setOrderNo(orderNo);
  124. examRegistrationPayment.setTransAmount(amount);
  125. examRegistrationPayment.setTransStatus(TransStatusEnum.ING);
  126. examRegistrationPayment.setCreateTime(nowDate);
  127. examRegistrationPayment.setUpdateTime(nowDate);
  128. examRegistrationPaymentService.insert(examRegistrationPayment);
  129. HashMap<String, Object> rpMap = new HashMap<>();
  130. String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
  131. Map<String, Object> payMap = payService.getPayMap(
  132. amount,
  133. orderNo,
  134. baseApiUrl + "/api-user/examOrder/notify",
  135. baseApiUrl + "/api-user/examOrder/paymentResult?orderNo=" + orderNo,
  136. examinationBasic.getName(),
  137. examinationBasic.getName()
  138. );
  139. examRegistrationPayment.setMerNo((String) payMap.get("routingMerNos"));
  140. examRegistrationPayment.setPayType((String) payMap.get("type"));
  141. examRegistrationPaymentService.update(examRegistrationPayment);
  142. rpMap.put("examRegister", examRegistration);
  143. rpMap.put("payMap", payMap);
  144. return rpMap;
  145. }
  146. @Override
  147. public PageInfo<ExamRegistrationRoomDto> queryExamRegistrationStudents(ExamRegistrationQueryInfo queryInfo) {
  148. PageInfo<ExamRegistrationRoomDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
  149. Map<String, Object> params = new HashMap<String, Object>();
  150. MapUtil.populateMap(params, queryInfo);
  151. if (Objects.nonNull(queryInfo.getExamId())) {
  152. List<Integer> nextLevelOrganIds = organizationService.getChildOrganIds(queryInfo.getOrganId(), true);
  153. params.put("organIds", nextLevelOrganIds);
  154. params.put("organId", null);
  155. }
  156. List<ExamRegistrationRoomDto> dataList = Collections.EMPTY_LIST;
  157. int count = examRegistrationDao.countExamRegist(params);
  158. if (count > 0) {
  159. pageInfo.setTotal(count);
  160. params.put("offset", pageInfo.getOffset());
  161. dataList = examRegistrationDao.queryExamRegist(params);
  162. List<Long> examIds = dataList.stream().filter(e -> Objects.nonNull(e.getOrganId())).map(ExamRegistration::getExaminationBasicId).collect(Collectors.toList());
  163. Map<Long, String> examIdNameMap = this.getMap("examination_basic", "id_", "name_", examIds, Long.class, String.class);
  164. List<Integer> organIds = dataList.stream().filter(e -> Objects.nonNull(e.getOrganId())).map(ExamRegistration::getOrganId).collect(Collectors.toList());
  165. Map<Integer, String> organIdNameMap = this.getMap("organization", "id_", "name_", organIds, Integer.class, String.class);
  166. List<Integer> subjectIds = dataList.stream().map(ExamRegistration::getSubjectId).collect(Collectors.toList());
  167. Map<Integer, String> subjectIdNameMap = this.getMap("subject", "id_", "name_", subjectIds, Integer.class, String.class);
  168. List<Integer> studentIds = dataList.stream().map(ExamRegistration::getStudentId).collect(Collectors.toList());
  169. Map<Integer, String> idPhotoMap = this.getMap("student", "user_id_", "certificate_photo_", studentIds, Integer.class, String.class);
  170. List<Integer> registIds = dataList.stream().map(ExamRegistrationRoomDto::getId).collect(Collectors.toList());
  171. Map<Integer, Integer> registExamStatusMap = this.getMap("student_exam_result", "exam_registration_id_", "is_finished_exam_", registIds, Integer.class, Integer.class);
  172. for (ExamRegistrationRoomDto examRegistration : dataList) {
  173. examRegistration.setOrganization(new Organization(examRegistration.getOrganId(), organIdNameMap.get(examRegistration.getOrganId())));
  174. examRegistration.getSubject().setName(subjectIdNameMap.get(examRegistration.getSubjectId()));
  175. examRegistration.getSysUser().setCertificatePhoto(idPhotoMap.get(examRegistration.getStudentId()));
  176. examRegistration.setIsFinishedExam(registExamStatusMap.get(examRegistration.getId()));
  177. examRegistration.setExaminationBasic(new ExaminationBasic(examRegistration.getExaminationBasicId(), examIdNameMap.get(examRegistration.getExaminationBasicId())));
  178. }
  179. }
  180. pageInfo.setRows(dataList);
  181. return pageInfo;
  182. }
  183. @Override
  184. public ExamRegistrationStatisticsDto getExamRegistrationStaticsInfo(Integer organId, Integer examId) {
  185. List<Integer> childOrganIds = organizationService.getChildOrganIds(organId, true);
  186. ExamRegistrationStatisticsDto examRegistrationStaticsInfo = examRegistrationDao.getExamRegistrationStaticsInfo(organId, childOrganIds, examId);
  187. if (Objects.isNull(examRegistrationStaticsInfo)) {
  188. examRegistrationStaticsInfo = new ExamRegistrationStatisticsDto();
  189. }
  190. return examRegistrationStaticsInfo;
  191. }
  192. @Override
  193. public PageInfo<ExamRegistrationDto> applyList(ApplyListQueryInfo queryInfo) {
  194. PageInfo<ExamRegistrationDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
  195. Map<String, Object> params = new HashMap<String, Object>();
  196. MapUtil.populateMap(params, queryInfo);
  197. SysUser sysUser = sysUserFeignService.queryUserInfo();
  198. params.put("studentId",sysUser.getId());
  199. List<ExamRegistrationDto> dataList = null;
  200. int count = examRegistrationDao.countStudentList(params);
  201. if (count > 0) {
  202. pageInfo.setTotal(count);
  203. params.put("offset", pageInfo.getOffset());
  204. dataList = examRegistrationDao.queryStudentList(params);
  205. List<Integer> subjectIds = dataList.stream().map(e -> e.getSubjectId()).collect(Collectors.toList());
  206. Map<Integer, String> subjectNameMap = this.getMap("subject", "id_", "name_", subjectIds, Integer.class, String.class);
  207. dataList.forEach(e -> {
  208. e.setSubjectName(subjectNameMap.get(e.getSubjectId()));
  209. });
  210. }
  211. if (count == 0) {
  212. dataList = new ArrayList<>();
  213. }
  214. pageInfo.setRows(dataList);
  215. return pageInfo;
  216. }
  217. @Override
  218. public PageInfo<StudentExamListDto> examList(ExamRecordQueryInfo queryInfo) {
  219. PageInfo<StudentExamListDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
  220. Map<String, Object> params = new HashMap<String, Object>();
  221. MapUtil.populateMap(params, queryInfo);
  222. List<StudentExamListDto> dataList = null;
  223. int count = examRegistrationDao.countExamList(params);
  224. if (count > 0) {
  225. pageInfo.setTotal(count);
  226. params.put("offset", pageInfo.getOffset());
  227. dataList = examRegistrationDao.queryExamList(params);
  228. List<Integer> subjectIds = dataList.stream().map(e -> e.getSubjectId()).collect(Collectors.toList());
  229. Map<Integer, String> subjectNameMap = this.getMap("subject", "id_", "name_", subjectIds, Integer.class, String.class);
  230. dataList.forEach(e -> {
  231. e.setSubjectName(subjectNameMap.get(e.getSubjectId()));
  232. });
  233. }
  234. if (count == 0) {
  235. dataList = new ArrayList<>();
  236. }
  237. pageInfo.setRows(dataList);
  238. return pageInfo;
  239. }
  240. @Override
  241. public void updateExamRegistrationStatus(Long registId, StudentRegistrationStatusEnum status, String memo) {
  242. if (Objects.isNull(registId)) {
  243. throw new BizException("请指定学员报名信息");
  244. }
  245. ExamRegistration er = examRegistrationDao.get(registId);
  246. if (Objects.isNull(er)) {
  247. throw new BizException("学员报名信息不存在");
  248. }
  249. if (!StudentRegistrationStatusEnum.AUDIT_WAIT.equals(er.getStatus())) {
  250. throw new BizException("审核状态错误");
  251. }
  252. if (!StudentRegistrationStatusEnum.AUDIT_PASS.equals(status)
  253. && !StudentRegistrationStatusEnum.AUDIT_REJECT.equals(status)) {
  254. throw new BizException("审核状态错误");
  255. }
  256. er.setStatus(status);
  257. er.setMemo(memo);
  258. SysConfig baseUrlConfig = sysConfigService.findByParamName(SysConfigService.BASE_H5_URL);
  259. String baseUrl="";
  260. if(Objects.nonNull(baseUrlConfig)){
  261. baseUrl=baseUrlConfig.getParanValue();
  262. }
  263. baseUrl = "1?" + baseUrl+"/#/appDetail?id=" + registId;
  264. Map<Integer, String> receiverMap = new HashMap<>(1);
  265. receiverMap.put(er.getStudentId(), er.getStudentId().toString());
  266. if(StudentRegistrationStatusEnum.AUDIT_PASS.equals(er.getStatus())){
  267. sysMessageService.batchSendMessage(MessageTypeEnum.REGIST_PASS_PUSH,
  268. receiverMap, null, 0, null, JiguangPushPlugin.PLUGIN_NAME);
  269. }else if(StudentRegistrationStatusEnum.AUDIT_REJECT.equals(er.getStatus())){
  270. sysMessageService.batchSendMessage(MessageTypeEnum.REGIST_REJECT_PUSH,
  271. receiverMap, null, 0, baseUrl, JiguangPushPlugin.PLUGIN_NAME);
  272. SysUser student = sysUserDao.get(er.getStudentId());
  273. Map<Integer, String> phoneMap = new HashMap<>(1);
  274. phoneMap.put(er.getStudentId(), student.getPhone());
  275. sysMessageService.batchSendMessage(MessageTypeEnum.REGIST_REJECT_SMS,
  276. phoneMap, null, 0, null, YimeiSmsPlugin.PLUGIN_NAME);
  277. }
  278. examRegistrationDao.update(er);
  279. }
  280. @Override
  281. public void updateExamRegistration(ExamRegistration examRegistration) {
  282. if (Objects.isNull(examRegistration.getId())) {
  283. throw new BizException("学员报名信息有误");
  284. }
  285. ExamRegistration er = examRegistrationDao.get(examRegistration.getId().longValue());
  286. if (Objects.isNull(er)) {
  287. throw new BizException("学员报名信息有误");
  288. }
  289. if(er.getStudentId().equals(examRegistration.getStudentId())){
  290. examRegistration.setStatus(StudentRegistrationStatusEnum.AUDIT_WAIT);
  291. }else{
  292. examRegistration.setStatus(null);
  293. }
  294. examRegistrationDao.update(examRegistration);
  295. }
  296. @Override
  297. public ExamRegistrationDto getExamRegistration(Long examRegistrationId) {
  298. return examRegistrationDao.getExamRegistration(examRegistrationId);
  299. }
  300. @Override
  301. @Transactional(rollbackFor = Exception.class)
  302. public Map<String, Object> repay(Integer userId, String orderNo) throws Exception {
  303. ExamRegistrationPayment order = examRegistrationPaymentService.getByOrderNo(orderNo);
  304. if (!order.getTransStatus().equals(TransStatusEnum.ING)) {
  305. throw new BizException("订单不是待支付状态,请重新报名");
  306. }
  307. Date nowDate = new Date();
  308. order.setTransStatus(TransStatusEnum.CLOSE);
  309. order.setUpdateTime(nowDate);
  310. examRegistrationPaymentService.update(order);
  311. orderNo = idGeneratorService.generatorId("payment") + "";
  312. order.setId(null);
  313. order.setTransNo(null);
  314. order.setCreateTime(nowDate);
  315. order.setTransStatus(TransStatusEnum.ING);
  316. order.setOrderNo(orderNo);
  317. examRegistrationPaymentService.insert(order);
  318. ExaminationBasic examinationBasic = examinationBasicDao.get(order.getExaminationBasicId());
  319. if (examinationBasic == null || !examinationBasic.getStatus().equals(ExamStatusEnum.APPLYING)) {
  320. throw new BizException("项目不在报名中,请核对");
  321. }
  322. Map<String, Object> rpMap = new HashMap<>();
  323. String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
  324. Map<String, Object> payMap = payService.getPayMap(
  325. order.getTransAmount(),
  326. orderNo,
  327. baseApiUrl + "/api-user/examOrder/notify",
  328. baseApiUrl + "/api-user/examOrder/paymentResult?orderNo=" + orderNo,
  329. examinationBasic.getName(),
  330. examinationBasic.getName()
  331. );
  332. order.setMerNo((String) payMap.get("routingMerNos"));
  333. order.setPayType((String) payMap.get("type"));
  334. examRegistrationPaymentService.update(order);
  335. ExamRegistration examRegistration = examRegistrationDao.get(order.getExamRegistrationId());
  336. rpMap.put("examRegister", examRegistration);
  337. rpMap.put("payMap", payMap);
  338. return rpMap;
  339. }
  340. @Override
  341. public PageInfo<StudentBaseExamsDto> studentBaseExams(QueryInfo queryInfo) {
  342. PageInfo<StudentBaseExamsDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
  343. Map<String, Object> params = new HashMap<>();
  344. MapUtil.populateMap(params, queryInfo);
  345. SysUser sysUser = sysUserFeignService.queryUserInfo();
  346. params.put("studentId",sysUser.getId());
  347. List<StudentBaseExamsDto> dataList = null;
  348. params.put("paymentStatus",1);
  349. int count = examRegistrationDao.countStudentBaseExams(params);
  350. if (count > 0) {
  351. pageInfo.setTotal(count);
  352. params.put("offset", pageInfo.getOffset());
  353. dataList = examRegistrationDao.queryStudentBaseExams(params);
  354. }
  355. if (count == 0) {
  356. dataList = new ArrayList<>();
  357. }
  358. pageInfo.setRows(dataList);
  359. return pageInfo;
  360. }
  361. }