package com.liangjian.dataplatform.member.controller;

import com.liangjian.dataplatform.member.entity.response.PageResult;
import com.liangjian.dataplatform.member.entity.response.ResultObject;
import com.liangjian.dataplatform.member.service.ITagDatabaseService;
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.Map;

/**
 * @author 黄树文
 * @date 2020/4/17 16:41
 */
@RestController
@RequestMapping("/tagDataBase")
@Api(value = "标签库接口控制器", tags = "标签库接口控制器")
public class TagDatabaseController {

    @Autowired
    private ITagDatabaseService iTagDatabaseService;

    @GetMapping("/findByTagTypeName")
    @ApiOperation(value = "根据标签类型名称分页查询标签")
    public ResultObject<PageResult<Map<String, Object>>> findByTagTypeName(@ApiParam(value = "页数") @RequestParam("pageIndex") Integer pageIndex,
                                                                           @ApiParam(value = "每页条数") @RequestParam("pageSize") Integer pageSize,
                                                                           @ApiParam(value = "标签类型名称") @RequestParam("tagTypeName") String tagTypeName) throws IOException {
        if(pageIndex == null || pageSize == null || tagTypeName == null || "".equals(tagTypeName)){
            return ResultObject.error("pageIndex|pageSize|tagTypeName均不能为空");
        }
        if(pageIndex <=0 || pageSize <=0){
            return ResultObject.error("pageIndex|pageSize必须大于0");
        }
        if(pageIndex*pageSize > 10000){
            return PageResult.error("查询的记录不能超过10000行");
        }

        return ResultObject.success(iTagDatabaseService.queryByCondition(pageIndex, pageSize, tagTypeName));
    }



}
