package com.njcn.system.controller;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;

import com.njcn.system.pojo.param.ReportTemplateParam;
import com.njcn.system.pojo.po.ReportTemplate;
import com.njcn.system.service.ReportTemplateService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * pqs-event
 * 暂态报告模板
 * @author cdf
 * @date 2022/8/29
 */
@Slf4j
@RestController
@RequestMapping("/reportTemplate")
@Api(tags = "暂态报告模板")
@AllArgsConstructor
public class ReportTemplateController extends BaseController {

    private final ReportTemplateService reportTemplateService;


    /**
     * 新增暂态报表模板
     * @param reportTemplateParam 暂态报表模板实体
     * @author cdf
     * @date 2022/7/5
     */
    @PostMapping("addReportTemplate")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON,operateType = OperateType.ADD)
    @ApiOperation("新增暂态报表模板")
    @ApiImplicitParam(name = "reportTemplateParam",value = "暂态报表模板实体",required = true)
    public HttpResult<Object> addReportTemplate(@RequestBody @Validated ReportTemplateParam reportTemplateParam){
        String methodDescribe = getMethodDescribe("addReportTemplate");
        boolean res = reportTemplateService.addReportTemplate(reportTemplateParam);
        if(res){
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
    }


    /**
     * 修改暂态报表模板
     * @author cdf
     * @date 2022/7/5
     */
    @PostMapping("updateReportTemplate")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON,operateType = OperateType.UPDATE)
    @ApiOperation("修改暂态报表模板")
    @ApiImplicitParam(name = "updateReportTemplateParam",value = "暂态报表模板实体",required = true)
    public HttpResult<Object> updateReportTemplate(@RequestBody @Validated ReportTemplateParam.UpdateReportTemplateParam updateReportTemplateParam){
        String methodDescribe = getMethodDescribe("updateReportTemplate");
        boolean res = reportTemplateService.updateReportTemplate(updateReportTemplateParam);
        if(res){
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
    }




    /**
     * 查询所有暂态报表模板
     * @author cdf
     * @date 2022/7/5
     * @return Page<ReportTemplate>
     */
    @GetMapping("getAllReportTemplateList")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("查询所有暂态报表模板")
    public HttpResult<List<ReportTemplate>> getAllReportTemplateList(){
        String methodDescribe = getMethodDescribe("getAllReportTemplateList");
        List<ReportTemplate> list = reportTemplateService.getAllReportTemplateList();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }


    /**
     * 根据暂态报表模板id查询暂态报表模板
     * @param id 暂态报表模板id
     * @author cdf
     * @date 2022/7/5
     * @return ReportTemplate
     */
    @GetMapping("getReportTemplateById")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("根据暂态报表模板id查询暂态报表模板")
    @ApiImplicitParam(name = "id",value = "暂态报表模板id",required = true)
    public HttpResult<ReportTemplate> getReportTemplateById(@RequestParam("id") String id){
        String methodDescribe = getMethodDescribe("getReportTemplateById");
        ReportTemplate reportTemplate = reportTemplateService.getReportTemplateById(id);
        if(Objects.nonNull(reportTemplate)){
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, reportTemplate, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);

    }


    /**
     * 删除暂态报表模板
     * @param ids 暂态报表模板id
     * @author cdf
     * @date 2022/7/5
     * @return boolean
     */
    @PostMapping("delReportTemplate")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("删除暂态报表模板")
    @ApiImplicitParam(name = "ids",value = "暂态报表模板ids",required = true)
    public HttpResult<ReportTemplate> delReportTemplate(@RequestBody List<String> ids){
        String methodDescribe = getMethodDescribe("delReportTemplate");
        boolean res = reportTemplateService.delReportTemplate(ids);
        if(res){
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
    }


}
