zy vor 7 Monaten
Ursprung
Commit
e6ced3cc64

+ 4 - 0
bus-biz/src/main/java/bus/mapper/BUserPreMapper.java

@@ -1,6 +1,8 @@
 package bus.mapper;
 
+import bus.model.dto.BUserPreCountVo;
 import bus.model.dto.BUserPrePageDto;
+import bus.model.dto.BUserPreStatDto;
 import bus.model.vo.BUserPreVo;
 import bus.model.po.*;
 import org.apache.ibatis.annotations.Mapper;
@@ -17,4 +19,6 @@ import java.util.List;
 public interface BUserPreMapper extends BaseMapper<BUserPrePo> {
 
     List<BUserPreVo> list(BUserPrePageDto dto);
+
+    List<BUserPreCountVo> countByDateAndType(BUserPreStatDto dto);
 }

+ 19 - 0
bus-biz/src/main/java/bus/service/BCoursePreService.java

@@ -2,6 +2,8 @@ package bus.service;
 
 import bus.model.dto.BCoursePreDto;
 import bus.model.dto.BCoursePrePageDto;
+import bus.model.dto.BCoursePreTypeDto;
+import bus.model.dto.BUserPreDto;
 import bus.model.vo.BCoursePreVo;
 import bus.model.po.BCoursePrePo;
 import com.baomidou.mybatisplus.extension.service.IService;
