package com.ruoyi.excel.wecom.service.impl;

import com.ruoyi.excel.wecom.domain.DepartmentStatisticsData;
import com.ruoyi.excel.wecom.mapper.DepartmentStatisticsDataMapper;
import com.ruoyi.excel.wecom.service.IDepartmentStatisticsDataService;
import com.ruoyi.excel.wecom.vo.DepartmentStatisticsDataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 部门统计数据Service业务层处理
 */
@Service
public class DepartmentStatisticsDataServiceImpl implements IDepartmentStatisticsDataService {

    @Autowired
    private DepartmentStatisticsDataMapper departmentStatisticsDataMapper;

    /**
     * 查询部门统计数据列表
     * @param startDate 开始日期
     * @param endDate 结束日期
     * @param departmentPath 部门路径
     * @return 部门统计数据列表
     */
    @Override
    public List<DepartmentStatisticsData> selectDepartmentStatisticsDataList(Date startDate, Date endDate, String departmentPath) {
        return departmentStatisticsDataMapper.selectDepartmentStatisticsDataList(startDate, endDate, departmentPath);
    }

    /**
     * 查询部门统计数据VO列表(用于导出)
     * @param startDate 开始日期
     * @param endDate 结束日期
     * @param departmentPath 部门路径
     * @return 部门统计数据VO列表
     */
    @Override
    public List<DepartmentStatisticsDataVO> selectDepartmentStatisticsDataVOList(Date startDate, Date endDate, String departmentPath) {
        return departmentStatisticsDataMapper.selectDepartmentStatisticsDataVOList(startDate, endDate, departmentPath);
    }

    /**
     * 根据ID查询部门统计数据
     * @param id 主键ID
     * @return 部门统计数据
     */
    @Override
    public DepartmentStatisticsData selectDepartmentStatisticsDataById(Long id) {
        return departmentStatisticsDataMapper.selectById(id);
    }

    /**
     * 新增部门统计数据
     * @param departmentStatisticsData 部门统计数据
     * @return 结果
     */
    @Override
    public int insertDepartmentStatisticsData(DepartmentStatisticsData departmentStatisticsData) {
        return departmentStatisticsDataMapper.insert(departmentStatisticsData);
    }

    /**
     * 修改部门统计数据
     * @param departmentStatisticsData 部门统计数据
     * @return 结果
     */
    @Override
    public int updateDepartmentStatisticsData(DepartmentStatisticsData departmentStatisticsData) {
        return departmentStatisticsDataMapper.updateById(departmentStatisticsData);
    }

    /**
     * 批量删除部门统计数据
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteDepartmentStatisticsDataByIds(Long[] ids) {
        int count = 0;
        for (Long id : ids) {
            count += departmentStatisticsDataMapper.deleteById(id);
        }
        return count;
    }

    @Override
    public Map<String, BigDecimal> getSummary(Date startDate, Date endDate, String departmentPath) {
        return departmentStatisticsDataMapper.getSummary(startDate,endDate,departmentPath);
    }
}
