|
|
@@ -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
|