Browse Source

fix 预约逻辑完成

Administrator 1 year ago
parent
commit
6f33cacc5e

+ 2 - 4
ruoyi-admin/src/main/java/com/ruoyi/web/controller/reservat/BomanReservatController.java

@@ -73,11 +73,11 @@ public class BomanReservatController extends BaseController
      * 新增陵园预约
      */
     //@PreAuthorize("@ss.hasPermi('system:reservat:add')")
-    @Log(title = "陵园预约", businessType = BusinessType.INSERT)
+    //@Log(title = "陵园预约", businessType = BusinessType.INSERT)
     @PostMapping
     public AjaxResult add(@RequestBody BomanReservat bomanReservat)
     {
-        return bomanReservatService.insertBomanReservat(bomanReservat) > 0 ? AjaxResult.success() : AjaxResult.error("预约人数已满");
+        return bomanReservatService.insertBomanReservat(bomanReservat) > 0 ? AjaxResult.success() : AjaxResult.error("超过最大可预约人数");
     }
 
     /**
@@ -114,8 +114,6 @@ public class BomanReservatController extends BaseController
     /**
      * 删除陵园预约
      */
-    @PreAuthorize("@ss.hasPermi('system:reservat:remove')")
-    @Log(title = "陵园预约", businessType = BusinessType.DELETE)
     @GetMapping("/delete/{receptionIds}")
     public AjaxResult remove(@PathVariable Long[] receptionIds)
     {

+ 4 - 4
ruoyi-system/src/main/java/com/ruoyi/system/domain/BomanReservatConfig.java

@@ -18,12 +18,12 @@ public class BomanReservatConfig extends BaseEntity
     /** 预约配置ID */
     private Long reservatConfigId;
 
-    /** 周末是否可预约 N:可预约  Y:不可约 */
-    @Excel(name = "周末是否可预约 N:可预约  Y:不可约")
+    /** 周末是否可预约 N:不预约  Y:可约 */
+    @Excel(name = "周末是否可预约 N:不预约  Y:可约")
     private String reservatConfigWeek;
 
-    /** 节假日是否可预约 N:可预约  Y:不可约 */
-    @Excel(name = "节假日是否可预约 N:可预约  Y:不可约")
+    /** 节假日是否可预约 N:不预约  Y:可约 */
+    @Excel(name = "节假日是否可预约 N:不预约  Y:可约")
     private String reservatConfigHoliday;
 
     /** 创建部门 */

+ 2 - 2
ruoyi-system/src/main/java/com/ruoyi/system/domain/BomanReservatConfigTime.java

@@ -42,8 +42,8 @@ public class BomanReservatConfigTime extends BaseEntity
     @Excel(name = "1: AM 2: PM")
     private String reservatConfigType;
 
-    /** 当前时段是否可预约 N:可预约  Y:不可约 */
-    @Excel(name = "当前时段是否可预约 N:可预约  Y:不可约")
+    /** 当前时段是否可预约 N:不预约  Y:可约 */
+    @Excel(name = "当前时段是否可预约 N:不预约  Y:可约")
     private String reservatConfigStatus;
 
     /** 创建部门 */

+ 8 - 4
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BomanNewsServiceImpl.java

@@ -7,6 +7,7 @@ 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.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysDictData;
@@ -116,15 +117,17 @@ public class BomanNewsServiceImpl implements IBomanNewsService
         Map<String,Object> map = new HashMap<>();
         map.put("year",0);
         map.put("yearMonth",0);
+        JSONArray jsonArray = new JSONArray();
         //查询字典值
         List<SysDictData> dictDataList = dictTypeService.selectDictDataByType("wenzl");
         if (dictDataList != null && dictDataList.size() > 0){
             for (SysDictData sysDictData : dictDataList) {
                 JSONObject jsonObject = new JSONObject();
+                jsonObject.put("id",sysDictData.getDictValue());
                 jsonObject.put("this",0);
                 jsonObject.put("last",0);
                 jsonObject.put("status",0);
-                map.put(sysDictData.getDictValue(),jsonObject);
+                jsonArray.add(Integer.parseInt(sysDictData.getDictValue()),jsonObject);
             }
         }
         //查询本月发布的文章数据
@@ -143,8 +146,8 @@ public class BomanNewsServiceImpl implements IBomanNewsService
             //进行数据比对
             Map<String, List<BomanNews>> collect = bomanNewsList.stream().collect(Collectors.groupingBy(BomanNews::getType));
             if (collect != null && collect.size() > 0){
-                for (String key : collect.keySet()) {
-                    JSONObject jsonObject = (JSONObject)map.get(key);
+                for (String  key: collect.keySet()) {
+                    JSONObject jsonObject = (JSONObject)jsonArray.get(Integer.parseInt(key));
                     jsonObject.put("this",collect.get(key).size());
                 }
             }
@@ -154,7 +157,7 @@ public class BomanNewsServiceImpl implements IBomanNewsService
                 if (collect != null && collect.size() > 0){
                     for (String key : collect.keySet()) {
                         //本月数据
-                        JSONObject jsonObject = (JSONObject)map.get(key);
+                        JSONObject jsonObject = (JSONObject)jsonArray.get(Integer.parseInt(key));
                         int num = (int)jsonObject.get("this");
                         //上月数据
                         int numLast = collectLast.get(key).size();
@@ -166,6 +169,7 @@ public class BomanNewsServiceImpl implements IBomanNewsService
                 }
             }
         }
+        map.put("arrayList",jsonArray);
         return AjaxResult.success(map);
     }
 }

