Browse Source

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

Administrator 1 year ago
parent
commit
4b5d1c64e1

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

@@ -204,9 +204,22 @@ 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 + sysDept.getDeptId() + ":" + DateUtils.getDateByDays(-1));
+                    if (ObjectUtils.isEmpty(num)) {
+                        //设置昨日延迟放学数量 = 0
+                        RedisUtils.setCacheObject(LAST_DAY_YAN_CHI + sysDept.getDeptId() + ":" + DateUtils.getDateByDays(-1), 0);
+                        //设置昨日准时放学数量 = pSysDeptList.size() - 昨日延迟放学数量
+                        RedisUtils.setCacheObject(LAST_DAY_ZHUN_SHI + sysDept.getDeptId() + ":" + DateUtils.getDateByDays(-1), pSysDeptList.size());
+                    } else {
+                        RedisUtils.setCacheObject(LAST_DAY_YAN_CHI + sysDept.getDeptId() + ":" + DateUtils.getDateByDays(-1), num);
+                        RedisUtils.setCacheObject(LAST_DAY_ZHUN_SHI + sysDept.getDeptId() + ":" + DateUtils.getDateByDays(-1), pSysDeptList.size() - (int) num);
+                    }
+                    //设置今日延迟放学数量
+                    RedisUtils.setCacheObject(TODAY_YAN_CHI + sysDept.getDeptId() + ":" + DateUtils.getDate(), 0);
                 }
             }
         }
