12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559 |
- package com.jiayue.ipfcst.fileupload.service;
- import cn.hutool.core.util.StrUtil;
- import com.jiayue.ipfcst.common.core.exception.BusinessException;
- import com.jiayue.ipfcst.common.core.util.DateMomentUtil;
- import com.jiayue.ipfcst.common.data.abst.equipmentinfo.AbstractEquipmentInfo;
- import com.jiayue.ipfcst.common.data.constant.enums.FileTypeEnum;
- import com.jiayue.ipfcst.common.data.entity.*;
- import com.jiayue.ipfcst.common.data.repository.*;
- import com.jiayue.ipfcst.common.data.service.uploadfilerule.E63UploadFileRuleService;
- import com.jiayue.ipfcst.console.service.ForecastPowerShortTermService;
- import com.jiayue.ipfcst.console.service.ForecastPowerUltraShortTermService;
- import com.jiayue.ipfcst.console.util.RedisUtils;
- import com.jiayue.ipfcst.fileupload.util.FileUtil;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang.time.DateFormatUtils;
- import org.apache.commons.lang.time.DateUtils;
- import org.apache.velocity.Template;
- import org.apache.velocity.VelocityContext;
- import org.apache.velocity.app.VelocityEngine;
- import org.springframework.stereotype.Service;
- import java.io.File;
- import java.io.StringWriter;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.text.DecimalFormat;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * 青海上报文件生成
- *
- * @author tl
- * @version 3.0
- */
- @Service
- @Slf4j
- public class E63UploadFileService extends BaseUploadFileService {
- private final String vmsPath = FileUtil.getResourceBasePath() + "/vms/E63";
- private final VelocityEngine velocityEngine;
- private final ForecastPowerShortTermService forecastPowerShortTermService;
- private final ForecastPowerUltraShortTermService forecastPowerUltraShortTermService;
- private final E63UploadFileRuleService e63UploadFileRuleService;
- private final WeatherStationInfoRepository weatherStationInfoRepository;
- private final WindTurbineInfoRepository windTurbineInfoRepository;
- private final WeatherStationStatusDataRepository weatherStationStatusDataRepository;
- private final WindTowerInfoRepository windTowerInfoRepository;
- private final WindTowerStatusDataRepository windTowerStatusDataRepository;
- private final NwpRepository nwpRepository;
- private final InverterInfoRepository inverterInfoRepository;
- private final WindTurbineStatusDataRepository windTurbineStatusDataRepository;
- private final InverterStatusDataRepository inverterStatusDataRepository;
- private final PowerStationStatusDataRepository powerStationStatusDataRepository;
- private final RedisUtils redisUtils;
- public E63UploadFileService(VelocityEngine velocityEngine, ForecastPowerShortTermService forecastPowerShortTermService, ForecastPowerUltraShortTermService forecastPowerUltraShortTermService, E63UploadFileRuleService e63UploadFileRuleService, WeatherStationInfoRepository weatherStationInfoRepository, WindTurbineInfoRepository windTurbineInfoRepository, WeatherStationStatusDataRepository weatherStationStatusDataRepository, WindTowerInfoRepository windTowerInfoRepository, WindTowerStatusDataRepository windTowerStatusDataRepository, NwpRepository nwpRepository, InverterInfoRepository inverterInfoRepository, WindTurbineStatusDataRepository windTurbineStatusDataRepository, InverterStatusDataRepository inverterStatusDataRepository, PowerStationStatusDataRepository powerStationStatusDataRepository, RedisUtils redisUtils) {
- this.velocityEngine = velocityEngine;
- this.forecastPowerShortTermService = forecastPowerShortTermService;
- this.forecastPowerUltraShortTermService = forecastPowerUltraShortTermService;
- this.e63UploadFileRuleService = e63UploadFileRuleService;
- this.weatherStationInfoRepository = weatherStationInfoRepository;
- this.windTurbineInfoRepository = windTurbineInfoRepository;
- this.weatherStationStatusDataRepository = weatherStationStatusDataRepository;
- this.windTowerInfoRepository = windTowerInfoRepository;
- this.windTowerStatusDataRepository = windTowerStatusDataRepository;
- this.nwpRepository = nwpRepository;
- this.inverterInfoRepository = inverterInfoRepository;
- this.windTurbineStatusDataRepository = windTurbineStatusDataRepository;
- this.inverterStatusDataRepository = inverterStatusDataRepository;
- this.powerStationStatusDataRepository = powerStationStatusDataRepository;
- this.redisUtils = redisUtils;
- }
- /**
- * 生成短期预测上报文件。
- */
- public void generateDqFile(Date date) {
- List<ElectricField> electricFieldList = new ArrayList<>();
- try {
- electricFieldList = super.getMultipleStation();
- } catch (BusinessException e) {
- log.error("场站获取失败", e);
- }
- // 循环场站生成短期
- for (ElectricField electricFieldInfo : electricFieldList) {
- String stationCode = electricFieldInfo.getStationCode();
- try {
- Template template;
- // 获取短期模板
- if (electricFieldInfo.getElectricFieldTypeEnum().equals("E1")) {
- template = this.velocityEngine.getTemplate(this.vmsPath + "/DQ.vm");
- } else {
- template = this.velocityEngine.getTemplate(this.vmsPath + "/DQ_F.vm");
- }
- if (template != null) {
- VelocityContext velocityContext;
- StringWriter writer;
- String fileName;
- File file;
- // 获取当前系统时间
- Date systemDate = new Date();
- if (date != null) {
- systemDate = date;
- }
- // 短期默认天数
- int dqDays = super.getTranSysParameter("FILE_FORECAST_DAYS", "3", stationCode);
- // 开始时间
- Long startTime = DateMomentUtil.getDayStartTime(DateUtils.addDays(systemDate, 1).getTime());
- // 结束时间(开始加24小时再减去1秒)
- Long endTime = DateMomentUtil.getDayLastTime(DateUtils.addDays(systemDate, dqDays).getTime());
- // 生成上报文件名格式
- fileName = e63UploadFileRuleService.getFileNameRule(electricFieldInfo, "E1", startTime);
- if (getFileName(fileName, "E1", stationCode)) {
- // 查询短期预测功率
- List<ForecastPowerShortTermHis> forecastPowerShortTermHisList = this.forecastPowerShortTermService.getForecastPowerShortTerm(startTime, endTime, stationCode);
- // 按照预测时间进行升序
- forecastPowerShortTermHisList.sort(Comparator.comparing(ForecastPowerShortTermHis::getForecastTime));
- // 创建上报文件
- file = super.createTempFile(fileName);
- // 根据模板生成文件内容
- velocityContext = new VelocityContext();
- velocityContext.put("vList", forecastPowerShortTermHisList);
- //场站标识
- velocityContext.put("sign", electricFieldInfo.getSign());
- //场站装机容量
- velocityContext.put("capacity", electricFieldInfo.getCapacity());
- //系统当前日期
- if (electricFieldInfo.getElectricFieldTypeEnum().equals("E1")) {
- velocityContext.put("currentTime", DateFormatUtils.format(systemDate, "yyyy-MM-dd_" + "00:00:00"));
- } else {
- velocityContext.put("currentTime", DateFormatUtils.format(systemDate, "yyyy-MM-dd " + "00:00"));
- }
- //上报数据开始日期
- velocityContext.put("uploadTime", DateFormatUtils.format(startTime, "yyyy-MM-dd_") + "00:00");
- writer = new StringWriter();
- template.merge(velocityContext, writer);
- // 将文件复制到上报路径中
- super.copyUploadFile(writer, file, FileTypeEnum.E1.name(), null, date, stationCode);
- }
- } else {
- log.error(stationCode + "短期上报模板不存在!");
- }
- } catch (Exception e) {
- log.error(stationCode + "生成短期异常", e);
- }
- }
- }
- /**
- * 生成短期可用预测上报文件。
- */
- public void generateDqUseFile(Date date) {
- List<ElectricField> electricFieldList = new ArrayList<>();
- try {
- electricFieldList = super.getMultipleStation();
- } catch (BusinessException e) {
- log.error("场站获取失败", e);
- }
- // 循环场站生成短期
- for (ElectricField electricFieldInfo : electricFieldList) {
- String stationCode = electricFieldInfo.getStationCode();
- try {
- Template template;
- // 获取短期模板
- if (electricFieldInfo.getElectricFieldTypeEnum().equals("E1")) {
- template = this.velocityEngine.getTemplate(this.vmsPath + "/DQ_USE.vm");
- } else {
- template = this.velocityEngine.getTemplate(this.vmsPath + "/DQ_USE_F.vm");
- }
- if (template != null) {
- VelocityContext velocityContext;
- StringWriter writer;
- String fileName;
- File file;
- // 获取当前系统时间
- Date systemDate = new Date();
- if (date != null) {
- systemDate = date;
- }
- // 短期默认天数
- int dqDays = super.getTranSysParameter("FILE_FORECAST_DAYS", "3", stationCode);
- // 开始时间
- Long startTime = DateMomentUtil.getDayStartTime(DateUtils.addDays(systemDate, 1).getTime());
- // 结束时间(开始加24小时再减去1秒)
- Long endTime = DateMomentUtil.getDayLastTime(DateUtils.addDays(systemDate, dqDays).getTime());
- // 生成上报文件名格式
- fileName = e63UploadFileRuleService.getFileNameRule(electricFieldInfo, "E26", startTime);
- if (getFileName(fileName, "E26", stationCode)) {
- // 查询短期预测功率
- List<ForecastPowerShortTermHis> forecastPowerShortTermHisList = this.forecastPowerShortTermService.getForecastPowerShortTerm(startTime, endTime, stationCode);
- if (forecastPowerShortTermHisList.size() > 0) {
- // 按照预测时间进行升序
- forecastPowerShortTermHisList.sort(Comparator.comparing(ForecastPowerShortTermHis::getForecastTime));
- }
- // 创建上报文件
- file = super.createTempFile(fileName);
- // 根据模板生成文件内容
- velocityContext = new VelocityContext();
- velocityContext.put("vList", forecastPowerShortTermHisList);
- //场站标识
- velocityContext.put("sign", electricFieldInfo.getSign());
- //系统当前日期
- velocityContext.put("currentTime", DateFormatUtils.format(systemDate, "yyyy-MM-dd_" + "00:00:00"));
- //上报数据开始日期
- velocityContext.put("uploadTime", DateFormatUtils.format(startTime, "yyyy-MM-dd_") + "00:00");
- writer = new StringWriter();
- template.merge(velocityContext, writer);
- // 将文件复制到上报路径中
- super.copyUploadFile(writer, file, FileTypeEnum.E26.name(), null, date, stationCode);
- }
- } else {
- log.error(stationCode + "可用短期上报模板不存在!");
- }
- } catch (Exception e) {
- log.error(stationCode + "生成可用短期异常", e);
- }
- }
- }
- /**
- * 生成超短期预测上报文件。
- */
- public void generateCdqFile(Date date) {
- List<ElectricField> electricFieldList = new ArrayList<>();
- try {
- electricFieldList = super.getMultipleStation();
- } catch (BusinessException e) {
- log.error("场站获取失败", e);
- }
- // 循环场站生成短期
- for (ElectricField electricFieldInfo : electricFieldList) {
- String stationCode = electricFieldInfo.getStationCode();
- try {
- Template template;
- // 获取短期模板
- if (electricFieldInfo.getElectricFieldTypeEnum().equals("E1")) {
- template = this.velocityEngine.getTemplate(this.vmsPath + "/CDQ.vm");
- } else {
- template = this.velocityEngine.getTemplate(this.vmsPath + "/CDQ_F.vm");
- }
- if (template != null) {
- VelocityContext velocityContext;
- StringWriter writer;
- String fileName;
- File file;
- // 获取当前系统时间
- Date systemDate = new Date();
- if (date != null) {
- systemDate = date;
- }
- // 短期默认天数
- int cdqPoint = super.getTranSysParameter("FILE_CDQ_POINT", "16", stationCode);
- // 获取提前几分钟生成超短期
- int cdqUpMin = super.getTranSysParameter("CDQ_UP_MIN", "0", stationCode);
- // 开始时间
- long startTime = DateMomentUtil.getMomentTime(systemDate.getTime() + 15 * 60 * 1000 + (long) cdqUpMin * 1000 * 60, 1, 15 * 60 * 1000L);
- // 结束时间
- long endTime = startTime + (long) cdqPoint * 15 * 60 * 1000 - 1000;
- // 生成上报文件名格式
- fileName = e63UploadFileRuleService.getFileNameRule(electricFieldInfo, "E2", startTime);
- if (getFileName(fileName, "E2", stationCode)) {
- // 查询超短期预测功率
- List<ForecastPowerUltraShortTermHis> forecastPowerUltraShortTermHisList = this.forecastPowerUltraShortTermService.getForecastPowerUltraShortTerm(startTime, endTime, stationCode);
- // 按照预测时间进行升序
- forecastPowerUltraShortTermHisList.sort(Comparator.comparing(ForecastPowerUltraShortTermHis::getForecastTime));
- // 创建上报文件
- file = super.createTempFile(fileName);
- // 根据模板生成文件内容
- velocityContext = new VelocityContext();
- velocityContext.put("vList", forecastPowerUltraShortTermHisList);
- // 场站标识
- velocityContext.put("sign", electricFieldInfo.getSign());
- // 场站装机容量
- velocityContext.put("capacity", electricFieldInfo.getCapacity());
- // 系统当前日期
- if (electricFieldInfo.getElectricFieldTypeEnum().equals("E1")) {
- velocityContext.put("currentTime", DateFormatUtils.format(systemDate, "yyyy-MM-dd_HH:mm" + ":00"));
- } else {
- velocityContext.put("currentTime", DateFormatUtils.format(systemDate, "yyyy-MM-dd HH:mm" + ":00"));
- }
- // 上报数据开始日期
- velocityContext.put("uploadTime", DateFormatUtils.format(startTime, "yyyy-MM-dd_HH:mm"));
- writer = new StringWriter();
- template.merge(velocityContext, writer);
- super.copyUploadFile(writer, file, FileTypeEnum.E2.name(), null, date, stationCode);
- }
- } else {
- log.error(stationCode + "超短期上报模板不存在!");
- }
- } catch (Exception e) {
- log.error(stationCode + "生成超短期异常", e);
- }
- }
- }
- /**
- * 生成超短期可用预测上报文件。
- */
- public void generateCdqUseFile(Date date) {
- List<ElectricField> electricFieldList = new ArrayList<>();
- try {
- electricFieldList = super.getMultipleStation();
- } catch (BusinessException e) {
- log.error("场站获取失败", e);
- }
- // 循环场站生成短期
- for (ElectricField electricFieldInfo : electricFieldList) {
- String stationCode = electricFieldInfo.getStationCode();
- try {
- Template template;
- // 获取短期模板
- if (electricFieldInfo.getElectricFieldTypeEnum().equals("E1")) {
- template = this.velocityEngine.getTemplate(this.vmsPath + "/CDQ_USE.vm");
- } else {
- template = this.velocityEngine.getTemplate(this.vmsPath + "/CDQ_USE_F.vm");
- }
- if (template != null) {
- VelocityContext velocityContext;
- StringWriter writer;
- String fileName;
- File file;
- // 获取当前系统时间
- Date systemDate = new Date();
- if (date != null) {
- systemDate = date;
- }
- // 短期默认天数
- int cdqPoint = super.getTranSysParameter("FILE_CDQ_POINT", "16", stationCode);
- // 获取提前几分钟生成超短期
- int cdqUpMin = super.getTranSysParameter("CDQ_UP_MIN", "0", stationCode);
- // 开始时间
- long startTime = DateMomentUtil.getMomentTime(systemDate.getTime() + 15 * 60 * 1000 + (long) cdqUpMin * 1000 * 60, 1, 15 * 60 * 1000L);
- // 结束时间
- long endTime = startTime + (long) cdqPoint * 15 * 60 * 1000 - 1000;
- // 生成上报文件名格式
- fileName = e63UploadFileRuleService.getFileNameRule(electricFieldInfo, "E27", startTime);
- if (getFileName(fileName, "E27", stationCode)) {
- List<ForecastPowerUltraShortTermHis> forecastPowerUltraShortTermHisList = this.forecastPowerUltraShortTermService.getForecastPowerUltraShortTerm(startTime, endTime, stationCode);
- // 按照预测时间进行升序
- if (forecastPowerUltraShortTermHisList.size() > 0) {
- forecastPowerUltraShortTermHisList.sort(Comparator.comparing(ForecastPowerUltraShortTermHis::getForecastTime));
- }
- // 创建上报文件
- file = super.createTempFile(fileName);
- // 根据模板生成文件内容
- velocityContext = new VelocityContext();
- velocityContext.put("vList", forecastPowerUltraShortTermHisList);
- // 场站标识
- velocityContext.put("sign", electricFieldInfo.getSign());
- // 场站装机容量
- velocityContext.put("capacity", electricFieldInfo.getCapacity());
- // 系统当前日期
- if (electricFieldInfo.getElectricFieldTypeEnum().equals("E1")) {
- velocityContext.put("currentTime", DateFormatUtils.format(systemDate, "yyyy-MM-dd_HH:mm" + ":00"));
- } else {
- velocityContext.put("currentTime", DateFormatUtils.format(systemDate, "yyyy-MM-dd HH:mm" + ":00"));
- }
- // 上报数据开始日期
- velocityContext.put("uploadTime", DateFormatUtils.format(startTime - 15 * 60 * 1000, "yyyy-MM-dd_HH:mm"));
- writer = new StringWriter();
- template.merge(velocityContext, writer);
- super.copyUploadFile(writer, file, FileTypeEnum.E27.name(), null, date, stationCode);
- }
- } else {
- log.error(stationCode + "可用超短期上报模板不存在!");
- }
- } catch (Exception e) {
- log.error(stationCode + "生成可用超短期异常", e);
- }
- }
- }
- /**
- * 生成气象站或者测风塔上报文件
- */
- public void generateQxzOrCftFile(Date date) {
- List<ElectricField> electricFieldList = new ArrayList<>();
- try {
- electricFieldList = super.getMultipleStation();
- } catch (BusinessException e) {
- log.error("场站获取失败", e);
- }
- // 循环场站生成短期
- for (ElectricField electricFieldInfo : electricFieldList) {
- String stationCode = electricFieldInfo.getStationCode();
- try {
- String fileName;
- // 获取当前系统时间
- Date systemDate = new Date();
- if (date != null) {
- systemDate = date;
- }
- Long endTime = DateMomentUtil.getMomentTime(systemDate.getTime(), 1, 5 * 60 * 1000L);
- Long startTime = endTime - 4 * 60 * 1000;
- // 生成上报文件名格式
- Template template;
- if (electricFieldInfo.getElectricFieldTypeEnum().toString().equals("E1")) {
- // 获取气象站模板
- template = this.velocityEngine.getTemplate(this.vmsPath + "/QXZ.vm");
- fileName = e63UploadFileRuleService.getFileNameRule(electricFieldInfo, "E6", endTime);
- if (getFileName(fileName, "E6", stationCode)) {
- generateQxzFile(fileName, template, electricFieldInfo, date, startTime, endTime);
- }
- } else {
- template = this.velocityEngine.getTemplate(this.vmsPath + "/CFT.vm");
- fileName = e63UploadFileRuleService.getFileNameRule(electricFieldInfo, "E7", endTime);
- if (getFileName(fileName, "E7", stationCode)) {
- generateCftFile(fileName, template, electricFieldInfo, date, startTime, endTime);
- }
- }
- } catch (Exception e) {
- log.error(stationCode + "生成文件异常", e);
- }
- }
- }
- /**
- * 生成气象站上报文件
- */
- private void generateQxzFile(String fileName, Template template, ElectricField electricFieldInfo, Date date, Long startTime, Long endTime) {
- // 获取气象站信息
- List<WeatherStationInfo> weatherStationInfoList = weatherStationInfoRepository.findAll();
- // 将气象站信息过滤出上报
- List<WeatherStationInfo> weatherStationInfos = weatherStationInfoList.stream().filter(AbstractEquipmentInfo::getReport).collect(Collectors.toList());
- if (!weatherStationInfos.isEmpty()) {
- String qxzId = String.valueOf(weatherStationInfos.get(0).getId());
- Map<String, String> qxzMap = redisUtils.hgetall("qxz-" + electricFieldInfo.getStationCode() + "-" + qxzId);
- // 数据格式化
- DecimalFormat df = new DecimalFormat("0.00");
- BigDecimal globalR = new BigDecimal(0);
- BigDecimal directR = new BigDecimal(0);
- BigDecimal diffuseR = new BigDecimal(0);
- BigDecimal ws = new BigDecimal(0);
- BigDecimal wd = new BigDecimal(0);
- BigDecimal airT = new BigDecimal(0);
- BigDecimal p = new BigDecimal(0);
- BigDecimal rh = new BigDecimal(0);
- BigDecimal cellT = new BigDecimal(0);
- boolean isUseRedis = false;
- if (!qxzMap.isEmpty()) {
- String time = qxzMap.get("time");
- long timestamp = new Date().getTime();
- SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
- try{
- Date d = sf.parse(time);// 日期转换为时间戳
- timestamp = d.getTime();
- }catch (Exception e){
- log.info("日期转换异常");
- e.printStackTrace();
- }
- if (StrUtil.isNotBlank(time)) {
- if (timestamp >= startTime && timestamp <= endTime) {
- // 从缓存里赋值
- globalR = qxzMap.get("globalR") == null ? qxzRandomCreate("globalR") : new BigDecimal(qxzMap.get("globalR"));
- directR = qxzMap.get("directR") == null ? qxzRandomCreate("directR") : new BigDecimal(qxzMap.get("directR"));
- diffuseR = qxzMap.get("diffuseR") == null ? globalR.subtract(directR) : new BigDecimal(qxzMap.get("diffuseR"));
- airT = qxzMap.get("airT") == null ? qxzRandomCreate("airT") : new BigDecimal(qxzMap.get("airT"));
- p = qxzMap.get("p") == null ? qxzRandomCreate("p") : new BigDecimal(qxzMap.get("p"));
- rh = qxzMap.get("rh") == null ? qxzRandomCreate("rh") : new BigDecimal(qxzMap.get("rh"));
- cellT = qxzMap.get("cellT") == null ? qxzRandomCreate("cellT") : new BigDecimal(qxzMap.get("cellT"));
- ws = qxzMap.get("ws") == null ? qxzRandomCreate("ws") : new BigDecimal(qxzMap.get("ws"));
- wd = qxzMap.get("wd") == null ? qxzRandomCreate("wd") : new BigDecimal(qxzMap.get("wd"));
- isUseRedis = true;
- log.info(electricFieldInfo.getStationCode() + "生成气象站数据从redis获取:" + qxzMap);
- }
- }
- }
- if (!isUseRedis) {
- List<WeatherStationStatusData> weatherStationStatusDataList = weatherStationStatusDataRepository.findByStationCodeAndTimeBetweenAndEquipmentId(electricFieldInfo.getStationCode(), new Date(startTime), new Date(endTime), qxzId);
- if (weatherStationStatusDataList.isEmpty()) {
- // 总辐射产生500-1000随机数
- globalR = qxzRandomCreate("globalR");
- // 直辐射产生400-500随机数
- directR = qxzRandomCreate("directR");
- // 散辐射 = 总 - 直
- diffuseR = globalR.subtract(directR);
- airT = qxzRandomCreate("airT");
- p = qxzRandomCreate("p");
- rh = qxzRandomCreate("rh");
- cellT = qxzRandomCreate("cellT");
- ws = qxzRandomCreate("ws");
- wd = qxzRandomCreate("wd");
- log.info(electricFieldInfo.getStationCode() + "生成气象站数据用随机数");
- } else {
- weatherStationStatusDataList.stream().sorted(Comparator.comparing(WeatherStationStatusData::getTime).reversed()).collect(Collectors.toList());
- WeatherStationStatusData weatherStationStatusData = weatherStationStatusDataList.get(0);
- globalR = weatherStationStatusData.getGlobalR();
- directR = weatherStationStatusData.getDirectR();
- diffuseR = globalR.subtract(directR);
- airT = weatherStationStatusData.getAirT();
- p = weatherStationStatusData.getP();
- rh = weatherStationStatusData.getRh();
- cellT = weatherStationStatusData.getCellT();
- ws = weatherStationStatusData.getWs();
- wd = weatherStationStatusData.getWd();
- log.info(electricFieldInfo.getStationCode() + "生成气象站数据从数据表获取");
- }
- }
- // 创建上报文件
- File file = super.createTempFile(fileName);
- //青海要求 直=总-散;但是当散辐射大于总辐射时直辐射为负数不符合该规则。所以比较总直散三个值,用最大的当总辐射去减去
- log.info(electricFieldInfo.getStationCode() + "qxz实际值 总GlobalR:" + globalR + " 直DirectR:" + directR + " 散DiffuseR:" + diffuseR);
- if (globalR.compareTo(diffuseR) < 0) {
- //当散辐射大于总辐射时,数值互换
- BigDecimal a = globalR;
- globalR = diffuseR;
- diffuseR = a;
- }
- directR = globalR.subtract(diffuseR);
- // 根据模板生成文件内容
- VelocityContext velocityContext = new VelocityContext();
- velocityContext.put("GlobalR", df.format(globalR));
- velocityContext.put("AirT", df.format(airT));
- velocityContext.put("P", df.format(p));
- velocityContext.put("RH", df.format(rh));
- velocityContext.put("CellT", df.format(cellT));
- velocityContext.put("DirectR", df.format(directR));
- velocityContext.put("DiffuseR", df.format(diffuseR));
- velocityContext.put("WS", df.format(ws));
- velocityContext.put("WD", df.format(wd));
- // 场站标识
- velocityContext.put("sign", electricFieldInfo.getSign());
- // 场站装机容量
- velocityContext.put("capacity", electricFieldInfo.getCapacity());
- // 系统当前日期
- velocityContext.put("currentTime", DateFormatUtils.format(endTime, "yyyy-MM-dd_HH:mm") + ":00");
- // 上报数据开始日期
- velocityContext.put("uploadTime", DateFormatUtils.format(endTime, "yyyy-MM-dd_HH:mm"));
- StringWriter writer = new StringWriter();
- template.merge(velocityContext, writer);
- super.copyUploadFile(writer, file, FileTypeEnum.E6.name(), null, date, electricFieldInfo.getStationCode());
- }
- }
- /**
- * 生成测风塔上报文件
- */
- private void generateCftFile(String fileName, Template template, ElectricField electricFieldInfo, Date date, Long startTime, Long endTime) {
- // 获取测风塔信息
- List<WindTowerInfo> windTowerInfoList = windTowerInfoRepository.findAll();
- // 将测风塔信息过滤出上报的塔
- List<WindTowerInfo> filterWindTowerInfoList = windTowerInfoList.stream().filter(AbstractEquipmentInfo::getReport).collect(Collectors.toList());
- if (!filterWindTowerInfoList.isEmpty()) {
- String cftId = String.valueOf(filterWindTowerInfoList.get(0).getId());
- Map<String, String> cftMap = redisUtils.hgetall("cft-" + electricFieldInfo.getStationCode() + "-" + cftId);
- // 数据格式化
- DecimalFormat df = new DecimalFormat("0.00");
- BigDecimal ws10 = new BigDecimal(0);
- BigDecimal wd10 = new BigDecimal(0);
- BigDecimal ws30 = new BigDecimal(0);
- BigDecimal wd30 = new BigDecimal(0);
- BigDecimal ws50 = new BigDecimal(0);
- BigDecimal wd50 = new BigDecimal(0);
- BigDecimal ws60 = new BigDecimal(0);
- BigDecimal wd60 = new BigDecimal(0);
- BigDecimal ws70 = new BigDecimal(0);
- BigDecimal wd70 = new BigDecimal(0);
- BigDecimal ws80 = new BigDecimal(0);
- BigDecimal wd80 = new BigDecimal(0);
- BigDecimal ws90 = new BigDecimal(0);
- BigDecimal wd90 = new BigDecimal(0);
- BigDecimal ws100 = new BigDecimal(0);
- BigDecimal wd100 = new BigDecimal(0);
- BigDecimal wsHubHeight = new BigDecimal(0);
- BigDecimal wdHubHeight = new BigDecimal(0);
- BigDecimal t8 = new BigDecimal(0);
- BigDecimal p8 = new BigDecimal(0);
- BigDecimal rh8 = new BigDecimal(0);
- boolean isUseRedis = false;
- if (!cftMap.isEmpty()) {
- String time = cftMap.get("time");
- long timestamp = new Date().getTime();
- SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
- try{
- Date d = sf.parse(time);// 日期转换为时间戳
- timestamp = d.getTime();
- }catch (Exception e){
- log.info("日期转换异常");
- e.printStackTrace();
- }
- if (StrUtil.isNotBlank(time)) {
- if (timestamp>= startTime && timestamp <= endTime) {
- // 从缓存里赋值
- ws10 = cftMap.get("wsInst10") == null ? new BigDecimal("-99") : new BigDecimal(cftMap.get("wsInst10"));
- wd10 = cftMap.get("wdInst10") == null ? new BigDecimal("-99") : new BigDecimal(cftMap.get("wdInst10"));
- ws30 = cftMap.get("wsInst30") == null ? new BigDecimal("-99") : new BigDecimal(cftMap.get("wsInst30"));
- wd30 = cftMap.get("wdInst30") == null ? new BigDecimal("-99") : new BigDecimal(cftMap.get("wdInst30"));
- ws50 = cftMap.get("wsInst50") == null ? new BigDecimal("-99") : new BigDecimal(cftMap.get("wsInst50"));
- wd50 = cftMap.get("wdInst50") == null ? new BigDecimal("-99") : new BigDecimal(cftMap.get("wdInst50"));
- ws60 = cftMap.get("wsInst60") == null ? new BigDecimal("-99") : new BigDecimal(cftMap.get("wsInst60"));
- wd60 = cftMap.get("wdInst60") == null ? new BigDecimal("-99") : new BigDecimal(cftMap.get("wdInst60"));
- ws70 = cftMap.get("wsInst70") == null ? new BigDecimal("-99") : new BigDecimal(cftMap.get("wsInst70"));
- wd70 = cftMap.get("wdInst70") == null ? new BigDecimal("-99") : new BigDecimal(cftMap.get("wdInst70"));
- ws80 = cftMap.get("wsInst80") == null ? new BigDecimal("-99") : new BigDecimal(cftMap.get("wsInst80"));
- wd80 = cftMap.get("wdInst80") == null ? new BigDecimal("-99") : new BigDecimal(cftMap.get("wdInst80"));
- ws90 = cftMap.get("wsInst90") == null ? new BigDecimal("-99") : new BigDecimal(cftMap.get("wsInst90"));
- wd90 = cftMap.get("wdInst90") == null ? new BigDecimal("-99") : new BigDecimal(cftMap.get("wdInst90"));
- ws100 = cftMap.get("wsInst100") == null ? new BigDecimal("-99") : new BigDecimal(cftMap.get("wsInst100"));
- wd100 = cftMap.get("wdInst100") == null ? new BigDecimal("-99") : new BigDecimal(cftMap.get("wdInst100"));
- wsHubHeight = cftMap.get("wsInstHubHeight") == null ? cftRandomCreate("wsInstHubHeight") : new BigDecimal(cftMap.get("wsInstHubHeight"));
- wdHubHeight = cftMap.get("wdInstHubHeight") == null ? cftRandomCreate("wdInstHubHeight") : new BigDecimal(cftMap.get("wdInstHubHeight"));
- t8 = cftMap.get("tInst") == null ? cftRandomCreate("tInst") : new BigDecimal(cftMap.get("tInst"));
- p8 = cftMap.get("paInst") == null ? cftRandomCreate("paInst") : new BigDecimal(cftMap.get("paInst"));
- rh8 = cftMap.get("rhInst") == null ? cftRandomCreate("rhInst") : new BigDecimal(cftMap.get("rhInst"));
- isUseRedis = true;
- log.info(electricFieldInfo.getStationCode() + "生成测风塔数据从redis获取:" + cftMap);
- }
- }
- }
- if (!isUseRedis) {
- List<WindTowerStatusData> windTowerStatusDataList = windTowerStatusDataRepository.findByStationCodeAndEquipmentIdAndTimeBetween(electricFieldInfo.getStationCode(), cftId, new Date(startTime), new Date(endTime));
- if (windTowerStatusDataList.isEmpty()) {
- // 没有测风塔数据用nwp数据补
- long nwpTime;
- try {
- nwpTime = DateMomentUtil.getMomentTime(endTime, 1, 15 * 60 * 1000L);
- } catch (Exception e) {
- log.error("获取nwp时刻步长错误", e);
- nwpTime = DateMomentUtil.getDayStartTime(new Date().getTime());
- }
- List<Nwp> nwpList = nwpRepository.findByPreTimeBetween(nwpTime, nwpTime);
- if (nwpList.size() > 0) {
- Nwp nwpData = nwpList.get(0);
- ws10 = nwpData.getWs10();
- ws10 = ws10.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- wd10 = nwpData.getWd10();
- wd10 = wd10.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- ws30 = nwpData.getWs30();
- ws30 = ws30.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- wd30 = nwpData.getWd30();
- wd30 = wd30.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- ws50 = nwpData.getWs50();
- ws50 = ws50.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- wd50 = nwpData.getWd50();
- wd50 = wd50.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- ws60 = ws50.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- wd60 = wd50.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- ws70 = nwpData.getWs70();
- ws70 = ws70.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- wd70 = nwpData.getWd70();
- wd70 = wd70.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- ws80 = nwpData.getWs80();
- ws80 = ws80.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- wd80 = nwpData.getWd80();
- wd80 = wd80.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- ws90 = nwpData.getWs90();
- ws90 = ws90.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- wd90 = nwpData.getWd90();
- wd90 = wd90.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- ws100 = nwpData.getWs100();
- ws100 = ws100.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- wd100 = nwpData.getWd100();
- wd100 = wd100.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- wsHubHeight = nwpData.getWs170();
- wsHubHeight = wsHubHeight.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- wdHubHeight = nwpData.getWd170();
- wdHubHeight = wdHubHeight.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- rh8 = nwpData.getRh();
- rh8 = rh8.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- t8 = nwpData.getT();
- t8 = t8.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- p8 = nwpData.getPressure();
- p8 = p8.add(new BigDecimal(df.format(Math.random() * 1 + 0.01))).setScale(2, RoundingMode.HALF_UP);
- log.info(electricFieldInfo.getStationCode() + "生成测风塔数据用nwp+随机数");
- } else {
- // 10米风速产生1-5随机数
- ws10 = cftRandomCreate("wsInst10");
- // 10米风向产生40-60随机数
- wd10 = cftRandomCreate("wdInst10");
- // 30米风速产生6-10随机数
- ws30 = cftRandomCreate("wsInst30");
- // 30米风向产生70-90随机数
- wd30 = cftRandomCreate("wdInst30");
- // 50米风速产生16-20随机数
- ws50 = cftRandomCreate("wsInst50");
- // 50米风向产生130-150随机数
- wd50 = cftRandomCreate("wdInst50");
- // 60米风速产生16-20随机数
- ws60 = cftRandomCreate("wsInst60");
- // 60米风向产生130-150随机数
- wd60 = cftRandomCreate("wdInst60");
- // 70米风速产生31-35随机数
- ws70 = cftRandomCreate("wsInst70");
- // 70米风向产生220-240随机数
- wd70 = cftRandomCreate("wdInst70");
- // 80米风速产生35-40随机数
- ws80 = cftRandomCreate("wsInst80");
- // 80米风向产生240-250随机数
- wd80 = cftRandomCreate("wdInst80");
- // 90米风速产生45-50随机数
- ws90 = cftRandomCreate("wsInst90");
- // 90米风向产生260-270随机数
- wd90 = cftRandomCreate("wdInst90");
- // 100米风速产生60-70随机数
- ws100 = cftRandomCreate("wsInst100");
- // 100米风向产生280-290随机数
- wd100 = cftRandomCreate("wdInst100");
- wsHubHeight = cftRandomCreate("wsInstHubHeight");
- wdHubHeight = cftRandomCreate("wdInstHubHeight");
- // 湿度产生50-60随机数
- rh8 = cftRandomCreate("rhInst");
- // 温度产生20-35随机数
- t8 = cftRandomCreate("tInst");
- // 气压产生75-90随机数
- p8 = cftRandomCreate("paInst");
- log.info(electricFieldInfo.getStationCode() + "生成测风塔数据用随机数");
- }
- } else {
- windTowerStatusDataList.stream().sorted(Comparator.comparing(WindTowerStatusData::getTime).reversed()).collect(Collectors.toList());
- WindTowerStatusData windTowerStatusData = windTowerStatusDataList.get(0);
- // 10米风速
- if (windTowerStatusData.getWsInst10() != null)
- ws10 = windTowerStatusData.getWsInst10();
- // 10米风向
- if (windTowerStatusData.getWdInst10() != null)
- wd10 = windTowerStatusData.getWdInst10();
- // 30米风速
- if (windTowerStatusData.getWdInst30() != null)
- ws30 = windTowerStatusData.getWsInst30();
- // 30米风向
- if (windTowerStatusData.getWdInst30() != null)
- wd30 = windTowerStatusData.getWdInst30();
- // 50米风速
- if (windTowerStatusData.getWdInst50() != null)
- ws50 = windTowerStatusData.getWsInst50();
- // 50米风向
- if (windTowerStatusData.getWdInst50() != null)
- wd50 = windTowerStatusData.getWdInst50();
- // 60米风速
- if (windTowerStatusData.getWdInst60() != null)
- ws60 = windTowerStatusData.getWsInst60();
- // 60米风向
- if (windTowerStatusData.getWdInst60() != null)
- wd60 = windTowerStatusData.getWdInst60();
- // 70米风速
- if (windTowerStatusData.getWdInst70() != null)
- ws70 = windTowerStatusData.getWsInst70();
- // 70米风向
- if (windTowerStatusData.getWdInst70() != null)
- wd70 = windTowerStatusData.getWdInst70();
- // 80米风速
- if (windTowerStatusData.getWdInst80() != null)
- ws80 = windTowerStatusData.getWsInst80();
- // 80米风向
- if (windTowerStatusData.getWdInst80() != null)
- wd80 = windTowerStatusData.getWdInst80();
- // 90米风速
- if (windTowerStatusData.getWdInst90() != null)
- ws90 = windTowerStatusData.getWsInst90();
- // 90米风向
- if (windTowerStatusData.getWdInst90() != null)
- wd90 = windTowerStatusData.getWdInst90();
- // 100米风速
- if (windTowerStatusData.getWdInst100() != null)
- ws100 = windTowerStatusData.getWsInst100();
- // 100米风向
- if (windTowerStatusData.getWdInst100() != null)
- wd100 = windTowerStatusData.getWdInst100();
- if (windTowerStatusData.getWsInstHubHeight() != null)
- wsHubHeight = windTowerStatusData.getWsInstHubHeight();
- if (windTowerStatusData.getWdInstHubHeight() != null)
- wdHubHeight = windTowerStatusData.getWdInstHubHeight();
- // 湿度产生
- if (windTowerStatusData.getRhInst() != null)
- rh8 = windTowerStatusData.getRhInst();
- // 温度产生
- if (windTowerStatusData.getTInst() != null)
- t8 = windTowerStatusData.getTInst();
- // 气压产生
- if (windTowerStatusData.getPaInst() != null)
- p8 = windTowerStatusData.getPaInst();
- log.info(electricFieldInfo.getStationCode() + "生成测风塔数据用数据表");
- }
- }
- // 创建上报文件
- File file = super.createTempFile(fileName);
- // 根据模板生成文件内容
- VelocityContext velocityContext = new VelocityContext();
- velocityContext.put("WS_10", df.format(ws10));
- velocityContext.put("WD_10", df.format(wd10));
- velocityContext.put("WS_30", df.format(ws30));
- velocityContext.put("WD_30", df.format(wd30));
- velocityContext.put("WS_50", df.format(ws50));
- velocityContext.put("WD_50", df.format(wd50));
- velocityContext.put("WS_60", df.format(ws60));
- velocityContext.put("WD_60", df.format(wd60));
- velocityContext.put("WS_70", df.format(ws70));
- velocityContext.put("WD_70", df.format(wd70));
- velocityContext.put("WS_80", df.format(ws80));
- velocityContext.put("WD_80", df.format(wd80));
- velocityContext.put("WS_90", df.format(ws90));
- velocityContext.put("WD_90", df.format(wd90));
- velocityContext.put("WS_100", df.format(ws100));
- velocityContext.put("WD_100", df.format(wd100));
- velocityContext.put("WS_HubHeight", df.format(wsHubHeight));
- velocityContext.put("WD_HubHeight", df.format(wdHubHeight));
- velocityContext.put("T_8", df.format(t8));
- velocityContext.put("P_8", df.format(p8));
- velocityContext.put("RH_8", df.format(rh8));
- // 场站标识
- velocityContext.put("sign", electricFieldInfo.getSign());
- // 系统当前日期
- velocityContext.put("currentTime", DateFormatUtils.format(endTime, "yyyy-MM-dd_HH:mm") + ":00");
- // 上报数据开始日期
- velocityContext.put("uploadTime", DateFormatUtils.format(endTime, "yyyy-MM-dd_HH:mm"));
- StringWriter writer = new StringWriter();
- template.merge(velocityContext, writer);
- super.copyUploadFile(writer, file, FileTypeEnum.E7.name(), null, date, electricFieldInfo.getStationCode());
- }
- }
- /**
- * 生成逆变器上报文件。
- */
- public void generateNbqOrFjFile(Date date) {
- List<ElectricField> electricFieldList = new ArrayList<>();
- try {
- electricFieldList = super.getMultipleStation();
- } catch (BusinessException e) {
- log.error("场站获取失败", e);
- }
- // 循环场站生成短期
- for (ElectricField electricFieldInfo : electricFieldList) {
- String stationCode = electricFieldInfo.getStationCode();
- try {
- String fileName;
- // 获取当前系统时间
- Date systemDate = new Date();
- if (date != null) {
- systemDate = date;
- }
- Long endTime = DateMomentUtil.getMomentTime(systemDate.getTime(), 1, 5 * 60 * 1000L);
- Long startTime = endTime - 4 * 60 * 1000;
- // 生成上报文件名格式
- Template template;
- if (electricFieldInfo.getElectricFieldTypeEnum().toString().equals("E1")) {
- // 获取逆变器模板
- template = this.velocityEngine.getTemplate(this.vmsPath + "/NBQ.vm");
- fileName = e63UploadFileRuleService.getFileNameRule(electricFieldInfo, "E8", endTime);
- if (getFileName(fileName, "E8", stationCode)) {
- generateNbqFile(fileName, template, electricFieldInfo, systemDate, startTime, endTime);
- }
- } else {
- template = this.velocityEngine.getTemplate(this.vmsPath + "/FJ.vm");
- fileName = e63UploadFileRuleService.getFileNameRule(electricFieldInfo, "E9", endTime);
- if (getFileName(fileName, "E9", stationCode)) {
- generateFjFile(fileName, template, electricFieldInfo, systemDate, startTime, endTime);
- }
- }
- } catch (Exception e) {
- log.error(stationCode + "生成文件异常", e);
- }
- }
- }
- /**
- * 生成风机上报文件
- */
- private void generateFjFile(String fileName, Template template, ElectricField electricFieldInfo, Date date, Long startTime, Long endTime) {
- // 获取风机信息
- List<WindTurbineInfo> windTurbineInfoList = windTurbineInfoRepository.findAll();
- // 将测风塔信息过滤出上报的塔
- List<WindTurbineInfo> filterWindTurbineInfoList = windTurbineInfoList.stream().filter(AbstractEquipmentInfo::getReport).collect(Collectors.toList());
- if (filterWindTurbineInfoList.size() > 0) {
- List<Map<String, Object>> fanList = new ArrayList<>();
- for (WindTurbineInfo windTurbineInfo : filterWindTurbineInfoList) {
- Map<String, Object> map = new HashMap<>();
- map.put("name", windTurbineInfo.getName());
- map.put("dtaStatus", windTurbineInfo);
- map.put("sample", windTurbineInfo.getSample() ? "1" : "0");
- map.put("modelNumber", windTurbineInfo.getModelNumber());
- map.put("RatedCapacity", div(BigDecimal.valueOf(windTurbineInfo.getMaxPower()), new BigDecimal("1000"), 2));
- map.put("elName", electricFieldInfo.getName());
- map.put("collectorCircuit", windTurbineInfo.getCollectorCircuit());
- String fjId = String.valueOf(windTurbineInfo.getId());
- Map<String, String> fjMap = redisUtils.hgetall("fj-" + electricFieldInfo.getStationCode() + "-" + fjId);
- DecimalFormat df = new DecimalFormat("0.00");
- // 状态
- String status = "1";
- // 有功
- BigDecimal activePower = new BigDecimal("0");
- // 无功
- BigDecimal reactivePower = new BigDecimal("0");
- // 功率因数
- BigDecimal powerFactor = new BigDecimal("0");
- // 电压
- BigDecimal voltage = new BigDecimal("0");
- // 电流
- BigDecimal electricalCurrent = new BigDecimal("0");
- // 当日发电量
- BigDecimal dayElectricQuantity = new BigDecimal("0");
- // 转速
- BigDecimal windWheelRatedSpeed = new BigDecimal("0");
- // 风速
- BigDecimal ws = new BigDecimal("0");
- // 风向
- BigDecimal wd = new BigDecimal("0");
- // 温度
- BigDecimal t = new BigDecimal("0");
- // 桨距角
- BigDecimal pitchAngle = new BigDecimal("0");
- // 累积发电量
- BigDecimal cumulativeGeneratedEnergy = new BigDecimal("0");
- boolean isUseRedis = false;
- if (!fjMap.isEmpty()) {
- String time = fjMap.get("time");
- long timestamp = new Date().getTime();
- SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
- try{
- Date d = sf.parse(time);// 日期转换为时间戳
- timestamp = d.getTime();
- }catch (Exception e){
- log.info("日期转换异常");
- e.printStackTrace();
- }
- if (StrUtil.isNotBlank(time)) {
- if (timestamp >= startTime && timestamp <= endTime) {
- if (fjMap.get("status") != null) {
- status = fjMap.get("status");
- }
- if (fjMap.get("activePower") != null) {
- activePower = new BigDecimal(fjMap.get("activePower"));
- }
- if (fjMap.get("reactivePower") != null) {
- reactivePower = new BigDecimal(fjMap.get("reactivePower"));
- }
- if (fjMap.get("powerFactor") != null) {
- powerFactor = new BigDecimal(fjMap.get("powerFactor"));
- }
- if (fjMap.get("voltage") != null) {
- voltage = new BigDecimal(fjMap.get("voltage"));
- }
- if (fjMap.get("electricalCurrent") != null) {
- electricalCurrent = new BigDecimal(fjMap.get("electricalCurrent"));
- }
- if (fjMap.get("dayElectricQuantity") != null) {
- dayElectricQuantity = new BigDecimal(fjMap.get("dayElectricQuantity"));
- }
- if (fjMap.get("cumulativeGeneratedEnergy") != null) {
- cumulativeGeneratedEnergy = new BigDecimal(fjMap.get("cumulativeGeneratedEnergy"));
- }
- if (fjMap.get("windWheelRatedSpeed") != null) {
- windWheelRatedSpeed = new BigDecimal(fjMap.get("windWheelRatedSpeed"));
- }
- if (fjMap.get("ws") != null) {
- ws = new BigDecimal(fjMap.get("ws"));
- }
- if (fjMap.get("wd") != null) {
- wd = new BigDecimal(fjMap.get("wd"));
- }
- if (fjMap.get("t") != null) {
- t = new BigDecimal(fjMap.get("t"));
- }
- if (fjMap.get("pitchAngle") != null) {
- pitchAngle = new BigDecimal(fjMap.get("pitchAngle"));
- }
- isUseRedis = true;
- log.info(electricFieldInfo.getStationCode() + "生成风机数据用缓存");
- }
- }
- }
- if (!isUseRedis) {
- List<WindTurbineStatusData> windTurbineStatusDataList = windTurbineStatusDataRepository.findByTimeBetweenAndEquipmentId(new Date(startTime), new Date(endTime), fjId);
- if (!windTurbineStatusDataList.isEmpty()) {
- windTurbineStatusDataList.stream().sorted(Comparator.comparing(WindTurbineStatusData::getTime).reversed()).collect(Collectors.toList());
- WindTurbineStatusData windTurbineStatusData = windTurbineStatusDataList.get(0);
- if (windTurbineStatusData.getStatus() != null) {
- status = String.valueOf(windTurbineStatusData.getStatus());
- }
- if (windTurbineStatusData.getActivePower() != null) {
- activePower = windTurbineStatusData.getActivePower();
- }
- if (windTurbineStatusData.getReactivePower() != null) {
- reactivePower = windTurbineStatusData.getReactivePower();
- }
- if (windTurbineStatusData.getPowerFactor() != null) {
- powerFactor = windTurbineStatusData.getPowerFactor();
- }
- if (windTurbineStatusData.getVoltage() != null) {
- voltage = windTurbineStatusData.getVoltage();
- }
- if (windTurbineStatusData.getElectricalCurrent() != null) {
- electricalCurrent = windTurbineStatusData.getElectricalCurrent();
- }
- if (windTurbineStatusData.getDayElectricQuantity() != null) {
- dayElectricQuantity = windTurbineStatusData.getDayElectricQuantity();
- }
- if (windTurbineStatusData.getCumulativeGeneratedEnergy() != null) {
- cumulativeGeneratedEnergy = windTurbineStatusData.getCumulativeGeneratedEnergy();
- }
- if (windTurbineStatusData.getWindWheelRatedSpeed() != null) {
- windWheelRatedSpeed = windTurbineStatusData.getWindWheelRatedSpeed();
- }
- if (windTurbineStatusData.getWs() != null) {
- ws = windTurbineStatusData.getWs();
- }
- if (windTurbineStatusData.getWd() != null) {
- wd = windTurbineStatusData.getWd();
- }
- if (windTurbineStatusData.getT() != null) {
- t = windTurbineStatusData.getT();
- }
- if (windTurbineStatusData.getPitchAngle() != null) {
- pitchAngle = windTurbineStatusData.getPitchAngle();
- }
- log.info(electricFieldInfo.getStationCode() + "生成风机数据用数据表");
- } else {
- log.info(electricFieldInfo.getStationCode() + "生成风机数据缓存和数据表都没有值,使用默认0");
- }
- }
- map.put("ActivePower", div(activePower, new BigDecimal("1000"), 2).toString());
- map.put("ReActivePower", div(reactivePower, new BigDecimal("1000"), 2).toString());
- map.put("RotationlSpeed", df.format(windWheelRatedSpeed));
- map.put("WS", df.format(ws));
- map.put("WD", df.format(wd));
- map.put("T", df.format(t));
- map.put("Voltage", df.format(voltage));
- map.put("GalvanicCurrent", df.format(electricalCurrent));
- map.put("PowerFactor", df.format(powerFactor));
- map.put("GeneratingCap", df.format(cumulativeGeneratedEnergy));
- map.put("dtaStatus", status);
- map.put("DayElectricQuantity", df.format(dayElectricQuantity));
- map.put("PropellerPitchAngle", df.format(pitchAngle));
- fanList.add(map);
- }
- // 创建上报文件
- File file = super.createTempFile(fileName);
- VelocityContext velocityContext = new VelocityContext();
- // 根据模板生成文件内容
- velocityContext.put("vList", fanList);
- // 场站标识
- velocityContext.put("sign", electricFieldInfo.getSign());
- // 场站装机容量
- velocityContext.put("capacity", electricFieldInfo.getCapacity());
- // 系统当前日期
- velocityContext.put("currentTime", DateFormatUtils.format(endTime, "yyyy-MM-dd_HH:mm") + ":00");
- // 上报数据开始日期
- velocityContext.put("uploadTime", DateFormatUtils.format(endTime, "yyyy-MM-dd_HH:mm"));
- StringWriter writer = new StringWriter();
- template.merge(velocityContext, writer);
- super.copyUploadFile(writer, file, FileTypeEnum.E9.name(), null, date, electricFieldInfo.getStationCode());
- }
- }
- /**
- * 生成逆变器上报文件
- */
- private void generateNbqFile(String fileName, Template template, ElectricField electricFieldInfo, Date date, Long startTime, Long endTime) {
- // 获取逆变器
- List<InverterInfo> inverterInfoList = inverterInfoRepository.findAll();
- // 过滤上报的逆变器
- List<InverterInfo> filterInverterInfoList = inverterInfoList.stream().filter(AbstractEquipmentInfo::getReport).collect(Collectors.toList());
- if (filterInverterInfoList.size() > 0) {
- List<Map<String, String>> dtaInverterList = new ArrayList<>();
- for (InverterInfo inverterInfo : filterInverterInfoList) {
- Map<String, String> map = new HashMap<>();
- //场站名称
- map.put("czmc", electricFieldInfo.getName());
- // 名称
- map.put("name", inverterInfo.getName());
- //集电线名称
- map.put("CollectorCircuit", inverterInfo.getCollectorCircuit());
- //额定容量
- map.put("RatedCapacity", div(inverterInfo.getCapacity(), new BigDecimal("1000"), 2).toString());
- // 开机容量
- map.put("nbqCapacity", inverterInfo.getCapacity().toString());
- //型号
- map.put("modelNumber", inverterInfo.getModelNumber());
- // 是否样板
- map.put("sample", inverterInfo.getSample() ? "1" : "0");
- //是否组串
- map.put("IsString", inverterInfo.getGroupSeries() ? "1" : "0");
- String nbqId = String.valueOf(inverterInfo.getId());
- Map<String, String> nbqMap = redisUtils.hgetall("nbq-" + electricFieldInfo.getStationCode() + "-" + nbqId);
- DecimalFormat df = new DecimalFormat("0.00");
- // 状态
- String status = "1";
- // 有功
- BigDecimal activePower = new BigDecimal("0");
- // 无功
- BigDecimal reactivePower = new BigDecimal("0");
- // 功率因数
- BigDecimal powerFactor = new BigDecimal("0");
- // 电压
- BigDecimal voltage = new BigDecimal("0");
- // 电流
- BigDecimal electricalCurrent = new BigDecimal("0");
- // 当日发电量
- BigDecimal dayElectricQuantity = new BigDecimal("0");
- // 累积发电量
- BigDecimal cumulativeGeneratedEnergy = new BigDecimal("0");
- boolean isUseRedis = false;
- if (!nbqMap.isEmpty()) {
- String time = nbqMap.get("time");
- long timestamp = new Date().getTime();
- SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
- try{
- Date d = sf.parse(time);// 日期转换为时间戳
- timestamp = d.getTime();
- }catch (Exception e){
- log.info("日期转换异常");
- e.printStackTrace();
- }
- if (StrUtil.isNotBlank(time)) {
- if (timestamp >= startTime && timestamp <= endTime) {
- if (nbqMap.get("status") != null) {
- status = nbqMap.get("status");
- }
- if (nbqMap.get("activePower") != null) {
- activePower = new BigDecimal(nbqMap.get("activePower"));
- }
- if (nbqMap.get("reactivePower") != null) {
- reactivePower = new BigDecimal(nbqMap.get("reactivePower"));
- }
- if (nbqMap.get("powerFactor") != null) {
- powerFactor = new BigDecimal(nbqMap.get("powerFactor"));
- }
- if (nbqMap.get("voltage") != null) {
- voltage = new BigDecimal(nbqMap.get("voltage"));
- }
- if (nbqMap.get("electricalCurrent") != null) {
- electricalCurrent = new BigDecimal(nbqMap.get("electricalCurrent"));
- }
- if (nbqMap.get("dayElectricQuantity") != null) {
- dayElectricQuantity = new BigDecimal(nbqMap.get("dayElectricQuantity"));
- }
- if (nbqMap.get("cumulativeGeneratedEnergy") != null) {
- cumulativeGeneratedEnergy = new BigDecimal(nbqMap.get("cumulativeGeneratedEnergy"));
- }
- isUseRedis = true;
- log.info(electricFieldInfo.getStationCode() + "生成逆变器数据用缓存");
- }
- }
- }
- if (!isUseRedis) {
- List<InverterStatusData> inverterStatusDataList = inverterStatusDataRepository.findByTimeBetweenAndEquipmentId(new Date(startTime), new Date(endTime), nbqId);
- if (!inverterStatusDataList.isEmpty()) {
- inverterStatusDataList.stream().sorted(Comparator.comparing(InverterStatusData::getTime).reversed()).collect(Collectors.toList());
- InverterStatusData inverterStatusData = inverterStatusDataList.get(0);
- if (inverterStatusData.getStatus() != null) {
- status = String.valueOf(inverterStatusData.getStatus());
- }
- // 有功
- if (inverterStatusData.getActivePower() != null) {
- activePower = inverterStatusData.getActivePower();
- }
- // 无功
- if (inverterStatusData.getReactivePower() != null) {
- reactivePower = inverterStatusData.getReactivePower();
- }
- // 电压
- if (inverterStatusData.getVoltage() != null) {
- voltage = inverterStatusData.getVoltage();
- }
- // 电流
- if (inverterStatusData.getElectricalCurrent() != null) {
- electricalCurrent = inverterStatusData.getElectricalCurrent();
- }
- // 功率因数
- if (inverterStatusData.getPowerFactor() != null) {
- powerFactor = inverterStatusData.getPowerFactor();
- }
- // 日发电量
- if (inverterStatusData.getDayElectricQuantity() != null) {
- dayElectricQuantity = inverterStatusData.getDayElectricQuantity();
- }
- // 累计发电量
- if (inverterStatusData.getCumulativeGeneratedEnergy() != null) {
- cumulativeGeneratedEnergy = inverterStatusData.getCumulativeGeneratedEnergy();
- }
- log.info(electricFieldInfo.getStationCode() + "生成逆变器数据用数据表");
- } else {
- log.info(electricFieldInfo.getStationCode() + "生成逆变器数据缓存和数据表都没有值,使用默认0");
- }
- }
- map.put("status", status);
- // 有功
- map.put("NbqActivePower", div(activePower, new BigDecimal("1000"), 2).toString());
- // 无功
- map.put("NbqReActivePower", div(reactivePower, new BigDecimal("1000"), 2).toString());
- // 电压
- map.put("Voltage", df.format(voltage));
- // 电流
- map.put("GalvanicCurrent", df.format(electricalCurrent));
- // 功率因数
- map.put("PowerFactor", df.format(powerFactor));
- // 日发电量
- map.put("NbqDailyOutPut", df.format(dayElectricQuantity));
- // 累计发电量
- map.put("GeneratingCap", df.format(cumulativeGeneratedEnergy));
- dtaInverterList.add(map);
- }
- // 创建上报文件
- File file = super.createTempFile(fileName);
- VelocityContext velocityContext = new VelocityContext();
- // 根据模板生成文件内容
- velocityContext.put("vList", dtaInverterList);
- // 场站标识
- velocityContext.put("sign", electricFieldInfo.getSign());
- // 场站装机容量
- velocityContext.put("capacity", electricFieldInfo.getCapacity());
- // 系统当前日期
- velocityContext.put("currentTime", DateFormatUtils.format(endTime, "yyyy-MM-dd_HH:mm") + ":00");
- // 上报数据开始日期
- velocityContext.put("uploadTime", DateFormatUtils.format(endTime, "yyyy-MM-dd_HH:mm"));
- StringWriter writer = new StringWriter();
- template.merge(velocityContext, writer);
- super.copyUploadFile(writer, file, FileTypeEnum.E8.name(), null, date, electricFieldInfo.getStationCode());
- }
- }
- /**
- * 生成理论功率上报文件
- */
- public void generateTheroyFile(Date date) {
- List<ElectricField> electricFieldList = new ArrayList<>();
- try {
- electricFieldList = super.getMultipleStation();
- } catch (BusinessException e) {
- log.error("场站获取失败", e);
- }
- // 循环场站生成短期
- for (ElectricField electricFieldInfo : electricFieldList) {
- String stationCode = electricFieldInfo.getStationCode();
- try {
- String fileName;
- // 获取当前系统时间
- Date systemDate = new Date();
- if (date != null) {
- systemDate = date;
- }
- Long endTime = DateMomentUtil.getMomentTime(systemDate.getTime(), 1, 5 * 60 * 1000L);
- Long startTime = endTime - 4 * 60 * 1000;
- // 生成上报文件名格式
- Template template;
- if (electricFieldInfo.getElectricFieldTypeEnum().toString().equals("E1")) {
- fileName = e63UploadFileRuleService.getFileNameRule(electricFieldInfo, "E3", endTime);
- if (getFileName(fileName, "E3", stationCode)) {
- template = this.velocityEngine.getTemplate(this.vmsPath + "/THEROY.vm");
- generatePvTheroyFile(fileName, template, electricFieldInfo, date, startTime, endTime);
- }
- } else {
- fileName = e63UploadFileRuleService.getFileNameRule(electricFieldInfo, "E85", endTime);
- if (getFileName(fileName, "E85", stationCode)) {
- // 理论功率风
- template = this.velocityEngine.getTemplate(this.vmsPath + "/THEROY_F.vm");
- generateWpTheroyFile(fileName, template, electricFieldInfo, date, startTime, endTime);
- }
- }
- } catch (Exception e) {
- log.error(stationCode + "生成文件异常", e);
- }
- }
- }
- /**
- * 生成理论功率光上报文件
- */
- private void generatePvTheroyFile(String fileName, Template template, ElectricField electricFieldInfo, Date date, Long startTime, Long endTime) {
- // 样板机变量
- float ableValueAfter = 0f;
- // 辐照仪变量
- float theoryValueAfter = 0f;
- Map<String, String> powerMap = redisUtils.hgetall("power-" + electricFieldInfo.getStationCode());
- boolean isUseRedis = false;
- if (!powerMap.isEmpty()) {
- String time = powerMap.get("time");
- if (StrUtil.isNotBlank(time)) {
- if (Long.parseLong(time) >= startTime && Long.parseLong(time) <= endTime) {
- // 对预测值保留2位小数显示输出
- if (powerMap.get("ableValue") != null) {
- ableValueAfter = Float.parseFloat(powerMap.get("ableValue"));
- }
- if (powerMap.get("theoryValue") != null) {
- theoryValueAfter = Float.parseFloat(powerMap.get("theoryValue"));
- }
- isUseRedis = true;
- log.info(electricFieldInfo.getStationCode() + "生成理论功率使用缓存");
- }
- }
- }
- if (!isUseRedis) {
- // 从数据表获取
- List<PowerStationStatusData> powerStationStatusDataList = powerStationStatusDataRepository.findByTimeBetweenAndStationCode(new Date(startTime), new Date(endTime), electricFieldInfo.getStationCode());
- if (!powerStationStatusDataList.isEmpty()) {
- powerStationStatusDataList.stream().sorted(Comparator.comparing(PowerStationStatusData::getTime).reversed()).collect(Collectors.toList());
- PowerStationStatusData powerStationStatusData = powerStationStatusDataList.get(0);
- if (powerStationStatusData.getAbleValue() != null)
- ableValueAfter = powerStationStatusData.getAbleValue().floatValue();
- if (powerStationStatusData.getTheoryValue() != null)
- theoryValueAfter = powerStationStatusData.getTheoryValue().floatValue();
- log.info(electricFieldInfo.getStationCode() + "生成理论功率使用数据表");
- }
- }
- DecimalFormat df = new DecimalFormat("0.00");
- // 创建上报文件
- File file = super.createTempFile(fileName);
- // 根据模板生成文件内容
- VelocityContext velocityContext = new VelocityContext();
- // 样板机
- velocityContext.put("ableValueAfter", df.format(ableValueAfter));
- // 辐照仪
- velocityContext.put("theoryValueAfter", df.format(theoryValueAfter));
- // 场站标识
- velocityContext.put("sign", electricFieldInfo.getSign());
- // 系统当前日期
- velocityContext.put("currentTime", DateFormatUtils.format(endTime, "yyyy-MM-dd_HH:mm") + ":00");
- // 上报数据开始日期
- velocityContext.put("uploadTime", DateFormatUtils.format(endTime, "yyyy-MM-dd_HH:mm"));
- StringWriter writer = new StringWriter();
- template.merge(velocityContext, writer);
- super.copyUploadFile(writer, file, FileTypeEnum.E3.name(), null, date, electricFieldInfo.getStationCode());
- }
- /**
- * 生成理论功率风上报文件
- */
- private void generateWpTheroyFile(String fileName, Template template, ElectricField electricFieldInfo, Date date, Long startTime, Long endTime) {
- // 可用
- float ableValueAfter = 0f;
- // 理论
- float theoryValueAfter = 0f;
- //样板机
- float referencePowerBySampleAfter = 0f;
- //测风
- float referencePowerByMeasuringAfter = 0f;
- Map<String, String> powerMap = redisUtils.hgetall("power-" + electricFieldInfo.getStationCode());
- boolean isUseRedis = false;
- if (!powerMap.isEmpty()) {
- String time = powerMap.get("time");
- if (StrUtil.isNotBlank(time)) {
- if (Long.parseLong(time) >= startTime && Long.parseLong(time) <= endTime) {
- if (powerMap.get("ableValue") != null) {
- ableValueAfter = Float.parseFloat(powerMap.get("ableValue"));
- }
- if (powerMap.get("theoryValue") != null) {
- theoryValueAfter = Float.parseFloat(powerMap.get("theoryValue"));
- }
- if (powerMap.get("referencePowerBySample") != null) {
- referencePowerBySampleAfter = Float.parseFloat(powerMap.get("referencePowerBySample"));
- }
- if (powerMap.get("referencePowerByMeasuring") != null) {
- referencePowerByMeasuringAfter = Float.parseFloat(powerMap.get("referencePowerByMeasuring"));
- }
- isUseRedis = true;
- log.info(electricFieldInfo.getStationCode() + "生成理论功率使用缓存");
- }
- }
- }
- if (!isUseRedis) {
- // 从数据表获取
- List<PowerStationStatusData> powerStationStatusDataList = powerStationStatusDataRepository.findByTimeBetweenAndStationCode(new Date(startTime), new Date(endTime), electricFieldInfo.getStationCode());
- if (!powerStationStatusDataList.isEmpty()) {
- powerStationStatusDataList.stream().sorted(Comparator.comparing(PowerStationStatusData::getTime).reversed()).collect(Collectors.toList());
- PowerStationStatusData powerStationStatusData = powerStationStatusDataList.get(0);
- if (powerStationStatusData.getAbleValue() != null)
- ableValueAfter = powerStationStatusData.getAbleValue().floatValue();
- if (powerStationStatusData.getTheoryValue() != null)
- theoryValueAfter = powerStationStatusData.getTheoryValue().floatValue();
- if (powerStationStatusData.getReferencePowerBySample() != null)
- referencePowerBySampleAfter = powerStationStatusData.getReferencePowerBySample().floatValue();
- if (powerStationStatusData.getReferencePowerByMeasuring() != null)
- referencePowerByMeasuringAfter = powerStationStatusData.getReferencePowerByMeasuring().floatValue();
- log.info(electricFieldInfo.getStationCode() + "生成理论功率使用数据表");
- }
- }
- DecimalFormat df = new DecimalFormat("0.00");
- // 创建上报文件
- File file = super.createTempFile(fileName);
- // 根据模板生成文件内容
- VelocityContext velocityContext = new VelocityContext();
- // 样板机
- velocityContext.put("ableValueAfter", df.format(ableValueAfter));
- // 辐照仪
- velocityContext.put("theoryValueAfter", df.format(theoryValueAfter));
- // 样板机
- velocityContext.put("referencePowerBySampleAfter", df.format(referencePowerBySampleAfter));
- // 测风
- velocityContext.put("referencePowerByMeasuringAfter", df.format(referencePowerByMeasuringAfter));
- // 场站标识
- velocityContext.put("sign", electricFieldInfo.getSign());
- // 系统当前日期
- velocityContext.put("currentTime", DateFormatUtils.format(endTime, "yyyy-MM-dd_HH:mm") + ":00");
- // 上报数据开始日期
- velocityContext.put("uploadTime", DateFormatUtils.format(endTime, "yyyy-MM-dd_HH:mm") + ":00");
- StringWriter writer = new StringWriter();
- template.merge(velocityContext, writer);
- super.copyUploadFile(writer, file, FileTypeEnum.E85.name(), null, date, electricFieldInfo.getStationCode());
- }
- /**
- * 除法
- *
- * @param v1
- * @param v2
- * @param scale 精度,到小数点后几位
- * @return
- */
- private BigDecimal div(BigDecimal v1, BigDecimal v2, int scale) {
- if (scale < 0) {
- throw new IllegalArgumentException("The scale must be a positive integer or zero");
- }
- return v1.divide(v2, scale, RoundingMode.HALF_UP);
- }
- private BigDecimal qxzRandomCreate(String type) {
- DecimalFormat df = new DecimalFormat("0.00");
- switch (type) {
- case "globalR":
- // 总辐射产生500-1000随机数
- return new BigDecimal(df.format(Math.random() * 500 + 500));
- case "directR":
- // 直辐射产生400-500随机数
- return new BigDecimal(df.format(Math.random() * 100 + 400));
- case "airT":
- // 温度
- return new BigDecimal(df.format(Math.random() * 4 + 8));
- case "p":
- // 气压
- return new BigDecimal(df.format(Math.random() * 200 + 800));
- case "rh":
- // 湿度
- return new BigDecimal(df.format(Math.random() * 10 + 30));
- case "cellT":
- // 电池板温度
- return new BigDecimal(df.format(Math.random() * 26 + 4));
- case "ws":
- // 风速
- return new BigDecimal(df.format(Math.random() * 9 + 1));
- case "wd":
- // 风向
- return new BigDecimal(df.format(Math.random() * 100 + 200));
- default:
- return new BigDecimal("0");
- }
- }
- private BigDecimal cftRandomCreate(String type) {
- DecimalFormat df = new DecimalFormat("0.00");
- switch (type) {
- case "wsInst10":
- // 10米风速产生1-5随机数
- return new BigDecimal(df.format(Math.random() * 4 + 1));
- case "wdInst10":
- // 10米风向产生40-60随机数
- return new BigDecimal(df.format(Math.random() * 20 + 40));
- case "wsInst30":
- // 30米风速产生6-10随机数
- return new BigDecimal(df.format(Math.random() * 4 + 6));
- case "wdInst30":
- // 30米风向产生70-90随机数
- return new BigDecimal(df.format(Math.random() * 20 + 70));
- case "wsInst50":
- // 50米风速产生16-20随机数
- return new BigDecimal(df.format(Math.random() * 4 + 16));
- case "wdInst50":
- // 50米风向产生130-150随机数
- return new BigDecimal(df.format(Math.random() * 20 + 130));
- case "wsInst60":
- // 60米风速产生25-30随机数
- return new BigDecimal(df.format(Math.random() * 5 + 25));
- case "wdInst60":
- // 60米风向产生160-200随机数
- return new BigDecimal(df.format(Math.random() * 40 + 160));
- case "wsInst70":
- // 70米风速产生31-35随机数
- return new BigDecimal(df.format(Math.random() * 4 + 31));
- case "wdInst70":
- // 70米风向产生220-240随机数
- return new BigDecimal(df.format(Math.random() * 20 + 220));
- case "wsInst80":
- // 80米风速产生35-40随机数
- return new BigDecimal(df.format(Math.random() * 20 + 220));
- case "wdInst80":
- // 80米风向产生240-250随机数
- return new BigDecimal(df.format(Math.random() * 10 + 240));
- case "wsInst90":
- // 90米风速产生45-50随机数
- return new BigDecimal(df.format(Math.random() * 5 + 45));
- case "wdInst90":
- // 90米风向产生260-270随机数
- return new BigDecimal(df.format(Math.random() * 10 + 260));
- case "wsInst100":
- // 100米风速产生60-70随机数
- return new BigDecimal(df.format(Math.random() * 10 + 60));
- case "wdInst100":
- // 100米风向产生280-290随机数
- return new BigDecimal(df.format(Math.random() * 10 + 280));
- case "wsInstHubHeight":
- // 轮毂风速70-74随机数
- return new BigDecimal(df.format(Math.random() * 4 + 70));
- case "wdInstHubHeight":
- // 轮毂风向280-290随机数
- return new BigDecimal(df.format(Math.random() * 20 + 250));
- case "tInst":
- // 温度产生20-35随机数
- return new BigDecimal(df.format(Math.random() * 15 + 20));
- case "paInst":
- // 气压产生75-90随机数
- return new BigDecimal(df.format(Math.random() * 15 + 75));
- case "rhInst":
- // 湿度产生50-60随机数
- return new BigDecimal(df.format(Math.random() * 10 + 50));
- default:
- return new BigDecimal("0");
- }
- }
- }
|