Administrator 1 year ago
parent
commit
41dbb69a90

+ 20 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/BomanCommonController.java

@@ -48,7 +48,7 @@ public class BomanCommonController extends BaseController {
                 //查询所有时段和最大人数
                 //去redis找对应日期,对应时段id的预约数量 reservat_num:2023-10-10_1
                 String reservatConfigDate = bomanReservatConfigTime.getReservatConfigDate();
-                //预约人数
+                //已经预约人数
                 Object  reservatNum= redisCache.getCacheObject(Constants.RESERVAT_NUM + reservatConfigDate + "_" + reservatConfigTime.getReservatConfigTimeId());
                 if (ObjectUtils.isNotEmpty(reservatNum)){
                     //判断人数是否大于可预约人数
@@ -69,4 +69,23 @@ public class BomanCommonController extends BaseController {
     public AjaxResult indexStatistics(BomanReservat bomanReservat) {
         return  bomanReservatService.indexStatistics(bomanReservat);
     }
+
+
+    /**
+     * H5时段信息 日历
+     */
+    @PostMapping("/reservatConfig/calendar")
+    public AjaxResult calendar(@RequestBody BomanReservatConfigTime bomanReservatConfigTime)
+    {
+
+        //signList: [{date: "2023-11-10",title: "可预约",val:'0',info: "张三生日"},
+        //           {date: "2023-11-11",title: "不可约",val:'1'},
+        //           {date: "2023-11-12",title: "已约满",val:'2'},
+        //           {date: "2023-11-13",title: "已结束",val:'3'},
+        //           {date: "2023-11-14",title: "可预约",val:'0'},
+        //           {date: "2023-11-29",title: "可预约",val:'0'}],
+
+        AjaxResult calendar = bomanReservatConfigTimeService.getCalendar(bomanReservatConfigTime.getReservatConfigDate());
+        return calendar;
+    }
 }

+ 3 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/news/BomanNewsController.java

@@ -4,6 +4,7 @@ import java.util.List;
 import javax.servlet.http.HttpServletResponse;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PutMapping;
@@ -75,7 +76,7 @@ public class BomanNewsController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:news:add')")
     @Log(title = "boman_news", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@RequestBody BomanNews bomanNews)
+    public AjaxResult add(@Validated @RequestBody BomanNews bomanNews)
     {
         return toAjax(bomanNewsService.insertBomanNews(bomanNews));
     }
@@ -86,7 +87,7 @@ public class BomanNewsController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:news:edit')")
     @Log(title = "boman_news", businessType = BusinessType.UPDATE)
     @PostMapping("/put")
-    public AjaxResult edit(@RequestBody BomanNews bomanNews)
+    public AjaxResult edit(@Validated @RequestBody BomanNews bomanNews)
     {
         return toAjax(bomanNewsService.updateBomanNews(bomanNews));
     }

+ 1 - 1
ruoyi-admin/src/main/resources/application.yml

@@ -90,6 +90,6 @@ xss:
   # 过滤开关
   enabled: true
   # 排除链接(多个用逗号分隔)
-  excludes: /system/notice
+  excludes: /system/notice,/system/news,/system/news/put
   # 匹配链接
   urlPatterns: /system/*,/monitor/*,/tool/*

+ 26 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java

@@ -8,7 +8,11 @@ import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.time.ZoneId;
 import java.time.ZonedDateTime;
+import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Date;
+import java.util.List;
+
 import org.apache.commons.lang3.time.DateFormatUtils;
 
 /**
@@ -200,4 +204,26 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
         ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
         return Date.from(zdt.toInstant());
     }
+
+    /**
+     *     获取传入日期大于等于的全部日期
+     */
+    public static List<String> getMonthFullDay(Date date) {
+        List<String> monthFullDay = new ArrayList<>();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        calendar.set(Calendar.DAY_OF_MONTH, 1);
+        int max = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
+        for (int i = 0; i < max; i++) {
+            calendar.set(Calendar.DAY_OF_MONTH, i + 1);
+            Date time = calendar.getTime();
+            //判断两个日期谁大
+            if (! time.before(date)){
+                String day = sdf.format(calendar.getTime());
+                monthFullDay.add(day);
+            }
+        }
+        return monthFullDay;
+    }
 }

+ 6 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IBomanReservatConfigTimeService.java

@@ -1,6 +1,8 @@
 package com.ruoyi.system.service;
 
 import java.util.List;
+
+import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.system.domain.BomanReservatConfigTime;
 
 /**
@@ -58,4 +60,8 @@ public interface IBomanReservatConfigTimeService
      * @return 结果
      */
     public int deleteBomanReservatConfigTimeByReservatConfigTimeId(Long reservatConfigTimeId);
+    /**
+     * H5时段信息 日历
+     */
+    public AjaxResult getCalendar(String date);
 }

