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.business.interceptor.BusinessControllerMarker;
import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.datapermission.core.annotation.DeptDataPermissionIgnore;
import com.zt.plat.module.qms.business.bus.controller.vo.*;
import com.zt.plat.module.qms.business.bus.service.SampleAnalysisService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;

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

/**
 * 样品分析
 */
@Tag(name = "管理后台 - 样品分析")
@RestController
@RequestMapping("/qms/bus/sample/analysis")
@Validated
@DeptDataPermissionIgnore(enable = "true")
public class SampleAnalysisController implements BusinessControllerMarker {
	
	@Resource
	private SampleAnalysisService sampleAnalysisService ;
	
	@Deprecated
	@GetMapping("/batchSampleAnalysisByTaskId")
	public CommonResult<?> batchSampleAnalysisByTaskId(Long businessAssayTaskId) {
		BusinessAssayTaskAnalysisSampleProjectRespVO businessAssayTaskAnalysisSampleProject = sampleAnalysisService.batchSampleAnalysisByTaskId(businessAssayTaskId);
		return success(businessAssayTaskAnalysisSampleProject);
	}

	@Deprecated
	@PostMapping("/saveBatchSampleAnalysis")
	public CommonResult<?> saveBatchSampleAnalysis(@RequestBody BusinessAssayTaskAnalysisSampleProjectRespVO vo) {
		sampleAnalysisService.saveBatchSampleAnalysis(vo);
		return success("成功");
	}
	
	@GetMapping("/batchSampleAndQcAnalysisByTaskId")
	public CommonResult<?> batchSampleAndQcAnalysisByTaskId(Long businessAssayTaskId) {
		BusinessAssayTaskAnalysisSampleAndQcProjectRespVO businessAssayTaskAnalysisSampleAndQcProject = sampleAnalysisService.batchSampleAndQcAnalysisByTaskId(businessAssayTaskId);
		return success(businessAssayTaskAnalysisSampleAndQcProject);
	}
	
	@PostMapping("/saveBatchSmpleAndQcAnalysis")
	public CommonResult<?> saveBatchSmpleAndQcAnalysis(@RequestBody BusinessAssayTaskAnalysisSampleAndQcProjectRespVO  vo) {
		sampleAnalysisService.saveBatchSmpleAndQcAnalysis(vo);
		return success("成功");
	}
	
	//下发配料(自动火试金配料)
	@PostMapping("/issuedIngredients")
	public CommonResult<?> issuedIngredients(Long businessAssayTaskId) {
		sampleAnalysisService.issuedIngredients(businessAssayTaskId);
		return success("成功");
	}
	
	//人工配料
	@PostMapping("/manualIngredients")
	public CommonResult<?> manualIngredients(Long businessAssayTaskId) {
		sampleAnalysisService.manualIngredients(businessAssayTaskId);
		return success("成功");
	}
	
	//提交分析
	@PostMapping("/submitSampleAnalysisByTaskId")
	public CommonResult<?> submitSampleAnalysisByTaskId(Long businessAssayTaskId) {
		sampleAnalysisService.submitSampleAnalysisByTaskId(businessAssayTaskId);
		return success("成功");
	}
	
	@GetMapping("/getSampleAnalysisDataByTaskDataId")
	public CommonResult<?> getSampleAnalysisDataByTaskDataId(Long businessAssayTaskDataId) {
		JSONObject json = sampleAnalysisService.getSampleAnalysisDataByTaskDataId(businessAssayTaskDataId);
		return success(json);
	}
	
	@PostMapping("/rollbackAnalysisSample")
	public CommonResult<?> rollbackAnalysisSample(@RequestBody BusinessAssayTaskBackSampleReqVO req) {
		sampleAnalysisService.rollbackAnalysisSample(req);
		return success("成功");
	}

}
