forked from gitee/vben-java
增加流程分类与模板
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
package com.zsvg.vboot.wf.tem.cate;
|
||||
|
||||
import com.zsvg.vboot.common.mvc.entity.BaseCateEntity;
|
||||
import com.zsvg.vboot.module.sys.auth.menu.SysAuthMenu;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@@ -18,5 +18,8 @@ public class WfTemCate extends BaseCateEntity {
|
||||
@JoinColumn(name = "pid")
|
||||
private WfTemCate parent;//父类别
|
||||
|
||||
@Transient
|
||||
private List<WfTemCate> children = new ArrayList<>(); //行项目
|
||||
|
||||
private String notes;//备注
|
||||
}
|
||||
|
||||
@@ -3,9 +3,12 @@ package com.zsvg.vboot.wf.tem.cate;
|
||||
import com.zsvg.vboot.common.mvc.api.RestResult;
|
||||
import com.zsvg.vboot.common.mvc.dao.Sqler;
|
||||
import com.zsvg.vboot.common.mvc.pojo.Ztree;
|
||||
import com.zsvg.vboot.common.util.lang.XstringUtil;
|
||||
import com.zsvg.vboot.module.sys.auth.menu.SysAuthMenu;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@@ -17,9 +20,10 @@ public class WfTemCateApi {
|
||||
@GetMapping
|
||||
public RestResult get(String name) {
|
||||
Sqler sqler = new Sqler(table);
|
||||
sqler.addSelect("t.pid,t.crtim,t.uptim");
|
||||
sqler.addLike("t.name", name);
|
||||
sqler.addSelect("t.notes,t.ornum");
|
||||
return RestResult.ok(service.findPageData(sqler));
|
||||
sqler.addOrder("t.ornum");
|
||||
return RestResult.ok(service.findTree(sqler));
|
||||
}
|
||||
|
||||
@GetMapping("one/{id}")
|
||||
|
||||
@@ -1,18 +1,59 @@
|
||||
package com.zsvg.vboot.wf.tem.cate;
|
||||
|
||||
import com.zsvg.vboot.common.mvc.dao.Sqler;
|
||||
import com.zsvg.vboot.common.mvc.service.BaseCateService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class WfTemCateService extends BaseCateService<WfTemCate> {
|
||||
|
||||
|
||||
public List<WfTemCate> findTree(Sqler sqler) {
|
||||
List<WfTemCate> list = jdbcDao.getTp().query(sqler.getSql(), sqler.getParams(), new BeanPropertyRowMapper<>(WfTemCate.class));
|
||||
return buildByRecursive(list);
|
||||
}
|
||||
|
||||
//使用递归方法建树
|
||||
private List<WfTemCate> buildByRecursive(List<WfTemCate> nodes) {
|
||||
List<WfTemCate> list = new ArrayList<>();
|
||||
for (WfTemCate node : nodes) {
|
||||
if (node.getPid() == null) {
|
||||
list.add(findChildrenByTier(node, nodes));
|
||||
} else {
|
||||
boolean flag = false;
|
||||
for (WfTemCate node2 : nodes) {
|
||||
if (node.getPid().equals(node2.getId())) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag) {
|
||||
list.add(findChildrenByTier(node, nodes));
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//递归查找子节点
|
||||
private WfTemCate findChildrenByTier(WfTemCate node, List<WfTemCate> nodes) {
|
||||
for (WfTemCate item : nodes) {
|
||||
if (node.getId().equals(item.getPid())) {
|
||||
if (node.getChildren() == null) {
|
||||
node.setChildren(new ArrayList<>());
|
||||
}
|
||||
node.getChildren().add(findChildrenByTier(item, nodes));
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
//----------bean注入------------
|
||||
@Autowired
|
||||
|
||||
Reference in New Issue
Block a user