package com.zt.plat.module.qms.business.bus.controller.admin;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
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 com.alibaba.fastjson2.JSONObject;
import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.module.qms.business.bus.controller.vo.*;
import com.zt.plat.module.qms.business.bus.service.SampleAnalysisAuditService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;

import static com.zt.plat.framework.common.pojo.CommonResult.success;

import java.util.List;
import java.util.Map;

/**
 * 分析审核
 */
@Tag(name = "管理后台 - 样品分析")
@RestController
@RequestMapping("/qms/bus/sample/analysis-audit")
@Validated
public class SampleAnalysisAuditController {
	
	@Resource
	private SampleAnalysisAuditService sampleAnalysisAuditService;

	/**
	 * 交叉审核
	 * @return
	 */
	@PostMapping("/crossAudit")
	public CommonResult<?> crossAudit(Long businessAssayTaskId, String auditStatus) {
		sampleAnalysisAuditService.crossAuditByByTaskId(businessAssayTaskId, auditStatus);
		return success("成功");
	}
	
	@GetMapping("/getSampleResultAssessmentList")
	public CommonResult<JSONObject> getSampleResultAssessmentList(Long configAssayMethodId, String assessmentStatus) {
		
		JSONObject result = sampleAnalysisAuditService.getSampleResultAssessmentList(configAssayMethodId, assessmentStatus);
		
		return success(result);
	}
	
	@GetMapping("/getResultAssessment")
	public CommonResult<?> getResultAssessment(String assayType, Long sampleId, Long configAssayMethodId) {
		JSONObject result = null;
		if ("平行".equals(assayType)) {
			result = sampleAnalysisAuditService.getParallelResultAssessment(sampleId, configAssayMethodId);
		} else if ("双杯".equals(assayType)) {
			result = sampleAnalysisAuditService.getDoubleCupResultAssessment(sampleId, configAssayMethodId);
		}
		return success(result);
	}
	
	//平行分析结果判定
	@GetMapping("/getParallelResultAssessment")
	public CommonResult<?> getParallelResultAssessment(Long businessSubSampleId, Long configAssayMethodId) {
		JSONObject result = sampleAnalysisAuditService.getParallelResultAssessment(businessSubSampleId, configAssayMethodId);
		return success(result);
	}
	
	//双杯分析结果判定
	@GetMapping("/getDoubleCupResultAssessment")
	public CommonResult<?> getDoubleCupResultAssessment(Long businessSubParentSampleId, Long configAssayMethodId) {
		JSONObject result = sampleAnalysisAuditService.getDoubleCupResultAssessment(businessSubParentSampleId, configAssayMethodId);
		return success(result);
	}
	
	//修改结果判定
	@PostMapping("/modifyResultAssessment")
	public CommonResult<?> modifyResultAssessment(@RequestBody ModifyResultAssessmentReqVO reqVO) {
		JSONObject result = null;
		if ("平行".equals(reqVO.getAssayType())) {
			result = sampleAnalysisAuditService.modifyParallelResultAssessment(reqVO.getSampleId(), reqVO.getConfigAssayMethodId(), reqVO.getSampleAssessmentId(), reqVO.getBusinessAssayProjectDataIds());
		} else if ("双杯".equals(reqVO.getAssayType())) {
			
		}
		return success(result);
	}
	
	//判定数据上报
	@PostMapping("/assessmentDataReporting")
	public CommonResult<?> assessmentDataReporting(Long businessSubSampleId, Long configAssayMethodId) {
		sampleAnalysisAuditService.assessmentDataReporting(businessSubSampleId, configAssayMethodId);
		return success("成功"); 
	}
	
	//重新创建复检委托
	@PostMapping("/createReAnalysis")
	public CommonResult<?> createReAnalysis(Long businessSubSampleId, Long configAssayMethodId) {
		sampleAnalysisAuditService.createReAnalysis(businessSubSampleId, configAssayMethodId);
		return success("成功"); 
	}
	
}
