Przeglądaj źródła

fix 预约逻辑完成

Administrator 1 rok temu
rodzic
commit
5e7738004f

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

@@ -53,7 +53,7 @@ public class BomanCommonController extends BaseController {
                 if (ObjectUtils.isNotEmpty(reservatNum)){
                     //判断人数是否大于可预约人数
                     //如果 x==y 返回0;x<y 返回负数(-1);x>y 返回正数(1)
-                   if (NumberUtils.compare(reservatConfigTime.getReservatConfigNum(),(long)reservatNum) < 0){
+                   if (NumberUtils.compare(reservatConfigTime.getReservatConfigNum(),(long)reservatNum) < 1){
                        reservatConfigTime.setReservatConfigStatus("Y");
                    }
                 }

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

@@ -77,7 +77,7 @@ public class BomanReservatController extends BaseController
     @PostMapping
     public AjaxResult add(@RequestBody BomanReservat bomanReservat)
     {
-        return toAjax(bomanReservatService.insertBomanReservat(bomanReservat));
+        return bomanReservatService.insertBomanReservat(bomanReservat) > 0 ? AjaxResult.success() : AjaxResult.error("预约人数已满");
     }
 
     /**
@@ -88,7 +88,7 @@ public class BomanReservatController extends BaseController
     @PostMapping("/put")
     public AjaxResult edit(@RequestBody BomanReservat bomanReservat)
     {
-        return toAjax(bomanReservatService.updateBomanReservat(bomanReservat));
+        return bomanReservatService.updateBomanReservat(bomanReservat) > 0 ? AjaxResult.success() : AjaxResult.error("预约人数已满");
     }
 
     /**
@@ -117,9 +117,9 @@ public class BomanReservatController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:reservat:remove')")
     @Log(title = "陵园预约", businessType = BusinessType.DELETE)
     @GetMapping("/delete/{receptionIds}")
-    public AjaxResult remove(@PathVariable Long[] reservatIds)
+    public AjaxResult remove(@PathVariable Long[] receptionIds)
     {
-        return toAjax(bomanReservatService.deleteBomanReservatByReservatIds(reservatIds));
+        return toAjax(bomanReservatService.deleteBomanReservatByReservatIds(receptionIds));
     }
 
     /**

+ 11 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/BomanReservat.java

@@ -20,6 +20,9 @@ public class BomanReservat extends BaseEntity
     /** 陵园预约ID */
     private Long reservatId;
 
+    /** 预约时段配置ID */
+    private Long reservatConfigTimeId;
+
     /** 来访者姓名 */
     @Excel(name = "来访者姓名")
     private String visitName;
@@ -102,6 +105,14 @@ public class BomanReservat extends BaseEntity
         this.dataType = dataType;
     }
 
+    public Long getReservatConfigTimeId() {
+        return reservatConfigTimeId;
+    }
+
+    public void setReservatConfigTimeId(Long reservatConfigTimeId) {
+        this.reservatConfigTimeId = reservatConfigTimeId;
+    }
+
     public void setReservatId(Long reservatId)
     {
         this.reservatId = reservatId;

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

@@ -136,7 +136,7 @@ public class BomanReservatConfigTimeServiceImpl implements IBomanReservatConfigT
                             //判断人数是否大于可预约人数
                             //如果 x==y 返回0;x<y 返回负数(-1);x>y 返回正数(1)
                             reservatConfigTime.setReservatConfigStatus("N");
-                            if (NumberUtils.compare(reservatConfigTime.getReservatConfigNum(),(long)reservatNum) < 0){
+                            if (NumberUtils.compare(reservatConfigTime.getReservatConfigNum(),(long)reservatNum) < 1){
                                 reservatConfigTime.setReservatConfigStatus("Y");
                                 index++;
                             }

+ 103 - 63
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BomanReservatServiceImpl.java

@@ -3,9 +3,15 @@ package com.ruoyi.system.service.impl;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
+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.StringUtils;
+import com.ruoyi.system.domain.BomanReservatConfigTime;
+import com.ruoyi.system.mapper.BomanReservatConfigTimeMapper;
+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.BomanReservatMapper;
@@ -14,42 +20,44 @@ import com.ruoyi.system.service.IBomanReservatService;
 
 /**
  * 陵园预约Service业务层处理
- * 
+ *
  * @author ruoyi
  * @date 2023-11-02
  */
 @Service
-public class BomanReservatServiceImpl implements IBomanReservatService 
-{
+public class BomanReservatServiceImpl implements IBomanReservatService {
     @Autowired
     private BomanReservatMapper bomanReservatMapper;
 
+    @Autowired
+    private BomanReservatConfigTimeMapper bomanReservatConfigTimeMapper;
+    @Autowired
+    private RedisCache redisCache;
+
     /**
      * 查询陵园预约
-     * 
+     *
      * @param reservatId 陵园预约主键
      * @return 陵园预约
      */
     @Override
-    public BomanReservat selectBomanReservatByReservatId(Long reservatId)
-    {
+    public BomanReservat selectBomanReservatByReservatId(Long reservatId) {
         return bomanReservatMapper.selectBomanReservatByReservatId(reservatId);
     }
 
     /**
      * 查询陵园预约列表
-     * 
+     *
      * @param bomanReservat 陵园预约
      * @return 陵园预约
      */
     @Override
-    public List<BomanReservat> selectBomanReservatList(BomanReservat bomanReservat)
-    {
+    public List<BomanReservat> selectBomanReservatList(BomanReservat bomanReservat) {
         String dataType = bomanReservat.getDataType();
-        if ("1".equals(dataType)){
+        if ("1".equals(dataType)) {
             bomanReservat.setVisitDate(DateUtils.getDate());
         }
-        if ("2".equals(dataType)){
+        if ("2".equals(dataType)) {
             bomanReservat.setVisitDate(DateUtils.getDateByDays(-1));
         }
         return bomanReservatMapper.selectBomanReservatList(bomanReservat);
@@ -57,15 +65,33 @@ public class BomanReservatServiceImpl implements IBomanReservatService
 
     /**
      * 新增陵园预约
-     * 
+     *
      * @param bomanReservat 陵园预约
      * @return 结果
      */
     @Override
-    public int insertBomanReservat(BomanReservat bomanReservat)
-    {
+    public int insertBomanReservat(BomanReservat bomanReservat) {
+        Long reservatConfigTimeId = bomanReservat.getReservatConfigTimeId();
+        //查询可预约人数
+        BomanReservatConfigTime bomanReservatConfigTime = bomanReservatConfigTimeMapper.selectBomanReservatConfigTimeByReservatConfigTimeId(reservatConfigTimeId);
+        //组装key
+        //去redis找对应日期,对应时段id的预约数量 reservat_num:2023-10-10_1
+        String key = Constants.RESERVAT_NUM + bomanReservat.getVisitDate() + "_" + reservatConfigTimeId;
+        //已经预约人数
+        Object reservatNum = redisCache.getCacheObject(key);
+        //最新预约人数 = 已经预约人数 + 新增预约人数
+        long numNew = (long) reservatNum + 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;
+            }
+        }
+        //新增预约往redis中存放数据
+        redisCache.setCacheObject(key, numNew);
         bomanReservat.setCreateTime(DateUtils.getNowDate());
-        if("2".equals(bomanReservat.getReservatType())){
+        if ("2".equals(bomanReservat.getReservatType())) {
             bomanReservat.setVisitType("3");
         }
         return bomanReservatMapper.insertBomanReservat(bomanReservat);
@@ -73,38 +99,51 @@ public class BomanReservatServiceImpl implements IBomanReservatService
 
     /**
      * 修改陵园预约
-     * 
+     *
      * @param bomanReservat 陵园预约
      * @return 结果
      */
     @Override
-    public int updateBomanReservat(BomanReservat bomanReservat)
-    {
+    public int updateBomanReservat(BomanReservat bomanReservat) {
         bomanReservat.setUpdateTime(DateUtils.getNowDate());
         return bomanReservatMapper.updateBomanReservat(bomanReservat);
     }
 
     /**
      * 批量删除陵园预约
-     * 
+     *
      * @param reservatIds 需要删除的陵园预约主键
      * @return 结果
      */
     @Override
-    public int deleteBomanReservatByReservatIds(Long[] reservatIds)
-    {
+    public int deleteBomanReservatByReservatIds(Long[] reservatIds) {
+        //取消预约,需要修改redis中的预约人数
+        for (Long reservatId : reservatIds) {
+            BomanReservat bomanReservat = bomanReservatMapper.selectBomanReservatByReservatId(reservatId);
+            Long reservatConfigTimeId = bomanReservat.getReservatConfigTimeId();
+            String visitNum = bomanReservat.getVisitNum();
+            //去redis找对应日期,对应时段id的预约数量 reservat_num:2023-10-10_1
+            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){
+                    reservatNumNew = 0;
+                }
+                redisCache.setCacheObject(key,reservatNumNew);
+            }
+        }
         return bomanReservatMapper.deleteBomanReservatByReservatIds(reservatIds);
     }
 
     /**
      * 删除陵园预约信息
-     * 
+     *
      * @param reservatId 陵园预约主键
      * @return 结果
      */
     @Override
-    public int deleteBomanReservatByReservatId(Long reservatId)
-    {
+    public int deleteBomanReservatByReservatId(Long reservatId) {
         return bomanReservatMapper.deleteBomanReservatByReservatId(reservatId);
     }
 
@@ -112,7 +151,7 @@ public class BomanReservatServiceImpl implements IBomanReservatService
     public AjaxResult examine(BomanReservat bomanReservat) {
         BomanReservat reservat = bomanReservatMapper.selectBomanReservatByReservatId(bomanReservat.getReservatId());
 
-        if("3".equals(bomanReservat.getVisitType()) && "Y".equals(reservat.getIsReception()) && StringUtils.isEmpty(reservat.getReceptionName())){
+        if ("3".equals(bomanReservat.getVisitType()) && "Y".equals(reservat.getIsReception()) && StringUtils.isEmpty(reservat.getReceptionName())) {
             return AjaxResult.error("请先分配接待人员");
         }
         bomanReservat.setUpdateTime(DateUtils.getNowDate());
@@ -122,26 +161,27 @@ public class BomanReservatServiceImpl implements IBomanReservatService
 
     /**
      * 预约首页统计
+     *
      * @param
      * @return
      */
     @Override
     public AjaxResult indexStatistics(BomanReservat bomanReservat) {
-        Map<String,Object> map = new HashMap<>(4);
-        map.put("canGuan",0);
-        map.put("yuYue",0);
-        map.put("todayYuYue",0);
-        map.put("todayCanGuan",0);
+        Map<String, Object> map = new HashMap<>(4);
+        map.put("canGuan" , 0);
+        map.put("yuYue" , 0);
+        map.put("todayYuYue" , 0);
+        map.put("todayCanGuan" , 0);
         List<BomanReservat> bomanReservats = bomanReservatMapper.selectBomanReservatList(bomanReservat);
-        if (bomanReservats != null && bomanReservats.size() > 0){
+        if (bomanReservats != null && bomanReservats.size() > 0) {
             //来访数
             long canGuan = bomanReservats.stream().filter(s -> "2".equals(s.getVisitStatus())).count();
             long todayYuYue = bomanReservats.stream().filter(s -> DateUtils.getDate().equals(s.getVisitDate())).count();
             long todayCanGuan = bomanReservats.stream().filter(s -> DateUtils.getDate().equals(s.getVisitDate())).filter(s -> "2".equals(s.getVisitStatus())).count();
-            map.put("canGuan",canGuan);
-            map.put("yuYue",bomanReservats.size());
-            map.put("todayYuYue",todayYuYue);
-            map.put("todayCanGuan",todayCanGuan);
+            map.put("canGuan" , canGuan);
+            map.put("yuYue" , bomanReservats.size());
+            map.put("todayYuYue" , todayYuYue);
+            map.put("todayCanGuan" , todayCanGuan);
         }
         return AjaxResult.success(map);
     }
@@ -149,7 +189,7 @@ public class BomanReservatServiceImpl implements IBomanReservatService
     @Override
     public AjaxResult verification(Long reservatId) {
         BomanReservat reservat = bomanReservatMapper.selectBomanReservatByReservatId(reservatId);
-        if("2".equals(reservat.getVisitStatus())){
+        if ("2".equals(reservat.getVisitStatus())) {
             return AjaxResult.error("当前预约已核销,请勿重复操作。");
         }
         BomanReservat bomanReservat = new BomanReservat();
@@ -166,17 +206,17 @@ public class BomanReservatServiceImpl implements IBomanReservatService
     @Override
     public AjaxResult realTime() {
         // todo
-        Map<String,Object> resultMap = new HashMap<>();
+        Map<String, Object> resultMap = new HashMap<>();
 
-        resultMap.put("scale","50%");
-        resultMap.put("current",50);
-        resultMap.put("total",100);
+        resultMap.put("scale" , "50%");
+        resultMap.put("current" , 50);
+        resultMap.put("total" , 100);
         return AjaxResult.success(resultMap);
     }
 
     @Override
     public AjaxResult people() {
-        Map<String,Object> map = new HashMap<>();
+        Map<String, Object> map = new HashMap<>();
 
         String time = DateUtils.getDate();
         //获取当前年
@@ -190,39 +230,39 @@ public class BomanReservatServiceImpl implements IBomanReservatService
         long todayYy = 0;
         for (BomanReservat bomanReservat : bomanReservatYearList) {
             yearYy = yearYy + Long.parseLong(bomanReservat.getVisitNum());
-            if(bomanReservat.getVisitDate().contains(time.substring(0,time.lastIndexOf("_")))){
+            if (bomanReservat.getVisitDate().contains(time.substring(0, time.lastIndexOf("_")))) {
                 monthYy = monthYy + Long.parseLong(bomanReservat.getVisitNum());
             }
-            if(bomanReservat.getVisitDate().equals(time)){
+            if (bomanReservat.getVisitDate().equals(time)) {
                 todayYy = todayYy + Long.parseLong(bomanReservat.getVisitNum());
             }
         }
-        map.put("yearYy",yearYy);
-        map.put("monthYy",monthYy);
-        map.put("todayYy",todayYy);
+        map.put("yearYy" , yearYy);
+        map.put("monthYy" , monthYy);
+        map.put("todayYy" , todayYy);
         //todo 今日参观人数
-        map.put("todayVisit",10);
+        map.put("todayVisit" , 10);
 
-        Map<String,Object> sevenMap = new HashMap<>();
+        Map<String, Object> sevenMap = new HashMap<>();
         //获取近7天的数组
         List<String> sevenDate = getSevenDate();
         //获取7天中最早的一天
         String first = sevenDate.get(0);
         //查询七天中的数据
-        List<BomanReservat> bomanReservatSevenList = bomanReservatMapper.selectBomanReservatbySeven(first,time);
+        List<BomanReservat> bomanReservatSevenList = bomanReservatMapper.selectBomanReservatbySeven(first, time);
         List<Long> zrsList = new ArrayList<>();
         List<Long> skList = new ArrayList<>();
         List<Long> tdList = new ArrayList<>();
-        Long zrs = 0l;
-        Long sk = 0l;
-        Long td = 0l;
+        Long zrs = 0L;
+        Long sk = 0L;
+        Long td = 0L;
         for (int i = 0; i < sevenDate.size(); i++) {
             for (BomanReservat bomanReservat : bomanReservatSevenList) {
-                if(bomanReservat.getVisitDate().equals(sevenDate.get(i))){
+                if (bomanReservat.getVisitDate().equals(sevenDate.get(i))) {
                     zrs = zrs + Long.parseLong(bomanReservat.getVisitNum());
-                    if("1".equals(bomanReservat.getReservatType())){
+                    if ("1".equals(bomanReservat.getReservatType())) {
                         td = td + Long.parseLong(bomanReservat.getVisitNum());
-                    }else{
+                    } else {
                         sk = sk + Long.parseLong(bomanReservat.getVisitNum());
                     }
                 }
@@ -231,17 +271,17 @@ public class BomanReservatServiceImpl implements IBomanReservatService
             skList.add(sk);
             tdList.add(td);
             //循环完一轮之后重置
-            zrs = 0l;
-            sk = 0l;
-            td = 0l;
+            zrs = 0L;
+            sk = 0L;
+            td = 0L;
         }
 
-        sevenMap.put("date",sevenDate);
-        sevenMap.put("zrs",zrsList);
-        sevenMap.put("sk",skList);
-        sevenMap.put("td",tdList);
+        sevenMap.put("date" , sevenDate);
+        sevenMap.put("zrs" , zrsList);
+        sevenMap.put("sk" , skList);
+        sevenMap.put("td" , tdList);
 
-        map.put("sevenMap",sevenMap);
+        map.put("sevenMap" , sevenMap);
         return AjaxResult.success(map);
     }
 

+ 5 - 1
ruoyi-system/src/main/resources/mapper/system/BomanReservatMapper.xml

@@ -12,6 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="visitIdCard"    column="visit_id_card"    />
         <result property="visitNum"    column="visit_num"    />
         <result property="visitRemark"    column="visit_remark"    />
+        <result property="reservatConfigTimeId"    column="reservat_config_time_id"    />
         <result property="visitDate"    column="visit_date"    />
         <result property="visitTime"    column="visit_time"    />
         <result property="visitDateTime"    column="visit_date_time"    />
@@ -32,7 +33,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectBomanReservatVo">
-        select reservat_id, visit_name, visit_unit_name, visit_phone, visit_id_card, visit_num, visit_remark, visit_date, visit_time, visit_date_time, visit_qr, visit_type, visit_status, reservat_type, is_reception, reception_id,reception_name,reception_phone,  create_dept, create_by, create_time, update_by, update_time, remark from boman_reservat
+        select reservat_id, visit_name, visit_unit_name,reservat_config_time_id, visit_phone, visit_id_card, visit_num, visit_remark, visit_date, visit_time, visit_date_time, visit_qr, visit_type, visit_status, reservat_type, is_reception, reception_id,reception_name,reception_phone,  create_dept, create_by, create_time, update_by, update_time, remark from boman_reservat
     </sql>
 
     <select id="selectBomanReservatList" parameterType="BomanReservat" resultMap="BomanReservatResult">
@@ -80,6 +81,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         insert into boman_reservat
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="visitName != null">visit_name,</if>
+            <if test="reservatConfigTimeId != null">reservat_config_time_id,</if>
             <if test="visitUnitName != null">visit_unit_name,</if>
             <if test="visitPhone != null">visit_phone,</if>
             <if test="visitIdCard != null">visit_id_card,</if>
@@ -107,6 +109,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="visitName != null">#{visitName},</if>
+            <if test="reservatConfigTimeId != null">#{reservatConfigTimeId},</if>
             <if test="visitUnitName != null">#{visitUnitName},</if>
             <if test="visitPhone != null">#{visitPhone},</if>
             <if test="visitIdCard != null">#{visitIdCard},</if>
@@ -138,6 +141,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         update boman_reservat
         <trim prefix="SET" suffixOverrides=",">
             <if test="visitName != null">visit_name = #{visitName},</if>
+            <if test="reservatConfigTimeId != null">reservat_config_time_id = #{reservatConfigTimeId},</if>
             <if test="visitUnitName != null">visit_unit_name = #{visitUnitName},</if>
             <if test="visitPhone != null">visit_phone = #{visitPhone},</if>
             <if test="visitIdCard != null">visit_id_card = #{visitIdCard},</if>