package com.liangjian.dataplatform.member.controller;

import com.liangjian.dataplatform.member.entity.po.elasticsearch.AreaData;
import com.liangjian.dataplatform.member.entity.po.elasticsearch.AreaDataTag;
import com.liangjian.dataplatform.member.entity.response.ResultObject;
import com.liangjian.dataplatform.member.entity.vo.request.BirdGirdRequest;
import com.liangjian.dataplatform.member.entity.vo.response.BirdGirdTableResponse2;
import com.liangjian.dataplatform.member.service.IAreaDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.ArrayList;

/**
 * @author 黄树文
 * @date 2020/3/10 9:32
 */
@RestController
@RequestMapping("/areaData")
@Api(value = "区域数据数据搜索控制器", tags = "区域数据数据搜索控制器")
public class AreaDataController {

    @Autowired
    private IAreaDataService iAreaDataService;

    @PostMapping("/areaDataCondition")
    @ApiOperation(value = "查询积分记录(BirdGird)")
    public BirdGirdTableResponse2<AreaData> query2(@ApiParam(value = "birdgird的条件请求对象") @RequestBody BirdGirdRequest girdRequest) {
        girdRequest.setPageIndex(girdRequest.getPageIndex() - 1);
        return iAreaDataService.queryByCondition(girdRequest);
    }

    @GetMapping("/areaDataTag")
    @ApiOperation(value = "查询区域标签")
    public ResultObject<BirdGirdTableResponse2<AreaDataTag>> search(@ApiParam(value = "搜索关键词", required = true) @RequestParam String kw,
                                                                    @ApiParam(value = "页数", required = true) @RequestParam Integer page,
                                                                    @ApiParam(value = "每页数量", required = true) @RequestParam Integer pageSize) throws IOException {
        BirdGirdTableResponse2<AreaDataTag> list = iAreaDataService.findAreaDataTag(kw, page - 1, pageSize);
        return ResultObject.success(list);
    }

    @DeleteMapping("/areaDataTag")
    @ApiOperation(value = "删除标签")
    public ResultObject<Object> delete(@ApiParam(value = "删除区域数据标签", required = true) @RequestParam String id){
        if (iAreaDataService.deleteAreaDataTag(id)) {
            return ResultObject.success("删除成功", null);
        } else {
            return ResultObject.error("删除失败");
        }
    }

    @PostMapping("/areaDataTag")
    @ApiOperation(value = "保存标签")
    public ResultObject<Object> saveAllAreaDataTag(@ApiParam(value = "删除区域数据标签", required = true) @RequestBody ArrayList<AreaDataTag> areaDataTags){
        if (iAreaDataService.saveAllAreaDataTag(areaDataTags)) {
            return ResultObject.success("保存标签成功", null);
        } else {
            return ResultObject.error("保存标签失败");
        }
    }



}