+ 68 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BomanReservatConfigTimeServiceImpl.java

@@ -1,7 +1,18 @@
 package com.ruoyi.system.service.impl;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.ruoyi.common.constant.Constants;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.utils.DateUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.math.NumberUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.system.mapper.BomanReservatConfigTimeMapper;
@@ -20,6 +31,9 @@ public class BomanReservatConfigTimeServiceImpl implements IBomanReservatConfigT
     @Autowired
     private BomanReservatConfigTimeMapper bomanReservatConfigTimeMapper;
 
+    @Autowired
+    private RedisCache redisCache;
+
     /**
      * 查询预约时段配置
      * 
@@ -93,4 +107,58 @@ public class BomanReservatConfigTimeServiceImpl implements IBomanReservatConfigT
     {
         return bomanReservatConfigTimeMapper.deleteBomanReservatConfigTimeByReservatConfigTimeId(reservatConfigTimeId);
     }
+
+    /**
+     * H5时段信息 日历
+     */
+    @Override
+    public AjaxResult getCalendar(String date) {
+        Map map =new HashMap();
+        //获取所有时段
+        List<BomanReservatConfigTime> bomanReservatConfigTimes = bomanReservatConfigTimeMapper.selectBomanReservatConfigTimeList(new BomanReservatConfigTime());
+
+        JSONArray jsonArray = new JSONArray();
+        List<String> monthFullDay = DateUtils.getMonthFullDay(DateUtils.parseDate(date));
+        if (monthFullDay != null && monthFullDay.size() > 0){
+            for (String dateMonth : monthFullDay) {
+                JSONObject jsonObject = new JSONObject();
+                jsonObject.put("date",dateMonth);
+                jsonObject.put("title","不可约");
+                int index = 0;
+                //去查询对应日期是否还有时段可以预约
+                if (bomanReservatConfigTimes != null && bomanReservatConfigTimes.size() > 0){
+                    for (BomanReservatConfigTime reservatConfigTime : bomanReservatConfigTimes) {
+                        //查询所有时段和最大人数
+                        //去redis找对应日期,对应时段id的预约数量 reservat_num:2023-10-10_1
+                        //已经预约人数
+                        Object  reservatNum= redisCache.getCacheObject(Constants.RESERVAT_NUM + dateMonth + "_" + reservatConfigTime.getReservatConfigTimeId());
+                        if (ObjectUtils.isNotEmpty(reservatNum)){
+                            //判断人数是否大于可预约人数
+                            //如果 x==y 返回0;x<y 返回负数(-1);x>y 返回正数(1)
+                            reservatConfigTime.setReservatConfigStatus("N");
+                            if (NumberUtils.compare(reservatConfigTime.getReservatConfigNum(),(long)reservatNum) < 0){
+                                reservatConfigTime.setReservatConfigStatus("Y");
+                                index++;
+                            }
+                        }
+                    }
+                    if (index < bomanReservatConfigTimes.size()){
+                        jsonObject.put("title","可预约");
+                    }
+                    //1: AM 2: PM
+                    Map<String, List<BomanReservatConfigTime>> collect = bomanReservatConfigTimes.stream().collect(Collectors.groupingBy(BomanReservatConfigTime::getReservatConfigType));
+                    for (String key : collect.keySet()) {
+                        if ("1".equals(key)){
+                            jsonObject.put("amList",collect.get(key));
+                        }else {
+                            jsonObject.put("pmList",collect.get(key));
+                        }
+                    }
+                }
+                jsonArray.add(jsonObject);
+            }
+        }
+        map.put("signList",jsonArray);
+        return AjaxResult.success(map);
+    }
 }