package com.yiqi.activity.service.impl;

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

import com.yiqi.activity.domain.vo.ActivityClothItemMinPriceVO;
import com.yiqi.activity.domain.vo.ActivityClothItemVO;
import com.yiqi.common.utils.DateUtils;
import com.yiqi.common.utils.SecurityUtils;
import com.yiqi.core.domain.ClothWashMode;
import com.yiqi.core.service.IClothWashModeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yiqi.activity.mapper.ActivityClothItemMapper;
import com.yiqi.activity.domain.ActivityClothItem;
import com.yiqi.activity.service.IActivityClothItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 指定衣服折扣活动明细Service业务层处理
 *
 * @author xiaohei
 * @date 2023-09-11
 */
@Service
public class ActivityClothItemServiceImpl extends ServiceImpl<ActivityClothItemMapper,ActivityClothItem> implements IActivityClothItemService {

    @Autowired
    private IClothWashModeService clothWashModeService;
    /**
     * 查询指定衣服折扣活动明细
     *
     * @param id 指定衣服折扣活动明细主键
     * @return 指定衣服折扣活动明细
     */
    @Override
    public ActivityClothItem selectActivityClothItemById(Long id) {
        return baseMapper.selectActivityClothItemById(id);
    }

    /**
     * 查询指定衣服折扣活动明细列表
     *
     * @param activityClothItem 指定衣服折扣活动明细
     * @return 指定衣服折扣活动明细
     */
    @Override
    public List<ActivityClothItemVO> selectActivityClothItemList(ActivityClothItem activityClothItem) {
        List<ActivityClothItemVO> activityClothItemVOList = baseMapper.selectActivityClothItemList(activityClothItem);
//        List<ClothWashMode> clothWashModeList = clothWashModeService.list();
//        Map<Long,String> washModeMap = clothWashModeList.stream().collect(Collectors.toMap(ClothWashMode::getId, ClothWashMode::getName));
//        for(ActivityClothItemVO activityClothItemVO : activityClothItemVOList){
//            //washModeIds 转为逗号分隔，并获取washModeName
//            activityClothItemVO.setWashModeName(Arrays.stream(activityClothItemVO.getWashModeIds().split(",")).map(Long::valueOf).map(washModeMap::get).collect(Collectors.joining(",")));
//        }
        return activityClothItemVOList;
    }

    /**
     * 新增指定衣服折扣活动明细
     *
     * @param activityClothItem 指定衣服折扣活动明细
     * @return 结果
     */
    @Override
    public int insertActivityClothItem(ActivityClothItem activityClothItem) {
        activityClothItem.setCreateTime(DateUtils.getNowDate());
        return baseMapper.insert(activityClothItem);
    }

    /**
     * 修改指定衣服折扣活动明细
     *
     * @param activityClothItem 指定衣服折扣活动明细
     * @return 结果
     */
    @Override
    public int updateActivityClothItem(ActivityClothItem activityClothItem) {
        activityClothItem.setUpdateTime(DateUtils.getNowDate());
        return baseMapper.updateById(activityClothItem);
    }

    /**
     * 批量删除指定衣服折扣活动明细
     *
     * @param ids 需要删除的指定衣服折扣活动明细主键
     * @return 结果
     */
    @Override
    public int deleteActivityClothItemByIds(Long[] ids) {
        return baseMapper.deleteActivityClothItemByIds(ids);
    }

    /**
     * 删除指定衣服折扣活动明细信息
     *
     * @param id 指定衣服折扣活动明细主键
     * @return 结果
     */
    @Override
    public int deleteActivityClothItemById(Long id) {
        return baseMapper.deleteActivityClothItemById(id);
    }

    @Override
    public List<ActivityClothItemMinPriceVO> getMinPriceWith1WashByActivity() {
        return baseMapper.getMinPriceByActivity(DateUtils.dateTimeNow("yyyy-MM-dd"),
                                                SecurityUtils.getLoginUser().getOrgId(),
                                                SecurityUtils.getLoginUser().getSourceType());
    }

    @Override
    public List<ActivityClothItemMinPriceVO> getMinPriceWith1ClothItemByActivity(Long clothId) {
        return baseMapper.getMinPriceWith1ClothItemByActivity(clothId,
                                                            DateUtils.dateTimeNow("yyyy-MM-dd"),
                                                            SecurityUtils.getLoginUser().getOrgId(),
                                                            SecurityUtils.getLoginUser().getSourceType());
    }
}
