Browse Source

首页service接口的完成

yq 4 years ago
parent
commit
3b310130dd

+ 3 - 0
fiveep-model/src/main/java/com/bizmatics/model/Site.java

@@ -95,4 +95,7 @@ public class Site implements Serializable {
     private Integer enable;
 
 
+    private String installedCapacity;
+
+
 }

+ 1 - 0
fiveep-persistence/src/main/java/com/bizmatics/persistence/mapper/RtAnalogDataMapper.java

@@ -25,4 +25,5 @@ public interface RtAnalogDataMapper extends CrudMapper<RtAnalogData> {
      */
     Double selectTotalLoad(@Param("userId") Integer userId,
                         @Param("siteId") Integer siteId);
+
 }

+ 2 - 0
fiveep-persistence/src/main/java/com/bizmatics/persistence/mapper/UserSiteMapper.java

@@ -2,6 +2,7 @@ package com.bizmatics.persistence.mapper;
 
 import com.bizmatics.model.UserSite;
 import com.bizmatics.common.mvc.base.CrudMapper;
+import org.springframework.stereotype.Repository;
 
 /**
  * <p>
@@ -11,6 +12,7 @@ import com.bizmatics.common.mvc.base.CrudMapper;
  * @author ya
  * @since 2021-07-07
  */
+@Repository
 public interface UserSiteMapper extends CrudMapper<UserSite> {
 
 }

+ 8 - 0
fiveep-service/src/main/java/com/bizmatics/service/AlarmPowerService.java

@@ -3,7 +3,9 @@ package com.bizmatics.service;
 import com.bizmatics.model.AlarmPower;
 import com.bizmatics.common.mvc.base.CrudService;
 import com.bizmatics.service.vo.ApCountVO;
+import com.bizmatics.service.vo.CommonIcoVO;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -22,4 +24,10 @@ public interface AlarmPowerService extends CrudService<AlarmPower> {
      */
     ApCountVO selectCount();
 
+    /**
+     * 告警趋势图
+     * @return
+     */
+    List<CommonIcoVO> selectByDate(Date date);
+
 }

+ 4 - 0
fiveep-service/src/main/java/com/bizmatics/service/RtAnalogDataService.java

@@ -2,6 +2,7 @@ package com.bizmatics.service;
 
 import com.bizmatics.model.RtAnalogData;
 import com.bizmatics.common.mvc.base.CrudService;
+import com.bizmatics.service.vo.RadCountVO;
 
 /**
  * <p>
@@ -13,4 +14,7 @@ import com.bizmatics.common.mvc.base.CrudService;
  */
 public interface RtAnalogDataService extends CrudService<RtAnalogData> {
 
+
+    RadCountVO selectCount();
+
 }

+ 15 - 0
fiveep-service/src/main/java/com/bizmatics/service/impl/AlarmPowerServiceImpl.java

@@ -9,9 +9,14 @@ import com.bizmatics.service.AlarmPowerService;
 import com.bizmatics.common.mvc.base.AbstractCrudService;
 import com.bizmatics.service.util.SessionLocal;
 import com.bizmatics.service.vo.ApCountVO;
+import com.bizmatics.service.vo.CommonIcoVO;
 import org.checkerframework.checker.units.qual.A;
+import org.checkerframework.checker.units.qual.C;
 import org.springframework.stereotype.Service;
 
