|
@@ -22,6 +22,7 @@ import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.*;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
@@ -50,19 +51,68 @@ public class LeanModelStatistics {
|
|
|
@Autowired
|
|
|
RedisTemplate redisTemplate;
|
|
|
|
|
|
+ // 每日3点执行 测试期间1ms一次
|
|
|
+// @Scheduled(cron = "0 0 03 * * *")
|
|
|
+ @Scheduled(fixedDelay = 1000)
|
|
|
+ public void t2(){
|
|
|
+ changeProportion("1000");
|
|
|
+ } // 1ms
|
|
|
+ public void changeProportion(String freq){
|
|
|
+ log.info("变更占比");
|
|
|
+ // 峰平谷精益模型配置获取
|
|
|
+ LambdaQueryWrapper<FpgLeanModel> leanmodelQuery = new LambdaQueryWrapper<FpgLeanModel>().eq(FpgLeanModel::getStatus, "1");
|
|
|
+ List<FpgLeanModel> fpgLeanModellist = fpgLeanModelService.list(leanmodelQuery);
|
|
|
+ LocalDate today = LocalDate.now(); // 获取今天的日期
|
|
|
+ LocalDate yesterday = today.minusDays(1); // 减去一天,得到昨天的日期
|
|
|
+ /* Criteria criteria = new Criteria();
|
|
|
+ criteria.orOperator(Criteria.where("status").is(0),
|
|
|
+ Criteria.where("status").is(1));*/
|
|
|
+ // 处理数据业务逻辑
|
|
|
+ fpgLeanModellist.stream().filter(fpgLeanModeInfo -> fpgLeanModeInfo.getProportion() != null && fpgLeanModeInfo.getProportion() == 1).forEach(fpgLeanModeInfo -> {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("proportion").is(1)).addCriteria(Criteria.where("dates").is(String.valueOf(yesterday)));
|
|
|
+ List<FpgStatiscsModelMongodb> fpgStatiscsModelMongoList = mongoTemplate.find(query, FpgStatiscsModelMongodb.class, "leanmodel_" + fpgLeanModeInfo.getLeanModelCode());
|
|
|
+ BigDecimal zb = new BigDecimal("100");
|
|
|
+ fpgStatiscsModelMongoList.forEach(fpgStatiscsModelMongoInfo -> { // 循环处理采集数据处理
|
|
|
+ BigDecimal proportion = fpgStatiscsModelMongoInfo.getPower();
|
|
|
+ BigDecimal topsProportion = fpgStatiscsModelMongoInfo.getTopsPower();
|
|
|
+ BigDecimal peaksProportion = fpgStatiscsModelMongoInfo.getPeaksPower();
|
|
|
+ BigDecimal flatProportion = fpgStatiscsModelMongoInfo.getFlatPower();
|
|
|
+ BigDecimal valleysProportion = fpgStatiscsModelMongoInfo.getValleysPower();
|
|
|
+ // 核算占比
|
|
|
+ UpdateDefinition update = new Update();
|
|
|
+ ((Update) update).set("proportion", 2);
|
|
|
+ if(topsProportion.compareTo(new BigDecimal("0.00")) > 0) { // 尖
|
|
|
+ ((Update) update).set("topsProportion", topsProportion.divide(proportion, 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
+ }
|
|
|
+ if(peaksProportion.compareTo(new BigDecimal("0.00")) > 0) { // 峰
|
|
|
+ ((Update) update).set("peaksProportion", peaksProportion.divide(proportion, 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
+ }
|
|
|
+ if(flatProportion.compareTo(new BigDecimal("0.00")) > 0) { // 平
|
|
|
+ ((Update) update).set("flatProportion", flatProportion.divide(proportion, 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
+ }
|
|
|
+ if(valleysProportion.compareTo(new BigDecimal("0.00")) > 0) { // 谷
|
|
|
+ ((Update) update).set("valleysProportion", valleysProportion.divide(proportion, 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
+ }
|
|
|
+ // 保存
|
|
|
+ mongoTemplate.updateFirst(query, update, FpgStatiscsModelMongodb.class, "leanmodel_" + fpgLeanModeInfo.getLeanModelCode());
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
@Scheduled(fixedDelay = 1000)
|
|
|
public void t1(){
|
|
|
- opc("1000");
|
|
|
+ leanModel("1000");
|
|
|
} // 1ms
|
|
|
|
|
|
// 精益模型统计数据
|
|
|
- public void opc(String freq){
|
|
|
+ public void leanModel(String freq){
|
|
|
// 峰平谷精益模型配置获取
|
|
|
LambdaQueryWrapper<FpgLeanModel> leanmodelQuery = new LambdaQueryWrapper<FpgLeanModel>().eq(FpgLeanModel::getStatus, "1");
|
|
|
List<FpgLeanModel> fpgLeanModellist = fpgLeanModelService.list(leanmodelQuery);
|
|
|
log.info("峰平谷模型");
|
|
|
// 获取当前时间
|
|
|
- Date curentDate = new Date();
|
|
|
+ Date curentDate = new Date(new Date().getTime() + 8 * 60 * 60 * 1000);
|
|
|
// 尖峰平谷时段配置
|
|
|
List<PeaksAndValleysTimeConfig> peaksAndValleysTimeConfiglist = peaksAndValleysTimeConfigService.list();
|
|
|
//遍历设备集合
|
|
@@ -73,20 +123,21 @@ public class LeanModelStatistics {
|
|
|
fpgGatherList.forEach(fpgGatherData -> { // 循环处理采集数据处理
|
|
|
try {
|
|
|
// 变更记录状态
|
|
|
- fpgGatherDataService.updateById(fpgGatherData.getId());
|
|
|
+ fpgGatherData.setFpgModelState("1");
|
|
|
+ fpgGatherDataService.updateById(fpgGatherData);
|
|
|
String finalDatestr = "";
|
|
|
// 统计单位
|
|
|
if("minute". equals(fpgLeanModeInfo.getTotalUnit())){ // 分钟
|
|
|
finalDatestr = new SimpleDateFormat("HH:mm").format(fpgGatherData.getCreateTime());
|
|
|
} else if("hour". equals(fpgLeanModeInfo.getTotalUnit())){ // 小时
|
|
|
- finalDatestr = new SimpleDateFormat("HH").format(fpgGatherData.getCreateTime());
|
|
|
+ finalDatestr = new SimpleDateFormat("HH:00").format(fpgGatherData.getCreateTime());
|
|
|
} else if("day". equals(fpgLeanModeInfo.getTotalUnit())){ //
|
|
|
- finalDatestr = new SimpleDateFormat("dd").format(fpgGatherData.getCreateTime());
|
|
|
+ finalDatestr = new SimpleDateFormat("yyyy-MM-dd").format(fpgGatherData.getCreateTime());
|
|
|
} else if("week". equals(fpgLeanModeInfo.getTotalUnit())){ //
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
finalDatestr = String.valueOf(calendar.get(Calendar.WEEK_OF_MONTH));
|
|
|
} else if("month". equals(fpgLeanModeInfo.getTotalUnit())){ //
|
|
|
- finalDatestr = new SimpleDateFormat("MM").format(fpgGatherData.getCreateTime());
|
|
|
+ finalDatestr = new SimpleDateFormat("yyyy-MM").format(fpgGatherData.getCreateTime());
|
|
|
}
|
|
|
String dayDate = new SimpleDateFormat("yyyy-MM-dd").format(fpgGatherData.getCreateTime());
|
|
|
String classs = "";
|