Forráskód Böngészése

Merge remote-tracking branch 'origin/master'

LIVE_YE 2 éve
szülő
commit
f611d35c29

+ 2 - 5
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/AppletController.java

@@ -22,9 +22,9 @@ public class AppletController {
      * 准备下课
      */
     @PostMapping("/xiaKe")
-    public void xiake(@Validated @RequestBody FormalTeacherClass formalTeacherClass)
+    public AjaxResult xiake(@Validated @RequestBody FormalTeacherClass formalTeacherClass)
     {
-        appletService.xiake(formalTeacherClass);
+     return    appletService.xiake(formalTeacherClass);
     }
 
     /**
@@ -39,9 +39,6 @@ public class AppletController {
     }
 
     /**
-     * 小程序首页数据
-     * 共多少班级
-     * 已放学 未放学
      */
     @PostMapping("/indexList")
     public AjaxResult indexList(@Validated @RequestBody FormalTeacherClass formalTeacherClass)

+ 13 - 1
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/FormalTeacherClass.java

@@ -45,8 +45,20 @@ public class FormalTeacherClass extends BaseEntity
     /** 学科 */
     @Excel(name = "学科")
     private String discipline;
+    /**
+     * 准备放学1,延迟放学 2
+     */
+    private String type;
 
-    public void setId(Long id) 
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public void setId(Long id)
     {
         this.id = id;
     }

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/IAppletService.java

@@ -9,7 +9,7 @@ import com.ruoyi.common.core.domain.entity.FormalTeacherClass;
  * @Describe:
  */
 public interface IAppletService {
-    public void xiake(FormalTeacherClass formalTeacherClass);
+    public AjaxResult xiake(FormalTeacherClass formalTeacherClass);
     public AjaxResult index(FormalTeacherClass formalTeacherClass);
     public AjaxResult indexList(FormalTeacherClass formalTeacherClass);
 

+ 57 - 22
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/AppletServiceImpl.java

@@ -8,12 +8,17 @@ import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.system.domain.SysConfig;
+import com.ruoyi.system.domain.XiakeConfig;
+import com.ruoyi.system.mapper.SysConfigMapper;
+import com.ruoyi.system.mapper.XiakeConfigMapper;
 import com.ruoyi.system.domain.*;
 import com.ruoyi.system.mapper.*;
 import com.ruoyi.system.service.IAppletService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -29,8 +34,10 @@ public class AppletServiceImpl implements IAppletService {
     private RedisCache redisCache;
 
     @Autowired
-    private SysConfigMapper configMapper;
+    private XiakeConfigMapper xiakeConfigMapper;
 
+    @Autowired
+    private SysConfigMapper configMapper;
     @Autowired
     private RegisterParentsStudentMapper registerParentsStudentMapper;
 
@@ -52,29 +59,57 @@ public class AppletServiceImpl implements IAppletService {
      * @param formalTeacherClass
      */
     @Override
-    public void xiake(FormalTeacherClass formalTeacherClass) {
-        Collection<String> keys = redisCache.keys(formalTeacherClass.getSchoolId() + "*");
+    public AjaxResult xiake(FormalTeacherClass formalTeacherClass) {
+        String key = formalTeacherClass.getSchoolId() + ":" + formalTeacherClass.getClassId();
         //key = 学校id:班级id
-        for (String key : keys) {
-            //从key键中提取班级ID
-            String classId = key.replaceAll(formalTeacherClass.getSchoolId()+":", "");
-            if (classId.equals(formalTeacherClass.getClassId())) {
-                //Redis根据key键,查询对应的值
-                String value = redisCache.getCacheObject(key);
-                //value = 班级名称:放学时间
-                //获取当前时间
-                Calendar nowTime = Calendar.getInstance();
+        //Redis根据key键,查询对应的值
+        String value = redisCache.getCacheObject(key);
+        if ("2".equals(formalTeacherClass.getType())) {
+            if (value.contains("time")) {
+                return AjaxResult.error("未准备放学,请勿点击延迟放学");
+            } else {
+                //延迟放学
+                String[] split = value.split(":");
+                //下课时间
+                String xiakeTime = split[1];
                 //获取参数中默认下课时间
-                SysConfig config = new SysConfig();
-                config.setConfigKey("xiake.time");
-                SysConfig retConfig = configMapper.selectConfig(config);
+                XiakeConfig config = new XiakeConfig();
+                config.setConfigKey(formalTeacherClass.getClassId()+":2");
+                XiakeConfig retConfig = xiakeConfigMapper.selectConfig(config);
+                //延迟下课的默认值
                 String configValue = retConfig.getConfigValue();
-                nowTime.add(Calendar.MINUTE, Integer.parseInt(configValue));
-                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-                value = value.replace("time", sdf.format(nowTime.getTime()));
-                redisCache.setCacheObject(key, value);
+                SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                Date date = null;
+                try {
+                    date = sdf.parse(xiakeTime);
+                    Calendar calendar = Calendar.getInstance();
+                    calendar.setTime(date);
+                    calendar.add(Calendar.MINUTE, Integer.parseInt(configValue));
+                    redisCache.setCacheObject(key, value);
+                    return AjaxResult.success("延迟放学成功");
+                } catch (ParseException e) {
+                    return AjaxResult.error("延迟放学失败");
+                }
+            }
+        }
+        if ("1".equals(formalTeacherClass.getType())) {
+            if (!value.contains("time")) {
+                return AjaxResult.error("请勿重复点击");
             }
+            //value = 班级名称:放学时间
+            //获取当前时间
+            Calendar nowTime = Calendar.getInstance();
+            //获取参数中默认下课时间
+            XiakeConfig config = new XiakeConfig();
+            config.setConfigKey(formalTeacherClass.getClassId()+":1");
+            XiakeConfig retConfig = xiakeConfigMapper.selectConfig(config);
+            String configValue = retConfig.getConfigValue();
+            nowTime.add(Calendar.MINUTE, Integer.parseInt(configValue));
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            value = value.replace("time", sdf.format(nowTime.getTime()));
+            redisCache.setCacheObject(key, value);
         }
+        return AjaxResult.success();
     }
 
     @Override
@@ -127,7 +162,7 @@ public class AppletServiceImpl implements IAppletService {
 
     @Override
     public AjaxResult pcStatistics() {
-        Map<String,Object> map = new HashMap<>();
+        Map<String, Object> map = new HashMap<>();
         //获取当前月第一天
         String monthFirst = DateUtils.timeMonthFirst();
         SysUser user = SecurityUtils.getLoginUser().getUser();
@@ -135,10 +170,10 @@ public class AppletServiceImpl implements IAppletService {
         boolean blt = false;
         boolean bls = false;
         for (SysRole role : roles) {
-            if("teacher".equals(role.getRoleKey())){
+            if ("teacher".equals(role.getRoleKey())) {
                 blt = true;
             }
-            if("school".equals(role.getRoleKey())){
+            if ("school".equals(role.getRoleKey())) {
                 bls = true;
             }
         }