forked from gitee/vben-java
增加crud~demo案例
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
### 🍿 项目简介
|
||||
### 🍿 项目简介
|
||||
|
||||
[](https://gitee.com/vben/vben-java)
|
||||
[]()
|
||||
|
||||
@@ -326,6 +326,7 @@
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
+12
-12
@@ -25,25 +25,25 @@
|
||||
|
||||
<!-- <!– mp支持的数据库均支持 只需要增加对应的jdbc依赖即可 –>-->
|
||||
<!-- <!– Oracle –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.oracle.database.jdbc</groupId>-->
|
||||
<!-- <artifactId>ojdbc8</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.oracle.database.jdbc</groupId>
|
||||
<artifactId>ojdbc8</artifactId>
|
||||
</dependency>
|
||||
<!-- <!– 兼容oracle低版本 –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.oracle.database.nls</groupId>-->
|
||||
<!-- <artifactId>orai18n</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <!– PostgreSql –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.postgresql</groupId>-->
|
||||
<!-- <artifactId>postgresql</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
<!-- <!– SqlServer –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.microsoft.sqlserver</groupId>-->
|
||||
<!-- <artifactId>mssql-jdbc</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.microsoft.sqlserver</groupId>
|
||||
<artifactId>mssql-jdbc</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package vben.jpa.demo.link.cate;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Index;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import vben.common.jpa.entity.BaseCateEntity;
|
||||
|
||||
/**
|
||||
* 关联分类表
|
||||
*/
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "关联分类表")
|
||||
@Table(indexes = {@Index(columnList = "cruid"), @Index(columnList = "upuid")})
|
||||
public class DemoLinkCate extends BaseCateEntity {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package vben.jpa.demo.link.cate;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import vben.common.core.domain.R;
|
||||
import vben.common.idempotent.annotation.RepeatSubmit;
|
||||
import vben.common.jdbc.dto.Lmove;
|
||||
import vben.common.jdbc.dto.Ltree;
|
||||
import vben.common.jdbc.sqler.Sqler;
|
||||
import vben.common.log.annotation.Log;
|
||||
import vben.common.log.enums.BusinessType;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 关联分类表案例
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("demo/link/cate")
|
||||
@RequiredArgsConstructor
|
||||
public class DemoLinkCateController {
|
||||
|
||||
private final String table = "demo_link_cate";
|
||||
|
||||
/**
|
||||
* 关联分类表-树状查询
|
||||
* @param name 案例名称
|
||||
* @param id 排除的案例ID
|
||||
* @return 案例树状数据
|
||||
*/
|
||||
@GetMapping("tree")
|
||||
@SaCheckPermission("link:cate:query")
|
||||
public R<List<Ltree>> getTree(String name, Long id) {
|
||||
Sqler sqler = new Sqler(table);
|
||||
List<Ltree> list = service.findTreeList(sqler, name, id);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联分类表-列表查询
|
||||
* @param name 案例名称
|
||||
* @return 案例列表数据
|
||||
*/
|
||||
@GetMapping("list")
|
||||
@SaCheckPermission("link:cate:query")
|
||||
public R<List<DemoLinkCate>> getList(String name) {
|
||||
Sqler sqler = new Sqler(table);
|
||||
sqler.addLike("t.name", name);
|
||||
sqler.addSelect("t.notes");
|
||||
List<DemoLinkCate> list = service.findList(sqler, DemoLinkCate.class);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联分类表-详情查询
|
||||
* @param id 案例ID
|
||||
* @return 案例对象
|
||||
*/
|
||||
@GetMapping("info/{id}")
|
||||
@SaCheckPermission("link:cate:query")
|
||||
public R<DemoLinkCate> info(@PathVariable Long id) {
|
||||
DemoLinkCate cate = service.select(id);
|
||||
return R.ok(cate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联分类表-新增
|
||||
* @param cate 案例对象
|
||||
* @return 案例ID
|
||||
*/
|
||||
@PostMapping
|
||||
@SaCheckPermission("link:cate:add")
|
||||
@Log(title = "综合树表案例", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS, message = "{repeat.submit.message}")
|
||||
public R<Long> post(@RequestBody DemoLinkCate cate) {
|
||||
return R.ok(null, service.insert(cate,table));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联分类表-修改
|
||||
* @param cate 案例对象
|
||||
* @return 案例ID
|
||||
*/
|
||||
@PutMapping
|
||||
@RepeatSubmit
|
||||
@SaCheckPermission("link:cate:edit")
|
||||
@Log(title = "关联分类表案例", businessType = BusinessType.UPDATE)
|
||||
public R<Long> put(@RequestBody DemoLinkCate cate) {
|
||||
return R.ok(null, service.update(cate, table));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联分类表-删除
|
||||
* @param ids 案例ID串
|
||||
* @return 删除的案例数量
|
||||
*/
|
||||
@DeleteMapping("{ids}")
|
||||
@SaCheckPermission("link:cate:remove")
|
||||
@Log(title = "关联分类表案例", businessType = BusinessType.DELETE)
|
||||
public R<Integer> delete(@PathVariable Long[] ids) {
|
||||
return R.ok(service.delete(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联分类表-移动
|
||||
* @param bo 移动对象
|
||||
*/
|
||||
@PostMapping("move")
|
||||
@SaCheckPermission("link:cate:edit")
|
||||
@Log(title = "关联分类表案例", businessType = BusinessType.OTHER)
|
||||
public R<Void> move(@RequestBody Lmove bo) {
|
||||
service.move(bo, table);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
private final DemoLinkCateService service;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package vben.jpa.demo.link.cate;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface DemoLinkCateRepo extends JpaRepository<DemoLinkCate,Long> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package vben.jpa.demo.link.cate;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import vben.common.jpa.service.BaseCateService;
|
||||
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DemoLinkCateService extends BaseCateService<DemoLinkCate> {
|
||||
|
||||
private final DemoLinkCateRepo repo;
|
||||
|
||||
@PostConstruct
|
||||
public void initDao() {
|
||||
super.setRepo(repo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package vben.jpa.demo.link.item;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 关联子表
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
@Schema(description = "关联子表")
|
||||
public class DemoLinkItem {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@Id
|
||||
@Schema(description = "主键ID")
|
||||
@Column(length = 32)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 主表ID
|
||||
*/
|
||||
@Schema(description = "主表ID")
|
||||
private Long maiid;
|
||||
|
||||
/**
|
||||
* 子项目名称
|
||||
*/
|
||||
@Column(length = 32)
|
||||
@Schema(description = "子项目名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
@Schema(description = "排序号")
|
||||
private Integer ornum;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注")
|
||||
private String notes;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package vben.jpa.demo.link.main;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import vben.common.jpa.entity.BaseMainEntity;
|
||||
import vben.common.jpa.entity.SysOrg;
|
||||
import vben.jpa.demo.link.item.DemoLinkItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 关联主表
|
||||
*/
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "关联主表")
|
||||
@Table(indexes = {@Index(columnList = "cruid"), @Index(columnList = "upuid")})
|
||||
public class DemoLinkMain extends BaseMainEntity {
|
||||
|
||||
/**
|
||||
* 所属分类ID
|
||||
*/
|
||||
@Schema(description = "所属分类ID")
|
||||
private Long catid;
|
||||
|
||||
/**
|
||||
* 行项目列表(OneToMany示例)
|
||||
*/
|
||||
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JoinColumn(name = "maiid")
|
||||
@OrderBy("ornum ASC")
|
||||
@Schema(description = "行项目列表")
|
||||
private List<DemoLinkItem> items = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 成员列表(ManyToMany示例)
|
||||
*/
|
||||
@ManyToMany
|
||||
@JoinTable(name = "demo_link_main_org", joinColumns = {@JoinColumn(name = "mid")},
|
||||
inverseJoinColumns = {@JoinColumn(name = "oid")})
|
||||
@Schema(description = "成员信息")
|
||||
private List<SysOrg> orgs;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package vben.jpa.demo.link.main;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import vben.common.core.domain.R;
|
||||
import vben.common.idempotent.annotation.RepeatSubmit;
|
||||
import vben.common.jdbc.dto.PageData;
|
||||
import vben.common.jdbc.sqler.Sqler;
|
||||
import vben.common.log.annotation.Log;
|
||||
import vben.common.log.enums.BusinessType;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 关联主表案例
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("demo/link/main")
|
||||
@RequiredArgsConstructor
|
||||
public class DemoLinkMainController {
|
||||
|
||||
/**
|
||||
* 关联主表-分页查询
|
||||
* @param name XX名称
|
||||
* @param catid 分类ID
|
||||
* @return XX分页数据
|
||||
*/
|
||||
@SaCheckPermission("link:main:query")
|
||||
@GetMapping
|
||||
public R<PageData> get(String name,Long catid) {
|
||||
Sqler sqler = new Sqler("demo_link_main");
|
||||
sqler.addLike("t.name", name);
|
||||
sqler.addSelect("t.notes");
|
||||
sqler.addEqual("t.catid", catid);
|
||||
sqler.addLeftJoin("c.name catna","demo_link_cate c","c.id=t.catid");
|
||||
return R.ok(service.findPageData(sqler));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联主表-详情查询
|
||||
* @param id ID
|
||||
* @return XX对象
|
||||
*/
|
||||
@SaCheckPermission("link:main:query")
|
||||
@GetMapping("info/{id}")
|
||||
public R<DemoLinkMain> info(@PathVariable Long id) {
|
||||
DemoLinkMain main = service.select(id);
|
||||
return R.ok(main);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联主表-新增
|
||||
* @param main XX对象
|
||||
* @return ID
|
||||
*/
|
||||
@SaCheckPermission("link:main:add")
|
||||
@Log(title = "关联主表案例", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS, message = "{repeat.submit.message}")
|
||||
@PostMapping
|
||||
public R<Long> post(@RequestBody DemoLinkMain main) {
|
||||
return R.ok(null,service.insert(main));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联主表-修改
|
||||
* @param main XX对象
|
||||
* @return ID
|
||||
*/
|
||||
@SaCheckPermission("link:main:edit")
|
||||
@Log(title = "关联主表案例", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit
|
||||
@PutMapping
|
||||
public R<Long> put(@RequestBody DemoLinkMain main) {
|
||||
return R.ok(null,service.update(main));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联主表-删除
|
||||
* @param ids ID串
|
||||
* @return 删除的XX数量
|
||||
*/
|
||||
@SaCheckPermission("link:main:remove")
|
||||
@Log(title = "关联主表案例", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("{ids}")
|
||||
public R<Integer> delete(@PathVariable Long[] ids) {
|
||||
return R.ok(service.delete(ids));
|
||||
}
|
||||
|
||||
private final DemoLinkMainService service;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package vben.jpa.demo.link.main;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface DemoLinkMainRepo extends JpaRepository<DemoLinkMain,Long> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package vben.jpa.demo.link.main;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import vben.common.jpa.service.BaseMainService;
|
||||
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DemoLinkMainService extends BaseMainService<DemoLinkMain> {
|
||||
|
||||
private final DemoLinkMainRepo repo;
|
||||
|
||||
@PostConstruct
|
||||
public void initDao() {
|
||||
super.setRepo(repo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package vben.jpa.demo.single.cate;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.Entity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import vben.common.jpa.entity.BaseCateEntity;
|
||||
|
||||
/**
|
||||
* 单一树表
|
||||
*/
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "单一树表")
|
||||
public class DemoSingleCate extends BaseCateEntity {
|
||||
|
||||
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
package vben.jpa.demo.single.cate;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import vben.common.core.domain.R;
|
||||
import vben.common.idempotent.annotation.RepeatSubmit;
|
||||
import vben.common.jdbc.dto.Ltree;
|
||||
import vben.common.jdbc.sqler.Sqler;
|
||||
import vben.common.log.annotation.Log;
|
||||
import vben.common.log.enums.BusinessType;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 单一树表案例
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("demo/single/cate")
|
||||
@RequiredArgsConstructor
|
||||
public class DemoSingleCateController {
|
||||
|
||||
private final String table = "demo_single_cate";
|
||||
|
||||
/**
|
||||
* 单一树表-树状查询
|
||||
* @param name XX名称
|
||||
* @param id 排除的ID
|
||||
* @return XX树状数据
|
||||
*/
|
||||
@GetMapping("tree")
|
||||
@SaCheckPermission("single:main:query")
|
||||
public R<List<Ltree>> getTree(String name, Long id) {
|
||||
Sqler sqler = new Sqler(table);
|
||||
List<Ltree> list = service.findTreeList(sqler, name, id);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一树表-列表查询
|
||||
* @param name XX名称
|
||||
* @return XX列表数据
|
||||
*/
|
||||
@GetMapping("list")
|
||||
@SaCheckPermission("single:main:query")
|
||||
public R<List<DemoSingleCate>> getList(String name) {
|
||||
Sqler sqler = new Sqler(table);
|
||||
sqler.addLike("t.name", name);
|
||||
sqler.addSelect("t.notes");
|
||||
List<DemoSingleCate> list = service.findList(sqler, DemoSingleCate.class);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一树表-详情查询
|
||||
* @param id ID
|
||||
* @return XX对象
|
||||
*/
|
||||
@SaCheckPermission("single:main:query")
|
||||
@GetMapping("info/{id}")
|
||||
public R<DemoSingleCate> info(@PathVariable Long id) {
|
||||
DemoSingleCate cate = service.select(id);
|
||||
return R.ok(cate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一树表-新增
|
||||
* @param cate XX对象
|
||||
* @return ID
|
||||
*/
|
||||
@PostMapping
|
||||
@SaCheckPermission("single:cate:add")
|
||||
@Log(title = "单一树表案例", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS, message = "{repeat.submit.message}")
|
||||
public R<Long> post(@RequestBody DemoSingleCate cate) {
|
||||
return R.ok(null, service.insert(cate,table));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一树表-修改
|
||||
* @param cate XX对象
|
||||
* @return ID
|
||||
*/
|
||||
@PutMapping
|
||||
@RepeatSubmit
|
||||
@SaCheckPermission("single:cate:edit")
|
||||
@Log(title = "单一树表案例", businessType = BusinessType.UPDATE)
|
||||
public R<Long> put(@RequestBody DemoSingleCate cate) {
|
||||
return R.ok(null, service.update(cate, table));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一树表-删除
|
||||
* @param ids ID串
|
||||
* @return 删除的XX数量
|
||||
*/
|
||||
@DeleteMapping("{ids}")
|
||||
@RepeatSubmit
|
||||
@SaCheckPermission("single:cate:delete")
|
||||
@Log(title = "单一树表案例", businessType = BusinessType.DELETE)
|
||||
public R<Integer> delete(@PathVariable Long[] ids) {
|
||||
return R.ok(service.delete(ids));
|
||||
}
|
||||
|
||||
private final DemoSingleCateService service;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package vben.jpa.demo.single.cate;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface DemoSingleCateRepo extends JpaRepository<DemoSingleCate,Long> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package vben.jpa.demo.single.cate;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import vben.common.jpa.service.BaseCateService;
|
||||
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DemoSingleCateService extends BaseCateService<DemoSingleCate> {
|
||||
|
||||
private final DemoSingleCateRepo repo;
|
||||
|
||||
@PostConstruct
|
||||
public void initDao() {
|
||||
super.setRepo(repo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package vben.jpa.demo.single.main;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.Entity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import vben.common.jpa.entity.BaseMainEntity;
|
||||
|
||||
/**
|
||||
* 单一主表
|
||||
*/
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "单一主表")
|
||||
public class DemoSingleMain extends BaseMainEntity {
|
||||
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
package vben.jpa.demo.single.main;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import vben.common.core.domain.R;
|
||||
import vben.common.idempotent.annotation.RepeatSubmit;
|
||||
import vben.common.jdbc.dto.PageData;
|
||||
import vben.common.jdbc.sqler.JdbcHelper;
|
||||
import vben.common.jdbc.sqler.Sqler;
|
||||
import vben.common.log.annotation.Log;
|
||||
import vben.common.log.enums.BusinessType;
|
||||
|
||||
/**
|
||||
* 单一主表案例
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("demo/single/main")
|
||||
@RequiredArgsConstructor
|
||||
public class DemoSingleMainController {
|
||||
|
||||
private final JdbcHelper jdbcHelper;
|
||||
|
||||
/**
|
||||
* 单一主表-分页查询
|
||||
* @param name XX名称
|
||||
* @return XX分页数据
|
||||
*/
|
||||
@GetMapping
|
||||
@SaCheckPermission("single:main:query")
|
||||
public R<PageData> get(String name) {
|
||||
Sqler sqler = new Sqler("demo_single_main");
|
||||
sqler.addLike("t.name", name);
|
||||
sqler.addSelect("t.notes");
|
||||
return R.ok(service.findPageData(sqler));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一主表-详情查询
|
||||
* @param id ID
|
||||
* @return XX对象
|
||||
*/
|
||||
@GetMapping("info/{id}")
|
||||
@SaCheckPermission("single:main:query")
|
||||
public R<DemoSingleMain> info(@PathVariable Long id) {
|
||||
DemoSingleMain main = service.select(id);
|
||||
return R.ok(main);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一主表-新增
|
||||
* @param main XX对象
|
||||
* @return ID
|
||||
*/
|
||||
@PostMapping
|
||||
@SaCheckPermission("single:main:add")
|
||||
@Log(title = "单一主表案例", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit
|
||||
// @RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS, message = "{repeat.submit.message}")
|
||||
public R<Long> post(@RequestBody DemoSingleMain main) {
|
||||
return R.ok(null,service.insert(main));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一主表-修改
|
||||
* @param main XX对象
|
||||
* @return ID
|
||||
*/
|
||||
@PutMapping
|
||||
@RepeatSubmit
|
||||
@SaCheckPermission("single:main:edit")
|
||||
@Log(title = "单一主表案例", businessType = BusinessType.UPDATE)
|
||||
public R<Long> put(@RequestBody DemoSingleMain main) {
|
||||
return R.ok(null,service.update(main));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一主表-删除
|
||||
* @param ids ID串
|
||||
* @return 删除的XX数量
|
||||
*/
|
||||
@DeleteMapping("{ids}")
|
||||
@SaCheckPermission("single:main:remove")
|
||||
@Log(title = "单一主表案例", businessType = BusinessType.DELETE)
|
||||
public R<Integer> delete(@PathVariable Long[] ids) {
|
||||
return R.ok(service.delete(ids));
|
||||
}
|
||||
|
||||
private final DemoSingleMainService service;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package vben.jpa.demo.single.main;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface DemoSingleMainRepo extends JpaRepository<DemoSingleMain,Long> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package vben.jpa.demo.single.main;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import vben.common.jpa.service.BaseMainService;
|
||||
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DemoSingleMainService extends BaseMainService<DemoSingleMain> {
|
||||
|
||||
private final DemoSingleMainRepo repo;
|
||||
|
||||
@PostConstruct
|
||||
public void initDao() {
|
||||
super.setRepo(repo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,12 +34,31 @@ spring:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
# 动态数据源文档 https://www.kancloud.cn/tracy5546/dynamic-datasource/content
|
||||
primary:
|
||||
dbType: mysql
|
||||
#mysql
|
||||
validationQuery: SELECT 1 FROM DUAL
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
jdbcUrl: jdbc:mysql://localhost:3306/vben-java?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||
username: root
|
||||
password: 123456
|
||||
|
||||
# validationQuery: SELECT 1 FROM DUAL
|
||||
# driverClassName: oracle.jdbc.OracleDriver
|
||||
# jdbcUrl: jdbc:oracle:thin:@localhost:1521:orcl
|
||||
# username:
|
||||
# password:
|
||||
|
||||
# validationQuery: SELECT 1
|
||||
# driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
# jdbcUrl: jdbc:sqlserver://localhost:1433;DatabaseName=vben-java;SelectMethod=cursor;encrypt=false;rewriteBatchedStatements=true
|
||||
# username:
|
||||
# password:
|
||||
|
||||
# validationQuery: SELECT 1
|
||||
# driverClassName: org.postgresql.Driver
|
||||
# jdbcUrl: jdbc:postgresql://localhost:5432/vben-java?useUnicode=true&characterEncoding=utf8&useSSL=true&autoReconnect=true&reWriteBatchedInserts=true
|
||||
# username:
|
||||
# password:
|
||||
|
||||
jpa:
|
||||
entityScan: vben
|
||||
hbm2ddl:
|
||||
|
||||
@@ -34,7 +34,6 @@ spring:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
# 动态数据源文档 https://www.kancloud.cn/tracy5546/dynamic-datasource/content
|
||||
primary:
|
||||
dbType: mysql
|
||||
validationQuery: SELECT 1 FROM DUAL
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
jdbcUrl: jdbc:mysql://localhost:3306/vben-java?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||
|
||||
@@ -25,25 +25,25 @@
|
||||
|
||||
<!-- <!– mp支持的数据库均支持 只需要增加对应的jdbc依赖即可 –>-->
|
||||
<!-- <!– Oracle –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.oracle.database.jdbc</groupId>-->
|
||||
<!-- <artifactId>ojdbc8</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.oracle.database.jdbc</groupId>
|
||||
<artifactId>ojdbc8</artifactId>
|
||||
</dependency>
|
||||
<!-- <!– 兼容oracle低版本 –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.oracle.database.nls</groupId>-->
|
||||
<!-- <artifactId>orai18n</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <!– PostgreSql –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.postgresql</groupId>-->
|
||||
<!-- <artifactId>postgresql</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
<!-- <!– SqlServer –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.microsoft.sqlserver</groupId>-->
|
||||
<!-- <artifactId>mssql-jdbc</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.microsoft.sqlserver</groupId>
|
||||
<artifactId>mssql-jdbc</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package vben.mybatis.demo.link.cate;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import vben.common.mybatis.core.domain.BaseCateEntity;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 关联分类表
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("demo_link_cate")
|
||||
public class DemoLinkCate extends BaseCateEntity {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
package vben.mybatis.demo.link.cate;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import vben.common.core.domain.R;
|
||||
import vben.common.core.utils.ValidatorUtils;
|
||||
import vben.common.core.validate.AddGroup;
|
||||
import vben.common.core.validate.EditGroup;
|
||||
import vben.common.idempotent.annotation.RepeatSubmit;
|
||||
import vben.common.jdbc.dto.Lmove;
|
||||
import vben.common.jdbc.dto.Ltree;
|
||||
import vben.common.jdbc.dto.PageData;
|
||||
import vben.common.jdbc.sqler.Sqler;
|
||||
import vben.common.log.annotation.Log;
|
||||
import vben.common.log.enums.BusinessType;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 关联树表案例
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("demo/link/cate")
|
||||
public class DemoLinkCateController {
|
||||
|
||||
private final DemoLinkCateService service;
|
||||
|
||||
private final String table = "demo_link_cate";
|
||||
|
||||
/**
|
||||
* 关联分类表-树状查询
|
||||
* @param name 案例名称
|
||||
* @param id 排除的案例ID
|
||||
* @return 案例树状数据
|
||||
*/
|
||||
@SaCheckPermission("link:cate:query")
|
||||
@GetMapping("tree")
|
||||
public R<List<Ltree>> getTree(String name, Long id) {
|
||||
Sqler sqler = new Sqler(table);
|
||||
List<Ltree> list = service.findTreeList(sqler, name, id);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联分类表-列表查询
|
||||
* @param name 案例名称
|
||||
* @return 案例列表数据
|
||||
*/
|
||||
@SaCheckPermission("link:cate:query")
|
||||
@GetMapping("list")
|
||||
public R<List<DemoLinkCate>> getList(String name) {
|
||||
Sqler sqler = new Sqler(table);
|
||||
sqler.addLike("t.name", name);
|
||||
sqler.addSelect("t.notes");
|
||||
List<DemoLinkCate> list = service.findList(sqler, DemoLinkCate.class);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联分类表-分页查询
|
||||
* @param name 案例名称
|
||||
* @return 案例分页数据
|
||||
*/
|
||||
@SaCheckPermission("link:cate:query")
|
||||
@GetMapping
|
||||
public R<PageData> get(String name) {
|
||||
Sqler sqler = new Sqler("demo_easy_main");
|
||||
sqler.addLike("t.name", name);
|
||||
sqler.addSelect("t.notes");
|
||||
sqler.selectCUinfo();
|
||||
return R.ok(service.findPageData(sqler));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联分类表-详情查询
|
||||
* @param id 案例ID
|
||||
* @return 案例对象
|
||||
*/
|
||||
@SaCheckPermission("link:cate:query")
|
||||
@GetMapping("info/{id}")
|
||||
public R<DemoLinkCate> info(@PathVariable("id") Long id) {
|
||||
return R.ok(service.select(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联分类表-新增
|
||||
* @param cate 案例对象
|
||||
* @return 案例ID
|
||||
*/
|
||||
@SaCheckPermission("link:cate:add")
|
||||
@Log(title = "综合树表案例", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS, message = "{repeat.submit.message}")
|
||||
@PostMapping
|
||||
public R<Long> post(@RequestBody DemoLinkCate cate) {
|
||||
ValidatorUtils.validate(cate, AddGroup.class);
|
||||
return R.ok(null,service.insert(cate,table));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联分类表-修改
|
||||
* @param cate 案例对象
|
||||
* @return 案例ID
|
||||
*/
|
||||
@SaCheckPermission("link:cate:edit")
|
||||
@Log(title = "关联分类表", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit
|
||||
@PutMapping
|
||||
public R<Long> put(@Validated(EditGroup.class) @RequestBody DemoLinkCate cate) {
|
||||
return R.ok(null, service.update(cate, table));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联分类表-删除
|
||||
* @param ids 案例ID串
|
||||
* @return 删除的案例数量
|
||||
*/
|
||||
@SaCheckPermission("link:cate:remove")
|
||||
@Log(title = "关联分类表", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("{ids}")
|
||||
public R<Integer> delete(@PathVariable Long[] ids) {
|
||||
return R.ok(null,service.delete(Arrays.asList(ids)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联分类表-移动
|
||||
* @param bo 移动对象
|
||||
*/
|
||||
@PostMapping("move")
|
||||
@Log(title = "关联分类表", businessType = BusinessType.UPDATE)
|
||||
public R<Void> move(@RequestBody Lmove bo) {
|
||||
service.move(bo, table);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package vben.mybatis.demo.link.cate;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface DemoLinkCateMapper extends BaseMapper<DemoLinkCate> {
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package vben.mybatis.demo.link.cate;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import vben.common.mybatis.core.service.BaseCateService;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DemoLinkCateService extends BaseCateService<DemoLinkCate> {
|
||||
|
||||
private final DemoLinkCateMapper mapper;
|
||||
|
||||
@PostConstruct
|
||||
public void initDao() {
|
||||
super.setMapper(mapper);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package vben.mybatis.demo.link.item;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 关联子表
|
||||
*/
|
||||
@Data
|
||||
@TableName("demo_link_item")
|
||||
public class DemoLinkItem {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 主表ID
|
||||
*/
|
||||
private Long maiid;
|
||||
|
||||
/**
|
||||
* 子项目名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
private Integer ornum;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String notes;
|
||||
|
||||
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package vben.mybatis.demo.link.item;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface DemoLinkItemMapper extends BaseMapper<DemoLinkItem> {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package vben.mybatis.demo.link.main;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import vben.common.mybatis.core.domain.BaseMainEntity;
|
||||
import vben.common.mybatis.core.domain.SysOrg;
|
||||
import vben.mybatis.demo.link.item.DemoLinkItem;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 关联主表
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("demo_link_main")
|
||||
public class DemoLinkMain extends BaseMainEntity {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 分类ID
|
||||
*/
|
||||
private String catid;
|
||||
|
||||
/**
|
||||
* 行项目列表
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private List<DemoLinkItem> items = new ArrayList<>();
|
||||
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<SysOrg> orgs;
|
||||
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package vben.mybatis.demo.link.main;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import vben.common.core.domain.R;
|
||||
import vben.common.idempotent.annotation.RepeatSubmit;
|
||||
import vben.common.jdbc.dto.PageData;
|
||||
import vben.common.jdbc.sqler.Sqler;
|
||||
import vben.common.log.annotation.Log;
|
||||
import vben.common.log.enums.BusinessType;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 关联主表案例
|
||||
*
|
||||
* @author baby_fox
|
||||
* @date 2025-11-29
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("demo/link/main")
|
||||
public class DemoLinkMainController {
|
||||
|
||||
private final DemoLinkMainService service;
|
||||
|
||||
/**
|
||||
* 关联主表-分页查询
|
||||
* @param name XX名称
|
||||
* @param catid 分类ID
|
||||
* @return XX分页数据
|
||||
*/
|
||||
@SaCheckPermission("link:main:query")
|
||||
@GetMapping
|
||||
public R<PageData> get(String name,Long catid) {
|
||||
Sqler sqler = new Sqler("demo_link_main");
|
||||
sqler.addLike("t.name", name);
|
||||
sqler.addSelect("t.notes");
|
||||
sqler.addEqual("t.catid", catid);
|
||||
sqler.addLeftJoin("c.name catna","demo_link_cate c","c.id=t.catid");
|
||||
return R.ok(service.findPageData(sqler));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联主表-详情查询
|
||||
* @param id ID
|
||||
* @return XX对象
|
||||
*/
|
||||
@SaCheckPermission("link:main:query")
|
||||
@GetMapping("info/{id}")
|
||||
public R<DemoLinkMain> info(@NotNull(message = "主键不能为空")
|
||||
@PathVariable("id") Long id) {
|
||||
return R.ok(service.selectx(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联主表-新增
|
||||
* @param main XX对象
|
||||
* @return ID
|
||||
*/
|
||||
@SaCheckPermission("link:main:add")
|
||||
@Log(title = "关联主表", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS, message = "{repeat.submit.message}")
|
||||
@PostMapping
|
||||
public R<Long> post(@RequestBody DemoLinkMain main) {
|
||||
return R.ok(null,service.insertx(main));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联主表-修改
|
||||
* @param main XX对象
|
||||
* @return ID
|
||||
*/
|
||||
@SaCheckPermission("link:main:edit")
|
||||
@Log(title = "关联主表", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit
|
||||
@PutMapping
|
||||
public R<Long> put(@RequestBody DemoLinkMain main) {
|
||||
return R.ok(null,service.updatex(main));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联主表-删除
|
||||
* @param ids ID串
|
||||
* @return 删除的XX数量
|
||||
*/
|
||||
@SaCheckPermission("link:main:remove")
|
||||
@Log(title = "关联主表", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("{ids}")
|
||||
public R<Integer> delete(@PathVariable Long[] ids) {
|
||||
return R.ok(null,service.deletex(Arrays.asList(ids)));
|
||||
}
|
||||
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package vben.mybatis.demo.link.main;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface DemoLinkMainMapper extends BaseMapper<DemoLinkMain> {
|
||||
|
||||
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package vben.mybatis.demo.link.main;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import icu.mhb.mybatisplus.plugln.extend.Joins;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import vben.common.mybatis.core.domain.SysOrg;
|
||||
import vben.common.mybatis.core.service.BaseMainService;
|
||||
import vben.mybatis.demo.link.item.DemoLinkItem;
|
||||
import vben.mybatis.demo.link.item.DemoLinkItemMapper;
|
||||
import vben.mybatis.demo.link.mid.DemoLinkMainOrg;
|
||||
import vben.mybatis.demo.link.mid.DemoLinkMainOrgMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DemoLinkMainService extends BaseMainService<DemoLinkMain> {
|
||||
|
||||
private final DemoLinkMainMapper mapper;
|
||||
|
||||
private final DemoLinkItemMapper itemMapper;
|
||||
|
||||
private final DemoLinkMainOrgMapper midMapper;
|
||||
|
||||
@PostConstruct
|
||||
public void initDao() {
|
||||
super.setMapper(mapper);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public DemoLinkMain selectx(Long id) {
|
||||
DemoLinkMain main = select(id);
|
||||
//一对多关联查询
|
||||
main.setItems(itemMapper.selectList(new LambdaQueryWrapper<DemoLinkItem>().eq(DemoLinkItem::getMaiid, main.getId())));
|
||||
//多对多关联查询
|
||||
List<SysOrg> list = Joins.of(SysOrg.class)
|
||||
.leftJoin(DemoLinkMainOrg.class,DemoLinkMainOrg::getOid,SysOrg::getId)
|
||||
.eq(DemoLinkMainOrg::getMid,id).end()
|
||||
.joinList(SysOrg.class);
|
||||
main.setOrgs(list);
|
||||
return main;
|
||||
}
|
||||
|
||||
public Long insertx(DemoLinkMain main) {
|
||||
insert(main);
|
||||
for (DemoLinkItem item : main.getItems()) {
|
||||
item.setMaiid(main.getId());
|
||||
itemMapper.insert(item);
|
||||
}
|
||||
for (SysOrg sysOrg : main.getOrgs()) {
|
||||
DemoLinkMainOrg mid = new DemoLinkMainOrg(main.getId(),sysOrg.getId());
|
||||
midMapper.insert(mid);
|
||||
}
|
||||
return main.getId();
|
||||
}
|
||||
|
||||
public Long updatex(DemoLinkMain main) {
|
||||
//先删
|
||||
itemMapper.delete(new LambdaQueryWrapper<DemoLinkItem>().eq(DemoLinkItem::getMaiid, main.getId()));
|
||||
midMapper.delete(new LambdaQueryWrapper<DemoLinkMainOrg>().eq(DemoLinkMainOrg::getMid, main.getId()));
|
||||
//后增
|
||||
update(main);
|
||||
for (DemoLinkItem item : main.getItems()) {
|
||||
itemMapper.insert(item);
|
||||
}
|
||||
for (SysOrg sysOrg : main.getOrgs()) {
|
||||
DemoLinkMainOrg mid = new DemoLinkMainOrg(main.getId(),sysOrg.getId());
|
||||
midMapper.insert(mid);
|
||||
}
|
||||
return main.getId();
|
||||
}
|
||||
|
||||
public Integer deletex(List<Long> list) {
|
||||
itemMapper.delete(new LambdaQueryWrapper<DemoLinkItem>().in(DemoLinkItem::getMaiid, list));
|
||||
midMapper.delete(new LambdaQueryWrapper<DemoLinkMainOrg>().in(DemoLinkMainOrg::getMid, list));
|
||||
return delete(list);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package vben.mybatis.demo.link.mid;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode
|
||||
@TableName("demo_link_main_org")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DemoLinkMainOrg {
|
||||
|
||||
private Long mid;
|
||||
|
||||
private String oid;
|
||||
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package vben.mybatis.demo.link.mid;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface DemoLinkMainOrgMapper extends BaseMapper<DemoLinkMainOrg> {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package vben.mybatis.demo.ruoyi;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.idev.excel.context.AnalysisContext;
|
||||
import vben.common.core.utils.ValidatorUtils;
|
||||
import vben.common.core.validate.AddGroup;
|
||||
import vben.common.core.validate.EditGroup;
|
||||
import vben.common.excel.core.DefaultExcelListener;
|
||||
import vben.common.excel.core.DropDownOptions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Excel带下拉框的解析处理器
|
||||
*
|
||||
* @author Emil.Zhang
|
||||
*/
|
||||
public class ExportDemoListener extends DefaultExcelListener<ExportDemoVo> {
|
||||
|
||||
public ExportDemoListener() {
|
||||
// 显示使用构造函数,否则将导致空指针
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(ExportDemoVo data, AnalysisContext context) {
|
||||
// 先校验必填
|
||||
ValidatorUtils.validate(data, AddGroup.class);
|
||||
|
||||
// 处理级联下拉的部分
|
||||
String province = data.getProvince();
|
||||
String city = data.getCity();
|
||||
String area = data.getArea();
|
||||
// 本行用户选择的省
|
||||
List<String> thisRowSelectedProvinceOption = DropDownOptions.analyzeOptionValue(province);
|
||||
if (thisRowSelectedProvinceOption.size() == 2) {
|
||||
String provinceIdStr = thisRowSelectedProvinceOption.get(1);
|
||||
if (NumberUtil.isNumber(provinceIdStr)) {
|
||||
// 严格要求数据的话可以在这里做与数据库相关的判断
|
||||
// 例如判断省信息是否在数据库中存在等,建议结合RedisCache做缓存10s,减少数据库调用
|
||||
data.setProvinceId(Integer.parseInt(provinceIdStr));
|
||||
}
|
||||
}
|
||||
// 本行用户选择的市
|
||||
List<String> thisRowSelectedCityOption = DropDownOptions.analyzeOptionValue(city);
|
||||
if (thisRowSelectedCityOption.size() == 2) {
|
||||
String cityIdStr = thisRowSelectedCityOption.get(1);
|
||||
if (NumberUtil.isNumber(cityIdStr)) {
|
||||
data.setCityId(Integer.parseInt(cityIdStr));
|
||||
}
|
||||
}
|
||||
// 本行用户选择的县
|
||||
List<String> thisRowSelectedAreaOption = DropDownOptions.analyzeOptionValue(area);
|
||||
if (thisRowSelectedAreaOption.size() == 2) {
|
||||
String areaIdStr = thisRowSelectedAreaOption.get(1);
|
||||
if (NumberUtil.isNumber(areaIdStr)) {
|
||||
data.setAreaId(Integer.parseInt(areaIdStr));
|
||||
}
|
||||
}
|
||||
|
||||
// 处理完毕以后判断是否符合规则
|
||||
ValidatorUtils.validate(data, EditGroup.class);
|
||||
|
||||
// 添加到处理结果中
|
||||
getExcelResult().getList().add(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package vben.mybatis.demo.ruoyi;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import vben.common.core.enums.UserStatus;
|
||||
import vben.common.core.validate.AddGroup;
|
||||
import vben.common.core.validate.EditGroup;
|
||||
import vben.common.excel.annotation.ExcelDictFormat;
|
||||
import vben.common.excel.annotation.ExcelEnumFormat;
|
||||
import vben.common.excel.convert.ExcelDictConvert;
|
||||
import vben.common.excel.convert.ExcelEnumConvert;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 带有下拉选的Excel导出
|
||||
*
|
||||
* @author Emil.Zhang
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ExportDemoVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
@ExcelProperty(value = "用户名", index = 0)
|
||||
@NotEmpty(message = "用户名不能为空", groups = AddGroup.class)
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 用户类型
|
||||
* </p>
|
||||
* 使用ExcelEnumFormat注解需要进行下拉选的部分
|
||||
*/
|
||||
@ExcelProperty(value = "用户类型", index = 1, converter = ExcelEnumConvert.class)
|
||||
@ExcelEnumFormat(enumClass = UserStatus.class, textField = "info")
|
||||
@NotEmpty(message = "用户类型不能为空", groups = AddGroup.class)
|
||||
private String userStatus;
|
||||
|
||||
/**
|
||||
* 性别
|
||||
* <p>
|
||||
* 使用ExcelDictFormat注解需要进行下拉选的部分
|
||||
*/
|
||||
@ExcelProperty(value = "性别", index = 2, converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(dictType = "sys_user_sex")
|
||||
@NotEmpty(message = "性别不能为空", groups = AddGroup.class)
|
||||
private String gender;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
@ExcelProperty(value = "手机号", index = 3)
|
||||
@NotEmpty(message = "手机号不能为空", groups = AddGroup.class)
|
||||
private String phoneNumber;
|
||||
|
||||
/**
|
||||
* Email
|
||||
*/
|
||||
@ExcelProperty(value = "Email", index = 4)
|
||||
@NotEmpty(message = "Email不能为空", groups = AddGroup.class)
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 省
|
||||
* <p>
|
||||
* 级联下拉,仅判断是否选了
|
||||
*/
|
||||
@ExcelProperty(value = "省", index = 5)
|
||||
@NotNull(message = "省不能为空", groups = AddGroup.class)
|
||||
private String province;
|
||||
|
||||
/**
|
||||
* 数据库中的省ID
|
||||
* </p>
|
||||
* 处理完毕后再判断是否市正确的值
|
||||
*/
|
||||
@NotNull(message = "请勿手动输入", groups = EditGroup.class)
|
||||
private Integer provinceId;
|
||||
|
||||
/**
|
||||
* 市
|
||||
* <p>
|
||||
* 级联下拉
|
||||
*/
|
||||
@ExcelProperty(value = "市", index = 6)
|
||||
@NotNull(message = "市不能为空", groups = AddGroup.class)
|
||||
private String city;
|
||||
|
||||
/**
|
||||
* 数据库中的市ID
|
||||
*/
|
||||
@NotNull(message = "请勿手动输入", groups = EditGroup.class)
|
||||
private Integer cityId;
|
||||
|
||||
/**
|
||||
* 县
|
||||
* <p>
|
||||
* 级联下拉
|
||||
*/
|
||||
@ExcelProperty(value = "县", index = 7)
|
||||
@NotNull(message = "县不能为空", groups = AddGroup.class)
|
||||
private String area;
|
||||
|
||||
/**
|
||||
* 数据库中的县ID
|
||||
*/
|
||||
@NotNull(message = "请勿手动输入", groups = EditGroup.class)
|
||||
private Integer areaId;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package vben.mybatis.demo.ruoyi;
|
||||
|
||||
|
||||
import vben.common.mybatis.core.page.PageQuery;
|
||||
import vben.common.mybatis.core.page.TableDataInfo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 测试单表Service接口
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-07-26
|
||||
*/
|
||||
public interface ITestDemoService {
|
||||
|
||||
/**
|
||||
* 查询单个
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
TestDemoVo queryById(Long id);
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
*/
|
||||
TableDataInfo<TestDemoVo> queryPageList(TestDemoBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 自定义分页查询
|
||||
*/
|
||||
TableDataInfo<TestDemoVo> customPageList(TestDemoBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
*/
|
||||
List<TestDemoVo> queryList(TestDemoBo bo);
|
||||
|
||||
/**
|
||||
* 根据新增业务对象插入测试单表
|
||||
*
|
||||
* @param bo 测试单表新增业务对象
|
||||
* @return
|
||||
*/
|
||||
Boolean insertByBo(TestDemoBo bo);
|
||||
|
||||
/**
|
||||
* 根据编辑业务对象修改测试单表
|
||||
*
|
||||
* @param bo 测试单表编辑业务对象
|
||||
* @return
|
||||
*/
|
||||
Boolean updateByBo(TestDemoBo bo);
|
||||
|
||||
/**
|
||||
* 校验并删除数据
|
||||
*
|
||||
* @param ids 主键集合
|
||||
* @param isValid 是否校验,true-删除前校验,false-不校验
|
||||
* @return
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 批量保存
|
||||
*/
|
||||
Boolean saveBatch(List<TestDemo> list);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package vben.mybatis.demo.ruoyi;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import vben.common.mybatis.core.domain.BaseEntity;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 测试单表对象 test_demo
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-07-26
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("test_demo")
|
||||
public class TestDemo extends BaseEntity {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 部门id
|
||||
*/
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
@OrderBy(asc = false, sort = 1)
|
||||
private Integer orderNum;
|
||||
|
||||
/**
|
||||
* key键
|
||||
*/
|
||||
private String testKey;
|
||||
|
||||
/**
|
||||
* 值
|
||||
*/
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* 版本
|
||||
*/
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
/**
|
||||
* 删除标志
|
||||
*/
|
||||
@TableLogic
|
||||
private Long delFlag;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package vben.mybatis.demo.ruoyi;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import vben.common.core.validate.AddGroup;
|
||||
import vben.common.core.validate.EditGroup;
|
||||
import vben.common.mybatis.core.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 测试单表业务对象 test_demo
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-07-26
|
||||
*/
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AutoMapper(target = TestDemo.class, reverseConvertGenerate = false)
|
||||
public class TestDemoBo extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@NotNull(message = "主键不能为空", groups = {EditGroup.class})
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 部门id
|
||||
*/
|
||||
@NotNull(message = "部门id不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@NotNull(message = "用户id不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
@NotNull(message = "排序号不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private Integer orderNum;
|
||||
|
||||
/**
|
||||
* key键
|
||||
*/
|
||||
@NotBlank(message = "key键不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String testKey;
|
||||
|
||||
/**
|
||||
* 值
|
||||
*/
|
||||
@NotBlank(message = "值不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* 版本
|
||||
*/
|
||||
private Long version;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package vben.mybatis.demo.ruoyi;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import vben.common.core.domain.R;
|
||||
import vben.common.core.utils.MapstructUtils;
|
||||
import vben.common.core.utils.ValidatorUtils;
|
||||
import vben.common.core.validate.AddGroup;
|
||||
import vben.common.core.validate.EditGroup;
|
||||
import vben.common.core.validate.QueryGroup;
|
||||
import vben.common.excel.core.ExcelResult;
|
||||
import vben.common.excel.utils.ExcelUtil;
|
||||
import vben.common.idempotent.annotation.RepeatSubmit;
|
||||
import vben.common.log.annotation.Log;
|
||||
import vben.common.log.enums.BusinessType;
|
||||
import vben.common.mybatis.core.page.PageQuery;
|
||||
import vben.common.mybatis.core.page.TableDataInfo;
|
||||
import vben.common.web.core.BaseController;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 测试单表Controller
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-07-26
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/demo/demo")
|
||||
public class TestDemoController extends BaseController {
|
||||
|
||||
private final ITestDemoService testDemoService;
|
||||
|
||||
/**
|
||||
* 查询测试单表列表
|
||||
*/
|
||||
@SaCheckPermission("demo:demo:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<TestDemoVo> list(@Validated(QueryGroup.class) TestDemoBo bo, PageQuery pageQuery) {
|
||||
return testDemoService.queryPageList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义分页查询
|
||||
*/
|
||||
@SaCheckPermission("demo:demo:list")
|
||||
@GetMapping("/page")
|
||||
public TableDataInfo<TestDemoVo> page(@Validated(QueryGroup.class) TestDemoBo bo, PageQuery pageQuery) {
|
||||
return testDemoService.customPageList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
*
|
||||
* @param file 导入文件
|
||||
*/
|
||||
@Log(title = "测试单表", businessType = BusinessType.IMPORT)
|
||||
@SaCheckPermission("demo:demo:import")
|
||||
@PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public R<Void> importData(@RequestPart("file") MultipartFile file) throws Exception {
|
||||
ExcelResult<TestDemoImportVo> excelResult = ExcelUtil.importExcel(file.getInputStream(), TestDemoImportVo.class, true);
|
||||
List<TestDemo> list = MapstructUtils.convert(excelResult.getList(), TestDemo.class);
|
||||
testDemoService.saveBatch(list);
|
||||
return R.ok(excelResult.getAnalysis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出测试单表列表
|
||||
*/
|
||||
@SaCheckPermission("demo:demo:export")
|
||||
@Log(title = "测试单表", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(@Validated TestDemoBo bo, HttpServletResponse response) {
|
||||
List<TestDemoVo> list = testDemoService.queryList(bo);
|
||||
// 测试雪花id导出
|
||||
// for (TestDemoVo vo : list) {
|
||||
// vo.setId(1234567891234567893L);
|
||||
// }
|
||||
ExcelUtil.exportExcel(list, "测试单表", TestDemoVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取测试单表详细信息
|
||||
*
|
||||
* @param id 测试ID
|
||||
*/
|
||||
@SaCheckPermission("demo:demo:query")
|
||||
@GetMapping("/{id}")
|
||||
public R<TestDemoVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable("id") Long id) {
|
||||
return R.ok(testDemoService.queryById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增测试单表
|
||||
*/
|
||||
@SaCheckPermission("demo:demo:add")
|
||||
@Log(title = "测试单表", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS, message = "{repeat.submit.message}")
|
||||
@PostMapping()
|
||||
public R<Void> add(@RequestBody TestDemoBo bo) {
|
||||
// 使用校验工具对标 @Validated(AddGroup.class) 注解
|
||||
// 用于在非 Controller 的地方校验对象
|
||||
ValidatorUtils.validate(bo, AddGroup.class);
|
||||
return toAjax(testDemoService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改测试单表
|
||||
*/
|
||||
@SaCheckPermission("demo:demo:edit")
|
||||
@Log(title = "测试单表", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit
|
||||
@PutMapping()
|
||||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody TestDemoBo bo) {
|
||||
return toAjax(testDemoService.updateByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除测试单表
|
||||
*
|
||||
* @param ids 测试ID串
|
||||
*/
|
||||
@SaCheckPermission("demo:demo:remove")
|
||||
@Log(title = "测试单表", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Long[] ids) {
|
||||
return toAjax(testDemoService.deleteWithValidByIds(Arrays.asList(ids), true));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package vben.mybatis.demo.ruoyi;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 测试单表业务对象 test_demo
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-07-26
|
||||
*/
|
||||
@Data
|
||||
public class TestDemoImportVo {
|
||||
|
||||
/**
|
||||
* 部门id
|
||||
*/
|
||||
@NotNull(message = "部门id不能为空")
|
||||
@ExcelProperty(value = "部门id")
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@NotNull(message = "用户id不能为空")
|
||||
@ExcelProperty(value = "用户id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
@NotNull(message = "排序号不能为空")
|
||||
@ExcelProperty(value = "排序号")
|
||||
private Long orderNum;
|
||||
|
||||
/**
|
||||
* key键
|
||||
*/
|
||||
@NotBlank(message = "key键不能为空")
|
||||
@ExcelProperty(value = "key键")
|
||||
private String testKey;
|
||||
|
||||
/**
|
||||
* 值
|
||||
*/
|
||||
@NotBlank(message = "值不能为空")
|
||||
@ExcelProperty(value = "值")
|
||||
private String value;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package vben.mybatis.demo.ruoyi;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import vben.common.mybatis.annotation.DataColumn;
|
||||
import vben.common.mybatis.annotation.DataPermission;
|
||||
import vben.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 测试单表Mapper接口
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-07-26
|
||||
*/
|
||||
@Mapper
|
||||
public interface TestDemoMapper extends BaseMapperPlus<TestDemo, TestDemoVo> {
|
||||
|
||||
@DataPermission({
|
||||
@DataColumn(key = "deptName", value = "dept_id"),
|
||||
@DataColumn(key = "userName", value = "user_id")
|
||||
})
|
||||
Page<TestDemoVo> customPageList(@Param("page") Page<TestDemo> page, @Param("ew") Wrapper<TestDemo> wrapper);
|
||||
|
||||
@Override
|
||||
@DataPermission({
|
||||
@DataColumn(key = "deptName", value = "dept_id"),
|
||||
@DataColumn(key = "userName", value = "user_id")
|
||||
})
|
||||
default <P extends IPage<TestDemoVo>> P selectVoPage(IPage<TestDemo> page, Wrapper<TestDemo> wrapper) {
|
||||
return selectVoPage(page, wrapper, this.currentVoClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
@DataPermission({
|
||||
@DataColumn(key = "deptName", value = "dept_id"),
|
||||
@DataColumn(key = "userName", value = "user_id")
|
||||
})
|
||||
default List<TestDemoVo> selectVoList(Wrapper<TestDemo> wrapper) {
|
||||
return selectVoList(wrapper, this.currentVoClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
@DataPermission(value = {
|
||||
@DataColumn(key = "deptName", value = "dept_id"),
|
||||
@DataColumn(key = "userName", value = "user_id")
|
||||
}, joinStr = "AND")
|
||||
List<TestDemo> selectByIds(@Param(Constants.COLL) Collection<? extends Serializable> idList);
|
||||
|
||||
@Override
|
||||
@DataPermission({
|
||||
@DataColumn(key = "deptName", value = "dept_id"),
|
||||
@DataColumn(key = "userName", value = "user_id")
|
||||
})
|
||||
int updateById(@Param(Constants.ENTITY) TestDemo entity);
|
||||
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
package vben.mybatis.demo.ruoyi;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import vben.common.core.exception.ServiceException;
|
||||
import vben.common.core.utils.MapstructUtils;
|
||||
import vben.common.core.utils.StrUtils;
|
||||
import vben.common.mybatis.core.page.PageQuery;
|
||||
import vben.common.mybatis.core.page.TableDataInfo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 测试单表Service业务层处理
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-07-26
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class TestDemoServiceImpl implements ITestDemoService {
|
||||
|
||||
private final TestDemoMapper baseMapper;
|
||||
|
||||
@Override
|
||||
public TestDemoVo queryById(Long id) {
|
||||
return baseMapper.selectVoById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo<TestDemoVo> queryPageList(TestDemoBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<TestDemo> lqw = buildQueryWrapper(bo);
|
||||
Page<TestDemoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义分页查询
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<TestDemoVo> customPageList(TestDemoBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<TestDemo> lqw = buildQueryWrapper(bo);
|
||||
Page<TestDemoVo> result = baseMapper.customPageList(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TestDemoVo> queryList(TestDemoBo bo) {
|
||||
return baseMapper.selectVoList(buildQueryWrapper(bo));
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<TestDemo> buildQueryWrapper(TestDemoBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<TestDemo> lqw = Wrappers.lambdaQuery();
|
||||
lqw.like(StrUtils.isNotBlank(bo.getTestKey()), TestDemo::getTestKey, bo.getTestKey());
|
||||
lqw.eq(StrUtils.isNotBlank(bo.getValue()), TestDemo::getValue, bo.getValue());
|
||||
lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null,
|
||||
TestDemo::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime"));
|
||||
lqw.orderByAsc(TestDemo::getId);
|
||||
return lqw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean insertByBo(TestDemoBo bo) {
|
||||
TestDemo add = MapstructUtils.convert(bo, TestDemo.class);
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setId(add.getId());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateByBo(TestDemoBo bo) {
|
||||
TestDemo update = MapstructUtils.convert(bo, TestDemo.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*
|
||||
* @param entity 实体类数据
|
||||
*/
|
||||
private void validEntityBeforeSave(TestDemo entity) {
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
// 做一些业务上的校验,判断是否需要校验
|
||||
List<TestDemo> list = baseMapper.selectByIds(ids);
|
||||
if (list.size() != ids.size()) {
|
||||
throw new ServiceException("您没有删除权限!");
|
||||
}
|
||||
}
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean saveBatch(List<TestDemo> list) {
|
||||
return baseMapper.insertBatch(list);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package vben.mybatis.demo.ruoyi;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import cn.idev.excel.annotation.format.DateTimeFormat;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
import vben.common.excel.annotation.ExcelNotation;
|
||||
import vben.common.excel.annotation.ExcelRequired;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* 测试单表视图对象 test_demo
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-07-26
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@AutoMapper(target = TestDemo.class)
|
||||
public class TestDemoVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@ExcelProperty(value = "主键")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 部门id
|
||||
*/
|
||||
@ExcelRequired
|
||||
@ExcelProperty(value = "部门id")
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@ExcelRequired
|
||||
@ExcelProperty(value = "用户id", index = 5)
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
@ExcelRequired
|
||||
@ExcelProperty(value = "排序号")
|
||||
private Integer orderNum;
|
||||
|
||||
/**
|
||||
* key键
|
||||
*/
|
||||
@ExcelNotation(value = "测试key")
|
||||
@ExcelProperty(value = "key键")
|
||||
private String testKey;
|
||||
|
||||
/**
|
||||
* 值
|
||||
*/
|
||||
@ExcelNotation(value = "测试value")
|
||||
@ExcelProperty(value = "值")
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@ExcelRequired
|
||||
@DateTimeFormat("yyyy-MM-dd HH:mm:ss")
|
||||
@ExcelProperty(value = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@ExcelProperty(value = "创建人")
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 创建人账号
|
||||
*/
|
||||
// @Translation(type = TransConstant.USER_ID_TO_NAME, mapper = "createBy")
|
||||
@ExcelProperty(value = "创建人账号")
|
||||
private String createByName;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@ExcelProperty(value = "更新时间")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@ExcelProperty(value = "更新人")
|
||||
private Long updateBy;
|
||||
|
||||
/**
|
||||
* 更新人账号
|
||||
*/
|
||||
// @Translation(type = TransConstant.USER_ID_TO_NAME, mapper = "updateBy")
|
||||
@ExcelProperty(value = "更新人账号")
|
||||
private String updateByName;
|
||||
|
||||
/**
|
||||
* 版本
|
||||
*/
|
||||
private Long version;
|
||||
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package vben.mybatis.demo.single.cate;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import vben.common.mybatis.core.domain.BaseCateEntity;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 单一树表
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("demo_single_cate")
|
||||
public class DemoSingleCate extends BaseCateEntity {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
package vben.mybatis.demo.single.cate;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import vben.common.core.domain.R;
|
||||
import vben.common.core.utils.ValidatorUtils;
|
||||
import vben.common.core.validate.AddGroup;
|
||||
import vben.common.core.validate.EditGroup;
|
||||
import vben.common.idempotent.annotation.RepeatSubmit;
|
||||
import vben.common.jdbc.dto.Ltree;
|
||||
import vben.common.jdbc.dto.PageData;
|
||||
import vben.common.jdbc.sqler.JdbcHelper;
|
||||
import vben.common.jdbc.sqler.Sqler;
|
||||
import vben.common.log.annotation.Log;
|
||||
import vben.common.log.enums.BusinessType;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 单一树表案例
|
||||
*
|
||||
* @author baby_fox
|
||||
* @date 2025-11-29
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("demo/single/cate")
|
||||
public class DemoSingleCateController {
|
||||
|
||||
private final DemoSingleCateService service;
|
||||
|
||||
private final JdbcHelper jdbcHelper;
|
||||
|
||||
private final String table = "demo_single_cate";
|
||||
|
||||
/**
|
||||
* 单一树表-树状查询
|
||||
* @param name XX名称
|
||||
* @param id 排除的ID
|
||||
* @return XX树状数据
|
||||
*/
|
||||
@SaCheckPermission("single:cate:query")
|
||||
@GetMapping("tree")
|
||||
public R<List<Ltree>> getTree(String name, Long id) {
|
||||
Sqler sqler = new Sqler(table);
|
||||
List<Ltree> list = service.findTreeList(sqler, name, id);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一树表-列表查询
|
||||
* @param name XX名称
|
||||
* @return XX列表数据
|
||||
*/
|
||||
@SaCheckPermission("single:cate:query")
|
||||
@GetMapping("list")
|
||||
public R<List<DemoSingleCate>> getList(String name) {
|
||||
Sqler sqler = new Sqler(table);
|
||||
sqler.addLike("t.name", name);
|
||||
sqler.addSelect("t.notes");
|
||||
List<DemoSingleCate> list = service.findList(sqler, DemoSingleCate.class);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一树表-分页查询
|
||||
* @param name XX名称
|
||||
* @return XX分页数据
|
||||
*/
|
||||
@SaCheckPermission("single:cate:query")
|
||||
@GetMapping
|
||||
public R<PageData> get(String name) {
|
||||
Sqler sqler = new Sqler("demo_single_main");
|
||||
sqler.addLike("t.name", name);
|
||||
sqler.addSelect("t.notes");
|
||||
sqler.selectCUinfo();
|
||||
return R.ok(jdbcHelper.findPageData(sqler));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一树表-详情查询
|
||||
* @param id ID
|
||||
* @return XX对象
|
||||
*/
|
||||
@SaCheckPermission("single:cate:query")
|
||||
@GetMapping("info/{id}")
|
||||
public R<DemoSingleCate> info(@PathVariable("id") Long id) {
|
||||
return R.ok(service.select(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一树表-新增
|
||||
* @param cate XX对象
|
||||
* @return ID
|
||||
*/
|
||||
@SaCheckPermission("single:cate:add")
|
||||
@Log(title = "单一树表", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS, message = "{repeat.submit.message}")
|
||||
@PostMapping
|
||||
public R<Long> post(@RequestBody DemoSingleCate cate) {
|
||||
ValidatorUtils.validate(cate, AddGroup.class);
|
||||
return R.ok(null,service.insert(cate,table));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一树表-修改
|
||||
* @param cate XX对象
|
||||
* @return ID
|
||||
*/
|
||||
@SaCheckPermission("single:cate:edit")
|
||||
@Log(title = "单一树表", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit
|
||||
@PutMapping
|
||||
public R<Long> put(@Validated(EditGroup.class) @RequestBody DemoSingleCate cate) {
|
||||
return R.ok(null, service.update(cate, table));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一树表-删除
|
||||
* @param ids ID串
|
||||
* @return 删除的XX数量
|
||||
*/
|
||||
@SaCheckPermission("single:cate:remove")
|
||||
@Log(title = "单一树表", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("{ids}")
|
||||
public R<Integer> delete(@PathVariable Long[] ids) {
|
||||
return R.ok(null,service.delete(Arrays.asList(ids)));
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package vben.mybatis.demo.single.cate;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface DemoSingleCateMapper extends BaseMapper<DemoSingleCate> {
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package vben.mybatis.demo.single.cate;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import vben.common.mybatis.core.service.BaseCateService;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DemoSingleCateService extends BaseCateService<DemoSingleCate> {
|
||||
|
||||
private final DemoSingleCateMapper mapper;
|
||||
|
||||
@PostConstruct
|
||||
public void initDao() {
|
||||
super.setMapper(mapper);
|
||||
}
|
||||
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package vben.mybatis.demo.single.main;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import vben.common.mybatis.core.domain.BaseMainEntity;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 单一主表
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("demo_single_main")
|
||||
public class DemoSingleMain extends BaseMainEntity {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package vben.mybatis.demo.single.main;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import vben.common.core.domain.R;
|
||||
import vben.common.idempotent.annotation.RepeatSubmit;
|
||||
import vben.common.jdbc.dto.PageData;
|
||||
import vben.common.jdbc.sqler.JdbcHelper;
|
||||
import vben.common.jdbc.sqler.Sqler;
|
||||
import vben.common.log.annotation.Log;
|
||||
import vben.common.log.enums.BusinessType;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 单一主表案例
|
||||
*
|
||||
* @author baby_fox
|
||||
* @date 2025-11-29
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("demo/single/main")
|
||||
public class DemoSingleMainController {
|
||||
|
||||
private final DemoSingleMainService service;
|
||||
|
||||
private final JdbcHelper jdbcHelper;
|
||||
|
||||
/**
|
||||
* 单一主表-分页查询
|
||||
* @param name XX名称
|
||||
* @return XX分页数据
|
||||
*/
|
||||
@SaCheckPermission("single:main:query")
|
||||
@GetMapping
|
||||
public R<PageData> get(String name) {
|
||||
Sqler sqler = new Sqler("demo_single_main");
|
||||
sqler.addLike("t.name", name);
|
||||
sqler.addSelect("t.notes");
|
||||
sqler.selectCUinfo();
|
||||
return R.ok(jdbcHelper.findPageData(sqler));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一主表-详情查询
|
||||
* @param id ID
|
||||
* @return XX对象
|
||||
*/
|
||||
@SaCheckPermission("single:main:query")
|
||||
@GetMapping("info/{id}")
|
||||
public R<DemoSingleMain> info(@PathVariable("id") Long id) {
|
||||
return R.ok(service.select(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一主表-新增
|
||||
* @param main XX对象
|
||||
* @return ID
|
||||
*/
|
||||
@SaCheckPermission("single:main:add")
|
||||
@Log(title = "单一主表", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS, message = "{repeat.submit.message}")
|
||||
@PostMapping
|
||||
public R<Long> post(@RequestBody DemoSingleMain main) {
|
||||
return R.ok(null,service.insert(main));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一主表-修改
|
||||
* @param main XX对象
|
||||
* @return ID
|
||||
*/
|
||||
@SaCheckPermission("single:main:edit")
|
||||
@Log(title = "单一主表", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit
|
||||
@PutMapping
|
||||
public R<Long> put(@RequestBody DemoSingleMain main) {
|
||||
return R.ok(null,service.update(main));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单一主表-删除
|
||||
* @param ids ID串
|
||||
* @return 删除的XX数量
|
||||
*/
|
||||
@SaCheckPermission("single:main:remove")
|
||||
@Log(title = "单一主表", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("{ids}")
|
||||
public R<Integer> delete(@PathVariable Long[] ids) {
|
||||
return R.ok(null,service.delete(Arrays.asList(ids)));
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package vben.mybatis.demo.single.main;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface DemoSingleMainMapper extends BaseMapper<DemoSingleMain> {
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package vben.mybatis.demo.single.main;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import vben.common.mybatis.core.service.BaseMainService;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DemoSingleMainService extends BaseMainService<DemoSingleMain> {
|
||||
|
||||
private final DemoSingleMainMapper mapper;
|
||||
|
||||
@PostConstruct
|
||||
public void initDao() {
|
||||
super.setMapper(mapper);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,6 +50,7 @@ spring:
|
||||
url: jdbc:mysql://localhost:3306/vben-java?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||
username: root
|
||||
password: 123456
|
||||
|
||||
# # 从库数据源
|
||||
# slave:
|
||||
# lazy: true
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="vben.mybatis.demo.ruoyi.TestDemoMapper">
|
||||
|
||||
<select id="customPageList" resultType="vben.mybatis.demo.ruoyi.TestDemoVo">
|
||||
SELECT * FROM test_demo ${ew.customSqlSegment}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -25,25 +25,25 @@
|
||||
|
||||
<!-- <!– mp支持的数据库均支持 只需要增加对应的jdbc依赖即可 –>-->
|
||||
<!-- <!– Oracle –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.oracle.database.jdbc</groupId>-->
|
||||
<!-- <artifactId>ojdbc8</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.oracle.database.jdbc</groupId>
|
||||
<artifactId>ojdbc8</artifactId>
|
||||
</dependency>
|
||||
<!-- <!– 兼容oracle低版本 –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.oracle.database.nls</groupId>-->
|
||||
<!-- <artifactId>orai18n</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <!– PostgreSql –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.postgresql</groupId>-->
|
||||
<!-- <artifactId>postgresql</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
<!-- <!– SqlServer –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.microsoft.sqlserver</groupId>-->
|
||||
<!-- <artifactId>mssql-jdbc</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.microsoft.sqlserver</groupId>
|
||||
<artifactId>mssql-jdbc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zsvg</groupId>
|
||||
|
||||
@@ -6,6 +6,9 @@ import org.springframework.stereotype.Service;
|
||||
import vben.setup.bpm.proc.BpmProcDefEntity;
|
||||
import vben.setup.bpm.proc.BpmProcDefRepo;
|
||||
|
||||
/**
|
||||
* 流程初始化
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Transactional
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package vben.setup.demo.link;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Index;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import vben.common.jpa.entity.BaseCateEntity;
|
||||
|
||||
/**
|
||||
* 关联分类表
|
||||
*/
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "关联分类表")
|
||||
@Table(indexes = {@Index(columnList = "cruid"), @Index(columnList = "upuid")})
|
||||
public class DemoLinkCate extends BaseCateEntity {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package vben.setup.demo.link;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 关联子表
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
@Schema(description = "关联子表")
|
||||
public class DemoLinkItem {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@Id
|
||||
@Schema(description = "主键ID")
|
||||
@Column(length = 32)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 主表ID
|
||||
*/
|
||||
@Schema(description = "主表ID")
|
||||
private Long maiid;
|
||||
|
||||
/**
|
||||
* 子项目名称
|
||||
*/
|
||||
@Column(length = 32)
|
||||
@Schema(description = "子项目名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
@Schema(description = "排序号")
|
||||
private Integer ornum;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注")
|
||||
private String notes;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package vben.setup.demo.link;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import vben.common.jpa.entity.BaseMainEntity;
|
||||
import vben.common.jpa.entity.SysOrg;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 关联主表
|
||||
*/
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "关联主表")
|
||||
@Table(indexes = {@Index(columnList = "cruid"), @Index(columnList = "upuid")})
|
||||
public class DemoLinkMain extends BaseMainEntity {
|
||||
|
||||
/**
|
||||
* 所属分类ID
|
||||
*/
|
||||
@Schema(description = "所属分类ID")
|
||||
private Long catid;
|
||||
|
||||
/**
|
||||
* 子项目列表(OneToMany示例)
|
||||
*/
|
||||
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JoinColumn(name = "maiid")
|
||||
@OrderBy("ornum ASC")
|
||||
@Schema(description = "子项目列表")
|
||||
private List<DemoLinkItem> items = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 成员列表(ManyToMany示例)
|
||||
*/
|
||||
@ManyToMany
|
||||
@JoinTable(name = "demo_link_main_org", joinColumns = {@JoinColumn(name = "mid")},
|
||||
inverseJoinColumns = {@JoinColumn(name = "oid")})
|
||||
@Schema(description = "成员信息")
|
||||
private List<SysOrg> orgs;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
package vben.setup.demo.root;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import vben.setup.sys.perm.api.SysPermApiEntity;
|
||||
import vben.setup.sys.perm.api.SysPermApiRepo;
|
||||
import vben.setup.sys.perm.menu.SysPermMenuEntity;
|
||||
import vben.setup.sys.perm.menu.SysPermMenuRepo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 案例初始化
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Transactional
|
||||
public class DemoInitService {
|
||||
|
||||
private final SysPermMenuRepo menuRrepo;
|
||||
|
||||
private final SysPermApiRepo apiRepo;
|
||||
|
||||
public void init() {
|
||||
List<SysPermMenuEntity> menuList = new ArrayList<>();
|
||||
SysPermMenuEntity m8000 = new SysPermMenuEntity();
|
||||
m8000.setId(8000L);
|
||||
m8000.setIcon("hugeicons:star");
|
||||
m8000.setName("使用案例");
|
||||
m8000.setOrnum(8000);
|
||||
m8000.setPath("demo");
|
||||
m8000.setPid(0L);
|
||||
m8000.setType("1");
|
||||
m8000.setComp("Layout");
|
||||
menuList.add(m8000);
|
||||
|
||||
SysPermMenuEntity m8010 = new SysPermMenuEntity();
|
||||
m8010.setId(8010L);
|
||||
m8010.setComp("demo/single/main/index");
|
||||
m8010.setIcon("pajamas:work-item-requirement");
|
||||
m8010.setName("单一主表案例");
|
||||
m8010.setOrnum(8010);
|
||||
m8010.setPath("single/main");
|
||||
m8010.setPid(8000L);
|
||||
menuList.add(m8010);
|
||||
|
||||
SysPermMenuEntity m8020 = new SysPermMenuEntity();
|
||||
m8020.setId(8020L);
|
||||
m8020.setComp("demo/single/cate/index");
|
||||
m8020.setIcon("pajamas:work-item-requirement");
|
||||
m8020.setName("单一树表案例");
|
||||
m8020.setOrnum(8020);
|
||||
m8020.setPath("single/cate");
|
||||
m8020.setPid(8000L);
|
||||
menuList.add(m8020);
|
||||
|
||||
SysPermMenuEntity m8030 = new SysPermMenuEntity();
|
||||
m8030.setId(8030L);
|
||||
m8030.setComp("demo/link/index");
|
||||
m8030.setIcon("pajamas:work-item-requirement");
|
||||
m8030.setName("关联主分子案例");
|
||||
m8030.setOrnum(8030);
|
||||
m8030.setPath("link");
|
||||
m8030.setPid(8000L);
|
||||
menuList.add(m8030);
|
||||
|
||||
insertMenus(menuList);
|
||||
|
||||
List<SysPermApiEntity> apiList = new ArrayList<>();
|
||||
|
||||
SysPermApiEntity a801001 = new SysPermApiEntity();
|
||||
a801001.setId(801001L);
|
||||
a801001.setOrnum(801001);
|
||||
a801001.setName("单一主表-查询");
|
||||
a801001.setMenid(8010L);
|
||||
a801001.setPerm("single:main:query");
|
||||
apiList.add(a801001);
|
||||
|
||||
SysPermApiEntity a801002 = new SysPermApiEntity();
|
||||
a801002.setId(801002L);
|
||||
a801002.setOrnum(801002);
|
||||
a801002.setName("单一主表-新增");
|
||||
a801002.setMenid(8010L);
|
||||
a801002.setPerm("single:main:add");
|
||||
apiList.add(a801002);
|
||||
|
||||
SysPermApiEntity a801003 = new SysPermApiEntity();
|
||||
a801003.setId(801003L);
|
||||
a801003.setOrnum(801003);
|
||||
a801003.setName("单一主表-修改");
|
||||
a801003.setMenid(8010L);
|
||||
a801003.setPerm("single:main:edit");
|
||||
apiList.add(a801003);
|
||||
|
||||
SysPermApiEntity a801004 = new SysPermApiEntity();
|
||||
a801004.setId(801004L);
|
||||
a801004.setOrnum(801004);
|
||||
a801004.setName("单一主表-删除");
|
||||
a801004.setMenid(8010L);
|
||||
a801004.setPerm("single:main:remove");
|
||||
apiList.add(a801004);
|
||||
|
||||
SysPermApiEntity a802001 = new SysPermApiEntity();
|
||||
a802001.setId(802001L);
|
||||
a802001.setOrnum(802001);
|
||||
a802001.setName("单一树表-查询");
|
||||
a802001.setMenid(8020L);
|
||||
a802001.setPerm("single:cate:query");
|
||||
apiList.add(a802001);
|
||||
|
||||
SysPermApiEntity a802002 = new SysPermApiEntity();
|
||||
a802002.setId(802002L);
|
||||
a802002.setOrnum(802002);
|
||||
a802002.setName("单一树表-新增");
|
||||
a802002.setMenid(8020L);
|
||||
a802002.setPerm("single:cate:add");
|
||||
apiList.add(a802002);
|
||||
|
||||
SysPermApiEntity a802003 = new SysPermApiEntity();
|
||||
a802003.setId(802003L);
|
||||
a802003.setOrnum(802003);
|
||||
a802003.setName("单一树表-修改");
|
||||
a802003.setMenid(8020L);
|
||||
a802003.setPerm("single:cate:edit");
|
||||
apiList.add(a802003);
|
||||
|
||||
SysPermApiEntity a802004 = new SysPermApiEntity();
|
||||
a802004.setId(802004L);
|
||||
a802004.setOrnum(802004);
|
||||
a802004.setName("单一树表-删除");
|
||||
a802004.setMenid(8020L);
|
||||
a802004.setPerm("single:cate:remove");
|
||||
apiList.add(a802004);
|
||||
|
||||
SysPermApiEntity a803001 = new SysPermApiEntity();
|
||||
a803001.setId(803001L);
|
||||
a803001.setOrnum(803001);
|
||||
a803001.setName("关联主表-查询");
|
||||
a803001.setMenid(8030L);
|
||||
a803001.setPerm("link:main:query");
|
||||
apiList.add(a803001);
|
||||
|
||||
SysPermApiEntity a803002 = new SysPermApiEntity();
|
||||
a803002.setId(803002L);
|
||||
a803002.setOrnum(803002);
|
||||
a803002.setName("关联主表-新增");
|
||||
a803002.setMenid(8030L);
|
||||
a803002.setPerm("link:main:add");
|
||||
apiList.add(a803002);
|
||||
|
||||
SysPermApiEntity a803003 = new SysPermApiEntity();
|
||||
a803003.setId(803003L);
|
||||
a803003.setOrnum(803003);
|
||||
a803003.setName("关联主表-修改");
|
||||
a803003.setMenid(8030L);
|
||||
a803003.setPerm("link:main:edit");
|
||||
apiList.add(a803003);
|
||||
|
||||
SysPermApiEntity a803004 = new SysPermApiEntity();
|
||||
a803004.setId(803004L);
|
||||
a803004.setOrnum(803004);
|
||||
a803004.setName("关联主表-删除");
|
||||
a803004.setMenid(8030L);
|
||||
a803004.setPerm("link:main:remove");
|
||||
apiList.add(a803004);
|
||||
|
||||
SysPermApiEntity a803011 = new SysPermApiEntity();
|
||||
a803011.setId(803011L);
|
||||
a803011.setOrnum(803011);
|
||||
a803011.setName("关联树表-查询");
|
||||
a803011.setMenid(8030L);
|
||||
a803011.setPerm("link:cate:query");
|
||||
apiList.add(a803011);
|
||||
|
||||
SysPermApiEntity a803012 = new SysPermApiEntity();
|
||||
a803012.setId(803012L);
|
||||
a803012.setOrnum(803012);
|
||||
a803012.setName("关联树表-新增");
|
||||
a803012.setMenid(8030L);
|
||||
a803012.setPerm("link:cate:add");
|
||||
apiList.add(a803012);
|
||||
|
||||
SysPermApiEntity a803013 = new SysPermApiEntity();
|
||||
a803013.setId(803013L);
|
||||
a803013.setOrnum(803013);
|
||||
a803013.setName("关联树表-修改");
|
||||
a803013.setMenid(8030L);
|
||||
a803013.setPerm("link:cate:edit");
|
||||
apiList.add(a803013);
|
||||
|
||||
SysPermApiEntity a803014 = new SysPermApiEntity();
|
||||
a803014.setId(803014L);
|
||||
a803014.setOrnum(803014);
|
||||
a803014.setName("关联树表-删除");
|
||||
a803014.setMenid(8030L);
|
||||
a803014.setPerm("link:cate:remove");
|
||||
apiList.add(a803014);
|
||||
|
||||
insertApis(apiList);
|
||||
|
||||
}
|
||||
|
||||
private void insertMenus(List<SysPermMenuEntity> list) {
|
||||
for (SysPermMenuEntity main : list) {
|
||||
main.setAvtag(true);
|
||||
if(main.getCatag()==null){
|
||||
main.setCatag(false);
|
||||
}
|
||||
if(main.getType()==null){
|
||||
main.setType("2");
|
||||
}
|
||||
if(main.getShtag()==null){
|
||||
main.setShtag(true);
|
||||
}
|
||||
if(main.getOutag()==null){
|
||||
main.setOutag(false);
|
||||
}
|
||||
main.setUptim(main.getCrtim());
|
||||
}
|
||||
menuRrepo.saveAll(list);
|
||||
}
|
||||
|
||||
private void insertApis(List<SysPermApiEntity> list) {
|
||||
for (SysPermApiEntity api : list) {
|
||||
api.setAvtag(true);
|
||||
api.setUptim(api.getCrtim());
|
||||
}
|
||||
apiRepo.saveAll(list);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package vben.setup.demo.single;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.Entity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import vben.common.jpa.entity.BaseCateEntity;
|
||||
|
||||
/**
|
||||
* 单一树表
|
||||
*/
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "单一树表")
|
||||
public class DemoSingleCate extends BaseCateEntity {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package vben.setup.demo.single;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.Entity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import vben.common.jpa.entity.BaseMainEntity;
|
||||
|
||||
/**
|
||||
* 单一主表案
|
||||
*/
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "单一主表")
|
||||
public class DemoSingleMain extends BaseMainEntity {
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package vben.setup.root;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import vben.common.jdbc.sqler.JdbcHelper;
|
||||
import vben.setup.bpm.bus.BpmBusInitService;
|
||||
import vben.setup.demo.root.DemoInitService;
|
||||
import vben.setup.sys.config.SysConfigInitService;
|
||||
import vben.setup.sys.notice.SysNoticeInitService;
|
||||
import vben.setup.sys.org.dept.SysOrgDeptInitService;
|
||||
@@ -14,7 +16,6 @@ import vben.setup.sys.perm.menu.SysPermMenuInitService;
|
||||
import vben.setup.sys.perm.role.SysPermRoleInitService;
|
||||
import vben.setup.tool.dict.ToolDictInitService;
|
||||
import vben.setup.tool.num.ToolNumInitService;
|
||||
import vben.setup.bpm.bus.BpmBusInitService;
|
||||
|
||||
/**
|
||||
* 数据初始化
|
||||
@@ -49,6 +50,7 @@ public class DataInitService {
|
||||
|
||||
//流程相关数据
|
||||
bpmBusInitService.init();
|
||||
demoInitService.init();
|
||||
}
|
||||
|
||||
private final JdbcHelper jdbcHelper;
|
||||
@@ -77,5 +79,7 @@ public class DataInitService {
|
||||
|
||||
private final BpmBusInitService bpmBusInitService;
|
||||
|
||||
private final DemoInitService demoInitService;
|
||||
|
||||
|
||||
}
|
||||
|
||||
+16
-16
@@ -24,7 +24,7 @@ public class SysOrgDeptInitService {
|
||||
dept.setId("d1000");
|
||||
dept.setName("维本科技");
|
||||
dept.setType(1);
|
||||
dept.setTier("d1000");
|
||||
dept.setTier("_d1000_");
|
||||
list.add(dept);
|
||||
|
||||
SysOrgDeptEntity dept1100 = new SysOrgDeptEntity();
|
||||
@@ -32,7 +32,7 @@ public class SysOrgDeptInitService {
|
||||
dept1100.setName("北京分公司");
|
||||
dept1100.setType(2);
|
||||
dept1100.setPid("d1000");
|
||||
dept1100.setTier("d1000_d1100");
|
||||
dept1100.setTier("_d1000_d1100_");
|
||||
list.add(dept1100);
|
||||
|
||||
SysOrgDeptEntity dept1110 = new SysOrgDeptEntity();
|
||||
@@ -40,7 +40,7 @@ public class SysOrgDeptInitService {
|
||||
dept1110.setName("北京分公司销售部");
|
||||
dept1110.setType(8);
|
||||
dept1110.setPid("d1100");
|
||||
dept1110.setTier("d1000_d1100_d1110");
|
||||
dept1110.setTier("_d1000_d1100_d1110_");
|
||||
list.add(dept1110);
|
||||
|
||||
SysOrgDeptEntity dept1111 = new SysOrgDeptEntity();
|
||||
@@ -48,7 +48,7 @@ public class SysOrgDeptInitService {
|
||||
dept1111.setName("北京分公司销售部一组");
|
||||
dept1111.setType(8);
|
||||
dept1111.setPid("d1110");
|
||||
dept1111.setTier("d1000_d1100_d1110_d1111");
|
||||
dept1111.setTier("_d1000_d1100_d1110_d1111_");
|
||||
list.add(dept1111);
|
||||
|
||||
SysOrgDeptEntity dept1112 = new SysOrgDeptEntity();
|
||||
@@ -56,7 +56,7 @@ public class SysOrgDeptInitService {
|
||||
dept1112.setName("北京分公司销售部二组");
|
||||
dept1112.setType(8);
|
||||
dept1112.setPid("d1110");
|
||||
dept1112.setTier("d1000_d1100_d1110_d1112");
|
||||
dept1112.setTier("_d1000_d1100_d1110_d1112_");
|
||||
list.add(dept1112);
|
||||
|
||||
SysOrgDeptEntity dept1120 = new SysOrgDeptEntity();
|
||||
@@ -64,7 +64,7 @@ public class SysOrgDeptInitService {
|
||||
dept1120.setName("北京分公司人事部");
|
||||
dept1120.setType(8);
|
||||
dept1120.setPid("d1100");
|
||||
dept1120.setTier("d1000_d1100_d1120;");
|
||||
dept1120.setTier("_d1000_d1100_d1120_");
|
||||
list.add(dept1120);
|
||||
|
||||
SysOrgDeptEntity dept1130 = new SysOrgDeptEntity();
|
||||
@@ -72,7 +72,7 @@ public class SysOrgDeptInitService {
|
||||
dept1130.setName("北京分公司财务部");
|
||||
dept1130.setType(8);
|
||||
dept1130.setPid("d1100");
|
||||
dept1130.setTier("d1000_d1100_d1130");
|
||||
dept1130.setTier("_d1000_d1100_d1130_");
|
||||
list.add(dept1130);
|
||||
|
||||
SysOrgDeptEntity dept1140 = new SysOrgDeptEntity();
|
||||
@@ -80,7 +80,7 @@ public class SysOrgDeptInitService {
|
||||
dept1140.setName("北京分公司综合部");
|
||||
dept1140.setType(8);
|
||||
dept1140.setPid("d1100");
|
||||
dept1140.setTier("d1000_d1100_d1410");
|
||||
dept1140.setTier("_d1000_d1100_d1410_");
|
||||
list.add(dept1140);
|
||||
|
||||
SysOrgDeptEntity dept1200 = new SysOrgDeptEntity();
|
||||
@@ -88,7 +88,7 @@ public class SysOrgDeptInitService {
|
||||
dept1200.setName("上海分公司");
|
||||
dept1200.setType(2);
|
||||
dept1200.setPid("d1000");
|
||||
dept1200.setTier("d1000_d1200");
|
||||
dept1200.setTier("_d1000_d1200_");
|
||||
list.add(dept1200);
|
||||
|
||||
SysOrgDeptEntity dept1210 = new SysOrgDeptEntity();
|
||||
@@ -96,7 +96,7 @@ public class SysOrgDeptInitService {
|
||||
dept1210.setName("上海分公司销售部");
|
||||
dept1210.setType(8);
|
||||
dept1210.setPid("d1200");
|
||||
dept1210.setTier("d1000_d1200_d1210");
|
||||
dept1210.setTier("_d1000_d1200_d1210_");
|
||||
list.add(dept1210);
|
||||
|
||||
SysOrgDeptEntity dept1220 = new SysOrgDeptEntity();
|
||||
@@ -104,7 +104,7 @@ public class SysOrgDeptInitService {
|
||||
dept1220.setName("上海分公司人事部");
|
||||
dept1220.setType(8);
|
||||
dept1220.setPid("d1200");
|
||||
dept1220.setTier("d1000_d1200_d1220");
|
||||
dept1220.setTier("_d1000_d1200_d1220_");
|
||||
list.add(dept1220);
|
||||
|
||||
SysOrgDeptEntity dept1230 = new SysOrgDeptEntity();
|
||||
@@ -112,7 +112,7 @@ public class SysOrgDeptInitService {
|
||||
dept1230.setName("上海分公司财务部");
|
||||
dept1230.setType(8);
|
||||
dept1230.setPid("d1200");
|
||||
dept1230.setTier("d1000_d1200_d1230");
|
||||
dept1230.setTier("_d1000_d1200_d1230_");
|
||||
list.add(dept1230);
|
||||
|
||||
SysOrgDeptEntity dept1300 = new SysOrgDeptEntity();
|
||||
@@ -120,7 +120,7 @@ public class SysOrgDeptInitService {
|
||||
dept1300.setName("广州分公司");
|
||||
dept1300.setType(2);
|
||||
dept1300.setPid("d1000");
|
||||
dept1300.setTier("d1000_d1300");
|
||||
dept1300.setTier("_d1000_d1300_");
|
||||
list.add(dept1300);
|
||||
|
||||
SysOrgDeptEntity dept1310 = new SysOrgDeptEntity();
|
||||
@@ -128,7 +128,7 @@ public class SysOrgDeptInitService {
|
||||
dept1310.setName("广州分公司综合部");
|
||||
dept1310.setType(8);
|
||||
dept1310.setPid("d1300");
|
||||
dept1310.setTier("d1000_d1300_d1310");
|
||||
dept1310.setTier("_d1000_d1300_d1310_");
|
||||
list.add(dept1310);
|
||||
|
||||
SysOrgDeptEntity dept1320 = new SysOrgDeptEntity();
|
||||
@@ -136,7 +136,7 @@ public class SysOrgDeptInitService {
|
||||
dept1320.setName("广州分公司销售部");
|
||||
dept1320.setType(8);
|
||||
dept1320.setPid("d1300");
|
||||
dept1320.setTier("d1000_d1300_d1320");
|
||||
dept1320.setTier("_d1000_d1300_d1320_");
|
||||
list.add(dept1320);
|
||||
|
||||
SysOrgDeptEntity dept1330 = new SysOrgDeptEntity();
|
||||
@@ -144,7 +144,7 @@ public class SysOrgDeptInitService {
|
||||
dept1330.setName("广州分公司人事部");
|
||||
dept1330.setType(8);
|
||||
dept1330.setPid("d1300");
|
||||
dept1330.setTier("d1000_d1300_d1330");
|
||||
dept1330.setTier("_d1000_d1300_d1330_");
|
||||
list.add(dept1330);
|
||||
|
||||
insert(list);
|
||||
|
||||
+4
-4
@@ -23,7 +23,7 @@ public class SysOrgPostInitService {
|
||||
post1.setName("董事长");
|
||||
post1.setUsers(List.of(new SysOrg("u3")));
|
||||
post1.setDepid("d1000");
|
||||
post1.setTier("d1000_p2001");
|
||||
post1.setTier("_d1000_p2001_");
|
||||
insert(post1);
|
||||
|
||||
SysOrgPostEntity post2 = new SysOrgPostEntity();
|
||||
@@ -31,7 +31,7 @@ public class SysOrgPostInitService {
|
||||
post2.setName("北京分公司总经理");
|
||||
post2.setUsers(List.of(new SysOrg("u4")));
|
||||
post2.setDepid("d1100");
|
||||
post2.setTier("d1000_d1100_p2002");
|
||||
post2.setTier("_d1000_d1100_p2002_");
|
||||
insert(post2);
|
||||
|
||||
SysOrgPostEntity post3 = new SysOrgPostEntity();
|
||||
@@ -39,7 +39,7 @@ public class SysOrgPostInitService {
|
||||
post3.setName("北京分公司销售部长");
|
||||
post3.setUsers(List.of(new SysOrg("u5")));
|
||||
post3.setDepid("d1110");
|
||||
post3.setTier("d1000_d1100_d1110_p2003");
|
||||
post3.setTier("_d1000_d1100_d1110_p2003_");
|
||||
insert(post3);
|
||||
|
||||
SysOrgPostEntity post4 = new SysOrgPostEntity();
|
||||
@@ -47,7 +47,7 @@ public class SysOrgPostInitService {
|
||||
post4.setName("北京分公司销售经理");
|
||||
post4.setUsers(List.of(new SysOrg("u6"),new SysOrg("u7")));
|
||||
post4.setDepid("d1111");
|
||||
post4.setTier("d1000_d1100_d1110_d1111_p2004");
|
||||
post4.setTier("_d1000_d1100_d1110_d1111_p2004_");
|
||||
insert(post4);
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class SysOrgReceEntity {
|
||||
*/
|
||||
@Column(length = 36)
|
||||
@Schema(description = "用户ID")
|
||||
private String uid;
|
||||
private String useid;
|
||||
|
||||
/**
|
||||
* 最近使用的组织架构ID
|
||||
|
||||
+9
-9
@@ -26,7 +26,7 @@ public class SysOrgUserInitService {
|
||||
user.setName("管理员");
|
||||
user.setUsnam("admin");
|
||||
user.setDepid("d1000");
|
||||
user.setTier("d1000_u1");
|
||||
user.setTier("_d1000_u1_");
|
||||
user.setMonum("13812345678");
|
||||
user.setEmail("admin@qq.com");
|
||||
user.setSex("1");
|
||||
@@ -38,7 +38,7 @@ public class SysOrgUserInitService {
|
||||
user2.setName("小狐狸");
|
||||
user2.setUsnam("vben");
|
||||
user2.setDepid("d1000");
|
||||
user2.setTier("d1000_u2");
|
||||
user2.setTier("_d1000_u2_");
|
||||
user2.setMonum("13912345678");
|
||||
user.setEmail("vben@qq.com");
|
||||
user2.setSex("2");
|
||||
@@ -49,7 +49,7 @@ public class SysOrgUserInitService {
|
||||
user3.setName("张三");
|
||||
user3.setUsnam("zs");
|
||||
user3.setDepid("d1000");
|
||||
user3.setTier("d1000_u3");
|
||||
user3.setTier("_d1000_u3_");
|
||||
list.add(user3);
|
||||
|
||||
SysOrgUserEntity user4 = new SysOrgUserEntity();
|
||||
@@ -57,7 +57,7 @@ public class SysOrgUserInitService {
|
||||
user4.setName("李四");
|
||||
user4.setUsnam("ls");
|
||||
user4.setDepid("d1100");
|
||||
user4.setTier("d1000_d1100_u4");
|
||||
user4.setTier("_d1000_d1100_u4_");
|
||||
list.add(user4);
|
||||
|
||||
SysOrgUserEntity user5 = new SysOrgUserEntity();
|
||||
@@ -65,7 +65,7 @@ public class SysOrgUserInitService {
|
||||
user5.setName("王五");
|
||||
user5.setUsnam("ww");
|
||||
user5.setDepid("d1110");
|
||||
user5.setTier("d1000_d1100_d1110_u5");
|
||||
user5.setTier("_d1000_d1100_d1110_u5_");
|
||||
list.add(user5);
|
||||
|
||||
SysOrgUserEntity user6 = new SysOrgUserEntity();
|
||||
@@ -73,7 +73,7 @@ public class SysOrgUserInitService {
|
||||
user6.setName("赵六");
|
||||
user6.setUsnam("zl");
|
||||
user6.setDepid("d1111");
|
||||
user6.setTier("d1000_d1100_d1110_d1111_u6");
|
||||
user6.setTier("_d1000_d1100_d1110_d1111_u6_");
|
||||
list.add(user6);
|
||||
|
||||
SysOrgUserEntity user7 = new SysOrgUserEntity();
|
||||
@@ -81,7 +81,7 @@ public class SysOrgUserInitService {
|
||||
user7.setName("孙七");
|
||||
user7.setUsnam("sq");
|
||||
user7.setDepid("d1111");
|
||||
user7.setTier("d1000_d1100_d1110_d1111_u7");
|
||||
user7.setTier("_d1000_d1100_d1110_d1111_u7_");
|
||||
list.add(user7);
|
||||
|
||||
SysOrgUserEntity user8 = new SysOrgUserEntity();
|
||||
@@ -89,7 +89,7 @@ public class SysOrgUserInitService {
|
||||
user8.setName("周八");
|
||||
user8.setUsnam("zb");
|
||||
user8.setDepid("d1111");
|
||||
user8.setTier("d1000_d1100_d1110_d1111_u8");
|
||||
user8.setTier("_d1000_d1100_d1110_d1111_u8_");
|
||||
list.add(user8);
|
||||
|
||||
SysOrgUserEntity user9 = new SysOrgUserEntity();
|
||||
@@ -97,7 +97,7 @@ public class SysOrgUserInitService {
|
||||
user9.setName("吴九");
|
||||
user9.setUsnam("wj");
|
||||
user9.setDepid("d1111");
|
||||
user9.setTier("d1000_d1100_d1110_d1111_u9");
|
||||
user9.setTier("_d1000_d1100_d1110_d1111_u9_");
|
||||
list.add(user9);
|
||||
|
||||
insert(list);
|
||||
|
||||
@@ -30,6 +30,18 @@ public class SysPermRoleEntity {
|
||||
@Schema(description = "角色名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 角色类型
|
||||
*/
|
||||
@Schema(description = "角色类型")
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 数据权限
|
||||
*/
|
||||
@Schema(description = "数据权限")
|
||||
private Integer scope;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@@ -42,12 +54,38 @@ public class SysPermRoleEntity {
|
||||
@Schema(description = "创建时间")
|
||||
private Date crtim = new Date();
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@Column(length = 36)
|
||||
@Schema(description = "创建人ID")
|
||||
private String cruid;
|
||||
|
||||
/**
|
||||
* 创建人姓名
|
||||
*/
|
||||
@Transient
|
||||
private String cruna;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Schema(description = "更新时间")
|
||||
private Date uptim;
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@Column(length = 36)
|
||||
@Schema(description = "更新人ID")
|
||||
private String upuid;
|
||||
|
||||
/**
|
||||
* 更新人姓名
|
||||
*/
|
||||
@Transient
|
||||
private String upuna;
|
||||
|
||||
/**
|
||||
* 可用标记
|
||||
*/
|
||||
|
||||
@@ -34,7 +34,6 @@ spring:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
# 动态数据源文档 https://www.kancloud.cn/tracy5546/dynamic-datasource/content
|
||||
primary:
|
||||
dbType: mysql
|
||||
validationQuery: SELECT 1 FROM DUAL
|
||||
# driverClassName: com.mysql.jdbc.Driver
|
||||
# jdbcUrl: jdbc:mysql://127.0.0.1:3306/ry-vue3?characterEncoding=utf-8&useSSL=false
|
||||
|
||||
@@ -34,7 +34,6 @@ spring:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
# 动态数据源文档 https://www.kancloud.cn/tracy5546/dynamic-datasource/content
|
||||
primary:
|
||||
dbType: mysql
|
||||
validationQuery: SELECT 1 FROM DUAL
|
||||
# driverClassName: com.mysql.jdbc.Driver
|
||||
# jdbcUrl: jdbc:mysql://127.0.0.1:3306/ry-vue3?characterEncoding=utf-8&useSSL=false
|
||||
|
||||
@@ -188,6 +188,10 @@ public class StrUtils {
|
||||
return StrUtil.lowerFirst(str);
|
||||
}
|
||||
|
||||
public static String toLowerCase(final CharSequence str) {
|
||||
return StrUtil.toLowerCase(str);
|
||||
}
|
||||
|
||||
public static boolean isUrl(CharSequence value) {
|
||||
return Validator.isUrl(value);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package vben.common.jdbc.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 树节点移动对象
|
||||
*/
|
||||
@Data
|
||||
public class Lmove {
|
||||
|
||||
/**
|
||||
* 拖动节点ID
|
||||
*/
|
||||
private Long draid;
|
||||
|
||||
/**
|
||||
* 放下时目标节点ID
|
||||
*/
|
||||
private Long droid;
|
||||
|
||||
/**
|
||||
* 移动类型
|
||||
*/
|
||||
private String type;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package vben.common.jdbc.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LpidTier
|
||||
{
|
||||
private Long pid;
|
||||
private String tier;
|
||||
|
||||
}
|
||||
+1
-1
@@ -6,7 +6,7 @@ import lombok.Data;
|
||||
* 树节点移动对象
|
||||
*/
|
||||
@Data
|
||||
public class TreeMoveBo {
|
||||
public class Smove {
|
||||
|
||||
/**
|
||||
* 拖动节点ID
|
||||
@@ -0,0 +1,10 @@
|
||||
package vben.common.jdbc.root;
|
||||
|
||||
public class Db {
|
||||
|
||||
public static String True = "1";
|
||||
|
||||
public static String False = "0";
|
||||
|
||||
public static String Type = "mysql";
|
||||
}
|
||||
+3
-1
@@ -1,4 +1,4 @@
|
||||
package vben.common.jdbc.dto;
|
||||
package vben.common.jdbc.root;
|
||||
|
||||
public class DbType {
|
||||
|
||||
@@ -8,6 +8,8 @@ public class DbType {
|
||||
|
||||
public static final String ORACLE = "oracle";
|
||||
|
||||
public static final String PGSQL = "postgresql";
|
||||
|
||||
public static final String SQL_SERVER = "sqlserver";
|
||||
|
||||
public static final String DB2 = "db2";
|
||||
@@ -1,16 +1,22 @@
|
||||
package vben.common.jdbc.sqler;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import vben.common.core.utils.ServletUtils;
|
||||
import vben.common.core.utils.StrUtils;
|
||||
import vben.common.jdbc.dto.*;
|
||||
import vben.common.jdbc.root.Db;
|
||||
import vben.common.jdbc.root.DbType;
|
||||
import vben.common.jdbc.utils.LtreeUtils;
|
||||
import vben.common.jdbc.utils.StreeUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -20,8 +26,29 @@ import java.util.Map;
|
||||
@RequiredArgsConstructor
|
||||
public class JdbcHelper {
|
||||
|
||||
//@Value("${spring.datasource.primary.dbType}")
|
||||
private final String DB_TYPE = "mysql";
|
||||
// @Value("${spring.datasource.primary.dbType}")
|
||||
// @Value("#{'${first.url:${secondary.url:}}}'")
|
||||
// private String DB_TYPE = "mysql";
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
jdbcTemplate.execute((Connection conn) -> {
|
||||
DatabaseMetaData metaData = conn.getMetaData();
|
||||
Db.Type= StrUtils.toLowerCase(metaData.getDatabaseProductName());
|
||||
if(Db.Type.contains("sql server")){
|
||||
Db.Type="sqlserver";
|
||||
}
|
||||
if("postgresql".equals(Db.Type)) {
|
||||
Db.True="true";
|
||||
Db.False="false";
|
||||
}
|
||||
return metaData.getDatabaseProductName(); // 返回数据库产品名称
|
||||
//return metaData.getDatabaseProductVersion(); // 返回版本号
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
|
||||
public PageData findPageData(Sqler sqler) {
|
||||
@@ -39,15 +66,16 @@ public class JdbcHelper {
|
||||
return new PageData(0, new ArrayList<>());
|
||||
}
|
||||
List<Map<String, Object>> list;
|
||||
if ("mysql".equalsIgnoreCase(DB_TYPE)) {
|
||||
if (DbType.MYSQL.equalsIgnoreCase(Db.Type)) {
|
||||
list = jdbcTemplate.queryForList(sqler.getMysqlPagingSql(), sqler.getParams());
|
||||
} else if ("oracle".equalsIgnoreCase(DB_TYPE)) {
|
||||
} else if (DbType.PGSQL.equalsIgnoreCase(Db.Type)) {
|
||||
list = jdbcTemplate.queryForList(sqler.getPgsqlPagingSql(), sqler.getParams());
|
||||
} else if (DbType.ORACLE.equalsIgnoreCase(Db.Type)) {
|
||||
list = jdbcTemplate.queryForList(sqler.getOraclePagingLowerCaseSql(), sqler.getParams());
|
||||
} else if ("sqlserver".equalsIgnoreCase(DB_TYPE)) {
|
||||
System.out.println(sqler.getSqlserverPagingSql());
|
||||
} else if (DbType.SQL_SERVER.equalsIgnoreCase(Db.Type)) {
|
||||
list = jdbcTemplate.queryForList(sqler.getSqlserverPagingSql(), sqler.getParams());
|
||||
} else {
|
||||
System.err.println("目前只支持mysql,oracle与sqlserver");
|
||||
System.err.println("目前只支持mysql,oracle,sqlserver与postgresql");
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
return new PageData(count, list);
|
||||
@@ -126,6 +154,10 @@ public class JdbcHelper {
|
||||
return i;
|
||||
}
|
||||
|
||||
public Integer findSize(Sqler sqler) {
|
||||
return jdbcTemplate.queryForObject(sqler.getSizeSql(), Integer.class,sqler.getParams());
|
||||
}
|
||||
|
||||
public Long findLong(String sql, Object... args) {
|
||||
Long l = null;
|
||||
try {
|
||||
@@ -155,7 +187,7 @@ public class JdbcHelper {
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> findMapList(Sqler sqler) {
|
||||
if (DbType.ORACLE.equals(DB_TYPE)) {
|
||||
if (DbType.ORACLE.equals(Db.Type)) {
|
||||
return jdbcTemplate.queryForList(sqler.getLowerCaseSql(), sqler.getParams());
|
||||
} else{
|
||||
return jdbcTemplate.queryForList(sqler.getSql(), sqler.getParams());
|
||||
@@ -175,9 +207,9 @@ public class JdbcHelper {
|
||||
return jdbcTemplate.batchUpdate(sql, list);
|
||||
}
|
||||
|
||||
public String getDbType() {
|
||||
return DB_TYPE;
|
||||
}
|
||||
// public String getDbType() {
|
||||
// return Db.Type;
|
||||
// }
|
||||
|
||||
public JdbcTemplate getTp() {
|
||||
return jdbcTemplate;
|
||||
|
||||
@@ -3,7 +3,7 @@ package vben.common.jdbc.sqler;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import vben.common.core.utils.StrUtils;
|
||||
import vben.common.jdbc.dto.DbType;
|
||||
import vben.common.jdbc.root.DbType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -335,6 +335,12 @@ public class Sqler
|
||||
return selectClause + fromClause + whereClause+groupClause + orderClause + " limit " + fromIndex + "," + pasiz;
|
||||
}
|
||||
|
||||
public String getPgsqlPagingSql()
|
||||
{
|
||||
int fromIndex = pasiz * (panum - 1);
|
||||
return selectClause + fromClause + whereClause+groupClause + orderClause + " limit " + pasiz + " OFFSET " +fromIndex;
|
||||
}
|
||||
|
||||
public String getSqlserverPagingSql()
|
||||
{
|
||||
int rownum = panum * pasiz;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package vben.common.jpa.config;
|
||||
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import org.hibernate.integrator.spi.Integrator;
|
||||
import org.hibernate.jpa.boot.spi.IntegratorProvider;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -13,8 +12,6 @@ import org.springframework.orm.jpa.JpaTransactionManager;
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
import vben.common.core.utils.SpringUtils;
|
||||
import vben.common.core.utils.StrUtils;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Collections;
|
||||
@@ -59,7 +56,6 @@ public class JpaConfig {
|
||||
// @Primary
|
||||
// @Bean(name = "entityManagerFactory")
|
||||
// public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder) {
|
||||
// System.out.println("dataSource = " + dataSource);
|
||||
// return builder
|
||||
// .dataSource(dataSource)
|
||||
// .packages(ENTITY_SCAN)
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
package vben.common.jpa.entity;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import jakarta.persistence.Transient;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分类Entity基类,可实现无限多级的树结构
|
||||
*/
|
||||
@MappedSuperclass
|
||||
@Getter
|
||||
@Setter
|
||||
public class BaseCateEntity {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@Id
|
||||
@Schema(description = "主键ID")
|
||||
protected Long id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@Schema(description = "名称")
|
||||
protected String name;
|
||||
|
||||
/**
|
||||
* 父分类ID
|
||||
*/
|
||||
@Schema(description = "父分类ID")
|
||||
protected Long pid;
|
||||
|
||||
/**
|
||||
* 层级信息
|
||||
*/
|
||||
@Column(length = 512)
|
||||
@Schema(description = "层级信息")
|
||||
protected String tier;
|
||||
|
||||
/**
|
||||
* 子元素
|
||||
*/
|
||||
@Transient
|
||||
protected List<BaseCateEntity> children = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 标签
|
||||
*/
|
||||
@Column(length = 32)
|
||||
@Schema(description = "标签")
|
||||
protected String label;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注")
|
||||
protected String notes;
|
||||
|
||||
/**
|
||||
* 可用标记
|
||||
*/
|
||||
@Schema(description = "可用标记 1启用,0禁用")
|
||||
protected Boolean avtag;
|
||||
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
@Schema(description = "排序号")
|
||||
protected Integer ornum;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Column(updatable = false)
|
||||
@Schema(description = "创建时间")
|
||||
protected Date crtim = new Date();
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@Column(length = 36)
|
||||
@Schema(description = "创建人ID")
|
||||
protected String cruid;
|
||||
|
||||
/**
|
||||
* 创建人姓名
|
||||
*/
|
||||
@Transient
|
||||
protected String cruna;
|
||||
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Schema(description = "更新时间")
|
||||
protected Date uptim;
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@Column(length = 36)
|
||||
@Schema(description = "更新人ID")
|
||||
protected String upuid;
|
||||
|
||||
/**
|
||||
* 更新人姓名
|
||||
*/
|
||||
@Transient
|
||||
protected String upuna;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package vben.common.jpa.entity;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 主数据Entity基类
|
||||
*/
|
||||
@MappedSuperclass
|
||||
@Getter
|
||||
@Setter
|
||||
public class BaseMainEntity {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@Id
|
||||
@Schema(description = "主键ID")
|
||||
protected Long id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@Column(length = 126)
|
||||
@Schema(description = "名称")
|
||||
protected String name;
|
||||
|
||||
/**
|
||||
* 可用标记
|
||||
*/
|
||||
@Schema(description = "可用标记")
|
||||
protected Boolean avtag = true;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@Column(length = 36)
|
||||
@Schema(description = "创建人ID")
|
||||
protected String cruid;
|
||||
|
||||
/**
|
||||
* 创建人姓名
|
||||
*/
|
||||
@Transient
|
||||
protected String cruna;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Column(updatable = false)
|
||||
@Schema(description = "创建时间")
|
||||
protected Date crtim = new Date();
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@Column(length = 36)
|
||||
@Schema(description = "更新人ID")
|
||||
protected String upuid;
|
||||
|
||||
/**
|
||||
* 更新人姓名
|
||||
*/
|
||||
@Transient
|
||||
protected String upuna;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Schema(description = "更新时间")
|
||||
protected Date uptim;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注")
|
||||
protected String notes;
|
||||
}
|
||||
+3
-3
@@ -13,7 +13,7 @@ import java.util.List;
|
||||
@MappedSuperclass
|
||||
@Getter
|
||||
@Setter
|
||||
public class BaseStringCateEntity {
|
||||
public class BaseStrCateEntity {
|
||||
@Id
|
||||
@Column(length = 36)
|
||||
@Schema(description = "主键ID")
|
||||
@@ -29,10 +29,10 @@ public class BaseStringCateEntity {
|
||||
protected String pid;
|
||||
|
||||
// @Transient
|
||||
// protected BaseStringCateEntity parent;
|
||||
// protected BaseStrCateEntity parent;
|
||||
//
|
||||
@Transient
|
||||
protected List<BaseStringCateEntity> children = new ArrayList<>();
|
||||
protected List<BaseStrCateEntity> children = new ArrayList<>();
|
||||
//----------------------通用属性-----------------------
|
||||
@Schema(description = "名称")
|
||||
protected String name;
|
||||
+1
-1
@@ -11,7 +11,7 @@ import java.util.Date;
|
||||
@MappedSuperclass
|
||||
@Getter
|
||||
@Setter
|
||||
public class BaseStringMainEntity {
|
||||
public class BaseStrMainEntity {
|
||||
//----------------------id属性-----------------------
|
||||
@Id
|
||||
@Column(length = 32)
|
||||
@@ -5,7 +5,6 @@ import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
|
||||
+302
@@ -0,0 +1,302 @@
|
||||
package vben.common.jpa.service;
|
||||
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import vben.common.core.utils.IdUtils;
|
||||
import vben.common.jdbc.dto.*;
|
||||
import vben.common.jdbc.root.Db;
|
||||
import vben.common.jdbc.sqler.JdbcHelper;
|
||||
import vben.common.jdbc.sqler.Sqler;
|
||||
import vben.common.jpa.entity.BaseCateEntity;
|
||||
import vben.common.satoken.utils.LoginHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
//分类Service基类,提供分类Entity增删改查的通用方法
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public abstract class BaseCateService<T extends BaseCateEntity> {
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<Ltree> findTreeList(Sqler sqler, String name, Long id) {
|
||||
sqler.addSelect("pid");
|
||||
sqler.addWhere("t.avtag = "+ Db.True);
|
||||
if (id != null) {
|
||||
sqler.addWhere("t.tier not like ?", "%_" + id + "_%");
|
||||
}
|
||||
sqler.addLike("t.name", name);
|
||||
sqler.addOrder("t.ornum");
|
||||
return jdbcHelper.findLtreeList(sqler);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<T> findList(Sqler sqler, Class<T> clazz) {
|
||||
sqler.selectCUinfo().addSelect("t.pid,t.ornum");
|
||||
sqler.addOrder("t.ornum");
|
||||
List<T> list = jdbcHelper.getTp().query(sqler.getSql(), sqler.getParams(),
|
||||
new BeanPropertyRowMapper<>(clazz));
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<SidNamePid> findInpList(String table, String name) {
|
||||
Sqler sqler = new Sqler(table);
|
||||
sqler.addSelect("t.pid");
|
||||
sqler.addLike("t.name", name);
|
||||
sqler.addOrder("t.ornum");
|
||||
return jdbcHelper.getTp().query(sqler.getSql(), new BeanPropertyRowMapper<>(SidNamePid.class));
|
||||
}
|
||||
|
||||
//查询分页
|
||||
@Transactional(readOnly = true)
|
||||
public PageData findPageData(Sqler sqler) {
|
||||
sqler.selectCUinfo().addSelect("t.label");
|
||||
sqler.addOrder("t.ornum");
|
||||
return jdbcHelper.findPageData(sqler);
|
||||
}
|
||||
|
||||
//查询SidName集合
|
||||
@Transactional(readOnly = true)
|
||||
public List<SidName> findIdNameRes(Sqler sqler) {
|
||||
return jdbcHelper.findSidNameList(sqler);
|
||||
}
|
||||
|
||||
//查询单个实体详细信息
|
||||
@Transactional(readOnly = true)
|
||||
public T select(Long id) {
|
||||
T main=repo.findById(id).get();
|
||||
//下面的可优化,从缓存读取
|
||||
String sql = "select name from sys_org where id = ?";
|
||||
if(main.getCruid()!=null){
|
||||
main.setCruna(jdbcHelper.findString(sql, main.getCruid()));
|
||||
}
|
||||
if(main.getUpuid()!=null){
|
||||
main.setUpuna(jdbcHelper.findString(sql, main.getUpuid()));
|
||||
}
|
||||
return main;
|
||||
}
|
||||
|
||||
//---------------------------------------增删改-------------------------------------
|
||||
//新增
|
||||
public Long insert(T cate,String table) {
|
||||
if(cate.getPid()==null){
|
||||
cate.setPid(0L);
|
||||
}
|
||||
if(cate.getOrnum()==null){
|
||||
cate.setOrnum(getCount(cate.getPid(), table) + 1);
|
||||
}
|
||||
if (cate.getId() == null) {
|
||||
cate.setId(IdUtils.getSnowflakeNextId());
|
||||
}
|
||||
if (cate.getCruid() == null) {
|
||||
String UserId=LoginHelper.getUserId();
|
||||
cate.setCruid(UserId);
|
||||
cate.setUpuid(UserId);
|
||||
}
|
||||
if (cate.getPid() != 0L) {
|
||||
T parent = repo.findById(cate.getPid()).get();
|
||||
cate.setTier(parent.getTier() + cate.getId()+"_");
|
||||
} else {
|
||||
cate.setTier("_"+cate.getId() + "_");
|
||||
}
|
||||
cate.setUptim(cate.getCrtim());
|
||||
repo.save(cate);
|
||||
return cate.getId();
|
||||
}
|
||||
|
||||
//更新
|
||||
public Long update(T cate) {
|
||||
if(cate.getPid()==null){
|
||||
cate.setPid(0L);
|
||||
}
|
||||
cate.setUptim(new Date());
|
||||
cate.setUpuid(LoginHelper.getUserId());
|
||||
repo.save(cate);
|
||||
return cate.getId();
|
||||
}
|
||||
|
||||
//级联更新
|
||||
public Long update(T cate, String table) {
|
||||
if(cate.getPid()==null){
|
||||
cate.setPid(0L);
|
||||
}
|
||||
cate.setUptim(new Date());
|
||||
cate.setUpuid(LoginHelper.getUserId());
|
||||
Long newPid = null;
|
||||
if (cate.getPid() != 0L) {
|
||||
newPid = cate.getPid();
|
||||
}
|
||||
String ptSql="select pid,tier from "+table+" where id=?";
|
||||
LpidTier oldCate = jdbcHelper.getTp().queryForObject(ptSql, new BeanPropertyRowMapper<>(LpidTier.class), cate.getId());
|
||||
String oldTier = oldCate.getTier();
|
||||
if (Objects.equals(oldCate.getPid(), newPid)) {//如果父节点没有变,则只更新自己
|
||||
// System.out.println("父节点没有变");
|
||||
cate.setTier(oldTier);
|
||||
repo.save(cate);
|
||||
} else {//如果父节点变了,则另外需要更新自己孩子节点的tier层级
|
||||
String newTier = "_"+ cate.getId() + "_";
|
||||
if (cate.getPid() != 0L) {
|
||||
// System.out.println("父节点变成其他点了");
|
||||
T newParentCate = repo.findById(cate.getPid()).get();
|
||||
newTier = newParentCate.getTier() + cate.getId() + "_";
|
||||
}
|
||||
cate.setTier(newTier);
|
||||
repo.save(cate);
|
||||
//更新子节点
|
||||
String sql = "select id,tier as name from " + table + " where tier like ? and id<>?";
|
||||
// System.out.println(sql);
|
||||
List<SidName> list = jdbcHelper.findSidNameList(sql, oldTier + "%", cate.getId());
|
||||
|
||||
String updateSql = "update " + table + " set tier=? where id=?";
|
||||
List<Object[]> updateList = new ArrayList<Object[]>();
|
||||
for (SidName ztwo : list) {
|
||||
Object[] arr = new Object[2];
|
||||
arr[0] = ztwo.getName().replace(oldTier, newTier);
|
||||
arr[1] = ztwo.getId();
|
||||
updateList.add(arr);
|
||||
}
|
||||
jdbcHelper.batch(updateSql, updateList);
|
||||
}
|
||||
return cate.getId();
|
||||
}
|
||||
|
||||
//删除
|
||||
public int delete(Long[] ids) {
|
||||
for (Long id : ids) {
|
||||
repo.deleteById(id);
|
||||
}
|
||||
return ids.length;
|
||||
}
|
||||
|
||||
//---------------------------------------构建树形结构辅助方法-------------------------------------
|
||||
|
||||
//使用递归方法建树
|
||||
public List<T> buildByRecursive(List<T> nodes) {
|
||||
List<T> list = new ArrayList<>();
|
||||
for (T node : nodes) {
|
||||
if (node.getPid() == 0L) {
|
||||
list.add(findChildrenByTier(node, nodes));
|
||||
} else {
|
||||
boolean flag = false;
|
||||
for (BaseCateEntity node2 : nodes) {
|
||||
if (Objects.equals(node.getPid(),(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 (Objects.equals(node.getId(),item.getPid())) {
|
||||
if (node.getChildren() == null) {
|
||||
node.setChildren(new ArrayList<>());
|
||||
}
|
||||
node.getChildren().add(findChildrenByTier(item, nodes));
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
//---------------------------------------bean注入-------------------------------------
|
||||
public Integer getCount(Long pid, String table) {
|
||||
if (pid != null) {
|
||||
String countSql = "select count(1) from " + table + " where pid=?";
|
||||
Integer count = jdbcHelper.getTp().queryForObject(countSql, Integer.class, pid);
|
||||
if (count == null) {
|
||||
count = 0;
|
||||
}
|
||||
return count;
|
||||
} else {
|
||||
String countSql = "select count(1) from " + table + " where pid is null";
|
||||
Integer count = jdbcHelper.getTp().queryForObject(countSql, Integer.class);
|
||||
if (count == null) {
|
||||
count = 0;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 节点移动
|
||||
* @param bo
|
||||
* @param table
|
||||
* draid 拖动节点ID
|
||||
* droid 放下时目标节点ID
|
||||
*/
|
||||
public void move(Lmove bo, String table) {
|
||||
T dragCate = repo.findById(bo.getDraid()).get();
|
||||
|
||||
//节点移动后,节点同级的下方节点ornum--
|
||||
String sql = "select id,ornum from " + table + " where ornum>? and pid=?";
|
||||
List<SidOrnum> list2 = jdbcHelper.getTp().query(sql, new BeanPropertyRowMapper<>(SidOrnum.class), dragCate.getOrnum(), dragCate.getPid());
|
||||
String updateSql = "update " + table + " set ornum=? where id=?";
|
||||
List<Object[]> updateList = new ArrayList<>();
|
||||
for (SidOrnum sidOrnum : list2) {
|
||||
Object[] arr = new Object[2];
|
||||
arr[0] = sidOrnum.getOrnum() - 1;
|
||||
arr[1] = sidOrnum.getId();
|
||||
updateList.add(arr);
|
||||
}
|
||||
jdbcHelper.batch(updateSql, updateList);
|
||||
|
||||
if ("inner".equals(bo.getType())) {
|
||||
Integer count = getCount(bo.getDroid(), table);
|
||||
dragCate.setPid(bo.getDroid());
|
||||
dragCate.setOrnum(count + 1);
|
||||
} else if ("before".equals(bo.getType())) {
|
||||
T dropCate = repo.findById(bo.getDroid()).get();
|
||||
Integer dropCateOrnum = dropCate.getOrnum();
|
||||
//目标节点与同级下方节点ornum++
|
||||
String sql3 = "select id,ornum from " + table + " where ornum>=? and pid=?";
|
||||
List<SidOrnum> list3 = jdbcHelper.getTp().query(sql3, new BeanPropertyRowMapper<>(SidOrnum.class), dropCate.getOrnum(), dropCate.getPid());
|
||||
String updateSql3 = "update " + table + " set ornum=? where id=?";
|
||||
List<Object[]> updateList3 = new ArrayList<>();
|
||||
for (SidOrnum sidOrnum : list3) {
|
||||
Object[] arr = new Object[2];
|
||||
arr[0] = sidOrnum.getOrnum() + 1;
|
||||
arr[1] = sidOrnum.getId();
|
||||
updateList3.add(arr);
|
||||
}
|
||||
jdbcHelper.batch(updateSql3, updateList3);
|
||||
dragCate.setPid(dropCate.getPid());
|
||||
dragCate.setOrnum(dropCateOrnum);
|
||||
} else if ("after".equals(bo.getType())) {
|
||||
T dropCate = repo.findById(bo.getDroid()).get();
|
||||
Integer dropCateOrnum = dropCate.getOrnum();
|
||||
//目标节点同级下方节点ornum++
|
||||
String sql4 = "select id,ornum from " + table + " where ornum>? and pid=?";
|
||||
List<SidOrnum> list4 = jdbcHelper.getTp().query(sql4, new BeanPropertyRowMapper<>(SidOrnum.class), dropCate.getOrnum(), dropCate.getPid());
|
||||
String updateSql4 = "update " + table + " set ornum=? where id=?";
|
||||
List<Object[]> updateList4 = new ArrayList<>();
|
||||
for (SidOrnum sidOrnum : list4) {
|
||||
Object[] arr = new Object[2];
|
||||
arr[0] = sidOrnum.getOrnum() + 1;
|
||||
arr[1] = sidOrnum.getId();
|
||||
updateList4.add(arr);
|
||||
}
|
||||
jdbcHelper.batch(updateSql4, updateList4);
|
||||
dragCate.setPid(dropCate.getPid());
|
||||
dragCate.setOrnum(dropCateOrnum+1);
|
||||
}
|
||||
update(dragCate, table);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
protected JdbcHelper jdbcHelper;
|
||||
|
||||
@Setter
|
||||
protected JpaRepository<T, Long> repo;
|
||||
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
package vben.common.jpa.service;
|
||||
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import vben.common.core.utils.IdUtils;
|
||||
import vben.common.jdbc.dto.PageData;
|
||||
import vben.common.jdbc.sqler.JdbcHelper;
|
||||
import vben.common.jdbc.sqler.Sqler;
|
||||
import vben.common.jpa.entity.BaseMainEntity;
|
||||
import vben.common.satoken.utils.LoginHelper;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
//主数据Service基类,提供主数据Entity增删改查的通用方法
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public abstract class BaseMainService<T extends BaseMainEntity> {
|
||||
|
||||
//---------------------------------------查询-------------------------------------
|
||||
//查询分页
|
||||
@Transactional(readOnly = true)
|
||||
public PageData findPageData(Sqler sqler) {
|
||||
if (sqler.getAutoType() == 1) {
|
||||
sqler.selectCUinfo();
|
||||
sqler.addOrder("t.crtim desc");
|
||||
}
|
||||
return jdbcHelper.findPageData(sqler);
|
||||
}
|
||||
|
||||
//查询MapList数据
|
||||
@Transactional(readOnly = true)
|
||||
public List<Map<String, Object>> findMapList(Sqler sqler) {
|
||||
return jdbcHelper.findMapList(sqler);
|
||||
}
|
||||
|
||||
//根据ID判断数据库实体是否存在
|
||||
@Transactional(readOnly = true)
|
||||
public boolean existsById(Long id) {
|
||||
return repo.existsById(id);
|
||||
}
|
||||
|
||||
//查询单个实体详细信息
|
||||
@Transactional(readOnly = true)
|
||||
public T select(Long id) {
|
||||
T main=repo.findById(id).get();
|
||||
//下面的可优化,从缓存读取
|
||||
String sql = "select name from sys_org where id = ?";
|
||||
if(main.getCruid()!=null){
|
||||
main.setCruna(jdbcHelper.findString(sql, main.getCruid()));
|
||||
}
|
||||
if(main.getUpuid()!=null){
|
||||
main.setUpuna(jdbcHelper.findString(sql, main.getUpuid()));
|
||||
}
|
||||
return main;
|
||||
}
|
||||
|
||||
//查询所有记录
|
||||
@Transactional(readOnly = true)
|
||||
public List<T> findAll() {
|
||||
return repo.findAll();
|
||||
}
|
||||
|
||||
//---------------------------------------增删改-------------------------------------
|
||||
//新增
|
||||
public Long insert(T main) {
|
||||
if (main.getId() == null) {
|
||||
main.setId(IdUtils.getSnowflakeNextId());
|
||||
}
|
||||
// main.setCrtim(new Date());
|
||||
main.setUptim(main.getCrtim());
|
||||
|
||||
if (main.getCruid() == null) {
|
||||
String UserId=LoginHelper.getUserId();
|
||||
main.setCruid(UserId);
|
||||
main.setUpuid(UserId);
|
||||
}
|
||||
repo.save(main);
|
||||
return main.getId();
|
||||
}
|
||||
|
||||
//修改
|
||||
public Long update(T main) {
|
||||
main.setUptim(new Date());
|
||||
main.setUpuid(LoginHelper.getUserId());
|
||||
repo.save(main);
|
||||
return main.getId();
|
||||
}
|
||||
|
||||
//删除
|
||||
public int delete(Long[] ids) {
|
||||
for (Long id : ids) {
|
||||
repo.deleteById(id);
|
||||
}
|
||||
return ids.length;
|
||||
}
|
||||
|
||||
//新增或修改
|
||||
public T save(T t) {
|
||||
return repo.save(t);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------bean注入-------------------------------------
|
||||
@Autowired
|
||||
protected JdbcHelper jdbcHelper;
|
||||
|
||||
@Setter
|
||||
protected JpaRepository<T, Long> repo;
|
||||
|
||||
}
|
||||
+16
-18
@@ -1,15 +1,17 @@
|
||||
package vben.common.jpa.service;
|
||||
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import vben.common.core.utils.StrUtils;
|
||||
import vben.common.jdbc.dto.*;
|
||||
import vben.common.jdbc.root.Db;
|
||||
import vben.common.jdbc.sqler.JdbcHelper;
|
||||
import vben.common.jdbc.sqler.Sqler;
|
||||
import vben.common.core.utils.IdUtils;
|
||||
import vben.common.jpa.entity.BaseStringCateEntity;
|
||||
import vben.common.jpa.entity.BaseStrCateEntity;
|
||||
import vben.common.jpa.entity.SysOrg;
|
||||
import vben.common.satoken.utils.LoginHelper;
|
||||
|
||||
@@ -19,7 +21,7 @@ import java.util.List;
|
||||
|
||||
//分类Service基类,提供分类Entity增删改查的通用方法
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public abstract class BaseStringCateService<T extends BaseStringCateEntity> {
|
||||
public abstract class BaseStrCateService<T extends BaseStrCateEntity> {
|
||||
|
||||
//---------------------------------------查询-------------------------------------
|
||||
//查询Tree树形集合数据
|
||||
@@ -36,7 +38,7 @@ public abstract class BaseStringCateService<T extends BaseStringCateEntity> {
|
||||
// public List<Stree> findTreeList(String table, String name){
|
||||
// Sqler sqler = new Sqler(table);
|
||||
// sqler.addSelect("pid");
|
||||
// sqler.addWhere("t.avtag = 1");
|
||||
// sqler.addWhere("t.avtag = "+Db.True);
|
||||
// sqler.addLike("t.name", name);
|
||||
// sqler.addOrder("t.ornum");
|
||||
// return jdbcHelper.findTreeList(sqler);
|
||||
@@ -45,9 +47,9 @@ public abstract class BaseStringCateService<T extends BaseStringCateEntity> {
|
||||
@Transactional(readOnly = true)
|
||||
public List<Stree> findTreeList(Sqler sqler, String name, String id){
|
||||
sqler.addSelect("pid");
|
||||
sqler.addWhere("t.avtag = 1");
|
||||
sqler.addWhere("t.avtag = "+ Db.True);
|
||||
if (StrUtils.isNotBlank(id)) {
|
||||
sqler.addWhere("t.tier not like ?", "%" + id + ";%");
|
||||
sqler.addWhere("t.tier not like ?", "%_" + id + "_%");
|
||||
sqler.addWhere("t.id <> ?", id);
|
||||
}
|
||||
sqler.addLike("t.name", name);
|
||||
@@ -92,9 +94,9 @@ public abstract class BaseStringCateService<T extends BaseStringCateEntity> {
|
||||
// public List<Stree> inpChoose(String table, String id, String name){
|
||||
// Sqler sqler = new Sqler(table);
|
||||
// sqler.addSelect("pid");
|
||||
// sqler.addWhere("t.avtag = 1");
|
||||
// sqler.addWhere("t.avtag = "+Db.True);
|
||||
// if (StrUtils.isNotBlank(id)) {
|
||||
// sqler.addWhere("t.tier not like ?", "%;" + id + ";%");
|
||||
// sqler.addWhere("t.tier not like ?", "%_" + id + "_%");
|
||||
// sqler.addWhere("t.id <> ?", id);
|
||||
// }
|
||||
// if(StrUtils.isNotBlank(name)){
|
||||
@@ -109,7 +111,7 @@ public abstract class BaseStringCateService<T extends BaseStringCateEntity> {
|
||||
// public R inpFind(String table){
|
||||
// Sqler sqlHelper = new Sqler(table);
|
||||
// sqlHelper.addSelect("pid");
|
||||
// sqlHelper.addWhere("t.avtag = 1");
|
||||
// sqlHelper.addWhere("t.avtag = "+Db.True);
|
||||
// sqlHelper.addOrder("t.ornum");
|
||||
// return R.ok(jdbcDao.findInpList(sqlHelper));
|
||||
// }
|
||||
@@ -142,9 +144,9 @@ public abstract class BaseStringCateService<T extends BaseStringCateEntity> {
|
||||
}
|
||||
if (cate.getPid() != null) {
|
||||
T parent = repo.findById(cate.getPid()).get();
|
||||
cate.setTier(parent.getTier()+"_"+cate.getId());
|
||||
cate.setTier(parent.getTier()+cate.getId()+"_");
|
||||
} else {
|
||||
cate.setTier(cate.getId());
|
||||
cate.setTier("_"+cate.getId()+"_");
|
||||
}
|
||||
cate.setUptim(cate.getCrtim());
|
||||
repo.save(cate);
|
||||
@@ -154,9 +156,7 @@ public abstract class BaseStringCateService<T extends BaseStringCateEntity> {
|
||||
//更新
|
||||
public String update(T cate){
|
||||
cate.setUptim(new Date());
|
||||
if(cate.getUpman()==null){
|
||||
cate.setUpman(new SysOrg(LoginHelper.getUserId()));
|
||||
}
|
||||
cate.setUpman(new SysOrg(LoginHelper.getUserId()));
|
||||
repo.save(cate);
|
||||
return cate.getId();
|
||||
}
|
||||
@@ -226,7 +226,7 @@ public abstract class BaseStringCateService<T extends BaseStringCateEntity> {
|
||||
list.add(findChildrenByTier(node, nodes));
|
||||
} else {
|
||||
boolean flag = false;
|
||||
for (BaseStringCateEntity node2 : nodes) {
|
||||
for (BaseStrCateEntity node2 : nodes) {
|
||||
if (node.getPid().equals(node2.getId())) {
|
||||
flag = true;
|
||||
break;
|
||||
@@ -272,7 +272,7 @@ public abstract class BaseStringCateService<T extends BaseStringCateEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
public void move(TreeMoveBo bo, String table) throws Exception {
|
||||
public void move(Smove bo, String table) throws Exception {
|
||||
T dragDept= repo.findById(bo.getDraid()).get();
|
||||
List<SidOrnum> list2;
|
||||
if(StrUtils.isNotBlank(dragDept.getPid())){
|
||||
@@ -372,9 +372,7 @@ public abstract class BaseStringCateService<T extends BaseStringCateEntity> {
|
||||
@Autowired
|
||||
protected JdbcHelper jdbcHelper;
|
||||
|
||||
@Setter
|
||||
protected JpaRepository<T,String> repo;
|
||||
|
||||
public void setRepo(JpaRepository<T,String> repo) {
|
||||
this.repo = repo;
|
||||
}
|
||||
}
|
||||
+5
-9
@@ -1,7 +1,8 @@
|
||||
package vben.common.jpa.service;
|
||||
|
||||
import lombok.Setter;
|
||||
import vben.common.jdbc.dto.PageData;
|
||||
import vben.common.jpa.entity.BaseStringMainEntity;
|
||||
import vben.common.jpa.entity.BaseStrMainEntity;
|
||||
import vben.common.jdbc.sqler.JdbcHelper;
|
||||
import vben.common.jdbc.sqler.Sqler;
|
||||
import vben.common.core.utils.IdUtils;
|
||||
@@ -17,7 +18,7 @@ import java.util.Map;
|
||||
|
||||
//主数据Service基类,提供主数据Entity增删改查的通用方法
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public abstract class BaseStringMainService<T extends BaseStringMainEntity> {
|
||||
public abstract class BaseStrMainService<T extends BaseStrMainEntity> {
|
||||
|
||||
//---------------------------------------查询-------------------------------------
|
||||
//查询分页
|
||||
@@ -72,9 +73,7 @@ public abstract class BaseStringMainService<T extends BaseStringMainEntity> {
|
||||
//修改
|
||||
public String update(T main) {
|
||||
main.setUptim(new Date());
|
||||
if (main.getUpman() == null) {
|
||||
main.setUpman(new SysOrg(LoginHelper.getUserId()));
|
||||
}
|
||||
main.setUpman(new SysOrg(LoginHelper.getUserId()));
|
||||
repo.save(main);
|
||||
return main.getId();
|
||||
}
|
||||
@@ -97,10 +96,7 @@ public abstract class BaseStringMainService<T extends BaseStringMainEntity> {
|
||||
@Autowired
|
||||
protected JdbcHelper jdbcHelper;
|
||||
|
||||
@Setter
|
||||
protected JpaRepository<T, String> repo;
|
||||
|
||||
public void setRepo(JpaRepository<T, String> repo) {
|
||||
this.repo = repo;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,6 +26,11 @@
|
||||
<artifactId>vben-common-satoken</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zsvg</groupId>
|
||||
<artifactId>vben-common-jdbc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- dynamic-datasource 多数据源-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
@@ -37,6 +42,12 @@
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>icu.mhb</groupId>
|
||||
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
||||
<version>2.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-jsqlparser</artifactId>
|
||||
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
package vben.common.mybatis.core.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* CateEntity基类
|
||||
*
|
||||
* @author baby_fox
|
||||
*/
|
||||
@Data
|
||||
public class BaseCateEntity implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 父ID
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Long pid;
|
||||
|
||||
/**
|
||||
* 层级
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private String tier;
|
||||
|
||||
/**
|
||||
* 子分类
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private List<BaseCateEntity> children = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
private Integer ornum;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String notes;
|
||||
|
||||
/**
|
||||
* 可用标记
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Boolean avtag;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date crtim;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String cruid;
|
||||
|
||||
// /**
|
||||
// * 创建人
|
||||
// */
|
||||
// @TableField(exist = false)
|
||||
// private SysOrg crman;
|
||||
|
||||
/**
|
||||
* 创建人姓名
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String cruna;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date uptim;
|
||||
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private String upuid;
|
||||
|
||||
// /**
|
||||
// * 更新人
|
||||
// */
|
||||
// @TableField(exist = false)
|
||||
// private SysOrg upman;
|
||||
|
||||
/**
|
||||
* 更新人姓名
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String upuna;
|
||||
|
||||
//
|
||||
// /**
|
||||
// * 标签
|
||||
// */
|
||||
// private String label;
|
||||
|
||||
|
||||
/**
|
||||
* 搜索值
|
||||
*/
|
||||
@JsonIgnore
|
||||
@TableField(exist = false)
|
||||
private String searchValue;
|
||||
|
||||
/**
|
||||
* 请求参数
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
@TableField(exist = false)
|
||||
private Map<String, Object> params = new HashMap<>();
|
||||
|
||||
// /**
|
||||
// * 创建部门
|
||||
// */
|
||||
// @TableField(fill = FieldFill.INSERT)
|
||||
// private String createDept;
|
||||
|
||||
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
package vben.common.mybatis.core.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* MainEntity基类
|
||||
*
|
||||
* @author baby_fox
|
||||
*/
|
||||
@Data
|
||||
public class BaseMainEntity implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String notes;
|
||||
|
||||
/**
|
||||
* 可用标记
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Boolean avtag;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date crtim;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String cruid;
|
||||
|
||||
// /**
|
||||
// * 创建人
|
||||
// */
|
||||
// @TableField(exist = false)
|
||||
// private SysOrg crman;
|
||||
|
||||
/**
|
||||
* 创建人姓名
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String cruna;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date uptim;
|
||||
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private String upuid;
|
||||
|
||||
// /**
|
||||
// * 更新人
|
||||
// */
|
||||
// @TableField(exist = false)
|
||||
// private SysOrg upman;
|
||||
|
||||
/**
|
||||
* 更新人姓名
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String upuna;
|
||||
|
||||
/**
|
||||
* 搜索值
|
||||
*/
|
||||
@JsonIgnore
|
||||
@TableField(exist = false)
|
||||
private String searchValue;
|
||||
|
||||
/**
|
||||
* 请求参数
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
@TableField(exist = false)
|
||||
private Map<String, Object> params = new HashMap<>();
|
||||
|
||||
// /**
|
||||
// * 创建部门
|
||||
// */
|
||||
// @TableField(fill = FieldFill.INSERT)
|
||||
// private String createDept;
|
||||
|
||||
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package vben.common.mybatis.core.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class SysOrg implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Integer type;
|
||||
|
||||
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package vben.common.mybatis.core.mapper;
|
||||
|
||||
import icu.mhb.mybatisplus.plugln.base.mapper.JoinBaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import vben.common.mybatis.core.domain.SysOrg;
|
||||
|
||||
@Mapper
|
||||
public interface SysOrgMapper extends JoinBaseMapper<SysOrg> {
|
||||
|
||||
|
||||
}
|
||||
+319
@@ -0,0 +1,319 @@
|
||||
package vben.common.mybatis.core.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import vben.common.core.utils.IdUtils;
|
||||
import vben.common.jdbc.dto.*;
|
||||
import vben.common.jdbc.root.Db;
|
||||
import vben.common.jdbc.sqler.JdbcHelper;
|
||||
import vben.common.jdbc.sqler.Sqler;
|
||||
import vben.common.mybatis.core.domain.BaseCateEntity;
|
||||
import vben.common.satoken.utils.LoginHelper;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
//主数据Service基类,提供主数据Entity增删改查的通用方法
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public abstract class BaseCateService<T extends BaseCateEntity> {
|
||||
|
||||
//---------------------------------------查询-------------------------------------
|
||||
@Transactional(readOnly = true)
|
||||
public List<Ltree> findTreeList(Sqler sqler, String name, Long id) {
|
||||
sqler.addSelect("pid");
|
||||
sqler.addWhere("t.avtag = "+ Db.True);
|
||||
if (id != null) {
|
||||
sqler.addWhere("t.tier not like ?", "%_" + id + "_%");
|
||||
sqler.addWhere("t.id <> ?", id);
|
||||
}
|
||||
sqler.addLike("t.name", name);
|
||||
sqler.addOrder("t.ornum");
|
||||
return jdbcHelper.findLtreeList(sqler);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<T> findList(Sqler sqler, Class<T> clazz) {
|
||||
sqler.selectCUinfo().addSelect("t.pid,t.ornum");
|
||||
sqler.addOrder("t.ornum");
|
||||
List<T> list = jdbcHelper.getTp().query(sqler.getSql(), sqler.getParams(),
|
||||
new BeanPropertyRowMapper<>(clazz));
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<SidNamePid> findInpList(String table, String name) {
|
||||
Sqler sqler = new Sqler(table);
|
||||
sqler.addSelect("t.pid");
|
||||
sqler.addLike("t.name", name);
|
||||
sqler.addOrder("t.ornum");
|
||||
return jdbcHelper.getTp().query(sqler.getSql(), new BeanPropertyRowMapper<>(SidNamePid.class));
|
||||
}
|
||||
|
||||
//查询分页
|
||||
@Transactional(readOnly = true)
|
||||
public PageData findPageData(Sqler sqler) {
|
||||
if (sqler.getAutoType() == 1) {
|
||||
sqler.selectCUinfo();
|
||||
sqler.addOrder("t.crtim desc");
|
||||
}
|
||||
return jdbcHelper.findPageData(sqler);
|
||||
}
|
||||
|
||||
//查询MapList数据
|
||||
@Transactional(readOnly = true)
|
||||
public List<Map<String, Object>> findMapList(Sqler sqler) {
|
||||
sqler.selectCUinfo().addSelect("t.pid,t.ornum");
|
||||
sqler.addOrder("t.ornum");
|
||||
return jdbcHelper.findMapList(sqler);
|
||||
}
|
||||
|
||||
//根据ID判断数据库实体是否存在
|
||||
// @Transactional(readOnly = true)
|
||||
// public boolean existsById(Long id) {
|
||||
// return mapper.exists(id);
|
||||
// }
|
||||
|
||||
//查询单个实体详细信息
|
||||
@Transactional(readOnly = true)
|
||||
public T select(Long id) {
|
||||
T cate= mapper.selectById(id);
|
||||
//下面的可优化,从缓存读取
|
||||
String sql = "select name from sys_org where id = ?";
|
||||
if(cate.getCruid()!=null){
|
||||
cate.setCruna(jdbcHelper.findString(sql, cate.getCruid()));
|
||||
}
|
||||
if(cate.getUpuid()!=null){
|
||||
cate.setUpuna(jdbcHelper.findString(sql, cate.getUpuid()));
|
||||
}
|
||||
return cate;
|
||||
}
|
||||
|
||||
//查询所有记录
|
||||
// @Transactional(readOnly = true)
|
||||
// public List<T> findAll() {
|
||||
// return mapper.findAll();
|
||||
// }
|
||||
|
||||
//---------------------------------------增删改-------------------------------------
|
||||
//新增
|
||||
public Long insert(T cate,String table) {
|
||||
if(cate.getPid()==null){
|
||||
cate.setPid(0L);
|
||||
}
|
||||
if(cate.getOrnum()==null){
|
||||
cate.setOrnum(getCount(cate.getPid(), table) + 1);
|
||||
}
|
||||
if (cate.getId() == null) {
|
||||
cate.setId(IdUtils.getSnowflakeNextId());
|
||||
}
|
||||
cate.setCrtim(new Date());
|
||||
cate.setUptim(cate.getCrtim());
|
||||
if (cate.getCruid() == null) {
|
||||
String UserId=LoginHelper.getUserId();
|
||||
cate.setCruid(UserId);
|
||||
cate.setUpuid(UserId);
|
||||
}
|
||||
if (cate.getPid() != 0) {
|
||||
T parent = mapper.selectById(cate.getPid());
|
||||
cate.setTier( parent.getTier() + cate.getId() + "_");
|
||||
} else {
|
||||
cate.setTier("_" + cate.getId() + "_");
|
||||
}
|
||||
mapper.insert(cate);
|
||||
return cate.getId();
|
||||
}
|
||||
|
||||
//修改
|
||||
public Long update(T cate) {
|
||||
if(cate.getPid()==null){
|
||||
cate.setPid(0L);
|
||||
}
|
||||
cate.setUptim(new Date());
|
||||
cate.setUpuid(LoginHelper.getUserId());
|
||||
mapper.updateById(cate);
|
||||
return cate.getId();
|
||||
}
|
||||
|
||||
//级联更新
|
||||
public Long update(T cate, String table) {
|
||||
if(cate.getPid()==null){
|
||||
cate.setPid(0L);
|
||||
}
|
||||
cate.setUptim(new Date());
|
||||
cate.setUpuid(LoginHelper.getUserId());
|
||||
Long newPid = null;
|
||||
if (cate.getPid() != 0L) {
|
||||
newPid = cate.getPid();
|
||||
}
|
||||
String ptSql="select pid,tier from "+table+" where id=?";
|
||||
LpidTier oldCate = jdbcHelper.getTp().queryForObject(ptSql, new BeanPropertyRowMapper<>(LpidTier.class), cate.getId());
|
||||
Long oldPid = 0L;
|
||||
if (oldCate.getPid() != 0L) {
|
||||
oldPid = oldCate.getPid();
|
||||
}
|
||||
String oldTier = oldCate.getTier();
|
||||
if (Objects.equals(oldPid, newPid)) {//如果父节点没有变,则只更新自己
|
||||
// System.out.println("父节点没有变");
|
||||
cate.setTier(oldTier);
|
||||
mapper.updateById(cate);
|
||||
} else {//如果父节点变了,则另外需要更新自己孩子节点的tier层级
|
||||
String newTier ="_" + cate.getId() + "_";
|
||||
if (cate.getPid() != 0L) {
|
||||
// System.out.println("父节点变成其他点了");
|
||||
T newParentCate = mapper.selectById(cate.getPid());
|
||||
newTier = newParentCate.getTier() + cate.getId()+ "_";
|
||||
}
|
||||
cate.setTier(newTier);
|
||||
mapper.updateById(cate);
|
||||
//更新子节点
|
||||
String sql = "select id,tier as name from " + table + " where tier like ? and id<>?";
|
||||
// System.out.println(sql);
|
||||
List<SidName> list = jdbcHelper.findSidNameList(sql, oldTier + "%", cate.getId());
|
||||
|
||||
String updateSql = "update " + table + " set tier=? where id=?";
|
||||
List<Object[]> updateList = new ArrayList<Object[]>();
|
||||
for (SidName ztwo : list) {
|
||||
Object[] arr = new Object[2];
|
||||
arr[0] = ztwo.getName().replace(oldTier, newTier);
|
||||
arr[1] = ztwo.getId();
|
||||
updateList.add(arr);
|
||||
}
|
||||
jdbcHelper.batch(updateSql, updateList);
|
||||
}
|
||||
return cate.getId();
|
||||
}
|
||||
|
||||
//删除
|
||||
public Integer delete(Collection<Long> ids) {
|
||||
return mapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
//---------------------------------------构建树形结构辅助方法-------------------------------------
|
||||
|
||||
//使用递归方法建树
|
||||
public List<T> buildByRecursive(List<T> nodes) {
|
||||
List<T> list = new ArrayList<>();
|
||||
for (T node : nodes) {
|
||||
if (node.getPid() == 0L) {
|
||||
list.add(findChildrenByTier(node, nodes));
|
||||
} else {
|
||||
boolean flag = false;
|
||||
for (BaseCateEntity node2 : nodes) {
|
||||
if (Objects.equals(node.getPid(),(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 (Objects.equals(node.getId(),item.getPid())) {
|
||||
if (node.getChildren() == null) {
|
||||
node.setChildren(new ArrayList<>());
|
||||
}
|
||||
node.getChildren().add(findChildrenByTier(item, nodes));
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
//---------------------------------------bean注入-------------------------------------
|
||||
public Integer getCount(Long pid, String table) {
|
||||
if (pid != null) {
|
||||
String countSql = "select count(1) from " + table + " where pid=?";
|
||||
Integer count = jdbcHelper.getTp().queryForObject(countSql, Integer.class, pid);
|
||||
if (count == null) {
|
||||
count = 0;
|
||||
}
|
||||
return count;
|
||||
} else {
|
||||
String countSql = "select count(1) from " + table + " where pid is null";
|
||||
Integer count = jdbcHelper.getTp().queryForObject(countSql, Integer.class);
|
||||
if (count == null) {
|
||||
count = 0;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 节点移动
|
||||
* @param bo
|
||||
* @param table
|
||||
* draid 拖动节点ID
|
||||
* droid 放下时目标节点ID
|
||||
*/
|
||||
public void move(Lmove bo, String table) {
|
||||
T dragCate = mapper.selectById(bo.getDraid());
|
||||
|
||||
//节点移动后,节点同级的下方节点ornum--
|
||||
String sql = "select id,ornum from " + table + " where ornum>? and pid=?";
|
||||
List<SidOrnum> list2 = jdbcHelper.getTp().query(sql, new BeanPropertyRowMapper<>(SidOrnum.class), dragCate.getOrnum(), dragCate.getPid());
|
||||
String updateSql = "update " + table + " set ornum=? where id=?";
|
||||
List<Object[]> updateList = new ArrayList<>();
|
||||
for (SidOrnum sidOrnum : list2) {
|
||||
Object[] arr = new Object[2];
|
||||
arr[0] = sidOrnum.getOrnum() - 1;
|
||||
arr[1] = sidOrnum.getId();
|
||||
updateList.add(arr);
|
||||
}
|
||||
jdbcHelper.batch(updateSql, updateList);
|
||||
|
||||
if ("inner".equals(bo.getType())) {
|
||||
Integer count = getCount(bo.getDroid(), table);
|
||||
dragCate.setPid(bo.getDroid());
|
||||
dragCate.setOrnum(count + 1);
|
||||
} else if ("before".equals(bo.getType())) {
|
||||
T dropCate = mapper.selectById(bo.getDroid());
|
||||
Integer dropCateOrnum = dropCate.getOrnum();
|
||||
//目标节点与同级下方节点ornum++
|
||||
String sql3 = "select id,ornum from " + table + " where ornum>=? and pid=?";
|
||||
List<SidOrnum> list3 = jdbcHelper.getTp().query(sql3, new BeanPropertyRowMapper<>(SidOrnum.class), dropCate.getOrnum(), dropCate.getPid());
|
||||
String updateSql3 = "update " + table + " set ornum=? where id=?";
|
||||
List<Object[]> updateList3 = new ArrayList<>();
|
||||
for (SidOrnum sidOrnum : list3) {
|
||||
Object[] arr = new Object[2];
|
||||
arr[0] = sidOrnum.getOrnum() + 1;
|
||||
arr[1] = sidOrnum.getId();
|
||||
updateList3.add(arr);
|
||||
}
|
||||
jdbcHelper.batch(updateSql3, updateList3);
|
||||
dragCate.setPid(dropCate.getPid());
|
||||
dragCate.setOrnum(dropCateOrnum);
|
||||
} else if ("after".equals(bo.getType())) {
|
||||
T dropCate = mapper.selectById(bo.getDroid());
|
||||
Integer dropCateOrnum = dropCate.getOrnum();
|
||||
//目标节点同级下方节点ornum++
|
||||
String sql4 = "select id,ornum from " + table + " where ornum>? and pid=?";
|
||||
List<SidOrnum> list4 = jdbcHelper.getTp().query(sql4, new BeanPropertyRowMapper<>(SidOrnum.class), dropCate.getOrnum(), dropCate.getPid());
|
||||
String updateSql4 = "update " + table + " set ornum=? where id=?";
|
||||
List<Object[]> updateList4 = new ArrayList<>();
|
||||
for (SidOrnum sidOrnum : list4) {
|
||||
Object[] arr = new Object[2];
|
||||
arr[0] = sidOrnum.getOrnum() + 1;
|
||||
arr[1] = sidOrnum.getId();
|
||||
updateList4.add(arr);
|
||||
}
|
||||
jdbcHelper.batch(updateSql4, updateList4);
|
||||
dragCate.setPid(dropCate.getPid());
|
||||
dragCate.setOrnum(dropCateOrnum+1);
|
||||
}
|
||||
update(dragCate, table);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
protected JdbcHelper jdbcHelper;
|
||||
|
||||
@Setter
|
||||
protected BaseMapper<T> mapper;
|
||||
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
package vben.common.mybatis.core.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import vben.common.core.utils.IdUtils;
|
||||
import vben.common.jdbc.dto.PageData;
|
||||
import vben.common.jdbc.sqler.JdbcHelper;
|
||||
import vben.common.jdbc.sqler.Sqler;
|
||||
import vben.common.mybatis.core.domain.BaseMainEntity;
|
||||
import vben.common.satoken.utils.LoginHelper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
//主数据Service基类,提供主数据Entity增删改查的通用方法
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public abstract class BaseMainService<T extends BaseMainEntity> {
|
||||
|
||||
//---------------------------------------查询-------------------------------------
|
||||
//查询分页
|
||||
@Transactional(readOnly = true)
|
||||
public PageData findPageData(Sqler sqler) {
|
||||
if (sqler.getAutoType() == 1) {
|
||||
sqler.selectCUinfo();
|
||||
sqler.addOrder("t.crtim desc");
|
||||
}
|
||||
return jdbcHelper.findPageData(sqler);
|
||||
}
|
||||
|
||||
//查询MapList数据
|
||||
@Transactional(readOnly = true)
|
||||
public List<Map<String, Object>> findMapList(Sqler sqler) {
|
||||
return jdbcHelper.findMapList(sqler);
|
||||
}
|
||||
|
||||
//根据ID判断数据库实体是否存在
|
||||
// @Transactional(readOnly = true)
|
||||
// public boolean existsById(Long id) {
|
||||
// return mapper.exists(id);
|
||||
// }
|
||||
|
||||
//查询单个实体详细信息
|
||||
// @Transactional(readOnly = true)
|
||||
public T select(Long id) {
|
||||
T main= mapper.selectById(id);
|
||||
//下面的可优化,从缓存读取
|
||||
String sql = "select name from sys_org where id = ?";
|
||||
if(main.getCruid()!=null){
|
||||
main.setCruna(jdbcHelper.findString(sql, main.getCruid()));
|
||||
}
|
||||
if(main.getUpuid()!=null){
|
||||
main.setUpuna(jdbcHelper.findString(sql, main.getUpuid()));
|
||||
}
|
||||
return main;
|
||||
}
|
||||
|
||||
//查询所有记录
|
||||
// @Transactional(readOnly = true)
|
||||
// public List<T> findAll() {
|
||||
// return mapper.findAll();
|
||||
// }
|
||||
|
||||
//---------------------------------------增删改-------------------------------------
|
||||
//新增
|
||||
public Long insert(T main) {
|
||||
if (main.getId() == null) {
|
||||
main.setId(IdUtils.getSnowflakeNextId());
|
||||
}
|
||||
main.setCrtim(new Date());
|
||||
main.setUptim(main.getCrtim());
|
||||
if (main.getCruid() == null) {
|
||||
String UserId=LoginHelper.getUserId();
|
||||
main.setCruid(UserId);
|
||||
main.setUpuid(UserId);
|
||||
}
|
||||
mapper.insert(main);
|
||||
return main.getId();
|
||||
}
|
||||
|
||||
//修改
|
||||
public Long update(T main) {
|
||||
main.setUptim(new Date());
|
||||
main.setUpuid(LoginHelper.getUserId());
|
||||
mapper.updateById(main);
|
||||
return main.getId();
|
||||
}
|
||||
|
||||
//删除
|
||||
public Integer delete(Collection<Long> ids) {
|
||||
return mapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
protected JdbcHelper jdbcHelper;
|
||||
|
||||
@Setter
|
||||
protected BaseMapper<T> mapper;
|
||||
|
||||
}
|
||||
-1
@@ -61,7 +61,6 @@ public class SecurityConfig implements WebMvcConfigurer {
|
||||
// 检查 header 与 param 里的 clientid 与 token 里的是否一致
|
||||
String headerCid = request.getHeader(LoginHelper.CLIENT_KEY);
|
||||
String paramCid = ServletUtils.getParameter(LoginHelper.CLIENT_KEY);
|
||||
System.out.println(StpUtil.getExtra(LoginHelper.CLIENT_KEY));
|
||||
String clientId = StpUtil.getExtra(LoginHelper.CLIENT_KEY).toString();
|
||||
// String clientId = "e5cd7e4891bf95d1d19206ce24a7b32e";
|
||||
if (!StrUtils.equalsAny(clientId, headerCid, paramCid)) {
|
||||
|
||||
@@ -79,5 +79,35 @@
|
||||
<artifactId>vben-common-social</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zsvg</groupId>
|
||||
<artifactId>vben-common-sms</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zsvg</groupId>
|
||||
<artifactId>vben-common-mail</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zsvg</groupId>
|
||||
<artifactId>vben-common-ratelimiter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zsvg</groupId>
|
||||
<artifactId>vben-common-idempotent</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zsvg</groupId>
|
||||
<artifactId>vben-common-excel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.zsvg</groupId>-->
|
||||
<!-- <artifactId>vben-common-translation</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -3,8 +3,13 @@ package vben.base.auth.captcha;
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import cn.hutool.captcha.AbstractCaptcha;
|
||||
import cn.hutool.captcha.generator.CodeGenerator;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.api.SmsBlend;
|
||||
import org.dromara.sms4j.api.entity.SmsResponse;
|
||||
import org.dromara.sms4j.core.factory.SmsFactory;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
@@ -14,15 +19,19 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import vben.common.core.constant.Constants;
|
||||
import vben.common.core.constant.GlobalConstants;
|
||||
import vben.common.core.domain.R;
|
||||
import vben.common.core.exception.ServiceException;
|
||||
import vben.common.core.utils.IdUtils;
|
||||
import vben.common.core.utils.SpringUtils;
|
||||
import vben.common.core.utils.StrUtils;
|
||||
import vben.common.core.utils.reflect.ReflectUtils;
|
||||
import vben.common.mail.config.properties.MailProperties;
|
||||
import vben.common.mail.utils.MailUtils;
|
||||
import vben.common.redis.utils.RedisUtils;
|
||||
import vben.common.web.config.properties.CaptchaProperties;
|
||||
import vben.common.web.enums.CaptchaType;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/**
|
||||
* 验证码操作处理
|
||||
@@ -38,6 +47,60 @@ public class AuthCaptchaApi {
|
||||
|
||||
private final CaptchaProperties captchaProperties;
|
||||
|
||||
private final MailProperties mailProperties;
|
||||
|
||||
/**
|
||||
* 短信验证码
|
||||
*
|
||||
* @param phonenumber 用户手机号
|
||||
*/
|
||||
@GetMapping("/resource/sms/code")
|
||||
public R<Void> smsCode(@NotBlank(message = "{user.phonenumber.not.blank}") String phonenumber) {
|
||||
String key = GlobalConstants.CAPTCHA_CODE_KEY + phonenumber;
|
||||
String code = RandomUtil.randomNumbers(4);
|
||||
RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
|
||||
// 验证码模板id 自行处理 (查数据库或写死均可)
|
||||
String templateId = "";
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
|
||||
map.put("code", code);
|
||||
SmsBlend smsBlend = SmsFactory.getSmsBlend("config1");
|
||||
SmsResponse smsResponse = smsBlend.sendMessage(phonenumber, templateId, map);
|
||||
if (!smsResponse.isSuccess()) {
|
||||
log.error("验证码短信发送异常 => {}", smsResponse);
|
||||
return R.fail(smsResponse.getData().toString());
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮箱验证码
|
||||
*
|
||||
* @param email 邮箱
|
||||
*/
|
||||
@GetMapping("/resource/email/code")
|
||||
public R<Void> emailCode(@NotBlank(message = "{user.email.not.blank}") String email) {
|
||||
if (!mailProperties.getEnabled()) {
|
||||
return R.fail("当前系统没有开启邮箱功能!");
|
||||
}
|
||||
SpringUtils.getAopProxy(this).emailCodeImpl(email);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮箱验证码
|
||||
* 独立方法避免验证码关闭之后仍然走限流
|
||||
*/
|
||||
public void emailCodeImpl(String email) {
|
||||
String key = GlobalConstants.CAPTCHA_CODE_KEY + email;
|
||||
String code = RandomUtil.randomNumbers(4);
|
||||
RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
|
||||
try {
|
||||
MailUtils.sendText(email, "登录验证码", "您本次验证码为:" + code + ",有效性为" + Constants.CAPTCHA_EXPIRATION + "分钟,请尽快填写。");
|
||||
} catch (Exception e) {
|
||||
log.error("验证码短信发送异常 => {}", e.getMessage());
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user