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

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 com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
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.liteflow.param.SampleFlowParam;
import com.zt.plat.module.qms.business.bus.liteflow.slot.SampleFlowContext;
import com.zt.plat.module.qms.business.bus.service.SampleFlowService;
import com.zt.plat.module.qms.enums.QmsCommonConstant;

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/flow")
@Validated
@DeptDataPermissionIgnore(enable = "true")
public class SampleFlowController implements BusinessControllerMarker {
	
	@Resource
	private SampleFlowService sampleFlowService;

    @Resource
    private FlowExecutor flowExecutor;
    
    @PostMapping("/sampleFlow")
    public CommonResult<?> sampleFlow(@Validated @RequestBody SampleFlowParam sampleFlowParam) {
    	LiteflowResponse response = sampleFlowService.sampleFlow(sampleFlowParam);
    	return success(response.getContextBean(SampleFlowContext.class));
    }

    /**
     * 中心收样并送样
     * @param sampleFlowParam
     * @return
     */
    @PostMapping("/centerReceiveAndSend")
    public CommonResult<?> centerReceiveAndSend(@Validated @RequestBody SampleFlowParam sampleFlowParam) {
    	//中心收样
    	sampleFlowParam.setCurrentSampleFlowKey(QmsCommonConstant.FLOW_NODE_CENTER_RECEIVE);
    	LiteflowResponse response = sampleFlowService.sampleFlow(sampleFlowParam);
    	//中心送样
    	sampleFlowParam.setCurrentSampleFlowKey(QmsCommonConstant.FLOW_NODE_CENTER_SEND);
    	sampleFlowParam.setSendSampleOper(null);
    	response = sampleFlowService.sampleFlow(sampleFlowParam);
    	return success(response.getContextBean(SampleFlowContext.class));
    }
}
