AppletServiceImpl.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package com.ruoyi.system.service.impl;
  2. import com.ruoyi.common.core.domain.AjaxResult;
  3. import com.ruoyi.common.core.domain.entity.FormalTeacherClass;
  4. import com.ruoyi.common.core.domain.entity.SysRole;
  5. import com.ruoyi.common.core.domain.entity.SysUser;
  6. import com.ruoyi.common.core.redis.RedisCache;
  7. import com.ruoyi.common.utils.SecurityUtils;
  8. import com.ruoyi.system.domain.SysConfig;
  9. import com.ruoyi.system.domain.XiakeConfig;
  10. import com.ruoyi.system.mapper.SysConfigMapper;
  11. import com.ruoyi.system.mapper.XiakeConfigMapper;
  12. import com.ruoyi.system.service.IAppletService;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import java.text.ParseException;
  16. import java.text.SimpleDateFormat;
  17. import java.util.*;
  18. /**
  19. * @Author: tjf
  20. * @Date: 2023/5/25 11:48
  21. * @Describe:
  22. */
  23. @Service
  24. public class AppletServiceImpl implements IAppletService {
  25. @Autowired
  26. private RedisCache redisCache;
  27. @Autowired
  28. private XiakeConfigMapper xiakeConfigMapper;
  29. /**
  30. * 老师准备下课按钮
  31. *
  32. * @param formalTeacherClass
  33. */
  34. @Override
  35. public AjaxResult xiake(FormalTeacherClass formalTeacherClass) {
  36. String key = formalTeacherClass.getSchoolId() + ":" + formalTeacherClass.getClassId();
  37. //key = 学校id:班级id
  38. //Redis根据key键,查询对应的值
  39. String value = redisCache.getCacheObject(key);
  40. if ("2".equals(formalTeacherClass.getType())) {
  41. if (value.contains("time")) {
  42. return AjaxResult.error("未准备放学,请勿点击延迟放学");
  43. } else {
  44. //延迟放学
  45. String[] split = value.split(":");
  46. //下课时间
  47. String xiakeTime = split[1];
  48. //获取参数中默认下课时间
  49. XiakeConfig config = new XiakeConfig();
  50. config.setConfigKey(formalTeacherClass.getClassId()+":2");
  51. XiakeConfig retConfig = xiakeConfigMapper.selectConfig(config);
  52. //延迟下课的默认值
  53. String configValue = retConfig.getConfigValue();
  54. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  55. Date date = null;
  56. try {
  57. date = sdf.parse(xiakeTime);
  58. Calendar calendar = Calendar.getInstance();
  59. calendar.setTime(date);
  60. calendar.add(Calendar.MINUTE, Integer.parseInt(configValue));
  61. redisCache.setCacheObject(key, value);
  62. return AjaxResult.success("延迟放学成功");
  63. } catch (ParseException e) {
  64. return AjaxResult.error("延迟放学失败");
  65. }
  66. }
  67. }
  68. if ("1".equals(formalTeacherClass.getType())) {
  69. if (!value.contains("time")) {
  70. return AjaxResult.error("请勿重复点击");
  71. }
  72. //value = 班级名称:放学时间
  73. //获取当前时间
  74. Calendar nowTime = Calendar.getInstance();
  75. //获取参数中默认下课时间
  76. XiakeConfig config = new XiakeConfig();
  77. config.setConfigKey(formalTeacherClass.getClassId()+":1");
  78. XiakeConfig retConfig = xiakeConfigMapper.selectConfig(config);
  79. String configValue = retConfig.getConfigValue();
  80. nowTime.add(Calendar.MINUTE, Integer.parseInt(configValue));
  81. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  82. value = value.replace("time", sdf.format(nowTime.getTime()));
  83. redisCache.setCacheObject(key, value);
  84. }
  85. return AjaxResult.success();
  86. }
  87. @Override
  88. public AjaxResult index(FormalTeacherClass formalTeacherClass) {
  89. Map<String, Object> map = new HashMap<>(3);
  90. map.put("all", 0);
  91. Collection<String> keys = redisCache.keys(formalTeacherClass.getSchoolId() + "*");
  92. if (keys != null && keys.size() > 0) {
  93. map.put("all", keys.size());
  94. map.put("n", 0);
  95. map.put("y", 0);
  96. int n = 0;
  97. for (String key : keys) {
  98. //Redis根据key键,查询对应的值
  99. String value = redisCache.getCacheObject(key);
  100. //value = 班级名称:放学时间
  101. //判断有多少放学时间是time,占位符
  102. String[] split = value.split(":");
  103. String time = split[1];
  104. if ("time".equals(time)) {
  105. n = n + 1;
  106. }
  107. }
  108. if (n > 0) {
  109. map.put("n", n);
  110. int y = keys.size() - n;
  111. map.put("y", Math.max(y, 0));
  112. }
  113. }
  114. return AjaxResult.success(map);
  115. }
  116. @Override
  117. public AjaxResult indexList(FormalTeacherClass formalTeacherClass) {
  118. List<Map<String, Object>> list = new ArrayList<>();
  119. Collection<String> keys = redisCache.keys(formalTeacherClass.getSchoolId() + "*");
  120. if (keys != null && keys.size() > 0) {
  121. for (String key : keys) {
  122. String value = redisCache.getCacheObject(key);
  123. //value = 班级名称:放学时间
  124. String[] split = value.split(":");
  125. Map<String, Object> map = new HashMap<>();
  126. map.put("className", split[0]);
  127. map.put("time", split[1]);
  128. list.add(map);
  129. }
  130. }
  131. return AjaxResult.success(list);
  132. }
  133. @Override
  134. public AjaxResult pcStatistics() {
  135. Map<String, Object> map = new HashMap<>();
  136. SysUser user = SecurityUtils.getLoginUser().getUser();
  137. List<SysRole> roles = user.getRoles();
  138. boolean blt = false;
  139. boolean bls = false;
  140. for (SysRole role : roles) {
  141. if ("teacher".equals(role.getRoleKey())) {
  142. blt = true;
  143. }
  144. if ("school".equals(role.getRoleKey())) {
  145. bls = true;
  146. }
  147. }
  148. //老师
  149. if (blt) {
  150. //查询本月家长的审核数据
  151. }
  152. //学校
  153. if (bls) {
  154. }
  155. //两个都有
  156. if (blt && bls) {
  157. }
  158. return null;
  159. }
  160. }