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

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
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.constant.SystemFieldConstants;
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;

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

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

    @Override
    public AcBaseConfigExt queryBaseConfigDetail(Long pkId, Integer pkCountry) {
        QueryWrapper<AcBaseConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("act_name,act_cover,act_start_date,act_end_date,act_explain");
        queryWrapper.eq(SystemFieldConstants.PK_ID, pkId);
        queryWrapper.eq(SystemFieldConstants.PK_COUNTRY, 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) {
        UpdateWrapper<AcBaseConfig> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set(SystemFieldConstants.DEL_FLAG, EDelFlag.DELETE.getValue());
        updateWrapper.set(SystemFieldConstants.PK_MODIFIED, pkModifyId);
        updateWrapper.set(SystemFieldConstants.MODIFIED_TIME, new Date());
        updateWrapper.eq("PK_ID", pkBaseId);
        return update(updateWrapper);
    }

    @Override
    public AcBaseConfigExt queryBaseAndOther(Long pkId) {
        return baseMapper.queryBaseAndOther(pkId);
    }

}