@@ -379,7 +392,7 @@ public class AppletServiceImpl implements IAppletService {
 
     @Override
     public AjaxResult pcClassStudentNum() {
-        List<Map<String,Object>> mapList = new ArrayList<>();
+        List<Map<String, Object>> mapList = new ArrayList<>();
         LoginUser loginUser = LoginHelper.getLoginUser();
         List<RoleDTO> roles = loginUser.getRoles();
         boolean bls = false;
@@ -389,11 +402,11 @@ public class AppletServiceImpl implements IAppletService {
                 break;
             }
         }
-        if("admin".equals(loginUser.getUsername())){
+        if ("admin".equals(loginUser.getUsername())) {
             bls = true;
         }
         //查看所有班级
-        if(bls){
+        if (bls) {
             List<SysDeptVo> sysDeptVos = deptService.selectDeptList(new SysDeptBo());
             //查询所有班级的学生
             List<Long> deptIdList = sysDeptVos.stream().map(SysDeptVo::getDeptId).collect(Collectors.toList());
@@ -402,20 +415,20 @@ public class AppletServiceImpl implements IAppletService {
             List<FormalParentsStudentVo> formalParentsStudent = formalParentsStudentServicel.queryList(sbo);
             Map<Long, List<FormalParentsStudentVo>> studentMap = formalParentsStudent.stream().collect(Collectors.groupingBy(FormalParentsStudentVo::getClassId));
             for (SysDeptVo sysDeptVo : sysDeptVos) {
-                if(sysDeptVo.getParentId()!=0L ){
-                    Map<String,Object> cMap = new HashMap<>();
+                if (sysDeptVo.getParentId() != 0L) {
+                    Map<String, Object> cMap = new HashMap<>();
                     int index = 0;
-                    if( studentMap.get(sysDeptVo.getDeptId())!=null){
+                    if (studentMap.get(sysDeptVo.getDeptId()) != null) {
                         index = studentMap.get(sysDeptVo.getDeptId()).size();
                     }
                     sysDeptVo.setStudentNum(index);
-                    cMap.put("className",sysDeptVo.getDeptName());
-                    cMap.put("value",sysDeptVo);
+                    cMap.put("className", sysDeptVo.getDeptName());
+                    cMap.put("value", sysDeptVo);
                     mapList.add(cMap);
                 }
             }
 
-        }else{
+        } else {
             //老师,查询自己的班级
             FormalTeacherClassBo formalTeacherClass = new FormalTeacherClassBo();
             formalTeacherClass.setTeacherId(loginUser.getUserId());
@@ -428,15 +441,15 @@ public class AppletServiceImpl implements IAppletService {
             for (FormalTeacherClassVo formalTeacherClassVo : formalTeacherClassList) {
                 //查询部门
                 SysDeptVo sysDeptVo = sysDeptMapper.selectDeptById(formalTeacherClassVo.getClassId());
-                if(sysDeptVo!=null){
+                if (sysDeptVo != null) {
                     int index = 0;
-                    if(studentMap.get(formalTeacherClassVo.getClassId())!=null){
+                    if (studentMap.get(formalTeacherClassVo.getClassId()) != null) {
                         index = studentMap.get(formalTeacherClassVo.getClassId()).size();
                     }
                     sysDeptVo.setStudentNum(index);
-                    Map<String,Object> tMap = new HashMap<>();
-                    tMap.put("className",sysDeptVo.getDeptName());
-                    tMap.put("value",sysDeptVo);
+                    Map<String, Object> tMap = new HashMap<>();
+                    tMap.put("className", sysDeptVo.getDeptName());
+                    tMap.put("value", sysDeptVo);
                     mapList.add(tMap);
                 }
 
@@ -459,41 +472,52 @@ public class AppletServiceImpl implements IAppletService {
         }
         Collection<String> schoolKeys = RedisUtils.keys(DateUtils.getDate() + ":" + LoginHelper.getDeptId() + "*");
         //获取今日延迟放学数量
-        int todayYanChiNum = Integer.parseInt(RedisUtils.getCacheObject(TODAY_YAN_CHI + LoginHelper.getDeptId() + ":" + DateUtils.getDate()));
-        //今日准时放学
-        map.put("todayZhunShi", schoolKeys.size() - todayYanChiNum);
+        Object todayYanChiNum = RedisUtils.getCacheObject(TODAY_YAN_CHI + LoginHelper.getDeptId() + ":" + DateUtils.getDate());
         //获取昨日准时放学
-        int lastDayZhunShiNum = Integer.parseInt(RedisUtils.getCacheObject(LAST_DAY_ZHUN_SHI + LoginHelper.getDeptId() + ":" + DateUtils.getDateByDays(-1)));
+        Object 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));
+        if (ObjectUtils.isNotEmpty(todayYanChiNum)) {
+            //今日准时放学
+            map.put("todayZhunShi", schoolKeys.size() - (int) todayYanChiNum);
+            //昨日准时放学
+            if (ObjectUtils.isNotEmpty(lastDayZhunShiNum) && (schoolKeys.size() - (int) todayYanChiNum) > (int) lastDayZhunShiNum) {
+                //0平1上2下
+                map.put("zhunShiType", 1);
+                //昨日准时放学差值
+                map.put("lastDayZhunShi", schoolKeys.size() - (int) todayYanChiNum - (int) lastDayZhunShiNum);
+            } else if (ObjectUtils.isNotEmpty(lastDayZhunShiNum) && (schoolKeys.size() - (int) todayYanChiNum) < (int) lastDayZhunShiNum) {
+                map.put("zhunShiType", 2);
+                //昨日准时放学差值
+                map.put("lastDayZhunShi", (int) lastDayZhunShiNum - (schoolKeys.size() - (int) todayYanChiNum));
+            } else {
+                //昨日准时放学差值
+                map.put("lastDayZhunShi", 0);
+            }
+        } else {
+            map.put("todayZhunShi", schoolKeys.size());
         }
 
         //今日延迟
-        map.put("todayYanChi", todayYanChiNum);
-        int lastDayYanChi = RedisUtils.getCacheObject(LAST_DAY_YAN_CHI + LoginHelper.getDeptId() + ":" + DateUtils.getDateByDays(-1));
+        map.put("todayYanChi", 0);
+        Object 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);
+        if (ObjectUtils.isNotEmpty(todayYanChiNum) && ObjectUtils.isNotEmpty(lastDayYanChi)) {
+            map.put("todayYanChi", todayYanChiNum);
+            //昨日准时放学
+            if ((int) todayYanChiNum > (int) lastDayYanChi) {
+                //0平1上2下
+                map.put("yanChiType", 1);
+                //昨日准时放学差值
+                map.put("lastDayYanChi", (int) todayYanChiNum - (int) lastDayYanChi);
+            } else if ((int) todayYanChiNum < (int) lastDayYanChi) {
+                map.put("yanChiType", 2);
+                //昨日延迟放学差值
+                map.put("lastDayYanChi", (int) lastDayYanChi - (int) todayYanChiNum);
+            }
         }
+
         //本周文章发布数量
         LambdaQueryWrapper<XiaoyuanInfo> lqw = buildQueryWrapper();
         Long weekInfo = xiaoyuanInfoMapper.selectCount(lqw);
@@ -511,7 +535,7 @@ public class AppletServiceImpl implements IAppletService {
         } else if (weekInfo < lastWeekInfo) {
             map.put("weekInfoType", 2);
             //上周发布文章差值
-            map.put("lastWeekInfo",lastWeekInfo-weekInfo);
+            map.put("lastWeekInfo", lastWeekInfo - weekInfo);
         }
         return AjaxResult.success(map);
     }