hfxc226 vor 2 Jahren
Ursprung
Commit
e94306a468

+ 4 - 0
platform-dao/src/main/java/com/platform/dao/mapper/sb/SbInfoMapper.java

@@ -135,5 +135,9 @@ public interface SbInfoMapper extends MyMapper<SbInfo> {
 
     List<SbInfoVO> getSubSb(SbInfoDTO sbInfoDTO);
 
+    // 根据位置code,查询该位置设备数量,包括下属位置
     int selectCountByPosition(String positionCode);
+
+    // 根据位置code,查询该位置设备数量,包括下属位置
+    List<Map<String, String>> selectCountByPositionGroup();
 }

+ 10 - 0
platform-dao/src/main/resources/mapper/sb/SbInfoMapper.xml

@@ -743,4 +743,14 @@ user.real_name as saveUserName,sb.repair_dept_id
         left join t_sb_position position on info.position_id = position.id
         where position.code like concat(#{keyword},'%')
     </select>
+
+    <select id="selectCountByPositionGroup" parameterType="java.lang.String"
+            resultType="java.util.Map">
+        select position.id, position.name, position.type, position.parent_id parentId, count(info.id) as num
+        from t_sb_position position
+        left join t_sb_info info on info.position_id=position.id
+        where position.type in (1, 2) and position.del_flag=0
+        group By position.id
+    </select>
+
 </mapper>

+ 10 - 1
platform-rest/src/main/java/com/platform/rest/controller/sb/SbPositionController.java

@@ -171,7 +171,16 @@ public class SbPositionController {
     public R selectCountByPosition(@PathVariable String code) {
         return new R<>(sbInfoService.selectCountByPosition(code));
     }
-
+    /**
+     * 查询厂区和车间分组数据
+     *
+     * @param code 位置code
+     * @return R
+     */
+    @GetMapping("/num/group")
+    public R selectCountByPositionGroup() {
+        return new R<>(sbInfoService.selectCountByPositionGroup());
+    }
     /**
      * 根据位置code查询设备数量,按照类别分组
      *

+ 5 - 0
platform-service/src/main/java/com/platform/service/sb/SbInfoService.java

@@ -159,6 +159,11 @@ public interface SbInfoService extends IBaseService<SbInfo, SbInfoDTO> {
      * @return :
      */
     int selectCountByPosition(String positionCode);
+    /**
+     * 查询所有厂区,车间的数据汇总
+     * @return :
+     */
+    List<Map<String, String>> selectCountByPositionGroup();
     /**
      * 查询所有某个位置的类型汇总数,包含下属位置的
      *

+ 29 - 0
platform-service/src/main/java/com/platform/service/sb/impl/SbInfoServiceImpl.java

@@ -967,6 +967,35 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
         return mapper.selectCountByPosition(positionCode);
     }
 
+    @Override
+    public List<Map<String, String>> selectCountByPositionGroup() {
+        List<Map<String, String>> sbInfoCountMapList = mapper.selectCountByPositionGroup();
+        if(sbInfoCountMapList != null) {
+            for (Map<String, String>  map: sbInfoCountMapList) {
+                // 汇总厂区的,将厂区下面的车间数量累加到上面
+                if ("1".equals(map.get("type"))) {
+                    String numStr = map.get("num");
+                    int num = 0;
+                    if(StringUtils.isEmpty(numStr)){
+                        num = 0;
+                    }else{
+                        num = Integer.valueOf(numStr);
+                    }
+                    for (Map<String, String>  child: sbInfoCountMapList) {
+                        if (map.get("id").equals(child.get("parentId"))) {
+                            String childNumStr = child.get("num");
+                            if(!StringUtils.isEmpty(numStr)){
+                                num = num + Integer.valueOf(childNumStr);
+                            }
+                        }
+                    }
+                    map.put("num", num + "");
+                }
+            }
+        }
+        return sbInfoCountMapList;
+    }
+
     @Override
     public List<Map<String, String>> selectCountByPositionGroupBySbType(String positionCode) {
         Weekend<SbPosition> weekend = new Weekend<>(SbPosition.class);