package com.hzs.system.home.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.enums.EHoProductDetailsType;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.core.utils.StringUtils;
import com.hzs.common.core.utils.ip.IpLocationUtils;
import com.hzs.common.domain.system.home.HoProductDetails;
import com.hzs.system.home.mapper.HoProductDetailsMapper;
import com.hzs.system.home.param.HoProductDetailsParam;
import com.hzs.system.home.service.IHoProductDetailsService;
import com.hzs.system.home.vo.HoProductDetailsVO;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 商品展示-商品简介详情配置 服务实现类
 * </p>
 *
 * @author hzs
 * @since 2022-10-12
 */
@Service
public class HoProductDetailsServiceImpl extends ServiceImpl<HoProductDetailsMapper, HoProductDetails> implements IHoProductDetailsService {

    @Override
    public HoProductDetailsParam queryProductDetails(Integer pkAreaClassify) {
        Integer languageType = IpLocationUtils.getIpLocation();
        if(StringUtils.isNull(pkAreaClassify)){
            //首页默认展示第一个系列
            pkAreaClassify=1;
        }
        List<HoProductDetailsParam> productBriefList=new ArrayList<>();
        HoProductDetailsParam hoProductDetailsParam=new HoProductDetailsParam();
        QueryWrapper<HoProductDetails> queryWrapper=new QueryWrapper();
        queryWrapper.eq("PK_AREA_CLASSIFY",pkAreaClassify);
        List<HoProductDetails>  hoProductDetails=baseMapper.selectList(queryWrapper);
        if(CollectionUtil.isNotEmpty(hoProductDetails)){
            hoProductDetails.forEach(item -> productBriefList.add(BeanUtil.copyProperties(item, HoProductDetailsParam.class)));
        }
        hoProductDetailsParam.setProductBriefList(productBriefList);
        hoProductDetailsParam.setProductDetailsList(productBriefList);
        return hoProductDetailsParam;
    }

    /**
     * @description: 查询全部商品介绍详情
     * @author: zhang jing
     * @date: 2023/9/10 20:53
     * @param: []
     * @return: com.hzs.system.home.param.HoProductDetailsParam
     **/
    @Override
    public List<HoProductDetailsParam> queryProductDetailsMove(Integer pkAreaClassify) {
        Integer languageType = IpLocationUtils.getIpLocation();
        List<HoProductDetailsParam> productBriefList=new ArrayList<>();
        HoProductDetailsParam hoProductDetailsParam=new HoProductDetailsParam();
        QueryWrapper<HoProductDetails> queryWrapper=new QueryWrapper();
        queryWrapper.eq("PK_AREA_CLASSIFY",pkAreaClassify);
        List<HoProductDetails>  hoProductDetails=baseMapper.selectList(queryWrapper);
        if(CollectionUtil.isNotEmpty(hoProductDetails)){
            hoProductDetails.forEach(item -> productBriefList.add(BeanUtil.copyProperties(item, HoProductDetailsParam.class)));
        }
        return productBriefList;
    }


    /**
     * @description: 查询商品展示下拉选
     * @author: zhang jing
     * @date: 2023/4/4 18:13
     * @param: [hoProductDetailsParam]
     * @return: java.util.List<com.hzs.system.home.param.HoProductDetailsParam>
     **/
    @Override
    public List<HoProductDetailsParam> selectBelowProductDetailsList(HoProductDetailsParam hoProductDetailsParam) {
        return baseMapper.selectBelowProductDetailsList(hoProductDetailsParam);
    }

    /**
     * @description: 查询站点配置商品列表
     * @author: zhang jing
     * @date: 2023/6/25 19:55
     * @param: [hoProductDetailsParam]
     * @return: java.util.List<com.hzs.system.home.vo.HoProductDetailsVO>
     **/
    @Override
    public List<HoProductDetailsVO> queryProductList(HoProductDetailsParam hoProductDetailsParam) {
         if(null!=hoProductDetailsParam.getStartDate()&&null!=hoProductDetailsParam.getEndDate()){
             hoProductDetailsParam.setEndDate(DateUtils.afterDateTime(1, ChronoUnit.DAYS,hoProductDetailsParam.getEndDate()));
         }
        return baseMapper.queryProductList(hoProductDetailsParam);
    }
}
