package com.nbclass.activity.controller.casesfirst;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.nbclass.activity.model.*;
import com.nbclass.activity.service.CaseTypeService;
import com.nbclass.activity.service.ElasticSearchService;
import com.nbclass.vo.base.Result;
import org.springframework.beans.factory.annotation.Autowired;
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.Map;

/**
 * 案例web前台
 * @author gao
 * @datetime 2021年10月12日
 */
@RestController
@RequestMapping("/caseType")
public class CaseTypeController {

    @Autowired
    private CaseTypeService caseTypeService;

    @Autowired
    private ElasticSearchService elasticSearchService;

    /**
     * 数据字典(案例类型、案例用途、创意形式、节日事件)列表查询
     * @return
     */
    @GetMapping("/getTypeCase")
    public Result getTypeCase(Integer dictId){
        List<DataDictItem> list = caseTypeService.getTypeCase(dictId);
        return Result.success(list);
    }

    /**
     * 字典值类型列表查询
     * @return
     */
    @GetMapping("/getDictionariesType")
    public Result getDictionariesType(){
        List<DataDict> list = caseTypeService.getDictionariesType();
        return Result.success(list);
    }


    /**
     *  案例列表
     * @param keyWord 任意参数（案例标签，案例标题，案例编号）
     * @param tagIds 标签id
     * @return
     */
    @GetMapping("/getSearchCase")
    public Result getSearchCase(String keyWord,String tagIds,Integer page,Integer pageSize){
        Map<String, Object> map = elasticSearchService.getList(page,pageSize,"",keyWord,tagIds,"");
        List<Content> list = (List<Content>) map.get("rows");
        for (Content content : list) {
            Content listCase = caseTypeService.getListCase(content.getId());
            content.setUserTotal(listCase.getUserTotal());
            content.setTotalScore(listCase.getTotalScore());
        }
        map.put("rows",list);
        return Result.success(map);
    }

    /**
     * 获取案例标签
     * @param contentId 案例id
     * @return
     */
    @GetMapping("/getContentTags")
    public Result getContentTags(Integer contentId){
        ContentTags contentTags = caseTypeService.getContentTags(contentId);
        return Result.success(contentTags);
    }


}
