package com.gyee.backconfig.service; import com.gyee.backconfig.model.auto.*; import com.gyee.backconfig.service.auto.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; /** * 生成测点服务类 */ @Service public class PointGenerateService { private static Logger logger = LoggerFactory.getLogger(PointGenerateService.class); @Resource private ICompanysService companysService;//公司 @Autowired private IRegionService regionService;//区域 @Resource private IProjectService projectService;//期次 @Resource private ILineService lineService;//线路 @Resource private IWindpowerstationService windpowerstationService;//场站 @Autowired private IWindturbineService windturbineService;//风机 @Autowired private IWindpowerstationpointnewService windpowerstationpointnewService; @Autowired private IWindturbinetestingpointnewService windturbinetestingpointnewService; @Autowired private IStandardpointService standardpointService; public int addGeneratePoint(String[] points) { int num = 0; List pointList = standardpointService.list(points); List companysList = companysService.getCompanysByidAndRid(""); for (Standardpoint p : pointList) { if ("czjs".equals(p.getType())) { List staionList = fjd(p, companysList); for (Windpowerstationpointnew i : staionList) { boolean b = windpowerstationpointnewService.addOrUpdate(i); if (!b){ logger.error( i.getCode()+"测点插入失败"); num++; } } } else { //fjjs //fjjcd for (Companys c : companysList) { List regionList = regionService.getReginBycode(c.getCapacityunit()); for (Region r : regionList) { List windpowerstationList = windpowerstationService.getList(r.getCompanyid()); List testingList = czd(p, windpowerstationList); for (Windturbinetestingpointnew i : testingList) { boolean b = windturbinetestingpointnewService.addOrUpdate(i); if (!b){ logger.error( i.getCode()+"测点插入失败"); num++; } } } } } } return num; } private List fjd(Standardpoint p, List companysList) { List stationList = new ArrayList<>(); Windpowerstationpointnew stationpoint = null; List gflist = new ArrayList<>(); gflist.add("G"); gflist.add("F"); for (Companys c : companysList) { StringBuilder gssb = null; List list1 = windpowerstationpointnewService.getStationpointByUniformcode(c.getId(), p.getUniformcode()); if (null == list1 || list1.size() <= 0) { //"JSFW.QY_JN_XXXX_XX_XX_XX_XXX_CI0144" "区域限电停机台数(明细)" gssb = new StringBuilder(); gssb.append("JSFW.").append(c.getId()).append("_JN_"); stationpoint = new Windpowerstationpointnew(); stationpoint.setCode(gssb.toString() + "XXXX_XX_XX_XX_XXX_" + p.getUniformcode()); stationpoint.setName(c.getName() + p.getName()); stationpoint.setUniformcode(p.getUniformcode()); stationpoint.setWindpowerstationid(c.getId()); stationpoint.setRealtimeid("JSFW"); stationList.add(stationpoint); } for (String gf: gflist){ List list1df = windpowerstationpointnewService.getStationpointByUniformcode(c.getId()+"_"+gf, p.getUniformcode()); if (null == list1df || list1df.size() <= 0) { //"JSFW.QY_JN_QYG_XX_XX_XX_XXX_CI0144" "区域光伏限电停机台数(明细)" //"JSFW.QY_JN_QYF_XX_XX_XX_XXX_CI0144" "区域风场限电停机台数(明细)" StringBuilder gsgfsb = new StringBuilder(gssb); gsgfsb.append(c.getId()).append(gf) .append("_XX_XX_XX_XXX_") .append(p.getUniformcode()); stationpoint = new Windpowerstationpointnew(); stationpoint.setCode(gsgfsb.toString()); stationpoint.setName(c.getName() + p.getName()); stationpoint.setUniformcode(p.getUniformcode()); stationpoint.setWindpowerstationid(c.getId()+"_"+gf); stationpoint.setRealtimeid("JSFW"); stationList.add(stationpoint); } } List regionList = regionService.getReginBycode(c.getCapacityunit()); for (Region r : regionList) { StringBuilder qusb = new StringBuilder(); List list2 = windpowerstationpointnewService.getStationpointByUniformcode( r.getId(), p.getUniformcode()); if (null == list2 || list2.size() <= 0) { //"JSFW.SX_JN_XXXX_XX_XX_XX_XXX_CI0144" "山西限电停机台数(明细)" qusb.append("JSFW.").append(r.getId()).append("_JN_"); stationpoint = new Windpowerstationpointnew(); stationpoint.setCode(gssb.toString() + "XXXX_XX_XX_XX_XXX_" + p.getUniformcode()); stationpoint.setName(c.getName() + p.getName()); stationpoint.setUniformcode(p.getUniformcode()); stationpoint.setWindpowerstationid(r.getId()); stationpoint.setRealtimeid("JSFW"); stationList.add(stationpoint); } for (String gf: gflist) { List list2df = windpowerstationpointnewService.getStationpointByUniformcode(r.getId() + "_" + gf, p.getUniformcode()); if (null == list2df || list2df.size() <= 0) { //"JSFW.SX_JN_SXG_XX_XX_XX_XXX_CI0144" "山西光伏限电停机台数(明细)" //"JSFW.SX_JN_SXF_XX_XX_XX_XXX_CI0144" "山西风场限电停机台数(明细)" StringBuilder qugfsb = new StringBuilder(qusb); qugfsb.append(r.getId()).append(gf) .append("_XX_XX_XX_XXX_") .append(p.getUniformcode()); stationpoint = new Windpowerstationpointnew(); stationpoint.setCode(qugfsb.toString()); stationpoint.setName(c.getName() + p.getName()); stationpoint.setUniformcode(p.getUniformcode()); stationpoint.setWindpowerstationid(r.getId() + "_" + gf); stationpoint.setRealtimeid("JSFW"); stationList.add(stationpoint); } } List windpowerstationList = windpowerstationService.getList(r.getCompanyid()); for (Windpowerstation station : windpowerstationList) { List list3 = windpowerstationpointnewService.getStationpointByUniformcode(station.getId(), p.getUniformcode()); if (null != list3 && list3.size() > 0) { continue; } stationpoint = new Windpowerstationpointnew(); //BHBFCJSFW.SX_JN_BHBF_JS_XX_XX_XXX_CI0079 //SYGCJSFW.SX_JN_SYG_JS_XX_XX_XXX_CI0001 StringBuilder stationsb = new StringBuilder(); String substaion = station.getId().substring(0, station.getId().indexOf("_")); stationsb.append(substaion).append(station.getId().endsWith("_FDC") ? "FCJSFW." : "GCJSFW."); stationsb.append("SX_JN_").append(substaion); stationsb.append(station.getId().endsWith("_FDC") ? "F" : "G").append("_JS_"); stationpoint.setCode(stationsb.toString() + "XX_XX_XXX_" + p.getUniformcode()); stationpoint.setName(station.getName() + p.getName()); stationpoint.setUniformcode(p.getUniformcode()); stationpoint.setWindpowerstationid(station.getId()); stationpoint.setRealtimeid(substaion + (station.getId().endsWith("_FDC") ? "FCJSFW" : "GCJSFW")); stationList.add(stationpoint); List projectList = projectService.getList(station.getId()); for (Project project : projectList) { List list4 = windpowerstationpointnewService.getStationpointByUniformcode(project.getId(), p.getUniformcode()); if (null != list4 && list4.size() > 0) { continue; } stationpoint = new Windpowerstationpointnew(); //BHBFCJSFW.SX_JN_BHBF_JS_P1_XX_XXX_CI0079 //SYGCJSFW.SX_JN_SYG_JS_P1_XX_XXX_CI0001 StringBuilder projectsb = new StringBuilder(stationsb); Integer pnum = Integer.valueOf(project.getId().substring(substaion.length(), project.getId().indexOf("_"))) * 1; projectsb.append("P") .append(pnum); stationpoint.setCode(projectsb.toString()+"_XX_XXX_"+p.getUniformcode()); stationpoint.setName(project.getName() + p.getName()); stationpoint.setUniformcode(p.getUniformcode()); stationpoint.setWindpowerstationid(project.getId()); stationpoint.setRealtimeid(substaion + (station.getId().endsWith("_FDC") ? "FCJSFW" : "GCJSFW")); stationList.add(stationpoint); List lineList = lineService.getList(project.getId()); for (Line l : lineList) { List list5 = windpowerstationpointnewService.getStationpointByUniformcode(l.getId(), p.getUniformcode()); if (null != list5 && list5.size() > 0) { continue; } stationpoint = new Windpowerstationpointnew(); //BHBFCJSFW.SX_JN_BHBF_JS_P1_L3_XXX_CI0079 //SYGCJSFW.SX_JN_SYG_JS_P1_L1_XXX_CI0001 StringBuilder linesb = new StringBuilder(projectsb); Integer lnum = Integer.valueOf(l.getId().substring(substaion.length(), project.getId().indexOf("_"))) * 1; linesb.append("_L").append(lnum) .append("_XXX_").append(p.getUniformcode()); stationpoint.setCode(linesb.toString()); stationpoint.setName(l.getName() + p.getName()); stationpoint.setUniformcode(p.getUniformcode()); stationpoint.setWindpowerstationid(l.getId()); stationpoint.setRealtimeid(substaion + (station.getId().endsWith("_FDC") ? "FCJSFW" : "GCJSFW")); stationList.add(stationpoint); } } } } } return stationList; } /** * @param p * @param windpowerstationList * @return */ private List czd(Standardpoint p, List windpowerstationList) { Windturbinetestingpointnew testing = null; List testingList = new ArrayList<>(); for (Windpowerstation station : windpowerstationList) { List windturbineList = windturbineService.getWindturbineGyLine(station.getId(), "", ""); for (Windturbine w : windturbineList) { List list = windturbinetestingpointnewService.list(w.getId(), p.getUniformcode()); if (null != list && list.size() > 0) { continue; } testing = new Windturbinetestingpointnew(); //fjjs //fjjcd String substaion = station.getId().substring(0, station.getId().indexOf("_")); if ("fjjs".equals(p.getType())) { StringBuilder stationsb = new StringBuilder(); stationsb.append(substaion).append(station.getId().endsWith("_FDC") ? "FJJSFW." : "GFJSFW."); stationsb.append("SX_JN_").append(substaion); stationsb.append(station.getId().endsWith("_FDC") ? "F" : "G").append("_JS_"); Integer pnum = Integer.valueOf(w.getProjectid().substring(substaion.length(), w.getProjectid().indexOf("_"))) * 1; stationsb.append("P").append(pnum); Integer lnum = Integer.valueOf(w.getLineid().substring(substaion.length(), w.getLineid().indexOf("_"))) * 1; stationsb.append("_L").append(lnum); String wnum = w.getId().substring(w.getId().indexOf("_") + 1, w.getId().length()); stationsb.append("_").append(wnum).append("_"); //BHB3FJJSFW.SX_JN_BHB3F_JS_P1_L30_001_CI0060 //SYGFJSFW.SX_JN_SYG_JS_P2_L3_NBQ0061_CI0174 testing.setCode(stationsb.toString() + p.getUniformcode()); testing.setRealtimeid(substaion + (station.getId().endsWith("_FDC") ? "FJJSFW" : "GFJSFW")); } else if ("fjjcd".equals(p.getType())) { testing.setCode("INITIAL"); testing.setRealtimeid(substaion + (station.getId().endsWith("_FDC") ? "FJ" : "GF")); } testing.setName(w.getName() + p.getName()); testing.setUniformcode(p.getUniformcode()); testing.setWindpowerstationid(w.getId()); testingList.add(testing); } } return testingList; } }