新增区域表树结构接口

dongdingding
董丁丁 2 years ago
parent a56d1a0373
commit e22a92c89e

@ -23,14 +23,14 @@ import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
* Controller
* Controller
*
* @author ruoyi
* @date 2023-08-10
*/
@RestController
@RequestMapping("/zongzhi/danger")
@Api(tags = " 监管单位")
@Api(tags = " 安全隐患")
public class TcSafetyDangerController extends BaseController
{
@Autowired

@ -1,9 +1,17 @@
package com.ruoyi.zongzhi.controller;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysDept;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@ -41,7 +49,7 @@ public class TcTownController extends BaseController
/**
*
*/
@PreAuthorize("@ss.hasPermi('zongzhi:town:list')")
@GetMapping("/list")
public TableDataInfo list(TcTown tcTown)
{
@ -53,8 +61,8 @@ public class TcTownController extends BaseController
/**
*
*/
@PreAuthorize("@ss.hasPermi('zongzhi:town:export')")
@Log(title = "区域", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, TcTown tcTown)
{
@ -67,7 +75,7 @@ public class TcTownController extends BaseController
/**
*
*/
@PreAuthorize("@ss.hasPermi('zongzhi:town:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
@ -77,8 +85,7 @@ public class TcTownController extends BaseController
/**
*
*/
@PreAuthorize("@ss.hasPermi('zongzhi:town:add')")
@Log(title = "区域", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody TcTown tcTown)
{
@ -88,8 +95,7 @@ public class TcTownController extends BaseController
/**
*
*/
@PreAuthorize("@ss.hasPermi('zongzhi:town:edit')")
@Log(title = "区域", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody TcTown tcTown)
{
@ -99,8 +105,7 @@ public class TcTownController extends BaseController
/**
*
*/
@PreAuthorize("@ss.hasPermi('zongzhi:town:remove')")
@Log(title = "区域", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
@ -108,7 +113,12 @@ public class TcTownController extends BaseController
}
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
/**
* excel
* @param file
* @return
* @throws Exception
*/
@PostMapping("/importData")
public AjaxResult importData(MultipartFile file) throws Exception
{
@ -118,5 +128,15 @@ public class TcTownController extends BaseController
return AjaxResult.success(message);
}
/**
*
* @return
*/
@GetMapping("/new/tree")
@ApiOperation(value = "树形结构列表")
public AjaxResult treeselect(TcTown tcTown)
{
List<TcTown> tcTowns = tcTownService.selectTcTownList(tcTown);
return AjaxResult.success(tcTownService.buildDeptTreeSelect(tcTowns));
}
}

@ -11,7 +11,7 @@ import io.swagger.annotations.ApiModelProperty;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* tc_safety_danger
* tc_safety_danger
*
* @author ruoyi
* @date 2023-08-10

@ -1,5 +1,6 @@
package com.ruoyi.zongzhi.domain;
import com.ruoyi.common.core.domain.entity.SysDept;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
@ -7,6 +8,9 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import java.util.ArrayList;
import java.util.List;
/**
* tc_town
*
@ -37,7 +41,7 @@ public class TcTown extends BaseEntity
private Long parentId;
/** 层级123村 */
@Excel(name = "层级123")
@Excel(name = "层级")
@ApiModelProperty(value = "层级")
private Long level;
@ -49,4 +53,8 @@ public class TcTown extends BaseEntity
@Excel(name = "修改人ID")
private Long updateId;
/** 子节点 */
private List<TcTown> children = new ArrayList<TcTown>();
}

@ -0,0 +1,54 @@
package com.ruoyi.zongzhi.domain.vo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.ruoyi.zongzhi.domain.TcTown;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;
/**
* Treeselect
*
* @author ruoyi
*/
@Data
public class TreeNode
{
/** 节点ID */
private Long id;
/** 节点名称 */
private String label;
/** 父节点名称 */
private String parentName;
/** 父节点id*/
Long parentId;
/** 子节点 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<TreeNode> children;
public TreeNode()
{
}
public TreeNode(TcTown tcTown)
{
this.id = tcTown.getId();
this.label = tcTown.getName();
this.parentName=tcTown.getParentName();
this.parentId=tcTown.getParentId();
this.children = tcTown.getChildren().stream().map(TreeNode::new).collect(Collectors.toList());
}
}

@ -1,19 +1,23 @@
package com.ruoyi.zongzhi.service;
import java.util.List;
import com.ruoyi.common.core.domain.TreeSelect;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.zongzhi.domain.TcTown;
import com.ruoyi.zongzhi.domain.vo.TreeNode;
/**
* Service
*
*
* @author ruoyi
* @date 2023-08-10
*/
public interface ITcTownService
{
public interface ITcTownService {
/**
*
*
*
* @param id
* @return
*/
@ -21,7 +25,7 @@ public interface ITcTownService
/**
*
*
*
* @param tcTown
* @return
*/
@ -29,7 +33,7 @@ public interface ITcTownService
/**
*
*
*
* @param tcTown
* @return
*/
@ -37,7 +41,7 @@ public interface ITcTownService
/**
*
*
*
* @param tcTown
* @return
*/
@ -45,7 +49,7 @@ public interface ITcTownService
/**
*
*
*
* @param ids
* @return
*/
@ -53,14 +57,13 @@ public interface ITcTownService
/**
*
*
*
* @param id
* @return
*/
public int deleteTcTownById(Long id);
/**
*
*
@ -68,4 +71,14 @@ public interface ITcTownService
*/
public String importUser(List<TcTown> tcTownList);
/**
*
*
* @param tcTowns
* @return
*/
public List<TreeNode> buildDeptTreeSelect(List<TcTown> tcTowns);
List<TcTown> buildDeptTree(List<TcTown> depts);
}

@ -9,7 +9,7 @@ import com.ruoyi.zongzhi.domain.TcSafetyDanger;
import com.ruoyi.zongzhi.service.ITcSafetyDangerService;
/**
* Service
* Service
*
* @author ruoyi
* @date 2023-08-10
@ -21,10 +21,10 @@ public class TcSafetyDangerServiceImpl implements ITcSafetyDangerService
private TcSafetyDangerMapper tcSafetyDangerMapper;
/**
*
*
*
* @param id
* @return
* @param id
* @return
*/
@Override
public TcSafetyDanger selectTcSafetyDangerById(Long id)

@ -1,95 +1,93 @@
package com.ruoyi.zongzhi.service.impl;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.zongzhi.mapper.TcTownMapper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.zongzhi.domain.TcTown;
import com.ruoyi.zongzhi.mapper.TcTownMapper;
import com.ruoyi.zongzhi.service.ITcTownService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.zongzhi.domain.vo.TreeNode;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
/**
* Service
*
*
* @author ruoyi
* @date 2023-08-10
*/
@Service
public class TcTownServiceImpl implements ITcTownService
{
public class TcTownServiceImpl implements ITcTownService {
@Autowired
private TcTownMapper tcTownMapper;
/**
*
*
*
* @param id
* @return
*/
@Override
public TcTown selectTcTownById(Long id)
{
public TcTown selectTcTownById(Long id) {
return tcTownMapper.selectTcTownById(id);
}
/**
*
*
*
* @param tcTown
* @return
*/
@Override
public List<TcTown> selectTcTownList(TcTown tcTown)
{
public List<TcTown> selectTcTownList(TcTown tcTown) {
return tcTownMapper.selectTcTownList(tcTown);
}
/**
*
*
*
* @param tcTown
* @return
*/
@Override
public int insertTcTown(TcTown tcTown)
{
public int insertTcTown(TcTown tcTown) {
tcTown.setCreateTime(DateUtils.getNowDate());
return tcTownMapper.insertTcTown(tcTown);
}
/**
*
*
*
* @param tcTown
* @return
*/
@Override
public int updateTcTown(TcTown tcTown)
{
public int updateTcTown(TcTown tcTown) {
return tcTownMapper.updateTcTown(tcTown);
}
/**
*
*
*
* @param ids
* @return
*/
@Override
public int deleteTcTownByIds(Long[] ids)
{
public int deleteTcTownByIds(Long[] ids) {
return tcTownMapper.deleteTcTownByIds(ids);
}
/**
*
*
*
* @param id
* @return
*/
@Override
public int deleteTcTownById(Long id)
{
public int deleteTcTownById(Long id) {
return tcTownMapper.deleteTcTownById(id);
}
@ -108,4 +106,81 @@ public class TcTownServiceImpl implements ITcTownService
return successMsg.toString();
}
/**
*
*
* @param tcTowns
* @return
*/
@Override
public List<TreeNode> buildDeptTreeSelect(List<TcTown> tcTowns) {
List<TcTown> deptTrees = buildDeptTree(tcTowns);
return deptTrees.stream().map(TreeNode::new).collect(Collectors.toList());
}
/**
*
*
* @param depts
* @return
*/
@Override
public List<TcTown> buildDeptTree(List<TcTown> depts) {
List<TcTown> returnList = new ArrayList<TcTown>();
List<Long> tempList = new ArrayList<Long>();
for (TcTown dept : depts) {
tempList.add(dept.getId());
}
for (Iterator<TcTown> iterator = depts.iterator(); iterator.hasNext(); ) {
TcTown dept = (TcTown) iterator.next();
// 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempList.contains(dept.getParentId())) {
recursionFn(depts, dept);
returnList.add(dept);
}
}
if (returnList.isEmpty()) {
returnList = depts;
}
return returnList;
}
/**
*
*/
private void recursionFn(List<TcTown> list, TcTown t) {
// 得到子节点列表
List<TcTown> childList = getChildList(list, t);
t.setChildren(childList);
for (TcTown tChild : childList) {
if (hasChild(list, tChild)) {
recursionFn(list, tChild);
}
}
}
/**
*
*/
private List<TcTown> getChildList(List<TcTown> list, TcTown t) {
List<TcTown> tlist = new ArrayList<TcTown>();
Iterator<TcTown> it = list.iterator();
while (it.hasNext()) {
TcTown n = (TcTown) it.next();
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue()) {
tlist.add(n);
}
}
return tlist;
}
/**
*
*/
private boolean hasChild(List<TcTown> list, TcTown t) {
return getChildList(list, t).size() > 0;
}
}

Loading…
Cancel
Save