package com.casic.PgInterface.rs;

import com.casic.PgInterface.intelPlan.dto.PgPlanParams;
import com.casic.PgInterface.intelPlan.dto.PgPlanResultRe;
import com.casic.PgInterface.intelPlan.dto.PgPlanTask;
import com.casic.PgInterface.intelPlan.manager.PgPileAcuManager;
import com.casic.PgInterface.test.PlanData;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.annotation.Resource;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
@Path("pgInNewPlan")
public class PgInNewPlanRs {

    @Resource
    private PgPileAcuManager pgPileAcuManager;

    @POST
    @Path("getPlanResult")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String,Object> getPlanResult(@FormParam("planParamStr") String planParamStr){
        Map<String,Object> resultMap=new HashMap<>();
        String msg="";

        //List<PgPlanTask> pgPlanTaskList=pgPlanParams.getPgPlanTaskList();
        List<PgPlanTask> pgPlanTaskList=new PgPlanParams().getPgPlanParamsByString(planParamStr);
        List<PgPlanResultRe> pgPlanResultReList=new ArrayList<>();

        try{
                pgPlanResultReList=pgPileAcuManager.getPgPlanResultList(pgPlanTaskList);
                if(pgPlanResultReList==null)
                    msg="管线智能规划出错";
                else
                    msg="管线智能规划完成";
        }
        catch(Exception ex){
            msg="智能规划出错";
            ex.printStackTrace();
        }

        resultMap.put("msg",msg);
        resultMap.put("result",pgPlanResultReList);

        return resultMap;
    }

    /*
    规划测试
     */
    @POST
    @Path("getPlanResultTest")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String,Object> getPlanResultTest(){
        Map<String,Object> resultMap=new HashMap<>();
        PlanData planData=new PlanData();
        List<PgPlanResultRe> pgPlanResultReList=new ArrayList<>();
        try{
            PgPlanParams pgPlanParams=planData.getPlanData();

            List<PgPlanTask> pgPlanTaskList = pgPlanParams.getPgPlanTaskList();
            pgPlanResultReList=pgPileAcuManager.getPgPlanResultList(pgPlanTaskList);
        }
        catch(Exception ex){
            ex.printStackTrace();
        }

        resultMap.put("msg","管线智能规划完成");
        resultMap.put("result",pgPlanResultReList);
        return resultMap;
    }

}