Commit 72ac9948 authored by 刘弈臻's avatar 刘弈臻

字典

parent e22b7f1c
......@@ -2,12 +2,20 @@ 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;
import org.springframework.web.bind.annotation.DeleteMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.govmade.common.utils.PageTreeUtils;
import com.govmade.common.utils.R;
import com.govmade.common.validator.Assert;
import com.govmade.modules.basic.controller.AbstractController;
import com.govmade.modules.system.entity.DictEntity;
import com.govmade.modules.system.service.DictService;
......@@ -37,5 +45,43 @@ public class DictController extends AbstractController {
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();
}
}
......@@ -45,7 +45,7 @@ public class MenuController extends AbstractController {
/**
* 保存或更新用户
* 保存或更新菜单
*/
@PostMapping("/save")
public R save(MenuEntity menu) {
......@@ -77,7 +77,7 @@ public class MenuController extends AbstractController {
* @return
*/
@DeleteMapping("/delete")
public R deleteArea(@RequestBody Set<Long> ids) {
public R deleteMenu(@RequestBody Set<Long> ids) {
Assert.isNull(ids, "删除项不能为空");
menuService.deleteBatch(ids);
......
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.Param;
......@@ -19,4 +21,15 @@ import com.govmade.modules.system.entity.DictEntity;
public interface DictDao extends BaseMapper<DictEntity> {
List<DictEntity> selectChilds(@Param("pValue") String pValue);
/**
* 批量删除或删除
*/
void deleteBatch(@Param("ids") Set<Long> ids);
/**
* 查询树形数据
*/
List<DictEntity> listTree(@Param("params") Map<String, Object> params);
}
......@@ -32,8 +32,6 @@ public class AreaEntity extends BaseEntity<Long>{
@TableField(exist=false)
private List<AreaEntity> children;
public Long getPid() {
return pid;
}
......
package com.govmade.modules.system.entity;
import java.util.List;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import com.govmade.modules.basic.entity.BaseEntity;
......@@ -20,12 +23,17 @@ public class DictEntity extends BaseEntity<Long> {
private String name; // 字典名
private String value; // 字典值
private Long rootId; //根Id
private Integer type; // 类型
private Integer weight; // 权重
private String remark; // 备注
@TableField(exist=false)
private List<DictEntity> children;
public Long getPid() {
return pid;
......@@ -49,6 +57,14 @@ public class DictEntity extends BaseEntity<Long> {
public void setValue(String value) {
this.value = value;
}
public Long getRootId() {
return rootId;
}
public void setRootId(Long rootId) {
this.rootId = rootId;
}
public Integer getType() {
......@@ -74,4 +90,12 @@ public class DictEntity extends BaseEntity<Long> {
public void setRemark(String remark) {
this.remark = remark;
}
public List<DictEntity> getChildren() {
return children;
}
public void setChildren(List<DictEntity> children) {
this.children = children;
}
}
......@@ -2,8 +2,10 @@ 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.PageTreeUtils;
import com.govmade.common.utils.PageUtils;
import com.govmade.modules.system.entity.DictEntity;
import com.govmade.modules.system.entity.UserEntity;
......@@ -17,10 +19,29 @@ import com.govmade.modules.system.entity.UserEntity;
*/
public interface DictService extends IService<DictEntity> {
PageUtils queryPage(Map<String, Object> params);
DictEntity queryOne(Map<String, Object> params);
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,12 +2,15 @@ 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.PageTreeUtils;
import com.govmade.common.utils.PageUtils;
import com.govmade.common.utils.Query;
import com.govmade.modules.system.dao.DictDao;
......@@ -26,12 +29,38 @@ import cn.hutool.core.util.StrUtil;
@Service("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());
return new PageUtils(page);
}
@Override
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
public DictEntity queryOne(Map<String, Object> params) {
......@@ -47,4 +76,24 @@ public class DictServiceImpl extends ServiceImpl<DictDao, DictEntity> implements
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);
}
}
......@@ -7,5 +7,38 @@
select value,name from
system_dicts where pid = (select id from system_dicts where value = #{pValue})
</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>
\ 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