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;

/**
 * @BelongsProject: hzs_cloud
 * @BelongsPackage: com.hzs.sale.wares.provider
 * @Author: yh
 * @CreateTime: 2023-03-02  17:07
 * @Description: TODO
 * @Version: 1.0
 */
@DubboService
public class WaresServiceProvider implements IWaresServiceApi {

    @Autowired
    private IBdWaresService waresService;
    @Autowired
    private IBdWaresLabelService waresLabelService;

    /**
     * 校验标签是否使用
     *
     * @param pkLabel 标签主键
     * @return
     */
    @Override
    public R<Boolean> checkLabelisUse(Integer pkLabel) {
        LambdaQueryWrapper<BdWaresLabel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BdWaresLabel::getPkLable, pkLabel);
        int count = waresLabelService.count(queryWrapper);
        if (count > 0) {
            return R.ok(true);
        } else {
            return R.fail(false);
        }
    }

    /**
     * 修改自动上下架状态（自动上架）
     *
     * @param currentTime 当前时间
     */
    @Override
    public void updateByAutoStartAndAutoStart(Date currentTime) {
        waresService.updateByAutoStartAndAutoStart(currentTime);
    }

    /**
     * @description: 修改商品预售状态
     * @author: zhang jing
     * @date: 2024/10/24 16:09
     * @param: []
     * @return: void
     **/
    @Override
    public void waresPreSale() {
        waresService.waresPreSale();
    }


    /**
     * 修改自动上下架状态（自动下架）
     *
     * @param currentTime 当前时间
     */
    @Override
    public void updateByAutoStartAndAutoEnd(Date currentTime) {
        waresService.updateByAutoStartAndAutoEnd(currentTime);
    }

}
