|
@@ -0,0 +1,158 @@
|
|
|
+package shop.alien.store.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import shop.alien.entity.store.*;
|
|
|
+import shop.alien.entity.store.dto.LifeGroupBuyDto;
|
|
|
+import shop.alien.entity.store.vo.LifeGroupBuyThaliVo;
|
|
|
+import shop.alien.entity.store.vo.StoreMenuVo;
|
|
|
+import shop.alien.mapper.*;
|
|
|
+import shop.alien.store.service.LifeGroupBuyService;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 团购
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class LifeGroupBuyServiceImpl extends ServiceImpl<LifeGroupBuyMainMapper, LifeGroupBuyMain> implements LifeGroupBuyService {
|
|
|
+
|
|
|
+ private final LifeGroupBuyMainMapper lifeGroupBuyMainMapper;
|
|
|
+
|
|
|
+ private final LifeGroupBuyThaliMapper lifeGroupBuyThaliMapper;
|
|
|
+
|
|
|
+ private final StoreImgMapper storeImgMapper;
|
|
|
+
|
|
|
+ private final EssentialHolidayComparisonMapper essentialHolidayComparisonMapper;
|
|
|
+
|
|
|
+ private final StoreMenuMapper storeMenuMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean saveThali(LifeGroupBuyDto lifeGroupBuyDto) {
|
|
|
+ LifeGroupBuyMain lifeGroupBuyMain = lifeGroupBuyDto.getLifeGroupBuyMain();
|
|
|
+ List<LifeGroupBuyThali> lifeGroupBuyThalis = lifeGroupBuyDto.getLifeGroupBuyThalis();
|
|
|
+ if (ObjectUtils.isEmpty(lifeGroupBuyMain.getId())) {
|
|
|
+ lifeGroupBuyMainMapper.insert(lifeGroupBuyMain);
|
|
|
+ if (ObjectUtils.isNotEmpty(lifeGroupBuyThalis)) {
|
|
|
+ for (LifeGroupBuyThali lifeGroupBuyThali : lifeGroupBuyThalis) {
|
|
|
+ lifeGroupBuyThali.setParentId(lifeGroupBuyMain.getId().toString());
|
|
|
+ lifeGroupBuyThaliMapper.insert(lifeGroupBuyThali);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ lifeGroupBuyMainMapper.updateById(lifeGroupBuyMain);
|
|
|
+ lifeGroupBuyThaliMapper.update(null, new LambdaUpdateWrapper<LifeGroupBuyThali>().eq(LifeGroupBuyThali::getParentId, lifeGroupBuyMain.getId()).set(LifeGroupBuyThali::getDeleteFlag, 1));
|
|
|
+ if (ObjectUtils.isNotEmpty(lifeGroupBuyThalis)) {
|
|
|
+ for (LifeGroupBuyThali lifeGroupBuyThali : lifeGroupBuyThalis) {
|
|
|
+ lifeGroupBuyThali.setParentId(lifeGroupBuyMain.getId().toString());
|
|
|
+ lifeGroupBuyThaliMapper.insert(lifeGroupBuyThali);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<LifeGroupBuyThaliVo> getThaliList(int page, int size, String storeId, String status, String groupName, String groupType) {
|
|
|
+ QueryWrapper<LifeGroupBuyThaliVo> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(StringUtils.isNotEmpty(storeId), "store_id", storeId)
|
|
|
+ .eq(StringUtils.isNotEmpty(status), "status", status)
|
|
|
+ .eq(StringUtils.isNotEmpty(groupType), "group_type", groupType)
|
|
|
+ .like(StringUtils.isNotEmpty(groupName), "group_name", groupName)
|
|
|
+ .eq("delete_flag", 0)
|
|
|
+ .orderByDesc("created_time");
|
|
|
+ IPage<LifeGroupBuyThaliVo> lifeGroupBuyThaliVoIPage = new Page<>(page, size);
|
|
|
+ IPage<LifeGroupBuyThaliVo> lifeGroupBuyMainIPage = lifeGroupBuyMainMapper.selectPageByThaliVo(lifeGroupBuyThaliVoIPage, queryWrapper);
|
|
|
+ List<LifeGroupBuyThaliVo> records = lifeGroupBuyMainIPage.getRecords();
|
|
|
+ if (ObjectUtils.isNotEmpty(records)) {
|
|
|
+ List<Integer> collect = records.stream().map(LifeGroupBuyThaliVo::getId).collect(Collectors.toList());
|
|
|
+ List<LifeGroupBuyThali> lifeGroupBuyThalis = lifeGroupBuyThaliMapper.selectList(new LambdaQueryWrapper<LifeGroupBuyThali>().in(LifeGroupBuyThali::getParentId, collect).eq(LifeGroupBuyThali::getDeleteFlag, 0));
|
|
|
+ records.forEach(i -> i.setDetails(lifeGroupBuyThalis.stream().filter(d -> i.getId().toString().equals(d.getParentId())).collect(Collectors.toList())));
|
|
|
+ for (LifeGroupBuyThaliVo record : records) {
|
|
|
+ record.setDetails(lifeGroupBuyThalis.stream().filter(d -> record.getId().toString().equals(d.getParentId())).collect(Collectors.toList()));
|
|
|
+
|
|
|
+ getMainImgAndDisableDate(record);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return lifeGroupBuyMainIPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public LifeGroupBuyThaliVo getThaliById(String id) {
|
|
|
+ LifeGroupBuyMain lifeGroupBuyMain = lifeGroupBuyMainMapper.selectById(id);
|
|
|
+ LifeGroupBuyThaliVo lifeGroupBuyThaliVo = new LifeGroupBuyThaliVo();
|
|
|
+ BeanUtils.copyProperties(lifeGroupBuyMain, lifeGroupBuyThaliVo);
|
|
|
+ List<LifeGroupBuyThali> lifeGroupBuyThalis = lifeGroupBuyThaliMapper.selectList(new LambdaQueryWrapper<LifeGroupBuyThali>().eq(LifeGroupBuyThali::getParentId, id).eq(LifeGroupBuyThali::getDeleteFlag, 0));
|
|
|
+
|
|
|
+ //美食
|
|
|
+ if (lifeGroupBuyMain.getGroupType() == 1) {
|
|
|
+ for (LifeGroupBuyThali lifeGroupBuyThali : lifeGroupBuyThalis) {
|
|
|
+ if (StringUtils.isNotEmpty(lifeGroupBuyThali.getDetailId())) {
|
|
|
+ StoreMenuVo menuInfo = storeMenuMapper.getMenuInfo(Integer.parseInt(lifeGroupBuyThali.getDetailId()));
|
|
|
+ if (ObjectUtils.isNotEmpty(menuInfo)) {
|
|
|
+ lifeGroupBuyThali.setDetailName(menuInfo.getDishName());
|
|
|
+ lifeGroupBuyThali.setDetailImg(menuInfo.getImgUrl());
|
|
|
+ lifeGroupBuyThali.setDetailPrice(menuInfo.getDishPrice().toString());
|
|
|
+ lifeGroupBuyThali.setDetailUnit(menuInfo.getDishesUnit());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ lifeGroupBuyThaliVo.setDetails(lifeGroupBuyThalis);
|
|
|
+ getMainImgAndDisableDate(lifeGroupBuyThaliVo);
|
|
|
+ return lifeGroupBuyThaliVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean updateStatus(String id, String status) {
|
|
|
+ lifeGroupBuyMainMapper.update(null, new LambdaUpdateWrapper<LifeGroupBuyMain>().eq(LifeGroupBuyMain::getId, id).set(LifeGroupBuyMain::getStatus, status));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean delThaliById(String id, String groupType) {
|
|
|
+ if ("1".equals(groupType)) {
|
|
|
+ lifeGroupBuyThaliMapper.update(null, new LambdaUpdateWrapper<LifeGroupBuyThali>().eq(LifeGroupBuyThali::getParentId, id).set(LifeGroupBuyThali::getDeleteFlag, 1));
|
|
|
+ }
|
|
|
+ lifeGroupBuyMainMapper.update(null, new LambdaUpdateWrapper<LifeGroupBuyMain>().eq(LifeGroupBuyMain::getId, id).set(LifeGroupBuyMain::getDeleteFlag, 1));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getMainImgAndDisableDate(LifeGroupBuyThaliVo record) {
|
|
|
+ //图片
|
|
|
+ if (StringUtils.isNotEmpty(record.getImageId())) {
|
|
|
+ List<String> imgIds = Arrays.asList(record.getImageId().split(","));
|
|
|
+ List<StoreImg> storeImgs = storeImgMapper.selectList(new LambdaQueryWrapper<StoreImg>().in(StoreImg::getId, imgIds));
|
|
|
+ if (ObjectUtils.isNotEmpty(storeImgs)) {
|
|
|
+ String imgs = storeImgs.stream()
|
|
|
+ .map(StoreImg::getImgUrl)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+ record.setImageValueStr(imgs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //不可用日期
|
|
|
+ if (ObjectUtils.isNotEmpty(record.getDisableDateType())) {
|
|
|
+ if (record.getDisableDateType() == 1) {
|
|
|
+ List<String> valueList = Arrays.asList(record.getDisableDateValue().split(";"));
|
|
|
+ List<String> list = Arrays.asList(valueList.get(1).split(","));
|
|
|
+ List<EssentialHolidayComparison> essentialHolidayComparisons = essentialHolidayComparisonMapper.selectList(new LambdaQueryWrapper<EssentialHolidayComparison>().in(EssentialHolidayComparison::getId, list));
|
|
|
+ String holiday = essentialHolidayComparisons.stream().map(EssentialHolidayComparison::getFestivalName).collect(Collectors.joining(","));
|
|
|
+ record.setDisableDateValueStr(valueList.get(0) + ";" + holiday);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|