package com.hzs.activity.base.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.activity.base.mapper.AcBaseConfigMapper;
import com.hzs.activity.base.service.IAcBaseConfigService;
import com.hzs.activity.people.vo.AcBaseConfigVO;
import com.hzs.common.core.enums.EDelFlag;
import com.hzs.common.domain.activity.base.AcBaseConfig;
import com.hzs.common.domain.activity.base.ext.AcBaseConfigExt;
import org.springframework.stereotype.Service;

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

/**
 * 活动基本配置表 服务实现类
 *
 * @author hzs
 * @since 2023-04-20
 */
@Service
public class AcBaseConfigServiceImpl extends ServiceImpl<AcBaseConfigMapper, AcBaseConfig> implements IAcBaseConfigService {

    @Override
    public List<AcBaseConfig> selectBaseConfigByType(AcBaseConfigVO baseConfigVO) {
        return baseMapper.selectBaseConfigByType(baseConfigVO);
    }

    @Override
    public List<AcBaseConfigExt> queryBaseConfigList(Integer pkCountry, Long pkMember) {
        return baseMapper.queryBaseConfigList(pkCountry, pkMember);
    }

    @Override
    public AcBaseConfigExt queryBaseConfigDetail(Long pkId, Integer pkCountry) {
        LambdaQueryWrapper<AcBaseConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(AcBaseConfig::getActName, AcBaseConfig::getActCover, AcBaseConfig::getActStartDate, AcBaseConfig::getActEndDate, AcBaseConfig::getActExplain);
        queryWrapper.eq(AcBaseConfig::getPkId, pkId);
        queryWrapper.eq(AcBaseConfig::getPkCountry, pkCountry);
        return BeanUtil.copyProperties(baseMapper.selectById(pkId), AcBaseConfigExt.class);
    }

    @Override
    public AcBaseConfig queryBaseConfigById(Long pkBaseId) {
        return baseMapper.selectById(pkBaseId);
    }

    @Override
    public Boolean deleteBaseConfigById(Long pkBaseId, Long pkModifyId) {
        LambdaUpdateWrapper<AcBaseConfig> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(AcBaseConfig::getDelFlag, EDelFlag.DELETE.getValue());
        updateWrapper.set(AcBaseConfig::getPkModified, pkModifyId);
        updateWrapper.set(AcBaseConfig::getModifiedTime, new Date());
        updateWrapper.eq(AcBaseConfig::getPkId, pkBaseId);
        return update(updateWrapper);
    }

    @Override
    public List<AcBaseConfig> queryBaseConfigSpecial(Integer actType, Integer pkCountry) {
        return baseMapper.queryBaseConfigSpecial(actType, pkCountry);
    }

}
