Переглянути джерело

更新首页今日准时放学/延迟放学/本周发布文章统计

Administrator 1 рік тому
батько
коміт
60f567b022

+ 12 - 0
ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/CacheConstants.java

@@ -63,5 +63,17 @@ public interface CacheConstants {
      * 下课管理
      */
     public static final String XIA_CONFIG_KEY = "xiake_config:";
+    /**
+     * 后台首页今日延迟放学数量
+     */
+    public static final String TODAY_YAN_CHI = "today_yan_chi:";
+    /**
+     * 后台首页昨日延迟放学数量
+     */
+    public static final String LAST_DAY_YAN_CHI = "last_day_yan_chi:";
+    /**
+     * 后台首页昨日准时放学数量
+     */
+    public static final String LAST_DAY_ZHUN_SHI = "last_day_zhun_shi:";
 
 }

+ 15 - 3
ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/DateUtils.java

@@ -214,7 +214,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
      * @return
      * @throws Exception
      */
-    public static Boolean isClass(String str1,String str2,String str3,String format) throws Exception {
+    public static Boolean isClass(String str1, String str2, String str3, String format) throws Exception {
         //判断某个日期是否在两个日期范围之外
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
         Date date1 = simpleDateFormat.parse(str1);
@@ -254,7 +254,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
         int day = cal.get(Calendar.DAY_OF_WEEK);
         cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - day);
         String imptimeBegin = sdf.format(cal.getTime());
-        return imptimeBegin ;
+        return imptimeBegin;
     }
 
     /***
@@ -283,9 +283,21 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
         return year;
     }
 
-    public static int getMonth () {
+    public static int getMonth() {
         Calendar calendar = Calendar.getInstance();
         int month = calendar.get(Calendar.MONTH) + 1;
         return month;
     }
+
+    /**
+     * 得到加减某个值的日期 yyyy-MM-dd
+     *
+     * @return
+     */
+    public static String getDateByDays(long days) {
+        //days为-1就是昨天日期,为1就是明天日期
+
+        LocalDate localDate = LocalDate.now().plusDays(days);
+        return localDate.toString();
+    }
 }

+ 10 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/common/AppletController.java

@@ -49,6 +49,7 @@ public class AppletController extends BaseController {
     }
 
     /**
+     * app放学状态列表
      */
     @PostMapping("/indexList")
     public AjaxResult indexList(@RequestBody FormalTeacherClass formalTeacherClass)
@@ -65,6 +66,15 @@ public class AppletController extends BaseController {
         return  appletService.pcStatistics();
     }
 
+    /**
+     *首页统计今日准时放学/延迟放学/本周发布文章
+     */
+    @PostMapping("/pc/fangXue/statistics")
+    public AjaxResult fangXueStatistics()
+    {
+        return  appletService.fangXueStatistics();
+    }
+
     @SaIgnore
     @GetMapping("/pc/afterClass")
     public AjaxResult afterClass()

+ 1 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/info/XiaoyuanInfo.java

