浏览代码

编写用sql递归,查询树结构

fanxw 2 年之前
父节点
当前提交
3567a2e85c

+ 24 - 54
src/main/java/com/chinaitop/depot/basic/controller/BasicEnumController.java

@@ -5,7 +5,6 @@ import java.util.Date;
5 5
 import java.util.HashMap;
6 6
 import java.util.List;
7 7
 import java.util.Map;
8
-import java.util.Random;
9 8
 
10 9
 import javax.annotation.Resource;
11 10
 import javax.servlet.http.HttpServletRequest;
@@ -23,8 +22,6 @@ import com.chinaitop.depot.basic.model.BasicEnumExample.Criteria;
23 22
 import com.chinaitop.depot.basic.model.BasicEnumVo;
24 23
 import com.chinaitop.depot.basic.service.BasicEnumService;
25 24
 import com.chinaitop.depot.common.service.ImportServiceImpl;
26
-import com.chinaitop.depot.utils.RedisUtil;
27
-import com.chinaitop.utils.ParameterUtil;
28 25
 import com.fasterxml.jackson.databind.ObjectMapper;
29 26
 import com.github.pagehelper.PageHelper;
30 27
 import com.github.pagehelper.PageInfo;
@@ -54,13 +51,6 @@ public class BasicEnumController {
54 51
 	@Value("${web.upload-path}")
55 52
 	private String uploadPath;
56 53
 
57
-	/**
58
-	 * 查找数据字典大类信息
59
-	 * @param pageNum 页数
60
-	 * @param pageSize 每页显示的条数
61
-	 * @param enumName 字典数据名称
62
-	 * @return
63
-	 */
64 54
 	@RequestMapping(value="/getList", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
65 55
 	@ApiOperation(value="查询字典数据", notes = "查询字典数据列表,支持分页")
66 56
 	@ApiImplicitParams({
@@ -94,11 +84,6 @@ public class BasicEnumController {
94 84
 		return pageInfo;
95 85
 	}
96 86
 
97
-	/**
98
-	 * 根据编号查找数据字典大类信息
99
-	 * @param id 数据ID
100
-	 * @return
101
-	 */
102 87
 	@RequestMapping(value="/findByEnum", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.GET)
103 88
 	@ApiOperation(value="按ID查询字典数据", notes = "查询一条字典数据")
104 89
 	@ApiImplicitParams({
@@ -117,12 +102,7 @@ public class BasicEnumController {
117 102
 		}
118 103
 		return basicEnum;
119 104
 	}
120
-	
121
-	/**
122
-	 * 更新数据字典大类信息
123
-	 * @param enumJson 字典数据对象
124
-	 * @return
125
-	 */
105
+
126 106
 	@RequestMapping(value="/edit", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
127 107
 	@ApiOperation(value="更新字典数据", notes = "新增或修改数据字典")
128 108
 	@ApiImplicitParams({
@@ -150,12 +130,7 @@ public class BasicEnumController {
150 130
         }
151 131
 		return modelMap;
152 132
 	}
153
-	
154
-	/**
155
-	 * 按数据字典大类ID逻辑删除数据字典大类信息
156
-	 * @param id 数据ID
157
-	 * @return
158
-	 */
133
+
159 134
 	@RequestMapping(value="/remove", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
160 135
 	@ApiOperation(value="删除字典数据", notes="删除字典数据")
161 136
 	@ApiImplicitParams({
@@ -180,24 +155,14 @@ public class BasicEnumController {
180 155
         }
181 156
 		return modelMap;
182 157
 	}
183
-	
184
-	/**
185
-	 * 获取数据字典json树结构
186
-	 * @return
187
-	 * @throws Exception 
188
-	 */
158
+
189 159
 	@RequestMapping(value="/getTree", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.GET)
190 160
 	@ApiOperation(value="查询字典数据树", notes="查询字典数据树")
191 161
 	public List<BasicEnum> getTree() {
192 162
 		List<BasicEnum> list = enumService.queryByTree();
193 163
 		return list;
194 164
 	}
195
-	
196
-	/**
197
-	 * 枚举字典数据获取统一对外接口
198
-	 * @return
199
-	 * @throws Exception 
200
-	 */
165
+
201 166
 	@RequestMapping(value="/findEnumObj", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.GET)
202 167
 	@ApiOperation(value="获取枚举字典数据统一对外接口", notes="获取枚举字典数据统一对外接口")
203 168
 	public Map<String, Object> findEnumObj() throws Exception {
@@ -208,12 +173,7 @@ public class BasicEnumController {
208 173
 		map.put("enumMap", enumMap);
209 174
 		return map;
210 175
 	}
211
-	
212
-	/**
213
-	 * 根据id获取所有子节点
214
-	 * @param enumid	节点id
215
-	 * @return
216
-	 */
176
+
217 177
 	@RequestMapping(value="/getAllChildren", method=RequestMethod.GET)
218 178
 	@ApiOperation(value="根据id获取这个字典下所有子节点", notes="根据id获取这个字典下所有子节点")
219 179
 	@ApiImplicitParams({
@@ -299,15 +259,7 @@ public class BasicEnumController {
299 259
 		modelMap.put("enumId", enumId);
300 260
 		return modelMap;
301 261
 	}
302
-    
303
-    
304
-	/**
305
-     * 根据id获取这个字典下所有子节点(有固定格式数据需要)
306
-     * 
307
-     * @param request
308
-     * @param deviceTypeId 字典ID
309
-     * @return
310
-     */
262
+
311 263
     @RequestMapping(value="/getTreeTypeList", method=RequestMethod.GET)
312 264
     @ApiOperation(value="根据id获取这个字典下所有子节点(有固定格式数据需要)", notes="根据id获取这个字典下所有子节点(有固定格式数据需要)")
313 265
     @ApiImplicitParams({
@@ -347,5 +299,23 @@ public class BasicEnumController {
347 299
     	}
348 300
     	return modelMap;
349 301
     }
302
+    
303
+    @RequestMapping(value="/findConditionEnum", method=RequestMethod.GET)
304
+    @ApiOperation(value="根据id获取一个树结构", notes="")
305
+    @ApiImplicitParams({
306
+    	@ApiImplicitParam(name="parentId", value="字典父级ID", paramType="query"),
307
+    	@ApiImplicitParam(name="notParentId", value="要排除的父级ID", paramType="query"),
308
+    	@ApiImplicitParam(name="notEnumId", value="要排除的字典ID", paramType="query")
309
+    })
310
+    public List<BasicEnumVo> getTreeTypeList(Integer parentId, Integer notParentId, Integer notEnumId) {
311
+    	List<BasicEnumVo> voList = null;
312
+		try {
313
+			voList = enumService.findCondition(parentId, notParentId, notEnumId);
314
+		} catch (Exception e) {
315
+			e.printStackTrace();
316
+		}
317
+
318
+    	return voList;
319
+    }
350 320
 
351 321
 }

+ 7 - 0
src/main/java/com/chinaitop/depot/basic/mapper/BasicEnumMapper.java

@@ -1,6 +1,7 @@
1 1
 package com.chinaitop.depot.basic.mapper;
2 2
 
3 3
 import java.util.List;
4
+import java.util.Map;
4 5
 
5 6
 import org.apache.ibatis.annotations.Param;
6 7
 
@@ -30,4 +31,10 @@ public interface BasicEnumMapper {
30 31
 
31 32
     int updateByPrimaryKey(BasicEnum record);
32 33
 
34
+    /**
35
+     * 递归查询树结构
36
+     * @param paramMap
37
+     * @return
38
+     */
39
+    List<BasicEnum> findCondition(Map<String, Integer> paramMap);
33 40
 }

+ 22 - 0
src/main/java/com/chinaitop/depot/basic/mapper/BasicEnumMapper.xml

@@ -261,4 +261,26 @@
261 261
       delFlag = #{delflag,jdbcType=INTEGER}
262 262
     where enumId = #{enumid,jdbcType=INTEGER}
263 263
   </update>
264
+  <!-- 递归查询树结构 -->
265
+  <select id="findCondition" parameterType="java.util.Map" resultMap="BaseResultMap" >
266
+    select * from basic_enum
267
+	start with delflag=1 
268
+	<if test="parentid != null" >
269
+		and parentId = #{parentid,jdbcType=INTEGER}
270
+	</if>
271
+	<if test="notParentid != null">
272
+		and parentid != #{notParentid,jdbcType=INTEGER}
273
+	</if>
274
+	<if test="notEnumid != null">
275
+		and enumid != #{notEnumid,jdbcType=INTEGER}
276
+	</if>
277
+	connect by prior enumid=parentid and delflag=1
278
+	<if test="notParentid != null">
279
+		and parentid != #{notParentid,jdbcType=INTEGER}
280
+	</if>
281
+	<if test="notEnumid != null">
282
+		and enumid != #{notEnumid,jdbcType=INTEGER}
283
+	</if>
284
+	order by parentid,enumid
285
+  </select>
264 286
 </mapper>

+ 9 - 0
src/main/java/com/chinaitop/depot/basic/service/BasicEnumService.java

@@ -5,6 +5,7 @@ import java.util.Map;
5 5
 
6 6
 import com.chinaitop.depot.basic.model.BasicEnum;
7 7
 import com.chinaitop.depot.basic.model.BasicEnumExample;
8
+import com.chinaitop.depot.basic.model.BasicEnumVo;
8 9
 
9 10
 public interface BasicEnumService {
10 11
 
@@ -96,4 +97,12 @@ public interface BasicEnumService {
96 97
 	 */
97 98
 	public BasicEnum getBasicEnum(Integer parentid, String gbcode) throws Exception;
98 99
 
100
+	/**
101
+	 * 递归查询树结构
102
+	 * @param parentId 字典父级ID
103
+	 * @param notParentId 要排除的父级ID
104
+	 * @param notEnumId 要排除的字典ID
105
+	 * @return
106
+	 */
107
+    List<BasicEnumVo> findCondition(Integer parentId, Integer notParentId, Integer notEnumId);
99 108
 }

+ 27 - 8
src/main/java/com/chinaitop/depot/basic/service/impl/BasicEnumServiceImpl.java

@@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
14 14
 import com.chinaitop.depot.basic.mapper.BasicEnumMapper;
15 15
 import com.chinaitop.depot.basic.model.BasicEnum;
16 16
 import com.chinaitop.depot.basic.model.BasicEnumExample;
17
+import com.chinaitop.depot.basic.model.BasicEnumVo;
17 18
 import com.chinaitop.depot.basic.model.BasicEnumExample.Criteria;
18 19
 import com.chinaitop.depot.basic.service.BasicEnumService;
19 20
 
@@ -101,14 +102,7 @@ public class BasicEnumServiceImpl implements BasicEnumService {
101 102
 					children.add(be);
102 103
 				}
103 104
 			}
104
-		} if (planManage!=null && planManage.equals("1")) {//合同管理和通知单管理下的出库业务不让选择省级储备粮
105
-			for(BasicEnum be: list){
106
-				//遍历出父id等于参数的id,add进子节点集合  除去储备粮=3045的和父节点是储备粮的
107
-				if (be.getParentid().equals(parentId) && !be.getEnumid().equals(6877)) {
108
-					children.add(be);
109
-				}
110
-			}
111
-		}else {
105
+		} else {
112 106
 			for(BasicEnum be: list){
113 107
 				//遍历出父id等于参数的id,add进子节点集合  
114 108
 				if (be.getParentid().equals(parentId)) {
@@ -275,5 +269,30 @@ public class BasicEnumServiceImpl implements BasicEnumService {
275 269
 		return emm;
276 270
 	}
277 271
 
272
+	@Override
273
+	public List<BasicEnumVo> findCondition(Integer parentId, Integer notParentId, Integer notEnumId) {
274
+		Map<String, Integer> param_map = new HashMap<>();
275
+		param_map.put("parentid", parentId);
276
+		if (null != notParentId) {
277
+			param_map.put("notParentid", notParentId);
278
+		}
279
+		if (null != notEnumId) {
280
+			param_map.put("notEnumid", notEnumId);
281
+		}
282
+		List<BasicEnum> list = enumMapper.findCondition(param_map);
283
+		List<BasicEnumVo> voList = new ArrayList<BasicEnumVo>();
284
+    	for (BasicEnum basicEnum : list) {
285
+    		BasicEnumVo basicEnumVo = new BasicEnumVo();
286
+    		basicEnumVo.setId(basicEnum.getEnumid());
287
+    		basicEnumVo.setName(basicEnum.getEnumname());
288
+    		basicEnumVo.setParentid(basicEnum.getParentid());
289
+    		basicEnumVo.setEnumcode(basicEnum.getEnumcode());
290
+    		basicEnumVo.setGbcode(basicEnum.getGbcode());
291
+    		voList.add(basicEnumVo);
292
+    	}
293
+
294
+        return voList;
295
+	}
296
+
278 297
 	
279 298
 }