Commit bbe8cb75 authored by Fred's avatar Fred
parents 50541076 1c07f07b
package com.govmade.modules.system.controller; package com.govmade.modules.system.controller;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.govmade.common.utils.PageUtils;
import com.govmade.common.utils.R; import com.govmade.common.utils.R;
import com.govmade.common.validator.Assert; import com.govmade.common.validator.Assert;
import com.govmade.modules.basic.controller.AbstractController; import com.govmade.modules.basic.controller.AbstractController;
...@@ -34,10 +36,10 @@ public class AreaController extends AbstractController{ ...@@ -34,10 +36,10 @@ public class AreaController extends AbstractController{
/** /**
* 所有区划数据树结构 * 所有区划数据树结构
*/ */
@GetMapping("/allList") @GetMapping("/listTree")
public R allList() { public R listTree(@RequestParam Map<String, Object> params) {
List<AreaEntity> data = areaService.queryAll(); PageUtils page = areaService.queryPage(params);
return R.ok().put("data", data); return R.ok().put("page", page);
} }
/** /**
......
package com.govmade.modules.system.dao; package com.govmade.modules.system.dao;
import java.util.List;
import java.util.Set; import java.util.Set;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
...@@ -21,4 +22,9 @@ public interface AreaDao extends BaseMapper<AreaEntity> { ...@@ -21,4 +22,9 @@ public interface AreaDao extends BaseMapper<AreaEntity> {
* 批量删除或删除 * 批量删除或删除
*/ */
void deleteBatch(@Param("ids") Set<Long> ids); void deleteBatch(@Param("ids") Set<Long> ids);
/**
* 查询树形数据
*/
List<AreaEntity> listTree(@Param("name") String name);
} }
...@@ -21,6 +21,8 @@ public class AreaEntity extends BaseEntity<Long>{ ...@@ -21,6 +21,8 @@ public class AreaEntity extends BaseEntity<Long>{
private String name; //区划名称 private String name; //区划名称
private Long rootId; //根ID
private String code; //区划代码 private String code; //区划代码
private Integer level; //区划级别 private Integer level; //区划级别
...@@ -80,5 +82,12 @@ public class AreaEntity extends BaseEntity<Long>{ ...@@ -80,5 +82,12 @@ public class AreaEntity extends BaseEntity<Long>{
this.children = children; this.children = children;
} }
public Long getRootId() {
return rootId;
}
public void setRootId(Long rootId) {
this.rootId = rootId;
}
} }
package com.govmade.modules.system.service; package com.govmade.modules.system.service;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import com.baomidou.mybatisplus.service.IService; import com.baomidou.mybatisplus.service.IService;
import com.govmade.common.utils.PageUtils;
import com.govmade.modules.system.entity.AreaEntity; import com.govmade.modules.system.entity.AreaEntity;
/** /**
...@@ -17,7 +19,12 @@ public interface AreaService extends IService<AreaEntity>{ ...@@ -17,7 +19,12 @@ public interface AreaService extends IService<AreaEntity>{
/** /**
* 查询所有数据树结构 * 查询所有数据树结构
*/ */
List<AreaEntity> queryAll(); /*List<AreaEntity> queryAll();*/
/**
* 查看列表
*/
PageUtils queryPage(Map<String, Object> params);
/** /**
* 保存或修改行政区划 * 保存或修改行政区划
......
package com.govmade.modules.system.service.impl; package com.govmade.modules.system.service.impl;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.govmade.common.utils.PageUtils;
import com.govmade.modules.system.dao.AreaDao; import com.govmade.modules.system.dao.AreaDao;
import com.govmade.modules.system.entity.AreaEntity; import com.govmade.modules.system.entity.AreaEntity;
import com.govmade.modules.system.service.AreaService; import com.govmade.modules.system.service.AreaService;
...@@ -22,13 +25,15 @@ import com.govmade.modules.system.service.AreaService; ...@@ -22,13 +25,15 @@ import com.govmade.modules.system.service.AreaService;
public class AreaServiceImpl extends ServiceImpl<AreaDao,AreaEntity> implements AreaService{ public class AreaServiceImpl extends ServiceImpl<AreaDao,AreaEntity> implements AreaService{
@Override @Override
public List<AreaEntity> queryAll() { public PageUtils queryPage(Map<String, Object> params) {
List<AreaEntity> areaList = this.selectList(new EntityWrapper<AreaEntity>().eq("state", 1)); String name = (String) params.get("name");
List<AreaEntity> allList=this.baseMapper.listTree(name);
List<AreaEntity> list=buildAreaTree(allList,0);
Page<AreaEntity> page= new Page<AreaEntity>();
page.setRecords(list);
return new PageUtils(page);
List<AreaEntity> aTreeList = buildAreaTree(areaList, 0L);
return aTreeList;
} }
......
...@@ -10,4 +10,30 @@ ...@@ -10,4 +10,30 @@
#{id} #{id}
</foreach> </foreach>
</update> </update>
<!-- 查询树形数据-->
<select id="listTree" resultType="AreaEntity">
SELECT * FROM system_areas AS t
INNER JOIN (
SELECT id AS id2 FROM system_areas
WHERE
pid = 0
<if test="name != null and name !=''">
AND NAME LIKE CONCAT('%',#{name},'%')
</if>
LIMIT 10
) AS t2 ON t.root_id = t2.id2
UNION ALL(SELECT *, 0 AS id2 FROM system_areas
WHERE
pid = 0
<if test="name != null and name !=''">
AND NAME LIKE CONCAT('%',#{name},'%')
</if>
LIMIT 10
)
ORDER BY id
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment