package com.cool.store.dao;

import cn.hutool.core.collection.CollStreamUtil;
import com.cool.store.entity.PointFinancialDataDO;
import com.cool.store.mapper.PointFinancialDataMapper;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @Auther zx_szh
 * @Date 2026/1/8 11:31
 * @Version 1.0
 */
@Repository
public class PointFinancialDataDAO {

    @Resource
    private PointFinancialDataMapper pointFinancialDataDOMapper;

    public int insertPointFinancialData(PointFinancialDataDO pointFinancialDataDO){
        return pointFinancialDataDOMapper.insertPointFinancialData(pointFinancialDataDO);
    }

    /**
     * 修改点位财务数据
     * @param pointFinancialDataDO 点位财务数据对象
     * @return 更新记录数
     */
    public int updatePointFinancialData(PointFinancialDataDO pointFinancialDataDO){
        return pointFinancialDataDOMapper.updatePointFinancialData(pointFinancialDataDO);
    }

    /**
     * 根据点位ID查询点位财务数据
     * @param pointId 点位ID
     * @return 点位财务数据对象
     */
    public PointFinancialDataDO selectByPointId(@Param("pointId") Long pointId){
        if(Objects.isNull(pointId)) {
            return null;
        }
        return pointFinancialDataDOMapper.selectByPointId(pointId);
    }

    public Map<Long, PointFinancialDataDO> getMapByPointIds(List<Long> pointIds) {
        if (CollectionUtils.isEmpty(pointIds)) {
            return Collections.emptyMap();
        }
        Example example = new Example(PointFinancialDataDO.class);
        example.createCriteria().andIn("pointId", pointIds);
        List<PointFinancialDataDO> list = pointFinancialDataDOMapper.selectByExample(example);
        return CollStreamUtil.toMap(list, PointFinancialDataDO::getPointId, v -> v);
    }

}
