xuhy
2024-10-31 0b00c7532a0330785d0c8cf46bcb05dfc63e65c4
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TFoundationPersonServiceImpl.java
@@ -6,6 +6,7 @@
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.domain.TFoundationConfig;
import com.ruoyi.system.domain.TFoundationPerson;
import com.ruoyi.system.dto.TFoundationPersonBatchDTO;
import com.ruoyi.system.dto.TFoundationPersonDTO;
import com.ruoyi.system.mapper.TFoundationPersonMapper;
import com.ruoyi.system.query.TFoundationPersonQuery;
@@ -18,6 +19,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
@@ -39,8 +41,13 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void add(List<TFoundationPersonDTO> dto) {
        for (TFoundationPersonDTO tFoundationPersonDTO : dto) {
    public void add(TFoundationPersonBatchDTO dto) {
        List<TFoundationPersonDTO> foundationPersonDTOS = dto.getFoundationPersonDTOS();
        boolean b = hasDuplicateId(foundationPersonDTOS);
        if(b){
            throw new ServiceException("设置存在重复用餐人数");
        }
        for (TFoundationPersonDTO tFoundationPersonDTO : foundationPersonDTOS) {
            List<TFoundationConfig> foundationConfigs = tFoundationPersonDTO.getFoundationConfigs();
            long count = foundationConfigs.stream().map(TFoundationConfig::getTypeId).distinct().count();
            if(foundationConfigs.size()!=count){
@@ -57,16 +64,20 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void edit(List<TFoundationPersonDTO> dto) {
        for (TFoundationPersonDTO tFoundationPersonDTO : dto) {
    public void edit(TFoundationPersonBatchDTO dto) {
        List<TFoundationPersonDTO> foundationPersonDTOS = dto.getFoundationPersonDTOS();
        boolean b = hasDuplicateId(foundationPersonDTOS);
        if(b){
            throw new ServiceException("设置存在重复用餐人数");
        }
        for (TFoundationPersonDTO tFoundationPersonDTO : foundationPersonDTOS) {
            List<TFoundationConfig> foundationConfigs = tFoundationPersonDTO.getFoundationConfigs();
            long count = foundationConfigs.stream().map(TFoundationConfig::getTypeId).distinct().count();
            if(foundationConfigs.size()!=count){
                throw new ServiceException("菜品重复设置");
            }
            // 添加人数
            this.updateById(tFoundationPersonDTO);
            this.saveOrUpdate(tFoundationPersonDTO);
            // 删除菜品
            foundationConfigService.remove(Wrappers.lambdaQuery(TFoundationConfig.class)
                    .eq(TFoundationConfig::getPersonId,tFoundationPersonDTO.getId()));
@@ -110,4 +121,42 @@
        }
        return false; // 没有发现重复的人数
    }
    @Override
    public List<TFoundationPersonVO> getSetList() {
        List<TFoundationPersonVO> list = new ArrayList<>();
        List<TFoundationPersonVO> setList = this.baseMapper.getSetList();
        for (int i = 1; i <= 2; i++) {
            TFoundationPersonVO foundationPersonVO = new TFoundationPersonVO();
            foundationPersonVO.setMealType(i);
            int finalI = i;
            List<TFoundationPersonVO> collect = setList.stream().filter(e -> e.getMealType() == finalI).collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(collect)){
                Integer minPerson = collect.stream().sorted(Comparator.comparingInt(TFoundationPerson::getMealCount)).findFirst().get().getMealCount();
                foundationPersonVO.setMinPerson(minPerson);
                Integer maxPerson = collect.stream().sorted(Comparator.comparingInt(TFoundationPerson::getMealCount).reversed()).findFirst().get().getMealCount();
                foundationPersonVO.setMaxPerson(maxPerson);
            }
            List<Long> ids = collect.stream().map(TFoundationPersonVO::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> collect1 = list1.stream().filter(item1 -> item1.getPersonId().equals(item.getId())).collect(Collectors.toList());
                    if(!CollectionUtils.isEmpty(collect1)){
                        item.setMinDish(collect1.stream().sorted(Comparator.comparingInt(TFoundationConfig::getMinCount)).findFirst().get().getMinCount());
                        item.setMaxDish(collect1.stream().sorted(Comparator.comparingInt(TFoundationConfig::getMaxCount).reversed()).findFirst().get().getMaxCount());
                        item.setFoundationConfigs(collect1);
                    }
                });
            }
            list.add(foundationPersonVO);
        }
        return list;
    }
    @Override
    public List<TFoundationPersonVO> getPersonList() {
        return this.baseMapper.getSetList();
    }
}