8 changed files with 252 additions and 0 deletions
-
21archives/pom.xml
-
34archives/src/main/java/com/storeroom/modules/dictionary/controller/DictrionaryController.java
-
49archives/src/main/java/com/storeroom/modules/dictionary/domain/Dictionary.java
-
55archives/src/main/java/com/storeroom/modules/dictionary/domain/vo/DictionaryVO.java
-
14archives/src/main/java/com/storeroom/modules/dictionary/repository/DictionaryRepository.java
-
9archives/src/main/java/com/storeroom/modules/dictionary/service/DictionaryService.java
-
7archives/src/main/java/com/storeroom/modules/dictionary/service/dto/DictionaryQueryCriteria.java
-
63archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DictionaryServiceImpl.java
@ -0,0 +1,34 @@ |
|||||
|
package com.storeroom.modules.dictionary.controller; |
||||
|
|
||||
|
import com.storeroom.annotaion.rest.AnonymousGetMapping; |
||||
|
import com.storeroom.annotaion.rest.AnonymousPostMapping; |
||||
|
import com.storeroom.modules.dictionary.domain.vo.DictionaryVO; |
||||
|
import com.storeroom.modules.dictionary.service.DictionaryService; |
||||
|
import com.storeroom.modules.dictionary.service.dto.DictionaryQueryCriteria; |
||||
|
import com.storeroom.utils.ApiResponse; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.springframework.data.domain.Pageable; |
||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
@RestController |
||||
|
@RequiredArgsConstructor |
||||
|
@Api(tags = "字典表管理") |
||||
|
@RequestMapping("/dictrionary") |
||||
|
public class DictrionaryController { |
||||
|
|
||||
|
private final DictionaryService dictionaryService; |
||||
|
|
||||
|
@ApiOperation("字典目录") |
||||
|
// @GetMapping("/menu") |
||||
|
@AnonymousGetMapping(value = "/menu") |
||||
|
public ApiResponse<Object> menu(){ |
||||
|
return ApiResponse.success(dictionaryService.findDictrionaryMenu()); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,49 @@ |
|||||
|
package com.storeroom.modules.dictionary.domain; |
||||
|
|
||||
|
import com.storeroom.base.BaseEntity; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
import org.hibernate.annotations.GenericGenerator; |
||||
|
|
||||
|
import javax.persistence.*; |
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
@Entity |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@Table(name="sys_dictionary") |
||||
|
public class Dictionary extends BaseEntity implements Serializable { |
||||
|
|
||||
|
@Id |
||||
|
@Column(name = "id") |
||||
|
@GeneratedValue(generator = "idGenerator") |
||||
|
@GenericGenerator(name = "idGenerator", strategy = "uuid") |
||||
|
private String id; |
||||
|
|
||||
|
@Column(name = "dic_name") |
||||
|
@ApiModelProperty(value = "名称") |
||||
|
private String dicName; |
||||
|
|
||||
|
@Column(name = "dic_code") |
||||
|
@ApiModelProperty(value = "代码") |
||||
|
private String dicCode; |
||||
|
|
||||
|
@Column(name = "dic_explain") |
||||
|
@ApiModelProperty(value = "备注") |
||||
|
private String dicExplain; |
||||
|
|
||||
|
@Column(name = "dic_sequence") |
||||
|
@ApiModelProperty(value = "排序") |
||||
|
private Integer dicSequence; |
||||
|
|
||||
|
@Column(name = "dic_type") |
||||
|
@ApiModelProperty(value = "是否为一级菜单") |
||||
|
private Boolean dicType; |
||||
|
|
||||
|
@Column(name = "dic_pid") |
||||
|
@ApiModelProperty(value = "父id") |
||||
|
private String dicPid; |
||||
|
|
||||
|
} |
@ -0,0 +1,55 @@ |
|||||
|
package com.storeroom.modules.dictionary.domain.vo; |
||||
|
|
||||
|
import com.alibaba.fastjson.annotation.JSONField; |
||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
public class DictionaryVO { |
||||
|
|
||||
|
@ApiModelProperty(value = "字典id") |
||||
|
@JSONField(name="id") |
||||
|
@JsonProperty("id") |
||||
|
private String id; |
||||
|
|
||||
|
@ApiModelProperty(value = "字典名称") |
||||
|
@JSONField(name="dicName") |
||||
|
@JsonProperty("dic_name") |
||||
|
private String dicName; |
||||
|
|
||||
|
@ApiModelProperty(value = "字典代码") |
||||
|
@JSONField(name="dicCode") |
||||
|
@JsonProperty("dic_code") |
||||
|
private String dicCode; |
||||
|
|
||||
|
@ApiModelProperty(value = "设备id") |
||||
|
@JSONField(name="deviceId") |
||||
|
@JsonProperty("device_id") |
||||
|
private String dicExplain; |
||||
|
|
||||
|
@ApiModelProperty(value = "设备id") |
||||
|
@JSONField(name="deviceId") |
||||
|
@JsonProperty("device_id") |
||||
|
private String dicSequence; |
||||
|
|
||||
|
@ApiModelProperty(value = "设备id") |
||||
|
@JSONField(name="deviceId") |
||||
|
@JsonProperty("device_id") |
||||
|
private String dicType; |
||||
|
|
||||
|
@ApiModelProperty(value = "父id") |
||||
|
@JSONField(name="deviceId") |
||||
|
@JsonProperty("dic_pid") |
||||
|
private String dicPid; |
||||
|
|
||||
|
@ApiModelProperty(value = "子菜单集合") |
||||
|
@JSONField(name="childMenus") |
||||
|
@JsonProperty("child_menus") |
||||
|
private List<DictionaryVO> childMenus; |
||||
|
|
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
package com.storeroom.modules.dictionary.repository; |
||||
|
|
||||
|
import com.storeroom.modules.dictionary.domain.Dictionary; |
||||
|
import org.springframework.data.jpa.repository.JpaRepository; |
||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
||||
|
import org.springframework.data.jpa.repository.Query; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
public interface DictionaryRepository extends JpaRepository<Dictionary, String> { |
||||
|
|
||||
|
@Query(" from Dictionary ") |
||||
|
List<Dictionary> findAllOrderBy(); |
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
package com.storeroom.modules.dictionary.service; |
||||
|
|
||||
|
import com.storeroom.modules.dictionary.domain.vo.DictionaryVO; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
public interface DictionaryService { |
||||
|
List<DictionaryVO> findDictrionaryMenu(); |
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
package com.storeroom.modules.dictionary.service.dto; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
@Data |
||||
|
public class DictionaryQueryCriteria { |
||||
|
} |
@ -0,0 +1,63 @@ |
|||||
|
package com.storeroom.modules.dictionary.service.impl; |
||||
|
|
||||
|
import cn.hutool.core.bean.BeanUtil; |
||||
|
import com.storeroom.modules.dictionary.domain.Dictionary; |
||||
|
import com.storeroom.modules.dictionary.domain.vo.DictionaryVO; |
||||
|
import com.storeroom.modules.dictionary.repository.DictionaryRepository; |
||||
|
import com.storeroom.modules.dictionary.service.DictionaryService; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import net.sf.json.JSONArray; |
||||
|
import org.springframework.cache.annotation.CacheConfig; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Service |
||||
|
@RequiredArgsConstructor |
||||
|
public class DictionaryServiceImpl implements DictionaryService { |
||||
|
|
||||
|
private final DictionaryRepository dictionaryRepository; |
||||
|
|
||||
|
@Override |
||||
|
public List<DictionaryVO> findDictrionaryMenu() { |
||||
|
List<Dictionary> dictionaryList = dictionaryRepository.findAllOrderBy(); |
||||
|
//树排序 |
||||
|
List<DictionaryVO> menuList = new ArrayList<>(); |
||||
|
// 先找到所有的一级菜单 |
||||
|
for (int i = 0; i < dictionaryList.size(); i++) { |
||||
|
Dictionary dictionary = dictionaryList.get(i); |
||||
|
if(dictionary.getDicType()){ |
||||
|
menuList.add(BeanUtil.copyProperties(dictionary,DictionaryVO.class)); |
||||
|
} |
||||
|
} |
||||
|
// 为一级菜单设置子菜单,getChild是递归调用的 |
||||
|
for (DictionaryVO menu : menuList) { |
||||
|
menu.setChildMenus(getChild(menu.getId(), dictionaryList)); |
||||
|
} |
||||
|
return menuList; |
||||
|
} |
||||
|
|
||||
|
private static List<DictionaryVO> getChild(String id, List<Dictionary> rootMenu) { |
||||
|
// 子菜单 |
||||
|
List<DictionaryVO> childList = new ArrayList<>(); |
||||
|
for (Dictionary dictionary : rootMenu) { |
||||
|
// 遍历所有节点,将父菜单id与传过来的id比较 |
||||
|
if (id.equals(dictionary.getDicPid())) { |
||||
|
childList.add(BeanUtil.copyProperties(dictionary,DictionaryVO.class)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 把子菜单的子菜单再循环一遍 |
||||
|
for (DictionaryVO menu : childList) { |
||||
|
menu.setChildMenus(getChild(menu.getId(), rootMenu));// 递归 |
||||
|
} |
||||
|
|
||||
|
// 判断递归结束 |
||||
|
if (childList.size() == 0) { |
||||
|
return null; |
||||
|
} |
||||
|
return childList; |
||||
|
} |
||||
|
|
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue