CompetitionServiceImpl.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package beilv.competition.service.impl;
  2. import beilv.common.core.text.Convert;
  3. import beilv.common.utils.ShiroUtils;
  4. import beilv.competition.domain.Competition;
  5. import beilv.competition.mapper.CompetitionMapper;
  6. import beilv.competition.service.ICompetitionService;
  7. import beilv.competition.task.CloseReg;
  8. import beilv.stadium.mapper.StadiumMapper;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import javax.annotation.PostConstruct;
  12. import java.util.Date;
  13. import java.util.List;
  14. import java.util.Timer;
  15. /**
  16. * 赛事发布Service业务层处理
  17. *
  18. * @author LG
  19. * @date 2024-12-31
  20. */
  21. @Service
  22. public class CompetitionServiceImpl implements ICompetitionService {
  23. @Autowired
  24. private CompetitionMapper competitionMapper;
  25. @Autowired
  26. private StadiumMapper stadiumMapper;
  27. private final static String DAI_FA_BU = "competiton_state_1";
  28. private final static String BAO_MING_ZHONG = "competiton_state_2";
  29. private final static String BAO_MING_JIE_SHU = "competiton_state_3";
  30. private final static String YI_GUAN_BI = "competiton_state_4";
  31. @PostConstruct
  32. public void init() {
  33. // 找到所有报名中的赛事
  34. Competition competition = new Competition();
  35. competition.setCompetitionState("competiton_state_2");
  36. List<Competition> competitionList = this.selectCompetitionList(competition);
  37. competitionList.forEach(item -> {
  38. Date date = new Date(item.getApplyStartTime().getTime() - (long) (item.getApplyBeforeTime() * 60 * 60 * 1000));
  39. if (new Date().getTime() >= date.getTime()) {
  40. item.setCompetitionState("competiton_state_3");
  41. competitionMapper.updateCompetition(item);
  42. } else {
  43. Timer timer = new Timer();
  44. timer.schedule(new CloseReg(competitionMapper, item.getId()), date);
  45. }
  46. });
  47. }
  48. /**
  49. * 查询赛事发布
  50. *
  51. * @param id 赛事发布主键
  52. * @return 赛事发布
  53. */
  54. @Override
  55. public Competition selectCompetitionById(Integer id) {
  56. return competitionMapper.selectCompetitionById(id);
  57. }
  58. /**
  59. * 查询赛事发布列表
  60. *
  61. * @param competition 赛事发布
  62. * @return 赛事发布
  63. */
  64. @Override
  65. public List<Competition> selectCompetitionList(Competition competition) {
  66. return competitionMapper.selectCompetitionList(competition);
  67. }
  68. /**
  69. * 新增赛事发布
  70. *
  71. * @param competition 赛事发布
  72. * @return 结果
  73. */
  74. @Override
  75. public int insertCompetition(Competition competition) {
  76. competition.setCreateTime(new Date());
  77. competition.setCreateBy(ShiroUtils.getSysUser().getUserId().toString());
  78. competition.setCreateName(ShiroUtils.getSysUser().getUserName());
  79. competition.setCompetitionState(DAI_FA_BU);
  80. return competitionMapper.insertCompetition(competition);
  81. }
  82. /**
  83. * 修改赛事发布
  84. *
  85. * @param competition 赛事发布
  86. * @return 结果
  87. */
  88. @Override
  89. public int updateCompetition(Competition competition) {
  90. competition.setUpdateTime(new Date());
  91. competition.setUpdateBy(ShiroUtils.getSysUser().getUserId().toString());
  92. competition.setUpdateName(ShiroUtils.getSysUser().getUserName());
  93. return competitionMapper.updateCompetition(competition);
  94. }
  95. /**
  96. * 批量删除赛事发布
  97. *
  98. * @param ids 需要删除的赛事发布主键
  99. * @return 结果
  100. */
  101. @Override
  102. public int deleteCompetitionByIds(String ids) {
  103. return competitionMapper.deleteCompetitionByIds(Convert.toStrArray(ids));
  104. }
  105. /**
  106. * 删除赛事发布信息
  107. *
  108. * @param id 赛事发布主键
  109. * @return 结果
  110. */
  111. @Override
  112. public int deleteCompetitionById(Integer id) {
  113. return competitionMapper.deleteCompetitionById(id);
  114. }
  115. @Override
  116. public int publishCompetitionById(String id) {
  117. Competition competition = new Competition();
  118. competition.setPublishTime(new Date());
  119. competition.setPublishBy(ShiroUtils.getSysUser().getUserId().toString());
  120. competition.setPublishName(ShiroUtils.getSysUser().getUserName());
  121. competition.setId(Integer.valueOf(id));
  122. competition.setCompetitionState(BAO_MING_ZHONG);
  123. Timer timer = new Timer();
  124. timer.schedule(new CloseReg(competitionMapper, Integer.parseInt(id)), new Date(competition.getApplyStartTime().getTime() - (long) (competition.getApplyBeforeTime() * 60 * 1000)));
  125. return competitionMapper.publishCompetition(competition);
  126. }
  127. @Override
  128. public int closeCompetitionById(String id) {
  129. // 查询是否存在为退款的订单
  130. if (competitionMapper.selectStadumIsOpenById(id)) {
  131. //修改赛事状态
  132. Competition competition = new Competition();
  133. competition.setId(Integer.valueOf(id));
  134. competition.setCompetitionState(YI_GUAN_BI);
  135. return competitionMapper.publishCompetition(competition);
  136. } else {
  137. return 0;
  138. }
  139. }
  140. @Override
  141. public List<Competition> getCompetitionList() {
  142. return competitionMapper.getCompetitionList();
  143. }
  144. }