Parcourir la source

新增帮代办提交逻辑

zhao il y a 6 mois
Parent
commit
eac3024f2f

+ 13 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/controller/ProxyDemandController.java

@@ -53,4 +53,17 @@ public class ProxyDemandController {
         proxyDemandService.deleteById(id);
         return "删除成功";
     }
+
+    //判断当前预约人数是否已满
+    @GetMapping("/judge")
+    public BaseResult judge(){
+        try {
+            proxyDemandService.findBylastTotal();
+            return BaseResult.ok();
+        }catch (BusinessException e){
+            return BaseResult.notOk(e.getMessage());
+        }
+    }
+
+
 }

+ 5 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/dao/ProxyDemandDao.java

@@ -2,6 +2,7 @@ package com.example.nngkxxdp.dao;
 
 import com.example.nngkxxdp.entity.ProxyDemand;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -25,6 +26,10 @@ public interface ProxyDemandDao {
 
     //根据Id删除一条数据
     void deleteById(Long id);
+
+    int findTotalByTime(Date startTime, Date endTime);
+
+    int findBylastTotal();
 }
 
 

+ 5 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/entity/ProxyDemand.java

@@ -16,6 +16,11 @@ public class ProxyDemand implements Serializable {
      * 南岸区重庆经开区帮办代办需求表id
      */
 
+    //办理总数
+    private Integer handleTotal;
+    //选择办理时间
+    private Date handleTime;
+
     private Long id;
 
     /**

+ 1 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/service/ProxyDemandService.java

@@ -28,4 +28,5 @@ public interface ProxyDemandService {
     //根据Id删除一条数据
     void deleteById(Long id);
 
+    BaseResult findBylastTotal();
 }

+ 37 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/ProxyDemandServiceImpl.java

@@ -12,6 +12,7 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 
@@ -40,6 +41,10 @@ public class ProxyDemandServiceImpl implements ProxyDemandService {
 
     @Override
     public BaseResult insert(ProxyVerifyDTO proxyVerifyDTO) {
+        int handleTotal = this.findTotalByTime(new Date());
+        if(handleTotal>=10){
+            throw new BusinessException("预约已满,请下周再提交!");
+        }
         Object o = redisTemplate.opsForValue().get(proxyVerifyDTO.getImgKey());
         if(o==null){
             throw new BusinessException("验证码已过期");
@@ -60,6 +65,7 @@ public class ProxyDemandServiceImpl implements ProxyDemandService {
         proxyDemand.setProxyName(proxyVerifyDTO.getProxyName());
         proxyDemand.setProxyPhone(proxyVerifyDTO.getProxyPhone());
         proxyDemand.setProxyMatters(proxyVerifyDTO.getProxyMatters());
+        proxyDemand.setHandleTotal(handleTotal+1);
         proxyDemandDao.insert(proxyDemand);
         return BaseResult.ok();
     }
@@ -73,6 +79,37 @@ public class ProxyDemandServiceImpl implements ProxyDemandService {
     public void deleteById(Long id) {
         proxyDemandDao.deleteById(id);
     }
+
+    //判断预约总数
+    @Override
+    public BaseResult findBylastTotal() {
+        int i=proxyDemandDao.findBylastTotal();
+        if(i<=9){
+            return null;
+        }else {
+            throw new BusinessException("预约已满,请下周再提交");
+        }
+
+    }
+
+    public int findTotalByTime(Date handleTime) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(handleTime);
+        // 设置为一周的开始时间(通常是周一的 00:00:00)
+        calendar.setFirstDayOfWeek(Calendar.MONDAY); // 设置每周的第一天为周一
+        calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); // 设置为本周的周一
+        calendar.set(Calendar.HOUR_OF_DAY, 0);
+        calendar.set(Calendar.MINUTE, 0);
+        calendar.set(Calendar.SECOND, 0);
+        calendar.set(Calendar.MILLISECOND, 0);
+        Date startTime = calendar.getTime();
+        // 设置为一周的结束时间(下周一的 00:00:00 前一秒)
+        calendar.add(Calendar.DAY_OF_WEEK, 7); // 向前移动7天,到达下周的周一
+        calendar.add(Calendar.MILLISECOND, -1); // 回退1毫秒,得到本周日的最后一刻
+        Date endTime = calendar.getTime();
+        return proxyDemandDao.findTotalByTime(startTime, endTime);
+    }
+
 }
 
 

+ 13 - 2
nngkxxdp/src/main/resources/mapper/ProxyDemandDao.xml

@@ -17,6 +17,8 @@
             <result property="proxyName" column="proxy_name" jdbcType="VARCHAR"/>
             <result property="proxyPhone" column="proxy_phone" jdbcType="VARCHAR"/>
             <result property="proxyMatters" column="proxy_matters" jdbcType="VARCHAR"/>
+            <result property="handleTotal" column="handle_total" jdbcType="INTEGER"/>
+            <result property="handleTime" column="handle_time" jdbcType="TIMESTAMP"/>
             <result property="creatTime" column="creat_time" jdbcType="TIMESTAMP"/>
     </resultMap>
 
@@ -28,8 +30,8 @@
         creat_time
     </sql>
     <insert id="insert">
-        insert into t_proxy_demand(unit_name,project_coding,key_project,project_addr,charge_name,charge_phone,handler_name,handler_phone,proxy_name,proxy_phone,proxy_matters,creat_time)
-        values(#{unitName},#{projectCoding},#{keyProject},#{projectAddr},#{chargeName},#{chargePhone},#{handlerName},#{handlerPhone},#{proxyName},#{proxyPhone},#{proxyMatters},#{creatTime})
+        insert into t_proxy_demand(unit_name,project_coding,key_project,project_addr,charge_name,charge_phone,handler_name,handler_phone,proxy_name,proxy_phone,proxy_matters,handle_total,creat_time)
+        values(#{unitName},#{projectCoding},#{keyProject},#{projectAddr},#{chargeName},#{chargePhone},#{handlerName},#{handlerPhone},#{proxyName},#{proxyPhone},#{proxyMatters},#{handleTotal},#{creatTime})
     </insert>
     <update id="update">
         update t_proxy_demand
@@ -56,6 +58,15 @@
     <select id="findById" resultType="com.example.nngkxxdp.entity.ProxyDemand">
         select * from t_proxy_demand where id = #{id}
     </select>
+    <select id="findTotalByTime" resultType="java.lang.Integer">
+        SELECT COUNT(*)
+        FROM t_proxy_demand
+        WHERE creat_time &gt;= #{startTime}
+        AND creat_time &lt; #{endTime}
+    </select>
+    <select id="findBylastTotal" resultType="java.lang.Integer">
+        SELECT handle_total FROM t_proxy_demand ORDER BY id DESC LIMIT 1;
+    </select>
 
 
 </mapper>