代码生成:主子表(inner)部分模版
parent
a4b1395e92
commit
90842542a9
@ -0,0 +1,115 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.demo12;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo12.vo.*;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentContactDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentTeacherDO;
|
||||
import cn.iocoder.yudao.module.infra.convert.demo12.InfraDemo12StudentConvert;
|
||||
import cn.iocoder.yudao.module.infra.service.demo12.InfraDemo12StudentService;
|
||||
|
||||
@Tag(name = "管理后台 - 学生")
|
||||
@RestController
|
||||
@RequestMapping("/infra/demo12-student")
|
||||
@Validated
|
||||
public class InfraDemo12StudentController {
|
||||
|
||||
@Resource
|
||||
private InfraDemo12StudentService demo12StudentService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建学生")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo12-student:create')")
|
||||
public CommonResult<Long> createDemo12Student(@Valid @RequestBody InfraDemo12StudentCreateReqVO createReqVO) {
|
||||
return success(demo12StudentService.createDemo12Student(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新学生")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo12-student:update')")
|
||||
public CommonResult<Boolean> updateDemo12Student(@Valid @RequestBody InfraDemo12StudentUpdateReqVO updateReqVO) {
|
||||
demo12StudentService.updateDemo12Student(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除学生")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo12-student:delete')")
|
||||
public CommonResult<Boolean> deleteDemo12Student(@RequestParam("id") Long id) {
|
||||
demo12StudentService.deleteDemo12Student(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得学生")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo12-student:query')")
|
||||
public CommonResult<InfraDemo12StudentRespVO> getDemo12Student(@RequestParam("id") Long id) {
|
||||
InfraDemo12StudentDO demo12Student = demo12StudentService.getDemo12Student(id);
|
||||
return success(InfraDemo12StudentConvert.INSTANCE.convert(demo12Student));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得学生分页")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo12-student:query')")
|
||||
public CommonResult<PageResult<InfraDemo12StudentRespVO>> getDemo12StudentPage(@Valid InfraDemo12StudentPageReqVO pageVO) {
|
||||
PageResult<InfraDemo12StudentDO> pageResult = demo12StudentService.getDemo12StudentPage(pageVO);
|
||||
return success(InfraDemo12StudentConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出学生 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo12-student:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportDemo12StudentExcel(@Valid InfraDemo12StudentExportReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<InfraDemo12StudentDO> list = demo12StudentService.getDemo12StudentList(exportReqVO);
|
||||
// 导出 Excel
|
||||
List<InfraDemo12StudentExcelVO> datas = InfraDemo12StudentConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "学生.xls", "数据", InfraDemo12StudentExcelVO.class, datas);
|
||||
}
|
||||
|
||||
// ==================== 子表(学生联系人) ====================
|
||||
|
||||
@GetMapping("/demo12-student/list-by-student-id")
|
||||
@Operation(summary = "获得学生联系人列表")
|
||||
@Parameter(name = "studentId", description = "学生编号")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo12-student:query')")
|
||||
public CommonResult<List<InfraDemo12StudentContactDO>> getDemo12StudentContactListByStudentId(@RequestParam("studentId") Long studentId) {
|
||||
return success(demo12StudentService.getDemo12StudentContactListByStudentId(studentId));
|
||||
}
|
||||
|
||||
// ==================== 子表(学生班主任) ====================
|
||||
|
||||
@GetMapping("/demo12-student/get-by-student-id")
|
||||
@Operation(summary = "获得学生班主任")
|
||||
@Parameter(name = "studentId", description = "学生编号")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo12-student:query')")
|
||||
public CommonResult<InfraDemo12StudentTeacherDO> getDemo12StudentTeacherByStudentId(@RequestParam("studentId") Long studentId) {
|
||||
return success(demo12StudentService.getDemo12StudentTeacherByStudentId(studentId));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 学生创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfraDemo12StudentCreateReqVO extends InfraDemo12StudentBaseVO {
|
||||
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
|
||||
|
||||
/**
|
||||
* 学生 Excel VO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
public class InfraDemo12StudentExcelVO {
|
||||
|
||||
@ExcelProperty("编号")
|
||||
private Long id;
|
||||
|
||||
@ExcelProperty("名字")
|
||||
private String name;
|
||||
|
||||
@ExcelProperty("简介")
|
||||
private String description;
|
||||
|
||||
@ExcelProperty("出生日期")
|
||||
private LocalDateTime birthday;
|
||||
|
||||
@ExcelProperty(value = "性别", converter = DictConvert.class)
|
||||
@DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
|
||||
private Integer sex;
|
||||
|
||||
@ExcelProperty(value = "是否有效", converter = DictConvert.class)
|
||||
@DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
|
||||
private Boolean enabled;
|
||||
|
||||
@ExcelProperty("头像")
|
||||
private String avatar;
|
||||
|
||||
@ExcelProperty("附件")
|
||||
private String video;
|
||||
|
||||
@ExcelProperty("备注")
|
||||
private String memo;
|
||||
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
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
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfraDemo12StudentPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "名字", example = "芋头")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "出生日期")
|
||||
private LocalDateTime birthday;
|
||||
|
||||
@Schema(description = "性别", example = "1")
|
||||
private Integer sex;
|
||||
|
||||
@Schema(description = "是否有效", example = "true")
|
||||
private Boolean enabled;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 学生 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfraDemo12StudentRespVO extends InfraDemo12StudentBaseVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 学生更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfraDemo12StudentUpdateReqVO extends InfraDemo12StudentBaseVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
@NotNull(message = "编号不能为空")
|
||||
private Long id;
|
||||
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package cn.iocoder.yudao.module.infra.convert.demo12;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo12.vo.*;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentDO;
|
||||
|
||||
/**
|
||||
* 学生 Convert
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface InfraDemo12StudentConvert {
|
||||
|
||||
InfraDemo12StudentConvert INSTANCE = Mappers.getMapper(InfraDemo12StudentConvert.class);
|
||||
|
||||
InfraDemo12StudentDO convert(InfraDemo12StudentCreateReqVO bean);
|
||||
|
||||
InfraDemo12StudentDO convert(InfraDemo12StudentUpdateReqVO bean);
|
||||
|
||||
InfraDemo12StudentRespVO convert(InfraDemo12StudentDO bean);
|
||||
|
||||
List<InfraDemo12StudentRespVO> convertList(List<InfraDemo12StudentDO> list);
|
||||
|
||||
PageResult<InfraDemo12StudentRespVO> convertPage(PageResult<InfraDemo12StudentDO> page);
|
||||
|
||||
List<InfraDemo12StudentExcelVO> convertList02(List<InfraDemo12StudentDO> list);
|
||||
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
package cn.iocoder.yudao.module.infra.dal.dataobject.demo12;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 学生联系人 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("infra_demo12_student_contact")
|
||||
@KeySequence("infra_demo12_student_contact_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class InfraDemo12StudentContactDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 学生编号
|
||||
*/
|
||||
private Long studentId;
|
||||
/**
|
||||
* 名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 简介
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 出生日期
|
||||
*/
|
||||
private LocalDateTime birthday;
|
||||
/**
|
||||
* 性别
|
||||
*
|
||||
* 枚举 {@link TODO system_user_sex 对应的类}
|
||||
*/
|
||||
private Integer sex;
|
||||
/**
|
||||
* 是否有效
|
||||
*
|
||||
* 枚举 {@link TODO infra_boolean_string 对应的类}
|
||||
*/
|
||||
private Boolean enabled;
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String avatar;
|
||||
/**
|
||||
* 附件
|
||||
*/
|
||||
private String video;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String memo;
|
||||
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
package cn.iocoder.yudao.module.infra.dal.dataobject.demo12;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 学生 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("infra_demo12_student")
|
||||
@KeySequence("infra_demo12_student_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class InfraDemo12StudentDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 简介
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 出生日期
|
||||
*/
|
||||
private LocalDateTime birthday;
|
||||
/**
|
||||
* 性别
|
||||
*
|
||||
* 枚举 {@link TODO system_user_sex 对应的类}
|
||||
*/
|
||||
private Integer sex;
|
||||
/**
|
||||
* 是否有效
|
||||
*
|
||||
* 枚举 {@link TODO infra_boolean_string 对应的类}
|
||||
*/
|
||||
private Boolean enabled;
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String avatar;
|
||||
/**
|
||||
* 附件
|
||||
*/
|
||||
private String video;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String memo;
|
||||
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
package cn.iocoder.yudao.module.infra.dal.dataobject.demo12;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 学生班主任 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("infra_demo12_student_teacher")
|
||||
@KeySequence("infra_demo12_student_teacher_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class InfraDemo12StudentTeacherDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 学生编号
|
||||
*/
|
||||
private Long studentId;
|
||||
/**
|
||||
* 名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 简介
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 出生日期
|
||||
*/
|
||||
private LocalDateTime birthday;
|
||||
/**
|
||||
* 性别
|
||||
*
|
||||
* 枚举 {@link TODO system_user_sex 对应的类}
|
||||
*/
|
||||
private Integer sex;
|
||||
/**
|
||||
* 是否有效
|
||||
*
|
||||
* 枚举 {@link TODO infra_boolean_string 对应的类}
|
||||
*/
|
||||
private Boolean enabled;
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String avatar;
|
||||
/**
|
||||
* 附件
|
||||
*/
|
||||
private String video;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String memo;
|
||||
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package cn.iocoder.yudao.module.infra.dal.mysql.demo12;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentContactDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 学生联系人 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface InfraDemo12StudentContactMapper extends BaseMapperX<InfraDemo12StudentContactDO> {
|
||||
|
||||
default List<InfraDemo12StudentContactDO> selectListByStudentId(Long studentId) {
|
||||
return selectList(InfraDemo12StudentContactDO::getStudentId, studentId);
|
||||
}
|
||||
|
||||
default int deleteByStudentId(Long studentId) {
|
||||
return delete(InfraDemo12StudentContactDO::getStudentId, studentId);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package cn.iocoder.yudao.module.infra.dal.mysql.demo12;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo12.vo.*;
|
||||
|
||||
/**
|
||||
* 学生 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface InfraDemo12StudentMapper extends BaseMapperX<InfraDemo12StudentDO> {
|
||||
|
||||
default PageResult<InfraDemo12StudentDO> selectPage(InfraDemo12StudentPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<InfraDemo12StudentDO>()
|
||||
.likeIfPresent(InfraDemo12StudentDO::getName, reqVO.getName())
|
||||
.eqIfPresent(InfraDemo12StudentDO::getBirthday, reqVO.getBirthday())
|
||||
.eqIfPresent(InfraDemo12StudentDO::getSex, reqVO.getSex())
|
||||
.eqIfPresent(InfraDemo12StudentDO::getEnabled, reqVO.getEnabled())
|
||||
.betweenIfPresent(InfraDemo12StudentDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(InfraDemo12StudentDO::getId));
|
||||
}
|
||||
|
||||
default List<InfraDemo12StudentDO> selectList(InfraDemo12StudentExportReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<InfraDemo12StudentDO>()
|
||||
.likeIfPresent(InfraDemo12StudentDO::getName, reqVO.getName())
|
||||
.eqIfPresent(InfraDemo12StudentDO::getBirthday, reqVO.getBirthday())
|
||||
.eqIfPresent(InfraDemo12StudentDO::getSex, reqVO.getSex())
|
||||
.eqIfPresent(InfraDemo12StudentDO::getEnabled, reqVO.getEnabled())
|
||||
.betweenIfPresent(InfraDemo12StudentDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(InfraDemo12StudentDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package cn.iocoder.yudao.module.infra.dal.mysql.demo12;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentTeacherDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 学生班主任 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface InfraDemo12StudentTeacherMapper extends BaseMapperX<InfraDemo12StudentTeacherDO> {
|
||||
|
||||
default InfraDemo12StudentTeacherDO selectByStudentId(Long studentId) {
|
||||
return selectOne(InfraDemo12StudentTeacherDO::getStudentId, studentId);
|
||||
}
|
||||
|
||||
default int deleteByStudentId(Long studentId) {
|
||||
return delete(InfraDemo12StudentTeacherDO::getStudentId, studentId);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
package cn.iocoder.yudao.module.infra.service.demo12;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo12.vo.*;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentContactDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentTeacherDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
/**
|
||||
* 学生 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface InfraDemo12StudentService {
|
||||
|
||||
/**
|
||||
* 创建学生
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createDemo12Student(@Valid InfraDemo12StudentCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新学生
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateDemo12Student(@Valid InfraDemo12StudentUpdateReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除学生
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteDemo12Student(Long id);
|
||||
|
||||
/**
|
||||
* 获得学生
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 学生
|
||||
*/
|
||||
InfraDemo12StudentDO getDemo12Student(Long id);
|
||||
|
||||
/**
|
||||
* 获得学生分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 学生分页
|
||||
*/
|
||||
PageResult<InfraDemo12StudentDO> getDemo12StudentPage(InfraDemo12StudentPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得学生列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return 学生列表
|
||||
*/
|
||||
List<InfraDemo12StudentDO> getDemo12StudentList(InfraDemo12StudentExportReqVO exportReqVO);
|
||||
|
||||
|
||||
// ==================== 子表(学生联系人) ====================
|
||||
|
||||
/**
|
||||
* 获得学生联系人列表
|
||||
*
|
||||
* @param studentId 学生编号
|
||||
* @return 学生联系人列表
|
||||
*/
|
||||
List<InfraDemo12StudentContactDO> getDemo12StudentContactListByStudentId(Long studentId);
|
||||
|
||||
|
||||
// ==================== 子表(学生班主任) ====================
|
||||
|
||||
/**
|
||||
* 获得学生班主任
|
||||
*
|
||||
* @param studentId 学生编号
|
||||
* @return 学生班主任
|
||||
*/
|
||||
InfraDemo12StudentTeacherDO getDemo12StudentTeacherByStudentId(Long studentId);
|
||||
|
||||
}
|
||||
@ -0,0 +1,183 @@
|
||||
package cn.iocoder.yudao.module.infra.service.demo12;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo12.vo.*;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.demo12.InfraDemo12StudentMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link InfraDemo12StudentServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Import(InfraDemo12StudentServiceImpl.class)
|
||||
public class InfraDemo12StudentServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private InfraDemo12StudentServiceImpl demo12StudentService;
|
||||
|
||||
@Resource
|
||||
private InfraDemo12StudentMapper demo12StudentMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateDemo12Student_success() {
|
||||
// 准备参数
|
||||
InfraDemo12StudentCreateReqVO reqVO = randomPojo(InfraDemo12StudentCreateReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long demo12StudentId = demo12StudentService.createDemo12Student(reqVO);
|
||||
// 断言
|
||||
assertNotNull(demo12StudentId);
|
||||
// 校验记录的属性是否正确
|
||||
InfraDemo12StudentDO demo12Student = demo12StudentMapper.selectById(demo12StudentId);
|
||||
assertPojoEquals(reqVO, demo12Student);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDemo12Student_success() {
|
||||
// mock 数据
|
||||
InfraDemo12StudentDO dbDemo12Student = randomPojo(InfraDemo12StudentDO.class);
|
||||
demo12StudentMapper.insert(dbDemo12Student);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
InfraDemo12StudentUpdateReqVO reqVO = randomPojo(InfraDemo12StudentUpdateReqVO.class, o -> {
|
||||
o.setId(dbDemo12Student.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
demo12StudentService.updateDemo12Student(reqVO);
|
||||
// 校验是否更新正确
|
||||
InfraDemo12StudentDO demo12Student = demo12StudentMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, demo12Student);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDemo12Student_notExists() {
|
||||
// 准备参数
|
||||
InfraDemo12StudentUpdateReqVO reqVO = randomPojo(InfraDemo12StudentUpdateReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> demo12StudentService.updateDemo12Student(reqVO), DEMO12_STUDENT_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteDemo12Student_success() {
|
||||
// mock 数据
|
||||
InfraDemo12StudentDO dbDemo12Student = randomPojo(InfraDemo12StudentDO.class);
|
||||
demo12StudentMapper.insert(dbDemo12Student);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbDemo12Student.getId();
|
||||
|
||||
// 调用
|
||||
demo12StudentService.deleteDemo12Student(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(demo12StudentMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteDemo12Student_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> demo12StudentService.deleteDemo12Student(id), DEMO12_STUDENT_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetDemo12StudentPage() {
|
||||
// mock 数据
|
||||
InfraDemo12StudentDO dbDemo12Student = randomPojo(InfraDemo12StudentDO.class, o -> { // 等会查询到
|
||||
o.setName(null);
|
||||
o.setBirthday(null);
|
||||
o.setSex(null);
|
||||
o.setEnabled(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
demo12StudentMapper.insert(dbDemo12Student);
|
||||
// 测试 name 不匹配
|
||||
demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setName(null)));
|
||||
// 测试 birthday 不匹配
|
||||
demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setBirthday(null)));
|
||||
// 测试 sex 不匹配
|
||||
demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setSex(null)));
|
||||
// 测试 enabled 不匹配
|
||||
demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setEnabled(null)));
|
||||
// 测试 createTime 不匹配
|
||||
demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
InfraDemo12StudentPageReqVO reqVO = new InfraDemo12StudentPageReqVO();
|
||||
reqVO.setName(null);
|
||||
reqVO.setBirthday(null);
|
||||
reqVO.setSex(null);
|
||||
reqVO.setEnabled(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
PageResult<InfraDemo12StudentDO> pageResult = demo12StudentService.getDemo12StudentPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbDemo12Student, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetDemo12StudentList() {
|
||||
// mock 数据
|
||||
InfraDemo12StudentDO dbDemo12Student = randomPojo(InfraDemo12StudentDO.class, o -> { // 等会查询到
|
||||
o.setName(null);
|
||||
o.setBirthday(null);
|
||||
o.setSex(null);
|
||||
o.setEnabled(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
demo12StudentMapper.insert(dbDemo12Student);
|
||||
// 测试 name 不匹配
|
||||
demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setName(null)));
|
||||
// 测试 birthday 不匹配
|
||||
demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setBirthday(null)));
|
||||
// 测试 sex 不匹配
|
||||
demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setSex(null)));
|
||||
// 测试 enabled 不匹配
|
||||
demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setEnabled(null)));
|
||||
// 测试 createTime 不匹配
|
||||
demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
InfraDemo12StudentExportReqVO reqVO = new InfraDemo12StudentExportReqVO();
|
||||
reqVO.setName(null);
|
||||
reqVO.setBirthday(null);
|
||||
reqVO.setSex(null);
|
||||
reqVO.setEnabled(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
List<InfraDemo12StudentDO> list = demo12StudentService.getDemo12StudentList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbDemo12Student, list.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue