Browse Source

调整管理后台类目的导出方式。

yuj 7 years ago
parent
commit
8184602fe1

+ 32 - 11
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/GoodsServiceImpl.java

@@ -4188,21 +4188,42 @@ public class GoodsServiceImpl implements GoodsService {
                         ids.add(kindHierarchical.getKindId());
                     }
                 }
-                if (CollectionUtils.isNotEmpty(ids)) {
-                    Map<String, List<Long>> map = new HashMap<>();
+                Map<String, List<Long>> map = null;
+                for (int i = 0; (i < 3) && CollectionUtils.isNotEmpty(ids); i++) {
+                    // i = 0 时表示 获取本级, = 1 时代表获取第二层,= 2 时代表获取顶层
+                    map = new HashMap<>();
                     map.put("ids", ids);
-                    List<Map<String, Object>> mapQuery = namedParameterJdbcTemplate.queryForList("select c.ki_id as id,p1.ki_name as secondName,p2.ki_name as firstName " +
-                            "from product$kind c left join product$kind p1 on c.ki_parentid = p1.ki_id " +
-                            "left join product$kind p2 on p1.ki_parentid = p2.ki_id where c.ki_id in (:ids)", map);
-                    for (KindHierarchicalCount hierarchical : kindHierarchicals) {
-                        if (hierarchical.getKindId() != null) {
-                            for (Map<String, Object> mapRest : mapQuery) {
-                                if (hierarchical.getKindId().equals(mapRest.get("id"))) {
-                                    hierarchical.setSecondKind(StringUtilB2C.getStr(mapRest.get("secondName")));
-                                    hierarchical.setFirstKind(StringUtilB2C.getStr(mapRest.get("firstName")));
+                    List<Map<String, Object>> mapQuery = namedParameterJdbcTemplate.queryForList("select c.ki_id as id, c.ki_name as name, c.ki_parentid as pid " +
+                            "from product$kind c where c.ki_id in (:ids)", map);
+                    ids = new ArrayList<>();
+                    for (Map<String, Object> mapRest : mapQuery) {
+                        Object id = mapRest.get("id");
+
+                        Object pid = mapRest.get("pid");
+                        if (pid != null) {
+                            ids.add(Long.valueOf(pid.toString()));
+                        }
+                        for (KindHierarchicalCount hierarchical : kindHierarchicals) {
+                            if (i == 0) {
+                                if (id.equals(hierarchical.getKindId())) {
+                                    if (pid != null) {
+                                        hierarchical.setSecondId(Long.valueOf(pid.toString()));
+                                    }
+                                }
+                            } else if (i == 1) {
+                                if (id.equals(hierarchical.getSecondId())) {
+                                    hierarchical.setSecondKind(StringUtilB2C.getStr(mapRest.get("name")));
+                                    if (pid != null) {
+                                        hierarchical.setFirstId(Long.valueOf(pid.toString()));
+                                    }
+                                }
+                            } else if (i == 2) {
+                                if (id.equals(hierarchical.getFirstId())) {
+                                    hierarchical.setFirstKind(StringUtilB2C.getStr(mapRest.get("name")));
                                 }
                             }
                         }
+
                     }
                 }
 

+ 26 - 0
src/main/java/com/uas/platform/b2c/prod/store/model/KindHierarchicalCount.java

@@ -38,6 +38,16 @@ public class KindHierarchicalCount {
      */
     private Long kindId;
 
+    /**
+     * 第二级类目id
+     */
+    private Long secondId;
+
+    /**
+     * 頂級id
+     */
+    private Long firstId;
+
     public String getFirstKind() {
         return firstKind;
     }
@@ -85,4 +95,20 @@ public class KindHierarchicalCount {
     public void setKindId(Long kindId) {
         this.kindId = kindId;
     }
+
+    public Long getSecondId() {
+        return secondId;
+    }
+
+    public void setSecondId(Long secondId) {
+        this.secondId = secondId;
+    }
+
+    public Long getFirstId() {
+        return firstId;
+    }
+
+    public void setFirstId(Long firstId) {
+        this.firstId = firstId;
+    }
 }