Jelajahi Sumber

设备类别统计接口

lipenghui 2 hari lalu
induk
melakukan
dfa2b67e63

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

@@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
+import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceSimple;
 import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.IotProductClassifyDO;
 import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
@@ -31,7 +32,9 @@ import org.springframework.web.bind.annotation.*;
 import javax.annotation.Resource;
 import javax.annotation.security.PermitAll;
 import javax.validation.Valid;
+import java.sql.Array;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@@ -43,16 +46,19 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
 @Validated
 @PermitAll
 public class IotReportDeviceController {
-    private static final ImmutableList<String> jt = ImmutableList.<String>builder()
-            .add("提纯撬", "空气处理撬", "膜组", "注水泵", "绞车") // 第二批5个
-            .add("井架", "底座", "发动机", "泥浆泵", "连油主车") // 第三批5个
+    private static final ImmutableList<Integer> jt = ImmutableList.<Integer>builder()
+            .add(159, 160, 232, 157, 158) // 第一批5个
+            .add(107, 119, 106, 108, 19)
+            .add(191, 28,30,35)
+            .add(85, 90, 177, 144, 31) // 第三批5个
             .build();
-    private static final ImmutableList<String> rh = ImmutableList.<String>builder()
-            .add("提纯撬", "空气处理撬", "膜组", "注水泵").build();
-    private static final ImmutableList<String> ry = ImmutableList.<String>builder()
-            .add("井架", "底座", "发动机", "泥浆泵","绞车").build();
-    private static final ImmutableList<String> rd = ImmutableList.<String>builder()
-            .add("连油主车","混砂车","仪表车","小车").build();
+    private static final ImmutableList<Integer> rh = ImmutableList.<Integer>builder()
+            .add(159, 160, 232, 157, 158) // 第一批5个
+            .add(107, 119, 106, 108,191).build();
+    private static final ImmutableList<Integer> ry = ImmutableList.<Integer>builder()
+            .add(85, 90, 177, 144,19).build();
+    private static final ImmutableList<Integer> rd = ImmutableList.<Integer>builder()
+            .add(31,28,30,35).build();
     private final DeptApi deptApi;
     private final IotDeviceMapper iotDeviceMapper;
     private final IotProductClassifyMapper iotProductClassifyMapper;
@@ -73,7 +79,7 @@ public class IotReportDeviceController {
 
     @Operation(summary = "类别统计")
     @GetMapping("/device/type")
-    public CommonResult<List<Map<String, Object>>> getDeviceTypeStat(@Valid IotDevicePageReqVO iotDevicePageReqVO) {
+    public CommonResult<List<IotDeviceSimple>> getDeviceTypeStat(@Valid IotDevicePageReqVO iotDevicePageReqVO) {
         Set<Long> ids;
         String companyCode;
         if (Objects.isNull(iotDevicePageReqVO.getDeptId())){
@@ -87,42 +93,97 @@ public class IotReportDeviceController {
         }
         IotDevicePageReqVO pageReqVO = new IotDevicePageReqVO();
         pageReqVO.setDeptIds(new ArrayList<>(ids));
-        List<IotDeviceDO> iotDeviceDOS = iotDeviceMapper.selectList(pageReqVO);
-        LinkedList<Map<String, Object>> results = new LinkedList<>();
-        List<Map.Entry<Long, Long>> collect = iotDeviceDOS.stream().collect(Collectors.groupingBy(IotDeviceDO::getAssetClass, Collectors.counting())).entrySet().stream().sorted(Map.Entry.<Long, Long>comparingByValue().reversed()).collect(Collectors.toList());
-        collect.forEach(e->{
-            IotProductClassifyDO iotProductClassifyDO = iotProductClassifyMapper.selectById(e.getKey());
-            if ("jt".equals(companyCode)) {
-                if (jt.contains(iotProductClassifyDO.getName())||"空压机".equals(iotProductClassifyDO.getName())||iotProductClassifyDO.getName().contains("驱增压机")) {
-                    Map<String, Object> map = new HashMap<>(4);
-                    map.put("category", iotProductClassifyDO.getName());
-                    map.put("value", e.getValue());
-                    results.add(map);
+        if ("jt".equals(companyCode)) {
+            List<IotDeviceSimple> iotDeviceSimples = iotDeviceMapper.selectTypeNumber(pageReqVO, jt);
+            AtomicInteger zyj = new AtomicInteger();
+            AtomicInteger kyj = new AtomicInteger();
+            iotDeviceSimples.forEach(e ->{
+                if ("电驱增压机".equals(e.getCategory())||"柴驱增压机".equals(e.getCategory())||"液驱增压机".equals(e.getCategory())) {
+                    zyj.addAndGet(Math.toIntExact(e.getValue()==null?0:e.getValue()));
                 }
-            } else if ("rh".equals(companyCode)) {
-                if (rh.contains(iotProductClassifyDO.getName())||"空压机".equals(iotProductClassifyDO.getName())||iotProductClassifyDO.getName().contains("驱增压机")){
-                    Map<String, Object> map = new HashMap<>(4);
-                    map.put("category", iotProductClassifyDO.getName());
-                    map.put("value", e.getValue());
-                    results.add(map);
+                if ("电驱空压机".equals(e.getCategory())||"柴驱空压机".equals(e.getCategory())||"天然气驱空压机".equals(e.getCategory())) {
+                    kyj.addAndGet(Math.toIntExact(e.getValue()==null?0:e.getValue()));
                 }
-            } else if ("ry".equals(companyCode)) {
-                if (ry.contains(iotProductClassifyDO.getName())){
-                    Map<String, Object> map = new HashMap<>(4);
-                    map.put("category", iotProductClassifyDO.getName());
-                    map.put("value", e.getValue());
-                    results.add(map);
+            });
+            List<IotDeviceSimple> result = iotDeviceSimples.stream().filter(e -> !"电驱增压机".equals(e.getCategory()) && !"柴驱增压机".equals(e.getCategory()) && !"液驱增压机".equals(e.getCategory())
+                    && !"电驱空压机".equals(e.getCategory()) && !"柴驱空压机".equals(e.getCategory()) && !"天然气驱空压机".equals(e.getCategory())).collect(Collectors.toList());
+            IotDeviceSimple iotDeviceSimple = new IotDeviceSimple();
+            iotDeviceSimple.setCategory("增压机");
+            iotDeviceSimple.setValue(zyj.longValue());
+            result.add(iotDeviceSimple);
+            IotDeviceSimple iotDeviceSimple1 = new IotDeviceSimple();
+            iotDeviceSimple1.setCategory("空压机");
+            iotDeviceSimple1.setValue(kyj.longValue());
+            result.add(iotDeviceSimple1);
+            return CommonResult.success((result.stream().sorted(Comparator.comparing(IotDeviceSimple::getValue).reversed())).collect(Collectors.toList()));
+        } else if ("rh".equals(companyCode)) {
+            List<IotDeviceSimple> iotDeviceSimples = iotDeviceMapper.selectTypeNumber(pageReqVO, rh);
+            AtomicInteger zyj = new AtomicInteger();
+            AtomicInteger kyj = new AtomicInteger();
+            iotDeviceSimples.forEach(e ->{
+                if ("电驱增压机".equals(e.getCategory())||"柴驱增压机".equals(e.getCategory())||"液驱增压机".equals(e.getCategory())) {
+                    zyj.addAndGet(Math.toIntExact(e.getValue()==null?0:e.getValue()));
                 }
-            } else if ("rd".equals(companyCode)) {
-                if (rd.contains(iotProductClassifyDO.getName())||iotProductClassifyDO.getName().contains("压裂泵车")){
-                    Map<String, Object> map = new HashMap<>(4);
-                    map.put("category", iotProductClassifyDO.getName());
-                    map.put("value", e.getValue());
-                    results.add(map);
+                if ("电驱空压机".equals(e.getCategory())||"柴驱空压机".equals(e.getCategory())||"天然气驱空压机".equals(e.getCategory())) {
+                    kyj.addAndGet(Math.toIntExact(e.getValue()==null?0:e.getValue()));
                 }
-            }
-        });
-        return CommonResult.success(results);
+            });
+            List<IotDeviceSimple> result = iotDeviceSimples.stream().filter(e -> !"电驱增压机".equals(e.getCategory()) && !"柴驱增压机".equals(e.getCategory()) && !"液驱增压机".equals(e.getCategory())
+                    && !"电驱空压机".equals(e.getCategory()) && !"柴驱空压机".equals(e.getCategory()) && !"天然气驱空压机".equals(e.getCategory())).collect(Collectors.toList());
+            IotDeviceSimple iotDeviceSimple = new IotDeviceSimple();
+            iotDeviceSimple.setCategory("增压机");
+            iotDeviceSimple.setValue(zyj.longValue());
+            result.add(iotDeviceSimple);
+            IotDeviceSimple iotDeviceSimple1 = new IotDeviceSimple();
+            iotDeviceSimple1.setCategory("空压机");
+            iotDeviceSimple1.setValue(kyj.longValue());
+            result.add(iotDeviceSimple1);
+            return CommonResult.success((result.stream().sorted(Comparator.comparing(IotDeviceSimple::getValue).reversed())).collect(Collectors.toList()));
+        } else if ("ry".equals(companyCode)) {
+            List<IotDeviceSimple> iotDeviceSimples = iotDeviceMapper.selectTypeNumber(pageReqVO, ry);
+            return CommonResult.success((iotDeviceSimples.stream().sorted(Comparator.comparing(IotDeviceSimple::getValue).reversed())).collect(Collectors.toList()));
+        } else if ("rd".equals(companyCode)) {
+            List<IotDeviceSimple> iotDeviceSimples = iotDeviceMapper.selectTypeNumber(pageReqVO, rd);
+            return CommonResult.success((iotDeviceSimples.stream().sorted(Comparator.comparing(IotDeviceSimple::getValue).reversed())).collect(Collectors.toList()));
+        } else {
+            return CommonResult.success(new ArrayList<>());
+        }
+//        List<IotDeviceDO> iotDeviceDOS = iotDeviceMapper.selectList(pageReqVO);
+//        LinkedList<Map<String, Object>> results = new LinkedList<>();
+//        List<Map.Entry<Long, Long>> collect = iotDeviceDOS.stream().collect(Collectors.groupingBy(IotDeviceDO::getAssetClass, Collectors.counting())).entrySet().stream().sorted(Map.Entry.<Long, Long>comparingByValue().reversed()).collect(Collectors.toList());
+//        collect.forEach(e->{
+//            IotProductClassifyDO iotProductClassifyDO = iotProductClassifyMapper.selectById(e.getKey());
+//            if ("jt".equals(companyCode)) {
+//                if (jt.contains(iotProductClassifyDO.getName())||"空压机".equals(iotProductClassifyDO.getName())||iotProductClassifyDO.getName().contains("驱增压机")) {
+//                    Map<String, Object> map = new HashMap<>(4);
+//                    map.put("category", iotProductClassifyDO.getName());
+//                    map.put("value", e.getValue());
+//                    results.add(map);
+//                }
+//            } else if ("rh".equals(companyCode)) {
+//                if (rh.contains(iotProductClassifyDO.getName())||"空压机".equals(iotProductClassifyDO.getName())||iotProductClassifyDO.getName().contains("驱增压机")){
+//                    Map<String, Object> map = new HashMap<>(4);
+//                    map.put("category", iotProductClassifyDO.getName());
+//                    map.put("value", e.getValue());
+//                    results.add(map);
+//                }
+//            } else if ("ry".equals(companyCode)) {
+//                if (ry.contains(iotProductClassifyDO.getName())){
+//                    Map<String, Object> map = new HashMap<>(4);
+//                    map.put("category", iotProductClassifyDO.getName());
+//                    map.put("value", e.getValue());
+//                    results.add(map);
+//                }
+//            } else if ("rd".equals(companyCode)) {
+//                if (rd.contains(iotProductClassifyDO.getName())||iotProductClassifyDO.getName().contains("压裂泵车")){
+//                    Map<String, Object> map = new HashMap<>(4);
+//                    map.put("category", iotProductClassifyDO.getName());
+//                    map.put("value", e.getValue());
+//                    results.add(map);
+//                }
+//            }
+//        });
+//        return CommonResult.success(results);
     }
 
 

+ 2 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/vo/IotDeviceSimple.java

@@ -9,4 +9,6 @@ public class IotDeviceSimple {
     private String deviceName;
     private Long orderCount;
     private Long deptId;
+    private String category;
+    private Long value;
 }

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

@@ -6,6 +6,8 @@ import cn.iocoder.yudao.framework.common.pojo.SortablePageParam;
 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
 import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorder.vo.IotMainWorkOrderPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.stat.vo.AllOrderResp;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotCarDevicePlateVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
@@ -345,4 +347,5 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> {
                                            @Param("deviceIds") Collection<Long> deviceIds,
                                            @Param("mainBomDeviceIds") Collection<Long> mainBomDeviceIds);
     List<IotDeviceSimple> selectCodeAndNameList();
+    List<IotDeviceSimple> selectTypeNumber(@Param("reqVO") IotDevicePageReqVO reqVO,@Param("products") List<Integer> products);
 }

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

@@ -534,4 +534,25 @@
         WHERE
             deleted = 0
     </select>
+    <select id="selectTypeNumber" resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceSimple">
+        select b.name as category, a.count as value from (select asset_class, count(id) as count from rq_iot_device d
+            <where>
+                d.deleted=0
+                <if test="reqVO.deptIds != null and reqVO.deptIds.size &gt; 0">
+                    AND d.dept_id IN
+                    <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
+                        #{key}
+                    </foreach>
+                </if>
+                and d.deleted=0
+                <if test="products != null and products.size &gt; 0">
+                    AND d.asset_class IN
+                    <foreach collection="products" index="index" item="key" open="(" separator="," close=")">
+                        #{key}
+                    </foreach>
+                </if>
+            </where>
+            group by asset_class)a
+        left join rq_iot_product_classify b on a.asset_class=b.id
+    </select>
 </mapper>