package com.kcim.web;
import com.kcim.common.util.Result;
import com.kcim.dao.model.*;
import com.kcim.service.*;
import com.kcim.web.request.ChildColumnRequest;
import com.kcim.web.request.ReportRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 成本报表管理
 *
 * @author Wang.YS
 * @date 2023-11-01 10:41:09
 */
@RestController
@RequestMapping("/report")
@Api(tags = "成本报表配置相关接口")
@AllArgsConstructor
public class CostReportController {
    /**
     * 报表管理
     */
    private CostReportService costReportService;
    /**
     * 报表-报表列对照
     */
    private CostReportColumnService costReportColumnService;
    /**
     * 报表列管理
     */
    private CostColumnService costColumnService;
    /**
     * 报表跳转配置
     */
    private CostReportRedirectService costReportRedirectService;
    /**
     * 报表列子列管理
     */
    private CostChildColumnService costChildColumnService;



    @ApiOperation("报表设置-报表列管理-获取")
    @GetMapping("getColumnList")
    public Result getColumnList(@RequestParam(required = false,value = "current",defaultValue = "1") Integer current,
                                @RequestParam(required = false,value = "pageSize",defaultValue = "10")Integer pageSize,
                                @RequestParam(required = false,value = "columnName")String columnName,
                                @RequestParam(required = false,value = "columnType")String columnType){
        return Result.ok(costColumnService.getColumnList(current,pageSize,columnName,columnType));
    }


    @ApiOperation("报表设置-报表列管理-获取报表列类型")
    @GetMapping("getColumnType")
    public Result getColumnType(){
        return Result.ok(costColumnService.getColumnType());
    }

    /**
     * 新增报表列
     * @param column 报表列对象
     * @return 无返回值
     */
    @ApiOperation("报表设置-报表列管理-新增")
    @PostMapping("addColumn")
    public Result addColumn(@RequestBody CostColumn column){
        costColumnService.addColumn(column);
        return Result.ok();
    }


    @ApiOperation("报表设置-报表列管理-编辑")
    @PostMapping("editColumn")
    public Result editColumn(@RequestBody CostColumn column){
        costColumnService.editColumn(column);
        return Result.ok();
    }

    @ApiOperation("报表设置-报表列管理-删除")
    @PostMapping("deleteColumn")
    public Result deleteColumn(@RequestParam Integer id){
        costColumnService.deleteColumn(id);
        return Result.ok();
    }


    @ApiOperation("报表设置-报表列管理-添加子列")
    @PostMapping("addChildColumn")
    public Result addChildColumn(@RequestBody ChildColumnRequest childColumn){
        costChildColumnService.addChildColumn(childColumn);
        return Result.ok();
    }
    @ApiOperation("报表设置-报表列管理-子列获取报表列")
    @GetMapping("getChildColumnList")
    public Result getChildColumnList(@RequestParam Long columnCode){
        return Result.ok(costColumnService.getChildColumnList(columnCode));
    }
    @ApiOperation("报表设置-报表管理-获取")
    @GetMapping("getReport")
    public Result getList(@RequestParam(required = false,value = "reportName")String reportName,
    @RequestParam(required = false,value = "reportType")String reportType){
        return Result.ok(costReportService.getList(reportName,reportType));
    }

    @ApiOperation("报表设置-报表管理-新增")
    @PostMapping("addReport")
    public Result addReport(@RequestBody CostReport report){
        costReportService.addReport(report);
        return Result.ok();
    }
    @ApiOperation("报表设置-报表管理-编辑")
    @PostMapping("editReport")
    public Result editReport(@RequestBody CostReport report){
        costReportService.editReport(report);
        return Result.ok();
    }

