package com.casic.PgInterface.rs; import com.casic.PgInterface.construction.domain.PgConstruction; import com.casic.PgInterface.construction.domain.PgConstructionType; import com.casic.PgInterface.construction.dto.PgConstructionDto; import com.casic.PgInterface.construction.dto.PgConstructionStiatistic; import com.casic.PgInterface.construction.manager.PgConstructionManager; import com.casic.PgInterface.construction.manager.PgConstructionTypeManager; import com.casic.PgInterface.devTable.dto.PgDeviceDto; import com.casic.PgInterface.devTable.manager.PgDeviceManager; 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.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * Created by zxh on 2018/3/27. */ @Component @Path("pgConstruction") public class PgConstructionRs { private static Logger logger = LoggerFactory.getLogger(PgConstructionRs.class); @Resource private PgConstructionTypeManager pgConstructionTypeManager; @Resource private PgConstructionManager pgConstructionManager; @Resource private PgDeviceManager pgDeviceManager; /* *新建工程 */ @POST @Path("addConstruction") @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> addConstruction(@FormParam("cs_name")String cs_name, @FormParam("constructionType")String constructionType, @FormParam("cs_detail")String cs_detail, @FormParam("cs_beginTime")String cs_beginTime, @FormParam("cs_endTime")String cs_endTime, @FormParam("cs_charge")String cs_charge, @FormParam("cs_phone")String cs_phone, @FormParam("cs_type")String cs_type, @FormParam("parName") String parName) throws Exception { Map<String, Object> resultMap = new HashMap<>(); String result = ""; String msg = ""; String code="0"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try { PgConstructionType pgConstructionType = pgConstructionTypeManager.getConstructionTypeByType(constructionType); if (pgConstructionType==null) { result = "false"; msg = "保存失败,不存在项目状态:"+"constructionType"; } else { PgConstruction pgConstruction = new PgConstruction(); pgConstruction.setCs_name(cs_name); pgConstruction.setCs_detail(cs_detail); pgConstruction.setCs_beginTime(sdf.parse(cs_beginTime)); pgConstruction.setCs_endTime(sdf.parse(cs_endTime)); pgConstruction.setCs_charge(cs_charge); pgConstruction.setCs_phone(cs_phone); pgConstruction.setCs_type(cs_type); pgConstruction.setPgConstructionTypeId(pgConstructionType.getId()); pgConstruction.setActive(1); pgConstruction.setParName(parName); pgConstructionManager.save(pgConstruction); code="200"; result = "true"; msg = "保存成功"; } } catch (Exception e) { result = "false"; msg = "保存失败"; e.printStackTrace(); } resultMap.put("code",code); resultMap.put("success", result); resultMap.put("msg", msg); return resultMap; } /* 施工信息编辑 */ @POST @Path("editConstruction") @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> editConstruction(@FormParam("id")String id, @FormParam("cs_name")String cs_name, @FormParam("constructionType")String constructionType, @FormParam("cs_detail")String cs_detail, @FormParam("cs_beginTime")String cs_beginTime, @FormParam("cs_endTime")String cs_endTime, @FormParam("cs_charge")String cs_charge, @FormParam("cs_phone")String cs_phone, @FormParam("cs_type")String cs_type, @FormParam("parName") String parName) throws Exception{ Map<String, Object> resultMap = new HashMap<String, Object>(); String result = ""; String msg = ""; String code="0"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try { if (id.equals("")) { result = "false"; msg = "请输入ID"; }else { PgConstructionType pgConstructionType=pgConstructionTypeManager.getConstructionTypeByType(constructionType); PgConstruction pgConstruction = pgConstructionManager.get(Long.valueOf(id)); pgConstruction.setCs_name(cs_name); pgConstruction.setCs_detail(cs_detail); pgConstruction.setCs_beginTime(sdf.parse(cs_beginTime)); pgConstruction.setCs_endTime(sdf.parse(cs_endTime)); pgConstruction.setCs_charge(cs_charge); pgConstruction.setCs_phone(cs_phone); pgConstruction.setCs_type(cs_type); pgConstruction.setPgConstructionTypeId(pgConstructionType.getId()); pgConstruction.setActive(1); pgConstruction.setParName(parName); pgConstructionManager.save(pgConstruction); code="200"; result = "true"; msg = "编辑成功"; } }catch (Exception e){ result = "false"; msg = "编辑失败"; e.printStackTrace(); } resultMap.put("code",code); resultMap.put("result", result); resultMap.put("msg", msg); return resultMap; } /* 删除信息 */ @POST @Path("delConstruction") @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> delConstruction(@FormParam("id")String id) throws Exception{ Map<String, Object> resultMap = new HashMap<String, Object>(); String result = ""; String msg = ""; String code="0"; try { PgConstruction pgConstruction = pgConstructionManager.get(Long.valueOf(id)); if (pgConstruction == null) { result = "false"; msg = "不存在该施工信息"; }else { pgConstruction.setActive(0); pgConstructionManager.save(pgConstruction); code="200"; result = "true"; msg = "成功删除信息"; } }catch (Exception e){ e.printStackTrace(); result = "false"; msg = "删除失败"; } resultMap.put("code",code); resultMap.put("result", result); resultMap.put("msg", msg); return resultMap; } /* 查询 */ @POST @Path("searchConstruction") @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> searchConstruction(@FormParam("cs_name")String cs_name, @FormParam("cs_type")String cs_type, @FormParam("startTime")String startTime, @FormParam("endTime")String endTime, @FormParam("page") int page, @FormParam("rows") int rows)throws Exception{ Map<String,Object> resultMap=new HashMap<>(); String msg=""; String code="0"; List<PgConstructionDto> pgConstructionDtoList=new ArrayList<>(); try{ pgConstructionDtoList=pgConstructionManager.getPgContructionDto(cs_name,cs_type,startTime,endTime,page,rows); code="200"; msg="信息获取成功"; } catch(Exception e) { e.printStackTrace(); msg="查询失败"; } resultMap.put("code",code); resultMap.put("msg",msg); resultMap.put("result",pgConstructionDtoList); return resultMap; } /** * 根据时间统计施工次数 */ @POST @Path("getConstructionByTimeAndStatus") @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> getConstructionByTimeAndStatus(@FormParam("startTime") String startTime, @FormParam("endTime") String endTime, @FormParam("statisticType") String statisticType) throws Exception { Map<String, Object> resultMap = new HashMap<>(); String msg = ""; String code="0"; List<PgConstructionStiatistic> pgConstructionStiatisticList=new ArrayList<>(); try { pgConstructionStiatisticList = pgConstructionManager.getConstructionByTimeAndStatus(startTime, endTime, statisticType); if(pgConstructionStiatisticList==null) msg="施工统计信息获取失败"; else { code="200"; msg = "施工统计信息获取成功"; } } catch (Exception e) { e.printStackTrace(); msg = "施工统计信息获取失败"; } resultMap.put("code",code); resultMap.put("msg", msg); resultMap.put("result", pgConstructionStiatisticList); return resultMap; } /** * 工程类别统计 */ @POST @Path("getConstructionByType") @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> getConstructionByType(@FormParam("statisticType") String statisticType){ Map<String,Object> resultMap=new HashMap<>(); String msg=""; String code="0"; List<PgConstructionStiatistic> pgConstructionStiatisticList=new ArrayList<>(); try{ pgConstructionStiatisticList=statisticType.equals("0")?pgConstructionManager.getStatisticByType(): pgConstructionManager.getStatisticByPar(); if(pgConstructionStiatisticList==null||pgConstructionStiatisticList.size()==0) { msg="不存在统计信息"; resultMap.put("result",null); } else { code="200"; msg = "统计信息获取成功"; resultMap.put("result", pgConstructionStiatisticList); } } catch(Exception e) { e.printStackTrace(); msg="统计失败"; resultMap.put("result",null); } resultMap.put("code",code); resultMap.put("msg",msg); return resultMap; } /** * 当天施工 */ @POST @Path("getConstructionToday") @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> getConstructionToday() throws Exception{ Map<String,Object> resultMap=new HashMap<String, Object>(); String msg=""; String code="0"; List<PgConstructionDto> pgConstructionDtoList=new ArrayList<PgConstructionDto>(); try { pgConstructionDtoList = pgConstructionManager.getConstructionToday(); code="200"; msg = "当天施工信息获取成功"; } catch(Exception e) { e.printStackTrace(); msg="获取失败"; } resultMap.put("code",code); resultMap.put("msg",msg); resultMap.put("result",pgConstructionDtoList); return resultMap; } /** * 获取关联设备《摄像机》 */ @POST @Path("getConstructionDev") @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> getConstructionDev(@FormParam("id") String id) throws Exception{ Map<String,Object> resultMap=new HashMap<>(); String msg=""; String code="0"; List<PgDeviceDto> pgDeviceDtoList =new ArrayList<>(); try{ PgConstruction pgConstruction=pgConstructionManager.get(Long.valueOf(id)); pgDeviceDtoList=pgDeviceManager.getPgCameraListByPartition(pgConstruction.getParName()); if(pgDeviceDtoList==null) msg="信息获取失败"; else { code="200"; msg = "信息获取成功"; } } catch(Exception e) { e.printStackTrace(); msg="信息获取是被"; } resultMap.put("code",code); resultMap.put("msg",msg); resultMap.put("result",pgDeviceDtoList); return resultMap; } /* * 获取施工信息 */ @POST @Path("getConstruction") @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> getConstruction() throws Exception { Map<String, Object> resultMap = new HashMap<>(); String result = ""; String msg = ""; String code="0"; List<PgConstructionDto> pgConstructionDtoList=new ArrayList<>(); try{ pgConstructionDtoList=pgConstructionManager.getPgConstructionList(); if(pgConstructionDtoList==null||pgConstructionDtoList.size()==0) msg="不存在施工记录"; else { code = "200"; msg = "施工信息获取成功"; } } catch(Exception e) { e.printStackTrace(); msg="施工信息获取失败"; result="false"; } resultMap.put("code",code); resultMap.put("msg",msg); resultMap.put("result",pgConstructionDtoList); return resultMap; } }