package com.lantone.daqe.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lantone.common.api.CommonResult;
import com.lantone.daqe.dto.GetByIdColumnVerifyDTO;
import com.lantone.daqe.dto.GetColumnNameDTO;
import com.lantone.daqe.dto.GetColumnVerifyPageDTO;
import com.lantone.daqe.dto.GetRegularDTO;
import com.lantone.daqe.dto.GetTableColumnNameDTO;
import com.lantone.daqe.dto.GetTableNameDTO;
import com.lantone.daqe.facade.ColumnVerifyManagementFacade;
import com.lantone.daqe.vo.AddColumnVO;
import com.lantone.daqe.vo.AddColumnVerifyVO;
import com.lantone.daqe.vo.DelColumnVerifyVO;
import com.lantone.daqe.vo.GetByIdColumnVerifyVO;
import com.lantone.daqe.vo.GetColumnNameVO;
import com.lantone.daqe.vo.GetColumnVerifyPageVO;
import com.lantone.daqe.vo.GetRegularVO;
import com.lantone.daqe.vo.GetTableColumnNameVO;
import com.lantone.daqe.vo.GetTableNameVO;
import com.lantone.daqe.vo.UpdateColumnVerifyVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 字段校验规则维护API
 * @author： zhanghang
 * @time: 2022/3/1 10:14
 */

@RestController
@Api(value = "字段校验规则维护API", tags = { "字段校验规则维护API" })
@RequestMapping("/columnVerifyManagement")
public class ColumnVerifyManagementController {

    @Autowired
    private ColumnVerifyManagementFacade columnVerifyManagementFacade;


    @ApiOperation(value = "获取字段校验规则维护分页列表 [by:zhanghang]")
    @PostMapping("/getColumnVerifyPage")
    public CommonResult<IPage<GetColumnVerifyPageDTO>> getColumnVerifyPage(@RequestBody GetColumnVerifyPageVO getColumnVerifyPageVO) {
        return CommonResult.success(columnVerifyManagementFacade.getColumnVerifyPage(getColumnVerifyPageVO));
    }

    @ApiOperation(value = "根据ID获取字段校验规则明细数据 [by:zhanghang]")
    @PostMapping("/getByIdColumnVerify")
    public CommonResult<GetByIdColumnVerifyDTO> getByIdColumnVerify(@RequestBody GetByIdColumnVerifyVO getByIdColumnVerifyVO) {
        return CommonResult.success(columnVerifyManagementFacade.getByIdColumnVerify(getByIdColumnVerifyVO));
    }

    @ApiOperation(value = "查询下拉框获取数据库表中列数据表名称信息 [by:zhanghang]")
    @PostMapping("/getTableName")
    public CommonResult<List<GetTableNameDTO>> getTableName(@RequestBody GetTableNameVO getTableNameVO) {
        return CommonResult.success(columnVerifyManagementFacade.getTableName(getTableNameVO));
    }

    @ApiOperation(value = "查询下拉框获取数据库表中列数据字段名称信息 [by:zhanghang]")
    @PostMapping("/getColumnName")
    public CommonResult<List<GetColumnNameDTO>> getColumnName(@RequestBody GetColumnNameVO getColumnNameVO) {
        return CommonResult.success(columnVerifyManagementFacade.getColumnName(getColumnNameVO));
    }

    @ApiOperation(value = "新增修改下拉框获取数据库表中列数据字段名称信息 [by:zhanghang]")
    @PostMapping("/getAddUpColumnName")
    public CommonResult<List<GetTableColumnNameDTO>> getTableColumnName(@RequestBody GetTableColumnNameVO getTableColumnNameVO) {
        return CommonResult.success(columnVerifyManagementFacade.getTableColumnName(getTableColumnNameVO ));
    }

    @ApiOperation(value = "下拉框获取正则式名称 [by:zhanghang]")
    @PostMapping("/getRegular")
    public CommonResult<List<GetRegularDTO>> getRegular(@RequestBody GetRegularVO getRegularVO) {
        return CommonResult.success(columnVerifyManagementFacade.getRegular(getRegularVO));
    }


    @ApiOperation(value = "新增字段校验规则 [by:zhanghang]")
    @PostMapping("/addColumnVerify")
    @Transactional
    public CommonResult<Boolean> addColumnVerify(@RequestBody AddColumnVerifyVO addColumnVerifyVO) {
        return CommonResult.success(columnVerifyManagementFacade.addColumnVerify(addColumnVerifyVO));
    }

    @ApiOperation(value = "删除字段校验规则 [by:zhanghang]")
    @PostMapping("/delColumnVerify")
    @Transactional
    public CommonResult<Boolean> delColumnVerify(@RequestBody DelColumnVerifyVO delColumnVerifyVO) {
        return CommonResult.success(columnVerifyManagementFacade.delColumnVerify(delColumnVerifyVO));
    }

    @ApiOperation(value = "修改字段校验规则 [by:zhanghang]")
    @PostMapping("/updateColumnVerify")
    @Transactional
    public CommonResult<Boolean> updateColumnVerify(@RequestBody UpdateColumnVerifyVO updateColumnVerifyVO) {
        return CommonResult.success(columnVerifyManagementFacade.updateColumnVerify(updateColumnVerifyVO));
    }

    @ApiOperation(value = "根据表名新增字段信息 [by:zhanghang]")
    @PostMapping("/addColumn")
    @Transactional
    public CommonResult<Boolean> addColumn(@RequestBody AddColumnVO addColumnVO) {
        return CommonResult.success(columnVerifyManagementFacade.addColumn(addColumnVO));
    }
}
