package com.hzs.member.storeconfig.provider;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzs.common.core.domain.R;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.domain.member.storeconfig.BdStoreMonthCheckConfig;
import com.hzs.member.storeconfig.IBdStoreMonthCheckConfigApi;
import com.hzs.member.storeconfig.dto.StoreMonthCheckConfigDto;
import com.hzs.member.storeconfig.service.IBdStoreMonthCheckConfigService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@DubboService
public class IBdStoreMonthCheckConfigProvider implements IBdStoreMonthCheckConfigApi {

    @Autowired
    private IBdStoreMonthCheckConfigService storeMonthCheckConfigService;

    @Override
    public R<StoreMonthCheckConfigDto> getByStoreMonthCheckConfig(Integer pkStoreMonthCheckConfig) {
        QueryWrapper<BdStoreMonthCheckConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("PK_ID", pkStoreMonthCheckConfig);
        queryWrapper.ge("START_DATE", DateUtils.currentDate());
        queryWrapper.le("END_DATE", DateUtils.currentDate());
        BdStoreMonthCheckConfig storeMonthCheckConfig = storeMonthCheckConfigService.getOne(queryWrapper);
        StoreMonthCheckConfigDto storeMonthCheckConfigDto = BeanUtil.copyProperties(storeMonthCheckConfig, StoreMonthCheckConfigDto.class);
        return R.ok(storeMonthCheckConfigDto);
    }
}