    @ApiOperation("报表设置-报表管理-删除")
    @PostMapping("deleteReport")
    public Result deleteReport(@RequestParam Integer id){
        costReportService.deleteReport(id);
        return Result.ok();
    }
    @ApiOperation("报表设置-报表管理-获取报表列")
    @GetMapping("getReportColumn")
    public Result getReportColumn(@RequestParam(required = false,value = "current",defaultValue = "1") Integer current,
                                  @RequestParam(required = false,value = "pageSize",defaultValue = "10")Integer pageSize,
                                  @RequestParam Long reportCode,
                                  @RequestParam(required = false)String headText){
        return Result.ok(costReportColumnService.getReportColumn(current,pageSize,reportCode,headText));
    }
    @ApiOperation("报表设置-报表管理-获取报表列字典")
    @GetMapping("getReportCostColumn")
    public Result getReportCostColumn(@RequestParam Long reportCode,
                                  @RequestParam(required = false)String headText,
                                  @RequestParam(required = false,value = "columnType")String columnType){
        return Result.ok(costReportColumnService.getReportCostColumn(reportCode,headText,columnType));
    }
    @ApiOperation("报表设置-报表管理-新增报表列")
    @PostMapping("addReportColumn")
    public Result addReportColumn(@RequestBody List<CostReportColumn> ReportColumn){
        costReportColumnService.addReportColumn(ReportColumn);
        return Result.ok();
    }
    @ApiOperation("报表设置-报表管理-编辑报表列")
    @PostMapping("editReportColumn")
    public Result editReportColumn(@RequestBody List<CostReportColumn> ReportColumn){
        costReportColumnService.editReportColumn(ReportColumn);
        return Result.ok();
    }
    @ApiOperation("报表设置-报表管理-移除报表列")
    @PostMapping("deleteReportColumn")
    public Result deleteReportColumn(@RequestParam Integer id){
        costReportColumnService.deleteReportColumn(id);
        return Result.ok();
    }
    @ApiOperation("报表设置-报表管理-批量移除报表列")
    @PostMapping("batchDeleteReportColumn")
    public Result batchDeleteReportColumn(@RequestBody List<Integer> id){
        costReportColumnService.batchDeleteReportColumn(id);
        return Result.ok();
    }
    @ApiOperation("报表设置-报表管理-编辑状态")
    @PostMapping("editReportColumnStatus")
    public Result editReportColumnStatus(@RequestParam Integer id,
                                          @RequestParam Integer type,
                                          @RequestParam Integer status){
        costReportColumnService.editReportColumnStatus(id,type,status);
        return Result.ok();
    }
    @ApiOperation("报表设置-报表跳转管理-获取")
    @GetMapping("getRedirect")
    public Result getRedirect(@RequestParam(required = false,value = "current" ,defaultValue = "1")Integer current,
                              @RequestParam(required = false,value = "pageSize",defaultValue = "10")Integer pageSize,
                              @RequestParam(required = false,value = "reportName")String reportName){
        return Result.ok(costReportRedirectService.getRedirect(current,pageSize,reportName));
    }

    @ApiOperation("报表设置-报表跳转管理-新增")
    @PostMapping("addRedirect")
    public Result addRedirect(@RequestBody CostReportRedirect reportRedirect){
        costReportRedirectService.addRedirect(reportRedirect);
        return Result.ok();
    }

    @ApiOperation("报表设置-报表跳转管理-编辑")
    @PostMapping("editRedirect")
    public Result editRedirect(@RequestBody CostReportRedirect reportRedirect){
        costReportRedirectService.editRedirect(reportRedirect);
        return Result.ok();
    }

    @ApiOperation("报表设置-报表跳转管理-删除")
    @PostMapping("deleteRedirect")
    public Result deleteRedirect(@RequestParam Integer id){
        costReportRedirectService.deleteRedirect(id);
        return Result.ok();
    }
    SqlService sqlService;

    @ApiOperation("基础设置-自定义SQL管理-获取自定义sql类型")
    @GetMapping("getSqlType")
    public Result getSqlType(){
        return Result.ok(sqlService.getSqlType());
    }

    @ApiOperation("基础设置-自定义SQL管理-获取")
    @GetMapping("getSql")
    public Result getSql(@RequestParam String sqlType,
                         @RequestParam(required = false) String sqlDefinition){
        return Result.ok(sqlService.getSql(sqlType,sqlDefinition));
    }

    @ApiOperation("基础设置-自定义SQL管理-新增")
    @PostMapping("addSql")
    public Result addSql(@RequestBody Sql sql){
        sqlService.addSql(sql);
        return Result.ok();
    }
    @ApiOperation("基础设置-自定义SQL管理-排序")
    @PostMapping("sortSql")
    public Result sortSql(@RequestBody List<Sql> sql){
        sqlService.sortSql(sql);
        return Result.ok();
    }
    @ApiOperation("基础设置-自定义SQL管理-编辑")
    @PostMapping("editSql")
    public Result editSql(@RequestBody Sql sql){
        sqlService.editSql(sql);
        return Result.ok();
    }

    @ApiOperation("基础设置-自定义SQL管理-删除")
    @PostMapping("deleteSql")
    public Result deleteSql(@RequestParam Integer id){
        sqlService.deleteSql(id);
        return Result.ok();
    }



    ReportService reportService;
    @ApiOperation("报表管理-报表查询")
    @PostMapping("search")
    public Result getReportData(@RequestBody ReportRequest request){
        return Result.ok(reportService.getReportData(request.getCurrent(),request.getPageSize(),request.getReportCode(),request.getParameter()));
    }

    @ApiOperation("报表管理-报表跳转")
    @PostMapping("redirect")
    public Result redirect(@RequestBody ReportRequest request){
        return Result.ok(reportService.getReportData(request.getCurrent(), request.getPageSize(), request.getReportCode(),request.getParameter()));
    }

    @ApiOperation("报表管理-获取索引")
    @GetMapping("getReportIndex")
    public Result getReportIndex(@RequestParam Long reportCode){
        return Result.ok(reportService.getReportIndex(reportCode));
    }

}
