Newer
Older
PgInterface / src / main / java / com / casic / PgInterface / rs / PipeGalleryRs.java
xiaowei on 21 Dec 2017 6 KB 按资产表修改设备表
package com.casic.PgInterface.rs;

import com.casic.PgInterface.devTable.domain.PgPartition;
import com.casic.PgInterface.devTable.domain.PipeGallery;
import com.casic.PgInterface.devTable.dto.PipeGalleryDto;
import com.casic.PgInterface.devTable.manager.PgPartitionManager;
import com.casic.PgInterface.devTable.manager.PipeGalleryManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 2017/11/6.
 */
@Component
@Path("pipeGallery")
public class PipeGalleryRs {

    private static Logger logger = LoggerFactory.getLogger(PgAlarmRs.class);

    private PipeGalleryManager pipeGalleryManager;

    private PgPartitionManager pgPartitionManager;

    @Resource
    public void setPipeGalleryManager(PipeGalleryManager pipeGalleryManager) {
        this.pipeGalleryManager = pipeGalleryManager;
    }

    @Resource
    public void setPgPartitionManager(PgPartitionManager pgPartitionManager) {
        this.pgPartitionManager = pgPartitionManager;
    }

    /**
     * 新增管廊
     */
    @POST
    @Path("addPipeGallery")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> addPipeGallery(@FormParam("pgName") String pgName,
                                              @FormParam("parName") String parName) throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        String result = "";
        String msg = "";
        PipeGallery pipeGallery = new PipeGallery();
        try {
            PgPartition pgPartition=pgPartitionManager.getPartitionByParName(parName);
            if(pgPartition==null) {
                result = "false";
                msg = "不存在分区信息";
            }
            else {
                if (pipeGalleryManager.getPipeGalleryByPgName(pgName,pgPartition) != null) {
                    result = "false";
                    msg = "已存在相同管廊";
                } else {
                    pipeGallery.setPgName(pgName);
                    pipeGallery.setPgPartitionId(pgPartition);
                    pipeGallery.setActive(1);
                    logger.info("成功保存");
                    pipeGalleryManager.save(pipeGallery);
                    result = "true";
                    msg = "保存成功";
                }
            }
        } catch (Exception e) {
            result = "false";
            msg = "保存失败";
            e.printStackTrace();
        }

        resultMap.put("result", result);
        resultMap.put("msg", msg);
        return resultMap;
    }

    /**
     *获取分区下的管廊仓列表
     */
    @POST
    @Path("getPiprGallerys")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> getPipeGalleryList(@FormParam("parName") String parName)throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        String msg="";
        List<PipeGalleryDto> pipeGalleryDtoList=new ArrayList<PipeGalleryDto>();
        try {
            pipeGalleryDtoList=pipeGalleryManager.getPipeGalleryByParName(parName);
            if(pipeGalleryDtoList.size()==0)
                msg="没有分区信息";
            else
                msg="分区信息获取成功";
        }catch(Exception e){
            e.printStackTrace();
            msg="分区信息获取失败";
        }
        resultMap.put("msg",msg);
        resultMap.put("result",pipeGalleryDtoList);
        return resultMap;
    }

    /*
    *编辑管廊信息
     */
    @POST
    @Path("editPipeGallery")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> editPipeGallery(@FormParam("id") String id,
                                               @FormParam("pgName") String pgName,
                                               @FormParam("parName") String parName) throws Exception {

        Map<String, Object> resultMap = new HashMap<String, Object>();
        String result = "";
        String msg = "";

        PipeGallery pipeGallery=new PipeGallery();
        try {
            PgPartition pgPartition=pgPartitionManager.getPartitionByParName(parName);
            if (pgPartition == null) {
                result = "false";
                msg = "不存在该分区信息";
            } else {
                if (pipeGalleryManager.getPipeGalleryByPgName(pgName, pgPartition) != null) {
                    result = "false";
                    msg = "已存在相同管廊";
                } else {
                    pipeGallery = pipeGalleryManager.get(Long.valueOf(id));

                    pipeGallery.setPgName(pgName);
                    pipeGallery.setPgPartitionId(pgPartition);
                    pipeGallery.setActive(1);

                    pipeGalleryManager.save(pipeGallery);
                    result = "true";
                    msg = "编辑成功";
                }
            }
        } catch (Exception e) {
            result = "false";
            msg = "编辑失败";
            e.printStackTrace();
        }
        resultMap.put("result",result);
        resultMap.put("msg",msg);
        return resultMap;
    }

    /**
     * 删除管廊信息
     */
    @POST
    @Path("deletePipeGallery")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> deletePipeGallery(@FormParam("id") String id)throws Exception {

        Map<String, Object> resultMap = new HashMap<String, Object>();
        String msg="";
        String result="false";

        try {
            PipeGallery pipeGallery=pipeGalleryManager.get(Long.valueOf(id));
            if(pipeGallery==null) {
                msg = "不存在该管廊信息";
                result="false";
            }
            else
            {
                pipeGallery.setActive(0);
                pipeGalleryManager.save(pipeGallery);
                msg="管廊删除成功";
                result="true";
            }
        }catch(Exception e){
            e.printStackTrace();
            msg="管廊删除失败";
            result="false";
        }
        resultMap.put("msg",msg);
        resultMap.put("result",result);
        return resultMap;
    }

}