package com.liquidnet.client.admin.zhengzai.goblin.service.imp;

import com.liquidnet.client.admin.zhengzai.goblin.service.IGoblinFrontBannerService;
import com.liquidnet.client.admin.zhengzai.kylin.utils.DataUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.goblin.constant.GoblinRedisConst;
import com.liquidnet.service.goblin.entity.GoblinFrontBanner;
import com.liquidnet.service.goblin.mapper.GoblinFrontBannerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 轮播图 服务实现类
 * </p>
 *
 * @author liquidnet
 * @since 2021-12-27
 */
@Service
public class GoblinFrontBannerServiceImpl extends ServiceImpl<GoblinFrontBannerMapper, GoblinFrontBanner> implements IGoblinFrontBannerService {
    @Autowired
    private MongoTemplate mongoTemplate;
    @Autowired
    private DataUtils dataUtils;
    @Autowired
    GoblinFrontBannerMapper goblinFrontBannerMapper;
    @Autowired
    private RedisUtil redisUtil;

    public boolean create(GoblinFrontBanner goblinFrontBanner){
        //设置bannerid
        goblinFrontBanner.setBannerId(GoblinRedisConst.FRONT_BANNER+ IDGenerator.nextTimeId());
        //增加 banner
        goblinFrontBannerMapper.insert(goblinFrontBanner);
        //mongo  db增加
        mongoTemplate.save(goblinFrontBanner,GoblinFrontBanner.class.getSimpleName());
      /*  if(redisUtil.hasKey(GoblinRedisConst.FRONT_BANNER+"0")){
            //从redis里面取出
            ArrayList<GoblinFrontBanner> list = (ArrayList<GoblinFrontBanner>) redisUtil.get(GoblinRedisConst.FRONT_BANNER+0);
            list.add(goblinFrontBanner);
            redisUtil.set(GoblinRedisConst.FRONT_BANNER+"0",list);
        }else{
            //创建一个list
            ArrayList<Object> list=CollectionUtil.arrayListObject();
            list.add(goblinFrontBanner);
            //redis 没有这个键*/
            redisUtil.set(GoblinRedisConst.FRONT_BANNER+"0","fsdf1");
       /* }*/
        return true;
    }

}
