forked from gitee/vben-java
增加树形分类DEMO示例
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package vboot.app.module.de.supp.cate;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import vboot.core.common.entity.BaseCateEntity;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
public class DeSuppCate extends BaseCateEntity {
|
||||
|
||||
@ManyToOne(fetch= FetchType.EAGER)
|
||||
@JoinColumn(name = "pid")
|
||||
private DeSuppCate parent;//父类别
|
||||
|
||||
// @Transient
|
||||
// private List<DeSuppCate> children = new ArrayList<>(); //子元素
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package vboot.app.module.de.supp.cate;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import vboot.core.common.api.R;
|
||||
import vboot.core.common.dao.Sqler;
|
||||
import vboot.core.common.pojo.Ztree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("de/supp/cate")
|
||||
public class DeSuppCateApi {
|
||||
|
||||
private String table = "de_supp_cate";
|
||||
|
||||
@GetMapping("treez")
|
||||
public R getTreez(String name,String id) {
|
||||
List<Ztree> list = service.tier2Choose(table,id,name);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
@GetMapping("treea")
|
||||
public R getTreea(String name) {
|
||||
List<Ztree> list = service.findTreeList(table,name);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
@GetMapping("tree")
|
||||
public R getTree(String name) {
|
||||
Sqler sqler = new Sqler(table);
|
||||
sqler.addLike("t.name", name);
|
||||
sqler.addOrder("t.ornum");
|
||||
sqler.addWhere("t.avtag=1");
|
||||
sqler.addSelect("t.crtim,t.uptim,t.pid");
|
||||
List<DeSuppCate> list = service.findTree(sqler);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
@GetMapping("one/{id}")
|
||||
public R getOne(@PathVariable String id) {return R.ok(service.findOne(id)); }
|
||||
|
||||
@PostMapping
|
||||
public R post(@RequestBody DeSuppCate main) {
|
||||
return R.ok(service.insert(main));
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public R put(@RequestBody DeSuppCate main) {
|
||||
return R.ok(service.update(main,table));
|
||||
}
|
||||
|
||||
@DeleteMapping("{ids}")
|
||||
public R delete(@PathVariable String[] ids) {
|
||||
return R.ok(service.delete(ids));
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private DeSuppCateService service;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package vboot.app.module.de.supp.cate;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface DeSuppCateRepo extends JpaRepository<DeSuppCate,String> {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package vboot.app.module.de.supp.cate;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import vboot.core.common.dao.Sqler;
|
||||
import vboot.core.common.service.BaseCateService;
|
||||
import vboot.core.common.service.BaseMainService;
|
||||
import vboot.core.common.service.BaseService;
|
||||
import vboot.core.module.sys.portal.menu.SysPortalMenu;
|
||||
import vboot.extend.module.sa.cust.cate.SaCustCate;
|
||||
import vboot.extend.module.sa.cust.cate.SaCustCateRepo;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class DeSuppCateService extends BaseCateService<DeSuppCate> {
|
||||
|
||||
public List<DeSuppCate> findTree(Sqler sqler) {
|
||||
List<DeSuppCate> list = jdbcDao.getTp().query(sqler.getSql(), sqler.getParams(), new BeanPropertyRowMapper<>(DeSuppCate.class));
|
||||
return buildByRecursive(list);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private DeSuppCateRepo repo;
|
||||
|
||||
@PostConstruct
|
||||
public void initDao() {
|
||||
super.setRepo(repo);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package vboot.app.module.de.supp.main;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class DeSuppContact {
|
||||
@Id
|
||||
@Column(length = 36)
|
||||
private String id;//主键
|
||||
|
||||
@Column(length = 32)
|
||||
private String name;//姓名
|
||||
|
||||
@Column(length = 32)
|
||||
private String monum;//手机号
|
||||
|
||||
@Column(length = 32)
|
||||
private String gender;//性别
|
||||
|
||||
@Column(length = 64)
|
||||
private String post;//职务
|
||||
|
||||
@Column(length = 32)
|
||||
private String email;//邮箱
|
||||
|
||||
@Column(length = 32)
|
||||
private String notes;//备注
|
||||
|
||||
private Integer ornum;//排序号
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package vboot.app.module.de.supp.main;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import vboot.core.common.entity.BaseMainEntity;
|
||||
import vboot.core.module.sys.org.root.SysOrg;
|
||||
import vboot.extend.module.sa.prod.main.SaProdMain;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
public class DeSuppMain extends BaseMainEntity {
|
||||
|
||||
//--------地址相关信息------<<<
|
||||
private String addre;//完整地址
|
||||
|
||||
@Column(length = 64)
|
||||
private String adreg;//省市区
|
||||
|
||||
@Column(length = 128)
|
||||
private String addet;//省市区以外的详细信息
|
||||
|
||||
@Column(length = 32)
|
||||
private String adcoo;//经纬度
|
||||
|
||||
@Column(length = 32)
|
||||
private String adpro;//省
|
||||
|
||||
@Column(length = 32)
|
||||
private String adcit;//市
|
||||
|
||||
@Column(length = 32)
|
||||
private String addis;//区
|
||||
//--------地址相关信息------>>>
|
||||
|
||||
@Column(length = 32)
|
||||
private String catid;//供应商分类
|
||||
|
||||
@Column(length = 32)
|
||||
private String senum;//流水号
|
||||
|
||||
private String notes;//备注
|
||||
|
||||
@Column(length = 32)
|
||||
private String level;//供应商资质
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "opman")
|
||||
private SysOrg opman;//经办人
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name = "de_supp_viewer", joinColumns = {@JoinColumn(name = "mid")},
|
||||
inverseJoinColumns = {@JoinColumn(name = "oid")})
|
||||
private List<SysOrg> viewers;//可查看者
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name = "de_supp_editor", joinColumns = {@JoinColumn(name = "mid")},
|
||||
inverseJoinColumns = {@JoinColumn(name = "oid")})
|
||||
private List<SysOrg> editors;//可编辑者
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JoinColumn(name = "maiid")
|
||||
@OrderBy("ornum ASC")
|
||||
private List<DeSuppContact> contacts = new ArrayList<>();//联系人
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package vboot.app.module.de.supp.main;
|
||||
|
||||
import vboot.core.common.api.R;
|
||||
import vboot.core.common.dao.Sqler;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import vboot.core.module.ass.num.main.AssNumMainService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("de/supp/main")
|
||||
public class DeSuppMainApi {
|
||||
|
||||
@GetMapping
|
||||
public R get(String name) {
|
||||
Sqler sqler = new Sqler("de_supp_main");
|
||||
sqler.addLike("t.name", name);
|
||||
sqler.addSelect("t.addre,t.senum,t.notes");
|
||||
return R.ok(service.findPageData(sqler));
|
||||
}
|
||||
|
||||
@GetMapping("one/{id}")
|
||||
public R getOne(@PathVariable String id) {
|
||||
DeSuppMain main = service.findOne(id);
|
||||
return R.ok(main);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public R post(@RequestBody DeSuppMain main) {
|
||||
main.setSenum(numService.getNum("SUPP"));
|
||||
return R.ok(service.insert(main));
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public R put(@RequestBody DeSuppMain main) {
|
||||
return R.ok(service.update(main));
|
||||
}
|
||||
|
||||
@DeleteMapping("{ids}")
|
||||
public R delete(@PathVariable String[] ids) {
|
||||
return R.ok(service.delete(ids));
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private DeSuppMainService service;
|
||||
|
||||
@Autowired
|
||||
private AssNumMainService numService;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package vboot.app.module.de.supp.main;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface DeSuppMainRepo extends JpaRepository<DeSuppMain,String> {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package vboot.app.module.de.supp.main;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import vboot.core.common.service.BaseMainService;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@Service
|
||||
public class DeSuppMainService extends BaseMainService<DeSuppMain> {
|
||||
|
||||
@Autowired
|
||||
private DeSuppMainRepo repo;
|
||||
|
||||
@PostConstruct
|
||||
public void initDao() {
|
||||
super.setRepo(repo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
package vboot.app.module.demo.cust.main;
|
||||
|
||||
public class DemoCustMain {
|
||||
}
|
||||
@@ -5,7 +5,9 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@MappedSuperclass
|
||||
@Getter
|
||||
@@ -15,26 +17,19 @@ public class BaseCateEntity {
|
||||
@Id
|
||||
@Column(length = 32)
|
||||
protected String id;
|
||||
//----------------------权限属性-----------------------
|
||||
// @ManyToMany
|
||||
// @JoinTable(name = "xxx_viewer", joinColumns = {@JoinColumn(name = "id")},
|
||||
// inverseJoinColumns = {@JoinColumn(name = "org")})
|
||||
// private List<SysOrg> viewers;//分类可查看使用者,拥有此权限者可以创建此分类下主数据信息
|
||||
//
|
||||
// @ManyToMany
|
||||
// @JoinTable(name = "xxx_editor", joinColumns = {@JoinColumn(name = "id")},
|
||||
// inverseJoinColumns = {@JoinColumn(name = "org")})
|
||||
// private List<SysOrg> editors;//分类可编辑维护者,拥有此权限者可以查看此分类下所有主数据信息
|
||||
|
||||
//----------------------层级属性参考-----------------------
|
||||
@Column(length = 1000)
|
||||
protected String tier;//层级信息
|
||||
|
||||
@Transient
|
||||
private String pid;
|
||||
protected String pid;
|
||||
|
||||
@Transient
|
||||
protected BaseCateEntity parent;//父类别
|
||||
|
||||
@Transient
|
||||
protected List<BaseCateEntity> children = new ArrayList<>(); //子元素
|
||||
//----------------------norm标准属性-----------------------
|
||||
@Column(length = 100)
|
||||
protected String name;//名称
|
||||
|
||||
@@ -8,6 +8,7 @@ import vboot.core.common.entity.BaseCateEntity;
|
||||
import vboot.core.common.pojo.ZidName;
|
||||
import vboot.core.common.pojo.Zinp;
|
||||
import vboot.core.common.pojo.Ztree;
|
||||
import vboot.core.module.sys.portal.menu.SysPortalMenu;
|
||||
import vboot.core.xutil.lang.XstrUtil;
|
||||
import vboot.core.xutil.web.XuserUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -30,7 +31,6 @@ public abstract class BaseCateService<T extends BaseCateEntity> {
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public PageData findPageData(Sqler sqler) {
|
||||
sqler.selectCUinfo().addSelect("t.label");
|
||||
@@ -44,7 +44,6 @@ public abstract class BaseCateService<T extends BaseCateEntity> {
|
||||
}
|
||||
|
||||
|
||||
|
||||
//用户编辑时选择父类别,不能选择自己及孩子节点,否则会造成无线循环
|
||||
@Transactional(readOnly = true)
|
||||
public List<Zinp> inpChoose(String table, String id, String name){
|
||||
@@ -202,6 +201,60 @@ public abstract class BaseCateService<T extends BaseCateEntity> {
|
||||
}
|
||||
return ids.length;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//使用递归方法建树
|
||||
public List<T> buildByRecursive(List<T> nodes) {
|
||||
List<T> list = new ArrayList<>();
|
||||
for (T node : nodes) {
|
||||
if (node.getPid() == null) {
|
||||
list.add(findChildrenByTier(node, nodes));
|
||||
} else {
|
||||
boolean flag = false;
|
||||
for (BaseCateEntity node2 : nodes) {
|
||||
if (node.getPid().equals(node2.getId())) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag) {
|
||||
list.add(findChildrenByTier(node, nodes));
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
//递归查找子节点
|
||||
private T findChildrenByTier(T node, List<T> nodes) {
|
||||
for (T item : nodes) {
|
||||
if (node.getId().equals(item.getPid())) {
|
||||
if (node.getChildren() == null) {
|
||||
node.setChildren(new ArrayList<>());
|
||||
}
|
||||
node.getChildren().add(findChildrenByTier(item, nodes));
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// public void deleteOne(T t) {
|
||||
// repo.delete(t);
|
||||
|
||||
@@ -17,8 +17,7 @@ public class OaDocCate extends BaseCateEntity {
|
||||
@JoinColumn(name = "pid")
|
||||
private OaDocCate parent;//父类别
|
||||
|
||||
@Transient
|
||||
private List<OaDocCate> children = new ArrayList<>(); //行项目
|
||||
// @Transient
|
||||
// private List<OaDocCate> children = new ArrayList<>(); //行项目
|
||||
|
||||
private String notes;//备注
|
||||
}
|
||||
|
||||
@@ -20,40 +20,40 @@ public class OaDocCateService extends BaseCateService<OaDocCate> {
|
||||
}
|
||||
|
||||
//使用递归方法建树
|
||||
private List<OaDocCate> buildByRecursive(List<OaDocCate> nodes) {
|
||||
List<OaDocCate> list = new ArrayList<>();
|
||||
for (OaDocCate node : nodes) {
|
||||
if (node.getPid() == null) {
|
||||
list.add(findChildrenByTier(node, nodes));
|
||||
} else {
|
||||
boolean flag = false;
|
||||
for (OaDocCate node2 : nodes) {
|
||||
if (node.getPid().equals(node2.getId())) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag) {
|
||||
list.add(findChildrenByTier(node, nodes));
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
//递归查找子节点
|
||||
private OaDocCate findChildrenByTier(OaDocCate node, List<OaDocCate> nodes) {
|
||||
for (OaDocCate item : nodes) {
|
||||
if (node.getId().equals(item.getPid())) {
|
||||
if (node.getChildren() == null) {
|
||||
node.setChildren(new ArrayList<>());
|
||||
}
|
||||
node.getChildren().add(findChildrenByTier(item, nodes));
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
// private List<OaDocCate> buildByRecursive(List<OaDocCate> nodes) {
|
||||
// List<OaDocCate> list = new ArrayList<>();
|
||||
// for (OaDocCate node : nodes) {
|
||||
// if (node.getPid() == null) {
|
||||
// list.add(findChildrenByTier(node, nodes));
|
||||
// } else {
|
||||
// boolean flag = false;
|
||||
// for (OaDocCate node2 : nodes) {
|
||||
// if (node.getPid().equals(node2.getId())) {
|
||||
// flag = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (!flag) {
|
||||
// list.add(findChildrenByTier(node, nodes));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return list;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// //递归查找子节点
|
||||
// private OaDocCate findChildrenByTier(OaDocCate node, List<OaDocCate> nodes) {
|
||||
// for (OaDocCate 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
|
||||
|
||||
@@ -17,8 +17,7 @@ public class OaFlowCate extends BaseCateEntity {
|
||||
@JoinColumn(name = "pid")
|
||||
private OaFlowCate parent;//父类别
|
||||
|
||||
@Transient
|
||||
private List<OaFlowCate> children = new ArrayList<>(); //行项目
|
||||
// @Transient
|
||||
// private List<OaFlowCate> children = new ArrayList<>(); //父流程分类
|
||||
|
||||
private String notes;//备注
|
||||
}
|
||||
|
||||
+35
-35
@@ -19,41 +19,41 @@ public class OaFlowCateService extends BaseCateService<OaFlowCate> {
|
||||
return buildByRecursive(list);
|
||||
}
|
||||
|
||||
//使用递归方法建树
|
||||
private List<OaFlowCate> buildByRecursive(List<OaFlowCate> nodes) {
|
||||
List<OaFlowCate> list = new ArrayList<>();
|
||||
for (OaFlowCate node : nodes) {
|
||||
if (node.getPid() == null) {
|
||||
list.add(findChildrenByTier(node, nodes));
|
||||
} else {
|
||||
boolean flag = false;
|
||||
for (OaFlowCate node2 : nodes) {
|
||||
if (node.getPid().equals(node2.getId())) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag) {
|
||||
list.add(findChildrenByTier(node, nodes));
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
//递归查找子节点
|
||||
private OaFlowCate findChildrenByTier(OaFlowCate node, List<OaFlowCate> nodes) {
|
||||
for (OaFlowCate item : nodes) {
|
||||
if (node.getId().equals(item.getPid())) {
|
||||
if (node.getChildren() == null) {
|
||||
node.setChildren(new ArrayList<>());
|
||||
}
|
||||
node.getChildren().add(findChildrenByTier(item, nodes));
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
// //使用递归方法建树
|
||||
// private List<OaFlowCate> buildByRecursive(List<OaFlowCate> nodes) {
|
||||
// List<OaFlowCate> list = new ArrayList<>();
|
||||
// for (OaFlowCate node : nodes) {
|
||||
// if (node.getPid() == null) {
|
||||
// list.add(findChildrenByTier(node, nodes));
|
||||
// } else {
|
||||
// boolean flag = false;
|
||||
// for (OaFlowCate node2 : nodes) {
|
||||
// if (node.getPid().equals(node2.getId())) {
|
||||
// flag = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (!flag) {
|
||||
// list.add(findChildrenByTier(node, nodes));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return list;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// //递归查找子节点
|
||||
// private OaFlowCate findChildrenByTier(OaFlowCate node, List<OaFlowCate> nodes) {
|
||||
// for (OaFlowCate 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
|
||||
|
||||
@@ -55,7 +55,7 @@ public class SaProjMain extends BaseMainEntity {
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "opman")
|
||||
private SysOrg opman;//创建人
|
||||
private SysOrg opman;//经办人
|
||||
|
||||
private String type; //项目类型
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public class ${table.bunam}Api {
|
||||
|
||||
@PostMapping
|
||||
public R post(@RequestBody ${table.bunam} main) {
|
||||
return R.ok(service.insert(main);
|
||||
return R.ok(service.insert(main));
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
|
||||
Reference in New Issue
Block a user