package com.casic.PgInterface.rs;

import com.casic.PgInterface.patroler.domain.PgMaintainType;
import com.casic.PgInterface.patroler.dto.PgMaintainTypeDto;
import com.casic.PgInterface.patroler.manager.PgMaintainTypeManager;
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;

/**
 * Created by yxw on 2018/8/21.
 */
@Component
@Path("pgMaintainType")
public class PgMaintainTypeRs {

    @Resource
    private PgMaintainTypeManager pgMaintainTypeManager;

    /**
     * 获取维护类型
     */
    @POST
    @Path("getMaintainType")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String,Object> getMaintainType(){
        Map<String,Object> resultMap=new HashMap<>();

        String msg = "";
        List<PgMaintainType> pgMaintainTypeList=new ArrayList<>();
        try{
            pgMaintainTypeList=pgMaintainTypeManager.getMaintainType();
            if(pgMaintainTypeList!=null&&pgMaintainTypeList.size()!=0)
                msg="不存在运维类别";
            else
                msg="运维类别获取成功";
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            msg="运维类别获取失败";
        }
        resultMap.put("msg",msg);
        resultMap.put("result",pgMaintainTypeList);

        return resultMap;
    }

    /**
     * 获取维护模板
     */
    @POST
    @Path("getMaintainTypeModel")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String,Object> getMaintainTypeModel(@FormParam("type") String type){
        Map<String,Object> resultMap=new HashMap<>();

        String msg = "";
        List<PgMaintainTypeDto> pgMaintainTypeDtoList=new ArrayList<PgMaintainTypeDto>();
        try{
            pgMaintainTypeDtoList=pgMaintainTypeManager.getMaintainTypeModel(type);

            msg="维护类型获取成功";
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            msg="维护类型获取失败";
        }

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

        return resultMap;
    }

}
