@@ -0,0 +1,32 @@ | |||||
package com.hz.pm.api.user.controller; | |||||
import com.hz.pm.api.user.manage.MhUnitManage; | |||||
import com.hz.pm.api.user.model.dto.MhUnitTreeDTO; | |||||
import lombok.RequiredArgsConstructor; | |||||
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; | |||||
/** | |||||
* <p> | |||||
* MhUnitController | |||||
* </p> | |||||
* | |||||
* @author WendyYang | |||||
* @since 15:28 2024/1/10 | |||||
*/ | |||||
@RestController | |||||
@RequiredArgsConstructor | |||||
@RequestMapping("/api/v1/mh/unit") | |||||
public class MhUnitController { | |||||
private final MhUnitManage mhUnitManage; | |||||
@GetMapping("/tree") | |||||
public List<MhUnitTreeDTO> getMhUnitTree() { | |||||
return mhUnitManage.getMhUnitTree(); | |||||
} | |||||
} |
@@ -0,0 +1,38 @@ | |||||
package com.hz.pm.api.user.manage; | |||||
import cn.hutool.core.bean.BeanUtil; | |||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||||
import com.hz.pm.api.common.model.constant.BizConst; | |||||
import com.hz.pm.api.user.model.dto.MhUnitTreeDTO; | |||||
import com.hz.pm.api.user.model.entity.MhUnit; | |||||
import com.hz.pm.api.user.service.IMhUnitService; | |||||
import com.ningdatech.basic.util.TreeUtil; | |||||
import lombok.RequiredArgsConstructor; | |||||
import org.springframework.stereotype.Component; | |||||
import java.util.List; | |||||
/** | |||||
* <p> | |||||
* MhUnitManage | |||||
* </p> | |||||
* | |||||
* @author WendyYang | |||||
* @since 15:33 2024/1/10 | |||||
*/ | |||||
@Component | |||||
@RequiredArgsConstructor | |||||
public class MhUnitManage { | |||||
private final IMhUnitService mhUnitService; | |||||
public List<MhUnitTreeDTO> getMhUnitTree() { | |||||
LambdaQueryWrapper<MhUnit> query = Wrappers.lambdaQuery(MhUnit.class) | |||||
.select(MhUnit::getSort, MhUnit::getId, MhUnit::getParentId, MhUnit::getName); | |||||
List<MhUnit> units = mhUnitService.list(query); | |||||
List<MhUnitTreeDTO> nodes = BeanUtil.copyToList(units, MhUnitTreeDTO.class); | |||||
return TreeUtil.convertToTree(nodes, 0L); | |||||
} | |||||
} |
@@ -0,0 +1,35 @@ | |||||
package com.hz.pm.api.user.model.dto; | |||||
import com.ningdatech.basic.model.ITree; | |||||
import lombok.Data; | |||||
import java.util.Comparator; | |||||
import java.util.List; | |||||
/** | |||||
* <p> | |||||
* MhUnitTreeDTO | |||||
* </p> | |||||
* | |||||
* @author WendyYang | |||||
* @since 15:29 2024/1/10 | |||||
*/ | |||||
@Data | |||||
public class MhUnitTreeDTO implements ITree<Long, MhUnitTreeDTO> { | |||||
private Long id; | |||||
private String name; | |||||
private Long parentId; | |||||
private Short sort; | |||||
private List<MhUnitTreeDTO> children; | |||||
@Override | |||||
public Comparator<? super MhUnitTreeDTO> comparator() { | |||||
return Comparator.comparing(MhUnitTreeDTO::getSort); | |||||
} | |||||
} |