@@ -17,6 +19,23 @@ import java.util.List;
 public interface BCoursePreService extends IService<BCoursePrePo> {
 
 
+    /**
+     * 预约时刻详情
+     * @return
+     */
+    BCoursePreTypeDto getDetailPre(String type);
+
+
+    /**
+     * 用户保存预约保存
+     * @param dto
+     * @return
+     */
+    void savePre(BUserPreDto dto);
+
+    void cancelPre(String preId,String Type);
+
+
     /**
      * 详情
      * @param id

+ 97 - 3
bus-biz/src/main/java/bus/service/impl/BCoursePreServiceImpl.java

@@ -1,18 +1,31 @@
 package bus.service.impl;
 
-import bus.model.dto.BCoursePreDto;
-import bus.model.dto.BCoursePrePageDto;
+import bus.mapper.BUserPreMapper;
+import bus.model.SnowflakeUtil;
+import bus.model.dto.*;
+import bus.model.po.BUserPrePo;
 import bus.model.vo.BCoursePreVo;
 import bus.model.po.BCoursePrePo;
 import bus.mapper.BCoursePreMapper;
 
 import bus.service.BCoursePreService;
+import bus.service.BUserPreService;
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.orcas.common.sso.model.ExtInfo;
+import com.orcas.iso.config.common.user.CurrentUserHolder;
+import org.springframework.data.web.config.QuerydslWebConfiguration;
 import org.springframework.stereotype.Service;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.BeanUtils;
+
+import javax.annotation.Resource;
+import java.util.Date;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @Program: bus
@@ -25,9 +38,90 @@ public class BCoursePreServiceImpl extends ServiceImpl<BCoursePreMapper, BCourse
 
     @Autowired
     private BCoursePreMapper bCoursePreMapper;
+    @Autowired
+    private BUserPreMapper bUserPreMapper;
+    @Resource
+    private SnowflakeUtil snowflakeUtil;
+
+    @Override
+    public BCoursePreTypeDto getDetailPre(String type) {
+        QueryWrapper<BCoursePrePo> queryWrapper = new QueryWrapper<>();
+        List<BCoursePrePo> list = this.bCoursePreMapper.selectList(queryWrapper);
+        Map<String,List<BCoursePrePo>> map = list.stream().collect(Collectors.groupingBy(BCoursePrePo::getType, Collectors.toList()));
+        BCoursePreTypeDto typeDto = new BCoursePreTypeDto();
+        for (Map.Entry<String, List<BCoursePrePo>> entry : map.entrySet()) {
+            List<BCoursePrePo> value = entry.getValue();
+            List<BCoursePreDto> bCoursePreDtos = BeanUtil.copyToList(value, BCoursePreDto.class);
+            typeDto.setType(entry.getKey());
+            typeDto.setBCoursePreDto(bCoursePreDtos);
+        }
+        // 计算当日、本周六和周日日期
+        Date now = new Date();
+        String today = DateUtil.format(now, "yyyy-MM-dd");
+       // String saturday = DateUtil.format(DateUtil.endOfWeek(now), "yyyy-MM-dd");
+        String sunday = DateUtil.format(DateUtil.offsetDay(DateUtil.endOfWeek(now), 1), "yyyy-MM-dd");
 
+        BUserPreStatDto statDto = new BUserPreStatDto();
+        statDto.setStartDate(DateUtil.parse(today, "yyyy-MM-dd"));
+        statDto.setEndDate(DateUtil.parse(sunday, "yyyy-MM-dd"));
+        statDto.setType(type);
+        // 查询各时间段预约数量
+        List<BUserPreCountVo> bUserPreCountVos = bUserPreMapper.countByDateAndType(statDto);
+        Map<String,BUserPreCountVo> s = bUserPreCountVos.stream().collect(Collectors.toMap(BUserPreCountVo::getPreId, a->a));
 
-	/**
+        // 设置各类型预约数量
+        typeDto.getBCoursePreDto().forEach(pre -> {
+            BUserPreCountVo bUserPreCountVo = s.get(pre.getId());
+            if(bUserPreCountVo == null){
+                pre.setCounts(0);
+            }else{
+                pre.setCounts(bUserPreCountVo.getCount());
+            }
+
+        });
+
+        return typeDto;
+    }
+
+    /**
+     * 用户保存预约保存
+     *
+     * @param dto
+     * @return
+     */
+    @Override
+    public void savePre(BUserPreDto dto) {
+        ExtInfo extInfo = CurrentUserHolder.get();
+        QueryWrapper<BUserPrePo> queryWrapper = new QueryWrapper();
+        queryWrapper.eq("pre_id",dto.getPreId());
+        queryWrapper.eq("user_id",extInfo.getUserId());
+        queryWrapper.eq("is_delete",0);
+        if(bUserPreMapper.selectList(queryWrapper).size()>0){
+            throw new RuntimeException("该时间段已预约");
+        }
+        BCoursePrePo bCoursePrePo = bCoursePreMapper.selectById(dto.getPreId());
+        BUserPrePo po = new BUserPrePo();
+        po.setCourseId(bCoursePrePo.getCourseId());
+        po.setPreId(dto.getPreId());
+        po.setPreDate(dto.getPreDate());
+        po.setType(dto.getType());
+        po.setUserId(extInfo.getUserId());
+        po.setId(snowflakeUtil.snowflakeId());
+        po.setCreateTime(new Date());
+        po.setUpdateTime(new Date());
+        po.setCreatorId(extInfo.getUserId());
+        po.setUpdaterId(extInfo.getUserId());
+        po.setCreatorName(extInfo.getUserName());
+        po.setUpdaterName(extInfo.getUserName());
+        bUserPreMapper.insert(po);
+    }
+
+    @Override
+    public void cancelPre(String preId, String Type) {
+
+    }
+
+    /**
      * 详情
      * @param id
      * @return

+ 17 - 1
bus-biz/src/main/resources/mapper/BUserPreMapper.xml

@@ -6,7 +6,7 @@
    select
    id,
    course_id,
-   pre_time,
+   pre_id,
    pre_date,
    remark,
    type,
@@ -21,4 +21,20 @@
    b_user_pre
  </select>
 
+     <select id="countByDateAndType" resultType="bus.model.dto.BUserPreCountVo">
+        SELECT
+            pre_id,
+            COUNT(*) AS count
+        FROM b_user_pre
+        <where>
+                is_delete= 0
+                and pre_date &gt;= #{startDate}
+                AND pre_date &lt;= #{endDate}
+                <if test="type != null and type != ''">
+                    AND type = #{type}
+                </if>
+        </where>
+         GROUP BY pre_id
+    </select>
+
 </mapper>

+ 2 - 0
bus-common/src/main/java/bus/model/dto/BCoursePreDto.java

@@ -24,5 +24,7 @@ public class BCoursePreDto{
     private String remark;
     @ApiModelProperty("类型 0当前 1星期6 2星期天")
     private String type;
+    @ApiModelProperty("预约次数")
+    private Integer counts;
 
 }

+ 14 - 0
bus-common/src/main/java/bus/model/dto/BCoursePreTypeDto.java

@@ -0,0 +1,14 @@
+package bus.model.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class BCoursePreTypeDto {
+
+    //0当日 1周六 2周日
+    private String type;
+    //预约时刻+统计数量
+    private List<BCoursePreDto> BCoursePreDto;
+}

+ 9 - 0
bus-common/src/main/java/bus/model/dto/BUserPreCountVo.java

@@ -0,0 +1,9 @@
+package bus.model.dto;
+
+import lombok.Data;
+
+@Data
+public class BUserPreCountVo {
+    private String preId;
+    private Integer count;
+}

+ 7 - 23
bus-common/src/main/java/bus/model/dto/BUserPreDto.java

@@ -13,30 +13,14 @@ import java.util.Date;
 **/
 @Data
 public class BUserPreDto{
-    @ApiModelProperty("id")
-    private String id;
-    @ApiModelProperty("路线id")
-    private String courseId;
-    @ApiModelProperty("预约时刻")
-    private String preTime;
-    @ApiModelProperty("预约日期")
+
+    @ApiModelProperty("预约时刻id")
+    private String preId;
+    @ApiModelProperty("预约日期 年月日")
     private Date preDate;
+    @ApiModelProperty("类型 0当日 1周6 2周天")
+    private String type;
     @ApiModelProperty("备注")
     private String remark;
-    @ApiModelProperty("类型,0-当天 1-星期6 2-星期天")
-    private String type;
-    @ApiModelProperty("记录创建时间")
-    private Date createTime;
-    @ApiModelProperty("记录更新时间")
-    private Date updateTime;
-    @ApiModelProperty("创建人id")
-    private String creatorId;
-    @ApiModelProperty("修改人id")
-    private String updaterId;
-    @ApiModelProperty("创建人姓名")
-    private String creatorName;
-    @ApiModelProperty("修改人姓名")
-    private String updaterName;
-    @ApiModelProperty("是否删除")
-    private Integer isDelete;
+
 }

+ 17 - 0
bus-common/src/main/java/bus/model/dto/BUserPreStatDto.java

@@ -0,0 +1,17 @@
+package bus.model.dto;
+
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+@Data
+public class BUserPreStatDto {
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date startDate;
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date endDate;
+     //0当日 1周6 2周日
+    private String type;
+
+}

+ 6 - 1
bus-common/src/main/java/bus/model/po/BUserPrePo.java

@@ -1,5 +1,6 @@
 package bus.model.po;
 
+import com.baomidou.mybatisplus.annotation.TableLogic;
 import lombok.Data;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.annotation.TableId;
@@ -19,7 +20,10 @@ public class BUserPrePo{
     @TableId
     private String id;
     private String courseId;
-    private String preTime;
+    //预约时刻id
+    private String preId;
+    private String userId;
+    //预约日期
     private Date preDate;
     private String remark;
     private String type;
@@ -29,5 +33,6 @@ public class BUserPrePo{
     private String updaterId;
     private String creatorName;
     private String updaterName;
+    @TableLogic
     private Integer isDelete;
 }

+ 73 - 50
bus-web/src/main/java/bus/controller/biz/BCoursePreController.java

@@ -1,5 +1,7 @@
 package bus.controller.biz;
 
+import bus.model.dto.BCoursePreTypeDto;
+import bus.model.dto.BUserPreDto;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageSerializable;
 import bus.model.dto.BCoursePreDto;
@@ -24,72 +26,93 @@ import com.qzwisdom.qzframework.core.tool.base.controller.BaseController;
 @Slf4j
 @CrossOrigin
 @RestController
-@Api(tags = "bCoursePre接口")
+@Api(tags = "用户预约接口")
 @RequestMapping(value="/bCoursePre")
 public class BCoursePreController implements BaseController {
 
     @Autowired
     private BCoursePreService bCoursePreService;
 
-
-
     /**
-     * 详情
-     * @param id
+     * 预约时刻详情
      * @return
      */
-    @ApiOperation("详情")
-    @GetMapping(value = "getDetailById")
-    public BCoursePreVo getDetailById(@RequestParam String id){
-        return doSingle(bCoursePreService.getDetailById(id),BCoursePreVo::new);
-    }
+     @ApiOperation("预约时刻详情")
+     @GetMapping(value = "getDetailPre")
+     public BCoursePreTypeDto getDetailPre(@RequestParam String type){
+         return bCoursePreService.getDetailPre(type);
+     }
 
-	/**
-     * 保存
+    /**
+     * 用户保存预约保存
      * @param dto
      * @return
      */
-    @ApiOperation("保存")
-    @PostMapping(value = "save")
-    public String save(@RequestBody BCoursePreDto dto){
-		bCoursePreService.save(dto);
+    @ApiOperation("用户预约保存")
+    @PostMapping(value = "savePre")
+    public String savePre(@RequestBody BUserPreDto dto){
+        bCoursePreService.savePre(dto);
         return "保存成功";
     }
 
-    /**
-    * 列表
-    * @param dto
-    * @return
-    */
-    @ApiOperation("列表")
-    @PostMapping(value = "list")
-    public PageSerializable<BCoursePreVo> list(@RequestBody BCoursePrePageDto dto){
-       PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
-       return new PageSerializable<>(bCoursePreService.list(dto));
-    }
-
-	/**
-     * 修改
-     * @param dto
-     * @return
-     */
-    @ApiOperation("修改")
-    @PostMapping(value = "update")
-    public String update(@RequestBody BCoursePreDto dto){
-		bCoursePreService.update(dto);
-        return "修改成功";
-    }
 
-	/**
-     * 删除
-     * @param id
-     * @return
-     */
-    @ApiOperation("删除")
-    @GetMapping(value = "deleteById")
-    public String deleteById(@RequestParam String id){
-		bCoursePreService.delete(id);
-        return "删除成功";
-    }
+//    /**
+//     * 详情
+//     * @param id
+//     * @return
+//     */
+//    @ApiOperation("详情")
+//    @GetMapping(value = "getDetailById")
+//    public BCoursePreVo getDetailById(@RequestParam String id){
+//        return doSingle(bCoursePreService.getDetailById(id),BCoursePreVo::new);
+//    }
+//
+//	/**
+//     * 保存
+//     * @param dto
+//     * @return
+//     */
+//    @ApiOperation("保存")
+//    @PostMapping(value = "save")
+//    public String save(@RequestBody BCoursePreDto dto){
+//		bCoursePreService.save(dto);
+//        return "保存成功";
+//    }
+//
+//    /**
+//    * 列表
+//    * @param dto
+//    * @return
+//    */
+//    @ApiOperation("列表")
+//    @PostMapping(value = "list")
+//    public PageSerializable<BCoursePreVo> list(@RequestBody BCoursePrePageDto dto){
+//       PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
+//       return new PageSerializable<>(bCoursePreService.list(dto));
+//    }
+//
+//	/**
+//     * 修改
+//     * @param dto
+//     * @return
+//     */
+//    @ApiOperation("修改")
+//    @PostMapping(value = "update")
+//    public String update(@RequestBody BCoursePreDto dto){
+//		bCoursePreService.update(dto);
+//        return "修改成功";
+//    }
+//
+//	/**
+//     * 删除
+//     * @param id
+//     * @return
+//     */
+//    @ApiOperation("删除")
+//    @GetMapping(value = "deleteById")
+//    public String deleteById(@RequestParam String id){
+//		bCoursePreService.delete(id);
+//        return "删除成功";
+//    }
 
 }