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.PgPartitionDto; 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("pgPartition") public class PgPartitionRs { private static Logger logger = LoggerFactory.getLogger(PgPartitionRs.class); private PipeGalleryManager pipeGalleryManager; private PgPartitionManager pgPartitionManager; @Resource public void setPgPartitionManager(PgPartitionManager pgPartitionManager) { this.pgPartitionManager = pgPartitionManager; } @Resource public void setPipeGalleryManager(PipeGalleryManager pipeGalleryManager) { this.pipeGalleryManager = pipeGalleryManager; } /** * 新增分区 */ @POST @Path("addPartition") @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> addAlarm(@FormParam("parCode") String parCode, @FormParam("parName") String parName, @FormParam("pgName") String pgName)throws Exception { Map<String, Object> resultMap = new HashMap<String, Object>(); String result = ""; String msg = ""; try { PgPartition pgPartition = new PgPartition(); pgPartition.setParCode(parCode); pgPartition.setParName(parName); pgPartition.setPipeGalleryId(pipeGalleryManager.getPipeGalleryByPgName(pgName)); pgPartition.setActive(1); logger.info("成功保存"); pgPartitionManager.save(pgPartition); result = "true"; msg = "保存成功"; } catch (Exception e) { result = "false"; msg = "保存失败"; e.printStackTrace(); } resultMap.put("success", result); resultMap.put("msg", msg); return resultMap; } /** *获取管廊仓下的分区列表 */ @POST @Path("getPartition") @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> getPartitionList(@FormParam("pgName") String pgName)throws Exception { Map<String, Object> resultMap = new HashMap<String, Object>(); String msg=""; List<PgPartitionDto> pgPartitionDtoList=new ArrayList<PgPartitionDto>(); try { pgPartitionDtoList=pgPartitionManager.getPartitionByPG(pgName); if(pgPartitionDtoList.size()==0) msg="没有分区信息"; else msg="分区信息获取成功"; }catch(Exception e){ e.printStackTrace(); msg="分区信息获取失败"; } resultMap.put("msg",msg); resultMap.put("result",pgPartitionDtoList); return resultMap; } @POST @Path("editPartition") @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> editPartition(@FormParam("id") String id, @FormParam("parCode") String parCode, @FormParam("parName") String parName, @FormParam("pgName") String pgName) throws Exception { Map<String, Object> resultMap = new HashMap<String, Object>(); String result = ""; String msg = ""; PgPartition partition=new PgPartition(); try { PipeGallery pipeGallery = pipeGalleryManager.getPipeGalleryByPgName(pgName); if (pipeGallery == null) { result = "false"; msg = "不存在该管廊信息"; } else { PgPartition pgPartition=pgPartitionManager.get(Long.valueOf(id)); pgPartition.setParCode(parCode); pgPartition.setParName(parName); pgPartition.setPipeGalleryId(pipeGallery); pgPartition.setActive(1); pgPartitionManager.save(pgPartition); result = "true"; msg = "编辑成功"; } } catch (Exception e) { result = "false"; msg = "编辑失败"; e.printStackTrace(); } resultMap.put("result",result); resultMap.put("msg",msg); return resultMap; } /** * 删除分区信息 */ @POST @Path("deletePartition") @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> deletePartition(@FormParam("id") String id)throws Exception { Map<String, Object> resultMap = new HashMap<String, Object>(); String msg=""; String result="false"; try { PgPartition pgPartition=pgPartitionManager.get(Long.valueOf(id)); if(pgPartition==null) { msg = "不存在该分区信息"; result="false"; } else { pgPartition.setActive(0); pgPartitionManager.save(pgPartition); msg="分区删除成功"; result="true"; } }catch(Exception e){ e.printStackTrace(); msg="分区删除失败"; result="false"; } resultMap.put("msg",msg); resultMap.put("result",result); return resultMap; } }