Commit 0fabd1b1 authored by Fred's avatar Fred

地区树,数据变更

parents 31ad8778 72ac9948
package com.govmade.common.utils;
import java.io.Serializable;
import java.util.List;
/**
* 树形数据分页工具类
*
* @author 刘弈臻
* @date 2018年8月14日
*/
public class PageTreeUtils implements Serializable{
private static final long serialVersionUID = 1L;
private int totalCount; // 总记录数
private int pageSize; // 每页记录数
private int totalPage; // 总页数
private int currPage; // 当前页数
private List<?> list; // 列表数据
/**
* 分页
*
* @param list
* 列表数据
* @param totalCount
* 总记录数
* @param pageSize
* 每页记录数
* @param currPage
* 当前页数
*/
public PageTreeUtils(List<?> list, int totalCount, int pageSize, int currPage) {
this.list = list;
this.totalCount = totalCount;
this.pageSize = pageSize;
this.currPage = currPage;
this.totalPage = (int) Math.ceil((double) totalCount / pageSize);
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getCurrPage() {
return currPage;
}
public void setCurrPage(int currPage) {
this.currPage = currPage;
}
public List<?> getList() {
return list;
}
public void setList(List<?> list) {
this.list = list;
}
}
...@@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
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.PageTreeUtils;
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;
...@@ -38,7 +38,7 @@ public class AreaController extends AbstractController{ ...@@ -38,7 +38,7 @@ public class AreaController extends AbstractController{
*/ */
@GetMapping("/listTree") @GetMapping("/listTree")
public R listTree(@RequestParam Map<String, Object> params) { public R listTree(@RequestParam Map<String, Object> params) {
PageUtils page = areaService.queryPage(params); PageTreeUtils page = areaService.queryPage(params);
return R.ok().put("page", page); return R.ok().put("page", page);
} }
......
...@@ -75,7 +75,7 @@ public class DepartController extends AbstractController{ ...@@ -75,7 +75,7 @@ public class DepartController extends AbstractController{
if(this.userService.userCount(depart.getId())>0) { if(this.userService.userCount(depart.getId())>0) {
return R.error("选中部门下有用户!!"); return R.error("选中部门下有用户!!");
} }
departService.deleteBatch(depart); departService.deleteDepart(depart);
return R.ok(); return R.ok();
} }
......
...@@ -2,12 +2,20 @@ package com.govmade.modules.system.controller; ...@@ -2,12 +2,20 @@ package com.govmade.modules.system.controller;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.govmade.common.utils.PageTreeUtils;
import com.govmade.common.utils.R; import com.govmade.common.utils.R;
import com.govmade.common.validator.Assert;
import com.govmade.modules.basic.controller.AbstractController; import com.govmade.modules.basic.controller.AbstractController;
import com.govmade.modules.system.entity.DictEntity; import com.govmade.modules.system.entity.DictEntity;
import com.govmade.modules.system.service.DictService; import com.govmade.modules.system.service.DictService;
...@@ -38,4 +46,42 @@ public class DictController extends AbstractController { ...@@ -38,4 +46,42 @@ public class DictController extends AbstractController {
return R.ok().put("childs", dictList); return R.ok().put("childs", dictList);
} }
/**
* 所有字典数据树结构
*/
@GetMapping("/listTree")
public R listTree(@RequestParam Map<String, Object> params) {
PageTreeUtils page = dictService.queryPage(params);
return R.ok().put("page", page);
}
/**
* 保存或更新字典
*/
@PostMapping("/save")
public R save(DictEntity dict) {
if (null == dict.getId()) {
if (this.dictService.checkDict(dict.getName()) > 0) {
return R.error(dict.getName() + " 已存在!");
}
}
dictService.save(dict);
return R.ok();
}
/**
* 批量删除字典
*
* @param ids
* @return
*/
@DeleteMapping("/delete")
public R deleteDict(@RequestBody Set<Long> ids) {
Assert.isNull(ids, "删除项不能为空");
dictService.deleteBatch(ids);
return R.ok();
}
} }
package com.govmade.modules.system.controller; package com.govmade.modules.system.controller;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.govmade.common.utils.PageTreeUtils;
import com.govmade.common.utils.R; import com.govmade.common.utils.R;
import com.govmade.common.validator.Assert;
import com.govmade.modules.basic.controller.AbstractController; import com.govmade.modules.basic.controller.AbstractController;
import com.govmade.modules.system.entity.MenuEntity; import com.govmade.modules.system.entity.MenuEntity;
import com.govmade.modules.system.service.MenuService; import com.govmade.modules.system.service.MenuService;
...@@ -28,17 +35,17 @@ public class MenuController extends AbstractController { ...@@ -28,17 +35,17 @@ public class MenuController extends AbstractController {
private MenuService menuService; private MenuService menuService;
/** /**
* 菜单列表 * 所有菜单数据树结构
*/ */
@GetMapping("/list") @GetMapping("/listTree")
public R list(Map<String, Object> params) { public R listTree(@RequestParam Map<String, Object> params) {
PageTreeUtils page = menuService.queryPage(params);
menuService.queryPage(params); return R.ok().put("page", page);
return null;
} }
/** /**
* 保存或更新用户 * 保存或更新菜单
*/ */
@PostMapping("/save") @PostMapping("/save")
public R save(MenuEntity menu) { public R save(MenuEntity menu) {
...@@ -48,6 +55,7 @@ public class MenuController extends AbstractController { ...@@ -48,6 +55,7 @@ public class MenuController extends AbstractController {
return R.error(menu.getName() + " 已存在!"); return R.error(menu.getName() + " 已存在!");
} }
} }
menuService.save(menu);
return R.ok(); return R.ok();
} }
...@@ -61,4 +69,20 @@ public class MenuController extends AbstractController { ...@@ -61,4 +69,20 @@ public class MenuController extends AbstractController {
public R info(@PathVariable("id") Long id) { public R info(@PathVariable("id") Long id) {
return R.ok().put("menu", menuService.queryById(id)); return R.ok().put("menu", menuService.queryById(id));
} }
/**
* 批量删除菜单
*
* @param ids
* @return
*/
@DeleteMapping("/delete")
public R deleteMenu(@RequestBody Set<Long> ids) {
Assert.isNull(ids, "删除项不能为空");
menuService.deleteBatch(ids);
return R.ok();
}
} }
package com.govmade.modules.system.dao; package com.govmade.modules.system.dao;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
...@@ -26,5 +27,5 @@ public interface AreaDao extends BaseMapper<AreaEntity> { ...@@ -26,5 +27,5 @@ public interface AreaDao extends BaseMapper<AreaEntity> {
/** /**
* 查询树形数据 * 查询树形数据
*/ */
List<AreaEntity> listTree(@Param("name") String name); List<AreaEntity> listTree(@Param("params") Map<String, Object> params);
} }
package com.govmade.modules.system.dao; package com.govmade.modules.system.dao;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -19,4 +21,15 @@ import com.govmade.modules.system.entity.DictEntity; ...@@ -19,4 +21,15 @@ import com.govmade.modules.system.entity.DictEntity;
public interface DictDao extends BaseMapper<DictEntity> { public interface DictDao extends BaseMapper<DictEntity> {
List<DictEntity> selectChilds(@Param("pValue") String pValue); List<DictEntity> selectChilds(@Param("pValue") String pValue);
/**
* 批量删除或删除
*/
void deleteBatch(@Param("ids") Set<Long> ids);
/**
* 查询树形数据
*/
List<DictEntity> listTree(@Param("params") Map<String, Object> params);
} }
package com.govmade.modules.system.dao; package com.govmade.modules.system.dao;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.mapper.BaseMapper; import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.govmade.modules.system.entity.MenuEntity; import com.govmade.modules.system.entity.MenuEntity;
...@@ -15,4 +21,14 @@ import com.govmade.modules.system.entity.MenuEntity; ...@@ -15,4 +21,14 @@ import com.govmade.modules.system.entity.MenuEntity;
@Mapper @Mapper
public interface MenuDao extends BaseMapper<MenuEntity> { public interface MenuDao extends BaseMapper<MenuEntity> {
/**
* 批量删除或删除
*/
void deleteBatch(@Param("ids") Set<Long> ids);
/**
* 查询树形数据
*/
List<MenuEntity> listTree(@Param("params") Map<String, Object> params);
} }
package com.govmade.modules.system.entity; package com.govmade.modules.system.entity;
import java.util.List;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.annotations.TableName;
import com.govmade.modules.basic.entity.BaseEntity; import com.govmade.modules.basic.entity.BaseEntity;
...@@ -21,12 +24,17 @@ public class DictEntity extends BaseEntity<Long> { ...@@ -21,12 +24,17 @@ public class DictEntity extends BaseEntity<Long> {
private String value; // 字典值 private String value; // 字典值
private Long rootId; //根Id
private Integer type; // 类型 private Integer type; // 类型
private Integer weight; // 权重 private Integer weight; // 权重
private String remark; // 备注 private String remark; // 备注
@TableField(exist=false)
private List<DictEntity> children;
public Long getPid() { public Long getPid() {
return pid; return pid;
} }
...@@ -51,6 +59,14 @@ public class DictEntity extends BaseEntity<Long> { ...@@ -51,6 +59,14 @@ public class DictEntity extends BaseEntity<Long> {
this.value = value; this.value = value;
} }
public Long getRootId() {
return rootId;
}
public void setRootId(Long rootId) {
this.rootId = rootId;
}
public Integer getType() { public Integer getType() {
return type; return type;
} }
...@@ -74,4 +90,12 @@ public class DictEntity extends BaseEntity<Long> { ...@@ -74,4 +90,12 @@ public class DictEntity extends BaseEntity<Long> {
public void setRemark(String remark) { public void setRemark(String remark) {
this.remark = remark; this.remark = remark;
} }
public List<DictEntity> getChildren() {
return children;
}
public void setChildren(List<DictEntity> children) {
this.children = children;
}
} }
package com.govmade.modules.system.entity; package com.govmade.modules.system.entity;
import java.util.List;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.annotations.TableName;
import com.govmade.modules.basic.entity.BaseEntity; import com.govmade.modules.basic.entity.BaseEntity;
...@@ -33,6 +36,9 @@ public class MenuEntity extends BaseEntity<Long> { ...@@ -33,6 +36,9 @@ public class MenuEntity extends BaseEntity<Long> {
private Long weight; private Long weight;
@TableField(exist=false)
private List<MenuEntity> children;
public Long getPid() { public Long getPid() {
return pid; return pid;
} }
...@@ -104,4 +110,13 @@ public class MenuEntity extends BaseEntity<Long> { ...@@ -104,4 +110,13 @@ public class MenuEntity extends BaseEntity<Long> {
public void setWeight(Long weight) { public void setWeight(Long weight) {
this.weight = weight; this.weight = weight;
} }
public List<MenuEntity> getChildren() {
return children;
}
public void setChildren(List<MenuEntity> children) {
this.children = children;
}
} }
package com.govmade.modules.system.service; package com.govmade.modules.system.service;
import java.util.List;
import java.util.Map; 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.common.utils.PageTreeUtils;
import com.govmade.modules.system.entity.AreaEntity; import com.govmade.modules.system.entity.AreaEntity;
/** /**
...@@ -24,7 +23,7 @@ public interface AreaService extends IService<AreaEntity>{ ...@@ -24,7 +23,7 @@ public interface AreaService extends IService<AreaEntity>{
/** /**
* 查看列表 * 查看列表
*/ */
PageUtils queryPage(Map<String, Object> params); PageTreeUtils queryPage(Map<String, Object> params);
/** /**
* 保存或修改行政区划 * 保存或修改行政区划
......
...@@ -28,7 +28,7 @@ public interface DepartService extends IService<DepartEntity>{ ...@@ -28,7 +28,7 @@ public interface DepartService extends IService<DepartEntity>{
/** /**
* 删除部门 * 删除部门
*/ */
void deleteBatch(DepartEntity depart); void deleteDepart(DepartEntity depart);
/** /**
......
...@@ -2,8 +2,10 @@ package com.govmade.modules.system.service; ...@@ -2,8 +2,10 @@ package com.govmade.modules.system.service;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import com.baomidou.mybatisplus.service.IService; import com.baomidou.mybatisplus.service.IService;
import com.govmade.common.utils.PageTreeUtils;
import com.govmade.common.utils.PageUtils; import com.govmade.common.utils.PageUtils;
import com.govmade.modules.system.entity.DictEntity; import com.govmade.modules.system.entity.DictEntity;
import com.govmade.modules.system.entity.UserEntity; import com.govmade.modules.system.entity.UserEntity;
...@@ -17,10 +19,29 @@ import com.govmade.modules.system.entity.UserEntity; ...@@ -17,10 +19,29 @@ import com.govmade.modules.system.entity.UserEntity;
*/ */
public interface DictService extends IService<DictEntity> { public interface DictService extends IService<DictEntity> {
PageUtils queryPage(Map<String, Object> params);
DictEntity queryOne(Map<String, Object> params); DictEntity queryOne(Map<String, Object> params);
List<DictEntity> queryChilds(String value); List<DictEntity> queryChilds(String value);
/**
* 树机构列表
*/
PageTreeUtils queryPage(Map<String, Object> params);
/**
* 保存或修改字典
*/
void save(DictEntity dict);
/**
* 检测是否重名
*/
Integer checkDict(String name);
DictEntity queryById(Long id);
/**
* 删除字典
*/
void deleteBatch(Set<Long> ids);
} }
...@@ -2,8 +2,10 @@ package com.govmade.modules.system.service; ...@@ -2,8 +2,10 @@ package com.govmade.modules.system.service;
import java.util.Map; import java.util.Map;
import java.util.Set;
import com.baomidou.mybatisplus.service.IService; import com.baomidou.mybatisplus.service.IService;
import com.govmade.common.utils.PageTreeUtils;
import com.govmade.common.utils.PageUtils; import com.govmade.common.utils.PageUtils;
import com.govmade.modules.system.entity.MenuEntity; import com.govmade.modules.system.entity.MenuEntity;
...@@ -17,7 +19,7 @@ import com.govmade.modules.system.entity.MenuEntity; ...@@ -17,7 +19,7 @@ import com.govmade.modules.system.entity.MenuEntity;
public interface MenuService extends IService<MenuEntity> { public interface MenuService extends IService<MenuEntity> {
PageUtils queryPage(Map<String, Object> params); PageTreeUtils queryPage(Map<String, Object> params);
/** /**
* 保存或修改菜单 * 保存或修改菜单
...@@ -30,4 +32,9 @@ public interface MenuService extends IService<MenuEntity> { ...@@ -30,4 +32,9 @@ public interface MenuService extends IService<MenuEntity> {
Integer checkMenu(String name); Integer checkMenu(String name);
MenuEntity queryById(Long id); MenuEntity queryById(Long id);
/**
* 删除菜单
*/
void deleteBatch(Set<Long> ids);
} }
...@@ -7,14 +7,15 @@ import java.util.Set; ...@@ -7,14 +7,15 @@ 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.common.utils.PageTreeUtils;
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;
import cn.hutool.core.util.StrUtil;
/** /**
* 系统管理 - 行政区划设置 * 系统管理 - 行政区划设置
* *
...@@ -22,36 +23,40 @@ import com.govmade.modules.system.service.AreaService; ...@@ -22,36 +23,40 @@ import com.govmade.modules.system.service.AreaService;
* @date 2018年8月9日 * @date 2018年8月9日
*/ */
@Service("AreaService") @Service("AreaService")
public class AreaServiceImpl extends ServiceImpl<AreaDao,AreaEntity> implements AreaService{ public class AreaServiceImpl extends ServiceImpl<AreaDao, AreaEntity> implements AreaService {
@Override @Override
public PageUtils queryPage(Map<String, Object> params) { public PageTreeUtils queryPage(Map<String, Object> params) {
String name = (String) params.get("name"); String name = (String) params.get("name");
List<AreaEntity> list=buildAreaTree(this.baseMapper.listTree(name),0);
Page<AreaEntity> page= new Page<AreaEntity>();
page.setRecords(list);
return new PageUtils(page);
int currPage = Integer.parseInt((String) params.get("currPage"));
int pageSize = Integer.parseInt((String) params.get("pageSize"));
int start = (currPage - 1) * pageSize;
params.put("name2", name);
params.put("pageSize2", pageSize);
params.put("start", start);
List<AreaEntity> allList = this.baseMapper.listTree(params);
List<AreaEntity> list = buildAreaTree(allList, 0L);
int totalCount = super.selectCount(new EntityWrapper<AreaEntity>().like(StrUtil.isNotBlank(name), "name", name)
.eq("pid", 0).eq("state", 1));
return new PageTreeUtils(list, totalCount, pageSize, currPage);
} }
/**
/** * 递归方法
*递归方法
*/ */
private List<AreaEntity> buildAreaTree(List<AreaEntity> list, long id) { private List<AreaEntity> buildAreaTree(List<AreaEntity> areaList, Long id) {
List<AreaEntity> aList = Lists.newArrayList(); List<AreaEntity> aList = Lists.newArrayList();
for (AreaEntity a : list) { for (AreaEntity area : areaList) {
if (id == a.getPid()) { if (id == area.getPid()) {
a.setChildren(buildAreaTree(list, a.getId())); area.setChildren(buildAreaTree(areaList, area.getId()));
aList.add(a); aList.add(area);
} }
} }
return aList; return aList;
} }
@Override @Override
public void save(AreaEntity area) { public void save(AreaEntity area) {
super.insertOrUpdate(area); super.insertOrUpdate(area);
...@@ -64,7 +69,7 @@ public class AreaServiceImpl extends ServiceImpl<AreaDao,AreaEntity> implements ...@@ -64,7 +69,7 @@ public class AreaServiceImpl extends ServiceImpl<AreaDao,AreaEntity> implements
@Override @Override
public Integer checkArea(String name) { public Integer checkArea(String name) {
return super.selectCount(new EntityWrapper<AreaEntity>().eq("name",name)); return super.selectCount(new EntityWrapper<AreaEntity>().eq("name", name));
} }
} }
...@@ -44,7 +44,7 @@ public class DepartServiceImpl extends ServiceImpl<DepartDao,DepartEntity> imple ...@@ -44,7 +44,7 @@ public class DepartServiceImpl extends ServiceImpl<DepartDao,DepartEntity> imple
} }
@Override @Override
public void deleteBatch(DepartEntity depart) { public void deleteDepart(DepartEntity depart) {
depart.setState(Constant.STATE_DELETE); depart.setState(Constant.STATE_DELETE);
super.updateById(depart); super.updateById(depart);
} }
......
...@@ -2,12 +2,15 @@ package com.govmade.modules.system.service.impl; ...@@ -2,12 +2,15 @@ package com.govmade.modules.system.service.impl;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
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.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.govmade.common.utils.PageTreeUtils;
import com.govmade.common.utils.PageUtils; import com.govmade.common.utils.PageUtils;
import com.govmade.common.utils.Query; import com.govmade.common.utils.Query;
import com.govmade.modules.system.dao.DictDao; import com.govmade.modules.system.dao.DictDao;
...@@ -26,11 +29,37 @@ import cn.hutool.core.util.StrUtil; ...@@ -26,11 +29,37 @@ import cn.hutool.core.util.StrUtil;
@Service("DictService") @Service("DictService")
public class DictServiceImpl extends ServiceImpl<DictDao, DictEntity> implements DictService { public class DictServiceImpl extends ServiceImpl<DictDao, DictEntity> implements DictService {
@Override
public PageUtils queryPage(Map<String, Object> params) {
Page<DictEntity> page = this.selectPage(new Query<DictEntity>(params).getPage()); @Override
return new PageUtils(page); public PageTreeUtils queryPage(Map<String, Object> params) {
String name = (String) params.get("name");
int currPage = Integer.parseInt((String) params.get("currPage"));
int pageSize = Integer.parseInt((String) params.get("pageSize"));
int start = (currPage-1)*pageSize;
params.put("name2", name);
params.put("pageSize2", pageSize);
params.put("start", start);
List<DictEntity> allList=this.baseMapper.listTree(params);
List<DictEntity> list=buildAreaTree(allList,0L);
int totalCount = super.selectCount(new EntityWrapper<DictEntity>().like(StrUtil.isNotBlank(name), "name", name)
.eq("pid", 0).eq("state", 1));
return new PageTreeUtils(list,totalCount,pageSize,currPage);
}
/**
*递归方法
*/
private List<DictEntity> buildAreaTree(List<DictEntity> dictList, Long id) {
List<DictEntity> dList = Lists.newArrayList();
for (DictEntity dict : dictList) {
if (id == dict.getPid()) {
dict.setChildren(buildAreaTree(dictList, dict.getId()));
dList.add(dict);
}
}
return dList;
} }
@Override @Override
...@@ -47,4 +76,24 @@ public class DictServiceImpl extends ServiceImpl<DictDao, DictEntity> implements ...@@ -47,4 +76,24 @@ public class DictServiceImpl extends ServiceImpl<DictDao, DictEntity> implements
return childs; return childs;
} }
@Override
public void save(DictEntity dict) {
super.insertOrUpdate(dict);
}
@Override
public void deleteBatch(Set<Long> ids) {
this.baseMapper.deleteBatch(ids);
}
@Override
public Integer checkDict(String name) {
return super.selectCount(new EntityWrapper<DictEntity>().eq("name",name));
}
@Override
public DictEntity queryById(Long id) {
return super.selectById(id);
}
} }
...@@ -2,16 +2,21 @@ package com.govmade.modules.system.service.impl; ...@@ -2,16 +2,21 @@ package com.govmade.modules.system.service.impl;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
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.service.impl.ServiceImpl; import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.govmade.common.utils.PageTreeUtils;
import com.govmade.common.utils.PageUtils; import com.govmade.common.utils.PageUtils;
import com.govmade.modules.system.dao.MenuDao; import com.govmade.modules.system.dao.MenuDao;
import com.govmade.modules.system.entity.MenuEntity; import com.govmade.modules.system.entity.MenuEntity;
import com.govmade.modules.system.service.MenuService; import com.govmade.modules.system.service.MenuService;
import cn.hutool.core.util.StrUtil;
/** /**
* 系统管理 - 菜单设置 * 系统管理 - 菜单设置
* *
...@@ -24,10 +29,35 @@ public class MenuServiceImpl extends ServiceImpl<MenuDao, MenuEntity> implements ...@@ -24,10 +29,35 @@ public class MenuServiceImpl extends ServiceImpl<MenuDao, MenuEntity> implements
@Override @Override
public PageUtils queryPage(Map<String, Object> params) { public PageTreeUtils queryPage(Map<String, Object> params) {
// TODO Auto-generated method stub String name = (String) params.get("name");
//this.baseMapper.selectPage(); int currPage = Integer.parseInt((String) params.get("currPage"));
return null; int pageSize = Integer.parseInt((String) params.get("pageSize"));
int start = (currPage-1)*pageSize;
params.put("name2", name);
params.put("pageSize2", pageSize);
params.put("start", start);
List<MenuEntity> allList=this.baseMapper.listTree(params);
List<MenuEntity> list=buildAreaTree(allList,0L);
int totalCount = super.selectCount(new EntityWrapper<MenuEntity>().like(StrUtil.isNotBlank(name), "name", name)
.eq("pid", 0).eq("state", 1));
return new PageTreeUtils(list,totalCount,pageSize,currPage);
}
/**
*递归方法
*/
private List<MenuEntity> buildAreaTree(List<MenuEntity> menuList, Long id) {
List<MenuEntity> mList = Lists.newArrayList();
for (MenuEntity menu : menuList) {
if (id == menu.getPid()) {
menu.setChildren(buildAreaTree(menuList, menu.getId()));
mList.add(menu);
}
}
return mList;
} }
/** /**
...@@ -57,4 +87,9 @@ public class MenuServiceImpl extends ServiceImpl<MenuDao, MenuEntity> implements ...@@ -57,4 +87,9 @@ public class MenuServiceImpl extends ServiceImpl<MenuDao, MenuEntity> implements
return super.selectById(id); return super.selectById(id);
} }
@Override
public void deleteBatch(Set<Long> ids) {
this.baseMapper.deleteBatch(ids);
}
} }
...@@ -19,21 +19,22 @@ ...@@ -19,21 +19,22 @@
SELECT id AS id2 FROM system_areas SELECT id AS id2 FROM system_areas
WHERE WHERE
pid = 0 pid = 0
<if test="name != null and name !=''"> AND state =1
AND NAME LIKE CONCAT('%',#{name},'%') <if test="params.name2 != null and params.name2 !=''">
AND NAME LIKE CONCAT('%',#{params.name2},'%')
</if> </if>
LIMIT #{params.start},#{params.pageSize2}
LIMIT 10 ) AS t2 ON t.root_id = t2.id2 AND t.state=1
) AS t2 ON t.root_id = t2.id2
UNION ALL(SELECT *, 0 AS id2 FROM system_areas UNION ALL(SELECT *, 0 AS id2 FROM system_areas
WHERE WHERE
pid = 0 pid = 0
<if test="name != null and name !=''"> AND state =1
AND NAME LIKE CONCAT('%',#{name},'%') <if test="params.name2 != null and params.name2 !=''">
AND NAME LIKE CONCAT('%',#{params.name2},'%')
</if> </if>
LIMIT 10 LIMIT #{params.start},#{params.pageSize2}
) )
ORDER BY id ORDER BY id
</select> </select>
</mapper> </mapper>
\ No newline at end of file
...@@ -8,4 +8,37 @@ ...@@ -8,4 +8,37 @@
system_dicts where pid = (select id from system_dicts where value = #{pValue}) system_dicts where pid = (select id from system_dicts where value = #{pValue})
</select> </select>
<!-- 批量删除 -->
<update id="deleteBatch">
UPDATE system_dicts SET state =${@com.govmade.common.utils.Constant@STATE_DELETE} WHERE id IN
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</update>
<!-- 查询树形数据-->
<select id="listTree" resultType="DictEntity">
SELECT * FROM system_dicts AS t
INNER JOIN (
SELECT id AS id2 FROM system_dicts
WHERE
pid = 0
AND state =1
<if test="params.name2 != null and params.name2 !=''">
AND NAME LIKE CONCAT('%',#{params.name2},'%')
</if>
LIMIT #{params.start},#{params.pageSize2}
) AS t2 ON t.root_id = t2.id2 AND t.state=1
UNION ALL(SELECT *, 0 AS id2 FROM system_dicts
WHERE
pid = 0
AND state =1
<if test="params.name2 != null and params.name2 !=''">
AND NAME LIKE CONCAT('%',#{params.name2},'%')
</if>
LIMIT #{params.start},#{params.pageSize2}
)
ORDER BY id
</select>
</mapper> </mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.govmade.modules.system.dao.MenuDao">
<!-- 批量删除 -->
<update id="deleteBatch">
UPDATE system_menus SET state =${@com.govmade.common.utils.Constant@STATE_DELETE} WHERE id IN
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</update>
<!-- 查询树形数据-->
<select id="listTree" resultType="MenuEntity">
SELECT * FROM system_menus AS t
INNER JOIN (
SELECT id AS id2 FROM system_menus
WHERE
pid = 0
AND state =1
<if test="params.name2 != null and params.name2 !=''">
AND NAME LIKE CONCAT('%',#{params.name2},'%')
</if>
LIMIT #{params.start},#{params.pageSize2}
) AS t2 ON t.root_id = t2.id2 AND t.state=1
UNION ALL(SELECT *, 0 AS id2 FROM system_menus
WHERE
pid = 0
AND state =1
<if test="params.name2 != null and params.name2 !=''">
AND NAME LIKE CONCAT('%',#{params.name2},'%')
</if>
LIMIT #{params.start},#{params.pageSize2}
)
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