package cn.com.tenlion.bigdata.controller.app.apis.bigdatatemplate;

import cn.com.tenlion.bigdata.service.bigdatatemplate.IBigdataTemplateService;
import cn.com.tenlion.bigdata.util.BigDataResult;
import cn.com.tenlion.bigdata.util.EncryptUtils;
import cn.com.tenlion.bigdata.util.WeatherUtil;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResult;
import ink.wgink.util.UUIDUtil;
import ink.wgink.util.date.DateUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;

/**
 * @ClassName: NewsAntistopAppController
 * @Description: 大数据模板
 * @Author: WenG
 * @Date: 2020-05-08 23:30
 * @Version: 1.0
 **/
@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "大数据模板接口")
@RestController
@RequestMapping(ISystemConstant.APP_PREFIX + "/bigdatatemplate")
public class BigdataTemplateAppController extends DefaultBaseController {

    @Autowired
    private IBigdataTemplateService bigdataTemplateService;

    @ApiOperation(value = "天气查询", notes = "天气查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "区域ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("queryweather"+ISystemConstant.APP_RELEASE_SUFFIX )
    public BigDataResult queryWeather(String id) throws Exception {
        BigDataResult result = new BigDataResult();
        result.setData(WeatherUtil.getWeather(id));
        return result;
    }

    @ApiOperation(value = "联动接口查询测试", notes = "联动接口查询测试")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "querySql", value = "联动接口查询测试", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("querydemo"+ISystemConstant.APP_RELEASE_SUFFIX )
    public BigDataResult queryDemo(String mapLink, String dateLink, String selectLink) throws Exception {
        Map<String, Object> params = requestParams();
        System.out.println(params);
        BigDataResult result = new BigDataResult();
        if("玉泉区".equals(mapLink)) {
            List<Map<String, String>> list = new ArrayList<Map<String, String>>();
            for(int i = 0 ; i < 11 ; i++) {
                Map<String, String> map = new LinkedHashMap<String, String>();
                map.put("title", "呼和浩特公安局玉泉分局");
                map.put("content", "接口响应演示数据:" + UUIDUtil.get32UUID() + UUIDUtil.get32UUID());
                map.put("date", dateLink == null ? DateUtil.getDay() : dateLink);
                list.add(map);
            }
            result.setList(list);
        }
        return result;
    }

    @ApiOperation(value = "SQL校验(加密传输)", notes = "SQL校验(加密传输)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "querySql", value = "SQL校验", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("querysql"+ISystemConstant.APP_RELEASE_SUFFIX )
    public BigDataResult querySqlDataCheck(String querySql) throws Exception {
        String querySQL = EncryptUtils.aesDecrypt(querySql);
        return bigdataTemplateService.querySqCheck(querySQL);
    }

    @ApiOperation(value = "区域SQL查询", notes = "区域SQL查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "areaId", value = "区域ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("querydata"+ISystemConstant.APP_RELEASE_SUFFIX + "/{areaId}")
    public BigDataResult querySqlData(@PathVariable("areaId") String areaId) throws Exception {
            return bigdataTemplateService.querySqlAll(areaId);
    }

    @ApiOperation(value = "大数据模板编码批量生成", notes = "大数据模板编码批量生成")
    @ApiImplicitParams({
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("buiderbigdatatemplateall"+ISystemConstant.APP_RELEASE_SUFFIX)
    public SuccessResult buiderBigdataTemplateAll() throws Exception {
        return bigdataTemplateService.buiderBigdataTemplateAll();
    }

    @ApiOperation(value = "大数据模板编码生成", notes = "大数据模板编码生成")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bigdataTemplateCode", value = "大数据模板编码", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("buiderbigdatatemplate"+ISystemConstant.APP_RELEASE_SUFFIX+"/{bigdataTemplateCode}")
    public SuccessResult buiderBigdataTemplateByBigdataTemplateId(@PathVariable("bigdataTemplateCode") String bigdataTemplateCode) throws Exception {
        return bigdataTemplateService.buiderBigdataTemplateByBigdataTemplateCode(bigdataTemplateCode);
    }

    @ApiOperation(value = "大数据模板编码生成", notes = "大数据模板编码生成")
    @ApiImplicitParams({
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("getdata"+ISystemConstant.APP_RELEASE_SUFFIX)
    @ResponseBody
    public Map<String, Object> getData() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("state", 200);
        map.put("msg", "查询成功");
        Integer[] list = {590,932,901,934,1290,1330,1320};
        map.put("list", list);
        return map;
    }

}
