package com.hzs.sale.wares.provider;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hzs.common.core.domain.R;
import com.hzs.common.domain.sale.wares.BdWaresLabel;
import com.hzs.sale.wares.IWaresServiceApi;
import com.hzs.sale.wares.service.IBdWaresLabelService;
import com.hzs.sale.wares.service.IBdWaresService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

@DubboService
public class WaresServiceProvider implements IWaresServiceApi {

    @Autowired
    private IBdWaresService iBdWaresService;
    @Autowired
    private IBdWaresLabelService iBdWaresLabelService;

    @Override
    public R<Boolean> checkLabelisUse(Integer pkLabel) {
        LambdaQueryWrapper<BdWaresLabel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BdWaresLabel::getPkLable, pkLabel);
        int count = iBdWaresLabelService.count(queryWrapper);
        if (count > 0) {
            return R.ok(true);
        } else {
            return R.fail(false);
        }
    }

    @Override
    public void updateByAutoStartAndAutoStart(Date currentTime) {
        iBdWaresService.updateByAutoStartAndAutoStart(currentTime);
    }

    @Override
    public void waresPreSale() {
        iBdWaresService.waresPreSale();
    }

    @Override
    public void updateByAutoStartAndAutoEnd(Date currentTime) {
        iBdWaresService.updateByAutoStartAndAutoEnd(currentTime);
    }

}
