package com.cyl.h5.controller;

import com.cyl.h5.pojo.vo.HomeConfigVO;
import com.cyl.manager.pms.service.ProductCategoryService;
import com.cyl.tencent.OrderMessageModel;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysDictTypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;

@RestController
@RequestMapping("/no-auth/home")
public class HomeController {
    @Autowired
    private ISysConfigService sysConfigService;
    @Autowired
    private ProductCategoryService categoryService;

    @Autowired
    @Qualifier("taskQueue")
    private BlockingQueue<OrderMessageModel> taskQueue;

    @Autowired
    private ISysDictTypeService dictTypeService;

    /**
     * 首页配置
     *
     * @return 首页配置
     */
    //@ApiOperation("获取首页banner配置")
    @GetMapping("/home-cfg")
    public ResponseEntity<HomeConfigVO> getHomeConfig() {
//        try {
//            //在需要的地方注入taskQueue队列，往队列里面添加model
//            ContentSharingStatisticsModel model = new ContentSharingStatisticsModel ();
//            model.setTid(1234L);
//            model.setServiceTime("111");
//            model.setMsg("msg");
//            //set需要的数据
//            taskQueue.put(model);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }

        HomeConfigVO res = new HomeConfigVO();
        res.setPublicCity(sysConfigService.selectConfigByKey("order.city.list"));

        List<SysDictData> data = dictTypeService.selectDictDataByType("sys_banner");
        if (StringUtils.isNull(data))
        {
            data = new ArrayList<SysDictData>();
        }

        res.setBannerList(data);

        //res.setBanners(sysConfigService.selectConfigByKey("h5.home.banner"));
        //res.setCategoryList(categoryService.queryCategoryWithProductsForH5());
        return ResponseEntity.ok(res);
    }
    /**
     * 首页配置
     *
     * @return 首页配置
     */
    //@ApiOperation("获取首页banner配置和产品目录")
    @GetMapping("/product-count")
    public ResponseEntity<HomeConfigVO> productCount() {
        HomeConfigVO res = new HomeConfigVO();
        res.setBanners(sysConfigService.selectConfigByKey("h5.home.banner"));
        res.setCategoryList(categoryService.queryCategoryWithProductsForH5());
        return ResponseEntity.ok(res);
    }
}
