Merge branch 'master-jdk17' of https://gitee.com/zhijiantianya/yudao-cloud
# Conflicts: # yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/vo/Demo01ContactSaveReqVO.java # yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo02/Demo02CategoryController.java # yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo02/vo/Demo02CategorySaveReqVO.java # yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerSaveReqVO.java # yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo01/Demo01ContactService.java # yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo01/Demo01ContactServiceImpl.java # yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo02/Demo02CategoryService.java # yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo02/Demo02CategoryServiceImpl.java # yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentErpService.java # yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentErpServiceImpl.java # yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.javapull/196/head
commit
d883e08fdd
|
@ -53,4 +53,14 @@ public abstract class BaseDO implements Serializable, TransPojo {
|
|||
@TableLogic
|
||||
private Boolean deleted;
|
||||
|
||||
/**
|
||||
* 把 creator、createTime、updateTime、updater 都清空,避免前端直接传递 creator 之类的字段,直接就被更新了
|
||||
*/
|
||||
public void clean(){
|
||||
this.creator = null;
|
||||
this.createTime = null;
|
||||
this.updater = null;
|
||||
this.updateTime = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -215,4 +215,11 @@ public interface BaseMapperX<T> extends MPJBaseMapper<T> {
|
|||
return delete(new LambdaQueryWrapper<T>().eq(field, value));
|
||||
}
|
||||
|
||||
default int deleteBatch(SFunction<T, ?> field, Collection<?> values) {
|
||||
if (CollUtil.isEmpty(values)) {
|
||||
return 0;
|
||||
}
|
||||
return delete(new LambdaQueryWrapper<T>().in(field, values));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ public class AiUtils {
|
|||
public static ChatOptions buildChatOptions(AiPlatformEnum platform, String model, Double temperature, Integer maxTokens,
|
||||
Set<String> toolNames, Map<String, Object> toolContext) {
|
||||
toolNames = ObjUtil.defaultIfNull(toolNames, Collections.emptySet());
|
||||
toolContext = ObjUtil.defaultIfNull(toolContext, Collections.emptyMap());
|
||||
// noinspection EnhancedSwitchMigration
|
||||
switch (platform) {
|
||||
case TONG_YI:
|
||||
|
|
|
@ -51,7 +51,7 @@ public class BpmProcessIdRedisDAO {
|
|||
String noPrefix = processIdRule.getPrefix() + infix + processIdRule.getPostfix();
|
||||
String key = RedisKeyConstants.BPM_PROCESS_ID + noPrefix;
|
||||
Long no = stringRedisTemplate.opsForValue().increment(key);
|
||||
if (StrUtil.isEmpty(infix)) {
|
||||
if (StrUtil.isNotEmpty(infix)) {
|
||||
// 特殊:没有前缀,则不能过期,不能每次都是从 0 开始
|
||||
stringRedisTemplate.expire(key, Duration.ofDays(1L));
|
||||
}
|
||||
|
|
|
@ -65,7 +65,8 @@ public interface ErrorCodeConstants {
|
|||
ErrorCode DEMO02_CATEGORY_NAME_DUPLICATE = new ErrorCode(1_001_201_005, "已经存在该名字的示例分类");
|
||||
ErrorCode DEMO02_CATEGORY_PARENT_IS_CHILD = new ErrorCode(1_001_201_006, "不能设置自己的子示例分类为父示例分类");
|
||||
ErrorCode DEMO03_STUDENT_NOT_EXISTS = new ErrorCode(1_001_201_007, "学生不存在");
|
||||
ErrorCode DEMO03_GRADE_NOT_EXISTS = new ErrorCode(1_001_201_008, "学生班级不存在");
|
||||
ErrorCode DEMO03_GRADE_EXISTS = new ErrorCode(1_001_201_009, "学生班级已存在");
|
||||
ErrorCode DEMO03_COURSE_NOT_EXISTS = new ErrorCode(1_001_201_008, "学生课程不存在");
|
||||
ErrorCode DEMO03_GRADE_NOT_EXISTS = new ErrorCode(1_001_201_009, "学生班级不存在");
|
||||
ErrorCode DEMO03_GRADE_EXISTS = new ErrorCode(1_001_201_010, "学生班级已存在");
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.infra.enums.codegen;
|
|||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import static cn.hutool.core.util.ArrayUtil.*;
|
||||
import static cn.hutool.core.util.ArrayUtil.firstMatch;
|
||||
|
||||
/**
|
||||
* 代码生成的场景枚举
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package cn.iocoder.yudao.module.infra.enums.codegen;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 代码生成的 VO 类型枚举
|
||||
*
|
||||
* 目前的作用:Controller 新增、修改、响应时,使用 VO 还是 DO
|
||||
* 注意:不包括 Controller 的分页参数!
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum CodegenVOTypeEnum {
|
||||
|
||||
VO(10, "VO"),
|
||||
DO(20, "DO");
|
||||
|
||||
/**
|
||||
* 场景
|
||||
*/
|
||||
private final Integer type;
|
||||
/**
|
||||
* 场景名
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
}
|
|
@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.table;
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
@ -13,8 +11,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
|||
|
||||
@Schema(description = "管理后台 - 表定义分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CodegenTablePageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "表名称,模糊匹配", example = "yudao")
|
||||
|
|
|
@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.infra.controller.admin.config.vo;
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
@ -13,8 +11,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
|||
|
||||
@Schema(description = "管理后台 - 参数配置分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ConfigPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "数据源名称,模糊匹配", example = "名称")
|
||||
|
|
|
@ -60,6 +60,15 @@ public class Demo01ContactController {
|
|||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除示例联系人")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo01-contact:delete')")
|
||||
public CommonResult<Boolean> deleteDemo0iContactList(@RequestParam("ids") List<Long> ids) {
|
||||
demo01ContactService.deleteDemo0iContactListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得示例联系人")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
|
@ -82,12 +91,12 @@ public class Demo01ContactController {
|
|||
@PreAuthorize("@ss.hasPermission('infra:demo01-contact:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportDemo01ContactExcel(@Valid Demo01ContactPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<Demo01ContactDO> list = demo01ContactService.getDemo01ContactPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "示例联系人.xls", "数据", Demo01ContactRespVO.class,
|
||||
BeanUtils.toBean(list, Demo01ContactRespVO.class));
|
||||
BeanUtils.toBean(list, Demo01ContactRespVO.class));
|
||||
}
|
||||
|
||||
}
|
|
@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo;
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
@ -13,8 +11,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
|||
|
||||
@Schema(description = "管理后台 - 示例联系人分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class Demo01ContactPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "名字", example = "张三")
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 示例联系人新增/修改 Request VO")
|
||||
|
|
|
@ -12,13 +12,13 @@ import cn.iocoder.yudao.module.infra.service.demo.demo02.Demo02CategoryService;
|
|||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -80,11 +80,11 @@ public class Demo02CategoryController {
|
|||
@PreAuthorize("@ss.hasPermission('infra:demo02-category:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportDemo02CategoryExcel(@Valid Demo02CategoryListReqVO listReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<Demo02CategoryDO> list = demo02CategoryService.getDemo02CategoryList(listReqVO);
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "示例分类.xls", "数据", Demo02CategoryRespVO.class,
|
||||
BeanUtils.toBean(list, Demo02CategoryRespVO.class));
|
||||
BeanUtils.toBean(list, Demo02CategoryRespVO.class));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +1,10 @@
|
|||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Schema(description = "管理后台 - 示例分类新增/修改 Request VO")
|
||||
@Data
|
||||
public class Demo02CategorySaveReqVO {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03;
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
|
@ -6,13 +6,13 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentRespVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpRespVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
|
||||
import cn.iocoder.yudao.module.infra.service.demo.demo03.Demo03StudentService;
|
||||
import cn.iocoder.yudao.module.infra.service.demo.demo03.erp.Demo03StudentErpService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
@ -31,25 +31,25 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|||
|
||||
@Tag(name = "管理后台 - 学生")
|
||||
@RestController
|
||||
@RequestMapping("/infra/demo03-student")
|
||||
@RequestMapping("/infra/demo03-student-erp")
|
||||
@Validated
|
||||
public class Demo03StudentController {
|
||||
public class Demo03StudentErpController {
|
||||
|
||||
@Resource
|
||||
private Demo03StudentService demo03StudentService;
|
||||
private Demo03StudentErpService demo03StudentErpService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建学生")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:create')")
|
||||
public CommonResult<Long> createDemo03Student(@Valid @RequestBody Demo03StudentSaveReqVO createReqVO) {
|
||||
return success(demo03StudentService.createDemo03Student(createReqVO));
|
||||
public CommonResult<Long> createDemo03Student(@Valid @RequestBody Demo03StudentErpSaveReqVO createReqVO) {
|
||||
return success(demo03StudentErpService.createDemo03Student(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新学生")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:update')")
|
||||
public CommonResult<Boolean> updateDemo03Student(@Valid @RequestBody Demo03StudentSaveReqVO updateReqVO) {
|
||||
demo03StudentService.updateDemo03Student(updateReqVO);
|
||||
public CommonResult<Boolean> updateDemo03Student(@Valid @RequestBody Demo03StudentErpSaveReqVO updateReqVO) {
|
||||
demo03StudentErpService.updateDemo03Student(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,17 @@ public class Demo03StudentController {
|
|||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
|
||||
public CommonResult<Boolean> deleteDemo03Student(@RequestParam("id") Long id) {
|
||||
demo03StudentService.deleteDemo03Student(id);
|
||||
demo03StudentErpService.deleteDemo03Student(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除学生")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
|
||||
public CommonResult<Boolean> deleteDemo03StudentList(@RequestParam("ids") List<Long> ids) {
|
||||
// TODO @puhui999:deleteDemo03StudentList
|
||||
demo03StudentErpService.deleteDemo03StudentListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -66,30 +76,30 @@ public class Demo03StudentController {
|
|||
@Operation(summary = "获得学生")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
|
||||
public CommonResult<Demo03StudentRespVO> getDemo03Student(@RequestParam("id") Long id) {
|
||||
Demo03StudentDO demo03Student = demo03StudentService.getDemo03Student(id);
|
||||
return success(BeanUtils.toBean(demo03Student, Demo03StudentRespVO.class));
|
||||
public CommonResult<Demo03StudentErpRespVO> getDemo03Student(@RequestParam("id") Long id) {
|
||||
Demo03StudentDO demo03Student = demo03StudentErpService.getDemo03Student(id);
|
||||
return success(BeanUtils.toBean(demo03Student, Demo03StudentErpRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得学生分页")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
|
||||
public CommonResult<PageResult<Demo03StudentRespVO>> getDemo03StudentPage(@Valid Demo03StudentPageReqVO pageReqVO) {
|
||||
PageResult<Demo03StudentDO> pageResult = demo03StudentService.getDemo03StudentPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, Demo03StudentRespVO.class));
|
||||
public CommonResult<PageResult<Demo03StudentErpRespVO>> getDemo03StudentPage(@Valid Demo03StudentErpPageReqVO pageReqVO) {
|
||||
PageResult<Demo03StudentDO> pageResult = demo03StudentErpService.getDemo03StudentPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, Demo03StudentErpRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出学生 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportDemo03StudentExcel(@Valid Demo03StudentPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
public void exportDemo03StudentExcel(@Valid Demo03StudentErpPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<Demo03StudentDO> list = demo03StudentService.getDemo03StudentPage(pageReqVO).getList();
|
||||
List<Demo03StudentDO> list = demo03StudentErpService.getDemo03StudentPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentRespVO.class,
|
||||
BeanUtils.toBean(list, Demo03StudentRespVO.class));
|
||||
ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentErpRespVO.class,
|
||||
BeanUtils.toBean(list, Demo03StudentErpRespVO.class));
|
||||
}
|
||||
|
||||
// ==================== 子表(学生课程) ====================
|
||||
|
@ -100,21 +110,21 @@ public class Demo03StudentController {
|
|||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
|
||||
public CommonResult<PageResult<Demo03CourseDO>> getDemo03CoursePage(PageParam pageReqVO,
|
||||
@RequestParam("studentId") Long studentId) {
|
||||
return success(demo03StudentService.getDemo03CoursePage(pageReqVO, studentId));
|
||||
return success(demo03StudentErpService.getDemo03CoursePage(pageReqVO, studentId));
|
||||
}
|
||||
|
||||
@PostMapping("/demo03-course/create")
|
||||
@Operation(summary = "创建学生课程")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:create')")
|
||||
public CommonResult<Long> createDemo03Course(@Valid @RequestBody Demo03CourseDO demo03Course) {
|
||||
return success(demo03StudentService.createDemo03Course(demo03Course));
|
||||
return success(demo03StudentErpService.createDemo03Course(demo03Course));
|
||||
}
|
||||
|
||||
@PutMapping("/demo03-course/update")
|
||||
@Operation(summary = "更新学生课程")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:update')")
|
||||
public CommonResult<Boolean> updateDemo03Course(@Valid @RequestBody Demo03CourseDO demo03Course) {
|
||||
demo03StudentService.updateDemo03Course(demo03Course);
|
||||
demo03StudentErpService.updateDemo03Course(demo03Course);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -123,7 +133,16 @@ public class Demo03StudentController {
|
|||
@Operation(summary = "删除学生课程")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
|
||||
public CommonResult<Boolean> deleteDemo03Course(@RequestParam("id") Long id) {
|
||||
demo03StudentService.deleteDemo03Course(id);
|
||||
demo03StudentErpService.deleteDemo03Course(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/demo03-course/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除学生课程")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
|
||||
public CommonResult<Boolean> deleteDemo03CourseList(@RequestParam("ids") List<Long> ids) {
|
||||
demo03StudentErpService.deleteDemo03CourseListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -132,15 +151,7 @@ public class Demo03StudentController {
|
|||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
|
||||
public CommonResult<Demo03CourseDO> getDemo03Course(@RequestParam("id") Long id) {
|
||||
return success(demo03StudentService.getDemo03Course(id));
|
||||
}
|
||||
|
||||
@GetMapping("/demo03-course/list-by-student-id")
|
||||
@Operation(summary = "获得学生课程列表")
|
||||
@Parameter(name = "studentId", description = "学生编号")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
|
||||
public CommonResult<List<Demo03CourseDO>> getDemo03CourseListByStudentId(@RequestParam("studentId") Long studentId) {
|
||||
return success(demo03StudentService.getDemo03CourseListByStudentId(studentId));
|
||||
return success(demo03StudentErpService.getDemo03Course(id));
|
||||
}
|
||||
|
||||
// ==================== 子表(学生班级) ====================
|
||||
|
@ -151,21 +162,21 @@ public class Demo03StudentController {
|
|||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
|
||||
public CommonResult<PageResult<Demo03GradeDO>> getDemo03GradePage(PageParam pageReqVO,
|
||||
@RequestParam("studentId") Long studentId) {
|
||||
return success(demo03StudentService.getDemo03GradePage(pageReqVO, studentId));
|
||||
return success(demo03StudentErpService.getDemo03GradePage(pageReqVO, studentId));
|
||||
}
|
||||
|
||||
@PostMapping("/demo03-grade/create")
|
||||
@Operation(summary = "创建学生班级")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:create')")
|
||||
public CommonResult<Long> createDemo03Grade(@Valid @RequestBody Demo03GradeDO demo03Grade) {
|
||||
return success(demo03StudentService.createDemo03Grade(demo03Grade));
|
||||
return success(demo03StudentErpService.createDemo03Grade(demo03Grade));
|
||||
}
|
||||
|
||||
@PutMapping("/demo03-grade/update")
|
||||
@Operation(summary = "更新学生班级")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:update')")
|
||||
public CommonResult<Boolean> updateDemo03Grade(@Valid @RequestBody Demo03GradeDO demo03Grade) {
|
||||
demo03StudentService.updateDemo03Grade(demo03Grade);
|
||||
demo03StudentErpService.updateDemo03Grade(demo03Grade);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -174,7 +185,16 @@ public class Demo03StudentController {
|
|||
@Operation(summary = "删除学生班级")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
|
||||
public CommonResult<Boolean> deleteDemo03Grade(@RequestParam("id") Long id) {
|
||||
demo03StudentService.deleteDemo03Grade(id);
|
||||
demo03StudentErpService.deleteDemo03Grade(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/demo03-grade/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除学生班级")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
|
||||
public CommonResult<Boolean> deleteDemo03GradeList(@RequestParam("ids") List<Long> ids) {
|
||||
demo03StudentErpService.deleteDemo03GradeListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -183,15 +203,7 @@ public class Demo03StudentController {
|
|||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
|
||||
public CommonResult<Demo03GradeDO> getDemo03Grade(@RequestParam("id") Long id) {
|
||||
return success(demo03StudentService.getDemo03Grade(id));
|
||||
}
|
||||
|
||||
@GetMapping("/demo03-grade/get-by-student-id")
|
||||
@Operation(summary = "获得学生班级")
|
||||
@Parameter(name = "studentId", description = "学生编号")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
|
||||
public CommonResult<Demo03GradeDO> getDemo03GradeByStudentId(@RequestParam("studentId") Long studentId) {
|
||||
return success(demo03StudentService.getDemo03GradeByStudentId(studentId));
|
||||
return success(demo03StudentErpService.getDemo03Grade(id));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,8 @@
|
|||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo;
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
@ -13,9 +11,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
|||
|
||||
@Schema(description = "管理后台 - 学生分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class Demo03StudentPageReqVO extends PageParam {
|
||||
public class Demo03StudentErpPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "名字", example = "芋艿")
|
||||
private String name;
|
|
@ -1,4 +1,4 @@
|
|||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo;
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
|
@ -12,7 +12,7 @@ import java.time.LocalDateTime;
|
|||
@Schema(description = "管理后台 - 学生 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class Demo03StudentRespVO {
|
||||
public class Demo03StudentErpRespVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525")
|
||||
@ExcelProperty("编号")
|
|
@ -0,0 +1,33 @@
|
|||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 学生新增/修改 Request VO")
|
||||
@Data
|
||||
public class Demo03StudentErpSaveReqVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
||||
@NotEmpty(message = "名字不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "性别不能为空")
|
||||
private Integer sex;
|
||||
|
||||
@Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "出生日期不能为空")
|
||||
private LocalDateTime birthday;
|
||||
|
||||
@Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便")
|
||||
@NotEmpty(message = "简介不能为空")
|
||||
private String description;
|
||||
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerRespVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
|
||||
import cn.iocoder.yudao.module.infra.service.demo.demo03.inner.Demo03StudentInnerService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - 学生")
|
||||
@RestController
|
||||
@RequestMapping("/infra/demo03-student-inner")
|
||||
@Validated
|
||||
public class Demo03StudentInnerController {
|
||||
|
||||
@Resource
|
||||
private Demo03StudentInnerService demo03StudentInnerService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建学生")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:create')")
|
||||
public CommonResult<Long> createDemo03Student(@Valid @RequestBody Demo03StudentInnerSaveReqVO createReqVO) {
|
||||
return success(demo03StudentInnerService.createDemo03Student(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新学生")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:update')")
|
||||
public CommonResult<Boolean> updateDemo03Student(@Valid @RequestBody Demo03StudentInnerSaveReqVO updateReqVO) {
|
||||
demo03StudentInnerService.updateDemo03Student(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除学生")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
|
||||
public CommonResult<Boolean> deleteDemo03Student(@RequestParam("id") Long id) {
|
||||
demo03StudentInnerService.deleteDemo03Student(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除学生")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
|
||||
public CommonResult<Boolean> deleteDemo03StudentList(@RequestParam("ids") List<Long> ids) {
|
||||
demo03StudentInnerService.deleteDemo03StudentListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得学生")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
|
||||
public CommonResult<Demo03StudentInnerRespVO> getDemo03Student(@RequestParam("id") Long id) {
|
||||
Demo03StudentDO demo03Student = demo03StudentInnerService.getDemo03Student(id);
|
||||
return success(BeanUtils.toBean(demo03Student, Demo03StudentInnerRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得学生分页")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
|
||||
public CommonResult<PageResult<Demo03StudentInnerRespVO>> getDemo03StudentPage(@Valid Demo03StudentInnerPageReqVO pageReqVO) {
|
||||
PageResult<Demo03StudentDO> pageResult = demo03StudentInnerService.getDemo03StudentPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, Demo03StudentInnerRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出学生 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportDemo03StudentExcel(@Valid Demo03StudentInnerPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<Demo03StudentDO> list = demo03StudentInnerService.getDemo03StudentPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentInnerRespVO.class,
|
||||
BeanUtils.toBean(list, Demo03StudentInnerRespVO.class));
|
||||
}
|
||||
|
||||
// ==================== 子表(学生课程) ====================
|
||||
|
||||
@GetMapping("/demo03-course/list-by-student-id")
|
||||
@Operation(summary = "获得学生课程列表")
|
||||
@Parameter(name = "studentId", description = "学生编号")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
|
||||
public CommonResult<List<Demo03CourseDO>> getDemo03CourseListByStudentId(@RequestParam("studentId") Long studentId) {
|
||||
return success(demo03StudentInnerService.getDemo03CourseListByStudentId(studentId));
|
||||
}
|
||||
|
||||
// ==================== 子表(学生班级) ====================
|
||||
|
||||
@GetMapping("/demo03-grade/get-by-student-id")
|
||||
@Operation(summary = "获得学生班级")
|
||||
@Parameter(name = "studentId", description = "学生编号")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
|
||||
public CommonResult<Demo03GradeDO> getDemo03GradeByStudentId(@RequestParam("studentId") Long studentId) {
|
||||
return success(demo03StudentInnerService.getDemo03GradeByStudentId(studentId));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 学生分页 Request VO")
|
||||
@Data
|
||||
public class Demo03StudentInnerPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "名字", example = "芋艿")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "性别")
|
||||
private Integer sex;
|
||||
|
||||
@Schema(description = "简介", example = "随便")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 学生 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class Demo03StudentInnerRespVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525")
|
||||
@ExcelProperty("编号")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
||||
@ExcelProperty("名字")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty(value = "性别", converter = DictConvert.class)
|
||||
@DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private Integer sex;
|
||||
|
||||
@Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("出生日期")
|
||||
private LocalDateTime birthday;
|
||||
|
||||
@Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便")
|
||||
@ExcelProperty("简介")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
|
@ -1,18 +1,18 @@
|
|||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo;
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo;
|
||||
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 学生新增/修改 Request VO")
|
||||
@Data
|
||||
public class Demo03StudentSaveReqVO {
|
||||
public class Demo03StudentInnerSaveReqVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525")
|
||||
private Long id;
|
||||
|
@ -33,9 +33,10 @@ public class Demo03StudentSaveReqVO {
|
|||
@NotEmpty(message = "简介不能为空")
|
||||
private String description;
|
||||
|
||||
|
||||
@Schema(description = "学生课程列表")
|
||||
private List<Demo03CourseDO> demo03Courses;
|
||||
|
||||
@Schema(description = "学生班级")
|
||||
private Demo03GradeDO demo03Grade;
|
||||
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalRespVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
|
||||
import cn.iocoder.yudao.module.infra.service.demo.demo03.normal.Demo03StudentNormalService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - 学生")
|
||||
@RestController
|
||||
@RequestMapping("/infra/demo03-student-normal")
|
||||
@Validated
|
||||
public class Demo03StudentNormalController {
|
||||
|
||||
@Resource
|
||||
private Demo03StudentNormalService demo03StudentNormalService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建学生")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:create')")
|
||||
public CommonResult<Long> createDemo03Student(@Valid @RequestBody Demo03StudentNormalSaveReqVO createReqVO) {
|
||||
return success(demo03StudentNormalService.createDemo03Student(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新学生")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:update')")
|
||||
public CommonResult<Boolean> updateDemo03Student(@Valid @RequestBody Demo03StudentNormalSaveReqVO updateReqVO) {
|
||||
demo03StudentNormalService.updateDemo03Student(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除学生")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
|
||||
public CommonResult<Boolean> deleteDemo03Student(@RequestParam("id") Long id) {
|
||||
demo03StudentNormalService.deleteDemo03Student(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除学生")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
|
||||
public CommonResult<Boolean> deleteDemo03StudentList(@RequestParam("ids") List<Long> ids) {
|
||||
demo03StudentNormalService.deleteDemo03StudentListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得学生")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
|
||||
public CommonResult<Demo03StudentNormalRespVO> getDemo03Student(@RequestParam("id") Long id) {
|
||||
Demo03StudentDO demo03Student = demo03StudentNormalService.getDemo03Student(id);
|
||||
return success(BeanUtils.toBean(demo03Student, Demo03StudentNormalRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得学生分页")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
|
||||
public CommonResult<PageResult<Demo03StudentNormalRespVO>> getDemo03StudentPage(@Valid Demo03StudentNormalPageReqVO pageReqVO) {
|
||||
PageResult<Demo03StudentDO> pageResult = demo03StudentNormalService.getDemo03StudentPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, Demo03StudentNormalRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出学生 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportDemo03StudentExcel(@Valid Demo03StudentNormalPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<Demo03StudentDO> list = demo03StudentNormalService.getDemo03StudentPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentNormalRespVO.class,
|
||||
BeanUtils.toBean(list, Demo03StudentNormalRespVO.class));
|
||||
}
|
||||
|
||||
// ==================== 子表(学生课程) ====================
|
||||
|
||||
@GetMapping("/demo03-course/list-by-student-id")
|
||||
@Operation(summary = "获得学生课程列表")
|
||||
@Parameter(name = "studentId", description = "学生编号")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
|
||||
public CommonResult<List<Demo03CourseDO>> getDemo03CourseListByStudentId(@RequestParam("studentId") Long studentId) {
|
||||
return success(demo03StudentNormalService.getDemo03CourseListByStudentId(studentId));
|
||||
}
|
||||
|
||||
// ==================== 子表(学生班级) ====================
|
||||
|
||||
@GetMapping("/demo03-grade/get-by-student-id")
|
||||
@Operation(summary = "获得学生班级")
|
||||
@Parameter(name = "studentId", description = "学生编号")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
|
||||
public CommonResult<Demo03GradeDO> getDemo03GradeByStudentId(@RequestParam("studentId") Long studentId) {
|
||||
return success(demo03StudentNormalService.getDemo03GradeByStudentId(studentId));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 学生分页 Request VO")
|
||||
@Data
|
||||
public class Demo03StudentNormalPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "名字", example = "芋艿")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "性别")
|
||||
private Integer sex;
|
||||
|
||||
@Schema(description = "简介", example = "随便")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 学生 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class Demo03StudentNormalRespVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525")
|
||||
@ExcelProperty("编号")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
||||
@ExcelProperty("名字")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty(value = "性别", converter = DictConvert.class)
|
||||
@DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private Integer sex;
|
||||
|
||||
@Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("出生日期")
|
||||
private LocalDateTime birthday;
|
||||
|
||||
@Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便")
|
||||
@ExcelProperty("简介")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo;
|
||||
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 学生新增/修改 Request VO")
|
||||
@Data
|
||||
public class Demo03StudentNormalSaveReqVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
||||
@NotEmpty(message = "名字不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "性别不能为空")
|
||||
private Integer sex;
|
||||
|
||||
@Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "出生日期不能为空")
|
||||
private LocalDateTime birthday;
|
||||
|
||||
@Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便")
|
||||
@NotEmpty(message = "简介不能为空")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "学生课程列表")
|
||||
private List<Demo03CourseDO> demo03Courses;
|
||||
|
||||
@Schema(description = "学生班级")
|
||||
private Demo03GradeDO demo03Grade;
|
||||
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03;
|
|
@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.infra.controller.admin.file.vo.config;
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
@ -13,8 +11,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
|||
|
||||
@Schema(description = "管理后台 - 文件配置分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class FileConfigPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "配置名", example = "S3 - 阿里云")
|
||||
|
|
|
@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.infra.controller.admin.file.vo.file;
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
@ -13,8 +11,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
|||
|
||||
@Schema(description = "管理后台 - 文件分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class FilePageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "文件路径,模糊匹配", example = "yudao")
|
||||
|
|
|
@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog;
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
@ -13,8 +11,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
|||
|
||||
@Schema(description = "管理后台 - API 访问日志分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ApiAccessLogPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "用户编号", example = "666")
|
||||
|
|
|
@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog;
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
@ -13,8 +11,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
|||
|
||||
@Schema(description = "管理后台 - API 错误日志分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ApiErrorLogPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "用户编号", example = "666")
|
||||
|
|
|
@ -24,9 +24,9 @@ public interface Demo02CategoryMapper extends BaseMapperX<Demo02CategoryDO> {
|
|||
.orderByDesc(Demo02CategoryDO::getId));
|
||||
}
|
||||
|
||||
default Demo02CategoryDO selectByParentIdAndName(Long parentId, String name) {
|
||||
return selectOne(Demo02CategoryDO::getParentId, parentId, Demo02CategoryDO::getName, name);
|
||||
}
|
||||
default Demo02CategoryDO selectByParentIdAndName(Long parentId, String name) {
|
||||
return selectOne(Demo02CategoryDO::getParentId, parentId, Demo02CategoryDO::getName, name);
|
||||
}
|
||||
|
||||
default Long selectCountByParentId(Long parentId) {
|
||||
return selectCount(Demo02CategoryDO::getParentId, parentId);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03;
|
||||
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
@ -15,7 +15,7 @@ import java.util.List;
|
|||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface Demo03CourseMapper extends BaseMapperX<Demo03CourseDO> {
|
||||
public interface Demo03CourseErpMapper extends BaseMapperX<Demo03CourseDO> {
|
||||
|
||||
default PageResult<Demo03CourseDO> selectPage(PageParam reqVO, Long studentId) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<Demo03CourseDO>()
|
||||
|
@ -23,12 +23,12 @@ public interface Demo03CourseMapper extends BaseMapperX<Demo03CourseDO> {
|
|||
.orderByDesc(Demo03CourseDO::getId));
|
||||
}
|
||||
|
||||
default List<Demo03CourseDO> selectListByStudentId(Long studentId) {
|
||||
return selectList(Demo03CourseDO::getStudentId, studentId);
|
||||
}
|
||||
|
||||
default int deleteByStudentId(Long studentId) {
|
||||
return delete(Demo03CourseDO::getStudentId, studentId);
|
||||
}
|
||||
|
||||
}
|
||||
default int deleteByStudentIds(List<Long> studentIds) {
|
||||
return deleteBatch(Demo03CourseDO::getStudentId, studentIds);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03;
|
||||
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
@ -7,13 +7,15 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
|||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 学生班级 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface Demo03GradeMapper extends BaseMapperX<Demo03GradeDO> {
|
||||
public interface Demo03GradeErpMapper extends BaseMapperX<Demo03GradeDO> {
|
||||
|
||||
default PageResult<Demo03GradeDO> selectPage(PageParam reqVO, Long studentId) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<Demo03GradeDO>()
|
||||
|
@ -29,4 +31,8 @@ public interface Demo03GradeMapper extends BaseMapperX<Demo03GradeDO> {
|
|||
return delete(Demo03GradeDO::getStudentId, studentId);
|
||||
}
|
||||
|
||||
}
|
||||
default int deleteByStudentIds(List<Long> studentIds) {
|
||||
return deleteBatch(Demo03GradeDO::getStudentId, studentIds);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03;
|
||||
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
@ -13,9 +13,9 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface Demo03StudentMapper extends BaseMapperX<Demo03StudentDO> {
|
||||
public interface Demo03StudentErpMapper extends BaseMapperX<Demo03StudentDO> {
|
||||
|
||||
default PageResult<Demo03StudentDO> selectPage(Demo03StudentPageReqVO reqVO) {
|
||||
default PageResult<Demo03StudentDO> selectPage(Demo03StudentErpPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<Demo03StudentDO>()
|
||||
.likeIfPresent(Demo03StudentDO::getName, reqVO.getName())
|
||||
.eqIfPresent(Demo03StudentDO::getSex, reqVO.getSex())
|
|
@ -0,0 +1,29 @@
|
|||
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 学生课程 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface Demo03CourseInnerMapper extends BaseMapperX<Demo03CourseDO> {
|
||||
|
||||
default List<Demo03CourseDO> selectListByStudentId(Long studentId) {
|
||||
return selectList(Demo03CourseDO::getStudentId, studentId);
|
||||
}
|
||||
|
||||
default int deleteByStudentId(Long studentId) {
|
||||
return delete(Demo03CourseDO::getStudentId, studentId);
|
||||
}
|
||||
|
||||
default int deleteByStudentIds(List<Long> studentIds) {
|
||||
return deleteBatch(Demo03CourseDO::getStudentId, studentIds);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 学生班级 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface Demo03GradeInnerMapper extends BaseMapperX<Demo03GradeDO> {
|
||||
|
||||
default Demo03GradeDO selectByStudentId(Long studentId) {
|
||||
return selectOne(Demo03GradeDO::getStudentId, studentId);
|
||||
}
|
||||
|
||||
default int deleteByStudentId(Long studentId) {
|
||||
return delete(Demo03GradeDO::getStudentId, studentId);
|
||||
}
|
||||
|
||||
default int deleteByStudentIds(List<Long> studentIds) {
|
||||
return deleteBatch(Demo03GradeDO::getStudentId, studentIds);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 学生 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface Demo03StudentInnerMapper extends BaseMapperX<Demo03StudentDO> {
|
||||
|
||||
default PageResult<Demo03StudentDO> selectPage(Demo03StudentInnerPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<Demo03StudentDO>()
|
||||
.likeIfPresent(Demo03StudentDO::getName, reqVO.getName())
|
||||
.eqIfPresent(Demo03StudentDO::getSex, reqVO.getSex())
|
||||
.eqIfPresent(Demo03StudentDO::getDescription, reqVO.getDescription())
|
||||
.betweenIfPresent(Demo03StudentDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(Demo03StudentDO::getId));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 学生课程 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface Demo03CourseNormalMapper extends BaseMapperX<Demo03CourseDO> {
|
||||
|
||||
default List<Demo03CourseDO> selectListByStudentId(Long studentId) {
|
||||
return selectList(Demo03CourseDO::getStudentId, studentId);
|
||||
}
|
||||
|
||||
default int deleteByStudentId(Long studentId) {
|
||||
return delete(Demo03CourseDO::getStudentId, studentId);
|
||||
}
|
||||
|
||||
default int deleteByStudentIds(List<Long> studentIds) {
|
||||
return deleteBatch(Demo03CourseDO::getStudentId, studentIds);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 学生班级 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface Demo03GradeNormalMapper extends BaseMapperX<Demo03GradeDO> {
|
||||
|
||||
default Demo03GradeDO selectByStudentId(Long studentId) {
|
||||
return selectOne(Demo03GradeDO::getStudentId, studentId);
|
||||
}
|
||||
|
||||
default int deleteByStudentId(Long studentId) {
|
||||
return delete(Demo03GradeDO::getStudentId, studentId);
|
||||
}
|
||||
|
||||
default int deleteByStudentIds(List<Long> studentIds) {
|
||||
return deleteBatch(Demo03GradeDO::getStudentId, studentIds);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 学生 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface Demo03StudentNormalMapper extends BaseMapperX<Demo03StudentDO> {
|
||||
|
||||
default PageResult<Demo03StudentDO> selectPage(Demo03StudentNormalPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<Demo03StudentDO>()
|
||||
.likeIfPresent(Demo03StudentDO::getName, reqVO.getName())
|
||||
.eqIfPresent(Demo03StudentDO::getSex, reqVO.getSex())
|
||||
.eqIfPresent(Demo03StudentDO::getDescription, reqVO.getDescription())
|
||||
.betweenIfPresent(Demo03StudentDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(Demo03StudentDO::getId));
|
||||
}
|
||||
|
||||
}
|
|
@ -36,7 +36,7 @@ public interface ApiAccessLogMapper extends BaseMapperX<ApiAccessLogDO> {
|
|||
* 物理删除指定时间之前的日志
|
||||
*
|
||||
* @param createTime 最大时间
|
||||
* @param limit 删除条数,防止一次删除太多
|
||||
* @param limit 删除条数,防止一次删除太多
|
||||
* @return 删除条数
|
||||
*/
|
||||
@Delete("DELETE FROM infra_api_access_log WHERE create_time < #{createTime} LIMIT #{limit}")
|
||||
|
|
|
@ -35,10 +35,10 @@ public interface ApiErrorLogMapper extends BaseMapperX<ApiErrorLogDO> {
|
|||
* 物理删除指定时间之前的日志
|
||||
*
|
||||
* @param createTime 最大时间
|
||||
* @param limit 删除条数,防止一次删除太多
|
||||
* @param limit 删除条数,防止一次删除太多
|
||||
* @return 删除条数
|
||||
*/
|
||||
@Delete("DELETE FROM infra_api_error_log WHERE create_time < #{createTime} LIMIT #{limit}")
|
||||
Integer deleteByCreateTimeLt(@Param("createTime") LocalDateTime createTime, @Param("limit")Integer limit);
|
||||
Integer deleteByCreateTimeLt(@Param("createTime") LocalDateTime createTime, @Param("limit") Integer limit);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cn.iocoder.yudao.module.infra.framework.codegen.config;
|
||||
|
||||
import cn.iocoder.yudao.module.infra.enums.codegen.CodegenFrontTypeEnum;
|
||||
import cn.iocoder.yudao.module.infra.enums.codegen.CodegenVOTypeEnum;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
@ -34,6 +35,20 @@ public class CodegenProperties {
|
|||
@NotNull(message = "代码生成的前端类型不能为空")
|
||||
private Integer frontType;
|
||||
|
||||
/**
|
||||
* 代码生成的 VO 类型
|
||||
*
|
||||
* 枚举 {@link CodegenVOTypeEnum#getType()}
|
||||
*/
|
||||
@NotNull(message = "代码生成的 VO 类型不能为空")
|
||||
private Integer voType;
|
||||
|
||||
/**
|
||||
* 是否生成批量删除接口
|
||||
*/
|
||||
@NotNull(message = "是否生成批量删除接口不能为空")
|
||||
private Boolean deleteBatchEnable;
|
||||
|
||||
/**
|
||||
* 是否生成单元测试
|
||||
*/
|
||||
|
|
|
@ -21,7 +21,7 @@ import java.io.IOException;
|
|||
@Slf4j
|
||||
public class FileTypeUtils {
|
||||
|
||||
private static final ThreadLocal<Tika> TIKA = TransmittableThreadLocal.withInitial(Tika::new);
|
||||
private static final Tika TIKA = new Tika();
|
||||
|
||||
/**
|
||||
* 获得文件的 mineType,对于 doc,jar 等文件会有误差
|
||||
|
@ -31,7 +31,7 @@ public class FileTypeUtils {
|
|||
*/
|
||||
@SneakyThrows
|
||||
public static String getMineType(byte[] data) {
|
||||
return TIKA.get().detect(data);
|
||||
return TIKA.detect(data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,7 +41,7 @@ public class FileTypeUtils {
|
|||
* @return mineType 无法识别时会返回“application/octet-stream”
|
||||
*/
|
||||
public static String getMineType(String name) {
|
||||
return TIKA.get().detect(name);
|
||||
return TIKA.detect(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,7 +52,7 @@ public class FileTypeUtils {
|
|||
* @return mineType 无法识别时会返回“application/octet-stream”
|
||||
*/
|
||||
public static String getMineType(byte[] data, String name) {
|
||||
return TIKA.get().detect(data, name);
|
||||
return TIKA.detect(data, name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,7 +22,7 @@ public interface CodegenService {
|
|||
* 基于数据库的表结构,创建代码生成器的表定义
|
||||
*
|
||||
* @param author 作者
|
||||
* @param reqVO 表信息
|
||||
* @param reqVO 表信息
|
||||
* @return 创建的表定义的编号数组
|
||||
*/
|
||||
List<Long> createCodegenList(String author, CodegenCreateListReqVO reqVO);
|
||||
|
@ -92,8 +92,8 @@ public interface CodegenService {
|
|||
* 获得数据库自带的表定义列表
|
||||
*
|
||||
* @param dataSourceConfigId 数据源的配置编号
|
||||
* @param name 表名称
|
||||
* @param comment 表描述
|
||||
* @param name 表名称
|
||||
* @param comment 表描述
|
||||
* @return 表定义列表
|
||||
*/
|
||||
List<DatabaseTableRespVO> getDatabaseTableList(Long dataSourceConfigId, String name, String comment);
|
||||
|
|
|
@ -214,7 +214,6 @@ public class CodegenBuilder {
|
|||
// description、memo、remark
|
||||
if (StrUtil.endWithAnyIgnoreCase(column.getColumnName(), "description", "memo", "remark")) {
|
||||
column.setExample(randomEle(new String[]{"你猜", "随便", "你说的对"}));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO;
|
|||
import cn.iocoder.yudao.module.infra.enums.codegen.CodegenFrontTypeEnum;
|
||||
import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum;
|
||||
import cn.iocoder.yudao.module.infra.enums.codegen.CodegenTemplateTypeEnum;
|
||||
import cn.iocoder.yudao.module.infra.enums.codegen.CodegenVOTypeEnum;
|
||||
import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableTable;
|
||||
|
@ -234,6 +235,8 @@ public class CodegenEngine {
|
|||
globalBindingMap.put("baseFrameworkPackage", codegenProperties.getBasePackage()
|
||||
+ '.' + "framework"); // 用于后续获取测试类的 package 地址
|
||||
globalBindingMap.put("jakartaPackage", jakartaEnable ? "jakarta" : "javax");
|
||||
globalBindingMap.put("voType", codegenProperties.getVoType());
|
||||
globalBindingMap.put("deleteBatchEnable", codegenProperties.getDeleteBatchEnable());
|
||||
// 全局 Java Bean
|
||||
globalBindingMap.put("CommonResultClassName", CommonResult.class.getName());
|
||||
globalBindingMap.put("PageResultClassName", PageResult.class.getName());
|
||||
|
@ -255,14 +258,15 @@ public class CodegenEngine {
|
|||
globalBindingMap.put("ApiAccessLogClassName", ApiAccessLog.class.getName());
|
||||
globalBindingMap.put("OperateTypeEnumClassName", OperateTypeEnum.class.getName());
|
||||
globalBindingMap.put("BeanUtils", BeanUtils.class.getName());
|
||||
globalBindingMap.put("CollectionUtilsClassName", CollectionUtils.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成代码
|
||||
*
|
||||
* @param table 表定义
|
||||
* @param columns table 的字段定义数组
|
||||
* @param subTables 子表数组,当且仅当主子表时使用
|
||||
* @param table 表定义
|
||||
* @param columns table 的字段定义数组
|
||||
* @param subTables 子表数组,当且仅当主子表时使用
|
||||
* @param subColumnsList subTables 的字段定义数组
|
||||
* @return 生成的代码,key 是路径,value 是对应代码
|
||||
*/
|
||||
|
@ -380,14 +384,15 @@ public class CodegenEngine {
|
|||
bindingMap.put("columns", columns);
|
||||
bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, CodegenColumnDO::getPrimaryKey)); // 主键字段
|
||||
bindingMap.put("sceneEnum", CodegenSceneEnum.valueOf(table.getScene()));
|
||||
|
||||
// className 相关
|
||||
// 去掉指定前缀,将 TestDictType 转换成 DictType. 因为在 create 等方法后,不需要带上 Test 前缀
|
||||
String className = table.getClassName();
|
||||
String simpleClassName = equalsAnyIgnoreCase(table.getClassName(), table.getModuleName()) ? table.getClassName()
|
||||
: removePrefix(table.getClassName(), upperFirst(table.getModuleName()));
|
||||
String classNameVar = lowerFirst(simpleClassName);
|
||||
bindingMap.put("simpleClassName", simpleClassName);
|
||||
bindingMap.put("simpleClassName_underlineCase", toUnderlineCase(simpleClassName)); // 将 DictType 转换成 dict_type
|
||||
bindingMap.put("classNameVar", lowerFirst(simpleClassName)); // 将 DictType 转换成 dictType,用于变量
|
||||
bindingMap.put("classNameVar", classNameVar); // 将 DictType 转换成 dictType,用于变量
|
||||
// 将 DictType 转换成 dict-type
|
||||
String simpleClassNameStrikeCase = toSymbolCase(simpleClassName, '-');
|
||||
bindingMap.put("simpleClassName_strikeCase", simpleClassNameStrikeCase);
|
||||
|
@ -441,6 +446,22 @@ public class CodegenEngine {
|
|||
bindingMap.put("subClassNameVars", subClassNameVars);
|
||||
bindingMap.put("subSimpleClassName_strikeCases", subSimpleClassNameStrikeCases);
|
||||
}
|
||||
|
||||
// 多个 vm 公用的 VO 变量
|
||||
if (ObjectUtil.equal(codegenProperties.getVoType(), CodegenVOTypeEnum.VO.getType())) {
|
||||
String prefixClass = CodegenSceneEnum.valueOf(table.getScene()).getPrefixClass();
|
||||
bindingMap.put("saveReqVOClass", prefixClass + className + "SaveReqVO");
|
||||
bindingMap.put("updateReqVOClass", prefixClass + className + "SaveReqVO");
|
||||
bindingMap.put("respVOClass", prefixClass + className + "RespVO");
|
||||
bindingMap.put("saveReqVOVar", "createReqVO");
|
||||
bindingMap.put("updateReqVOVar", "updateReqVO");
|
||||
} else if (ObjectUtil.equal(codegenProperties.getVoType(), CodegenVOTypeEnum.DO.getType())) {
|
||||
bindingMap.put("saveReqVOClass", className + "DO");
|
||||
bindingMap.put("updateReqVOClass", className + "DO");
|
||||
bindingMap.put("respVOClass", className + "DO");
|
||||
bindingMap.put("saveReqVOVar", classNameVar);
|
||||
bindingMap.put("updateReqVOVar", classNameVar);
|
||||
}
|
||||
return bindingMap;
|
||||
}
|
||||
|
||||
|
@ -461,6 +482,11 @@ public class CodegenEngine {
|
|||
templates.remove(javaTemplatePath("test/serviceTest"));
|
||||
templates.remove("codegen/sql/h2.vm");
|
||||
}
|
||||
// 如果禁用 VO 类型,则移除对应的模版
|
||||
if (ObjectUtil.notEqual(codegenProperties.getVoType(), CodegenVOTypeEnum.VO.getType())) {
|
||||
templates.remove(javaTemplatePath("controller/vo/respVO"));
|
||||
templates.remove(javaTemplatePath("controller/vo/saveReqVO"));
|
||||
}
|
||||
return templates;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ public interface DatabaseTableService {
|
|||
* 获得表列表,基于表名称 + 表描述进行模糊匹配
|
||||
*
|
||||
* @param dataSourceConfigId 数据源配置的编号
|
||||
* @param nameLike 表名称,模糊匹配
|
||||
* @param commentLike 表描述,模糊匹配
|
||||
* @param nameLike 表名称,模糊匹配
|
||||
* @param commentLike 表描述,模糊匹配
|
||||
* @return 表列表
|
||||
*/
|
||||
List<TableInfo> getTableList(Long dataSourceConfigId, String nameLike, String commentLike);
|
||||
|
@ -25,7 +25,7 @@ public interface DatabaseTableService {
|
|||
* 获得指定表名
|
||||
*
|
||||
* @param dataSourceConfigId 数据源配置的编号
|
||||
* @param tableName 表名称
|
||||
* @param tableName 表名称
|
||||
* @return 表
|
||||
*/
|
||||
TableInfo getTable(Long dataSourceConfigId, String tableName);
|
||||
|
|
|
@ -4,8 +4,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 示例联系人 Service 接口
|
||||
|
@ -36,6 +37,13 @@ public interface Demo01ContactService {
|
|||
*/
|
||||
void deleteDemo01Contact(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除示例联系人
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteDemo0iContactListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得示例联系人
|
||||
*
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
package cn.iocoder.yudao.module.infra.service.demo.demo01;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo01.Demo01ContactMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DEMO01_CONTACT_NOT_EXISTS;
|
||||
|
@ -52,6 +54,21 @@ public class Demo01ContactServiceImpl implements Demo01ContactService {
|
|||
demo01ContactMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDemo0iContactListByIds(List<Long> ids) {
|
||||
// 校验存在
|
||||
validateDemo01ContactExists(ids);
|
||||
// 删除
|
||||
demo01ContactMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
private void validateDemo01ContactExists(List<Long> ids) {
|
||||
List<Demo01ContactDO> list = demo01ContactMapper.selectByIds(ids);
|
||||
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
||||
throw exception(DEMO01_CONTACT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateDemo01ContactExists(Long id) {
|
||||
if (demo01ContactMapper.selectById(id) == null) {
|
||||
throw exception(DEMO01_CONTACT_NOT_EXISTS);
|
||||
|
|
|
@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.infra.service.demo.demo02;
|
|||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02CategoryListReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02CategorySaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo02.Demo02CategoryDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,10 +5,10 @@ import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02Categ
|
|||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02CategorySaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo02.Demo02CategoryDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo02.Demo02CategoryMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package cn.iocoder.yudao.module.infra.service.demo.demo03;
|
||||
package cn.iocoder.yudao.module.infra.service.demo.demo03.erp;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -16,7 +16,7 @@ import java.util.List;
|
|||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface Demo03StudentService {
|
||||
public interface Demo03StudentErpService {
|
||||
|
||||
/**
|
||||
* 创建学生
|
||||
|
@ -24,14 +24,14 @@ public interface Demo03StudentService {
|
|||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createDemo03Student(@Valid Demo03StudentSaveReqVO createReqVO);
|
||||
Long createDemo03Student(@Valid Demo03StudentErpSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新学生
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateDemo03Student(@Valid Demo03StudentSaveReqVO updateReqVO);
|
||||
void updateDemo03Student(@Valid Demo03StudentErpSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除学生
|
||||
|
@ -40,6 +40,13 @@ public interface Demo03StudentService {
|
|||
*/
|
||||
void deleteDemo03Student(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除学生
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteDemo03StudentListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得学生
|
||||
*
|
||||
|
@ -54,19 +61,10 @@ public interface Demo03StudentService {
|
|||
* @param pageReqVO 分页查询
|
||||
* @return 学生分页
|
||||
*/
|
||||
PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentPageReqVO pageReqVO);
|
||||
|
||||
PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentErpPageReqVO pageReqVO);
|
||||
|
||||
// ==================== 子表(学生课程) ====================
|
||||
|
||||
/**
|
||||
* 获得学生课程列表
|
||||
*
|
||||
* @param studentId 学生编号
|
||||
* @return 学生课程列表
|
||||
*/
|
||||
List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId);
|
||||
|
||||
/**
|
||||
* 获得学生课程分页
|
||||
*
|
||||
|
@ -98,6 +96,13 @@ public interface Demo03StudentService {
|
|||
*/
|
||||
void deleteDemo03Course(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除学生课程
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteDemo03CourseListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得学生课程
|
||||
*
|
||||
|
@ -108,14 +113,6 @@ public interface Demo03StudentService {
|
|||
|
||||
// ==================== 子表(学生班级) ====================
|
||||
|
||||
/**
|
||||
* 获得学生班级
|
||||
*
|
||||
* @param studentId 学生编号
|
||||
* @return 学生班级
|
||||
*/
|
||||
Demo03GradeDO getDemo03GradeByStudentId(Long studentId);
|
||||
|
||||
/**
|
||||
* 获得学生班级分页
|
||||
*
|
||||
|
@ -147,6 +144,13 @@ public interface Demo03StudentService {
|
|||
*/
|
||||
void deleteDemo03Grade(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除学生班级
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteDemo03GradeListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得学生班级
|
||||
*
|
|
@ -1,21 +1,22 @@
|
|||
package cn.iocoder.yudao.module.infra.service.demo.demo03;
|
||||
package cn.iocoder.yudao.module.infra.service.demo.demo03.erp;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03CourseMapper;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03GradeMapper;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03StudentMapper;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03CourseErpMapper;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03GradeErpMapper;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03StudentErpMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
@ -28,41 +29,31 @@ import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*;
|
|||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class Demo03StudentServiceImpl implements Demo03StudentService {
|
||||
public class Demo03StudentErpServiceImpl implements Demo03StudentErpService {
|
||||
|
||||
@Resource
|
||||
private Demo03StudentMapper demo03StudentMapper;
|
||||
private Demo03StudentErpMapper demo03StudentErpMapper;
|
||||
@Resource
|
||||
private Demo03CourseMapper demo03CourseMapper;
|
||||
private Demo03CourseErpMapper demo03CourseErpMapper;
|
||||
@Resource
|
||||
private Demo03GradeMapper demo03GradeMapper;
|
||||
private Demo03GradeErpMapper demo03GradeErpMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createDemo03Student(Demo03StudentSaveReqVO createReqVO) {
|
||||
public Long createDemo03Student(Demo03StudentErpSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class);
|
||||
demo03StudentMapper.insert(demo03Student);
|
||||
|
||||
// 插入子表
|
||||
createDemo03CourseList(demo03Student.getId(), createReqVO.getDemo03Courses());
|
||||
createDemo03Grade(demo03Student.getId(), createReqVO.getDemo03Grade());
|
||||
demo03StudentErpMapper.insert(demo03Student);
|
||||
// 返回
|
||||
return demo03Student.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateDemo03Student(Demo03StudentSaveReqVO updateReqVO) {
|
||||
public void updateDemo03Student(Demo03StudentErpSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateDemo03StudentExists(updateReqVO.getId());
|
||||
// 更新
|
||||
Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class);
|
||||
demo03StudentMapper.updateById(updateObj);
|
||||
|
||||
// 更新子表
|
||||
updateDemo03CourseList(updateReqVO.getId(), updateReqVO.getDemo03Courses());
|
||||
updateDemo03Grade(updateReqVO.getId(), updateReqVO.getDemo03Grade());
|
||||
demo03StudentErpMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -71,119 +62,117 @@ public class Demo03StudentServiceImpl implements Demo03StudentService {
|
|||
// 校验存在
|
||||
validateDemo03StudentExists(id);
|
||||
// 删除
|
||||
demo03StudentMapper.deleteById(id);
|
||||
demo03StudentErpMapper.deleteById(id);
|
||||
|
||||
// 删除子表
|
||||
deleteDemo03CourseByStudentId(id);
|
||||
deleteDemo03GradeByStudentId(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteDemo03StudentListByIds(List<Long> ids) {
|
||||
// 校验存在
|
||||
validateDemo03StudentExists(ids);
|
||||
// 删除
|
||||
demo03StudentErpMapper.deleteByIds(ids);
|
||||
|
||||
// 删除子表
|
||||
deleteDemo03CourseByStudentIds(ids);
|
||||
deleteDemo03GradeByStudentIds(ids);
|
||||
}
|
||||
|
||||
private void validateDemo03StudentExists(List<Long> ids) {
|
||||
List<Demo03StudentDO> list = demo03StudentErpMapper.selectByIds(ids);
|
||||
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
||||
throw exception(DEMO03_STUDENT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateDemo03StudentExists(Long id) {
|
||||
if (demo03StudentMapper.selectById(id) == null) {
|
||||
if (demo03StudentErpMapper.selectById(id) == null) {
|
||||
throw exception(DEMO03_STUDENT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Demo03StudentDO getDemo03Student(Long id) {
|
||||
return demo03StudentMapper.selectById(id);
|
||||
return demo03StudentErpMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentPageReqVO pageReqVO) {
|
||||
return demo03StudentMapper.selectPage(pageReqVO);
|
||||
public PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentErpPageReqVO pageReqVO) {
|
||||
return demo03StudentErpMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
// ==================== 子表(学生课程) ====================
|
||||
|
||||
@Override
|
||||
public List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId) {
|
||||
return demo03CourseMapper.selectListByStudentId(studentId);
|
||||
}
|
||||
|
||||
private void createDemo03CourseList(Long studentId, List<Demo03CourseDO> list) {
|
||||
if (list != null) {
|
||||
list.forEach(o -> o.setStudentId(studentId));
|
||||
}
|
||||
demo03CourseMapper.insertBatch(list);
|
||||
}
|
||||
|
||||
private void updateDemo03CourseList(Long studentId, List<Demo03CourseDO> list) {
|
||||
deleteDemo03CourseByStudentId(studentId);
|
||||
list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下:1)id 冲突;2)updateTime 不更新
|
||||
createDemo03CourseList(studentId, list);
|
||||
}
|
||||
|
||||
private void deleteDemo03CourseByStudentId(Long studentId) {
|
||||
demo03CourseMapper.deleteByStudentId(studentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Demo03CourseDO> getDemo03CoursePage(PageParam pageReqVO, Long studentId) {
|
||||
return demo03CourseMapper.selectPage(pageReqVO, studentId);
|
||||
return demo03CourseErpMapper.selectPage(pageReqVO, studentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createDemo03Course(Demo03CourseDO demo03Course) {
|
||||
demo03CourseMapper.insert(demo03Course);
|
||||
demo03CourseErpMapper.insert(demo03Course);
|
||||
return demo03Course.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDemo03Course(Demo03CourseDO demo03Course) {
|
||||
demo03CourseMapper.updateById(demo03Course);
|
||||
// 校验存在
|
||||
validateDemo03CourseExists(demo03Course.getId());
|
||||
// 更新
|
||||
demo03Course.clean();
|
||||
demo03CourseErpMapper.updateById(demo03Course);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDemo03Course(Long id) {
|
||||
demo03CourseMapper.deleteById(id);
|
||||
// 删除
|
||||
demo03CourseErpMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDemo03CourseListByIds(List<Long> ids) {
|
||||
// 删除
|
||||
demo03CourseErpMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Demo03CourseDO getDemo03Course(Long id) {
|
||||
return demo03CourseMapper.selectById(id);
|
||||
return demo03CourseErpMapper.selectById(id);
|
||||
}
|
||||
|
||||
private void validateDemo03CourseExists(Long id) {
|
||||
if (demo03CourseErpMapper.selectById(id) == null) {
|
||||
throw exception(DEMO03_COURSE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteDemo03CourseByStudentId(Long studentId) {
|
||||
demo03CourseErpMapper.deleteByStudentId(studentId);
|
||||
}
|
||||
|
||||
private void deleteDemo03CourseByStudentIds(List<Long> studentIds) {
|
||||
demo03CourseErpMapper.deleteByStudentIds(studentIds);
|
||||
}
|
||||
|
||||
// ==================== 子表(学生班级) ====================
|
||||
|
||||
@Override
|
||||
public Demo03GradeDO getDemo03GradeByStudentId(Long studentId) {
|
||||
return demo03GradeMapper.selectByStudentId(studentId);
|
||||
}
|
||||
|
||||
private void createDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) {
|
||||
if (demo03Grade == null) {
|
||||
return;
|
||||
}
|
||||
demo03Grade.setStudentId(studentId);
|
||||
demo03GradeMapper.insert(demo03Grade);
|
||||
}
|
||||
|
||||
private void updateDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) {
|
||||
if (demo03Grade == null) {
|
||||
return;
|
||||
}
|
||||
demo03Grade.setStudentId(studentId);
|
||||
demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新
|
||||
demo03GradeMapper.insertOrUpdate(demo03Grade);
|
||||
}
|
||||
|
||||
private void deleteDemo03GradeByStudentId(Long studentId) {
|
||||
demo03GradeMapper.deleteByStudentId(studentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Demo03GradeDO> getDemo03GradePage(PageParam pageReqVO, Long studentId) {
|
||||
return demo03GradeMapper.selectPage(pageReqVO, studentId);
|
||||
return demo03GradeErpMapper.selectPage(pageReqVO, studentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createDemo03Grade(Demo03GradeDO demo03Grade) {
|
||||
// 校验是否已经存在
|
||||
if (demo03GradeMapper.selectByStudentId(demo03Grade.getStudentId()) != null) {
|
||||
if (demo03GradeErpMapper.selectByStudentId(demo03Grade.getStudentId()) != null) {
|
||||
throw exception(DEMO03_GRADE_EXISTS);
|
||||
}
|
||||
demo03GradeMapper.insert(demo03Grade);
|
||||
// 插入
|
||||
demo03GradeErpMapper.insert(demo03Grade);
|
||||
return demo03Grade.getId();
|
||||
}
|
||||
|
||||
|
@ -192,26 +181,39 @@ public class Demo03StudentServiceImpl implements Demo03StudentService {
|
|||
// 校验存在
|
||||
validateDemo03GradeExists(demo03Grade.getId());
|
||||
// 更新
|
||||
demo03GradeMapper.updateById(demo03Grade);
|
||||
demo03Grade.clean();
|
||||
demo03GradeErpMapper.updateById(demo03Grade);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDemo03Grade(Long id) {
|
||||
// 校验存在
|
||||
validateDemo03GradeExists(id);
|
||||
// 删除
|
||||
demo03GradeMapper.deleteById(id);
|
||||
demo03GradeErpMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDemo03GradeListByIds(List<Long> ids) {
|
||||
// 删除
|
||||
demo03GradeErpMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Demo03GradeDO getDemo03Grade(Long id) {
|
||||
return demo03GradeMapper.selectById(id);
|
||||
return demo03GradeErpMapper.selectById(id);
|
||||
}
|
||||
|
||||
private void validateDemo03GradeExists(Long id) {
|
||||
if (demo03GradeMapper.selectById(id) == null) {
|
||||
if (demo03GradeErpMapper.selectById(id) == null) {
|
||||
throw exception(DEMO03_GRADE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteDemo03GradeByStudentId(Long studentId) {
|
||||
demo03GradeErpMapper.deleteByStudentId(studentId);
|
||||
}
|
||||
|
||||
private void deleteDemo03GradeByStudentIds(List<Long> studentIds) {
|
||||
demo03GradeErpMapper.deleteByStudentIds(studentIds);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package cn.iocoder.yudao.module.infra.service.demo.demo03.inner;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 学生 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface Demo03StudentInnerService {
|
||||
|
||||
/**
|
||||
* 创建学生
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createDemo03Student(@Valid Demo03StudentInnerSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新学生
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateDemo03Student(@Valid Demo03StudentInnerSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除学生
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteDemo03Student(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除学生
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteDemo03StudentListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得学生
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 学生
|
||||
*/
|
||||
Demo03StudentDO getDemo03Student(Long id);
|
||||
|
||||
/**
|
||||
* 获得学生分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 学生分页
|
||||
*/
|
||||
PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentInnerPageReqVO pageReqVO);
|
||||
|
||||
// ==================== 子表(学生课程) ====================
|
||||
|
||||
/**
|
||||
* 获得学生课程列表
|
||||
*
|
||||
* @param studentId 学生编号
|
||||
* @return 学生课程列表
|
||||
*/
|
||||
List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId);
|
||||
|
||||
// ==================== 子表(学生班级) ====================
|
||||
|
||||
/**
|
||||
* 获得学生班级
|
||||
*
|
||||
* @param studentId 学生编号
|
||||
* @return 学生班级
|
||||
*/
|
||||
Demo03GradeDO getDemo03GradeByStudentId(Long studentId);
|
||||
|
||||
}
|
|
@ -0,0 +1,194 @@
|
|||
package cn.iocoder.yudao.module.infra.service.demo.demo03.inner;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner.Demo03CourseInnerMapper;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner.Demo03GradeInnerMapper;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner.Demo03StudentInnerMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
|
||||
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DEMO03_STUDENT_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 学生 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class Demo03StudentInnerServiceImpl implements Demo03StudentInnerService {
|
||||
|
||||
@Resource
|
||||
private Demo03StudentInnerMapper demo03StudentInnerMapper;
|
||||
@Resource
|
||||
private Demo03CourseInnerMapper demo03CourseInnerMapper;
|
||||
@Resource
|
||||
private Demo03GradeInnerMapper demo03GradeInnerMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createDemo03Student(Demo03StudentInnerSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class);
|
||||
demo03StudentInnerMapper.insert(demo03Student);
|
||||
|
||||
// 插入子表
|
||||
createDemo03CourseList(demo03Student.getId(), createReqVO.getDemo03Courses());
|
||||
createDemo03Grade(demo03Student.getId(), createReqVO.getDemo03Grade());
|
||||
// 返回
|
||||
return demo03Student.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateDemo03Student(Demo03StudentInnerSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateDemo03StudentExists(updateReqVO.getId());
|
||||
// 更新
|
||||
Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class);
|
||||
demo03StudentInnerMapper.updateById(updateObj);
|
||||
|
||||
// 更新子表
|
||||
updateDemo03CourseList(updateReqVO.getId(), updateReqVO.getDemo03Courses());
|
||||
updateDemo03Grade(updateReqVO.getId(), updateReqVO.getDemo03Grade());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteDemo03Student(Long id) {
|
||||
// 校验存在
|
||||
validateDemo03StudentExists(id);
|
||||
// 删除
|
||||
demo03StudentInnerMapper.deleteById(id);
|
||||
|
||||
// 删除子表
|
||||
deleteDemo03CourseByStudentId(id);
|
||||
deleteDemo03GradeByStudentId(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteDemo03StudentListByIds(List<Long> ids) {
|
||||
// 校验存在
|
||||
validateDemo03StudentExists(ids);
|
||||
// 删除
|
||||
demo03StudentInnerMapper.deleteByIds(ids);
|
||||
|
||||
// 删除子表
|
||||
deleteDemo03CourseByStudentIds(ids);
|
||||
deleteDemo03GradeByStudentIds(ids);
|
||||
}
|
||||
|
||||
private void validateDemo03StudentExists(List<Long> ids) {
|
||||
List<Demo03StudentDO> list = demo03StudentInnerMapper.selectByIds(ids);
|
||||
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
||||
throw exception(DEMO03_STUDENT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateDemo03StudentExists(Long id) {
|
||||
if (demo03StudentInnerMapper.selectById(id) == null) {
|
||||
throw exception(DEMO03_STUDENT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Demo03StudentDO getDemo03Student(Long id) {
|
||||
return demo03StudentInnerMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentInnerPageReqVO pageReqVO) {
|
||||
return demo03StudentInnerMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
// ==================== 子表(学生课程) ====================
|
||||
|
||||
@Override
|
||||
public List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId) {
|
||||
return demo03CourseInnerMapper.selectListByStudentId(studentId);
|
||||
}
|
||||
|
||||
private void createDemo03CourseList(Long studentId, List<Demo03CourseDO> list) {
|
||||
list.forEach(o -> o.setStudentId(studentId).clean());
|
||||
demo03CourseInnerMapper.insertBatch(list);
|
||||
}
|
||||
|
||||
private void updateDemo03CourseList(Long studentId, List<Demo03CourseDO> list) {
|
||||
list.forEach(o -> o.setStudentId(studentId).clean());
|
||||
List<Demo03CourseDO> oldList = demo03CourseInnerMapper.selectListByStudentId(studentId);
|
||||
List<List<Demo03CourseDO>> diffList = diffList(oldList, list, (oldVal, newVal) -> {
|
||||
boolean same = ObjectUtil.equal(oldVal.getId(), newVal.getId());
|
||||
if (same) {
|
||||
newVal.setId(oldVal.getId());
|
||||
}
|
||||
return same;
|
||||
});
|
||||
|
||||
// 第二步,批量添加、修改、删除
|
||||
if (CollUtil.isNotEmpty(diffList.get(0))) {
|
||||
demo03CourseInnerMapper.insertBatch(diffList.get(0));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(diffList.get(1))) {
|
||||
demo03CourseInnerMapper.updateBatch(diffList.get(1));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(diffList.get(2))) {
|
||||
demo03CourseInnerMapper.deleteByIds(convertList(diffList.get(2), Demo03CourseDO::getId));
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteDemo03CourseByStudentId(Long studentId) {
|
||||
demo03CourseInnerMapper.deleteByStudentId(studentId);
|
||||
}
|
||||
|
||||
private void deleteDemo03CourseByStudentIds(List<Long> studentIds) {
|
||||
demo03CourseInnerMapper.deleteByStudentIds(studentIds);
|
||||
}
|
||||
|
||||
// ==================== 子表(学生班级) ====================
|
||||
|
||||
@Override
|
||||
public Demo03GradeDO getDemo03GradeByStudentId(Long studentId) {
|
||||
return demo03GradeInnerMapper.selectByStudentId(studentId);
|
||||
}
|
||||
|
||||
private void createDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) {
|
||||
if (demo03Grade == null) {
|
||||
return;
|
||||
}
|
||||
demo03Grade.setStudentId(studentId);
|
||||
demo03GradeInnerMapper.insert(demo03Grade);
|
||||
}
|
||||
|
||||
private void updateDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) {
|
||||
if (demo03Grade == null) {
|
||||
return;
|
||||
}
|
||||
demo03Grade.setStudentId(studentId).clean();
|
||||
demo03GradeInnerMapper.insertOrUpdate(demo03Grade);
|
||||
}
|
||||
|
||||
private void deleteDemo03GradeByStudentId(Long studentId) {
|
||||
demo03GradeInnerMapper.deleteByStudentId(studentId);
|
||||
}
|
||||
|
||||
private void deleteDemo03GradeByStudentIds(List<Long> studentIds) {
|
||||
demo03GradeInnerMapper.deleteByStudentIds(studentIds);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package cn.iocoder.yudao.module.infra.service.demo.demo03.normal;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 学生 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface Demo03StudentNormalService {
|
||||
|
||||
/**
|
||||
* 创建学生
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createDemo03Student(@Valid Demo03StudentNormalSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新学生
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateDemo03Student(@Valid Demo03StudentNormalSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除学生
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteDemo03Student(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除学生
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteDemo03StudentListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得学生
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 学生
|
||||
*/
|
||||
Demo03StudentDO getDemo03Student(Long id);
|
||||
|
||||
/**
|
||||
* 获得学生分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 学生分页
|
||||
*/
|
||||
PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentNormalPageReqVO pageReqVO);
|
||||
|
||||
// ==================== 子表(学生课程) ====================
|
||||
|
||||
/**
|
||||
* 获得学生课程列表
|
||||
*
|
||||
* @param studentId 学生编号
|
||||
* @return 学生课程列表
|
||||
*/
|
||||
List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId);
|
||||
|
||||
// ==================== 子表(学生班级) ====================
|
||||
|
||||
/**
|
||||
* 获得学生班级
|
||||
*
|
||||
* @param studentId 学生编号
|
||||
* @return 学生班级
|
||||
*/
|
||||
Demo03GradeDO getDemo03GradeByStudentId(Long studentId);
|
||||
|
||||
}
|
|
@ -0,0 +1,194 @@
|
|||
package cn.iocoder.yudao.module.infra.service.demo.demo03.normal;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal.Demo03CourseNormalMapper;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal.Demo03GradeNormalMapper;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal.Demo03StudentNormalMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
|
||||
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DEMO03_STUDENT_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 学生 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class Demo03StudentNormalServiceImpl implements Demo03StudentNormalService {
|
||||
|
||||
@Resource
|
||||
private Demo03StudentNormalMapper demo03StudentNormalMapper;
|
||||
@Resource
|
||||
private Demo03CourseNormalMapper demo03CourseNormalMapper;
|
||||
@Resource
|
||||
private Demo03GradeNormalMapper demo03GradeNormalMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createDemo03Student(Demo03StudentNormalSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class);
|
||||
demo03StudentNormalMapper.insert(demo03Student);
|
||||
|
||||
// 插入子表
|
||||
createDemo03CourseList(demo03Student.getId(), createReqVO.getDemo03Courses());
|
||||
createDemo03Grade(demo03Student.getId(), createReqVO.getDemo03Grade());
|
||||
// 返回
|
||||
return demo03Student.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateDemo03Student(Demo03StudentNormalSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateDemo03StudentExists(updateReqVO.getId());
|
||||
// 更新
|
||||
Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class);
|
||||
demo03StudentNormalMapper.updateById(updateObj);
|
||||
|
||||
// 更新子表
|
||||
updateDemo03CourseList(updateReqVO.getId(), updateReqVO.getDemo03Courses());
|
||||
updateDemo03Grade(updateReqVO.getId(), updateReqVO.getDemo03Grade());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteDemo03Student(Long id) {
|
||||
// 校验存在
|
||||
validateDemo03StudentExists(id);
|
||||
// 删除
|
||||
demo03StudentNormalMapper.deleteById(id);
|
||||
|
||||
// 删除子表
|
||||
deleteDemo03CourseByStudentId(id);
|
||||
deleteDemo03GradeByStudentId(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteDemo03StudentListByIds(List<Long> ids) {
|
||||
// 校验存在
|
||||
validateDemo03StudentExists(ids);
|
||||
// 删除
|
||||
demo03StudentNormalMapper.deleteByIds(ids);
|
||||
|
||||
// 删除子表
|
||||
deleteDemo03CourseByStudentIds(ids);
|
||||
deleteDemo03GradeByStudentIds(ids);
|
||||
}
|
||||
|
||||
private void validateDemo03StudentExists(List<Long> ids) {
|
||||
List<Demo03StudentDO> list = demo03StudentNormalMapper.selectByIds(ids);
|
||||
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
||||
throw exception(DEMO03_STUDENT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateDemo03StudentExists(Long id) {
|
||||
if (demo03StudentNormalMapper.selectById(id) == null) {
|
||||
throw exception(DEMO03_STUDENT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Demo03StudentDO getDemo03Student(Long id) {
|
||||
return demo03StudentNormalMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentNormalPageReqVO pageReqVO) {
|
||||
return demo03StudentNormalMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
// ==================== 子表(学生课程) ====================
|
||||
|
||||
@Override
|
||||
public List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId) {
|
||||
return demo03CourseNormalMapper.selectListByStudentId(studentId);
|
||||
}
|
||||
|
||||
private void createDemo03CourseList(Long studentId, List<Demo03CourseDO> list) {
|
||||
list.forEach(o -> o.setStudentId(studentId).clean());
|
||||
demo03CourseNormalMapper.insertBatch(list);
|
||||
}
|
||||
|
||||
private void updateDemo03CourseList(Long studentId, List<Demo03CourseDO> list) {
|
||||
list.forEach(o -> o.setStudentId(studentId).clean());
|
||||
List<Demo03CourseDO> oldList = demo03CourseNormalMapper.selectListByStudentId(studentId);
|
||||
List<List<Demo03CourseDO>> diffList = diffList(oldList, list, (oldVal, newVal) -> {
|
||||
boolean same = ObjectUtil.equal(oldVal.getId(), newVal.getId());
|
||||
if (same) {
|
||||
newVal.setId(oldVal.getId());
|
||||
}
|
||||
return same;
|
||||
});
|
||||
|
||||
// 第二步,批量添加、修改、删除
|
||||
if (CollUtil.isNotEmpty(diffList.get(0))) {
|
||||
demo03CourseNormalMapper.insertBatch(diffList.get(0));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(diffList.get(1))) {
|
||||
demo03CourseNormalMapper.updateBatch(diffList.get(1));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(diffList.get(2))) {
|
||||
demo03CourseNormalMapper.deleteByIds(convertList(diffList.get(2), Demo03CourseDO::getId));
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteDemo03CourseByStudentId(Long studentId) {
|
||||
demo03CourseNormalMapper.deleteByStudentId(studentId);
|
||||
}
|
||||
|
||||
private void deleteDemo03CourseByStudentIds(List<Long> studentIds) {
|
||||
demo03CourseNormalMapper.deleteByStudentIds(studentIds);
|
||||
}
|
||||
|
||||
// ==================== 子表(学生班级) ====================
|
||||
|
||||
@Override
|
||||
public Demo03GradeDO getDemo03GradeByStudentId(Long studentId) {
|
||||
return demo03GradeNormalMapper.selectByStudentId(studentId);
|
||||
}
|
||||
|
||||
private void createDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) {
|
||||
if (demo03Grade == null) {
|
||||
return;
|
||||
}
|
||||
demo03Grade.setStudentId(studentId);
|
||||
demo03GradeNormalMapper.insert(demo03Grade);
|
||||
}
|
||||
|
||||
private void updateDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) {
|
||||
if (demo03Grade == null) {
|
||||
return;
|
||||
}
|
||||
demo03Grade.setStudentId(studentId).clean();
|
||||
demo03GradeNormalMapper.insertOrUpdate(demo03Grade);
|
||||
}
|
||||
|
||||
private void deleteDemo03GradeByStudentId(Long studentId) {
|
||||
demo03GradeNormalMapper.deleteByStudentId(studentId);
|
||||
}
|
||||
|
||||
private void deleteDemo03GradeByStudentIds(List<Long> studentIds) {
|
||||
demo03GradeNormalMapper.deleteByStudentIds(studentIds);
|
||||
}
|
||||
|
||||
}
|
|
@ -16,14 +16,14 @@ import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientFactor
|
|||
import cn.iocoder.yudao.module.infra.framework.file.core.enums.FileStorageEnum;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Validator;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Validator;
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
@ -137,7 +137,7 @@ public class FileConfigServiceImpl implements FileConfigService {
|
|||
/**
|
||||
* 清空指定文件配置
|
||||
*
|
||||
* @param id 配置编号
|
||||
* @param id 配置编号
|
||||
* @param master 是否主配置
|
||||
*/
|
||||
private void clearCache(Long id, Boolean master) {
|
||||
|
|
|
@ -26,10 +26,10 @@ public interface FileService {
|
|||
/**
|
||||
* 保存文件,并返回文件的访问路径
|
||||
*
|
||||
* @param content 文件内容
|
||||
* @param name 文件名称,允许空
|
||||
* @param content 文件内容
|
||||
* @param name 文件名称,允许空
|
||||
* @param directory 目录,允许空
|
||||
* @param type 文件的 MIME 类型,允许空
|
||||
* @param type 文件的 MIME 类型,允许空
|
||||
* @return 文件路径
|
||||
*/
|
||||
String createFile(@NotEmpty(message = "文件内容不能为空") byte[] content,
|
||||
|
@ -38,7 +38,7 @@ public interface FileService {
|
|||
/**
|
||||
* 生成文件预签名地址信息
|
||||
*
|
||||
* @param name 文件名
|
||||
* @param name 文件名
|
||||
* @param directory 目录
|
||||
* @return 预签名地址信息
|
||||
*/
|
||||
|
|
|
@ -30,7 +30,7 @@ public interface ApiAccessLogService {
|
|||
/**
|
||||
* 清理 exceedDay 天前的访问日志
|
||||
*
|
||||
* @param exceedDay 超过多少天就进行清理
|
||||
* @param exceedDay 超过多少天就进行清理
|
||||
* @param deleteLimit 清理的间隔条数
|
||||
*/
|
||||
Integer cleanAccessLog(Integer exceedDay, Integer deleteLimit);
|
||||
|
|
|
@ -30,7 +30,7 @@ public interface ApiErrorLogService {
|
|||
/**
|
||||
* 更新 API 错误日志已处理
|
||||
*
|
||||
* @param id API 日志编号
|
||||
* @param id API 日志编号
|
||||
* @param processStatus 处理结果
|
||||
* @param processUserId 处理人
|
||||
*/
|
||||
|
@ -39,7 +39,7 @@ public interface ApiErrorLogService {
|
|||
/**
|
||||
* 清理 exceedDay 天前的错误日志
|
||||
*
|
||||
* @param exceedDay 超过多少天就进行清理
|
||||
* @param exceedDay 超过多少天就进行清理
|
||||
* @param deleteLimit 清理的间隔条数
|
||||
*/
|
||||
Integer cleanErrorLog(Integer exceedDay, Integer deleteLimit);
|
||||
|
|
|
@ -161,6 +161,8 @@ yudao:
|
|||
base-package: cn.iocoder.yudao
|
||||
db-schemas: ${spring.datasource.dynamic.datasource.master.name}
|
||||
front-type: 20 # 前端模版的类型,参见 CodegenFrontTypeEnum 枚举类
|
||||
vo-type: 10 # VO 的类型,参见 CodegenVOTypeEnum 枚举类
|
||||
delete-batch-enable: true # 是否生成批量删除接口
|
||||
unit-test-enable: false # 是否生成单元测试
|
||||
tenant: # 多租户相关配置项
|
||||
enable: true
|
||||
|
|
|
@ -49,8 +49,8 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
|
|||
#if ($sceneEnum.scene == 1)
|
||||
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')")
|
||||
#end
|
||||
public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}SaveReqVO createReqVO) {
|
||||
return success(${classNameVar}Service.create${simpleClassName}(createReqVO));
|
||||
public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid @RequestBody ${saveReqVOClass} ${saveReqVOVar}) {
|
||||
return success(${classNameVar}Service.create${simpleClassName}(${saveReqVOVar}));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
|
@ -58,8 +58,8 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
|
|||
#if ($sceneEnum.scene == 1)
|
||||
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')")
|
||||
#end
|
||||
public CommonResult<Boolean> update${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO) {
|
||||
${classNameVar}Service.update${simpleClassName}(updateReqVO);
|
||||
public CommonResult<Boolean> update${simpleClassName}(@Valid @RequestBody ${updateReqVOClass} ${updateReqVOVar}) {
|
||||
${classNameVar}Service.update${simpleClassName}(${updateReqVOVar});
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -74,15 +74,32 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
|
|||
return success(true);
|
||||
}
|
||||
|
||||
#if ( $table.templateType != 2 && $deleteBatchEnable)
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除${table.classComment}")
|
||||
#if ($sceneEnum.scene == 1)
|
||||
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")
|
||||
#end
|
||||
public CommonResult<Boolean> delete${simpleClassName}List(@RequestParam("ids") List<${primaryColumn.javaType}> ids) {
|
||||
${classNameVar}Service.delete${simpleClassName}ListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
#end
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得${table.classComment}")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
#if ($sceneEnum.scene == 1)
|
||||
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||
#end
|
||||
public CommonResult<${sceneEnum.prefixClass}${table.className}RespVO> get${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) {
|
||||
public CommonResult<${respVOClass}> get${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) {
|
||||
${table.className}DO ${classNameVar} = ${classNameVar}Service.get${simpleClassName}(id);
|
||||
return success(BeanUtils.toBean(${classNameVar}, ${sceneEnum.prefixClass}${table.className}RespVO.class));
|
||||
#if ($voType == 10)
|
||||
return success(BeanUtils.toBean(${classNameVar}, ${respVOClass}.class));
|
||||
#else
|
||||
return success(${classNameVar});
|
||||
#end
|
||||
}
|
||||
|
||||
#if ( $table.templateType != 2 )
|
||||
|
@ -91,9 +108,13 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
|
|||
#if ($sceneEnum.scene == 1)
|
||||
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||
#end
|
||||
public CommonResult<PageResult<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}Page(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO) {
|
||||
public CommonResult<PageResult<${respVOClass}>> get${simpleClassName}Page(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO) {
|
||||
PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, ${sceneEnum.prefixClass}${table.className}RespVO.class));
|
||||
#if ($voType == 10)
|
||||
return success(BeanUtils.toBean(pageResult, ${respVOClass}.class));
|
||||
#else
|
||||
return success(pageResult);
|
||||
#end
|
||||
}
|
||||
|
||||
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||
|
@ -103,9 +124,13 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
|
|||
#if ($sceneEnum.scene == 1)
|
||||
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||
#end
|
||||
public CommonResult<List<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}List(@Valid ${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO) {
|
||||
public CommonResult<List<${respVOClass}>> get${simpleClassName}List(@Valid ${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO) {
|
||||
List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(listReqVO);
|
||||
return success(BeanUtils.toBean(list, ${sceneEnum.prefixClass}${table.className}RespVO.class));
|
||||
#if ($voType == 10)
|
||||
return success(BeanUtils.toBean(list, ${respVOClass}.class));
|
||||
#else
|
||||
return success(list);
|
||||
#end
|
||||
}
|
||||
|
||||
#end
|
||||
|
@ -121,8 +146,8 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
|
|||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}Page(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${sceneEnum.prefixClass}${table.className}RespVO.class,
|
||||
BeanUtils.toBean(list, ${sceneEnum.prefixClass}${table.className}RespVO.class));
|
||||
ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${respVOClass}.class,
|
||||
BeanUtils.toBean(list, ${respVOClass}.class));
|
||||
}
|
||||
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||
#else
|
||||
|
@ -218,6 +243,19 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
|
|||
return success(true);
|
||||
}
|
||||
|
||||
#if ($deleteBatchEnable)
|
||||
@DeleteMapping("/${subSimpleClassName_strikeCase}/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除${subTable.classComment}")
|
||||
#if ($sceneEnum.scene == 1)
|
||||
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")
|
||||
#end
|
||||
public CommonResult<Boolean> delete${subSimpleClassName}List(@RequestParam("ids") List<${subPrimaryColumn.javaType}> ids) {
|
||||
${classNameVar}Service.delete${subSimpleClassName}ListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
#end
|
||||
|
||||
@GetMapping("/${subSimpleClassName_strikeCase}/get")
|
||||
@Operation(summary = "获得${subTable.classComment}")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
|
|
|
@ -28,8 +28,6 @@ import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
|||
|
||||
@Schema(description = "${sceneEnum.name} - ${table.classComment}分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ${sceneEnum.prefixClass}${table.className}PageReqVO extends PageParam {
|
||||
|
||||
#foreach ($column in $columns)
|
||||
|
|
|
@ -12,6 +12,18 @@ import java.time.LocalDateTime;
|
|||
#end
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import ${BaseDOClassName};
|
||||
## 处理 Excel 导出 + Schema 注解(仅 DO 模式)
|
||||
#if ($voType == 20)
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
#foreach ($column in $columns)
|
||||
#if ("$!column.dictType" != "")## 有设置数据字典
|
||||
import ${DictFormatClassName};
|
||||
import ${DictConvertClassName};
|
||||
#break
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
|
||||
/**
|
||||
* ${table.classComment} DO
|
||||
|
@ -26,6 +38,11 @@ import ${BaseDOClassName};
|
|||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
## 处理 Excel 导出 + Schema 注解(仅 DO 模式)
|
||||
#if ($voType == 20)
|
||||
@Schema(description = "${sceneEnum.name} - ${table.classComment} Response VO")
|
||||
@ExcelIgnoreUnannotated
|
||||
#end
|
||||
public class ${table.className}DO extends BaseDO {
|
||||
|
||||
## 特殊:树表专属逻辑
|
||||
|
@ -45,8 +62,42 @@ public class ${table.className}DO extends BaseDO {
|
|||
#if (${column.primaryKey})##处理主键
|
||||
@TableId#if (${column.javaType} == 'String')(type = IdType.INPUT)#end
|
||||
#end
|
||||
#if ($voType == 20)
|
||||
## 1. 处理 Swagger 注解
|
||||
@Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end)
|
||||
## 2. 处理 Excel 导出
|
||||
#if ("$!column.dictType" != "")##处理枚举值
|
||||
@ExcelProperty(value = "${column.columnComment}", converter = DictConvert.class)
|
||||
@DictFormat("${column.dictType}") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
#else
|
||||
@ExcelProperty("${column.columnComment}")
|
||||
#end
|
||||
#end
|
||||
## 3. 处理字段定义
|
||||
private ${column.javaType} ${column.javaField};
|
||||
#end
|
||||
#end
|
||||
|
||||
## 特殊:主子表专属逻辑(非 ERP 模式)
|
||||
#if ( $voType == 20 && $subTables && $subTables.size() > 0 && $table.templateType != 11 )
|
||||
#foreach ($subTable in $subTables)
|
||||
#set ($index = $foreach.count - 1)
|
||||
#if ( $subTable.subJoinMany)
|
||||
/**
|
||||
* ${subTable.classComment}列表
|
||||
*/
|
||||
@Schema(description = "${subTable.classComment}列表")
|
||||
@TableField(exist = false)
|
||||
private List<${subTable.className}DO> ${subClassNameVars.get($index)}s;
|
||||
#else
|
||||
/**
|
||||
* ${subTable.classComment}
|
||||
*/
|
||||
@Schema(description = "${subTable.classComment}")
|
||||
@TableField(exist = false)
|
||||
private ${subTable.className}DO ${subClassNameVars.get($index)};
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
|
||||
}
|
|
@ -14,6 +14,17 @@ import java.time.LocalDateTime;
|
|||
#end
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import ${BaseDOClassName};
|
||||
## 处理 Schema 注解(仅 DO 模式)
|
||||
#if ($voType == 20)
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
#foreach ($column in $columns)
|
||||
#if ("$!column.dictType" != "")## 有设置数据字典
|
||||
import ${DictFormatClassName};
|
||||
import ${DictConvertClassName};
|
||||
#break
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
|
||||
/**
|
||||
* ${subTable.classComment} DO
|
||||
|
@ -28,6 +39,10 @@ import ${BaseDOClassName};
|
|||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
## 处理 Schema 注解(仅 DO 模式)
|
||||
#if ($voType == 20)
|
||||
@Schema(description = "${sceneEnum.name} - ${table.classComment} Response VO")
|
||||
#end
|
||||
public class ${subTable.className}DO extends BaseDO {
|
||||
|
||||
#foreach ($column in $subColumns)
|
||||
|
@ -42,6 +57,11 @@ public class ${subTable.className}DO extends BaseDO {
|
|||
#if (${column.primaryKey})##处理主键
|
||||
@TableId#if (${column.javaType} == 'String')(type = IdType.INPUT)#end
|
||||
#end
|
||||
#if ($voType == 20)
|
||||
## 1. 处理 Swagger 注解
|
||||
@Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end)
|
||||
#end
|
||||
## 2. 处理字段定义
|
||||
private ${column.javaType} ${column.javaField};
|
||||
#end
|
||||
#end
|
||||
|
|
|
@ -54,4 +54,10 @@ public interface ${subTable.className}Mapper extends BaseMapperX<${subTable.clas
|
|||
return delete(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField});
|
||||
}
|
||||
|
||||
#if ( $table.templateType != 2 && $deleteBatchEnable)
|
||||
default int deleteBy${SubJoinColumnName}s(List<${subJoinColumn.javaType}> ${subJoinColumn.javaField}s) {
|
||||
return deleteBatch(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}s);
|
||||
}
|
||||
#end
|
||||
|
||||
}
|
||||
|
|
|
@ -21,17 +21,17 @@ public interface ${table.className}Service {
|
|||
/**
|
||||
* 创建${table.classComment}
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @param ${saveReqVOVar} 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
${primaryColumn.javaType} create${simpleClassName}(@Valid ${sceneEnum.prefixClass}${table.className}SaveReqVO createReqVO);
|
||||
${primaryColumn.javaType} create${simpleClassName}(@Valid ${saveReqVOClass} ${saveReqVOVar});
|
||||
|
||||
/**
|
||||
* 更新${table.classComment}
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
* @param ${updateReqVOVar} 更新信息
|
||||
*/
|
||||
void update${simpleClassName}(@Valid ${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO);
|
||||
void update${simpleClassName}(@Valid ${updateReqVOClass} ${updateReqVOVar});
|
||||
|
||||
/**
|
||||
* 删除${table.classComment}
|
||||
|
@ -40,6 +40,15 @@ public interface ${table.className}Service {
|
|||
*/
|
||||
void delete${simpleClassName}(${primaryColumn.javaType} id);
|
||||
|
||||
#if ( $table.templateType != 2 && $deleteBatchEnable)
|
||||
/**
|
||||
* 批量删除${table.classComment}
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void delete${simpleClassName}ListByIds(List<${primaryColumn.javaType}> ids);
|
||||
#end
|
||||
|
||||
/**
|
||||
* 获得${table.classComment}
|
||||
*
|
||||
|
@ -134,6 +143,15 @@ public interface ${table.className}Service {
|
|||
*/
|
||||
void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id);
|
||||
|
||||
#if ($deleteBatchEnable)
|
||||
/**
|
||||
* 批量删除${subTable.classComment}
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void delete${subSimpleClassName}ListByIds(List<${subPrimaryColumn.javaType}> ids);
|
||||
#end
|
||||
|
||||
/**
|
||||
* 获得${subTable.classComment}
|
||||
*
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package ${basePackage}.module.${table.moduleName}.service.${table.businessName};
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ${jakartaPackage}.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
@ -24,6 +25,8 @@ import ${basePackage}.module.${subTable.moduleName}.dal.mysql.${subTable.busines
|
|||
#end
|
||||
|
||||
import static ${ServiceExceptionUtilClassName}.exception;
|
||||
import static ${CollectionUtilsClassName}.convertList;
|
||||
import static ${CollectionUtilsClassName}.diffList;
|
||||
import static ${basePackage}.module.${table.moduleName}.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
|
@ -49,19 +52,22 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
|||
#if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 )
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
#end
|
||||
public ${primaryColumn.javaType} create${simpleClassName}(${sceneEnum.prefixClass}${table.className}SaveReqVO createReqVO) {
|
||||
public ${primaryColumn.javaType} create${simpleClassName}(${saveReqVOClass} ${saveReqVOVar}) {
|
||||
## 特殊:树表专属逻辑
|
||||
#if ( $table.templateType == 2 )
|
||||
#set ($TreeParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写
|
||||
#set ($TreeNameJavaField = $treeNameColumn.javaField.substring(0,1).toUpperCase() + ${treeNameColumn.javaField.substring(1)})##首字母大写
|
||||
// 校验${treeParentColumn.columnComment}的有效性
|
||||
validateParent${simpleClassName}(null, createReqVO.get${TreeParentJavaField}());
|
||||
validateParent${simpleClassName}(null, ${saveReqVOVar}.get${TreeParentJavaField}());
|
||||
// 校验${treeNameColumn.columnComment}的唯一性
|
||||
validate${simpleClassName}${TreeNameJavaField}Unique(null, createReqVO.get${TreeParentJavaField}(), createReqVO.get${TreeNameJavaField}());
|
||||
validate${simpleClassName}${TreeNameJavaField}Unique(null, ${saveReqVOVar}.get${TreeParentJavaField}(), ${saveReqVOVar}.get${TreeNameJavaField}());
|
||||
|
||||
#end
|
||||
// 插入
|
||||
#if ($voType == 10)
|
||||
## TODO @puhui999:insert 也要加下 clean。万一前端乱传递,哈哈哈。这个就是 do 模式的缺点;(只在 do 模式下);看看主子表,是不是也可能存在,insert 的时候;
|
||||
${table.className}DO ${classNameVar} = BeanUtils.toBean(createReqVO, ${table.className}DO.class);
|
||||
#end
|
||||
${classNameVar}Mapper.insert(${classNameVar});
|
||||
## 特殊:主子表专属逻辑(非 ERP 模式)
|
||||
#if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 )
|
||||
|
@ -73,9 +79,9 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
|||
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||
#if ( $subTable.subJoinMany)
|
||||
create${subSimpleClassName}List(${classNameVar}.getId(), createReqVO.get${subSimpleClassNames.get($index)}s());
|
||||
create${subSimpleClassName}List(${classNameVar}.getId(), ${saveReqVOVar}.get${subSimpleClassNames.get($index)}s());
|
||||
#else
|
||||
create${subSimpleClassName}(${classNameVar}.getId(), createReqVO.get${subSimpleClassNames.get($index)}());
|
||||
create${subSimpleClassName}(${classNameVar}.getId(), ${saveReqVOVar}.get${subSimpleClassNames.get($index)}());
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
|
@ -88,22 +94,26 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
|||
#if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 )
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
#end
|
||||
public void update${simpleClassName}(${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO) {
|
||||
public void update${simpleClassName}(${updateReqVOClass} ${updateReqVOVar}) {
|
||||
// 校验存在
|
||||
validate${simpleClassName}Exists(updateReqVO.getId());
|
||||
validate${simpleClassName}Exists(${updateReqVOVar}.getId());
|
||||
## 特殊:树表专属逻辑
|
||||
#if ( $table.templateType == 2 )
|
||||
#set ($TreeParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写
|
||||
#set ($TreeNameJavaField = $treeNameColumn.javaField.substring(0,1).toUpperCase() + ${treeNameColumn.javaField.substring(1)})##首字母大写
|
||||
// 校验${treeParentColumn.columnComment}的有效性
|
||||
validateParent${simpleClassName}(updateReqVO.getId(), updateReqVO.get${TreeParentJavaField}());
|
||||
validateParent${simpleClassName}(${updateReqVOVar}.getId(), ${updateReqVOVar}.get${TreeParentJavaField}());
|
||||
// 校验${treeNameColumn.columnComment}的唯一性
|
||||
validate${simpleClassName}${TreeNameJavaField}Unique(updateReqVO.getId(), updateReqVO.get${TreeParentJavaField}(), updateReqVO.get${TreeNameJavaField}());
|
||||
validate${simpleClassName}${TreeNameJavaField}Unique(${updateReqVOVar}.getId(), ${updateReqVOVar}.get${TreeParentJavaField}(), ${updateReqVOVar}.get${TreeNameJavaField}());
|
||||
|
||||
#end
|
||||
// 更新
|
||||
#if ($voType == 10)
|
||||
${table.className}DO updateObj = BeanUtils.toBean(updateReqVO, ${table.className}DO.class);
|
||||
${classNameVar}Mapper.updateById(updateObj);
|
||||
#else
|
||||
${classNameVar}Mapper.updateById(${updateReqVOVar});
|
||||
#end
|
||||
## 特殊:主子表专属逻辑(非 ERP 模式)
|
||||
#if ( $subTables && $subTables.size() > 0 && $table.templateType != 11)
|
||||
|
||||
|
@ -114,9 +124,9 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
|||
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||
#if ( $subTable.subJoinMany)
|
||||
update${subSimpleClassName}List(updateReqVO.getId(), updateReqVO.get${subSimpleClassNames.get($index)}s());
|
||||
update${subSimpleClassName}List(${updateReqVOVar}.getId(), ${updateReqVOVar}.get${subSimpleClassNames.get($index)}s());
|
||||
#else
|
||||
update${subSimpleClassName}(updateReqVO.getId(), updateReqVO.get${subSimpleClassNames.get($index)}());
|
||||
update${subSimpleClassName}(${updateReqVOVar}.getId(), ${updateReqVOVar}.get${subSimpleClassNames.get($index)}());
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
|
@ -154,6 +164,39 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
|||
#end
|
||||
}
|
||||
|
||||
#if ( $table.templateType != 2 && $deleteBatchEnable)
|
||||
@Override
|
||||
## 特殊:主子表专属逻辑
|
||||
#if ( $subTables && $subTables.size() > 0)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
#end
|
||||
public void delete${simpleClassName}ListByIds(List<${primaryColumn.javaType}> ids) {
|
||||
// 校验存在
|
||||
validate${simpleClassName}Exists(ids);
|
||||
// 删除
|
||||
${classNameVar}Mapper.deleteByIds(ids);
|
||||
## 特殊:主子表专属逻辑
|
||||
#if ( $subTables && $subTables.size() > 0)
|
||||
|
||||
// 删除子表
|
||||
#foreach ($subTable in $subTables)
|
||||
#set ($index = $foreach.count - 1)
|
||||
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||
delete${subSimpleClassName}By${SubJoinColumnName}s(ids);
|
||||
#end
|
||||
#end
|
||||
}
|
||||
|
||||
private void validate${simpleClassName}Exists(List<${primaryColumn.javaType}> ids) {
|
||||
List<${table.className}DO> list = ${classNameVar}Mapper.selectByIds(ids);
|
||||
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
||||
throw exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
#end
|
||||
|
||||
private void validate${simpleClassName}Exists(${primaryColumn.javaType} id) {
|
||||
if (${classNameVar}Mapper.selectById(id) == null) {
|
||||
throw exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
|
||||
|
@ -286,18 +329,24 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
|||
// 校验存在
|
||||
validate${subSimpleClassName}Exists(${subClassNameVar}.getId());
|
||||
// 更新
|
||||
${subClassNameVar}.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新
|
||||
${subClassNameVar}.clean(); // 解决更新情况下:updateTime 不更新
|
||||
${subClassNameVars.get($index)}Mapper.updateById(${subClassNameVar});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id) {
|
||||
// 校验存在
|
||||
validate${subSimpleClassName}Exists(id);
|
||||
// 删除
|
||||
${subClassNameVars.get($index)}Mapper.deleteById(id);
|
||||
}
|
||||
|
||||
#if ($deleteBatchEnable)
|
||||
@Override
|
||||
public void delete${subSimpleClassName}ListByIds(List<${subPrimaryColumn.javaType}> ids) {
|
||||
// 删除
|
||||
${subClassNameVars.get($index)}Mapper.deleteByIds(ids);
|
||||
}
|
||||
#end
|
||||
|
||||
@Override
|
||||
public ${subTable.className}DO get${subSimpleClassName}(${subPrimaryColumn.javaType} id) {
|
||||
return ${subClassNameVars.get($index)}Mapper.selectById(id);
|
||||
|
@ -313,14 +362,31 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
|||
#else
|
||||
#if ( $subTable.subJoinMany)
|
||||
private void create${subSimpleClassName}List(${primaryColumn.javaType} ${subJoinColumn.javaField}, List<${subTable.className}DO> list) {
|
||||
list.forEach(o -> o.set$SubJoinColumnName(${subJoinColumn.javaField}));
|
||||
list.forEach(o -> o.set${SubJoinColumnName}(${subJoinColumn.javaField}).clean());
|
||||
${subClassNameVars.get($index)}Mapper.insertBatch(list);
|
||||
}
|
||||
|
||||
private void update${subSimpleClassName}List(${primaryColumn.javaType} ${subJoinColumn.javaField}, List<${subTable.className}DO> list) {
|
||||
delete${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField});
|
||||
list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下:1)id 冲突;2)updateTime 不更新
|
||||
create${subSimpleClassName}List(${subJoinColumn.javaField}, list);
|
||||
list.forEach(o -> o.set${SubJoinColumnName}(${subJoinColumn.javaField}).clean());
|
||||
List<${subTable.className}DO> oldList = ${subClassNameVar}Mapper.selectListBy${SubJoinColumnName}(${subJoinColumn.javaField});
|
||||
List<List<${subTable.className}DO>> diffList = diffList(oldList, list, (oldVal, newVal) -> {
|
||||
boolean same = ObjectUtil.equal(oldVal.getId(), newVal.getId());
|
||||
if (same) {
|
||||
newVal.setId(oldVal.getId()).clean(); // 解决更新情况下:updateTime 不更新
|
||||
}
|
||||
return same;
|
||||
});
|
||||
|
||||
// 第二步,批量添加、修改、删除
|
||||
if (CollUtil.isNotEmpty(diffList.get(0))) {
|
||||
${subClassNameVar}Mapper.insertBatch(diffList.get(0));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(diffList.get(1))) {
|
||||
${subClassNameVar}Mapper.updateBatch(diffList.get(1));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(diffList.get(2))) {
|
||||
${subClassNameVar}Mapper.deleteByIds(convertList(diffList.get(2), ${subTable.className}DO::getId));
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -336,8 +402,7 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
|||
if (${subClassNameVar} == null) {
|
||||
return;
|
||||
}
|
||||
${subClassNameVar}.set$SubJoinColumnName(${subJoinColumn.javaField});
|
||||
${subClassNameVar}.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新
|
||||
${subClassNameVar}.set$SubJoinColumnName(${subJoinColumn.javaField}).clean();// 解决更新情况下:updateTime 不更新
|
||||
${subClassNameVars.get($index)}Mapper.insertOrUpdate(${subClassNameVar});
|
||||
}
|
||||
|
||||
|
@ -347,5 +412,11 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
|||
${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}(${subJoinColumn.javaField});
|
||||
}
|
||||
|
||||
#if ( $table.templateType != 2 && $deleteBatchEnable)
|
||||
private void delete${subSimpleClassName}By${SubJoinColumnName}s(List<${primaryColumn.javaType}> ${subJoinColumn.javaField}s) {
|
||||
${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}s(${subJoinColumn.javaField}s);
|
||||
}
|
||||
#end
|
||||
|
||||
#end
|
||||
}
|
|
@ -5,14 +5,30 @@ import { requestClient } from '#/api/request';
|
|||
#set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}")
|
||||
|
||||
export namespace ${simpleClassName}Api {
|
||||
## 特殊:主子表专属逻辑
|
||||
#foreach ($subTable in $subTables)
|
||||
#set ($index = $foreach.count - 1)
|
||||
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||
#set ($subColumns = $subColumnsList.get($index))##当前字段数组
|
||||
/** ${subTable.classComment}信息 */
|
||||
export interface ${subSimpleClassName} {
|
||||
#foreach ($column in $subColumns)
|
||||
## 特殊:主子表专属逻辑
|
||||
#foreach ($subTable in $subTables)
|
||||
#set ($index = $foreach.count - 1)
|
||||
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||
#set ($subColumns = $subColumnsList.get($index))##当前字段数组
|
||||
/** ${subTable.classComment}信息 */
|
||||
export interface ${subSimpleClassName} {
|
||||
#foreach ($column in $subColumns)
|
||||
#if ($column.createOperation || $column.updateOperation)
|
||||
#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "short" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal")
|
||||
${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: number; // ${column.columnComment}
|
||||
#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdate" || ${column.javaType.toLowerCase()} == "localdatetime")
|
||||
${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: string | Dayjs; // ${column.columnComment}
|
||||
#else
|
||||
${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: ${column.javaType.toLowerCase()}; // ${column.columnComment}
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
}
|
||||
|
||||
#end
|
||||
/** ${table.classComment}信息 */
|
||||
export interface ${simpleClassName} {
|
||||
#foreach ($column in $columns)
|
||||
#if ($column.createOperation || $column.updateOperation)
|
||||
#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "short" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal")
|
||||
${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: number; // ${column.columnComment}
|
||||
|
@ -23,37 +39,21 @@ export namespace ${simpleClassName}Api {
|
|||
#end
|
||||
#end
|
||||
#end
|
||||
}
|
||||
|
||||
#end
|
||||
/** ${table.classComment}信息 */
|
||||
export interface ${simpleClassName} {
|
||||
#foreach ($column in $columns)
|
||||
#if ($column.createOperation || $column.updateOperation)
|
||||
#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "short" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal")
|
||||
${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: number; // ${column.columnComment}
|
||||
#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdate" || ${column.javaType.toLowerCase()} == "localdatetime")
|
||||
${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: string | Dayjs; // ${column.columnComment}
|
||||
#else
|
||||
${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: ${column.javaType.toLowerCase()}; // ${column.columnComment}
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#if ( $table.templateType == 2 )
|
||||
children?: ${simpleClassName}[];
|
||||
#end
|
||||
## 特殊:主子表专属逻辑
|
||||
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||
#foreach ($subTable in $subTables)
|
||||
#set ($index = $foreach.count - 1)
|
||||
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||
#if ( $subTable.subJoinMany )
|
||||
${subSimpleClassName.toLowerCase()}s?: ${subSimpleClassName}[]
|
||||
#else
|
||||
${subSimpleClassName.toLowerCase()}?: ${subSimpleClassName}
|
||||
#if ( $table.templateType == 2 )
|
||||
children?: ${simpleClassName}[];
|
||||
#end
|
||||
## 特殊:主子表专属逻辑
|
||||
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||
#foreach ($subTable in $subTables)
|
||||
#set ($index = $foreach.count - 1)
|
||||
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||
#if ( $subTable.subJoinMany )
|
||||
${subSimpleClassName.toLowerCase()}s?: ${subSimpleClassName}[]
|
||||
#else
|
||||
${subSimpleClassName.toLowerCase()}?: ${subSimpleClassName}
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,65 +89,80 @@ export function delete${simpleClassName}(id: number) {
|
|||
return requestClient.delete(`${baseURL}/delete?id=${id}`);
|
||||
}
|
||||
|
||||
#if ( $table.templateType != 2 && $deleteBatchEnable)
|
||||
/** 批量删除${table.classComment} */
|
||||
export function delete${simpleClassName}ListByIds(ids: number[]) {
|
||||
return requestClient.delete(`${baseURL}/delete-list?ids=${ids.join(',')}`)
|
||||
}
|
||||
#end
|
||||
|
||||
/** 导出${table.classComment} */
|
||||
export function export${simpleClassName}(params: any) {
|
||||
return requestClient.download('${baseURL}/export-excel', params);
|
||||
}
|
||||
|
||||
## 特殊:主子表专属逻辑
|
||||
## TODO @puhui999:下面这块缩进调整了,会乱掉么?
|
||||
#foreach ($subTable in $subTables)
|
||||
#set ($index = $foreach.count - 1)
|
||||
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||
#set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段
|
||||
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||
#set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($index))
|
||||
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||
#set ($index = $foreach.count - 1)
|
||||
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||
#set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段
|
||||
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||
#set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($index))
|
||||
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||
|
||||
// ==================== 子表($subTable.classComment) ====================
|
||||
|
||||
## 情况一:MASTER_ERP 时,需要分查询页子表
|
||||
#if ( $table.templateType == 11 )
|
||||
/** 获得${subTable.classComment}分页 */
|
||||
export function get${subSimpleClassName}Page(params: PageParam) {
|
||||
return requestClient.get<PageResult<${simpleClassName}Api.${subSimpleClassName}>>(`${baseURL}/${subSimpleClassName_strikeCase}/page`, { params });
|
||||
}
|
||||
## 情况二:非 MASTER_ERP 时,需要列表查询子表
|
||||
#else
|
||||
#if ( $subTable.subJoinMany )
|
||||
/** 获得${subTable.classComment}列表 */
|
||||
export function get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaField}: number) {
|
||||
return requestClient.get<${simpleClassName}Api.${subSimpleClassName}[]>(`${baseURL}/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=${${subJoinColumn.javaField}}`);
|
||||
}
|
||||
## 情况一:MASTER_ERP 时,需要分查询页子表
|
||||
#if ( $table.templateType == 11 )
|
||||
/** 获得${subTable.classComment}分页 */
|
||||
export function get${subSimpleClassName}Page(params: PageParam) {
|
||||
return requestClient.get<PageResult<${simpleClassName}Api.${subSimpleClassName}>>(`${baseURL}/${subSimpleClassName_strikeCase}/page`, { params });
|
||||
}
|
||||
## 情况二:非 MASTER_ERP 时,需要列表查询子表
|
||||
#else
|
||||
/** 获得${subTable.classComment} */
|
||||
export function get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField}: number) {
|
||||
return requestClient.get<${simpleClassName}Api.${subSimpleClassName}>(`${baseURL}/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=${${subJoinColumn.javaField}}`);
|
||||
}
|
||||
#if ( $subTable.subJoinMany )
|
||||
/** 获得${subTable.classComment}列表 */
|
||||
export function get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaField}: number) {
|
||||
return requestClient.get<${simpleClassName}Api.${subSimpleClassName}[]>(`${baseURL}/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=${${subJoinColumn.javaField}}`);
|
||||
}
|
||||
#else
|
||||
/** 获得${subTable.classComment} */
|
||||
export function get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField}: number) {
|
||||
return requestClient.get<${simpleClassName}Api.${subSimpleClassName}>(`${baseURL}/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=${${subJoinColumn.javaField}}`);
|
||||
}
|
||||
#end
|
||||
#end
|
||||
## 特殊:MASTER_ERP 时,支持单个的新增、修改、删除操作
|
||||
#if ( $table.templateType == 11 )
|
||||
/** 新增${subTable.classComment} */
|
||||
export function create${subSimpleClassName}(data: ${simpleClassName}Api.${subSimpleClassName}) {
|
||||
return requestClient.post(`${baseURL}/${subSimpleClassName_strikeCase}/create`, data);
|
||||
}
|
||||
|
||||
/** 修改${subTable.classComment} */
|
||||
export function update${subSimpleClassName}(data: ${simpleClassName}Api.${subSimpleClassName}) {
|
||||
return requestClient.put(`${baseURL}/${subSimpleClassName_strikeCase}/update`, data);
|
||||
}
|
||||
|
||||
/** 删除${subTable.classComment} */
|
||||
export function delete${subSimpleClassName}(id: number) {
|
||||
return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete?id=${id}`);
|
||||
}
|
||||
|
||||
#if ($deleteBatchEnable)
|
||||
/** 批量删除${subTable.classComment} */
|
||||
export function delete${subSimpleClassName}ListByIds(ids: number[]) {
|
||||
return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete-list?ids=${ids.join(',')}`)
|
||||
}
|
||||
#end
|
||||
|
||||
/** 获得${subTable.classComment} */
|
||||
export function get${subSimpleClassName}(id: number) {
|
||||
return requestClient.get<${simpleClassName}Api.${subSimpleClassName}>(`${baseURL}/${subSimpleClassName_strikeCase}/get?id=${id}`);
|
||||
}
|
||||
#end
|
||||
#end
|
||||
## 特殊:MASTER_ERP 时,支持单个的新增、修改、删除操作
|
||||
#if ( $table.templateType == 11 )
|
||||
/** 新增${subTable.classComment} */
|
||||
export function create${subSimpleClassName}(data: ${simpleClassName}Api.${subSimpleClassName}) {
|
||||
return requestClient.post(`${baseURL}/${subSimpleClassName_strikeCase}/create`, data);
|
||||
}
|
||||
|
||||
/** 修改${subTable.classComment} */
|
||||
export function update${subSimpleClassName}(data: ${simpleClassName}Api.${subSimpleClassName}) {
|
||||
return requestClient.put(`${baseURL}/${subSimpleClassName_strikeCase}/update`, data);
|
||||
}
|
||||
|
||||
/** 删除${subTable.classComment} */
|
||||
export function delete${subSimpleClassName}(id: number) {
|
||||
return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete?id=${id}`);
|
||||
}
|
||||
|
||||
/** 获得${subTable.classComment} */
|
||||
export function get${subSimpleClassName}(id: number) {
|
||||
return requestClient.get<${simpleClassName}Api.${subSimpleClassName}>(`${baseURL}/${subSimpleClassName_strikeCase}/get?id=${id}`);
|
||||
}
|
||||
#end
|
||||
#end
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import { Button, message,Tabs,Pagination,Form,RangePicker,DatePicker,Select,Inpu
|
|||
import { DictTag } from '#/components/dict-tag';
|
||||
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
|
||||
import ${simpleClassName}Form from './modules/form.vue';
|
||||
import { Download, Plus, RefreshCw, Search } from '@vben/icons';
|
||||
import { Download, Plus, RefreshCw, Search, Trash2 } from '@vben/icons';
|
||||
import { ContentWrap } from '#/components/content-wrap';
|
||||
import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
|
||||
import { TableToolbar } from '#/components/table-toolbar';
|
||||
|
@ -29,7 +29,8 @@ import { $t } from '#/locales';
|
|||
import { handleTree,isEmpty } from '@vben/utils'
|
||||
import { get${simpleClassName}List, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||
#else## 标准表接口
|
||||
import { get${simpleClassName}Page, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||
import { isEmpty } from '@vben/utils';
|
||||
import { get${simpleClassName}Page, delete${simpleClassName},#if ($deleteBatchEnable) delete${simpleClassName}ListByIds,#end export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}';
|
||||
#end
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
|
@ -152,11 +153,38 @@ async function onDelete(row: ${simpleClassName}Api.${simpleClassName}) {
|
|||
key: 'action_process_msg',
|
||||
});
|
||||
await getList();
|
||||
} catch {
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
#if ($table.templateType != 2 && $deleteBatchEnable)
|
||||
/** 批量删除${table.classComment} */
|
||||
async function onDeleteBatch() {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting'),
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
try {
|
||||
await delete${simpleClassName}ListByIds(deleteIds.value);
|
||||
message.success( $t('ui.actionMessage.deleteSuccess') );
|
||||
await getList();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
const deleteIds = ref<number[]>([]) // 待删除${table.classComment} ID
|
||||
function setDeleteIds({
|
||||
records,
|
||||
}: {
|
||||
records: ${simpleClassName}Api.${simpleClassName}[];
|
||||
}) {
|
||||
deleteIds.value = records.map((item) => item.id);
|
||||
}
|
||||
#end
|
||||
|
||||
/** 导出表格 */
|
||||
async function onExport() {
|
||||
try {
|
||||
|
@ -302,6 +330,19 @@ onMounted(() => {
|
|||
>
|
||||
{{ $t('ui.actionTitle.export') }}
|
||||
</Button>
|
||||
#if ($table.templateType != 2 && $deleteBatchEnable)
|
||||
<Button
|
||||
:icon="h(Trash2)"
|
||||
type="primary"
|
||||
danger
|
||||
class="ml-2"
|
||||
:disabled="isEmpty(deleteIds)"
|
||||
@click="onDeleteBatch"
|
||||
v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:delete']"
|
||||
>
|
||||
批量删除
|
||||
</Button>
|
||||
#end
|
||||
</TableToolbar>
|
||||
</template>
|
||||
<vxe-table
|
||||
|
@ -326,7 +367,14 @@ onMounted(() => {
|
|||
#end
|
||||
show-overflow
|
||||
:loading="loading"
|
||||
#if ($table.templateType != 2 && $deleteBatchEnable)
|
||||
@checkboxAll="setDeleteIds"
|
||||
@checkboxChange="setDeleteIds"
|
||||
#end
|
||||
>
|
||||
#if ($table.templateType != 2 && $deleteBatchEnable)
|
||||
<vxe-column type="checkbox" width="40"></vxe-column>
|
||||
#end
|
||||
## 特殊:主子表专属逻辑
|
||||
#if ( $table.templateType == 12 && $subTables && $subTables.size() > 0 )
|
||||
<!-- 子表的列表 -->
|
||||
|
@ -421,7 +469,6 @@ onMounted(() => {
|
|||
</div>
|
||||
#end
|
||||
</ContentWrap>
|
||||
|
||||
#if ($table.templateType == 11) ## erp情况
|
||||
<ContentWrap>
|
||||
<!-- 子表的表单 -->
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
import type { VxeTableInstance } from '#/adapter/vxe-table';
|
||||
|
||||
import { DictTag } from '#/components/dict-tag';
|
||||
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
|
||||
import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
|
||||
import { reactive,ref, h, nextTick,watch,onMounted } from 'vue';
|
||||
import { cloneDeep, formatDateTime } from '@vben/utils';
|
||||
|
@ -22,15 +22,15 @@
|
|||
import { Tinymce as RichTextarea } from '#/components/tinymce';
|
||||
import { ImageUpload, FileUpload } from "#/components/upload";
|
||||
import { message,Button, Tabs,Pagination, Form, Input, Textarea, Select, RadioGroup, Radio, CheckboxGroup, Checkbox,RangePicker, DatePicker, TreeSelect } from 'ant-design-vue';
|
||||
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
|
||||
import { Plus } from '@vben/icons';
|
||||
import { Plus, Trash2 } from '@vben/icons';
|
||||
import { $t } from '#/locales';
|
||||
import { TableToolbar } from '#/components/table-toolbar';
|
||||
import { useTableToolbar } from '#/hooks';
|
||||
#end
|
||||
|
||||
#if ($table.templateType == 11) ## erp
|
||||
import { delete${subSimpleClassName}, get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||
import { delete${subSimpleClassName},#if ($deleteBatchEnable) delete${subSimpleClassName}ListByIds,#end get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${table.businessName}';
|
||||
import { isEmpty } from '@vben/utils';
|
||||
#else
|
||||
#if ($subTable.subJoinMany) ## 一对多
|
||||
import { get${subSimpleClassName}ListBy${SubJoinColumnName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||
|
@ -76,11 +76,38 @@ async function onDelete(row: ${simpleClassName}Api.${subSimpleClassName}) {
|
|||
content: $t('ui.actionMessage.deleteSuccess', [row.id]),
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
getList();
|
||||
} catch {
|
||||
await getList();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
#if ($deleteBatchEnable)
|
||||
/** 批量删除${subTable.classComment} */
|
||||
async function onDeleteBatch() {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting'),
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
try {
|
||||
await delete${subSimpleClassName}ListByIds(deleteIds.value);
|
||||
message.success( $t('ui.actionMessage.deleteSuccess') );
|
||||
await getList();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
const deleteIds = ref<number[]>([]) // 待删除${subTable.classComment} ID
|
||||
function setDeleteIds({
|
||||
records,
|
||||
}: {
|
||||
records: ${simpleClassName}Api.${subSimpleClassName}[];
|
||||
}) {
|
||||
deleteIds.value = records.map((item) => item.id);
|
||||
}
|
||||
#end
|
||||
#end
|
||||
|
||||
const loading = ref(true) // 列表的加载中
|
||||
|
@ -277,6 +304,19 @@ onMounted(() => {
|
|||
>
|
||||
{{ $t('ui.actionTitle.create', ['${table.classComment}']) }}
|
||||
</Button>
|
||||
#if ($deleteBatchEnable)
|
||||
<Button
|
||||
:icon="h(Trash2)"
|
||||
type="primary"
|
||||
danger
|
||||
class="ml-2"
|
||||
:disabled="isEmpty(deleteIds)"
|
||||
@click="onDeleteBatch"
|
||||
v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:delete']"
|
||||
>
|
||||
批量删除
|
||||
</Button>
|
||||
#end
|
||||
</TableToolbar>
|
||||
</template>
|
||||
<vxe-table
|
||||
|
@ -284,7 +324,14 @@ onMounted(() => {
|
|||
:data="list"
|
||||
show-overflow
|
||||
:loading="loading"
|
||||
#if ($deleteBatchEnable)
|
||||
@checkboxAll="setDeleteIds"
|
||||
@checkboxChange="setDeleteIds"
|
||||
#end
|
||||
>
|
||||
#if ($deleteBatchEnable)
|
||||
<vxe-column type="checkbox" width="40"></vxe-column>
|
||||
#end
|
||||
#foreach($column in $subColumns)
|
||||
#if ($column.listOperationResult)
|
||||
#set ($dictType=$column.dictType)
|
||||
|
|
|
@ -89,6 +89,13 @@ export function delete${simpleClassName}(id: number) {
|
|||
return requestClient.delete(`${baseURL}/delete?id=${id}`);
|
||||
}
|
||||
|
||||
#if ( $table.templateType != 2 && $deleteBatchEnable)
|
||||
/** 批量删除${table.classComment} */
|
||||
export function delete${simpleClassName}ListByIds(ids: number[]) {
|
||||
return requestClient.delete(`${baseURL}/delete-list?ids=${ids.join(',')}`)
|
||||
}
|
||||
#end
|
||||
|
||||
/** 导出${table.classComment} */
|
||||
export function export${simpleClassName}(params: any) {
|
||||
return requestClient.download('${baseURL}/export-excel', params);
|
||||
|
@ -144,6 +151,13 @@ export function delete${subSimpleClassName}(id: number) {
|
|||
return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete?id=${id}`);
|
||||
}
|
||||
|
||||
#if ($deleteBatchEnable)
|
||||
/** 批量删除${subTable.classComment} */
|
||||
export function delete${subSimpleClassName}ListByIds(ids: number[]) {
|
||||
return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete-list?ids=${ids.join(',')}`)
|
||||
}
|
||||
#end
|
||||
|
||||
/** 获得${subTable.classComment} */
|
||||
export function get${subSimpleClassName}(id: number) {
|
||||
return requestClient.get<${simpleClassName}Api.${subSimpleClassName}>(`${baseURL}/${subSimpleClassName_strikeCase}/get?id=${id}`);
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${table.businessName}';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { getRangePickerDefaultProps } from '#/utils/date';
|
||||
import { DICT_TYPE, getDictOptions } from '#/utils/dict';
|
||||
|
||||
import {
|
||||
DICT_TYPE,
|
||||
getDictOptions,
|
||||
getRangePickerDefaultProps,
|
||||
} from '#/utils';
|
||||
#if(${table.templateType} == 2)## 树表需要导入这些
|
||||
import { get${simpleClassName}List } from '#/api/${table.moduleName}/${table.businessName}';
|
||||
import { handleTree } from '@vben/utils';
|
||||
#end
|
||||
import { useAccess } from '@vben/access';
|
||||
|
||||
const { hasAccessByCodes } = useAccess();
|
||||
|
||||
/** 新增/修改的表单 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
|
@ -187,10 +186,11 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(
|
||||
onActionClick?: OnActionClickFn<${simpleClassName}Api.${simpleClassName}>,
|
||||
): VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>['columns'] {
|
||||
export function useGridColumns(): VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>['columns'] {
|
||||
return [
|
||||
#if ($table.templateType != 2 && $deleteBatchEnable)
|
||||
{ type: 'checkbox', width: 40 },
|
||||
#end
|
||||
#if ($table.templateType == 12) ## 内嵌情况
|
||||
{ type: 'expand', width: 80, slots: { content: 'expand_content' } },
|
||||
#end
|
||||
|
@ -218,43 +218,10 @@ export function useGridColumns(
|
|||
#end
|
||||
#end
|
||||
{
|
||||
field: 'operation',
|
||||
title: '操作',
|
||||
minWidth: 200,
|
||||
align: 'center',
|
||||
width: 200,
|
||||
fixed: 'right',
|
||||
headerAlign: 'center',
|
||||
showOverflow: false,
|
||||
cellRender: {
|
||||
attrs: {
|
||||
nameField: '${columns[0].javaField}',
|
||||
nameTitle: '${table.classComment}',
|
||||
onClick: onActionClick,
|
||||
},
|
||||
name: 'CellOperation',
|
||||
options: [
|
||||
#if (${table.templateType} == 2)## 树表特有操作
|
||||
{
|
||||
code: 'append',
|
||||
text: '新增下级',
|
||||
show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:create']),
|
||||
},
|
||||
#end
|
||||
{
|
||||
code: 'edit',
|
||||
show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:update']),
|
||||
},
|
||||
{
|
||||
code: 'delete',
|
||||
show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:delete']),
|
||||
#if (${table.templateType} == 2)## 树表禁止删除带有子节点的数据
|
||||
disabled: (row: ${simpleClassName}Api.${simpleClassName}) => {
|
||||
return !!(row.children && row.children.length > 0);
|
||||
},
|
||||
#end
|
||||
},
|
||||
],
|
||||
},
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
@ -422,10 +389,11 @@ export function use${subSimpleClassName}GridFormSchema(): VbenFormSchema[] {
|
|||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function use${subSimpleClassName}GridColumns(
|
||||
onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>,
|
||||
): VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>['columns'] {
|
||||
export function use${subSimpleClassName}GridColumns(): VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>['columns'] {
|
||||
return [
|
||||
#if ($table.templateType != 2 && $deleteBatchEnable)
|
||||
{ type: 'checkbox', width: 40 },
|
||||
#end
|
||||
#foreach($column in $subColumns)
|
||||
#if ($column.listOperationResult)
|
||||
#set ($dictType = $column.dictType)
|
||||
|
@ -447,31 +415,10 @@ export function use${subSimpleClassName}GridColumns(
|
|||
#end
|
||||
#end
|
||||
{
|
||||
field: 'operation',
|
||||
title: '操作',
|
||||
minWidth: 200,
|
||||
align: 'center',
|
||||
width: 200,
|
||||
fixed: 'right',
|
||||
headerAlign: 'center',
|
||||
showOverflow: false,
|
||||
cellRender: {
|
||||
attrs: {
|
||||
nameField: '${columns[0].javaField}',
|
||||
nameTitle: '${subTable.classComment}',
|
||||
onClick: onActionClick,
|
||||
},
|
||||
name: 'CellOperation',
|
||||
options: [
|
||||
{
|
||||
code: 'edit',
|
||||
show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:update']),
|
||||
},
|
||||
{
|
||||
code: 'delete',
|
||||
show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:delete']),
|
||||
},
|
||||
],
|
||||
},
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
@ -517,27 +464,10 @@ export function use${subSimpleClassName}GridColumns(
|
|||
#end
|
||||
#end
|
||||
{
|
||||
field: 'operation',
|
||||
title: '操作',
|
||||
minWidth: 60,
|
||||
align: 'center',
|
||||
width: 200,
|
||||
fixed: 'right',
|
||||
headerAlign: 'center',
|
||||
showOverflow: false,
|
||||
cellRender: {
|
||||
attrs: {
|
||||
nameField: '${columns[0].javaField}',
|
||||
nameTitle: '${table.classComment}',
|
||||
onClick: onActionClick,
|
||||
},
|
||||
name: 'CellOperation',
|
||||
options: [
|
||||
{
|
||||
code: 'delete',
|
||||
show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:delete']),
|
||||
},
|
||||
],
|
||||
},
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
@ -672,7 +602,6 @@ export function use${subSimpleClassName}GridColumns(
|
|||
#end
|
||||
];
|
||||
}
|
||||
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
<script lang="ts" setup>
|
||||
import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${table.businessName}';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
import { Button, message,Tabs } from 'ant-design-vue';
|
||||
import { Download, Plus } from '@vben/icons';
|
||||
import { message,Tabs } from 'ant-design-vue';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
## 特殊:主子表专属逻辑
|
||||
|
@ -12,19 +11,19 @@ import Form from './modules/form.vue';
|
|||
#foreach ($subSimpleClassName in $subSimpleClassNames)
|
||||
#set ($index = $foreach.count - 1)
|
||||
#set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($index))
|
||||
import ${subSimpleClassName}List from './modules/${subSimpleClassName_strikeCase}-list.vue'
|
||||
import ${subSimpleClassName}List from './modules/${subSimpleClassName_strikeCase}-list.vue'
|
||||
#end
|
||||
#end
|
||||
|
||||
import { ref, h } from 'vue';
|
||||
import { ref, computed } from 'vue';
|
||||
import { $t } from '#/locales';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
#if (${table.templateType} == 2)## 树表接口
|
||||
import { get${simpleClassName}List, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}';
|
||||
#else## 标准表接口
|
||||
import { get${simpleClassName}Page, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}';
|
||||
import { get${simpleClassName}Page, delete${simpleClassName},#if ($deleteBatchEnable) delete${simpleClassName}ListByIds,#end export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}';
|
||||
#end
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
|
||||
|
@ -60,65 +59,73 @@ function onRefresh() {
|
|||
}
|
||||
|
||||
/** 创建${table.classComment} */
|
||||
function onCreate() {
|
||||
function handleCreate() {
|
||||
formModalApi.setData({}).open();
|
||||
}
|
||||
|
||||
/** 编辑${table.classComment} */
|
||||
function onEdit(row: ${simpleClassName}Api.${simpleClassName}) {
|
||||
function handleEdit(row: ${simpleClassName}Api.${simpleClassName}) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
#if (${table.templateType} == 2)## 树表特有:新增下级
|
||||
/** 新增下级${table.classComment} */
|
||||
function onAppend(row: ${simpleClassName}Api.${simpleClassName}) {
|
||||
function handleAppend(row: ${simpleClassName}Api.${simpleClassName}) {
|
||||
formModalApi.setData({ ${treeParentColumn.javaField}: row.id }).open();
|
||||
}
|
||||
#end
|
||||
|
||||
/** 删除${table.classComment} */
|
||||
async function onDelete(row: ${simpleClassName}Api.${simpleClassName}) {
|
||||
async function handleDelete(row: ${simpleClassName}Api.${simpleClassName}) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.id]),
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
key: 'action_key_msg',
|
||||
});
|
||||
try {
|
||||
await delete${simpleClassName}(row.id as number);
|
||||
message.success( $t('ui.actionMessage.deleteSuccess', [row.id]) );
|
||||
message.success({
|
||||
content: $t('ui.actionMessage.deleteSuccess', [row.id]),
|
||||
key: 'action_key_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} catch {
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 导出表格 */
|
||||
async function onExport() {
|
||||
const data = await export${simpleClassName}(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '${table.classComment}.xls', source: data });
|
||||
#if ($table.templateType != 2 && $deleteBatchEnable)
|
||||
/** 批量删除${table.classComment} */
|
||||
async function handleDeleteBatch() {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting'),
|
||||
key: 'action_key_msg',
|
||||
});
|
||||
try {
|
||||
await delete${simpleClassName}ListByIds(deleteIds.value);
|
||||
message.success({
|
||||
content: $t('ui.actionMessage.deleteSuccess'),
|
||||
key: 'action_key_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 表格操作按钮的回调函数 */
|
||||
function onActionClick({
|
||||
code,
|
||||
row,
|
||||
}: OnActionClickParams<${simpleClassName}Api.${simpleClassName}>) {
|
||||
switch (code) {
|
||||
#if (${table.templateType} == 2)## 树表特有:新增下级
|
||||
case 'append': {
|
||||
onAppend(row);
|
||||
break;
|
||||
}
|
||||
#end
|
||||
case 'edit': {
|
||||
onEdit(row);
|
||||
break;
|
||||
}
|
||||
case 'delete': {
|
||||
onDelete(row);
|
||||
break;
|
||||
}
|
||||
}
|
||||
const deleteIds = ref<number[]>([]) // 待删除${table.classComment} ID
|
||||
function setDeleteIds({
|
||||
records,
|
||||
}: {
|
||||
records: ${simpleClassName}Api.${simpleClassName}[];
|
||||
}) {
|
||||
deleteIds.value = records.map((item) => item.id);
|
||||
}
|
||||
#end
|
||||
|
||||
/** 导出表格 */
|
||||
async function handleExport() {
|
||||
const data = await export${simpleClassName}(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '${table.classComment}.xls', source: data });
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
|
@ -126,7 +133,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(onActionClick),
|
||||
columns: useGridColumns(),
|
||||
#if (${table.templateType} == 11)
|
||||
height: '600px',
|
||||
#else
|
||||
|
@ -177,11 +184,17 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>,
|
||||
#if (${table.templateType} == 11)
|
||||
#if (${table.templateType} == 11 || $deleteBatchEnable)
|
||||
gridEvents:{
|
||||
#if(${table.templateType} == 11)
|
||||
cellClick: ({ row }: { row: ${simpleClassName}Api.${simpleClassName}}) => {
|
||||
select${simpleClassName}.value = row;
|
||||
},
|
||||
#end
|
||||
#if($deleteBatchEnable)
|
||||
checkboxAll: setDeleteIds,
|
||||
checkboxChange: setDeleteIds,
|
||||
#end
|
||||
}
|
||||
#end
|
||||
});
|
||||
|
@ -212,23 +225,75 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||
</template>
|
||||
#end
|
||||
<template #toolbar-tools>
|
||||
#if (${table.templateType} == 2)## 树表特有:展开/收缩按钮
|
||||
<Button @click="toggleExpand" class="mr-2">
|
||||
{{ isExpanded ? '收缩' : '展开' }}
|
||||
</Button>
|
||||
#end
|
||||
<Button :icon="h(Plus)" type="primary" @click="onCreate" v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:create']">
|
||||
{{ $t('ui.actionTitle.create', ['${table.classComment}']) }}
|
||||
</Button>
|
||||
<Button
|
||||
:icon="h(Download)"
|
||||
type="primary"
|
||||
class="ml-2"
|
||||
@click="onExport"
|
||||
v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:export']"
|
||||
>
|
||||
{{ $t('ui.actionTitle.export') }}
|
||||
</Button>
|
||||
<TableAction
|
||||
:actions="[
|
||||
#if (${table.templateType} == 2)## 树表特有:展开/收缩按钮
|
||||
{
|
||||
label: isExpanded ? '收缩' : '展开',
|
||||
type: 'primary',
|
||||
onClick: toggleExpand,
|
||||
},
|
||||
#end
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['${table.classComment}']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['${table.moduleName}:${simpleClassName_strikeCase}:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['${table.moduleName}:${simpleClassName_strikeCase}:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
#if ($table.templateType != 2 && $deleteBatchEnable)
|
||||
{
|
||||
label: $t('ui.actionTitle.deleteBatch'),
|
||||
type: 'primary',
|
||||
danger: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
disabled: isEmpty(deleteIds),
|
||||
auth: ['${table.moduleName}:${simpleClassName_strikeCase}:delete'],
|
||||
onClick: handleDeleteBatch,
|
||||
},
|
||||
#end
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
#if (${table.templateType} == 2)## 树表特有:新增下级
|
||||
{
|
||||
label: '新增下级',
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['${table.moduleName}:${simpleClassName_strikeCase}:create'],
|
||||
onClick: handleAppend.bind(null, row),
|
||||
},
|
||||
#end
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['${table.moduleName}:${simpleClassName_strikeCase}:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'link',
|
||||
danger: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['${table.moduleName}:${simpleClassName_strikeCase}:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.id]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
|
|
|
@ -6,44 +6,43 @@
|
|||
#set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($subIndex))
|
||||
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||
<script lang="ts" setup>
|
||||
import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${table.businessName}';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${table.businessName}';
|
||||
|
||||
#if ($table.templateType == 11) ## erp
|
||||
import ${subSimpleClassName}Form from './${subSimpleClassName_strikeCase}-form.vue'
|
||||
import ${subSimpleClassName}Form from './${subSimpleClassName_strikeCase}-form.vue'
|
||||
#end
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { Button, message } from 'ant-design-vue';
|
||||
import { Plus } from '@vben/icons';
|
||||
import { #if($table.templateType != 11)ref,#end h, nextTick,watch } from 'vue';
|
||||
import { $t } from '#/locales';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { message } from 'ant-design-vue';
|
||||
import { ref, computed, nextTick,watch } from 'vue';
|
||||
import { $t } from '#/locales';
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
|
||||
#if ($table.templateType == 11) ## erp
|
||||
import { delete${subSimpleClassName}, get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${table.businessName}';
|
||||
import { use${subSimpleClassName}GridFormSchema, use${subSimpleClassName}GridColumns } from '../data';
|
||||
#else
|
||||
#if ($subTable.subJoinMany) ## 一对多
|
||||
import { get${subSimpleClassName}ListBy${SubJoinColumnName} } from '#/api/${table.moduleName}/${table.businessName}';
|
||||
#else
|
||||
import { get${subSimpleClassName}By${SubJoinColumnName} } from '#/api/${table.moduleName}/${table.businessName}';
|
||||
#end
|
||||
import { use${subSimpleClassName}GridColumns } from '../data';
|
||||
import { delete${subSimpleClassName},#if ($deleteBatchEnable) delete${subSimpleClassName}ListByIds,#end get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${table.businessName}';
|
||||
import { use${subSimpleClassName}GridFormSchema, use${subSimpleClassName}GridColumns } from '../data';
|
||||
import { isEmpty } from '@vben/utils';
|
||||
#else
|
||||
#if ($subTable.subJoinMany) ## 一对多
|
||||
import { get${subSimpleClassName}ListBy${SubJoinColumnName} } from '#/api/${table.moduleName}/${table.businessName}';
|
||||
#else
|
||||
import { get${subSimpleClassName}By${SubJoinColumnName} } from '#/api/${table.moduleName}/${table.businessName}';
|
||||
#end
|
||||
import { use${subSimpleClassName}GridColumns } from '../data';
|
||||
#end
|
||||
|
||||
const props = defineProps<{
|
||||
${subJoinColumn.javaField}?: number // ${subJoinColumn.columnComment}(主表的关联字段)
|
||||
${subJoinColumn.javaField}?: number // ${subJoinColumn.columnComment}(主表的关联字段)
|
||||
}>()
|
||||
|
||||
#if ($table.templateType == 11) ## erp
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: ${subSimpleClassName}Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: ${subSimpleClassName}Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 创建${subTable.classComment} */
|
||||
function onCreate() {
|
||||
function handleCreate() {
|
||||
if (!props.${subJoinColumn.javaField}){
|
||||
message.warning("请先选择一个${table.classComment}!")
|
||||
return
|
||||
|
@ -52,117 +51,137 @@ function onCreate() {
|
|||
}
|
||||
|
||||
/** 编辑${subTable.classComment} */
|
||||
function onEdit(row: ${simpleClassName}Api.${subSimpleClassName}) {
|
||||
function handleEdit(row: ${simpleClassName}Api.${subSimpleClassName}) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 删除${subTable.classComment} */
|
||||
async function onDelete(row: ${simpleClassName}Api.${subSimpleClassName}) {
|
||||
async function handleDelete(row: ${simpleClassName}Api.${subSimpleClassName}) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.id]),
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
try {
|
||||
await delete${subSimpleClassName}(row.id as number);
|
||||
message.success( $t('ui.actionMessage.deleteSuccess', [row.id]) );
|
||||
message.success({
|
||||
content: $t('ui.actionMessage.deleteSuccess', [row.id]),
|
||||
key: 'action_key_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} catch {
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 表格操作按钮的回调函数 */
|
||||
function onActionClick({
|
||||
code,
|
||||
row,
|
||||
}: OnActionClickParams<${simpleClassName}Api.${subSimpleClassName}>) {
|
||||
switch (code) {
|
||||
case 'edit': {
|
||||
onEdit(row);
|
||||
break;
|
||||
}
|
||||
case 'delete': {
|
||||
onDelete(row);
|
||||
break;
|
||||
}
|
||||
#if ($deleteBatchEnable)
|
||||
/** 批量删除${subTable.classComment} */
|
||||
async function handleDeleteBatch() {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting'),
|
||||
key: 'action_key_msg',
|
||||
});
|
||||
try {
|
||||
await delete${subSimpleClassName}ListByIds(deleteIds.value);
|
||||
message.success({
|
||||
content: $t('ui.actionMessage.deleteSuccess', [row.id]),
|
||||
key: 'action_key_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
const deleteIds = ref<number[]>([]) // 待删除${subTable.classComment} ID
|
||||
function setDeleteIds({
|
||||
records,
|
||||
}: {
|
||||
records: ${simpleClassName}Api.${subSimpleClassName}[];
|
||||
}) {
|
||||
deleteIds.value = records.map((item) => item.id);
|
||||
}
|
||||
#end
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
#if ($table.templateType == 11)
|
||||
formOptions: {
|
||||
schema: use${subSimpleClassName}GridFormSchema(),
|
||||
},
|
||||
|
||||
#end
|
||||
gridOptions: {
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
#if ($table.templateType == 11)
|
||||
columns: use${subSimpleClassName}GridColumns(onActionClick),
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
if (!props.${subJoinColumn.javaField}){
|
||||
return []
|
||||
}
|
||||
return await get${subSimpleClassName}Page({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
${subJoinColumn.javaField}: props.${subJoinColumn.javaField},
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
formOptions: {
|
||||
schema: use${subSimpleClassName}GridFormSchema(),
|
||||
},
|
||||
#end
|
||||
gridOptions: {
|
||||
#if ($table.templateType == 11)
|
||||
columns: use${subSimpleClassName}GridColumns(),
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
if (!props.${subJoinColumn.javaField}){
|
||||
return []
|
||||
}
|
||||
return await get${subSimpleClassName}Page({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
${subJoinColumn.javaField}: props.${subJoinColumn.javaField},
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
pagerConfig: {
|
||||
enabled: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: { code: 'query' },
|
||||
search: true,
|
||||
},
|
||||
pagerConfig: {
|
||||
enabled: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: { code: 'query' },
|
||||
search: true,
|
||||
},
|
||||
#else
|
||||
columns: use${subSimpleClassName}GridColumns(),
|
||||
pagerConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
toolbarConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
columns: use${subSimpleClassName}GridColumns(),
|
||||
pagerConfig: {
|
||||
nabled: false,
|
||||
},
|
||||
toolbarConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
#end
|
||||
height: '600px',
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
} as VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>,
|
||||
});
|
||||
height: '600px',
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
} as VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>,
|
||||
#if (${table.templateType} == 11 && $deleteBatchEnable)
|
||||
gridEvents:{
|
||||
checkboxAll: setDeleteIds,
|
||||
checkboxChange: setDeleteIds,
|
||||
}
|
||||
#end
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
const onRefresh = async ()=> {
|
||||
async function onRefresh() {
|
||||
#if ($table.templateType == 11) ## erp
|
||||
await gridApi.query();
|
||||
await gridApi.query();
|
||||
#else
|
||||
#if ($subTable.subJoinMany) ## 一对多
|
||||
await gridApi.grid.loadData(await get${subSimpleClassName}ListBy${SubJoinColumnName}(props.${subJoinColumn.javaField}!));
|
||||
#else
|
||||
await gridApi.grid.loadData([await get${subSimpleClassName}By${SubJoinColumnName}(props.${subJoinColumn.javaField}!)]);
|
||||
#end
|
||||
#if ($subTable.subJoinMany) ## 一对多
|
||||
await gridApi.grid.loadData(await get${subSimpleClassName}ListBy${SubJoinColumnName}(props.${subJoinColumn.javaField}!));
|
||||
#else
|
||||
await gridApi.grid.loadData([await get${subSimpleClassName}By${SubJoinColumnName}(props.${subJoinColumn.javaField}!)]);
|
||||
#end
|
||||
#end
|
||||
}
|
||||
|
||||
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||
watch(
|
||||
() => props.${subJoinColumn.javaField},
|
||||
async (val) => {
|
||||
if (!val) {
|
||||
return;
|
||||
}
|
||||
await nextTick();
|
||||
await onRefresh()
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||
watch(
|
||||
() => props.${subJoinColumn.javaField},
|
||||
async (val) => {
|
||||
if (!val) {
|
||||
return;
|
||||
}
|
||||
await nextTick();
|
||||
await onRefresh()
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@ -170,9 +189,52 @@ const onRefresh = async ()=> {
|
|||
<FormModal @success="onRefresh" />
|
||||
<Grid table-title="${subTable.classComment}列表">
|
||||
<template #toolbar-tools>
|
||||
<Button :icon="h(Plus)" type="primary" @click="onCreate" v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:create']">
|
||||
{{ $t('ui.actionTitle.create', ['${subTable.classComment}']) }}
|
||||
</Button>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['${table.classComment}']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['${table.moduleName}:${simpleClassName_strikeCase}:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
#if ($table.templateType == 11 && $deleteBatchEnable)
|
||||
{
|
||||
label: $t('ui.actionTitle.deleteBatch'),
|
||||
type: 'primary',
|
||||
danger: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
disabled: isEmpty(deleteIds),
|
||||
auth: ['${table.moduleName}:${simpleClassName_strikeCase}:delete'],
|
||||
onClick: handleDeleteBatch,
|
||||
},
|
||||
#end
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['${table.moduleName}:${simpleClassName_strikeCase}:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'link',
|
||||
danger: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['${table.moduleName}:${simpleClassName_strikeCase}:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.id]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
#else
|
||||
|
|
|
@ -293,6 +293,8 @@ yudao:
|
|||
base-package: ${yudao.info.base-package}
|
||||
db-schemas: ${spring.datasource.dynamic.datasource.master.name}
|
||||
front-type: 20 # 前端模版的类型,参见 CodegenFrontTypeEnum 枚举类
|
||||
vo-type: 10 # VO 的类型,参见 CodegenVOTypeEnum 枚举类
|
||||
delete-batch-enable: true # 是否生成批量删除接口
|
||||
unit-test-enable: false # 是否生成单元测试
|
||||
tenant: # 多租户相关配置项
|
||||
enable: true
|
||||
|
|
Loading…
Reference in New Issue