| | |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.system.domain.TFoundationConfig; |
| | | import com.ruoyi.system.domain.TFoundationPerson; |
| | | import com.ruoyi.system.dto.TFoundationPersonDTO; |
| | |
| | | import com.ruoyi.system.vo.TFoundationPersonVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | |
| | | @Override |
| | | public void add(TFoundationPersonDTO dto) { |
| | | |
| | | long count1 = this.count(Wrappers.lambdaQuery(TFoundationPerson.class) |
| | | .eq(TFoundationPerson::getShopId, dto.getShopId()) |
| | | .eq(TFoundationPerson::getMealCount, dto.getMealCount())); |
| | | if(count1>0){ |
| | | throw new ServiceException("该店铺已存在该用餐人数设置"); |
| | | } |
| | | |
| | | List<TFoundationConfig> foundationConfigs = dto.getFoundationConfigs(); |
| | | long count = foundationConfigs.stream().map(TFoundationConfig::getTypeId).distinct().count(); |
| | | if(foundationConfigs.size()!=count){ |
| | | throw new ServiceException("菜品重复设置"); |
| | | } |
| | | // 添加人数 |
| | | this.save(dto); |
| | | // 添加菜品 |
| | | List<TFoundationConfig> foundationConfigs = dto.getFoundationConfigs(); |
| | | foundationConfigs.forEach(item -> { |
| | | item.setPersonId(dto.getId()); |
| | | }); |
| | |
| | | |
| | | @Override |
| | | public void edit(TFoundationPersonDTO dto) { |
| | | long count1 = this.count(Wrappers.lambdaQuery(TFoundationPerson.class) |
| | | .eq(TFoundationPerson::getShopId, dto.getShopId()) |
| | | .eq(TFoundationPerson::getMealCount, dto.getMealCount()) |
| | | .ne(TFoundationPerson::getId,dto.getId())); |
| | | if(count1>0){ |
| | | throw new ServiceException("该店铺已存在该用餐人数设置"); |
| | | } |
| | | |
| | | List<TFoundationConfig> foundationConfigs = dto.getFoundationConfigs(); |
| | | long count = foundationConfigs.stream().map(TFoundationConfig::getTypeId).distinct().count(); |
| | | if(foundationConfigs.size()!=count){ |
| | | throw new ServiceException("菜品重复设置"); |
| | | } |
| | | // 添加人数 |
| | | this.updateById(dto); |
| | | // 删除菜品 |
| | | foundationConfigService.remove(Wrappers.lambdaQuery(TFoundationConfig.class) |
| | | .eq(TFoundationConfig::getPersonId,dto.getId())); |
| | | // 添加菜品 |
| | | List<TFoundationConfig> foundationConfigs = dto.getFoundationConfigs(); |
| | | foundationConfigs.forEach(item -> { |
| | | item.setPersonId(dto.getId()); |
| | | }); |
| | |
| | | public List<TFoundationPersonVO> getList() { |
| | | List<TFoundationPersonVO> list = this.baseMapper.getList(); |
| | | List<Long> ids = list.stream().map(TFoundationPersonVO::getId).collect(Collectors.toList()); |
| | | List<TFoundationConfig> list1 = foundationConfigService.list(Wrappers.lambdaQuery(TFoundationConfig.class) |
| | | .in(TFoundationConfig::getPersonId, ids)); |
| | | list.forEach(item -> { |
| | | item.setFoundationConfigs(list1.stream().filter(item1 -> item1.getPersonId().equals(item.getId())).collect(Collectors.toList())); |
| | | }); |
| | | if(!CollectionUtils.isEmpty(ids)){ |
| | | List<TFoundationConfig> list1 = foundationConfigService.list(Wrappers.lambdaQuery(TFoundationConfig.class) |
| | | .in(TFoundationConfig::getPersonId, ids)); |
| | | list.forEach(item -> { |
| | | List<TFoundationConfig> collect = list1.stream().filter(item1 -> item1.getPersonId().equals(item.getId())).collect(Collectors.toList()); |
| | | if(!CollectionUtils.isEmpty(collect)){ |
| | | item.setMinDish(collect.stream().sorted(Comparator.comparingInt(TFoundationConfig::getMinCount)).findFirst().get().getMinCount()); |
| | | item.setMaxDish(collect.stream().sorted(Comparator.comparingInt(TFoundationConfig::getMaxCount).reversed()).findFirst().get().getMaxCount()); |
| | | item.setFoundationConfigs(collect); |
| | | } |
| | | }); |
| | | } |
| | | return list; |
| | | } |
| | | } |