+ 15 - 8
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BomanReservatConfigTimeServiceImpl.java

@@ -1,5 +1,6 @@
 package com.ruoyi.system.service.impl;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -11,6 +12,7 @@ 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 com.ruoyi.common.utils.bean.BeanUtils;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.math.NumberUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -113,14 +115,15 @@ public class BomanReservatConfigTimeServiceImpl implements IBomanReservatConfigT
      */
     @Override
     public AjaxResult getCalendar(String date) {
-        Map map =new HashMap();
+        Map<String,Object> map =new HashMap(1);
         //获取所有时段
         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){
+            JSONArray jsonArray = new JSONArray();
+            List<BomanReservatConfigTime> bomanReservatConfigTimeList = new ArrayList<>();
             for (String dateMonth : monthFullDay) {
+                bomanReservatConfigTimeList.clear();
                 JSONObject jsonObject = new JSONObject();
                 jsonObject.put("date",dateMonth);
                 jsonObject.put("title","不可约");
@@ -128,25 +131,29 @@ public class BomanReservatConfigTimeServiceImpl implements IBomanReservatConfigT
                 //去查询对应日期是否还有时段可以预约
                 if (bomanReservatConfigTimes != null && bomanReservatConfigTimes.size() > 0){
                     for (BomanReservatConfigTime reservatConfigTime : bomanReservatConfigTimes) {
+                        BomanReservatConfigTime bomanReservatConfigTime = new BomanReservatConfigTime();
+                        BeanUtils.copyBeanProp(bomanReservatConfigTime,reservatConfigTime);
                         //查询所有时段和最大人数
                         //去redis找对应日期,对应时段id的预约数量 reservat_num:2023-10-10_1
                         //已经预约人数
                         Object  reservatNum= redisCache.getCacheObject(Constants.RESERVAT_NUM + dateMonth + "_" + reservatConfigTime.getReservatConfigTimeId());
+                        bomanReservatConfigTime.setReservatConfigStatus("Y");
                         if (ObjectUtils.isNotEmpty(reservatNum)){
                             //判断人数是否大于可预约人数
                             //如果 x==y 返回0;x<y 返回负数(-1);x>y 返回正数(1)
-                            reservatConfigTime.setReservatConfigStatus("N");
-                            if (NumberUtils.compare(reservatConfigTime.getReservatConfigNum(),(long)reservatNum) < 1){
-                                reservatConfigTime.setReservatConfigStatus("Y");
+                            if (NumberUtils.compare(bomanReservatConfigTime.getReservatConfigNum(),(long)reservatNum) < 1){
+                                bomanReservatConfigTime.setReservatConfigStatus("N");
                                 index++;
                             }
                         }
+                        bomanReservatConfigTimeList.add(bomanReservatConfigTime);
                     }
                     if (index < bomanReservatConfigTimes.size()){
                         jsonObject.put("title","可预约");
                     }
                     //1: AM 2: PM
-                    Map<String, List<BomanReservatConfigTime>> collect = bomanReservatConfigTimes.stream().collect(Collectors.groupingBy(BomanReservatConfigTime::getReservatConfigType));
+                    Map<String, List<BomanReservatConfigTime>> collect = bomanReservatConfigTimeList.stream().collect(Collectors.groupingBy(BomanReservatConfigTime::getReservatConfigType));
+
                     for (String key : collect.keySet()) {
                         if ("1".equals(key)){
                             jsonObject.put("amList",collect.get(key));
@@ -157,8 +164,8 @@ public class BomanReservatConfigTimeServiceImpl implements IBomanReservatConfigT
                 }
                 jsonArray.add(jsonObject);
             }
+            map.put("signList",jsonArray);
         }
-        map.put("signList",jsonArray);
         return AjaxResult.success(map);
     }
 }

+ 25 - 10
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BomanReservatServiceImpl.java

@@ -79,15 +79,19 @@ public class BomanReservatServiceImpl implements IBomanReservatService {
         String key = Constants.RESERVAT_NUM + bomanReservat.getVisitDate() + "_" + reservatConfigTimeId;
         //已经预约人数
         Object reservatNum = redisCache.getCacheObject(key);
-        //最新预约人数 = 已经预约人数 + 新增预约人数
-        long numNew = (long) reservatNum + Long.parseLong(bomanReservat.getVisitNum());
+        //最新预约人数
+        long numNew = Long.parseLong(bomanReservat.getVisitNum());
         if (ObjectUtils.isNotEmpty(reservatNum)) {
-            //判断已预约人数+新增预约人数=是否大于可预约人数
-            //如果 x==y 返回0;x<y 返回负数(-1);x>y 返回正数(1)
-            if (NumberUtils.compare(bomanReservatConfigTime.getReservatConfigNum(), numNew) < 0) {
-                return 0;
-            }
+            //最新预约人数 = 已经预约人数 + 新增预约人数
+            numNew = (long) reservatNum + numNew;
+        }
+        //是否超过最大可预约人数
+        //判断已预约人数+新增预约人数=是否大于可预约人数
+        //如果 x==y 返回0;x<y 返回负数(-1);x>y 返回正数(1)
+        if (NumberUtils.compare(bomanReservatConfigTime.getReservatConfigNum(), numNew) < 0) {
+            return 0;
         }
+
         //新增预约往redis中存放数据
         redisCache.setCacheObject(key, numNew);
         bomanReservat.setCreateTime(DateUtils.getNowDate());
@@ -126,11 +130,11 @@ public class BomanReservatServiceImpl implements IBomanReservatService {
             String key = Constants.RESERVAT_NUM + bomanReservat.getVisitDate() + "_" + reservatConfigTimeId;
             Object reservatNum = redisCache.getCacheObject(key);
             if (ObjectUtils.isNotEmpty(reservatNum)) {
-               long reservatNumNew = (long)reservatNum - Long.parseLong(visitNum);
-                if (reservatNumNew < 0){
+                long reservatNumNew = (long) reservatNum - Long.parseLong(visitNum);
+                if (reservatNumNew < 0) {
                     reservatNumNew = 0;
                 }
-                redisCache.setCacheObject(key,reservatNumNew);
+                redisCache.setCacheObject(key, reservatNumNew);
             }
         }
         return bomanReservatMapper.deleteBomanReservatByReservatIds(reservatIds);
@@ -149,13 +153,24 @@ public class BomanReservatServiceImpl implements IBomanReservatService {
 
     @Override
     public AjaxResult examine(BomanReservat bomanReservat) {
+
         BomanReservat reservat = bomanReservatMapper.selectBomanReservatByReservatId(bomanReservat.getReservatId());
 
         if ("3".equals(bomanReservat.getVisitType()) && "Y".equals(reservat.getIsReception()) && StringUtils.isEmpty(reservat.getReceptionName())) {
             return AjaxResult.error("请先分配接待人员");
         }
+        //拒绝,释放名额
+        if ("2".equals(bomanReservat.getVisitType())){
+            Long reservatConfigTimeId = reservat.getReservatConfigTimeId();
+            String visitNum = reservat.getVisitNum();
+            //去redis找对应日期,对应时段id的预约数量 reservat_num:2023-10-10_1
+            String key = Constants.RESERVAT_NUM + reservat.getVisitDate() + "_" + reservatConfigTimeId;
+            Object num = redisCache.getCacheObject(key);
+            redisCache.setCacheObject(key,(long)num - Long.parseLong(visitNum));
+        }
         bomanReservat.setUpdateTime(DateUtils.getNowDate());
         int i = bomanReservatMapper.updateBomanReservat(bomanReservat);
+
         return i > 0 ? AjaxResult.success() : AjaxResult.error();
     }