Commit bbe8cb75 authored by Fred's avatar Fred
parents 50541076 1c07f07b
package com.govmade.modules.system.controller;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.govmade.common.utils.PageUtils;
import com.govmade.common.utils.R;
import com.govmade.common.validator.Assert;
import com.govmade.modules.basic.controller.AbstractController;
......@@ -34,10 +36,10 @@ public class AreaController extends AbstractController{
/**
* 所有区划数据树结构
*/
@GetMapping("/allList")
public R allList() {
List<AreaEntity> data = areaService.queryAll();
return R.ok().put("data", data);
@GetMapping("/listTree")
public R listTree(@RequestParam Map<String, Object> params) {
PageUtils page = areaService.queryPage(params);
return R.ok().put("page", page);
}
/**
......
package com.govmade.modules.system.dao;
import java.util.List;
import java.util.Set;
import org.apache.ibatis.annotations.Mapper;
......@@ -21,4 +22,9 @@ public interface AreaDao extends BaseMapper<AreaEntity> {
* 批量删除或删除
*/
void deleteBatch(@Param("ids") Set<Long> ids);
/**
* 查询树形数据
*/
List<AreaEntity> listTree(@Param("name") String name);
}
......@@ -21,6 +21,8 @@ public class AreaEntity extends BaseEntity<Long>{
private String name; //区划名称
private Long rootId; //根ID
private String code; //区划代码
private Integer level; //区划级别
......@@ -79,6 +81,13 @@ public class AreaEntity extends BaseEntity<Long>{
public void setChildren(List<AreaEntity> children) {
this.children = children;
}
public Long getRootId() {
return rootId;
}
public void setRootId(Long rootId) {
this.rootId = rootId;
}
}
package com.govmade.modules.system.service;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.baomidou.mybatisplus.service.IService;
import com.govmade.common.utils.PageUtils;
import com.govmade.modules.system.entity.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;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.govmade.common.utils.PageUtils;
import com.govmade.modules.system.dao.AreaDao;
import com.govmade.modules.system.entity.AreaEntity;
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{
@Override
public List<AreaEntity> queryAll() {
public PageUtils queryPage(Map<String, Object> params) {
List<AreaEntity> areaList = this.selectList(new EntityWrapper<AreaEntity>().eq("state", 1));
List<AreaEntity> aTreeList = buildAreaTree(areaList, 0L);
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);
return aTreeList;
}
......
......@@ -10,4 +10,30 @@
#{id}
</foreach>
</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>
\ 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