+import java.util.Date;
+import java.util.List;
+
 /**
  * <p>
  * 电力告警 服务实现类
@@ -23,6 +28,7 @@ import org.springframework.stereotype.Service;
 @Service
 public class AlarmPowerServiceImpl extends AbstractCrudService<AlarmPowerMapper, AlarmPower> implements AlarmPowerService {
 
+
     @Override
     public ApCountVO selectCount() {
         Integer count = baseMapper.selectCount(SessionLocal.getUserId(),null,null);
@@ -31,4 +37,13 @@ public class AlarmPowerServiceImpl extends AbstractCrudService<AlarmPowerMapper,
         apCountVo.setUnCount(baseMapper.selectCount(SessionLocal.getUserId(),null,0));
         return apCountVo;
     }
+
+    @Override
+    public List<CommonIcoVO> selectByDate(Date date) {
+        CommonIcoVO commonIcoVoToday = new CommonIcoVO();
+//        for (int i = 0; i < ; i++) {
+//
+//        }
+        return null;
+    }
 }

+ 44 - 2
fiveep-service/src/main/java/com/bizmatics/service/impl/RtAnalogDataServiceImpl.java

@@ -1,13 +1,24 @@
 package com.bizmatics.service.impl;
 
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.api.R;
 import com.bizmatics.model.RtAnalogData;
+import com.bizmatics.model.Site;
+import com.bizmatics.model.UserSite;
 import com.bizmatics.persistence.mapper.RtAnalogDataMapper;
 import com.bizmatics.service.RtAnalogDataService;
 import com.bizmatics.common.mvc.base.AbstractCrudService;
-import org.checkerframework.checker.units.qual.A;
+import com.bizmatics.service.SiteService;
+import com.bizmatics.service.UserSiteService;
+import com.bizmatics.service.util.Arith;
+import com.bizmatics.service.util.SessionLocal;
+import com.bizmatics.service.vo.RadCountVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+
 /**
  * <p>
  *  服务实现类
@@ -19,7 +30,38 @@ import org.springframework.stereotype.Service;
 @Service
 public class RtAnalogDataServiceImpl extends AbstractCrudService<RtAnalogDataMapper, RtAnalogData> implements RtAnalogDataService {
 
-
+    @Autowired
+    private UserSiteService userSiteService;
     @Autowired
     private RtAnalogDataMapper rtAnalogDataMapper;
+    @Autowired
+    private SiteService siteService;
+
+
+    @Override
+    public RadCountVO selectCount() {
+        Integer userId = SessionLocal.getUserId();
+        List<UserSite> list = userSiteService.list(Wrappers.lambdaQuery(UserSite.class).eq(UserSite::getUserId, userId));
+        AtomicReference<Integer> heavyLoad = new AtomicReference<>(0);
+        AtomicReference<Integer> easyLoad = new AtomicReference<>(0);
+        AtomicReference<Integer> norMalLoad = new AtomicReference<>(0);
+        list.forEach(userSite -> {
+            Site site = siteService.getOne(Wrappers.lambdaQuery(Site.class).eq(Site::getId, userSite.getId()));
+            Double aDouble = rtAnalogDataMapper.selectTotalLoad(userId, site.getId());
+            double div = Arith.div(aDouble, Double.parseDouble(site.getInstalledCapacity()));
+            if (div < 0.4){
+                easyLoad.getAndSet(easyLoad.get() + 1);
+            }else if (div >= 0.4 && div <= 0.8){
+                norMalLoad.getAndSet(norMalLoad.get() + 1);
+            }else {
+                heavyLoad.getAndSet(heavyLoad.get() + 1);
+            }
+        });
+        int count = list.size();
+        RadCountVO radCountVO = new RadCountVO();
+        radCountVO.setHeavyLoad(Arith.div(heavyLoad.get(),count));
+        radCountVO.setEasyLoad(Arith.div(easyLoad.get(),count));
+        radCountVO.setNorMalLoad(Arith.div(norMalLoad.get(),count));
+        return radCountVO;
+    }
 }

+ 87 - 0
fiveep-service/src/main/java/com/bizmatics/service/util/Arith.java

@@ -0,0 +1,87 @@
+package com.bizmatics.service.util;
+
+import java.math.BigDecimal;
+
+/**
+ * @author yq
+ * @date 2021/6/8 9:12
+ */
+public class Arith {
+
+
+    //默认除法运算精度
+    private static final int DEF_DIV_SCALE = 4;
+
+    /**
+     * 构造器私有,让这个类不能实例化
+     */
+    private Arith(){}
+
+    /**
+     * 加法
+     * @param v1
+     * @param v2
+     * @return
+     */
+    public static double add(double v1,double v2){
+        BigDecimal b1 = BigDecimal.valueOf(v1);
+        BigDecimal b2 = BigDecimal.valueOf(v2);
+        return b1.add(b2).doubleValue();
+    }
+
+    /**
+     * 减法
+     * @param v1
+     * @param v2
+     * @return
+     */
+    public static double sub(double v1,double v2){
+        BigDecimal b1 = BigDecimal.valueOf(v1);
+        BigDecimal b2 = BigDecimal.valueOf(v2);
+        return b1.subtract(b2).doubleValue();
+    }
+
+    /**
+     * 乘法
+     * @param v1
+     * @param v2
+     * @return
+     */
+    public static double mul(double v1,double v2){
+        BigDecimal b1 = BigDecimal.valueOf(v1);
+        BigDecimal b2 = BigDecimal.valueOf(v2);
+        return b1.multiply(b2).doubleValue();
+    }
+
+    /**
+     * 除法
+     * @param v1
+     * @param v2
+     * @return
+     */
+    public static double div(double v1,double v2){
+        return div(v1,v2,DEF_DIV_SCALE);
+    }
+
+
+    /**
+     * 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指定精度,以后的数字四舍五入
+     * @param v1
+     *            被除數
+     * @param v2
+     *            除數
+     * @param scale
+     *            表示表示需要精確到小數點以後位数。
+     * @return 兩個參數的商
+     */
+    public static double div(double v1, double v2, int scale) {
+        if (scale < 0) {
+            throw new IllegalArgumentException(
+                    "The scale must be a positive integer or zero");
+        }
+        BigDecimal b1 = BigDecimal.valueOf(v1);
+        BigDecimal b2 = BigDecimal.valueOf(v2);
+        return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
+    }
+
+}

+ 28 - 0
fiveep-service/src/main/java/com/bizmatics/service/vo/RadCountVO.java

@@ -0,0 +1,28 @@
+package com.bizmatics.service.vo;
+
+import lombok.Data;
+
+/**
+ * @author yq
+ * @date 2021/7/8 16:30
+ */
+@Data
+public class RadCountVO {
+
+    /**
+     * 重载运行
+     */
+    private Double heavyLoad;
+
+    /**
+     * 轻载运行
+     */
+    private Double easyLoad;
+
+
+    /**
+     * 正常运行
+     */
+    private Double norMalLoad;
+
+}