| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.web.core.api; |
| | | |
| | | |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.ruoyi.system.domain.SysLogininfor; |
| | | import com.ruoyi.system.service.ISysLogininforService; |
| | | import com.ruoyi.web.core.api.dto.DataRequest; |
| | | import com.ruoyi.web.core.api.dto.ElectricityDto; |
| | | import com.ruoyi.web.core.api.dto.LoggingDto; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.YearMonth; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Component |
| | | @Slf4j |
| | | //æ¦æå¸å·¥ä¸åä¿¡æ¯å屿°æ®æ¨é(宿¶ä»»å¡) |
| | | public class ScheduledApi { |
| | | |
| | | @Value("${api.entName}") |
| | | private String entName; |
| | | |
| | | @Value("${api.socialCreditCode}") |
| | | private String socialCreditCode; |
| | | |
| | | @Value("${api.dayPowerConsumption}") |
| | | private Double dayPowerConsumption; |
| | | |
| | | @Value("${api.outputValuesBase}") |
| | | private Double outputValuesBase; |
| | | |
| | | @Value("${api.electricityCost}") |
| | | private Double electricityCost; |
| | | |
| | | |
| | | @Autowired |
| | | private Api api; |
| | | |
| | | @Autowired |
| | | private ISysLogininforService logininforService; |
| | | |
| | | private static final Random RANDOM = new Random(); |
| | | |
| | | //æ¨éç»å½æ¥å¿æ¯å¨ |
| | | // @Scheduled(cron = "0 0 1 ? * 1") |
| | | public void logging(){ |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:dd"); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | //è·åç»å½æ¥å¿ |
| | | SysLogininfor logininfor= new SysLogininfor(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | //è·åæ¯ä¸ªå°æ¶ä¸çæçæ°æ°æ® |
| | | map.put("beginTime",LocalDateTime.now().minusDays(7L).format(formatter)); |
| | | map.put("endTime",LocalDateTime.now().format(formatter)); |
| | | logininfor.setParams(map); |
| | | List<SysLogininfor> list = logininforService.selectLogininforList(logininfor); |
| | | List<LoggingDto> loggingDtos = list.stream().map(sysLogininfor -> { |
| | | LoggingDto loggingDto = new LoggingDto(); |
| | | loggingDto.setEntName(entName); |
| | | loggingDto.setSocialCreditCode(socialCreditCode); |
| | | loggingDto.setUuid(UUID.randomUUID().toString()); |
| | | loggingDto.setUser_id(sysLogininfor.getUserName()); |
| | | loggingDto.setLogin_time(sdf.format(sysLogininfor.getLoginTime())); |
| | | loggingDto.setSysName("MISç³»ç»"); |
| | | loggingDto.setPushtime(LocalDateTime.now().format(formatter)); |
| | | return loggingDto; |
| | | }).collect(Collectors.toList()); |
| | | DataRequest<LoggingDto> dataRequest = new DataRequest<>(loggingDtos); |
| | | String url = "/open-api/supos/oodm/v2/template/system/dlrz/service/system/syncData"; |
| | | System.out.println(JSONUtil.toJsonStr(dataRequest)); |
| | | String code = api.pushData(url, dataRequest); |
| | | System.out.println("code===="+code); |
| | | } |
| | | |
| | | //æ¨éçµæ¯æ |
| | | // @Scheduled(cron = "0 0 1 1 * ?") |
| | | public void electricity(){ |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:dd"); |
| | | //è·åç»å½æ¥å¿ |
| | | List<ElectricityDto> electricityDtos = new ArrayList<>(); |
| | | ElectricityDto electricityDto = new ElectricityDto(); |
| | | electricityDto.setEntName(entName); |
| | | electricityDto.setSocialCreditCode(socialCreditCode); |
| | | electricityDto.setUuid(UUID.randomUUID().toString()); |
| | | //æ»èçµé(æ¥èçµé±10%ä¸ä¸æµ®å¨*天æ°) |
| | | YearMonth lastMonth = YearMonth.now().minusMonths(1); |
| | | int lastMonthDays = lastMonth.lengthOfMonth();//计ç®ä¸æå®é
å¤©æ° |
| | | double floatRate = 0.9 + RANDOM.nextDouble() * 0.2;//çæÂ±10%éæºæµ®å¨ç³»æ°ï¼0.9 ~ 1.1ï¼ |
| | | double totalPower = Math.round(dayPowerConsumption * floatRate * lastMonthDays * 100) / 100.0;//䏿æ»èçµé |
| | | electricityDto.setTotalPowerConsumption(String.valueOf(totalPower)); |
| | | //ç产èçµé(å æ¯70-90%) && åå
¬èçµéå æ¯å©ä½ |
| | | double productionRate = 0.7 + RANDOM.nextDouble() * 0.2; // 0.7 ~ 0.9 |
| | | double productionPower = Math.round(totalPower * productionRate * 100) / 100.0; |
| | | double officePower = Math.round((totalPower - productionPower) * 100) / 100.0; |
| | | electricityDto.setProductionPowerConsumption(String.valueOf(productionPower)); |
| | | electricityDto.setOfficePowerConsumption(String.valueOf(officePower)); |
| | | //å³°å¹³è°·æ¶æ®µåé
ï¼å·¥ä¸éç¨æ¯ä¾ï¼å³°50%ãå¹³30%ãè°·20%ï¼ |
| | | double peakPower = Math.round(totalPower * 0.5 * 100) / 100.0; |
| | | double flatPower = Math.round(totalPower * 0.3 * 100) / 100.0; |
| | | double valleyPower = Math.round(totalPower * 0.2 * 100) / 100.0; |
| | | electricityDto.setPeakPowerConsumption(String.valueOf(peakPower));//峰段èçµé |
| | | electricityDto.setFlatPowerConsumption(String.valueOf(flatPower));//å¹³åèçµé |
| | | electricityDto.setValleyPowerConsumption(String.valueOf(valleyPower));//谷段èçµé |
| | | //ä¼°ç®çµåæèéï¼å æ»èçµé3%-8%ï¼å·¥ä¸é
çµåçæèèå´ï¼ |
| | | double lossRate = 0.03 + RANDOM.nextDouble() * 0.05; // 0.03 ~ 0.08 |
| | | double powerLoss = Math.round(totalPower * lossRate * 100) / 100.0; |
| | | electricityDto.setPowerLossQty(String.valueOf(powerLoss));//çµåæèé |
| | | //计ç®åä½äº§å¼èçµéï¼åç¦æ¶/ä¸å
ï¼= ç产èçµé / 产å¼ï¼äº§å¼åºäºåºæ°éæºæµ®å¨ï¼Â±20%ï¼ |
| | | double outputValueFloat = 0.8 + RANDOM.nextDouble() * 0.4; // äº§å¼æµ®å¨ç³»æ°0.8~1.2 |
| | | double actualOutputValue = outputValuesBase * outputValueFloat; // å®é
产å¼ï¼ä¸å
ï¼ |
| | | double powerPerOutput = Math.round((productionPower / actualOutputValue) * 100) / 100.0; |
| | | electricityDto.setPowerPerOutput(String.valueOf(powerPerOutput));//åä½äº§å¼èçµé |
| | | //çµè´¹ |
| | | double feeFloatRate = 0.88 + RANDOM.nextDouble() * 0.24;//çæÂ±12%éæºæµ®å¨ç³»æ°ï¼0.88 ~ 1.12ï¼ |
| | | double totalFee = Math.round(electricityCost * feeFloatRate * 100) / 100.0; |
| | | electricityDto.setElectricityCost(String.valueOf(totalFee));//çµè´¹ |
| | | electricityDto.setTime(LocalDateTime.now().minusHours(2).format(formatter)); |
| | | electricityDto.setPushtime(LocalDateTime.now().format(formatter)); |
| | | electricityDtos.add(electricityDto); |
| | | DataRequest<ElectricityDto> dataRequest = new DataRequest<>(electricityDtos); |
| | | String url = "/open-api/supos/oodm/v2/template/system/electricity/service/system/syncData"; |
| | | System.out.println(JSONUtil.toJsonStr(dataRequest)); |
| | | String code = api.pushData(url, dataRequest); |
| | | System.out.println("code===="+code); |
| | | } |
| | | } |