package com.yiqi.core.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yiqi.common.utils.DateUtils;
import com.yiqi.core.domain.SettlementStoreClothStatistics;
import com.yiqi.core.mapper.SettlementStoreClothStatisticsMapper;
import com.yiqi.core.service.ISettlementStoreClothStatisticsService;
import com.yiqi.order.domain.dto.SettlementFactoryStatisticsDto;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 门店衣服入厂情况每日统计Service业务层处理
 *
 * @author ruoyi
 * @date 2025-04-09
 */
@Service
public class SettlementStoreClothStatisticsServiceImpl extends ServiceImpl<SettlementStoreClothStatisticsMapper, SettlementStoreClothStatistics> implements ISettlementStoreClothStatisticsService {

    /**
     * 查询门店衣服入厂情况每日统计
     *
     * @param id 门店衣服入厂情况每日统计主键
     * @return 门店衣服入厂情况每日统计
     */
    @Override
    public SettlementStoreClothStatistics selectSettlementStoreClothStatisticsById(Long id) {
        return baseMapper.selectById(id);
    }

    /**
     * 查询门店衣服入厂情况每日统计列表
     *
     * @param settlementStoreClothStatistics 门店衣服入厂情况每日统计
     * @return 门店衣服入厂情况每日统计
     */
    @Override
    public List<SettlementStoreClothStatistics> selectSettlementStoreClothStatisticsList(SettlementStoreClothStatistics settlementStoreClothStatistics) {
        return baseMapper.selectList(new LambdaQueryWrapper<>());
    }

    /**
     * 新增门店衣服入厂情况每日统计
     *
     * @param settlementStoreClothStatistics 门店衣服入厂情况每日统计
     * @return 结果
     */
    @Override
    public int insertSettlementStoreClothStatistics(SettlementStoreClothStatistics settlementStoreClothStatistics) {
        return baseMapper.insert(settlementStoreClothStatistics);
    }

    /**
     * 修改门店衣服入厂情况每日统计
     *
     * @param settlementStoreClothStatistics 门店衣服入厂情况每日统计
     * @return 结果
     */
    @Override
    public int updateSettlementStoreClothStatistics(SettlementStoreClothStatistics settlementStoreClothStatistics) {
        return baseMapper.updateById(settlementStoreClothStatistics);
    }

    /**
     * 批量删除门店衣服入厂情况每日统计
     *
     * @param ids 需要删除的门店衣服入厂情况每日统计主键
     * @return 结果
     */
    @Override
    public int deleteSettlementStoreClothStatisticsByIds(Long[] ids) {
        return baseMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除门店衣服入厂情况每日统计信息
     *
     * @param id 门店衣服入厂情况每日统计主键
     * @return 结果
     */
    @Override
    public int deleteSettlementStoreClothStatisticsById(Long id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public SettlementFactoryStatisticsDto totalByCondition(Long factoryId, Long storeId, Date start, Date end) {
        Integer startDay = start != null ? Integer.valueOf(DateUtil.format(start, "yyyyMMdd")) : null;
        Integer endDay = end != null ? Integer.valueOf(DateUtil.format(end, "yyyyMMdd")) : null;
        return baseMapper.totalByCondition(factoryId, storeId, startDay, endDay);
    }

    @Override
    public SettlementFactoryStatisticsDto totalByConditionByDate(Long factoryId, Long storeId, Date date) {
        return baseMapper.totalByConditionByDate(factoryId, storeId, Integer.valueOf(DateUtil.format(date, "yyyyMMdd")));
    }

    @Override
    public List<SettlementFactoryStatisticsDto> listDateByCondition(Long factoryId, Long storeId, Date start, Date end) {
        Integer startDay = start != null ? Integer.valueOf(DateUtil.format(start, "yyyyMMdd")) : null;
        Integer endDay = end != null ? Integer.valueOf(DateUtil.format(end, "yyyyMMdd")) : null;
        return baseMapper.listDateByCondition(factoryId, storeId, startDay, endDay);
    }

    @Override
    public List<SettlementFactoryStatisticsDto> listStoreByCondition(Long factoryId, Long storeId, Date start, Date end) {
        Integer startDay = start != null ? Integer.valueOf(DateUtil.format(start, "yyyyMMdd")) : null;
        Integer endDay = end != null ? Integer.valueOf(DateUtil.format(end, "yyyyMMdd")) : null;
        return baseMapper.listStoreByCondition(factoryId, storeId, startDay, endDay);
    }
}
