package com.chushang.inspection.terminal.service;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.IService;
import com.chushang.common.mybatis.utils.PageResult;
import com.chushang.inspection.project.po.Template;
import com.chushang.inspection.project.vo.CountVO;
import com.chushang.inspection.terminal.po.Store;
import com.chushang.inspection.terminal.query.StoreQuery;
import com.chushang.inspection.work.dto.WrkIcbcJsReceive;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
  * @auther: zhao
  * @date: 2024/6/21 16:39
  */
public interface StoreService extends IService<Store>{


    PageResult pageList(StoreQuery query);

    void upload(MultipartFile file, Long taskId);

    Store save(WrkIcbcJsReceive dto);

    List<CountVO> countByProjectIds(Set<Long> projectIds);
    default Map<Long, Integer> countByProjectIdsMap(Set<Long> projectIds){
        List<CountVO> countVOS = countByProjectIds(projectIds);
        if (CollectionUtil.isNotEmpty(countVOS)){
            return countVOS.stream().collect(Collectors.toMap(
                    CountVO::getProjectId,
                    CountVO::getTotal,
                    Integer::sum
            ));
        }
        return Map.of();
    }
}
