diff --git a/src/main/java/com/govmade/modules/system/controller/DictController.java b/src/main/java/com/govmade/modules/system/controller/DictController.java index abc588d152016b541253d3d01cb30c3347865c22..6412c86f167423e4cddc72e53137beffa7e08e4a 100644 --- a/src/main/java/com/govmade/modules/system/controller/DictController.java +++ b/src/main/java/com/govmade/modules/system/controller/DictController.java @@ -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(); + } } diff --git a/src/main/java/com/govmade/modules/system/controller/MenuController.java b/src/main/java/com/govmade/modules/system/controller/MenuController.java index 1ba3b578921f048ae6664a7aebaa9ed70584c079..796580e6206172841656d148d435343fc68a9feb 100644 --- a/src/main/java/com/govmade/modules/system/controller/MenuController.java +++ b/src/main/java/com/govmade/modules/system/controller/MenuController.java @@ -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); diff --git a/src/main/java/com/govmade/modules/system/dao/DictDao.java b/src/main/java/com/govmade/modules/system/dao/DictDao.java index 2f47b6de1d74e7631410c55c78442a045831710e..e4564054a0affca595b8fa5317586ff590460e28 100644 --- a/src/main/java/com/govmade/modules/system/dao/DictDao.java +++ b/src/main/java/com/govmade/modules/system/dao/DictDao.java @@ -1,6 +1,8 @@ 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); + } diff --git a/src/main/java/com/govmade/modules/system/entity/AreaEntity.java b/src/main/java/com/govmade/modules/system/entity/AreaEntity.java index b515fdaf213e64f60c6f5e73df4f2130ccf7d948..c31ede79e50fd0d4e33627dbd0d1d5a8a3f9ea15 100644 --- a/src/main/java/com/govmade/modules/system/entity/AreaEntity.java +++ b/src/main/java/com/govmade/modules/system/entity/AreaEntity.java @@ -32,8 +32,6 @@ public class AreaEntity extends BaseEntity<Long>{ @TableField(exist=false) private List<AreaEntity> children; - - public Long getPid() { return pid; } diff --git a/src/main/java/com/govmade/modules/system/entity/DictEntity.java b/src/main/java/com/govmade/modules/system/entity/DictEntity.java index 522148bfefac5634c904c427d69cfeaa68f7752a..6d68867058b687333f634b1473a1520e159b5ce6 100644 --- a/src/main/java/com/govmade/modules/system/entity/DictEntity.java +++ b/src/main/java/com/govmade/modules/system/entity/DictEntity.java @@ -1,5 +1,8 @@ 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; + } } diff --git a/src/main/java/com/govmade/modules/system/service/DictService.java b/src/main/java/com/govmade/modules/system/service/DictService.java index 90bd3ff6d47b1b961cdec9b2647cb006d1f4cc99..1d9159e50ee3cc65e4bf2dbb26a58c02777549c9 100644 --- a/src/main/java/com/govmade/modules/system/service/DictService.java +++ b/src/main/java/com/govmade/modules/system/service/DictService.java @@ -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); } diff --git a/src/main/java/com/govmade/modules/system/service/impl/DictServiceImpl.java b/src/main/java/com/govmade/modules/system/service/impl/DictServiceImpl.java index 2c6bbc5ac8442b80e9e8be3e26c75cc3070d5ccf..087b0dc3c2203cb24c18cd4d3c83687fdce2d118 100644 --- a/src/main/java/com/govmade/modules/system/service/impl/DictServiceImpl.java +++ b/src/main/java/com/govmade/modules/system/service/impl/DictServiceImpl.java @@ -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); + } } diff --git a/src/main/resources/mapper/system/DictDao.xml b/src/main/resources/mapper/system/DictDao.xml index 01598e967c0336c2d0e1a6584c33de46e379305a..7eadf89692e099894a63c2f50cb62b8f57549e2f 100644 --- a/src/main/resources/mapper/system/DictDao.xml +++ b/src/main/resources/mapper/system/DictDao.xml @@ -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