/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.distribution.comment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.common.config.Constant;
import com.yami.shop.distribution.comment.dao.DistributionRecruitSetMapper;
import com.yami.shop.distribution.comment.model.DistributionRecruitSet;
import com.yami.shop.distribution.comment.service.DistributionRecruitSetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 *
 * @author lgh on 2019/04/01.
 */
@Service
public class DistributionRecruitSetServiceImpl extends ServiceImpl<DistributionRecruitSetMapper, DistributionRecruitSet> implements DistributionRecruitSetService {

    @Autowired
    private DistributionRecruitSetMapper distributionRecruitSetMapper;

    @Override
    @Cacheable(cacheNames = "DistributionRecruitSet", key = "'0'")
    public DistributionRecruitSet getByShopId() {
        DistributionRecruitSet distributionRecruitSet=distributionRecruitSetMapper.selectOne(new LambdaQueryWrapper<DistributionRecruitSet>()
            .eq(DistributionRecruitSet::getShopId, Constant.PLATFORM_SHOP_ID)
        );
//        if(distributionRecruitSet == null){
//            return createInitialDistributionRecruitSet(shopId);
//        }
        return distributionRecruitSet;
    }

//    @Override
//    public DistributionRecruitSet createInitialDistributionRecruitSet(Long shopId) {
//        DistributionRecruitSet distributionRecruitSet=new DistributionRecruitSet();
//        distributionRecruitSet.setShopId(shopId);
//        distributionRecruitSet.setTitle("分销员推广");
//        distributionRecruitSet.setState(0);
//        distributionRecruitSetMapper.insert(distributionRecruitSet);
//        return distributionRecruitSet;
//    }

    @Override
    @CacheEvict(cacheNames = "DistributionRecruitSet", key = "'0'")
    public void removeCacheByShopId(Long shopId) {

    }

}
