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

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

import java.util.ArrayList;
import java.util.List;

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.JSON;
import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.framework.datapermission.core.annotation.DeptDataPermissionIgnore;
import com.zt.plat.module.qms.core.sampleflow.SampleFlowDefinition;
import com.zt.plat.module.qms.core.sampleflow.SampleFlowNode;


@RestController
@RequestMapping("/qms/bus/test")
@DeptDataPermissionIgnore(enable = "true")
public class TestController {


    @GetMapping("/testSampleFlow")
    public CommonResult<?> testSampleFlow() {
    	
    	SampleFlowDefinition sampleFlowDefinition = new SampleFlowDefinition();
    	sampleFlowDefinition.setFlowKey("flw_sub_sample_process");
    	sampleFlowDefinition.setFlowName("子样样品流转流程");
    	List<SampleFlowNode> flowNodeList = new ArrayList<>();
    	
    	SampleFlowNode zxr = new SampleFlowNode();
    	zxr.setNodeName("中心收样");
    	zxr.setNodeKey("flw_center_receive");
    	zxr.setSort(3100);

    	SampleFlowNode zxs = new SampleFlowNode();
    	zxs.setNodeName("中心送样");
    	zxs.setNodeKey("flw_center_send");
    	zxs.setSort(3200);

    	SampleFlowNode bzr = new SampleFlowNode();
    	bzr.setNodeName("班组收样");
    	bzr.setNodeKey("flw_team_receive");
    	bzr.setSort(3300);

//    	SampleFlowNode ypbm = new SampleFlowNode();
//    	ypbm.setNodeName("样品编密");
//    	ypbm.setNodeKey("flw_sample_encrypt");
//    	ypbm.setSort(3400);

//    	SampleFlowNode fxr = new SampleFlowNode();
//    	fxr.setNodeName("分析收样");
//    	fxr.setNodeKey("flw_analysis_receive");
//    	fxr.setSort(3500);
//
    	
//    	SampleFlowNode fx = new SampleFlowNode();
//    	fx.setNodeName("样品分析");
//    	fx.setNodeKey("flw_analysis");
//    	fx.setSort(3550);
    	
//
//    	SampleFlowNode fxs = new SampleFlowNode();
//    	fxs.setNodeName("分析送样");
//    	fxs.setNodeKey("flw_analysis_send");
//    	fxs.setSort(3600);

    	SampleFlowNode bzs = new SampleFlowNode();
    	bzs.setNodeName("班组送样");
    	bzs.setNodeKey("flw_team_send");
    	bzs.setSort(3700);

    	SampleFlowNode ypgk = new SampleFlowNode();
    	ypgk.setNodeName("样品归库");
    	ypgk.setNodeKey("flw_sample_storage");
    	ypgk.setSort(3800);
    	ypgk.setNextFlowNodeList(null);
    	flowNodeList.add(ypgk);
    	

    	zxr.setNextFlowNodeList(new ArrayList<SampleFlowNode>() {
			private static final long serialVersionUID = 6146393613606839512L;

			{
    			add(BeanUtils.toBean(zxs,SampleFlowNode.class).setIsDefault(true));
    		}
    	});
    	flowNodeList.add(zxr);
    	

    	zxs.setNextFlowNodeList(new ArrayList<>() {
			private static final long serialVersionUID = 5357543125760924047L;

		{
    		add(BeanUtils.toBean(bzr,SampleFlowNode.class).setIsDefault(true));
    	}});
    	flowNodeList.add(zxs);

    	bzr.setNextFlowNodeList(new ArrayList<>() {
			private static final long serialVersionUID = 6376704859477839016L;

		{
    		add(BeanUtils.toBean(bzs,SampleFlowNode.class).setIsDefault(true));//
//    		add(BeanUtils.toBean(ypbm,SampleFlowNode.class).setCondition("subSampleEncrypt"));//样品需要编密并且没编密过
//    		add(BeanUtils.toBean(bzs,SampleFlowNode.class).setCondition("subSampleNotEncrypt"));//样品无需编密或样品已编密过
    	}});
    	flowNodeList.add(bzr);
    	

//    	ypbm.setNextFlowNodeList(new ArrayList<>() {
//			private static final long serialVersionUID = 1014984817516902869L;
//
//		{
//    		add(BeanUtils.toBean(bzs,SampleFlowNode.class).setIsDefault(true));
//    	}});
//    	flowNodeList.add(ypbm);
    	

//    	fxr.setNextFlowNodeList(new ArrayList<>() {{
//    		add(BeanUtils.toBean(fxs,SampleFlowNode.class).setIsDefault(true));
//    	}});
//    	flowNodeList.add(fxr);
//    	
//
//    	fxs.setNextFlowNodeList(new ArrayList<>() {{
//    		add(BeanUtils.toBean(bzs,SampleFlowNode.class).setIsDefault(true).setCondition("当前部门任务已全部分析完"));
//    	}});
//    	flowNodeList.add(fxs);
    	
//    	fx.setNextFlowNodeList(new ArrayList<>() {
//			private static final long serialVersionUID = -610440034210287957L;
//
//		{
//    		add(BeanUtils.toBean(bzs,SampleFlowNode.class).setIsDefault(true).setCondition("当前部门任务已全部分析完"));
//    	}});
//    	flowNodeList.add(fx);

    	bzs.setNextFlowNodeList(new ArrayList<>() {
			private static final long serialVersionUID = -5057434004685743838L;

		{
//    		add(BeanUtils.toBean(fx,SampleFlowNode.class).setCondition("样品当前分析班组结果超差，需要发起复检"));
    		add(BeanUtils.toBean(bzr,SampleFlowNode.class).setCondition("subSampleSelfReportedOthersPending"));//当前部门数据已全部判断上报
    		add(BeanUtils.toBean(ypgk,SampleFlowNode.class).setCondition("subSampleAlldeptAnalyzed"));//当前样品所有分析任务已全部上报完
    	}});
    	flowNodeList.add(bzs);
    	
    	sampleFlowDefinition.setFlowNodeList(flowNodeList);
    	
    	String jsonSampleFlowDefinition = JSON.toJSONString(sampleFlowDefinition);
    	
    	System.out.println(jsonSampleFlowDefinition);
    	
    	return success(jsonSampleFlowDefinition);
	}

}
