package com.emr.controller.quality;

import com.alibaba.fastjson.JSON;
import com.emr.annotation.OptionalLog;
import com.emr.service.quality.QualityService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName QualityController
 * @Description 文件质检模块
 * @Author linjj
 * @Date 2023/4/13 14:51
 * @Version 1.0
 */
@Controller
@RequestMapping("qualityModel/")
public class QualityController {

    @Autowired
    QualityService qualityService;


    @RequiresPermissions("/qualityModel/qualityJsp")
    @OptionalLog(module = "查看", methods = "质检")
    @RequestMapping("qualityJsp")
    public String qualityModel(Model model) {
        return "quality/quality";
    }

    /**
     * @description: 查询功能
     * @params: startRange
     * @params: endRange
     * @return: String
     * @author linjj
     * @date: 2023/4/13 15:24
     */
    @RequestMapping(value = "getPhAndDocumentNum", method = RequestMethod.POST)
    @ResponseBody
    public String getPhAndDocumentNum(String startRange, String endRange) {
        if (StringUtils.isEmpty(startRange) && StringUtils.isEmpty(endRange)) {
            return "开始范围,结束范围不能全部为空";
        }
        if (StringUtils.isNotEmpty(startRange) && StringUtils.isNotEmpty(endRange)) {
            if (startRange.compareTo(endRange) > 0) {
                return "开始范围不能小于结束范围";
            }
        }
        String phAndDocumentNum = qualityService.getPhAndDocumentNum(startRange, endRange);
        return JSON.toJSONString(phAndDocumentNum);
    }

    /**
     * @description: 检查功能
     * @params: startRange
     * @params: endRange
     * @return: String
     * @author linjj
     * @date: 2023/4/14 9:32
     */
    @RequestMapping(value = "examineDocument", method = RequestMethod.POST)
    @ResponseBody
    public String examineDocument(String startRange, String endRange) {
        if (StringUtils.isEmpty(startRange) && StringUtils.isEmpty(endRange)) {
            return "开始范围,结束范围不能全部为空";
        }
        if (StringUtils.isNotEmpty(startRange) && StringUtils.isNotEmpty(endRange)) {
            if (startRange.compareTo(endRange) > 0) {
                return "开始范围不能小于结束范围";
            }
        }
        String s = qualityService.examineDocument(startRange, endRange);
        return JSON.toJSONString(s);
    }
    /**
     * @description: 高级检查
     * @params: startRange
     * @params: endRange
     * @return: String
     * @author linjj
     * @date: 2023/4/14 9:32
     */
    @RequestMapping(value = "SeniorExamine", method = RequestMethod.POST)
    @ResponseBody
    public String SeniorExamine(String startRange, String endRange) {
        if (StringUtils.isEmpty(startRange) && StringUtils.isEmpty(endRange)) {
            return "开始范围,结束范围不能全部为空";
        }
        if (StringUtils.isNotEmpty(startRange) && StringUtils.isNotEmpty(endRange)) {
            if (startRange.compareTo(endRange) > 0) {
                return "开始范围不能小于结束范围";
            }
        }
        String s = qualityService.SeniorExamine(startRange, endRange);
        return JSON.toJSONString(s);
    }
}
