package com.njcn.harmonic.controller.report;

import cn.hutool.core.date.TimeInterval;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.harmonic.pojo.dto.FpyReportDTO;
import com.njcn.harmonic.pojo.param.QualifiedReportParam;
import com.njcn.harmonic.service.majornetwork.QualifiedReportService;
import com.njcn.web.constant.ValidMessage;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
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.regex.Pattern;


/**
 * pqs
 * 合格率报告
 * @author cdf
 * @date 2023/5/31
 */
@Slf4j
@RestController
@RequestMapping("/qualifiedReport")
@Api(tags = "报告-合格率报告")
@RequiredArgsConstructor
public class QualifiedReportController extends BaseController {

    private final QualifiedReportService qualifiedReportService;

    /**
     * 合格率报告
     * @author cdf
     * @date 2023/6/7
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/pageTable")
    @ApiOperation("合格率报告_列表")
    @ApiImplicitParam(name = "qualifiedReportParam", value = "合格率报告参数", required = true)
    public HttpResult<Page<FpyReportDTO>> pageTable(@RequestBody @Validated QualifiedReportParam qualifiedReportParam) {
        TimeInterval timeInterval = new TimeInterval();
//        String searchValue = qualifiedReportParam.getSearchValue();
//        Pattern pattern = Pattern.compile(PatternRegex.SPECIAL_REGEX);
//        if(pattern.matcher(searchValue).find()){
//            throw new BusinessException(ValidMessage.SPECIAL_REGEX);
//        }
        String methodDescribe = getMethodDescribe("pageTable");
        Page<FpyReportDTO> result = qualifiedReportService.pageTable(qualifiedReportParam);
        log.info("合格率报告执行时长:"+timeInterval.interval());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);

    }


}
