Przeglądaj źródła

fixed 预约功能优化,增加联动效果

fushengqian 11 miesięcy temu
rodzic
commit
993da020ff

+ 1 - 1
fuint-application/src/main/java/com/fuint/common/dto/BookItemDto.java

@@ -47,7 +47,7 @@ public class BookItemDto implements Serializable {
     private String mobile;
 
     @ApiModelProperty("预约日期")
-    private Date serviceDate;
+    private String serviceDate;
 
     @ApiModelProperty("预约时间段")
     private String serviceTime;

+ 1 - 1
fuint-application/src/main/java/com/fuint/common/service/BookService.java

@@ -61,7 +61,7 @@ public interface BookService extends IService<MtBook> {
      * @throws BusinessCheckException
      * @return
      * */
-    Boolean isBookable(BookableParam param) throws BusinessCheckException;
+    List<String> isBookable(BookableParam param) throws BusinessCheckException;
 
     /**
      * 根据条件搜索预约项目

+ 2 - 2
fuint-application/src/main/java/com/fuint/common/service/impl/BookItemServiceImpl.java

@@ -148,8 +148,8 @@ public class BookItemServiceImpl extends ServiceImpl<MtBookItemMapper, MtBookIte
         param.setBookId(mtBookItem.getBookId());
         param.setDate(mtBookItem.getServiceDate());
         param.setTime(mtBookItem.getServiceTime());
-        Boolean bookable = bookService.isBookable(param);
-        if (!bookable) {
+        List<String> bookable = bookService.isBookable(param);
+        if (bookable.size() <= 0) {
             throw new BusinessCheckException("当前时间段不可预约,请重新选择!");
         }
 

+ 23 - 6
fuint-application/src/main/java/com/fuint/common/service/impl/BookServiceImpl.java

@@ -276,12 +276,15 @@ public class BookServiceImpl extends ServiceImpl<MtBookMapper, MtBook> implement
      * @return
      * */
     @Override
-    public Boolean isBookable(BookableParam param) throws BusinessCheckException {
+    public List<String> isBookable(BookableParam param) throws BusinessCheckException {
        MtBook mtBook = mtBookMapper.selectById(param.getBookId());
+       List<String> result = new ArrayList<>();
        if (mtBook == null) {
            throw new BusinessCheckException("预约项目不存在");
        }
-       Integer bookNum = mtBookItemMapper.getBookNum(param.getBookId(), param.getDate(), param.getTime());
+       List<String> bookList = mtBookItemMapper.getBookList(param.getBookId(), param.getDate(), param.getTime());
+       Integer bookNum = bookList.size();
+
        Integer limit = 0;
        String serviceTime = mtBook.getServiceTimes();
        if (StringUtil.isNotEmpty(serviceTime)) {
@@ -297,11 +300,25 @@ public class BookServiceImpl extends ServiceImpl<MtBookMapper, MtBook> implement
                }
            }
        }
-       if (bookNum >= limit) {
-           return false;
-       } else {
-           return true;
+       if (bookNum < limit) {
+           if (StringUtil.isNotEmpty(param.getTime())) {
+               result.add(param.getTime());
+           } else {
+               String[] times = mtBook.getServiceTimes().split(",");
+               if (times.length > 0) {
+                   for (String str : times) {
+                        String[] arr = str.split("-");
+                        if (arr.length > 2) {
+                            String item = arr[0] + "-" + arr[1];
+                            if (!bookList.contains(item)) {
+                                result.add(item);
+                            }
+                        }
+                   }
+               }
+           }
        }
+       return result;
     }
 
     /**

+ 2 - 2
fuint-application/src/main/java/com/fuint/module/clientApi/controller/ClientBookController.java

@@ -157,8 +157,8 @@ public class ClientBookController extends BaseController {
     @RequestMapping(value = "/bookable", method = RequestMethod.POST)
     @CrossOrigin
     public ResponseObject bookable(@RequestBody BookableParam param) throws BusinessCheckException {
-        Boolean bookable = bookService.isBookable(param);
-        return getSuccessResult(bookable);
+        List<String> result = bookService.isBookable(param);
+        return getSuccessResult(result);
     }
 
     /**

+ 3 - 1
fuint-repository/src/main/java/com/fuint/repository/mapper/MtBookItemMapper.java

@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.fuint.repository.model.MtBookItem;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 /**
  *  预约订单 Mapper 接口
  *
@@ -12,6 +14,6 @@ import org.apache.ibatis.annotations.Param;
  */
 public interface MtBookItemMapper extends BaseMapper<MtBookItem> {
 
-    Integer getBookNum(@Param("bookId") Integer bookId, @Param("date") String date, @Param("time") String time);
+    List<String> getBookList(@Param("bookId") Integer bookId, @Param("date") String date, @Param("time") String time);
 
 }

+ 9 - 2
fuint-repository/src/main/resources/mapper/MtBookItemMapper.xml

@@ -1,7 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.fuint.repository.mapper.MtBookItemMapper">
-    <select id="getBookNum" resultType="java.lang.Integer">
-        SELECT sum(t.id) as num FROM mt_book_item t where t.BOOK_ID = #{bookId} and t.SERVICE_DATE = #{date} and t.SERVICE_TIME = #{time} and t.STATUS !='D'
+    <select id="getBookList" resultType="java.lang.String">
+        SELECT SERVICE_TIME FROM mt_book_item t where t.BOOK_ID = #{bookId}
+        <if test="date != null and date != ''">
+            and t.SERVICE_DATE = #{date}
+        </if>
+        <if test="time != null and time != ''">
+            and t.SERVICE_TIME = #{time}
+        </if>
+            and t.STATUS !='D'
     </select>
 </mapper>