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.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.framework.security.core.LoginUser;
import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils;
import com.zt.plat.module.qms.business.bus.controller.vo.*;
import com.zt.plat.module.qms.business.bus.service.SampleResultReportingService;

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 org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;


/**
 * 结果上报
 */
@Tag(name = "管理后台 - 结果上报")
@RestController
@RequestMapping("/qms/bus/sample/result-reporting")
@Validated
@DeptDataPermissionIgnore(enable = "true")
public class SampleResultReportingController implements BusinessControllerMarker {
	
	@Resource
	private SampleResultReportingService sampleResultReportingService;
	
	//获取未上报的方法
	@GetMapping("/getUnReportMethodGroupList")
	public CommonResult<?> getUnReportMethodGroupList(BusinessSubParentSampleAssessmentGroupReqVO reqVO) {
    	if (reqVO.getAssayDepartmentId() == null) {
    		LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
            reqVO.setAssayDepartmentId(loginUser.getVisitDeptId());
		}
		List<BusinessSubParentSampleAssessmentGroupRespVO> list = sampleResultReportingService.getUnReportMethodGroupList(reqVO);
		return success(list);
	}
	
	//获取方法对应的样品
	@GetMapping("/getSampleResultReportingList")
	public CommonResult<?> getSampleResultReportingList(BusinessSubParentSampleAssessmentGroupReqVO reqVO) {
		JSONObject result = sampleResultReportingService.getSampleResultReportingList(reqVO);
		return success(result);
	}
	
	//获取复检方法
	@GetMapping("/getRecheckAssayMethodList")
	public CommonResult<?> getRecheckMethodList(Long baseSampleId, Long businessSubParentSampleId, Long configAssayMethodId) {
		List<RecheckSubSampleParentMethodRespVO> list = sampleResultReportingService.getRecheckAssayMethodList(baseSampleId, businessSubParentSampleId, configAssayMethodId);
		return success(list);
	}
	
	//创建复检样
	@PostMapping("/createRecheckSample")
	public CommonResult<?> createRecheckSample(@RequestBody RecheckSubSampleParentCreateReqVO reqVO) {
		sampleResultReportingService.createRecheckSample(reqVO);
		
		return success("成功");
	}
	
	//上报
	@PostMapping("/batchResultDataReporting")
	public CommonResult<?> batchResultDataReporting(@RequestBody BatchResultDataReportingReqVO reqVO) {
		sampleResultReportingService.batchResultDataReporting(reqVO);
		return success("成功");
	}
	
	//结果单个结果查询
	@GetMapping("/getSingleSampleResultReportingList")
	public CommonResult<?> getSingleSampleResultReportingList(Long businessSubParentSampleId, Long configAssayMethodId) {
		JSONObject result = sampleResultReportingService.getSingleSampleResultReportingList(businessSubParentSampleId, configAssayMethodId);
	    return success(result);
	}
	
	//修改结果
	@PostMapping("/modifySampleResultReporting")
	public CommonResult<?> modifySampleResultReporting(@RequestBody ModifySampleResultReportingReqVO reqVO) {
		sampleResultReportingService.modifySampleResultReporting(reqVO);
		return success("成功");
	}

}
