package com.casic.PgInterface.rs;

import com.casic.PgInterface.intelPlan.domain.PgPileAcu;
import com.casic.PgInterface.intelPlan.dto.PgLineHoleDTO;
import com.casic.PgInterface.intelPlan.manager.PgLineHoleManager;
import com.casic.PgInterface.intelPlan.manager.PgPileAcuManager;
import org.springframework.stereotype.Component;

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("pgLineHole")
public class PgLineHoleRs {

    @Resource
    private PgLineHoleManager pgLineHoleManager;

    @Resource
    private PgPileAcuManager pgPileAcuManager;

    @POST
    @Path("getPgLineAcuHole")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> getPgLineAcuHole(@FormParam("acuCode") String acuCode) throws Exception {
        Map<String, Object> resultMap = new HashMap<>();
        String msg = "";
        String result="";
        List<PgLineHoleDTO> pgLineHoleDTOList=new ArrayList<>();

        try {
            PgPileAcu pgPileAcu=pgPileAcuManager.getPgPileAcuByCode(acuCode);
            if(pgPileAcu==null){
                msg="不存在分区";
            }else{
                pgLineHoleDTOList=pgLineHoleManager.getCurrentHoleByAcu(pgPileAcu.getId());
                if(pgLineHoleDTOList!=null&&pgLineHoleDTOList.size()!=0)
                    msg="获取成功";
                else
                    msg="未找到入廊数据";
            }
        } catch (Exception e) {
            e.printStackTrace();
            msg = "获取失败";
        }
        resultMap.put("msg", msg);
        resultMap.put("result", pgLineHoleDTOList);
        return resultMap;
    }

}