Zimo 1 день назад
Родитель
Сommit
ed1d37d284

+ 66 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/IotReportDeviceController.java

@@ -25,6 +25,7 @@ import cn.iocoder.yudao.module.system.service.dept.DeptService;
 import cn.iocoder.yudao.module.system.service.dict.DictDataService;
 import com.alibaba.excel.EasyExcel;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -40,10 +41,13 @@ import javax.annotation.security.PermitAll;
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.net.URLEncoder;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
@@ -384,4 +388,66 @@ public class IotReportDeviceController {
         String encodeFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
         response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + encodeFileName + ".xlsx");
     }
+
+    @GetMapping("/rd/whl")
+    @PermitAll
+    public CommonResult<ImmutableMap<String, BigDecimal>> getWhl() {
+        Set<Long> ids;
+//        if (Objects.nonNull(pageReqVO.getDeptId())) {
+        ids = deptService.getChildDeptIdListFromCache(163L);
+        ids.add(163L);
+        IotDevicePageReqVO iotDevicePageReqVO = new IotDevicePageReqVO();
+        iotDevicePageReqVO.setDeptIds(new ArrayList<>(ids));
+        iotDevicePageReqVO.setRemark("A");
+        Long totalA = iotDeviceMapper.getTotalA(iotDevicePageReqVO);
+        List<Long> failureCount = iotDeviceMapper.getFailureCount(iotDevicePageReqVO);
+        List<Long> repairCount = iotDeviceMapper.getRepairCount(iotDevicePageReqVO);
+        List<Long> combined = Stream.concat(failureCount.stream(), repairCount.stream())
+                .distinct()
+                .collect(Collectors.toList());
+        int size = combined.size();
+        BigDecimal total = BigDecimal.valueOf(totalA);
+        BigDecimal sizeA = BigDecimal.valueOf(size);
+        BigDecimal diff = total.subtract(sizeA);
+        // 计算百分比并保留两位小数
+        BigDecimal percentA = diff.multiply(BigDecimal.valueOf(100))
+                .divide(total, 2, RoundingMode.HALF_UP);
+
+        iotDevicePageReqVO.setRemark("B");
+        Long totalB = iotDeviceMapper.getTotalA(iotDevicePageReqVO);
+        List<Long> failureCountB = iotDeviceMapper.getFailureCount(iotDevicePageReqVO);
+        List<Long> repairCountB = iotDeviceMapper.getRepairCount(iotDevicePageReqVO);
+        List<Long> combinedB = Stream.concat(failureCountB.stream(), repairCountB.stream())
+                .distinct()
+                .collect(Collectors.toList());
+        int sizeB = combinedB.size();
+
+        BigDecimal totalBB = BigDecimal.valueOf(totalB);
+        BigDecimal sizeBB = BigDecimal.valueOf(sizeB);
+        BigDecimal diffB = totalBB.subtract(sizeBB);
+        // 计算百分比并保留两位小数
+        BigDecimal percentB = diffB.multiply(BigDecimal.valueOf(100))
+                .divide(totalBB, 2, RoundingMode.HALF_UP);
+
+
+        iotDevicePageReqVO.setRemark("C");
+        Long totalC = iotDeviceMapper.getTotalA(iotDevicePageReqVO);
+        List<Long> failureCountC = iotDeviceMapper.getFailureCount(iotDevicePageReqVO);
+        List<Long> repairCountC = iotDeviceMapper.getRepairCount(iotDevicePageReqVO);
+
+        List<Long> combinedC = Stream.concat(failureCountC.stream(), repairCountC.stream())
+                .distinct()
+                .collect(Collectors.toList());
+        int sizeC = combinedC.size();
+
+        BigDecimal totalCC = BigDecimal.valueOf(totalC);
+        BigDecimal sizeCC = BigDecimal.valueOf(sizeC);
+        BigDecimal diffC = totalCC.subtract(sizeCC);
+        // 计算百分比并保留两位小数
+        BigDecimal percentC = diffC.multiply(BigDecimal.valueOf(100))
+                .divide(totalCC, 2, RoundingMode.HALF_UP);
+
+
+        return CommonResult.success(ImmutableMap.of("a",percentA,"b",percentB,"c",percentC));
+    }
 }

+ 3 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/IotDeviceMapper.java

@@ -349,4 +349,7 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> {
                                            @Param("mainBomDeviceIds") Collection<Long> mainBomDeviceIds);
     List<IotDeviceSimple> selectCodeAndNameList();
     List<IotDeviceSimple> selectTypeNumber(@Param("reqVO") IotDevicePageReqVO reqVO,@Param("products") List<Integer> products);
+    Long getTotalA(@Param("reqVO") IotDevicePageReqVO reqVO);
+    List<Long> getFailureCount(@Param("reqVO") IotDevicePageReqVO reqVO);
+    List<Long> getRepairCount(@Param("reqVO") IotDevicePageReqVO reqVO);
 }

+ 62 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotDeviceMapper.xml

@@ -555,4 +555,66 @@
             group by asset_class)a
         left join rq_iot_product_classify b on a.asset_class=b.id
     </select>
+
+    <select id="getTotalA" resultType="java.lang.Long">
+        SELECT COUNT(1) FROM RQ_IOT_DEVICE b WHERE ASSET_CLASS IN(select id from rq_iot_product_classify a
+            <where>
+                a.deleted=0
+                <if test='reqVO.remark!=null'>
+                    AND a.remark = #{reqVO.remark}
+                </if>
+            </where>
+        )
+        and
+            b.deleted=0
+            <if test="reqVO.deptIds != null and reqVO.deptIds.size &gt; 0">
+                AND b.dept_id IN
+                <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
+                    #{key}
+                </foreach>
+            </if>
+    </select>
+
+    <select id="getFailureCount" resultType="java.lang.Long">
+        select b.device_id from (SELECT ID FROM RQ_IOT_DEVICE c WHERE ASSET_CLASS IN(select id from rq_iot_product_classify a
+        <where>
+            a.deleted=0
+            <if test='reqVO.remark!=null'>
+                AND a.remark = #{reqVO.remark}
+            </if>
+        </where>
+        )
+        and
+            c.deleted=0
+        <if test="reqVO.deptIds != null and reqVO.deptIds.size &gt; 0">
+            AND c.dept_id IN
+            <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
+                #{key}
+            </foreach>
+        </if>
+        )a
+        left JOIN (select DISTINCT(device_id) from rq_iot_failure_report where `status`!='finished')b
+        on a.id=b.device_id where b.device_id is not NULL
+    </select>
+    <select id="getRepairCount" resultType="java.lang.Long">
+        select b.device_id from (SELECT ID FROM RQ_IOT_DEVICE c WHERE ASSET_CLASS IN(select id from rq_iot_product_classify a
+        <where>
+            a.deleted=0
+            <if test='reqVO.remark!=null'>
+                AND a.remark = #{reqVO.remark}
+            </if>
+        </where>
+        )
+        and
+        c.deleted=0
+        <if test="reqVO.deptIds != null and reqVO.deptIds.size &gt; 0">
+            AND c.dept_id IN
+            <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
+                #{key}
+            </foreach>
+        </if>
+        )a
+        left JOIN (select DISTINCT(device_id) from rq_iot_maintain where `status`!='finished')b
+        on a.id=b.device_id where b.device_id is not NULL
+    </select>
 </mapper>