@@ -72,6 +72,7 @@ public class XiaoyuanInfo extends TenantEntity {
     /**
      * 发布时间
      */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date faBuTime;
 
     /**

+ 1 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/info/bo/XiaoyuanInfoBo.java

@@ -80,6 +80,7 @@ public class XiaoyuanInfoBo extends BaseEntity {
     /**
      * 发布时间
      */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date faBuTime;
 
     /**

+ 1 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/info/vo/XiaoyuanInfoVo.java

@@ -93,6 +93,7 @@ public class XiaoyuanInfoVo implements Serializable {
      * 发布时间
      */
     @ExcelProperty(value = "发布时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date faBuTime;
 
     /**

+ 4 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/common/IAppletService.java

@@ -15,4 +15,8 @@ public interface IAppletService {
     public AjaxResult indexList(FormalTeacherClass formalTeacherClass);
 
     AjaxResult pcStatistics();
+    /**
+     *首页统计今日准时放学/延迟放学/本周发布文章
+     */
+    AjaxResult fangXueStatistics();
 }

+ 128 - 7
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/common/AppletServiceImpl.java

@@ -1,16 +1,23 @@
 package org.dromara.system.service.impl.common;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.google.api.client.util.SecurityUtils;
 import lombok.RequiredArgsConstructor;
+import org.apache.commons.lang3.ObjectUtils;
 import org.dromara.common.core.domain.AjaxResult;
 import org.dromara.common.core.domain.R;
 import org.dromara.common.core.domain.dto.RoleDTO;
 import org.dromara.common.core.domain.model.LoginUser;
 import org.dromara.common.core.utils.DateUtils;
+import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.redis.utils.RedisUtils;
 import org.dromara.common.satoken.utils.LoginHelper;
 import org.dromara.system.domain.*;
 import org.dromara.system.domain.bo.SysDeptBo;
+import org.dromara.system.domain.bo.XiaoyuanInfoBo;
+import org.dromara.system.domain.info.XiaoyuanInfo;
+import org.dromara.system.domain.info.vo.XiaoyuanInfoVo;
 import org.dromara.system.domain.notice.XiaoyuanNotice;
 import org.dromara.system.domain.notice.vo.XiaoyuanNoticeVo;
 import org.dromara.system.domain.vo.*;
@@ -18,6 +25,7 @@ import org.dromara.system.domain.xiake.XiakeConfig;
 import org.dromara.system.domain.xiake.bo.XiakeConfigBo;
 import org.dromara.system.domain.xiake.vo.XiakeConfigVo;
 import org.dromara.system.mapper.*;
+import org.dromara.system.mapper.info.XiaoyuanInfoMapper;
 import org.dromara.system.mapper.notice.XiaoyuanNoticeMapper;
 import org.dromara.system.mapper.xiake.XiakeConfigMapper;
 import org.dromara.system.service.common.IAppletService;
@@ -29,6 +37,8 @@ import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
 
+import static org.dromara.common.core.constant.CacheConstants.*;
+
 /**
  * @Author: tjf
  * @Date: 2023/8/21 10:22
@@ -54,12 +64,14 @@ public class AppletServiceImpl implements IAppletService {
 
     private final SysDeptMapper sysDeptMapper;
 
-    @Autowired
-    private XiaoyuanNoticeMapper xiaoyuanNoticeMapper;
+
+    private final XiaoyuanNoticeMapper xiaoyuanNoticeMapper;
+
+    private final XiaoyuanInfoMapper xiaoyuanInfoMapper;
 
     @Override
     public R<Void> xiake(FormalTeacherClass formalTeacherClass) {
-        String key = formalTeacherClass.getSchoolId() + ":" + formalTeacherClass.getClassId();
+        String key = DateUtils.getDate() + ":" + formalTeacherClass.getSchoolId() + ":" + formalTeacherClass.getClassId();
         //key = 学校id:班级id
         //Redis根据key键,查询对应的值
         String value = RedisUtils.getCacheObject(key);
@@ -87,6 +99,19 @@ public class AppletServiceImpl implements IAppletService {
                     String time = sdf.format(calendar.getTime());
                     value = split[0] + ":" + time;
                     RedisUtils.setCacheObject(key, value);
+                    //如果是延迟放学,给后台首页记录延迟放学
+                    //key = TODAY_YAN_CHI:学校id:日期 value = 数量
+                    String num = RedisUtils.getCacheObject(TODAY_YAN_CHI + formalTeacherClass.getSchoolId() + ":" + DateUtils.getDate());
+                    if (StringUtils.isBlank(num)) {
+                        //如果是空,则说明今天还没有延迟放学,则插入
+                        RedisUtils.setCacheObject(TODAY_YAN_CHI + formalTeacherClass.getSchoolId() + ":" + DateUtils.getDate(), 1);
+                        RedisUtils.expire(TODAY_YAN_CHI + formalTeacherClass.getSchoolId() + ":" + DateUtils.getDate(), 86400 - (System.currentTimeMillis() / 1000 + 8 * 3600) % 86400);
+                    } else {
+                        //不为空则+1
+                        RedisUtils.setCacheObject(TODAY_YAN_CHI + formalTeacherClass.getSchoolId() + ":" + DateUtils.getDate(), Integer.parseInt(num) + 1);
+                        RedisUtils.expire(TODAY_YAN_CHI + formalTeacherClass.getSchoolId() + ":" + DateUtils.getDate(), 86400 - (System.currentTimeMillis() / 1000 + 8 * 3600) % 86400);
+                    }
+
                     return R.ok("延迟放学成功");
                 } catch (ParseException e) {
                     return R.fail("延迟放学失败");
@@ -118,10 +143,10 @@ public class AppletServiceImpl implements IAppletService {
     public AjaxResult index(FormalTeacherClass formalTeacherClass) {
         Map<String, Object> map = new HashMap<>(3);
         map.put("all", 0);
-        Collection<String> keys = RedisUtils.keys(formalTeacherClass.getSchoolId() + "*");
+        Collection<String> keys = RedisUtils.keys(DateUtils.getDate() + ":" + formalTeacherClass.getSchoolId() + "*");
         if (keys == null || keys.size() == 0) {
             afterClass();
-            keys = RedisUtils.keys(formalTeacherClass.getSchoolId() + "*");
+            keys = RedisUtils.keys(DateUtils.getDate() + ":" + formalTeacherClass.getSchoolId() + "*");
         }
         if (keys != null && keys.size() > 0) {
             map.put("all", keys.size());
@@ -172,18 +197,32 @@ public class AppletServiceImpl implements IAppletService {
         for (SysDeptVo sysDept : fSysDeptList) {
             for (SysDeptVo dept : pSysDeptList) {
                 if (sysDept.getDeptId().equals(dept.getParentId())) {
-                    String key = sysDept.getDeptId() + ":" + dept.getDeptId();
+                    String key = DateUtils.getDate() + ":" + sysDept.getDeptId() + ":" + dept.getDeptId();
                     String value = dept.getDeptName() + ":time";
                     RedisUtils.setCacheObject(key, value);
                 }
             }
         }
+
+        //设置昨日延迟放学数量 = TODAY_YAN_CHI + formalTeacherClass.getSchoolId() + ":" + DateUtils.getDate()
+        Object num = RedisUtils.getCacheObject(TODAY_YAN_CHI + ":" + pSysDeptList.get(0).getDeptId() + ":" + DateUtils.getDateByDays(-1));
+        if (ObjectUtils.isEmpty(num)) {
+            //设置昨日延迟放学数量 = 0
+            RedisUtils.setCacheObject(LAST_DAY_YAN_CHI + ":" + pSysDeptList.get(0).getDeptId() + ":" + DateUtils.getDateByDays(-1), 0);
+            //设置昨日准时放学数量 = pSysDeptList.size() - 昨日延迟放学数量
+            RedisUtils.setCacheObject(LAST_DAY_ZHUN_SHI + ":" + pSysDeptList.get(0).getDeptId() + ":" + DateUtils.getDateByDays(-1), pSysDeptList.size());
+        } else {
+            RedisUtils.setCacheObject(LAST_DAY_YAN_CHI + ":" + pSysDeptList.get(0).getDeptId() + ":" + DateUtils.getDateByDays(-1), num);
+            RedisUtils.setCacheObject(LAST_DAY_ZHUN_SHI + ":" + pSysDeptList.get(0).getDeptId() + ":" + DateUtils.getDateByDays(-1), pSysDeptList.size() - (int) num);
+        }
+        //设置今日延迟放学数量
+        RedisUtils.setCacheObject(TODAY_YAN_CHI + ":" + pSysDeptList.get(0).getDeptId() + ":" + DateUtils.getDate(), 0);
     }
 
     @Override
     public AjaxResult indexList(FormalTeacherClass formalTeacherClass) {
         List<Map<String, Object>> list = new ArrayList<>();
-        Collection<String> keys = RedisUtils.keys(formalTeacherClass.getSchoolId() + "*");
+        Collection<String> keys = RedisUtils.keys(DateUtils.getDate() + ":" + formalTeacherClass.getSchoolId() + "*");
         if (keys != null && keys.size() > 0) {
             for (String key : keys) {
                 String value = RedisUtils.getCacheObject(key);
@@ -344,4 +383,86 @@ public class AppletServiceImpl implements IAppletService {
         }
         return AjaxResult.success(map);
     }
+
+    /**
+     * 首页统计今日准时放学/延迟放学/本周发布文章
+     */
+    @Override
+    public AjaxResult fangXueStatistics() {
+        //今日准时放学 = 所有班级数量- 延迟放学
+        Map<String, Object> map = new HashMap();
+        Collection<String> keys = RedisUtils.keys(DateUtils.getDate() + ":" + LoginHelper.getDeptId() + "*");
+        if (keys == null || keys.size() < 1) {
+            afterClass();
+        }
+        Collection<String> schoolKeys = RedisUtils.keys(DateUtils.getDate() + ":" + LoginHelper.getDeptId() + "*");
+        //获取今日延迟放学数量
+        int todayYanChiNum = RedisUtils.getCacheObject(TODAY_YAN_CHI + LoginHelper.getDeptId() + ":" + DateUtils.getDate());
+        //今日准时放学
+        map.put("todayZhunShi", schoolKeys.size() - todayYanChiNum);
+        //获取昨日准时放学
+        int lastDayZhunShiNum = RedisUtils.getCacheObject(LAST_DAY_ZHUN_SHI + LoginHelper.getDeptId() + ":" + DateUtils.getDateByDays(-1));
+        map.put("zhunShiType", 0);
+        map.put("lastDayZhunShi", 0);
+        //昨日准时放学
+        if ((schoolKeys.size() - todayYanChiNum) > lastDayZhunShiNum) {
+            //0平1上2下
+            map.put("zhunShiType", 1);
+            //昨日准时放学差值
+            map.put("lastDayZhunShi", schoolKeys.size() - todayYanChiNum - lastDayZhunShiNum);
+        } else if ((schoolKeys.size() - todayYanChiNum) < lastDayZhunShiNum) {
+            map.put("zhunShiType", 2);
+            //昨日准时放学差值
+            map.put("lastDayZhunShi", lastDayZhunShiNum - (schoolKeys.size() - todayYanChiNum));
+        }
+
+        //今日延迟
+        map.put("todayYanChi", todayYanChiNum);
+        int lastDayYanChi = RedisUtils.getCacheObject(LAST_DAY_YAN_CHI + LoginHelper.getDeptId() + ":" + DateUtils.getDateByDays(-1));
+        map.put("yanChiType", 0);
+        map.put("lastDayYanChi", 0);
+        //昨日准时放学
+        if (todayYanChiNum > lastDayYanChi) {
+            //0平1上2下
+            map.put("yanChiType", 1);
+            //昨日准时放学差值
+            map.put("lastDayYanChi", todayYanChiNum - lastDayYanChi);
+        } else if (todayYanChiNum < lastDayYanChi) {
+            map.put("yanChiType", 2);
+            //昨日延迟放学差值
+            map.put("lastDayYanChi",lastDayYanChi-todayYanChiNum);
+        }
+        //本周文章发布数量
+        LambdaQueryWrapper<XiaoyuanInfo> lqw = buildQueryWrapper();
+        Long weekInfo = xiaoyuanInfoMapper.selectCount(lqw);
+        map.put("weekInfo", weekInfo);
+        LambdaQueryWrapper<XiaoyuanInfo> lqwLast = buildQueryWrapperLast();
+        Long lastWeekInfo = xiaoyuanInfoMapper.selectCount(lqwLast);
+        map.put("weekInfoType", 0);
+        map.put("lastWeekInfo", 0);
+        //昨日准时放学
+        if (weekInfo > lastWeekInfo) {
+            //0平1上2下
+            map.put("weekInfoType", 1);
+            //上周发布文章差值
+            map.put("lastWeekInfo", weekInfo - lastWeekInfo);
+        } else if (weekInfo < lastWeekInfo) {
+            map.put("weekInfoType", 2);
+            //上周发布文章差值
+            map.put("lastWeekInfo",lastWeekInfo-weekInfo);
+        }
+        return AjaxResult.success(map);
+    }
+
+    private LambdaQueryWrapper<XiaoyuanInfo> buildQueryWrapper() {
+        LambdaQueryWrapper<XiaoyuanInfo> lqw = Wrappers.lambdaQuery();
+        lqw.apply(" WEEK(`fa_bu_time`,1) = WEEK(NOW(),1)");
+        return lqw;
+    }
+
+    private LambdaQueryWrapper<XiaoyuanInfo> buildQueryWrapperLast() {
+        LambdaQueryWrapper<XiaoyuanInfo> lqw = Wrappers.lambdaQuery();
+        lqw.apply(" WEEK(`fa_bu_time`,1) =  WEEK(DATE_SUB(NOW(), INTERVAL 1 WEEK), 1)");
+        return lqw;
+    }
 }