Commit 3d2022e31fb3490af69c3802f4be6c5bff288a7e
1 parent
c50d27f5
代码生成:完善 vue2 代码生成单元测试
Showing
107 changed files
with
8625 additions
and
0 deletions
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/assert.json
0 → 100644
| 1 | +[ { | |
| 2 | + "contentPath" : "java/InfraStudentPageReqVO", | |
| 3 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentPageReqVO.java" | |
| 4 | +}, { | |
| 5 | + "contentPath" : "java/InfraStudentRespVO", | |
| 6 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentRespVO.java" | |
| 7 | +}, { | |
| 8 | + "contentPath" : "java/InfraStudentSaveReqVO", | |
| 9 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentSaveReqVO.java" | |
| 10 | +}, { | |
| 11 | + "contentPath" : "java/InfraStudentController", | |
| 12 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/InfraStudentController.java" | |
| 13 | +}, { | |
| 14 | + "contentPath" : "java/InfraStudentDO", | |
| 15 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentDO.java" | |
| 16 | +}, { | |
| 17 | + "contentPath" : "java/InfraStudentContactDO", | |
| 18 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentContactDO.java" | |
| 19 | +}, { | |
| 20 | + "contentPath" : "java/InfraStudentTeacherDO", | |
| 21 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentTeacherDO.java" | |
| 22 | +}, { | |
| 23 | + "contentPath" : "java/InfraStudentMapper", | |
| 24 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentMapper.java" | |
| 25 | +}, { | |
| 26 | + "contentPath" : "java/InfraStudentContactMapper", | |
| 27 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentContactMapper.java" | |
| 28 | +}, { | |
| 29 | + "contentPath" : "java/InfraStudentTeacherMapper", | |
| 30 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentTeacherMapper.java" | |
| 31 | +}, { | |
| 32 | + "contentPath" : "xml/InfraStudentMapper", | |
| 33 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/resources/mapper/demo/InfraStudentMapper.xml" | |
| 34 | +}, { | |
| 35 | + "contentPath" : "java/InfraStudentServiceImpl", | |
| 36 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentServiceImpl.java" | |
| 37 | +}, { | |
| 38 | + "contentPath" : "java/InfraStudentService", | |
| 39 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentService.java" | |
| 40 | +}, { | |
| 41 | + "contentPath" : "java/InfraStudentServiceImplTest", | |
| 42 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentServiceImplTest.java" | |
| 43 | +}, { | |
| 44 | + "contentPath" : "java/ErrorCodeConstants_手动操作", | |
| 45 | + "filePath" : "yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants_手动操作.java" | |
| 46 | +}, { | |
| 47 | + "contentPath" : "sql/sql", | |
| 48 | + "filePath" : "sql/sql.sql" | |
| 49 | +}, { | |
| 50 | + "contentPath" : "sql/h2", | |
| 51 | + "filePath" : "sql/h2.sql" | |
| 52 | +}, { | |
| 53 | + "contentPath" : "vue/index", | |
| 54 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/index.vue" | |
| 55 | +}, { | |
| 56 | + "contentPath" : "js/student", | |
| 57 | + "filePath" : "yudao-ui-admin-vue2/src/api/infra/student.js" | |
| 58 | +}, { | |
| 59 | + "contentPath" : "vue/StudentForm", | |
| 60 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/StudentForm.vue" | |
| 61 | +}, { | |
| 62 | + "contentPath" : "vue/StudentContactForm", | |
| 63 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentContactForm.vue" | |
| 64 | +}, { | |
| 65 | + "contentPath" : "vue/StudentTeacherForm", | |
| 66 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentTeacherForm.vue" | |
| 67 | +}, { | |
| 68 | + "contentPath" : "vue/StudentContactList", | |
| 69 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentContactList.vue" | |
| 70 | +}, { | |
| 71 | + "contentPath" : "vue/StudentTeacherList", | |
| 72 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentTeacherList.vue" | |
| 73 | +} ] | |
| 0 | 74 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/ErrorCodeConstants_手动操作
0 → 100644
| 1 | +// TODO 待办:请将下面的错误码复制到 yudao-module-infra-api 模块的 ErrorCodeConstants 类中。注意,请给“TODO 补充编号”设置一个错误码编号!!! | |
| 2 | +// ========== 学生 TODO 补充编号 ========== | |
| 3 | +ErrorCode STUDENT_NOT_EXISTS = new ErrorCode(TODO 补充编号, "学生不存在"); | |
| 4 | +ErrorCode STUDENT_CONTACT_NOT_EXISTS = new ErrorCode(TODO 补充编号, "学生联系人不存在"); | |
| 5 | +ErrorCode STUDENT_TEACHER_NOT_EXISTS = new ErrorCode(TODO 补充编号, "学生班主任不存在"); | |
| 6 | +ErrorCode STUDENT_TEACHER_EXISTS = new ErrorCode(TODO 补充编号, "学生班主任已存在"); | |
| 0 | 7 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentContactDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生联系人 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student_contact") | |
| 16 | +@KeySequence("infra_student_contact_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentContactDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 学生编号 | |
| 32 | + */ | |
| 33 | + private Long studentId; | |
| 34 | + /** | |
| 35 | + * 名字 | |
| 36 | + */ | |
| 37 | + private String name; | |
| 38 | + /** | |
| 39 | + * 简介 | |
| 40 | + */ | |
| 41 | + private String description; | |
| 42 | + /** | |
| 43 | + * 出生日期 | |
| 44 | + */ | |
| 45 | + private LocalDateTime birthday; | |
| 46 | + /** | |
| 47 | + * 性别 | |
| 48 | + * | |
| 49 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 50 | + */ | |
| 51 | + private Integer sex; | |
| 52 | + /** | |
| 53 | + * 是否有效 | |
| 54 | + * | |
| 55 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 56 | + */ | |
| 57 | + private Boolean enabled; | |
| 58 | + /** | |
| 59 | + * 头像 | |
| 60 | + */ | |
| 61 | + private String avatar; | |
| 62 | + /** | |
| 63 | + * 附件 | |
| 64 | + */ | |
| 65 | + private String video; | |
| 66 | + /** | |
| 67 | + * 备注 | |
| 68 | + */ | |
| 69 | + private String memo; | |
| 70 | + | |
| 71 | +} | |
| 0 | 72 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentContactMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 9 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 10 | +import org.apache.ibatis.annotations.Mapper; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生联系人 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentContactMapper extends BaseMapperX<InfraStudentContactDO> { | |
| 19 | + | |
| 20 | + default PageResult<InfraStudentContactDO> selectPage(PageParam reqVO, Long studentId) { | |
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<InfraStudentContactDO>() | |
| 22 | + .eq(InfraStudentContactDO::getStudentId, studentId) | |
| 23 | + .orderByDesc(InfraStudentContactDO::getId)); | |
| 24 | + } | |
| 25 | + | |
| 26 | + default int deleteByStudentId(Long studentId) { | |
| 27 | + return delete(InfraStudentContactDO::getStudentId, studentId); | |
| 28 | + } | |
| 29 | + | |
| 30 | +} | |
| 0 | 31 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentController
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo; | |
| 2 | + | |
| 3 | +import org.springframework.web.bind.annotation.*; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 7 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 8 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 9 | +import io.swagger.v3.oas.annotations.Operation; | |
| 10 | + | |
| 11 | +import javax.validation.constraints.*; | |
| 12 | +import javax.validation.*; | |
| 13 | +import javax.servlet.http.*; | |
| 14 | +import java.util.*; | |
| 15 | +import java.io.IOException; | |
| 16 | + | |
| 17 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 18 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 19 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 20 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 21 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 22 | + | |
| 23 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 24 | + | |
| 25 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 26 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | |
| 27 | + | |
| 28 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 29 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 30 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 31 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 32 | +import cn.iocoder.yudao.module.infra.service.demo.InfraStudentService; | |
| 33 | + | |
| 34 | +@Tag(name = "管理后台 - 学生") | |
| 35 | +@RestController | |
| 36 | +@RequestMapping("/infra/student") | |
| 37 | +@Validated | |
| 38 | +public class InfraStudentController { | |
| 39 | + | |
| 40 | + @Resource | |
| 41 | + private InfraStudentService studentService; | |
| 42 | + | |
| 43 | + @PostMapping("/create") | |
| 44 | + @Operation(summary = "创建学生") | |
| 45 | + @PreAuthorize("@ss.hasPermission('infra:student:create')") | |
| 46 | + public CommonResult<Long> createStudent(@Valid @RequestBody InfraStudentSaveReqVO createReqVO) { | |
| 47 | + return success(studentService.createStudent(createReqVO)); | |
| 48 | + } | |
| 49 | + | |
| 50 | + @PutMapping("/update") | |
| 51 | + @Operation(summary = "更新学生") | |
| 52 | + @PreAuthorize("@ss.hasPermission('infra:student:update')") | |
| 53 | + public CommonResult<Boolean> updateStudent(@Valid @RequestBody InfraStudentSaveReqVO updateReqVO) { | |
| 54 | + studentService.updateStudent(updateReqVO); | |
| 55 | + return success(true); | |
| 56 | + } | |
| 57 | + | |
| 58 | + @DeleteMapping("/delete") | |
| 59 | + @Operation(summary = "删除学生") | |
| 60 | + @Parameter(name = "id", description = "编号", required = true) | |
| 61 | + @PreAuthorize("@ss.hasPermission('infra:student:delete')") | |
| 62 | + public CommonResult<Boolean> deleteStudent(@RequestParam("id") Long id) { | |
| 63 | + studentService.deleteStudent(id); | |
| 64 | + return success(true); | |
| 65 | + } | |
| 66 | + | |
| 67 | + @GetMapping("/get") | |
| 68 | + @Operation(summary = "获得学生") | |
| 69 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 70 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 71 | + public CommonResult<InfraStudentRespVO> getStudent(@RequestParam("id") Long id) { | |
| 72 | + InfraStudentDO student = studentService.getStudent(id); | |
| 73 | + return success(BeanUtils.toBean(student, InfraStudentRespVO.class)); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @GetMapping("/page") | |
| 77 | + @Operation(summary = "获得学生分页") | |
| 78 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 79 | + public CommonResult<PageResult<InfraStudentRespVO>> getStudentPage(@Valid InfraStudentPageReqVO pageReqVO) { | |
| 80 | + PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(pageReqVO); | |
| 81 | + return success(BeanUtils.toBean(pageResult, InfraStudentRespVO.class)); | |
| 82 | + } | |
| 83 | + | |
| 84 | + @GetMapping("/export-excel") | |
| 85 | + @Operation(summary = "导出学生 Excel") | |
| 86 | + @PreAuthorize("@ss.hasPermission('infra:student:export')") | |
| 87 | + @OperateLog(type = EXPORT) | |
| 88 | + public void exportStudentExcel(@Valid InfraStudentPageReqVO pageReqVO, | |
| 89 | + HttpServletResponse response) throws IOException { | |
| 90 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 91 | + List<InfraStudentDO> list = studentService.getStudentPage(pageReqVO).getList(); | |
| 92 | + // 导出 Excel | |
| 93 | + ExcelUtils.write(response, "学生.xls", "数据", InfraStudentRespVO.class, | |
| 94 | + BeanUtils.toBean(list, InfraStudentRespVO.class)); | |
| 95 | + } | |
| 96 | + | |
| 97 | + // ==================== 子表(学生联系人) ==================== | |
| 98 | + | |
| 99 | + @GetMapping("/student-contact/page") | |
| 100 | + @Operation(summary = "获得学生联系人分页") | |
| 101 | + @Parameter(name = "studentId", description = "学生编号") | |
| 102 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 103 | + public CommonResult<PageResult<InfraStudentContactDO>> getStudentContactPage(PageParam pageReqVO, | |
| 104 | + @RequestParam("studentId") Long studentId) { | |
| 105 | + return success(studentService.getStudentContactPage(pageReqVO, studentId)); | |
| 106 | + } | |
| 107 | + | |
| 108 | + @PostMapping("/student-contact/create") | |
| 109 | + @Operation(summary = "创建学生联系人") | |
| 110 | + @PreAuthorize("@ss.hasPermission('infra:student:create')") | |
| 111 | + public CommonResult<Long> createStudentContact(@Valid @RequestBody InfraStudentContactDO studentContact) { | |
| 112 | + return success(studentService.createStudentContact(studentContact)); | |
| 113 | + } | |
| 114 | + | |
| 115 | + @PutMapping("/student-contact/update") | |
| 116 | + @Operation(summary = "更新学生联系人") | |
| 117 | + @PreAuthorize("@ss.hasPermission('infra:student:update')") | |
| 118 | + public CommonResult<Boolean> updateStudentContact(@Valid @RequestBody InfraStudentContactDO studentContact) { | |
| 119 | + studentService.updateStudentContact(studentContact); | |
| 120 | + return success(true); | |
| 121 | + } | |
| 122 | + | |
| 123 | + @DeleteMapping("/student-contact/delete") | |
| 124 | + @Parameter(name = "id", description = "编号", required = true) | |
| 125 | + @Operation(summary = "删除学生联系人") | |
| 126 | + @PreAuthorize("@ss.hasPermission('infra:student:delete')") | |
| 127 | + public CommonResult<Boolean> deleteStudentContact(@RequestParam("id") Long id) { | |
| 128 | + studentService.deleteStudentContact(id); | |
| 129 | + return success(true); | |
| 130 | + } | |
| 131 | + | |
| 132 | + @GetMapping("/student-contact/get") | |
| 133 | + @Operation(summary = "获得学生联系人") | |
| 134 | + @Parameter(name = "id", description = "编号", required = true) | |
| 135 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 136 | + public CommonResult<InfraStudentContactDO> getStudentContact(@RequestParam("id") Long id) { | |
| 137 | + return success(studentService.getStudentContact(id)); | |
| 138 | + } | |
| 139 | + | |
| 140 | + // ==================== 子表(学生班主任) ==================== | |
| 141 | + | |
| 142 | + @GetMapping("/student-teacher/page") | |
| 143 | + @Operation(summary = "获得学生班主任分页") | |
| 144 | + @Parameter(name = "studentId", description = "学生编号") | |
| 145 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 146 | + public CommonResult<PageResult<InfraStudentTeacherDO>> getStudentTeacherPage(PageParam pageReqVO, | |
| 147 | + @RequestParam("studentId") Long studentId) { | |
| 148 | + return success(studentService.getStudentTeacherPage(pageReqVO, studentId)); | |
| 149 | + } | |
| 150 | + | |
| 151 | + @PostMapping("/student-teacher/create") | |
| 152 | + @Operation(summary = "创建学生班主任") | |
| 153 | + @PreAuthorize("@ss.hasPermission('infra:student:create')") | |
| 154 | + public CommonResult<Long> createStudentTeacher(@Valid @RequestBody InfraStudentTeacherDO studentTeacher) { | |
| 155 | + return success(studentService.createStudentTeacher(studentTeacher)); | |
| 156 | + } | |
| 157 | + | |
| 158 | + @PutMapping("/student-teacher/update") | |
| 159 | + @Operation(summary = "更新学生班主任") | |
| 160 | + @PreAuthorize("@ss.hasPermission('infra:student:update')") | |
| 161 | + public CommonResult<Boolean> updateStudentTeacher(@Valid @RequestBody InfraStudentTeacherDO studentTeacher) { | |
| 162 | + studentService.updateStudentTeacher(studentTeacher); | |
| 163 | + return success(true); | |
| 164 | + } | |
| 165 | + | |
| 166 | + @DeleteMapping("/student-teacher/delete") | |
| 167 | + @Parameter(name = "id", description = "编号", required = true) | |
| 168 | + @Operation(summary = "删除学生班主任") | |
| 169 | + @PreAuthorize("@ss.hasPermission('infra:student:delete')") | |
| 170 | + public CommonResult<Boolean> deleteStudentTeacher(@RequestParam("id") Long id) { | |
| 171 | + studentService.deleteStudentTeacher(id); | |
| 172 | + return success(true); | |
| 173 | + } | |
| 174 | + | |
| 175 | + @GetMapping("/student-teacher/get") | |
| 176 | + @Operation(summary = "获得学生班主任") | |
| 177 | + @Parameter(name = "id", description = "编号", required = true) | |
| 178 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 179 | + public CommonResult<InfraStudentTeacherDO> getStudentTeacher(@RequestParam("id") Long id) { | |
| 180 | + return success(studentService.getStudentTeacher(id)); | |
| 181 | + } | |
| 182 | + | |
| 183 | +} | |
| 0 | 184 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student") | |
| 16 | +@KeySequence("infra_student_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 名字 | |
| 32 | + */ | |
| 33 | + private String name; | |
| 34 | + /** | |
| 35 | + * 简介 | |
| 36 | + */ | |
| 37 | + private String description; | |
| 38 | + /** | |
| 39 | + * 出生日期 | |
| 40 | + */ | |
| 41 | + private LocalDateTime birthday; | |
| 42 | + /** | |
| 43 | + * 性别 | |
| 44 | + * | |
| 45 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 46 | + */ | |
| 47 | + private Integer sex; | |
| 48 | + /** | |
| 49 | + * 是否有效 | |
| 50 | + * | |
| 51 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 52 | + */ | |
| 53 | + private Boolean enabled; | |
| 54 | + /** | |
| 55 | + * 头像 | |
| 56 | + */ | |
| 57 | + private String avatar; | |
| 58 | + /** | |
| 59 | + * 附件 | |
| 60 | + */ | |
| 61 | + private String video; | |
| 62 | + /** | |
| 63 | + * 备注 | |
| 64 | + */ | |
| 65 | + private String memo; | |
| 66 | + | |
| 67 | +} | |
| 0 | 68 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 9 | +import org.apache.ibatis.annotations.Mapper; | |
| 10 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentMapper extends BaseMapperX<InfraStudentDO> { | |
| 19 | + | |
| 20 | + default PageResult<InfraStudentDO> selectPage(InfraStudentPageReqVO reqVO) { | |
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<InfraStudentDO>() | |
| 22 | + .likeIfPresent(InfraStudentDO::getName, reqVO.getName()) | |
| 23 | + .eqIfPresent(InfraStudentDO::getBirthday, reqVO.getBirthday()) | |
| 24 | + .eqIfPresent(InfraStudentDO::getSex, reqVO.getSex()) | |
| 25 | + .eqIfPresent(InfraStudentDO::getEnabled, reqVO.getEnabled()) | |
| 26 | + .betweenIfPresent(InfraStudentDO::getCreateTime, reqVO.getCreateTime()) | |
| 27 | + .orderByDesc(InfraStudentDO::getId)); | |
| 28 | + } | |
| 29 | + | |
| 30 | +} | |
| 0 | 31 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentPageReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 11 | + | |
| 12 | +@Schema(description = "管理后台 - 学生分页 Request VO") | |
| 13 | +@Data | |
| 14 | +@EqualsAndHashCode(callSuper = true) | |
| 15 | +@ToString(callSuper = true) | |
| 16 | +public class InfraStudentPageReqVO extends PageParam { | |
| 17 | + | |
| 18 | + @Schema(description = "名字", example = "芋头") | |
| 19 | + private String name; | |
| 20 | + | |
| 21 | + @Schema(description = "出生日期") | |
| 22 | + private LocalDateTime birthday; | |
| 23 | + | |
| 24 | + @Schema(description = "性别", example = "1") | |
| 25 | + private Integer sex; | |
| 26 | + | |
| 27 | + @Schema(description = "是否有效", example = "true") | |
| 28 | + private Boolean enabled; | |
| 29 | + | |
| 30 | + @Schema(description = "创建时间") | |
| 31 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 32 | + private LocalDateTime[] createTime; | |
| 33 | + | |
| 34 | +} | |
| 0 | 35 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentRespVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import java.util.*; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | +import com.alibaba.excel.annotation.*; | |
| 10 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 11 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - 学生 Response VO") | |
| 14 | +@Data | |
| 15 | +@ExcelIgnoreUnannotated | |
| 16 | +public class InfraStudentRespVO { | |
| 17 | + | |
| 18 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 19 | + @ExcelProperty("编号") | |
| 20 | + private Long id; | |
| 21 | + | |
| 22 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 23 | + @ExcelProperty("名字") | |
| 24 | + private String name; | |
| 25 | + | |
| 26 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍") | |
| 27 | + @ExcelProperty("简介") | |
| 28 | + private String description; | |
| 29 | + | |
| 30 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 31 | + @ExcelProperty("出生日期") | |
| 32 | + private LocalDateTime birthday; | |
| 33 | + | |
| 34 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 35 | + @ExcelProperty(value = "性别", converter = DictConvert.class) | |
| 36 | + @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 37 | + private Integer sex; | |
| 38 | + | |
| 39 | + @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 40 | + @ExcelProperty(value = "是否有效", converter = DictConvert.class) | |
| 41 | + @DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 42 | + private Boolean enabled; | |
| 43 | + | |
| 44 | + @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 45 | + @ExcelProperty("头像") | |
| 46 | + private String avatar; | |
| 47 | + | |
| 48 | + @Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.mp4") | |
| 49 | + @ExcelProperty("附件") | |
| 50 | + private String video; | |
| 51 | + | |
| 52 | + @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注") | |
| 53 | + @ExcelProperty("备注") | |
| 54 | + private String memo; | |
| 55 | + | |
| 56 | + @Schema(description = "创建时间") | |
| 57 | + @ExcelProperty("创建时间") | |
| 58 | + private LocalDateTime createTime; | |
| 59 | + | |
| 60 | +} | |
| 0 | 61 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentSaveReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import javax.validation.constraints.*; | |
| 7 | +import java.util.*; | |
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | +import java.time.LocalDateTime; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 11 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - 学生新增/修改 Request VO") | |
| 14 | +@Data | |
| 15 | +public class InfraStudentSaveReqVO { | |
| 16 | + | |
| 17 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 18 | + private Long id; | |
| 19 | + | |
| 20 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 21 | + @NotEmpty(message = "名字不能为空") | |
| 22 | + private String name; | |
| 23 | + | |
| 24 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍") | |
| 25 | + @NotEmpty(message = "简介不能为空") | |
| 26 | + private String description; | |
| 27 | + | |
| 28 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 29 | + @NotNull(message = "出生日期不能为空") | |
| 30 | + private LocalDateTime birthday; | |
| 31 | + | |
| 32 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 33 | + @NotNull(message = "性别不能为空") | |
| 34 | + private Integer sex; | |
| 35 | + | |
| 36 | + @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 37 | + @NotNull(message = "是否有效不能为空") | |
| 38 | + private Boolean enabled; | |
| 39 | + | |
| 40 | + @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 41 | + @NotEmpty(message = "头像不能为空") | |
| 42 | + private String avatar; | |
| 43 | + | |
| 44 | + @Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.mp4") | |
| 45 | + @NotEmpty(message = "附件不能为空") | |
| 46 | + private String video; | |
| 47 | + | |
| 48 | + @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注") | |
| 49 | + @NotEmpty(message = "备注不能为空") | |
| 50 | + private String memo; | |
| 51 | + | |
| 52 | +} | |
| 0 | 53 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentService
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | +import javax.validation.*; | |
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 6 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 7 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 9 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 10 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生 Service 接口 | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +public interface InfraStudentService { | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * 创建学生 | |
| 21 | + * | |
| 22 | + * @param createReqVO 创建信息 | |
| 23 | + * @return 编号 | |
| 24 | + */ | |
| 25 | + Long createStudent(@Valid InfraStudentSaveReqVO createReqVO); | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * 更新学生 | |
| 29 | + * | |
| 30 | + * @param updateReqVO 更新信息 | |
| 31 | + */ | |
| 32 | + void updateStudent(@Valid InfraStudentSaveReqVO updateReqVO); | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * 删除学生 | |
| 36 | + * | |
| 37 | + * @param id 编号 | |
| 38 | + */ | |
| 39 | + void deleteStudent(Long id); | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 获得学生 | |
| 43 | + * | |
| 44 | + * @param id 编号 | |
| 45 | + * @return 学生 | |
| 46 | + */ | |
| 47 | + InfraStudentDO getStudent(Long id); | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * 获得学生分页 | |
| 51 | + * | |
| 52 | + * @param pageReqVO 分页查询 | |
| 53 | + * @return 学生分页 | |
| 54 | + */ | |
| 55 | + PageResult<InfraStudentDO> getStudentPage(InfraStudentPageReqVO pageReqVO); | |
| 56 | + | |
| 57 | + // ==================== 子表(学生联系人) ==================== | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * 获得学生联系人分页 | |
| 61 | + * | |
| 62 | + * @param pageReqVO 分页查询 | |
| 63 | + * @param studentId 学生编号 | |
| 64 | + * @return 学生联系人分页 | |
| 65 | + */ | |
| 66 | + PageResult<InfraStudentContactDO> getStudentContactPage(PageParam pageReqVO, Long studentId); | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * 创建学生联系人 | |
| 70 | + * | |
| 71 | + * @param studentContact 创建信息 | |
| 72 | + * @return 编号 | |
| 73 | + */ | |
| 74 | + Long createStudentContact(@Valid InfraStudentContactDO studentContact); | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * 更新学生联系人 | |
| 78 | + * | |
| 79 | + * @param studentContact 更新信息 | |
| 80 | + */ | |
| 81 | + void updateStudentContact(@Valid InfraStudentContactDO studentContact); | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * 删除学生联系人 | |
| 85 | + * | |
| 86 | + * @param id 编号 | |
| 87 | + */ | |
| 88 | + void deleteStudentContact(Long id); | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * 获得学生联系人 | |
| 92 | + * | |
| 93 | + * @param id 编号 | |
| 94 | + * @return 学生联系人 | |
| 95 | + */ | |
| 96 | + InfraStudentContactDO getStudentContact(Long id); | |
| 97 | + | |
| 98 | + // ==================== 子表(学生班主任) ==================== | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * 获得学生班主任分页 | |
| 102 | + * | |
| 103 | + * @param pageReqVO 分页查询 | |
| 104 | + * @param studentId 学生编号 | |
| 105 | + * @return 学生班主任分页 | |
| 106 | + */ | |
| 107 | + PageResult<InfraStudentTeacherDO> getStudentTeacherPage(PageParam pageReqVO, Long studentId); | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * 创建学生班主任 | |
| 111 | + * | |
| 112 | + * @param studentTeacher 创建信息 | |
| 113 | + * @return 编号 | |
| 114 | + */ | |
| 115 | + Long createStudentTeacher(@Valid InfraStudentTeacherDO studentTeacher); | |
| 116 | + | |
| 117 | + /** | |
| 118 | + * 更新学生班主任 | |
| 119 | + * | |
| 120 | + * @param studentTeacher 更新信息 | |
| 121 | + */ | |
| 122 | + void updateStudentTeacher(@Valid InfraStudentTeacherDO studentTeacher); | |
| 123 | + | |
| 124 | + /** | |
| 125 | + * 删除学生班主任 | |
| 126 | + * | |
| 127 | + * @param id 编号 | |
| 128 | + */ | |
| 129 | + void deleteStudentTeacher(Long id); | |
| 130 | + | |
| 131 | + /** | |
| 132 | + * 获得学生班主任 | |
| 133 | + * | |
| 134 | + * @param id 编号 | |
| 135 | + * @return 学生班主任 | |
| 136 | + */ | |
| 137 | + InfraStudentTeacherDO getStudentTeacher(Long id); | |
| 138 | + | |
| 139 | +} | |
| 0 | 140 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentServiceImpl
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import org.springframework.stereotype.Service; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.transaction.annotation.Transactional; | |
| 7 | + | |
| 8 | +import java.util.*; | |
| 9 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 11 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 13 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 15 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 16 | + | |
| 17 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper; | |
| 18 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentContactMapper; | |
| 19 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentTeacherMapper; | |
| 20 | + | |
| 21 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 22 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 23 | + | |
| 24 | +/** | |
| 25 | + * 学生 Service 实现类 | |
| 26 | + * | |
| 27 | + * @author 芋道源码 | |
| 28 | + */ | |
| 29 | +@Service | |
| 30 | +@Validated | |
| 31 | +public class InfraStudentServiceImpl implements InfraStudentService { | |
| 32 | + | |
| 33 | + @Resource | |
| 34 | + private InfraStudentMapper studentMapper; | |
| 35 | + @Resource | |
| 36 | + private InfraStudentContactMapper studentContactMapper; | |
| 37 | + @Resource | |
| 38 | + private InfraStudentTeacherMapper studentTeacherMapper; | |
| 39 | + | |
| 40 | + @Override | |
| 41 | + public Long createStudent(InfraStudentSaveReqVO createReqVO) { | |
| 42 | + // 插入 | |
| 43 | + InfraStudentDO student = BeanUtils.toBean(createReqVO, InfraStudentDO.class); | |
| 44 | + studentMapper.insert(student); | |
| 45 | + // 返回 | |
| 46 | + return student.getId(); | |
| 47 | + } | |
| 48 | + | |
| 49 | + @Override | |
| 50 | + public void updateStudent(InfraStudentSaveReqVO updateReqVO) { | |
| 51 | + // 校验存在 | |
| 52 | + validateStudentExists(updateReqVO.getId()); | |
| 53 | + // 更新 | |
| 54 | + InfraStudentDO updateObj = BeanUtils.toBean(updateReqVO, InfraStudentDO.class); | |
| 55 | + studentMapper.updateById(updateObj); | |
| 56 | + } | |
| 57 | + | |
| 58 | + @Override | |
| 59 | + @Transactional(rollbackFor = Exception.class) | |
| 60 | + public void deleteStudent(Long id) { | |
| 61 | + // 校验存在 | |
| 62 | + validateStudentExists(id); | |
| 63 | + // 删除 | |
| 64 | + studentMapper.deleteById(id); | |
| 65 | + | |
| 66 | + // 删除子表 | |
| 67 | + deleteStudentContactByStudentId(id); | |
| 68 | + deleteStudentTeacherByStudentId(id); | |
| 69 | + } | |
| 70 | + | |
| 71 | + private void validateStudentExists(Long id) { | |
| 72 | + if (studentMapper.selectById(id) == null) { | |
| 73 | + throw exception(STUDENT_NOT_EXISTS); | |
| 74 | + } | |
| 75 | + } | |
| 76 | + | |
| 77 | + @Override | |
| 78 | + public InfraStudentDO getStudent(Long id) { | |
| 79 | + return studentMapper.selectById(id); | |
| 80 | + } | |
| 81 | + | |
| 82 | + @Override | |
| 83 | + public PageResult<InfraStudentDO> getStudentPage(InfraStudentPageReqVO pageReqVO) { | |
| 84 | + return studentMapper.selectPage(pageReqVO); | |
| 85 | + } | |
| 86 | + | |
| 87 | + // ==================== 子表(学生联系人) ==================== | |
| 88 | + | |
| 89 | + @Override | |
| 90 | + public PageResult<InfraStudentContactDO> getStudentContactPage(PageParam pageReqVO, Long studentId) { | |
| 91 | + return studentContactMapper.selectPage(pageReqVO, studentId); | |
| 92 | + } | |
| 93 | + | |
| 94 | + @Override | |
| 95 | + public Long createStudentContact(InfraStudentContactDO studentContact) { | |
| 96 | + studentContactMapper.insert(studentContact); | |
| 97 | + return studentContact.getId(); | |
| 98 | + } | |
| 99 | + | |
| 100 | + @Override | |
| 101 | + public void updateStudentContact(InfraStudentContactDO studentContact) { | |
| 102 | + // 校验存在 | |
| 103 | + validateStudentContactExists(studentContact.getId()); | |
| 104 | + // 更新 | |
| 105 | + studentContactMapper.updateById(studentContact); | |
| 106 | + } | |
| 107 | + | |
| 108 | + @Override | |
| 109 | + public void deleteStudentContact(Long id) { | |
| 110 | + // 校验存在 | |
| 111 | + validateStudentContactExists(id); | |
| 112 | + // 删除 | |
| 113 | + studentContactMapper.deleteById(id); | |
| 114 | + } | |
| 115 | + | |
| 116 | + @Override | |
| 117 | + public InfraStudentContactDO getStudentContact(Long id) { | |
| 118 | + return studentContactMapper.selectById(id); | |
| 119 | + } | |
| 120 | + | |
| 121 | + private void validateStudentContactExists(Long id) { | |
| 122 | + if (studentContactMapper.selectById(id) == null) { | |
| 123 | + throw exception(STUDENT_CONTACT_NOT_EXISTS); | |
| 124 | + } | |
| 125 | + } | |
| 126 | + | |
| 127 | + private void deleteStudentContactByStudentId(Long studentId) { | |
| 128 | + studentContactMapper.deleteByStudentId(studentId); | |
| 129 | + } | |
| 130 | + | |
| 131 | + // ==================== 子表(学生班主任) ==================== | |
| 132 | + | |
| 133 | + @Override | |
| 134 | + public PageResult<InfraStudentTeacherDO> getStudentTeacherPage(PageParam pageReqVO, Long studentId) { | |
| 135 | + return studentTeacherMapper.selectPage(pageReqVO, studentId); | |
| 136 | + } | |
| 137 | + | |
| 138 | + @Override | |
| 139 | + public Long createStudentTeacher(InfraStudentTeacherDO studentTeacher) { | |
| 140 | + // 校验是否已经存在 | |
| 141 | + if (studentTeacherMapper.selectByStudentId(studentTeacher.getStudentId()) != null) { | |
| 142 | + throw exception(STUDENT_TEACHER_EXISTS); | |
| 143 | + } | |
| 144 | + // 插入 | |
| 145 | + studentTeacherMapper.insert(studentTeacher); | |
| 146 | + return studentTeacher.getId(); | |
| 147 | + } | |
| 148 | + | |
| 149 | + @Override | |
| 150 | + public void updateStudentTeacher(InfraStudentTeacherDO studentTeacher) { | |
| 151 | + // 校验存在 | |
| 152 | + validateStudentTeacherExists(studentTeacher.getId()); | |
| 153 | + // 更新 | |
| 154 | + studentTeacherMapper.updateById(studentTeacher); | |
| 155 | + } | |
| 156 | + | |
| 157 | + @Override | |
| 158 | + public void deleteStudentTeacher(Long id) { | |
| 159 | + // 校验存在 | |
| 160 | + validateStudentTeacherExists(id); | |
| 161 | + // 删除 | |
| 162 | + studentTeacherMapper.deleteById(id); | |
| 163 | + } | |
| 164 | + | |
| 165 | + @Override | |
| 166 | + public InfraStudentTeacherDO getStudentTeacher(Long id) { | |
| 167 | + return studentTeacherMapper.selectById(id); | |
| 168 | + } | |
| 169 | + | |
| 170 | + private void validateStudentTeacherExists(Long id) { | |
| 171 | + if (studentTeacherMapper.selectById(id) == null) { | |
| 172 | + throw exception(STUDENT_TEACHER_NOT_EXISTS); | |
| 173 | + } | |
| 174 | + } | |
| 175 | + | |
| 176 | + private void deleteStudentTeacherByStudentId(Long studentId) { | |
| 177 | + studentTeacherMapper.deleteByStudentId(studentId); | |
| 178 | + } | |
| 179 | + | |
| 180 | +} | |
| 0 | 181 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentServiceImplTest
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import org.junit.jupiter.api.Disabled; | |
| 4 | +import org.junit.jupiter.api.Test; | |
| 5 | +import org.springframework.boot.test.mock.mockito.MockBean; | |
| 6 | + | |
| 7 | +import javax.annotation.Resource; | |
| 8 | + | |
| 9 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | |
| 10 | + | |
| 11 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 13 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper; | |
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 15 | + | |
| 16 | +import javax.annotation.Resource; | |
| 17 | +import org.springframework.context.annotation.Import; | |
| 18 | +import java.util.*; | |
| 19 | +import java.time.LocalDateTime; | |
| 20 | + | |
| 21 | +import static cn.hutool.core.util.RandomUtil.*; | |
| 22 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 23 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; | |
| 24 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | |
| 25 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; | |
| 26 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; | |
| 27 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; | |
| 28 | +import static org.junit.jupiter.api.Assertions.*; | |
| 29 | +import static org.mockito.Mockito.*; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * {@link InfraStudentServiceImpl} 的单元测试类 | |
| 33 | + * | |
| 34 | + * @author 芋道源码 | |
| 35 | + */ | |
| 36 | +@Import(InfraStudentServiceImpl.class) | |
| 37 | +public class InfraStudentServiceImplTest extends BaseDbUnitTest { | |
| 38 | + | |
| 39 | + @Resource | |
| 40 | + private InfraStudentServiceImpl studentService; | |
| 41 | + | |
| 42 | + @Resource | |
| 43 | + private InfraStudentMapper studentMapper; | |
| 44 | + | |
| 45 | + @Test | |
| 46 | + public void testCreateStudent_success() { | |
| 47 | + // 准备参数 | |
| 48 | + InfraStudentSaveReqVO createReqVO = randomPojo(InfraStudentSaveReqVO.class).setId(null); | |
| 49 | + | |
| 50 | + // 调用 | |
| 51 | + Long studentId = studentService.createStudent(createReqVO); | |
| 52 | + // 断言 | |
| 53 | + assertNotNull(studentId); | |
| 54 | + // 校验记录的属性是否正确 | |
| 55 | + InfraStudentDO student = studentMapper.selectById(studentId); | |
| 56 | + assertPojoEquals(createReqVO, student, "id"); | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Test | |
| 60 | + public void testUpdateStudent_success() { | |
| 61 | + // mock 数据 | |
| 62 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class); | |
| 63 | + studentMapper.insert(dbStudent);// @Sql: 先插入出一条存在的数据 | |
| 64 | + // 准备参数 | |
| 65 | + InfraStudentSaveReqVO updateReqVO = randomPojo(InfraStudentSaveReqVO.class, o -> { | |
| 66 | + o.setId(dbStudent.getId()); // 设置更新的 ID | |
| 67 | + }); | |
| 68 | + | |
| 69 | + // 调用 | |
| 70 | + studentService.updateStudent(updateReqVO); | |
| 71 | + // 校验是否更新正确 | |
| 72 | + InfraStudentDO student = studentMapper.selectById(updateReqVO.getId()); // 获取最新的 | |
| 73 | + assertPojoEquals(updateReqVO, student); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Test | |
| 77 | + public void testUpdateStudent_notExists() { | |
| 78 | + // 准备参数 | |
| 79 | + InfraStudentSaveReqVO updateReqVO = randomPojo(InfraStudentSaveReqVO.class); | |
| 80 | + | |
| 81 | + // 调用, 并断言异常 | |
| 82 | + assertServiceException(() -> studentService.updateStudent(updateReqVO), STUDENT_NOT_EXISTS); | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Test | |
| 86 | + public void testDeleteStudent_success() { | |
| 87 | + // mock 数据 | |
| 88 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class); | |
| 89 | + studentMapper.insert(dbStudent);// @Sql: 先插入出一条存在的数据 | |
| 90 | + // 准备参数 | |
| 91 | + Long id = dbStudent.getId(); | |
| 92 | + | |
| 93 | + // 调用 | |
| 94 | + studentService.deleteStudent(id); | |
| 95 | + // 校验数据不存在了 | |
| 96 | + assertNull(studentMapper.selectById(id)); | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Test | |
| 100 | + public void testDeleteStudent_notExists() { | |
| 101 | + // 准备参数 | |
| 102 | + Long id = randomLongId(); | |
| 103 | + | |
| 104 | + // 调用, 并断言异常 | |
| 105 | + assertServiceException(() -> studentService.deleteStudent(id), STUDENT_NOT_EXISTS); | |
| 106 | + } | |
| 107 | + | |
| 108 | + @Test | |
| 109 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 110 | + public void testGetStudentPage() { | |
| 111 | + // mock 数据 | |
| 112 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class, o -> { // 等会查询到 | |
| 113 | + o.setName(null); | |
| 114 | + o.setBirthday(null); | |
| 115 | + o.setSex(null); | |
| 116 | + o.setEnabled(null); | |
| 117 | + o.setCreateTime(null); | |
| 118 | + }); | |
| 119 | + studentMapper.insert(dbStudent); | |
| 120 | + // 测试 name 不匹配 | |
| 121 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setName(null))); | |
| 122 | + // 测试 birthday 不匹配 | |
| 123 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setBirthday(null))); | |
| 124 | + // 测试 sex 不匹配 | |
| 125 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setSex(null))); | |
| 126 | + // 测试 enabled 不匹配 | |
| 127 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setEnabled(null))); | |
| 128 | + // 测试 createTime 不匹配 | |
| 129 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setCreateTime(null))); | |
| 130 | + // 准备参数 | |
| 131 | + InfraStudentPageReqVO reqVO = new InfraStudentPageReqVO(); | |
| 132 | + reqVO.setName(null); | |
| 133 | + reqVO.setBirthday(null); | |
| 134 | + reqVO.setSex(null); | |
| 135 | + reqVO.setEnabled(null); | |
| 136 | + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 137 | + | |
| 138 | + // 调用 | |
| 139 | + PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(reqVO); | |
| 140 | + // 断言 | |
| 141 | + assertEquals(1, pageResult.getTotal()); | |
| 142 | + assertEquals(1, pageResult.getList().size()); | |
| 143 | + assertPojoEquals(dbStudent, pageResult.getList().get(0)); | |
| 144 | + } | |
| 145 | + | |
| 146 | +} | |
| 0 | 147 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentTeacherDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生班主任 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student_teacher") | |
| 16 | +@KeySequence("infra_student_teacher_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentTeacherDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 学生编号 | |
| 32 | + */ | |
| 33 | + private Long studentId; | |
| 34 | + /** | |
| 35 | + * 名字 | |
| 36 | + */ | |
| 37 | + private String name; | |
| 38 | + /** | |
| 39 | + * 简介 | |
| 40 | + */ | |
| 41 | + private String description; | |
| 42 | + /** | |
| 43 | + * 出生日期 | |
| 44 | + */ | |
| 45 | + private LocalDateTime birthday; | |
| 46 | + /** | |
| 47 | + * 性别 | |
| 48 | + * | |
| 49 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 50 | + */ | |
| 51 | + private Integer sex; | |
| 52 | + /** | |
| 53 | + * 是否有效 | |
| 54 | + * | |
| 55 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 56 | + */ | |
| 57 | + private Boolean enabled; | |
| 58 | + /** | |
| 59 | + * 头像 | |
| 60 | + */ | |
| 61 | + private String avatar; | |
| 62 | + /** | |
| 63 | + * 附件 | |
| 64 | + */ | |
| 65 | + private String video; | |
| 66 | + /** | |
| 67 | + * 备注 | |
| 68 | + */ | |
| 69 | + private String memo; | |
| 70 | + | |
| 71 | +} | |
| 0 | 72 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentTeacherMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 9 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 10 | +import org.apache.ibatis.annotations.Mapper; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生班主任 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentTeacherMapper extends BaseMapperX<InfraStudentTeacherDO> { | |
| 19 | + | |
| 20 | + default PageResult<InfraStudentTeacherDO> selectPage(PageParam reqVO, Long studentId) { | |
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<InfraStudentTeacherDO>() | |
| 22 | + .eq(InfraStudentTeacherDO::getStudentId, studentId) | |
| 23 | + .orderByDesc(InfraStudentTeacherDO::getId)); | |
| 24 | + } | |
| 25 | + | |
| 26 | + default int deleteByStudentId(Long studentId) { | |
| 27 | + return delete(InfraStudentTeacherDO::getStudentId, studentId); | |
| 28 | + } | |
| 29 | + | |
| 30 | +} | |
| 0 | 31 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/js/student
0 → 100644
| 1 | +import request from '@/utils/request' | |
| 2 | + | |
| 3 | +// 创建学生 | |
| 4 | +export function createStudent(data) { | |
| 5 | + return request({ | |
| 6 | + url: '/infra/student/create', | |
| 7 | + method: 'post', | |
| 8 | + data: data | |
| 9 | + }) | |
| 10 | +} | |
| 11 | + | |
| 12 | +// 更新学生 | |
| 13 | +export function updateStudent(data) { | |
| 14 | + return request({ | |
| 15 | + url: '/infra/student/update', | |
| 16 | + method: 'put', | |
| 17 | + data: data | |
| 18 | + }) | |
| 19 | +} | |
| 20 | + | |
| 21 | +// 删除学生 | |
| 22 | +export function deleteStudent(id) { | |
| 23 | + return request({ | |
| 24 | + url: '/infra/student/delete?id=' + id, | |
| 25 | + method: 'delete' | |
| 26 | + }) | |
| 27 | +} | |
| 28 | + | |
| 29 | +// 获得学生 | |
| 30 | +export function getStudent(id) { | |
| 31 | + return request({ | |
| 32 | + url: '/infra/student/get?id=' + id, | |
| 33 | + method: 'get' | |
| 34 | + }) | |
| 35 | +} | |
| 36 | + | |
| 37 | +// 获得学生分页 | |
| 38 | +export function getStudentPage(params) { | |
| 39 | + return request({ | |
| 40 | + url: '/infra/student/page', | |
| 41 | + method: 'get', | |
| 42 | + params | |
| 43 | + }) | |
| 44 | +} | |
| 45 | +// 导出学生 Excel | |
| 46 | +export function exportStudentExcel(params) { | |
| 47 | + return request({ | |
| 48 | + url: '/infra/student/export-excel', | |
| 49 | + method: 'get', | |
| 50 | + params, | |
| 51 | + responseType: 'blob' | |
| 52 | + }) | |
| 53 | +} | |
| 54 | + | |
| 55 | +// ==================== 子表(学生联系人) ==================== | |
| 56 | + | |
| 57 | + // 获得学生联系人分页 | |
| 58 | + export function getStudentContactPage(params) { | |
| 59 | + return request({ | |
| 60 | + url: '/infra/student/student-contact/page', | |
| 61 | + method: 'get', | |
| 62 | + params | |
| 63 | + }) | |
| 64 | + } | |
| 65 | + // 新增学生联系人 | |
| 66 | + export function createStudentContact(data) { | |
| 67 | + return request({ | |
| 68 | + url: `/infra/student/student-contact/create`, | |
| 69 | + method: 'post', | |
| 70 | + data | |
| 71 | + }) | |
| 72 | + } | |
| 73 | + | |
| 74 | + // 修改学生联系人 | |
| 75 | + export function updateStudentContact(data) { | |
| 76 | + return request({ | |
| 77 | + url: `/infra/student/student-contact/update`, | |
| 78 | + method: 'post', | |
| 79 | + data | |
| 80 | + }) | |
| 81 | + } | |
| 82 | + | |
| 83 | + // 删除学生联系人 | |
| 84 | + export function deleteStudentContact(id) { | |
| 85 | + return request({ | |
| 86 | + url: `/infra/student/student-contact/delete?id=` + id, | |
| 87 | + method: 'delete' | |
| 88 | + }) | |
| 89 | + } | |
| 90 | + | |
| 91 | + // 获得学生联系人 | |
| 92 | + export function getStudentContact(id) { | |
| 93 | + return request({ | |
| 94 | + url: `/infra/student/student-contact/get?id=` + id, | |
| 95 | + method: 'get' | |
| 96 | + }) | |
| 97 | + } | |
| 98 | + | |
| 99 | +// ==================== 子表(学生班主任) ==================== | |
| 100 | + | |
| 101 | + // 获得学生班主任分页 | |
| 102 | + export function getStudentTeacherPage(params) { | |
| 103 | + return request({ | |
| 104 | + url: '/infra/student/student-teacher/page', | |
| 105 | + method: 'get', | |
| 106 | + params | |
| 107 | + }) | |
| 108 | + } | |
| 109 | + // 新增学生班主任 | |
| 110 | + export function createStudentTeacher(data) { | |
| 111 | + return request({ | |
| 112 | + url: `/infra/student/student-teacher/create`, | |
| 113 | + method: 'post', | |
| 114 | + data | |
| 115 | + }) | |
| 116 | + } | |
| 117 | + | |
| 118 | + // 修改学生班主任 | |
| 119 | + export function updateStudentTeacher(data) { | |
| 120 | + return request({ | |
| 121 | + url: `/infra/student/student-teacher/update`, | |
| 122 | + method: 'post', | |
| 123 | + data | |
| 124 | + }) | |
| 125 | + } | |
| 126 | + | |
| 127 | + // 删除学生班主任 | |
| 128 | + export function deleteStudentTeacher(id) { | |
| 129 | + return request({ | |
| 130 | + url: `/infra/student/student-teacher/delete?id=` + id, | |
| 131 | + method: 'delete' | |
| 132 | + }) | |
| 133 | + } | |
| 134 | + | |
| 135 | + // 获得学生班主任 | |
| 136 | + export function getStudentTeacher(id) { | |
| 137 | + return request({ | |
| 138 | + url: `/infra/student/student-teacher/get?id=` + id, | |
| 139 | + method: 'get' | |
| 140 | + }) | |
| 141 | + } | |
| 0 | 142 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/sql/h2
0 → 100644
| 1 | +-- 将该建表 SQL 语句,添加到 yudao-module-infra-biz 模块的 test/resources/sql/create_tables.sql 文件里 | |
| 2 | +CREATE TABLE IF NOT EXISTS "infra_student" ( | |
| 3 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 4 | + "name" varchar NOT NULL, | |
| 5 | + "description" varchar NOT NULL, | |
| 6 | + "birthday" varchar NOT NULL, | |
| 7 | + "sex" int NOT NULL, | |
| 8 | + "enabled" bit NOT NULL, | |
| 9 | + "avatar" varchar NOT NULL, | |
| 10 | + "video" varchar NOT NULL, | |
| 11 | + "memo" varchar NOT NULL, | |
| 12 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 13 | + PRIMARY KEY ("id") | |
| 14 | +) COMMENT '学生表'; | |
| 15 | + | |
| 16 | +-- 将该删表 SQL 语句,添加到 yudao-module-infra-biz 模块的 test/resources/sql/clean.sql 文件里 | |
| 17 | +DELETE FROM "infra_student"; | |
| 0 | 18 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/sql/sql
0 → 100644
| 1 | +-- 菜单 SQL | |
| 2 | +INSERT INTO system_menu( | |
| 3 | + name, permission, type, sort, parent_id, | |
| 4 | + path, icon, component, status, component_name | |
| 5 | +) | |
| 6 | +VALUES ( | |
| 7 | + '学生管理', '', 2, 0, 888, | |
| 8 | + 'student', '', 'infra/demo/index', 0, 'InfraStudent' | |
| 9 | +); | |
| 10 | + | |
| 11 | +-- 按钮父菜单ID | |
| 12 | +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 | |
| 13 | +SELECT @parentId := LAST_INSERT_ID(); | |
| 14 | + | |
| 15 | +-- 按钮 SQL | |
| 16 | +INSERT INTO system_menu( | |
| 17 | + name, permission, type, sort, parent_id, | |
| 18 | + path, icon, component, status | |
| 19 | +) | |
| 20 | +VALUES ( | |
| 21 | + '学生查询', 'infra:student:query', 3, 1, @parentId, | |
| 22 | + '', '', '', 0 | |
| 23 | +); | |
| 24 | +INSERT INTO system_menu( | |
| 25 | + name, permission, type, sort, parent_id, | |
| 26 | + path, icon, component, status | |
| 27 | +) | |
| 28 | +VALUES ( | |
| 29 | + '学生创建', 'infra:student:create', 3, 2, @parentId, | |
| 30 | + '', '', '', 0 | |
| 31 | +); | |
| 32 | +INSERT INTO system_menu( | |
| 33 | + name, permission, type, sort, parent_id, | |
| 34 | + path, icon, component, status | |
| 35 | +) | |
| 36 | +VALUES ( | |
| 37 | + '学生更新', 'infra:student:update', 3, 3, @parentId, | |
| 38 | + '', '', '', 0 | |
| 39 | +); | |
| 40 | +INSERT INTO system_menu( | |
| 41 | + name, permission, type, sort, parent_id, | |
| 42 | + path, icon, component, status | |
| 43 | +) | |
| 44 | +VALUES ( | |
| 45 | + '学生删除', 'infra:student:delete', 3, 4, @parentId, | |
| 46 | + '', '', '', 0 | |
| 47 | +); | |
| 48 | +INSERT INTO system_menu( | |
| 49 | + name, permission, type, sort, parent_id, | |
| 50 | + path, icon, component, status | |
| 51 | +) | |
| 52 | +VALUES ( | |
| 53 | + '学生导出', 'infra:student:export', 3, 5, @parentId, | |
| 54 | + '', '', '', 0 | |
| 55 | +); | |
| 0 | 56 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/vue/StudentContactForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 对话框(添加 / 修改) --> | |
| 4 | + <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body> | |
| 5 | + <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px"> | |
| 6 | + <el-form-item label="名字" prop="name"> | |
| 7 | + <el-input v-model="formData.name" placeholder="请输入名字" /> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="简介" prop="description"> | |
| 10 | + <el-input v-model="formData.description" type="textarea" placeholder="请输入内容" /> | |
| 11 | + </el-form-item> | |
| 12 | + <el-form-item label="出生日期" prop="birthday"> | |
| 13 | + <el-date-picker clearable v-model="formData.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 14 | + </el-form-item> | |
| 15 | + <el-form-item label="性别" prop="sex"> | |
| 16 | + <el-select v-model="formData.sex" placeholder="请选择性别"> | |
| 17 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 18 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 19 | + </el-select> | |
| 20 | + </el-form-item> | |
| 21 | + <el-form-item label="是否有效" prop="enabled"> | |
| 22 | + <el-radio-group v-model="formData.enabled"> | |
| 23 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 24 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 25 | + </el-radio-group> | |
| 26 | + </el-form-item> | |
| 27 | + <el-form-item label="头像" prop="avatar"> | |
| 28 | + <ImageUpload v-model="formData.avatar"/> | |
| 29 | + </el-form-item> | |
| 30 | + <el-form-item label="附件" prop="video"> | |
| 31 | + <FileUpload v-model="formData.video"/> | |
| 32 | + </el-form-item> | |
| 33 | + <el-form-item label="备注" prop="memo"> | |
| 34 | + <editor v-model="formData.memo" :min-height="192"/> | |
| 35 | + </el-form-item> | |
| 36 | + </el-form> | |
| 37 | + <div slot="footer" class="dialog-footer"> | |
| 38 | + <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button> | |
| 39 | + <el-button @click="dialogVisible = false">取 消</el-button> | |
| 40 | + </div> | |
| 41 | + </el-dialog> | |
| 42 | + </div> | |
| 43 | +</template> | |
| 44 | + | |
| 45 | +<script> | |
| 46 | + import * as StudentApi from '@/api/infra/demo' | |
| 47 | + import ImageUpload from '@/components/ImageUpload'; | |
| 48 | + import FileUpload from '@/components/FileUpload'; | |
| 49 | + import Editor from '@/components/Editor'; | |
| 50 | + export default { | |
| 51 | + name: "StudentContactForm", | |
| 52 | + components: { | |
| 53 | + ImageUpload, | |
| 54 | + FileUpload, | |
| 55 | + Editor, | |
| 56 | + }, | |
| 57 | + data() { | |
| 58 | + return { | |
| 59 | + // 弹出层标题 | |
| 60 | + dialogTitle: "", | |
| 61 | + // 是否显示弹出层 | |
| 62 | + dialogVisible: false, | |
| 63 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 64 | + formLoading: false, | |
| 65 | + // 表单参数 | |
| 66 | + formData: { | |
| 67 | + id: undefined, | |
| 68 | + studentId: undefined, | |
| 69 | + name: undefined, | |
| 70 | + description: undefined, | |
| 71 | + birthday: undefined, | |
| 72 | + sex: undefined, | |
| 73 | + enabled: undefined, | |
| 74 | + avatar: undefined, | |
| 75 | + video: undefined, | |
| 76 | + memo: undefined, | |
| 77 | + }, | |
| 78 | + // 表单校验 | |
| 79 | + formRules: { | |
| 80 | + studentId: [{ required: true, message: "学生编号不能为空", trigger: "blur" }], | |
| 81 | + name: [{ required: true, message: "名字不能为空", trigger: "blur" }], | |
| 82 | + description: [{ required: true, message: "简介不能为空", trigger: "blur" }], | |
| 83 | + birthday: [{ required: true, message: "出生日期不能为空", trigger: "blur" }], | |
| 84 | + sex: [{ required: true, message: "性别不能为空", trigger: "change" }], | |
| 85 | + enabled: [{ required: true, message: "是否有效不能为空", trigger: "blur" }], | |
| 86 | + avatar: [{ required: true, message: "头像不能为空", trigger: "blur" }], | |
| 87 | + memo: [{ required: true, message: "备注不能为空", trigger: "blur" }], | |
| 88 | + }, | |
| 89 | + }; | |
| 90 | + }, | |
| 91 | + methods: { | |
| 92 | + /** 打开弹窗 */ | |
| 93 | + open(id, studentId) { | |
| 94 | + this.dialogVisible = true; | |
| 95 | + this.reset(); | |
| 96 | + const that = this; | |
| 97 | + this.formData.studentId = studentId; | |
| 98 | + // 修改时,设置数据 | |
| 99 | + if (id) { | |
| 100 | + this.formLoading = true; | |
| 101 | + try { | |
| 102 | + StudentApi.getStudentContact(id).then(res=>{ | |
| 103 | + that.formData = res.data; | |
| 104 | + that.dialogTitle = "修改学生联系人"; | |
| 105 | + }) | |
| 106 | + } finally { | |
| 107 | + this.formLoading = false; | |
| 108 | + } | |
| 109 | + } | |
| 110 | + this.dialogTitle = "新增学生联系人"; | |
| 111 | + }, | |
| 112 | + /** 提交按钮 */ | |
| 113 | + submitForm() { | |
| 114 | + this.formLoading = true; | |
| 115 | + try { | |
| 116 | + let data = this.formData; | |
| 117 | + this.$refs["formRef"].validate(valid => { | |
| 118 | + if (!valid) { | |
| 119 | + return; | |
| 120 | + } | |
| 121 | + // 修改的提交 | |
| 122 | + if (data.id) { | |
| 123 | + StudentApi.updateStudentContact(data).then(response => { | |
| 124 | + this.$modal.msgSuccess("修改成功"); | |
| 125 | + this.dialogVisible = false; | |
| 126 | + this.$emit('success'); | |
| 127 | + }); | |
| 128 | + return; | |
| 129 | + } | |
| 130 | + // 添加的提交 | |
| 131 | + StudentApi.createStudentContact(data).then(response => { | |
| 132 | + this.$modal.msgSuccess("新增成功"); | |
| 133 | + this.dialogVisible = false; | |
| 134 | + this.$emit('success'); | |
| 135 | + }); | |
| 136 | + }); | |
| 137 | + }finally { | |
| 138 | + this.formLoading = false | |
| 139 | + } | |
| 140 | + }, | |
| 141 | + /** 表单重置 */ | |
| 142 | + reset() { | |
| 143 | + this.formData = { | |
| 144 | + id: undefined, | |
| 145 | + studentId: undefined, | |
| 146 | + name: undefined, | |
| 147 | + description: undefined, | |
| 148 | + birthday: undefined, | |
| 149 | + sex: undefined, | |
| 150 | + enabled: undefined, | |
| 151 | + avatar: undefined, | |
| 152 | + video: undefined, | |
| 153 | + memo: undefined, | |
| 154 | + }; | |
| 155 | + this.resetForm("formRef"); | |
| 156 | + }, | |
| 157 | + } | |
| 158 | + }; | |
| 159 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/vue/StudentContactList
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 操作工具栏 --> | |
| 4 | + <el-row :gutter="10" class="mb8"> | |
| 5 | + <el-col :span="1.5"> | |
| 6 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)" | |
| 7 | + v-hasPermi="['infra:student:create']">新增</el-button> | |
| 8 | + </el-col> | |
| 9 | + </el-row> | |
| 10 | + <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | |
| 11 | + <el-table-column label="编号" align="center" prop="id" /> | |
| 12 | + <el-table-column label="名字" align="center" prop="name" /> | |
| 13 | + <el-table-column label="简介" align="center" prop="description" /> | |
| 14 | + <el-table-column label="出生日期" align="center" prop="birthday" width="180"> | |
| 15 | + <template v-slot="scope"> | |
| 16 | + <span>{{ parseTime(scope.row.birthday) }}</span> | |
| 17 | + </template> | |
| 18 | + </el-table-column> | |
| 19 | + <el-table-column label="性别" align="center" prop="sex"> | |
| 20 | + <template v-slot="scope"> | |
| 21 | + <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" /> | |
| 22 | + </template> | |
| 23 | + </el-table-column> | |
| 24 | + <el-table-column label="是否有效" align="center" prop="enabled"> | |
| 25 | + <template v-slot="scope"> | |
| 26 | + <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" /> | |
| 27 | + </template> | |
| 28 | + </el-table-column> | |
| 29 | + <el-table-column label="头像" align="center" prop="avatar" /> | |
| 30 | + <el-table-column label="附件" align="center" prop="video" /> | |
| 31 | + <el-table-column label="备注" align="center" prop="memo" /> | |
| 32 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 33 | + <template v-slot="scope"> | |
| 34 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 35 | + </template> | |
| 36 | + </el-table-column> | |
| 37 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 38 | + <template v-slot="scope"> | |
| 39 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)" | |
| 40 | + v-hasPermi="['infra:student:update']">修改</el-button> | |
| 41 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 42 | + v-hasPermi="['infra:student:delete']">删除</el-button> | |
| 43 | + </template> | |
| 44 | + </el-table-column> | |
| 45 | + </el-table> | |
| 46 | + <!-- 分页组件 --> | |
| 47 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | |
| 48 | + @pagination="getList"/> | |
| 49 | + <!-- 对话框(添加 / 修改) --> | |
| 50 | + <StudentContactForm ref="formRef" @success="getList" /> | |
| 51 | + </div> | |
| 52 | +</template> | |
| 53 | + | |
| 54 | +<script> | |
| 55 | + import * as StudentApi from '@/api/infra/demo' | |
| 56 | + import StudentContactForm from './StudentContactForm.vue' | |
| 57 | + export default { | |
| 58 | + name: "StudentContactList", | |
| 59 | + components: { | |
| 60 | + StudentContactForm | |
| 61 | + }, | |
| 62 | + props:[ | |
| 63 | + 'studentId' | |
| 64 | + ],// 学生编号(主表的关联字段) | |
| 65 | + data() { | |
| 66 | + return { | |
| 67 | + // 遮罩层 | |
| 68 | + loading: true, | |
| 69 | + // 列表的数据 | |
| 70 | + list: [], | |
| 71 | + // 列表的总页数 | |
| 72 | + total: 0, | |
| 73 | + // 查询参数 | |
| 74 | + queryParams: { | |
| 75 | + pageNo: 1, | |
| 76 | + pageSize: 10, | |
| 77 | + studentId: undefined | |
| 78 | + } | |
| 79 | + }; | |
| 80 | + }, | |
| 81 | + watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 82 | + studentId:{ | |
| 83 | + handler(val) { | |
| 84 | + this.queryParams.studentId = val; | |
| 85 | + if (val){ | |
| 86 | + this.handleQuery(); | |
| 87 | + } | |
| 88 | + }, | |
| 89 | + immediate: true | |
| 90 | + } | |
| 91 | + }, | |
| 92 | + methods: { | |
| 93 | + /** 查询列表 */ | |
| 94 | + getList() { | |
| 95 | + try { | |
| 96 | + this.loading = true; | |
| 97 | + const that = this; | |
| 98 | + StudentApi.getStudentContactPage(this.queryParams).then(response => { | |
| 99 | + that.list = response.data.list; | |
| 100 | + that.total = response.data.total; | |
| 101 | + }); | |
| 102 | + } finally { | |
| 103 | + this.loading = false; | |
| 104 | + } | |
| 105 | + }, | |
| 106 | + /** 搜索按钮操作 */ | |
| 107 | + handleQuery() { | |
| 108 | + this.queryParams.pageNo = 1; | |
| 109 | + this.getList(); | |
| 110 | + }, | |
| 111 | + /** 添加/修改操作 */ | |
| 112 | + openForm(id) { | |
| 113 | + if (!this.studentId) { | |
| 114 | + that.$modal.msgError('请选择一个学生'); | |
| 115 | + return; | |
| 116 | + } | |
| 117 | + this.$refs["formRef"].open(id, this.studentId); | |
| 118 | + }, | |
| 119 | + /** 删除按钮操作 */ | |
| 120 | + handleDelete(row) { | |
| 121 | + const that = this; | |
| 122 | + try { | |
| 123 | + const id = row.id; | |
| 124 | + this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?').then(()=>{ | |
| 125 | + return StudentApi.deleteStudentContact(id); | |
| 126 | + }).then(() => { | |
| 127 | + that.getList(); | |
| 128 | + that.$modal.msgSuccess("删除成功"); | |
| 129 | + }).catch(() => {}); | |
| 130 | + } catch {} | |
| 131 | + }, | |
| 132 | + } | |
| 133 | + }; | |
| 134 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/vue/StudentForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 对话框(添加 / 修改) --> | |
| 4 | + <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body> | |
| 5 | + <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px"> | |
| 6 | + <el-form-item label="名字" prop="name"> | |
| 7 | + <el-input v-model="formData.name" placeholder="请输入名字" /> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="简介" prop="description"> | |
| 10 | + <el-input v-model="formData.description" type="textarea" placeholder="请输入内容" /> | |
| 11 | + </el-form-item> | |
| 12 | + <el-form-item label="出生日期" prop="birthday"> | |
| 13 | + <el-date-picker clearable v-model="formData.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 14 | + </el-form-item> | |
| 15 | + <el-form-item label="性别" prop="sex"> | |
| 16 | + <el-select v-model="formData.sex" placeholder="请选择性别"> | |
| 17 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 18 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 19 | + </el-select> | |
| 20 | + </el-form-item> | |
| 21 | + <el-form-item label="是否有效" prop="enabled"> | |
| 22 | + <el-radio-group v-model="formData.enabled"> | |
| 23 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 24 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 25 | + </el-radio-group> | |
| 26 | + </el-form-item> | |
| 27 | + <el-form-item label="头像"> | |
| 28 | + <ImageUpload v-model="formData.avatar"/> | |
| 29 | + </el-form-item> | |
| 30 | + <el-form-item label="附件"> | |
| 31 | + <FileUpload v-model="formData.video"/> | |
| 32 | + </el-form-item> | |
| 33 | + <el-form-item label="备注"> | |
| 34 | + <Editor v-model="formData.memo" :min-height="192"/> | |
| 35 | + </el-form-item> | |
| 36 | + </el-form> | |
| 37 | + <div slot="footer" class="dialog-footer"> | |
| 38 | + <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button> | |
| 39 | + <el-button @click="dialogVisible = false">取 消</el-button> | |
| 40 | + </div> | |
| 41 | + </el-dialog> | |
| 42 | + </div> | |
| 43 | +</template> | |
| 44 | + | |
| 45 | +<script> | |
| 46 | + import * as StudentApi from '@/api/infra/demo' | |
| 47 | + import ImageUpload from '@/components/ImageUpload'; | |
| 48 | + import FileUpload from '@/components/FileUpload'; | |
| 49 | + import Editor from '@/components/Editor'; | |
| 50 | + export default { | |
| 51 | + name: "StudentForm", | |
| 52 | + components: { | |
| 53 | + ImageUpload, | |
| 54 | + FileUpload, | |
| 55 | + Editor, | |
| 56 | + }, | |
| 57 | + data() { | |
| 58 | + return { | |
| 59 | + // 弹出层标题 | |
| 60 | + dialogTitle: "", | |
| 61 | + // 是否显示弹出层 | |
| 62 | + dialogVisible: false, | |
| 63 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 64 | + formLoading: false, | |
| 65 | + // 表单参数 | |
| 66 | + formData: { | |
| 67 | + id: undefined, | |
| 68 | + name: undefined, | |
| 69 | + description: undefined, | |
| 70 | + birthday: undefined, | |
| 71 | + sex: undefined, | |
| 72 | + enabled: undefined, | |
| 73 | + avatar: undefined, | |
| 74 | + video: undefined, | |
| 75 | + memo: undefined, | |
| 76 | + }, | |
| 77 | + // 表单校验 | |
| 78 | + formRules: { | |
| 79 | + name: [{ required: true, message: '名字不能为空', trigger: 'blur' }], | |
| 80 | + description: [{ required: true, message: '简介不能为空', trigger: 'blur' }], | |
| 81 | + birthday: [{ required: true, message: '出生日期不能为空', trigger: 'blur' }], | |
| 82 | + sex: [{ required: true, message: '性别不能为空', trigger: 'change' }], | |
| 83 | + enabled: [{ required: true, message: '是否有效不能为空', trigger: 'blur' }], | |
| 84 | + avatar: [{ required: true, message: '头像不能为空', trigger: 'blur' }], | |
| 85 | + video: [{ required: true, message: '附件不能为空', trigger: 'blur' }], | |
| 86 | + memo: [{ required: true, message: '备注不能为空', trigger: 'blur' }], | |
| 87 | + }, | |
| 88 | + }; | |
| 89 | + }, | |
| 90 | + methods: { | |
| 91 | + /** 打开弹窗 */ | |
| 92 | + open(id) { | |
| 93 | + this.dialogVisible = true; | |
| 94 | + this.reset(); | |
| 95 | + const that = this; | |
| 96 | + // 修改时,设置数据 | |
| 97 | + if (id) { | |
| 98 | + this.formLoading = true; | |
| 99 | + try { | |
| 100 | + StudentApi.getStudent(id).then(res=>{ | |
| 101 | + that.formData = res.data; | |
| 102 | + that.title = "修改学生"; | |
| 103 | + }) | |
| 104 | + } finally { | |
| 105 | + this.formLoading = false; | |
| 106 | + } | |
| 107 | + } | |
| 108 | + this.title = "新增学生"; | |
| 109 | + }, | |
| 110 | + /** 提交按钮 */ | |
| 111 | + submitForm() { | |
| 112 | + this.formLoading = true; | |
| 113 | + try { | |
| 114 | + const that = this; | |
| 115 | + let data = this.formData; | |
| 116 | + let validate = false; | |
| 117 | + // 校验主表 | |
| 118 | + this.getRef("formRef").validate(valid => { | |
| 119 | + validate = valid; | |
| 120 | + }); | |
| 121 | + // 所有表单校验通过后方可提交 | |
| 122 | + if (!validate) { | |
| 123 | + return; | |
| 124 | + } | |
| 125 | + // 修改的提交 | |
| 126 | + if (data.id) { | |
| 127 | + StudentApi.updateStudent(data).then(response => { | |
| 128 | + that.$modal.msgSuccess("修改成功"); | |
| 129 | + that.dialogVisible = false; | |
| 130 | + that.$emit('success'); | |
| 131 | + }); | |
| 132 | + return; | |
| 133 | + } | |
| 134 | + // 添加的提交 | |
| 135 | + StudentApi.createStudent(data).then(response => { | |
| 136 | + that.$modal.msgSuccess("新增成功"); | |
| 137 | + that.dialogVisible = false; | |
| 138 | + that.$emit('success'); | |
| 139 | + }); | |
| 140 | + }finally { | |
| 141 | + this.formLoading = false; | |
| 142 | + } | |
| 143 | + }, | |
| 144 | + getRef(refName){ | |
| 145 | + return this.$refs[refName]; | |
| 146 | + }, | |
| 147 | + /** 表单重置 */ | |
| 148 | + reset() { | |
| 149 | + this.formData = { | |
| 150 | + id: undefined, | |
| 151 | + name: undefined, | |
| 152 | + description: undefined, | |
| 153 | + birthday: undefined, | |
| 154 | + sex: undefined, | |
| 155 | + enabled: undefined, | |
| 156 | + avatar: undefined, | |
| 157 | + video: undefined, | |
| 158 | + memo: undefined, | |
| 159 | + }; | |
| 160 | + this.resetForm("formRef"); | |
| 161 | + }, | |
| 162 | + } | |
| 163 | + }; | |
| 164 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/vue/StudentTeacherForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 对话框(添加 / 修改) --> | |
| 4 | + <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body> | |
| 5 | + <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px"> | |
| 6 | + <el-form-item label="名字" prop="name"> | |
| 7 | + <el-input v-model="formData.name" placeholder="请输入名字" /> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="简介" prop="description"> | |
| 10 | + <el-input v-model="formData.description" type="textarea" placeholder="请输入内容" /> | |
| 11 | + </el-form-item> | |
| 12 | + <el-form-item label="出生日期" prop="birthday"> | |
| 13 | + <el-date-picker clearable v-model="formData.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 14 | + </el-form-item> | |
| 15 | + <el-form-item label="性别" prop="sex"> | |
| 16 | + <el-select v-model="formData.sex" placeholder="请选择性别"> | |
| 17 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 18 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 19 | + </el-select> | |
| 20 | + </el-form-item> | |
| 21 | + <el-form-item label="是否有效" prop="enabled"> | |
| 22 | + <el-radio-group v-model="formData.enabled"> | |
| 23 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 24 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 25 | + </el-radio-group> | |
| 26 | + </el-form-item> | |
| 27 | + <el-form-item label="头像" prop="avatar"> | |
| 28 | + <ImageUpload v-model="formData.avatar"/> | |
| 29 | + </el-form-item> | |
| 30 | + <el-form-item label="附件" prop="video"> | |
| 31 | + <FileUpload v-model="formData.video"/> | |
| 32 | + </el-form-item> | |
| 33 | + <el-form-item label="备注" prop="memo"> | |
| 34 | + <editor v-model="formData.memo" :min-height="192"/> | |
| 35 | + </el-form-item> | |
| 36 | + </el-form> | |
| 37 | + <div slot="footer" class="dialog-footer"> | |
| 38 | + <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button> | |
| 39 | + <el-button @click="dialogVisible = false">取 消</el-button> | |
| 40 | + </div> | |
| 41 | + </el-dialog> | |
| 42 | + </div> | |
| 43 | +</template> | |
| 44 | + | |
| 45 | +<script> | |
| 46 | + import * as StudentApi from '@/api/infra/demo' | |
| 47 | + import ImageUpload from '@/components/ImageUpload'; | |
| 48 | + import FileUpload from '@/components/FileUpload'; | |
| 49 | + import Editor from '@/components/Editor'; | |
| 50 | + export default { | |
| 51 | + name: "StudentTeacherForm", | |
| 52 | + components: { | |
| 53 | + ImageUpload, | |
| 54 | + FileUpload, | |
| 55 | + Editor, | |
| 56 | + }, | |
| 57 | + data() { | |
| 58 | + return { | |
| 59 | + // 弹出层标题 | |
| 60 | + dialogTitle: "", | |
| 61 | + // 是否显示弹出层 | |
| 62 | + dialogVisible: false, | |
| 63 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 64 | + formLoading: false, | |
| 65 | + // 表单参数 | |
| 66 | + formData: { | |
| 67 | + id: undefined, | |
| 68 | + studentId: undefined, | |
| 69 | + name: undefined, | |
| 70 | + description: undefined, | |
| 71 | + birthday: undefined, | |
| 72 | + sex: undefined, | |
| 73 | + enabled: undefined, | |
| 74 | + avatar: undefined, | |
| 75 | + video: undefined, | |
| 76 | + memo: undefined, | |
| 77 | + }, | |
| 78 | + // 表单校验 | |
| 79 | + formRules: { | |
| 80 | + studentId: [{ required: true, message: "学生编号不能为空", trigger: "blur" }], | |
| 81 | + name: [{ required: true, message: "名字不能为空", trigger: "blur" }], | |
| 82 | + description: [{ required: true, message: "简介不能为空", trigger: "blur" }], | |
| 83 | + birthday: [{ required: true, message: "出生日期不能为空", trigger: "blur" }], | |
| 84 | + sex: [{ required: true, message: "性别不能为空", trigger: "change" }], | |
| 85 | + enabled: [{ required: true, message: "是否有效不能为空", trigger: "blur" }], | |
| 86 | + avatar: [{ required: true, message: "头像不能为空", trigger: "blur" }], | |
| 87 | + memo: [{ required: true, message: "备注不能为空", trigger: "blur" }], | |
| 88 | + }, | |
| 89 | + }; | |
| 90 | + }, | |
| 91 | + methods: { | |
| 92 | + /** 打开弹窗 */ | |
| 93 | + open(id, studentId) { | |
| 94 | + this.dialogVisible = true; | |
| 95 | + this.reset(); | |
| 96 | + const that = this; | |
| 97 | + this.formData.studentId = studentId; | |
| 98 | + // 修改时,设置数据 | |
| 99 | + if (id) { | |
| 100 | + this.formLoading = true; | |
| 101 | + try { | |
| 102 | + StudentApi.getStudentTeacher(id).then(res=>{ | |
| 103 | + that.formData = res.data; | |
| 104 | + that.dialogTitle = "修改学生班主任"; | |
| 105 | + }) | |
| 106 | + } finally { | |
| 107 | + this.formLoading = false; | |
| 108 | + } | |
| 109 | + } | |
| 110 | + this.dialogTitle = "新增学生班主任"; | |
| 111 | + }, | |
| 112 | + /** 提交按钮 */ | |
| 113 | + submitForm() { | |
| 114 | + this.formLoading = true; | |
| 115 | + try { | |
| 116 | + let data = this.formData; | |
| 117 | + this.$refs["formRef"].validate(valid => { | |
| 118 | + if (!valid) { | |
| 119 | + return; | |
| 120 | + } | |
| 121 | + // 修改的提交 | |
| 122 | + if (data.id) { | |
| 123 | + StudentApi.updateStudentTeacher(data).then(response => { | |
| 124 | + this.$modal.msgSuccess("修改成功"); | |
| 125 | + this.dialogVisible = false; | |
| 126 | + this.$emit('success'); | |
| 127 | + }); | |
| 128 | + return; | |
| 129 | + } | |
| 130 | + // 添加的提交 | |
| 131 | + StudentApi.createStudentTeacher(data).then(response => { | |
| 132 | + this.$modal.msgSuccess("新增成功"); | |
| 133 | + this.dialogVisible = false; | |
| 134 | + this.$emit('success'); | |
| 135 | + }); | |
| 136 | + }); | |
| 137 | + }finally { | |
| 138 | + this.formLoading = false | |
| 139 | + } | |
| 140 | + }, | |
| 141 | + /** 表单重置 */ | |
| 142 | + reset() { | |
| 143 | + this.formData = { | |
| 144 | + id: undefined, | |
| 145 | + studentId: undefined, | |
| 146 | + name: undefined, | |
| 147 | + description: undefined, | |
| 148 | + birthday: undefined, | |
| 149 | + sex: undefined, | |
| 150 | + enabled: undefined, | |
| 151 | + avatar: undefined, | |
| 152 | + video: undefined, | |
| 153 | + memo: undefined, | |
| 154 | + }; | |
| 155 | + this.resetForm("formRef"); | |
| 156 | + }, | |
| 157 | + } | |
| 158 | + }; | |
| 159 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/vue/StudentTeacherList
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 操作工具栏 --> | |
| 4 | + <el-row :gutter="10" class="mb8"> | |
| 5 | + <el-col :span="1.5"> | |
| 6 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)" | |
| 7 | + v-hasPermi="['infra:student:create']">新增</el-button> | |
| 8 | + </el-col> | |
| 9 | + </el-row> | |
| 10 | + <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | |
| 11 | + <el-table-column label="编号" align="center" prop="id" /> | |
| 12 | + <el-table-column label="名字" align="center" prop="name" /> | |
| 13 | + <el-table-column label="简介" align="center" prop="description" /> | |
| 14 | + <el-table-column label="出生日期" align="center" prop="birthday" width="180"> | |
| 15 | + <template v-slot="scope"> | |
| 16 | + <span>{{ parseTime(scope.row.birthday) }}</span> | |
| 17 | + </template> | |
| 18 | + </el-table-column> | |
| 19 | + <el-table-column label="性别" align="center" prop="sex"> | |
| 20 | + <template v-slot="scope"> | |
| 21 | + <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" /> | |
| 22 | + </template> | |
| 23 | + </el-table-column> | |
| 24 | + <el-table-column label="是否有效" align="center" prop="enabled"> | |
| 25 | + <template v-slot="scope"> | |
| 26 | + <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" /> | |
| 27 | + </template> | |
| 28 | + </el-table-column> | |
| 29 | + <el-table-column label="头像" align="center" prop="avatar" /> | |
| 30 | + <el-table-column label="附件" align="center" prop="video" /> | |
| 31 | + <el-table-column label="备注" align="center" prop="memo" /> | |
| 32 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 33 | + <template v-slot="scope"> | |
| 34 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 35 | + </template> | |
| 36 | + </el-table-column> | |
| 37 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 38 | + <template v-slot="scope"> | |
| 39 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)" | |
| 40 | + v-hasPermi="['infra:student:update']">修改</el-button> | |
| 41 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 42 | + v-hasPermi="['infra:student:delete']">删除</el-button> | |
| 43 | + </template> | |
| 44 | + </el-table-column> | |
| 45 | + </el-table> | |
| 46 | + <!-- 分页组件 --> | |
| 47 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | |
| 48 | + @pagination="getList"/> | |
| 49 | + <!-- 对话框(添加 / 修改) --> | |
| 50 | + <StudentTeacherForm ref="formRef" @success="getList" /> | |
| 51 | + </div> | |
| 52 | +</template> | |
| 53 | + | |
| 54 | +<script> | |
| 55 | + import * as StudentApi from '@/api/infra/demo' | |
| 56 | + import StudentTeacherForm from './StudentTeacherForm.vue' | |
| 57 | + export default { | |
| 58 | + name: "StudentTeacherList", | |
| 59 | + components: { | |
| 60 | + StudentTeacherForm | |
| 61 | + }, | |
| 62 | + props:[ | |
| 63 | + 'studentId' | |
| 64 | + ],// 学生编号(主表的关联字段) | |
| 65 | + data() { | |
| 66 | + return { | |
| 67 | + // 遮罩层 | |
| 68 | + loading: true, | |
| 69 | + // 列表的数据 | |
| 70 | + list: [], | |
| 71 | + // 列表的总页数 | |
| 72 | + total: 0, | |
| 73 | + // 查询参数 | |
| 74 | + queryParams: { | |
| 75 | + pageNo: 1, | |
| 76 | + pageSize: 10, | |
| 77 | + studentId: undefined | |
| 78 | + } | |
| 79 | + }; | |
| 80 | + }, | |
| 81 | + watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 82 | + studentId:{ | |
| 83 | + handler(val) { | |
| 84 | + this.queryParams.studentId = val; | |
| 85 | + if (val){ | |
| 86 | + this.handleQuery(); | |
| 87 | + } | |
| 88 | + }, | |
| 89 | + immediate: true | |
| 90 | + } | |
| 91 | + }, | |
| 92 | + methods: { | |
| 93 | + /** 查询列表 */ | |
| 94 | + getList() { | |
| 95 | + try { | |
| 96 | + this.loading = true; | |
| 97 | + const that = this; | |
| 98 | + StudentApi.getStudentTeacherPage(this.queryParams).then(response => { | |
| 99 | + that.list = response.data.list; | |
| 100 | + that.total = response.data.total; | |
| 101 | + }); | |
| 102 | + } finally { | |
| 103 | + this.loading = false; | |
| 104 | + } | |
| 105 | + }, | |
| 106 | + /** 搜索按钮操作 */ | |
| 107 | + handleQuery() { | |
| 108 | + this.queryParams.pageNo = 1; | |
| 109 | + this.getList(); | |
| 110 | + }, | |
| 111 | + /** 添加/修改操作 */ | |
| 112 | + openForm(id) { | |
| 113 | + if (!this.studentId) { | |
| 114 | + that.$modal.msgError('请选择一个学生'); | |
| 115 | + return; | |
| 116 | + } | |
| 117 | + this.$refs["formRef"].open(id, this.studentId); | |
| 118 | + }, | |
| 119 | + /** 删除按钮操作 */ | |
| 120 | + handleDelete(row) { | |
| 121 | + const that = this; | |
| 122 | + try { | |
| 123 | + const id = row.id; | |
| 124 | + this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?').then(()=>{ | |
| 125 | + return StudentApi.deleteStudentTeacher(id); | |
| 126 | + }).then(() => { | |
| 127 | + that.getList(); | |
| 128 | + that.$modal.msgSuccess("删除成功"); | |
| 129 | + }).catch(() => {}); | |
| 130 | + } catch {} | |
| 131 | + }, | |
| 132 | + } | |
| 133 | + }; | |
| 134 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/vue/index
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + | |
| 4 | + <!-- 搜索工作栏 --> | |
| 5 | + <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> | |
| 6 | + <el-form-item label="名字" prop="name"> | |
| 7 | + <el-input v-model="queryParams.name" placeholder="请输入名字" clearable @keyup.enter.native="handleQuery"/> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="出生日期" prop="birthday"> | |
| 10 | + <el-date-picker clearable v-model="queryParams.birthday" type="date" value-format="yyyy-MM-dd" placeholder="选择出生日期" /> | |
| 11 | + </el-form-item> | |
| 12 | + <el-form-item label="性别" prop="sex"> | |
| 13 | + <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable size="small"> | |
| 14 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 15 | + :key="dict.value" :label="dict.label" :value="dict.value"/> | |
| 16 | + </el-select> | |
| 17 | + </el-form-item> | |
| 18 | + <el-form-item label="是否有效" prop="enabled"> | |
| 19 | + <el-select v-model="queryParams.enabled" placeholder="请选择是否有效" clearable size="small"> | |
| 20 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 21 | + :key="dict.value" :label="dict.label" :value="dict.value"/> | |
| 22 | + </el-select> | |
| 23 | + </el-form-item> | |
| 24 | + <el-form-item label="创建时间" prop="createTime"> | |
| 25 | + <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange" | |
| 26 | + range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" /> | |
| 27 | + </el-form-item> | |
| 28 | + <el-form-item> | |
| 29 | + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button> | |
| 30 | + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button> | |
| 31 | + </el-form-item> | |
| 32 | + </el-form> | |
| 33 | + | |
| 34 | + <!-- 操作工具栏 --> | |
| 35 | + <el-row :gutter="10" class="mb8"> | |
| 36 | + <el-col :span="1.5"> | |
| 37 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)" | |
| 38 | + v-hasPermi="['infra:student:create']">新增</el-button> | |
| 39 | + </el-col> | |
| 40 | + <el-col :span="1.5"> | |
| 41 | + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading" | |
| 42 | + v-hasPermi="['infra:student:export']">导出</el-button> | |
| 43 | + </el-col> | |
| 44 | + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | |
| 45 | + </el-row> | |
| 46 | + | |
| 47 | + <el-table | |
| 48 | + v-loading="loading" | |
| 49 | + :data="list" | |
| 50 | + :stripe="true" | |
| 51 | + :highlight-current-row="true" | |
| 52 | + :show-overflow-tooltip="true" | |
| 53 | + @current-change="handleCurrentChange" | |
| 54 | + > | |
| 55 | + <el-table-column label="编号" align="center" prop="id"> | |
| 56 | + <template v-slot="scope"> | |
| 57 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.id" /> | |
| 58 | + </template> | |
| 59 | + </el-table-column> | |
| 60 | + <el-table-column label="名字" align="center" prop="name"> | |
| 61 | + <template v-slot="scope"> | |
| 62 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.name" /> | |
| 63 | + </template> | |
| 64 | + </el-table-column> | |
| 65 | + <el-table-column label="简介" align="center" prop="description"> | |
| 66 | + <template v-slot="scope"> | |
| 67 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.description" /> | |
| 68 | + </template> | |
| 69 | + </el-table-column> | |
| 70 | + <el-table-column label="出生日期" align="center" prop="birthday" width="180"> | |
| 71 | + <template v-slot="scope"> | |
| 72 | + <span>{{ parseTime(scope.row.birthday) }}</span> | |
| 73 | + </template> | |
| 74 | + </el-table-column> | |
| 75 | + <el-table-column label="性别" align="center" prop="sex"> | |
| 76 | + <template v-slot="scope"> | |
| 77 | + <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" /> | |
| 78 | + </template> | |
| 79 | + </el-table-column> | |
| 80 | + <el-table-column label="是否有效" align="center" prop="enabled"> | |
| 81 | + <template v-slot="scope"> | |
| 82 | + <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" /> | |
| 83 | + </template> | |
| 84 | + </el-table-column> | |
| 85 | + <el-table-column label="头像" align="center" prop="avatar"> | |
| 86 | + <template v-slot="scope"> | |
| 87 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.avatar" /> | |
| 88 | + </template> | |
| 89 | + </el-table-column> | |
| 90 | + <el-table-column label="附件" align="center" prop="video"> | |
| 91 | + <template v-slot="scope"> | |
| 92 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.video" /> | |
| 93 | + </template> | |
| 94 | + </el-table-column> | |
| 95 | + <el-table-column label="备注" align="center" prop="memo"> | |
| 96 | + <template v-slot="scope"> | |
| 97 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.memo" /> | |
| 98 | + </template> | |
| 99 | + </el-table-column> | |
| 100 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 101 | + <template v-slot="scope"> | |
| 102 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 103 | + </template> | |
| 104 | + </el-table-column> | |
| 105 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 106 | + <template v-slot="scope"> | |
| 107 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)" | |
| 108 | + v-hasPermi="['infra:student:update']">修改</el-button> | |
| 109 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 110 | + v-hasPermi="['infra:student:delete']">删除</el-button> | |
| 111 | + </template> | |
| 112 | + </el-table-column> | |
| 113 | + </el-table> | |
| 114 | + <!-- 分页组件 --> | |
| 115 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | |
| 116 | + @pagination="getList"/> | |
| 117 | + <!-- 对话框(添加 / 修改) --> | |
| 118 | + <StudentForm ref="formRef" @success="getList" /> | |
| 119 | + <!-- 子表的列表 --> | |
| 120 | + <el-tabs v-model="subTabsName"> | |
| 121 | + <el-tab-pane label="学生联系人" name="studentContact"> | |
| 122 | + <StudentContactList v-if="currentRow.id" :student-id="currentRow.id" /> | |
| 123 | + </el-tab-pane> | |
| 124 | + <el-tab-pane label="学生班主任" name="studentTeacher"> | |
| 125 | + <StudentTeacherList v-if="currentRow.id" :student-id="currentRow.id" /> | |
| 126 | + </el-tab-pane> | |
| 127 | + </el-tabs> | |
| 128 | + </div> | |
| 129 | +</template> | |
| 130 | + | |
| 131 | +<script> | |
| 132 | +import * as StudentApi from '@/api/infra/demo'; | |
| 133 | +import StudentForm from './StudentForm.vue'; | |
| 134 | + import StudentContactList from './components/StudentContactList.vue' | |
| 135 | + import StudentTeacherList from './components/StudentTeacherList.vue' | |
| 136 | +export default { | |
| 137 | + name: "Student", | |
| 138 | + components: { | |
| 139 | + StudentForm, | |
| 140 | + StudentContactList, | |
| 141 | + StudentTeacherList, | |
| 142 | + }, | |
| 143 | + data() { | |
| 144 | + return { | |
| 145 | + // 遮罩层 | |
| 146 | + loading: true, | |
| 147 | + // 导出遮罩层 | |
| 148 | + exportLoading: false, | |
| 149 | + // 显示搜索条件 | |
| 150 | + showSearch: true, | |
| 151 | + // 总条数 | |
| 152 | + total: 0, | |
| 153 | + // 学生列表 | |
| 154 | + list: [], | |
| 155 | + // 是否展开,默认全部展开 | |
| 156 | + isExpandAll: true, | |
| 157 | + // 重新渲染表格状态 | |
| 158 | + refreshTable: true, | |
| 159 | + // 选中行 | |
| 160 | + currentRow: {}, | |
| 161 | + // 查询参数 | |
| 162 | + queryParams: { | |
| 163 | + pageNo: 1, | |
| 164 | + pageSize: 10, | |
| 165 | + name: null, | |
| 166 | + birthday: null, | |
| 167 | + sex: null, | |
| 168 | + enabled: null, | |
| 169 | + createTime: [], | |
| 170 | + }, | |
| 171 | + /** 子表的列表 */ | |
| 172 | + subTabsName: 'studentContact' | |
| 173 | + }; | |
| 174 | + }, | |
| 175 | + created() { | |
| 176 | + this.getList(); | |
| 177 | + }, | |
| 178 | + methods: { | |
| 179 | + /** 查询列表 */ | |
| 180 | + getList() { | |
| 181 | + try { | |
| 182 | + this.loading = true; | |
| 183 | + StudentApi.getStudentPage(this.queryParams).then(response => { | |
| 184 | + this.list = response.data.list; | |
| 185 | + this.total = response.data.total; | |
| 186 | + }); | |
| 187 | + } finally { | |
| 188 | + this.loading = false; | |
| 189 | + } | |
| 190 | + }, | |
| 191 | + /** 搜索按钮操作 */ | |
| 192 | + handleQuery() { | |
| 193 | + this.queryParams.pageNo = 1; | |
| 194 | + this.getList(); | |
| 195 | + }, | |
| 196 | + /** 重置按钮操作 */ | |
| 197 | + resetQuery() { | |
| 198 | + this.resetForm("queryForm"); | |
| 199 | + this.handleQuery(); | |
| 200 | + }, | |
| 201 | + /** 添加/修改操作 */ | |
| 202 | + openForm(id) { | |
| 203 | + this.$refs["formRef"].open(id); | |
| 204 | + }, | |
| 205 | + /** 删除按钮操作 */ | |
| 206 | + handleDelete(row) { | |
| 207 | + const that = this; | |
| 208 | + try { | |
| 209 | + const id = row.id; | |
| 210 | + this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?').then(()=>{ | |
| 211 | + return StudentApi.deleteStudent(id); | |
| 212 | + }).then(() => { | |
| 213 | + that.getList(); | |
| 214 | + that.$modal.msgSuccess("删除成功"); | |
| 215 | + }).catch(() => {}); | |
| 216 | + } catch {} | |
| 217 | + }, | |
| 218 | + /** 导出按钮操作 */ | |
| 219 | + handleExport() { | |
| 220 | + const that = this; | |
| 221 | + try { | |
| 222 | + this.$modal.confirm('是否确认导出所有学生数据项?').then(() => { | |
| 223 | + that.exportLoading = true; | |
| 224 | + return StudentApi.exportStudentExcel(params); | |
| 225 | + }).then(response => { | |
| 226 | + that.$download.excel(response, '学生.xls'); | |
| 227 | + }); | |
| 228 | + } catch { | |
| 229 | + } finally { | |
| 230 | + that.exportLoading = false; | |
| 231 | + } | |
| 232 | + }, | |
| 233 | + /** 选中行操作 */ | |
| 234 | + handleCurrentChange(row) { | |
| 235 | + this.currentRow = row; | |
| 236 | + /** 子表的列表 */ | |
| 237 | + this.subTabsName = 'studentContact'; | |
| 238 | + }, | |
| 239 | + } | |
| 240 | +}; | |
| 241 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/xml/InfraStudentMapper
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 3 | +<mapper namespace="cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper"> | |
| 4 | + | |
| 5 | + <!-- | |
| 6 | + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 | |
| 7 | + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 | |
| 8 | + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 | |
| 9 | + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ | |
| 10 | + --> | |
| 11 | + | |
| 12 | +</mapper> | |
| 0 | 13 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/assert.json
0 → 100644
| 1 | +[ { | |
| 2 | + "contentPath" : "java/InfraStudentPageReqVO", | |
| 3 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentPageReqVO.java" | |
| 4 | +}, { | |
| 5 | + "contentPath" : "java/InfraStudentRespVO", | |
| 6 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentRespVO.java" | |
| 7 | +}, { | |
| 8 | + "contentPath" : "java/InfraStudentSaveReqVO", | |
| 9 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentSaveReqVO.java" | |
| 10 | +}, { | |
| 11 | + "contentPath" : "java/InfraStudentController", | |
| 12 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/InfraStudentController.java" | |
| 13 | +}, { | |
| 14 | + "contentPath" : "java/InfraStudentDO", | |
| 15 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentDO.java" | |
| 16 | +}, { | |
| 17 | + "contentPath" : "java/InfraStudentContactDO", | |
| 18 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentContactDO.java" | |
| 19 | +}, { | |
| 20 | + "contentPath" : "java/InfraStudentTeacherDO", | |
| 21 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentTeacherDO.java" | |
| 22 | +}, { | |
| 23 | + "contentPath" : "java/InfraStudentMapper", | |
| 24 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentMapper.java" | |
| 25 | +}, { | |
| 26 | + "contentPath" : "java/InfraStudentContactMapper", | |
| 27 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentContactMapper.java" | |
| 28 | +}, { | |
| 29 | + "contentPath" : "java/InfraStudentTeacherMapper", | |
| 30 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentTeacherMapper.java" | |
| 31 | +}, { | |
| 32 | + "contentPath" : "xml/InfraStudentMapper", | |
| 33 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/resources/mapper/demo/InfraStudentMapper.xml" | |
| 34 | +}, { | |
| 35 | + "contentPath" : "java/InfraStudentServiceImpl", | |
| 36 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentServiceImpl.java" | |
| 37 | +}, { | |
| 38 | + "contentPath" : "java/InfraStudentService", | |
| 39 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentService.java" | |
| 40 | +}, { | |
| 41 | + "contentPath" : "java/InfraStudentServiceImplTest", | |
| 42 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentServiceImplTest.java" | |
| 43 | +}, { | |
| 44 | + "contentPath" : "java/ErrorCodeConstants_手动操作", | |
| 45 | + "filePath" : "yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants_手动操作.java" | |
| 46 | +}, { | |
| 47 | + "contentPath" : "sql/sql", | |
| 48 | + "filePath" : "sql/sql.sql" | |
| 49 | +}, { | |
| 50 | + "contentPath" : "sql/h2", | |
| 51 | + "filePath" : "sql/h2.sql" | |
| 52 | +}, { | |
| 53 | + "contentPath" : "vue/index", | |
| 54 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/index.vue" | |
| 55 | +}, { | |
| 56 | + "contentPath" : "js/student", | |
| 57 | + "filePath" : "yudao-ui-admin-vue2/src/api/infra/student.js" | |
| 58 | +}, { | |
| 59 | + "contentPath" : "vue/StudentForm", | |
| 60 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/StudentForm.vue" | |
| 61 | +}, { | |
| 62 | + "contentPath" : "vue/StudentContactForm", | |
| 63 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentContactForm.vue" | |
| 64 | +}, { | |
| 65 | + "contentPath" : "vue/StudentTeacherForm", | |
| 66 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentTeacherForm.vue" | |
| 67 | +}, { | |
| 68 | + "contentPath" : "vue/StudentContactList", | |
| 69 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentContactList.vue" | |
| 70 | +}, { | |
| 71 | + "contentPath" : "vue/StudentTeacherList", | |
| 72 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentTeacherList.vue" | |
| 73 | +} ] | |
| 0 | 74 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/ErrorCodeConstants_手动操作
0 → 100644
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentContactDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生联系人 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student_contact") | |
| 16 | +@KeySequence("infra_student_contact_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentContactDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 学生编号 | |
| 32 | + */ | |
| 33 | + private Long studentId; | |
| 34 | + /** | |
| 35 | + * 名字 | |
| 36 | + */ | |
| 37 | + private String name; | |
| 38 | + /** | |
| 39 | + * 简介 | |
| 40 | + */ | |
| 41 | + private String description; | |
| 42 | + /** | |
| 43 | + * 出生日期 | |
| 44 | + */ | |
| 45 | + private LocalDateTime birthday; | |
| 46 | + /** | |
| 47 | + * 性别 | |
| 48 | + * | |
| 49 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 50 | + */ | |
| 51 | + private Integer sex; | |
| 52 | + /** | |
| 53 | + * 是否有效 | |
| 54 | + * | |
| 55 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 56 | + */ | |
| 57 | + private Boolean enabled; | |
| 58 | + /** | |
| 59 | + * 头像 | |
| 60 | + */ | |
| 61 | + private String avatar; | |
| 62 | + /** | |
| 63 | + * 附件 | |
| 64 | + */ | |
| 65 | + private String video; | |
| 66 | + /** | |
| 67 | + * 备注 | |
| 68 | + */ | |
| 69 | + private String memo; | |
| 70 | + | |
| 71 | +} | |
| 0 | 72 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentContactMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 9 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 10 | +import org.apache.ibatis.annotations.Mapper; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生联系人 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentContactMapper extends BaseMapperX<InfraStudentContactDO> { | |
| 19 | + | |
| 20 | + default List<InfraStudentContactDO> selectListByStudentId(Long studentId) { | |
| 21 | + return selectList(InfraStudentContactDO::getStudentId, studentId); | |
| 22 | + } | |
| 23 | + | |
| 24 | + default int deleteByStudentId(Long studentId) { | |
| 25 | + return delete(InfraStudentContactDO::getStudentId, studentId); | |
| 26 | + } | |
| 27 | + | |
| 28 | +} | |
| 0 | 29 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentController
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo; | |
| 2 | + | |
| 3 | +import org.springframework.web.bind.annotation.*; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 7 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 8 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 9 | +import io.swagger.v3.oas.annotations.Operation; | |
| 10 | + | |
| 11 | +import javax.validation.constraints.*; | |
| 12 | +import javax.validation.*; | |
| 13 | +import javax.servlet.http.*; | |
| 14 | +import java.util.*; | |
| 15 | +import java.io.IOException; | |
| 16 | + | |
| 17 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 18 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 19 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 20 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 21 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 22 | + | |
| 23 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 24 | + | |
| 25 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 26 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | |
| 27 | + | |
| 28 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 29 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 30 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 31 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 32 | +import cn.iocoder.yudao.module.infra.service.demo.InfraStudentService; | |
| 33 | + | |
| 34 | +@Tag(name = "管理后台 - 学生") | |
| 35 | +@RestController | |
| 36 | +@RequestMapping("/infra/student") | |
| 37 | +@Validated | |
| 38 | +public class InfraStudentController { | |
| 39 | + | |
| 40 | + @Resource | |
| 41 | + private InfraStudentService studentService; | |
| 42 | + | |
| 43 | + @PostMapping("/create") | |
| 44 | + @Operation(summary = "创建学生") | |
| 45 | + @PreAuthorize("@ss.hasPermission('infra:student:create')") | |
| 46 | + public CommonResult<Long> createStudent(@Valid @RequestBody InfraStudentSaveReqVO createReqVO) { | |
| 47 | + return success(studentService.createStudent(createReqVO)); | |
| 48 | + } | |
| 49 | + | |
| 50 | + @PutMapping("/update") | |
| 51 | + @Operation(summary = "更新学生") | |
| 52 | + @PreAuthorize("@ss.hasPermission('infra:student:update')") | |
| 53 | + public CommonResult<Boolean> updateStudent(@Valid @RequestBody InfraStudentSaveReqVO updateReqVO) { | |
| 54 | + studentService.updateStudent(updateReqVO); | |
| 55 | + return success(true); | |
| 56 | + } | |
| 57 | + | |
| 58 | + @DeleteMapping("/delete") | |
| 59 | + @Operation(summary = "删除学生") | |
| 60 | + @Parameter(name = "id", description = "编号", required = true) | |
| 61 | + @PreAuthorize("@ss.hasPermission('infra:student:delete')") | |
| 62 | + public CommonResult<Boolean> deleteStudent(@RequestParam("id") Long id) { | |
| 63 | + studentService.deleteStudent(id); | |
| 64 | + return success(true); | |
| 65 | + } | |
| 66 | + | |
| 67 | + @GetMapping("/get") | |
| 68 | + @Operation(summary = "获得学生") | |
| 69 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 70 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 71 | + public CommonResult<InfraStudentRespVO> getStudent(@RequestParam("id") Long id) { | |
| 72 | + InfraStudentDO student = studentService.getStudent(id); | |
| 73 | + return success(BeanUtils.toBean(student, InfraStudentRespVO.class)); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @GetMapping("/page") | |
| 77 | + @Operation(summary = "获得学生分页") | |
| 78 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 79 | + public CommonResult<PageResult<InfraStudentRespVO>> getStudentPage(@Valid InfraStudentPageReqVO pageReqVO) { | |
| 80 | + PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(pageReqVO); | |
| 81 | + return success(BeanUtils.toBean(pageResult, InfraStudentRespVO.class)); | |
| 82 | + } | |
| 83 | + | |
| 84 | + @GetMapping("/export-excel") | |
| 85 | + @Operation(summary = "导出学生 Excel") | |
| 86 | + @PreAuthorize("@ss.hasPermission('infra:student:export')") | |
| 87 | + @OperateLog(type = EXPORT) | |
| 88 | + public void exportStudentExcel(@Valid InfraStudentPageReqVO pageReqVO, | |
| 89 | + HttpServletResponse response) throws IOException { | |
| 90 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 91 | + List<InfraStudentDO> list = studentService.getStudentPage(pageReqVO).getList(); | |
| 92 | + // 导出 Excel | |
| 93 | + ExcelUtils.write(response, "学生.xls", "数据", InfraStudentRespVO.class, | |
| 94 | + BeanUtils.toBean(list, InfraStudentRespVO.class)); | |
| 95 | + } | |
| 96 | + | |
| 97 | + // ==================== 子表(学生联系人) ==================== | |
| 98 | + | |
| 99 | + @GetMapping("/student-contact/list-by-student-id") | |
| 100 | + @Operation(summary = "获得学生联系人列表") | |
| 101 | + @Parameter(name = "studentId", description = "学生编号") | |
| 102 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 103 | + public CommonResult<List<InfraStudentContactDO>> getStudentContactListByStudentId(@RequestParam("studentId") Long studentId) { | |
| 104 | + return success(studentService.getStudentContactListByStudentId(studentId)); | |
| 105 | + } | |
| 106 | + | |
| 107 | + // ==================== 子表(学生班主任) ==================== | |
| 108 | + | |
| 109 | + @GetMapping("/student-teacher/get-by-student-id") | |
| 110 | + @Operation(summary = "获得学生班主任") | |
| 111 | + @Parameter(name = "studentId", description = "学生编号") | |
| 112 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 113 | + public CommonResult<InfraStudentTeacherDO> getStudentTeacherByStudentId(@RequestParam("studentId") Long studentId) { | |
| 114 | + return success(studentService.getStudentTeacherByStudentId(studentId)); | |
| 115 | + } | |
| 116 | + | |
| 117 | +} | |
| 0 | 118 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student") | |
| 16 | +@KeySequence("infra_student_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 名字 | |
| 32 | + */ | |
| 33 | + private String name; | |
| 34 | + /** | |
| 35 | + * 简介 | |
| 36 | + */ | |
| 37 | + private String description; | |
| 38 | + /** | |
| 39 | + * 出生日期 | |
| 40 | + */ | |
| 41 | + private LocalDateTime birthday; | |
| 42 | + /** | |
| 43 | + * 性别 | |
| 44 | + * | |
| 45 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 46 | + */ | |
| 47 | + private Integer sex; | |
| 48 | + /** | |
| 49 | + * 是否有效 | |
| 50 | + * | |
| 51 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 52 | + */ | |
| 53 | + private Boolean enabled; | |
| 54 | + /** | |
| 55 | + * 头像 | |
| 56 | + */ | |
| 57 | + private String avatar; | |
| 58 | + /** | |
| 59 | + * 附件 | |
| 60 | + */ | |
| 61 | + private String video; | |
| 62 | + /** | |
| 63 | + * 备注 | |
| 64 | + */ | |
| 65 | + private String memo; | |
| 66 | + | |
| 67 | +} | |
| 0 | 68 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 9 | +import org.apache.ibatis.annotations.Mapper; | |
| 10 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentMapper extends BaseMapperX<InfraStudentDO> { | |
| 19 | + | |
| 20 | + default PageResult<InfraStudentDO> selectPage(InfraStudentPageReqVO reqVO) { | |
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<InfraStudentDO>() | |
| 22 | + .likeIfPresent(InfraStudentDO::getName, reqVO.getName()) | |
| 23 | + .eqIfPresent(InfraStudentDO::getBirthday, reqVO.getBirthday()) | |
| 24 | + .eqIfPresent(InfraStudentDO::getSex, reqVO.getSex()) | |
| 25 | + .eqIfPresent(InfraStudentDO::getEnabled, reqVO.getEnabled()) | |
| 26 | + .betweenIfPresent(InfraStudentDO::getCreateTime, reqVO.getCreateTime()) | |
| 27 | + .orderByDesc(InfraStudentDO::getId)); | |
| 28 | + } | |
| 29 | + | |
| 30 | +} | |
| 0 | 31 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentPageReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 11 | + | |
| 12 | +@Schema(description = "管理后台 - 学生分页 Request VO") | |
| 13 | +@Data | |
| 14 | +@EqualsAndHashCode(callSuper = true) | |
| 15 | +@ToString(callSuper = true) | |
| 16 | +public class InfraStudentPageReqVO extends PageParam { | |
| 17 | + | |
| 18 | + @Schema(description = "名字", example = "芋头") | |
| 19 | + private String name; | |
| 20 | + | |
| 21 | + @Schema(description = "出生日期") | |
| 22 | + private LocalDateTime birthday; | |
| 23 | + | |
| 24 | + @Schema(description = "性别", example = "1") | |
| 25 | + private Integer sex; | |
| 26 | + | |
| 27 | + @Schema(description = "是否有效", example = "true") | |
| 28 | + private Boolean enabled; | |
| 29 | + | |
| 30 | + @Schema(description = "创建时间") | |
| 31 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 32 | + private LocalDateTime[] createTime; | |
| 33 | + | |
| 34 | +} | |
| 0 | 35 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentRespVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import java.util.*; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | +import com.alibaba.excel.annotation.*; | |
| 10 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 11 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - 学生 Response VO") | |
| 14 | +@Data | |
| 15 | +@ExcelIgnoreUnannotated | |
| 16 | +public class InfraStudentRespVO { | |
| 17 | + | |
| 18 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 19 | + @ExcelProperty("编号") | |
| 20 | + private Long id; | |
| 21 | + | |
| 22 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 23 | + @ExcelProperty("名字") | |
| 24 | + private String name; | |
| 25 | + | |
| 26 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍") | |
| 27 | + @ExcelProperty("简介") | |
| 28 | + private String description; | |
| 29 | + | |
| 30 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 31 | + @ExcelProperty("出生日期") | |
| 32 | + private LocalDateTime birthday; | |
| 33 | + | |
| 34 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 35 | + @ExcelProperty(value = "性别", converter = DictConvert.class) | |
| 36 | + @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 37 | + private Integer sex; | |
| 38 | + | |
| 39 | + @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 40 | + @ExcelProperty(value = "是否有效", converter = DictConvert.class) | |
| 41 | + @DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 42 | + private Boolean enabled; | |
| 43 | + | |
| 44 | + @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 45 | + @ExcelProperty("头像") | |
| 46 | + private String avatar; | |
| 47 | + | |
| 48 | + @Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.mp4") | |
| 49 | + @ExcelProperty("附件") | |
| 50 | + private String video; | |
| 51 | + | |
| 52 | + @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注") | |
| 53 | + @ExcelProperty("备注") | |
| 54 | + private String memo; | |
| 55 | + | |
| 56 | + @Schema(description = "创建时间") | |
| 57 | + @ExcelProperty("创建时间") | |
| 58 | + private LocalDateTime createTime; | |
| 59 | + | |
| 60 | +} | |
| 0 | 61 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentSaveReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import javax.validation.constraints.*; | |
| 7 | +import java.util.*; | |
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | +import java.time.LocalDateTime; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 11 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - 学生新增/修改 Request VO") | |
| 14 | +@Data | |
| 15 | +public class InfraStudentSaveReqVO { | |
| 16 | + | |
| 17 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 18 | + private Long id; | |
| 19 | + | |
| 20 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 21 | + @NotEmpty(message = "名字不能为空") | |
| 22 | + private String name; | |
| 23 | + | |
| 24 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍") | |
| 25 | + @NotEmpty(message = "简介不能为空") | |
| 26 | + private String description; | |
| 27 | + | |
| 28 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 29 | + @NotNull(message = "出生日期不能为空") | |
| 30 | + private LocalDateTime birthday; | |
| 31 | + | |
| 32 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 33 | + @NotNull(message = "性别不能为空") | |
| 34 | + private Integer sex; | |
| 35 | + | |
| 36 | + @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 37 | + @NotNull(message = "是否有效不能为空") | |
| 38 | + private Boolean enabled; | |
| 39 | + | |
| 40 | + @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 41 | + @NotEmpty(message = "头像不能为空") | |
| 42 | + private String avatar; | |
| 43 | + | |
| 44 | + @Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.mp4") | |
| 45 | + @NotEmpty(message = "附件不能为空") | |
| 46 | + private String video; | |
| 47 | + | |
| 48 | + @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注") | |
| 49 | + @NotEmpty(message = "备注不能为空") | |
| 50 | + private String memo; | |
| 51 | + | |
| 52 | + @Schema(description = "学生联系人列表") | |
| 53 | + private List<InfraStudentContactDO> studentContacts; | |
| 54 | + | |
| 55 | + @Schema(description = "学生班主任") | |
| 56 | + private InfraStudentTeacherDO studentTeacher; | |
| 57 | + | |
| 58 | +} | |
| 0 | 59 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentService
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | +import javax.validation.*; | |
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 6 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 7 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 9 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 10 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生 Service 接口 | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +public interface InfraStudentService { | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * 创建学生 | |
| 21 | + * | |
| 22 | + * @param createReqVO 创建信息 | |
| 23 | + * @return 编号 | |
| 24 | + */ | |
| 25 | + Long createStudent(@Valid InfraStudentSaveReqVO createReqVO); | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * 更新学生 | |
| 29 | + * | |
| 30 | + * @param updateReqVO 更新信息 | |
| 31 | + */ | |
| 32 | + void updateStudent(@Valid InfraStudentSaveReqVO updateReqVO); | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * 删除学生 | |
| 36 | + * | |
| 37 | + * @param id 编号 | |
| 38 | + */ | |
| 39 | + void deleteStudent(Long id); | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 获得学生 | |
| 43 | + * | |
| 44 | + * @param id 编号 | |
| 45 | + * @return 学生 | |
| 46 | + */ | |
| 47 | + InfraStudentDO getStudent(Long id); | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * 获得学生分页 | |
| 51 | + * | |
| 52 | + * @param pageReqVO 分页查询 | |
| 53 | + * @return 学生分页 | |
| 54 | + */ | |
| 55 | + PageResult<InfraStudentDO> getStudentPage(InfraStudentPageReqVO pageReqVO); | |
| 56 | + | |
| 57 | + // ==================== 子表(学生联系人) ==================== | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * 获得学生联系人列表 | |
| 61 | + * | |
| 62 | + * @param studentId 学生编号 | |
| 63 | + * @return 学生联系人列表 | |
| 64 | + */ | |
| 65 | + List<InfraStudentContactDO> getStudentContactListByStudentId(Long studentId); | |
| 66 | + | |
| 67 | + // ==================== 子表(学生班主任) ==================== | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * 获得学生班主任 | |
| 71 | + * | |
| 72 | + * @param studentId 学生编号 | |
| 73 | + * @return 学生班主任 | |
| 74 | + */ | |
| 75 | + InfraStudentTeacherDO getStudentTeacherByStudentId(Long studentId); | |
| 76 | + | |
| 77 | +} | |
| 0 | 78 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentServiceImpl
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import org.springframework.stereotype.Service; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.transaction.annotation.Transactional; | |
| 7 | + | |
| 8 | +import java.util.*; | |
| 9 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 11 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 13 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 15 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 16 | + | |
| 17 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper; | |
| 18 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentContactMapper; | |
| 19 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentTeacherMapper; | |
| 20 | + | |
| 21 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 22 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 23 | + | |
| 24 | +/** | |
| 25 | + * 学生 Service 实现类 | |
| 26 | + * | |
| 27 | + * @author 芋道源码 | |
| 28 | + */ | |
| 29 | +@Service | |
| 30 | +@Validated | |
| 31 | +public class InfraStudentServiceImpl implements InfraStudentService { | |
| 32 | + | |
| 33 | + @Resource | |
| 34 | + private InfraStudentMapper studentMapper; | |
| 35 | + @Resource | |
| 36 | + private InfraStudentContactMapper studentContactMapper; | |
| 37 | + @Resource | |
| 38 | + private InfraStudentTeacherMapper studentTeacherMapper; | |
| 39 | + | |
| 40 | + @Override | |
| 41 | + @Transactional(rollbackFor = Exception.class) | |
| 42 | + public Long createStudent(InfraStudentSaveReqVO createReqVO) { | |
| 43 | + // 插入 | |
| 44 | + InfraStudentDO student = BeanUtils.toBean(createReqVO, InfraStudentDO.class); | |
| 45 | + studentMapper.insert(student); | |
| 46 | + | |
| 47 | + // 插入子表 | |
| 48 | + createStudentContactList(student.getId(), createReqVO.getStudentContacts()); | |
| 49 | + createStudentTeacher(student.getId(), createReqVO.getStudentTeacher()); | |
| 50 | + // 返回 | |
| 51 | + return student.getId(); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @Override | |
| 55 | + @Transactional(rollbackFor = Exception.class) | |
| 56 | + public void updateStudent(InfraStudentSaveReqVO updateReqVO) { | |
| 57 | + // 校验存在 | |
| 58 | + validateStudentExists(updateReqVO.getId()); | |
| 59 | + // 更新 | |
| 60 | + InfraStudentDO updateObj = BeanUtils.toBean(updateReqVO, InfraStudentDO.class); | |
| 61 | + studentMapper.updateById(updateObj); | |
| 62 | + | |
| 63 | + // 更新子表 | |
| 64 | + updateStudentContactList(updateReqVO.getId(), updateReqVO.getStudentContacts()); | |
| 65 | + updateStudentTeacher(updateReqVO.getId(), updateReqVO.getStudentTeacher()); | |
| 66 | + } | |
| 67 | + | |
| 68 | + @Override | |
| 69 | + @Transactional(rollbackFor = Exception.class) | |
| 70 | + public void deleteStudent(Long id) { | |
| 71 | + // 校验存在 | |
| 72 | + validateStudentExists(id); | |
| 73 | + // 删除 | |
| 74 | + studentMapper.deleteById(id); | |
| 75 | + | |
| 76 | + // 删除子表 | |
| 77 | + deleteStudentContactByStudentId(id); | |
| 78 | + deleteStudentTeacherByStudentId(id); | |
| 79 | + } | |
| 80 | + | |
| 81 | + private void validateStudentExists(Long id) { | |
| 82 | + if (studentMapper.selectById(id) == null) { | |
| 83 | + throw exception(STUDENT_NOT_EXISTS); | |
| 84 | + } | |
| 85 | + } | |
| 86 | + | |
| 87 | + @Override | |
| 88 | + public InfraStudentDO getStudent(Long id) { | |
| 89 | + return studentMapper.selectById(id); | |
| 90 | + } | |
| 91 | + | |
| 92 | + @Override | |
| 93 | + public PageResult<InfraStudentDO> getStudentPage(InfraStudentPageReqVO pageReqVO) { | |
| 94 | + return studentMapper.selectPage(pageReqVO); | |
| 95 | + } | |
| 96 | + | |
| 97 | + // ==================== 子表(学生联系人) ==================== | |
| 98 | + | |
| 99 | + @Override | |
| 100 | + public List<InfraStudentContactDO> getStudentContactListByStudentId(Long studentId) { | |
| 101 | + return studentContactMapper.selectListByStudentId(studentId); | |
| 102 | + } | |
| 103 | + | |
| 104 | + private void createStudentContactList(Long studentId, List<InfraStudentContactDO> list) { | |
| 105 | + list.forEach(o -> o.setStudentId(studentId)); | |
| 106 | + studentContactMapper.insertBatch(list); | |
| 107 | + } | |
| 108 | + | |
| 109 | + private void updateStudentContactList(Long studentId, List<InfraStudentContactDO> list) { | |
| 110 | + deleteStudentContactByStudentId(studentId); | |
| 111 | + list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下:1)id 冲突;2)updateTime 不更新 | |
| 112 | + createStudentContactList(studentId, list); | |
| 113 | + } | |
| 114 | + | |
| 115 | + private void deleteStudentContactByStudentId(Long studentId) { | |
| 116 | + studentContactMapper.deleteByStudentId(studentId); | |
| 117 | + } | |
| 118 | + | |
| 119 | + // ==================== 子表(学生班主任) ==================== | |
| 120 | + | |
| 121 | + @Override | |
| 122 | + public InfraStudentTeacherDO getStudentTeacherByStudentId(Long studentId) { | |
| 123 | + return studentTeacherMapper.selectByStudentId(studentId); | |
| 124 | + } | |
| 125 | + | |
| 126 | + private void createStudentTeacher(Long studentId, InfraStudentTeacherDO studentTeacher) { | |
| 127 | + if (studentTeacher == null) { | |
| 128 | + return; | |
| 129 | + } | |
| 130 | + studentTeacher.setStudentId(studentId); | |
| 131 | + studentTeacherMapper.insert(studentTeacher); | |
| 132 | + } | |
| 133 | + | |
| 134 | + private void updateStudentTeacher(Long studentId, InfraStudentTeacherDO studentTeacher) { | |
| 135 | + if (studentTeacher == null) { | |
| 136 | + return; | |
| 137 | + } | |
| 138 | + studentTeacher.setStudentId(studentId); | |
| 139 | + studentTeacher.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 | |
| 140 | + studentTeacherMapper.insertOrUpdate(studentTeacher); | |
| 141 | + } | |
| 142 | + | |
| 143 | + private void deleteStudentTeacherByStudentId(Long studentId) { | |
| 144 | + studentTeacherMapper.deleteByStudentId(studentId); | |
| 145 | + } | |
| 146 | + | |
| 147 | +} | |
| 0 | 148 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentServiceImplTest
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import org.junit.jupiter.api.Disabled; | |
| 4 | +import org.junit.jupiter.api.Test; | |
| 5 | +import org.springframework.boot.test.mock.mockito.MockBean; | |
| 6 | + | |
| 7 | +import javax.annotation.Resource; | |
| 8 | + | |
| 9 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | |
| 10 | + | |
| 11 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 13 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper; | |
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 15 | + | |
| 16 | +import javax.annotation.Resource; | |
| 17 | +import org.springframework.context.annotation.Import; | |
| 18 | +import java.util.*; | |
| 19 | +import java.time.LocalDateTime; | |
| 20 | + | |
| 21 | +import static cn.hutool.core.util.RandomUtil.*; | |
| 22 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 23 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; | |
| 24 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | |
| 25 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; | |
| 26 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; | |
| 27 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; | |
| 28 | +import static org.junit.jupiter.api.Assertions.*; | |
| 29 | +import static org.mockito.Mockito.*; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * {@link InfraStudentServiceImpl} 的单元测试类 | |
| 33 | + * | |
| 34 | + * @author 芋道源码 | |
| 35 | + */ | |
| 36 | +@Import(InfraStudentServiceImpl.class) | |
| 37 | +public class InfraStudentServiceImplTest extends BaseDbUnitTest { | |
| 38 | + | |
| 39 | + @Resource | |
| 40 | + private InfraStudentServiceImpl studentService; | |
| 41 | + | |
| 42 | + @Resource | |
| 43 | + private InfraStudentMapper studentMapper; | |
| 44 | + | |
| 45 | + @Test | |
| 46 | + public void testCreateStudent_success() { | |
| 47 | + // 准备参数 | |
| 48 | + InfraStudentSaveReqVO createReqVO = randomPojo(InfraStudentSaveReqVO.class).setId(null); | |
| 49 | + | |
| 50 | + // 调用 | |
| 51 | + Long studentId = studentService.createStudent(createReqVO); | |
| 52 | + // 断言 | |
| 53 | + assertNotNull(studentId); | |
| 54 | + // 校验记录的属性是否正确 | |
| 55 | + InfraStudentDO student = studentMapper.selectById(studentId); | |
| 56 | + assertPojoEquals(createReqVO, student, "id"); | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Test | |
| 60 | + public void testUpdateStudent_success() { | |
| 61 | + // mock 数据 | |
| 62 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class); | |
| 63 | + studentMapper.insert(dbStudent);// @Sql: 先插入出一条存在的数据 | |
| 64 | + // 准备参数 | |
| 65 | + InfraStudentSaveReqVO updateReqVO = randomPojo(InfraStudentSaveReqVO.class, o -> { | |
| 66 | + o.setId(dbStudent.getId()); // 设置更新的 ID | |
| 67 | + }); | |
| 68 | + | |
| 69 | + // 调用 | |
| 70 | + studentService.updateStudent(updateReqVO); | |
| 71 | + // 校验是否更新正确 | |
| 72 | + InfraStudentDO student = studentMapper.selectById(updateReqVO.getId()); // 获取最新的 | |
| 73 | + assertPojoEquals(updateReqVO, student); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Test | |
| 77 | + public void testUpdateStudent_notExists() { | |
| 78 | + // 准备参数 | |
| 79 | + InfraStudentSaveReqVO updateReqVO = randomPojo(InfraStudentSaveReqVO.class); | |
| 80 | + | |
| 81 | + // 调用, 并断言异常 | |
| 82 | + assertServiceException(() -> studentService.updateStudent(updateReqVO), STUDENT_NOT_EXISTS); | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Test | |
| 86 | + public void testDeleteStudent_success() { | |
| 87 | + // mock 数据 | |
| 88 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class); | |
| 89 | + studentMapper.insert(dbStudent);// @Sql: 先插入出一条存在的数据 | |
| 90 | + // 准备参数 | |
| 91 | + Long id = dbStudent.getId(); | |
| 92 | + | |
| 93 | + // 调用 | |
| 94 | + studentService.deleteStudent(id); | |
| 95 | + // 校验数据不存在了 | |
| 96 | + assertNull(studentMapper.selectById(id)); | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Test | |
| 100 | + public void testDeleteStudent_notExists() { | |
| 101 | + // 准备参数 | |
| 102 | + Long id = randomLongId(); | |
| 103 | + | |
| 104 | + // 调用, 并断言异常 | |
| 105 | + assertServiceException(() -> studentService.deleteStudent(id), STUDENT_NOT_EXISTS); | |
| 106 | + } | |
| 107 | + | |
| 108 | + @Test | |
| 109 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 110 | + public void testGetStudentPage() { | |
| 111 | + // mock 数据 | |
| 112 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class, o -> { // 等会查询到 | |
| 113 | + o.setName(null); | |
| 114 | + o.setBirthday(null); | |
| 115 | + o.setSex(null); | |
| 116 | + o.setEnabled(null); | |
| 117 | + o.setCreateTime(null); | |
| 118 | + }); | |
| 119 | + studentMapper.insert(dbStudent); | |
| 120 | + // 测试 name 不匹配 | |
| 121 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setName(null))); | |
| 122 | + // 测试 birthday 不匹配 | |
| 123 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setBirthday(null))); | |
| 124 | + // 测试 sex 不匹配 | |
| 125 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setSex(null))); | |
| 126 | + // 测试 enabled 不匹配 | |
| 127 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setEnabled(null))); | |
| 128 | + // 测试 createTime 不匹配 | |
| 129 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setCreateTime(null))); | |
| 130 | + // 准备参数 | |
| 131 | + InfraStudentPageReqVO reqVO = new InfraStudentPageReqVO(); | |
| 132 | + reqVO.setName(null); | |
| 133 | + reqVO.setBirthday(null); | |
| 134 | + reqVO.setSex(null); | |
| 135 | + reqVO.setEnabled(null); | |
| 136 | + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 137 | + | |
| 138 | + // 调用 | |
| 139 | + PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(reqVO); | |
| 140 | + // 断言 | |
| 141 | + assertEquals(1, pageResult.getTotal()); | |
| 142 | + assertEquals(1, pageResult.getList().size()); | |
| 143 | + assertPojoEquals(dbStudent, pageResult.getList().get(0)); | |
| 144 | + } | |
| 145 | + | |
| 146 | +} | |
| 0 | 147 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentTeacherDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生班主任 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student_teacher") | |
| 16 | +@KeySequence("infra_student_teacher_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentTeacherDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 学生编号 | |
| 32 | + */ | |
| 33 | + private Long studentId; | |
| 34 | + /** | |
| 35 | + * 名字 | |
| 36 | + */ | |
| 37 | + private String name; | |
| 38 | + /** | |
| 39 | + * 简介 | |
| 40 | + */ | |
| 41 | + private String description; | |
| 42 | + /** | |
| 43 | + * 出生日期 | |
| 44 | + */ | |
| 45 | + private LocalDateTime birthday; | |
| 46 | + /** | |
| 47 | + * 性别 | |
| 48 | + * | |
| 49 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 50 | + */ | |
| 51 | + private Integer sex; | |
| 52 | + /** | |
| 53 | + * 是否有效 | |
| 54 | + * | |
| 55 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 56 | + */ | |
| 57 | + private Boolean enabled; | |
| 58 | + /** | |
| 59 | + * 头像 | |
| 60 | + */ | |
| 61 | + private String avatar; | |
| 62 | + /** | |
| 63 | + * 附件 | |
| 64 | + */ | |
| 65 | + private String video; | |
| 66 | + /** | |
| 67 | + * 备注 | |
| 68 | + */ | |
| 69 | + private String memo; | |
| 70 | + | |
| 71 | +} | |
| 0 | 72 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentTeacherMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 9 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 10 | +import org.apache.ibatis.annotations.Mapper; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生班主任 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentTeacherMapper extends BaseMapperX<InfraStudentTeacherDO> { | |
| 19 | + | |
| 20 | + default InfraStudentTeacherDO selectByStudentId(Long studentId) { | |
| 21 | + return selectOne(InfraStudentTeacherDO::getStudentId, studentId); | |
| 22 | + } | |
| 23 | + | |
| 24 | + default int deleteByStudentId(Long studentId) { | |
| 25 | + return delete(InfraStudentTeacherDO::getStudentId, studentId); | |
| 26 | + } | |
| 27 | + | |
| 28 | +} | |
| 0 | 29 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/js/student
0 → 100644
| 1 | +import request from '@/utils/request' | |
| 2 | + | |
| 3 | +// 创建学生 | |
| 4 | +export function createStudent(data) { | |
| 5 | + return request({ | |
| 6 | + url: '/infra/student/create', | |
| 7 | + method: 'post', | |
| 8 | + data: data | |
| 9 | + }) | |
| 10 | +} | |
| 11 | + | |
| 12 | +// 更新学生 | |
| 13 | +export function updateStudent(data) { | |
| 14 | + return request({ | |
| 15 | + url: '/infra/student/update', | |
| 16 | + method: 'put', | |
| 17 | + data: data | |
| 18 | + }) | |
| 19 | +} | |
| 20 | + | |
| 21 | +// 删除学生 | |
| 22 | +export function deleteStudent(id) { | |
| 23 | + return request({ | |
| 24 | + url: '/infra/student/delete?id=' + id, | |
| 25 | + method: 'delete' | |
| 26 | + }) | |
| 27 | +} | |
| 28 | + | |
| 29 | +// 获得学生 | |
| 30 | +export function getStudent(id) { | |
| 31 | + return request({ | |
| 32 | + url: '/infra/student/get?id=' + id, | |
| 33 | + method: 'get' | |
| 34 | + }) | |
| 35 | +} | |
| 36 | + | |
| 37 | +// 获得学生分页 | |
| 38 | +export function getStudentPage(params) { | |
| 39 | + return request({ | |
| 40 | + url: '/infra/student/page', | |
| 41 | + method: 'get', | |
| 42 | + params | |
| 43 | + }) | |
| 44 | +} | |
| 45 | +// 导出学生 Excel | |
| 46 | +export function exportStudentExcel(params) { | |
| 47 | + return request({ | |
| 48 | + url: '/infra/student/export-excel', | |
| 49 | + method: 'get', | |
| 50 | + params, | |
| 51 | + responseType: 'blob' | |
| 52 | + }) | |
| 53 | +} | |
| 54 | + | |
| 55 | +// ==================== 子表(学生联系人) ==================== | |
| 56 | + | |
| 57 | + // 获得学生联系人列表 | |
| 58 | + export function getStudentContactListByStudentId(studentId) { | |
| 59 | + return request({ | |
| 60 | + url: `/infra/student/student-contact/list-by-student-id?studentId=` + studentId, | |
| 61 | + method: 'get' | |
| 62 | + }) | |
| 63 | + } | |
| 64 | + | |
| 65 | +// ==================== 子表(学生班主任) ==================== | |
| 66 | + | |
| 67 | + // 获得学生班主任 | |
| 68 | + export function getStudentTeacherByStudentId(studentId) { | |
| 69 | + return request({ | |
| 70 | + url: `/infra/student/student-teacher/get-by-student-id?studentId=` + studentId, | |
| 71 | + method: 'get' | |
| 72 | + }) | |
| 73 | + } | |
| 74 | + | |
| 0 | 75 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/sql/h2
0 → 100644
| 1 | +-- 将该建表 SQL 语句,添加到 yudao-module-infra-biz 模块的 test/resources/sql/create_tables.sql 文件里 | |
| 2 | +CREATE TABLE IF NOT EXISTS "infra_student" ( | |
| 3 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 4 | + "name" varchar NOT NULL, | |
| 5 | + "description" varchar NOT NULL, | |
| 6 | + "birthday" varchar NOT NULL, | |
| 7 | + "sex" int NOT NULL, | |
| 8 | + "enabled" bit NOT NULL, | |
| 9 | + "avatar" varchar NOT NULL, | |
| 10 | + "video" varchar NOT NULL, | |
| 11 | + "memo" varchar NOT NULL, | |
| 12 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 13 | + PRIMARY KEY ("id") | |
| 14 | +) COMMENT '学生表'; | |
| 15 | + | |
| 16 | +-- 将该删表 SQL 语句,添加到 yudao-module-infra-biz 模块的 test/resources/sql/clean.sql 文件里 | |
| 17 | +DELETE FROM "infra_student"; | |
| 0 | 18 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/sql/sql
0 → 100644
| 1 | +-- 菜单 SQL | |
| 2 | +INSERT INTO system_menu( | |
| 3 | + name, permission, type, sort, parent_id, | |
| 4 | + path, icon, component, status, component_name | |
| 5 | +) | |
| 6 | +VALUES ( | |
| 7 | + '学生管理', '', 2, 0, 888, | |
| 8 | + 'student', '', 'infra/demo/index', 0, 'InfraStudent' | |
| 9 | +); | |
| 10 | + | |
| 11 | +-- 按钮父菜单ID | |
| 12 | +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 | |
| 13 | +SELECT @parentId := LAST_INSERT_ID(); | |
| 14 | + | |
| 15 | +-- 按钮 SQL | |
| 16 | +INSERT INTO system_menu( | |
| 17 | + name, permission, type, sort, parent_id, | |
| 18 | + path, icon, component, status | |
| 19 | +) | |
| 20 | +VALUES ( | |
| 21 | + '学生查询', 'infra:student:query', 3, 1, @parentId, | |
| 22 | + '', '', '', 0 | |
| 23 | +); | |
| 24 | +INSERT INTO system_menu( | |
| 25 | + name, permission, type, sort, parent_id, | |
| 26 | + path, icon, component, status | |
| 27 | +) | |
| 28 | +VALUES ( | |
| 29 | + '学生创建', 'infra:student:create', 3, 2, @parentId, | |
| 30 | + '', '', '', 0 | |
| 31 | +); | |
| 32 | +INSERT INTO system_menu( | |
| 33 | + name, permission, type, sort, parent_id, | |
| 34 | + path, icon, component, status | |
| 35 | +) | |
| 36 | +VALUES ( | |
| 37 | + '学生更新', 'infra:student:update', 3, 3, @parentId, | |
| 38 | + '', '', '', 0 | |
| 39 | +); | |
| 40 | +INSERT INTO system_menu( | |
| 41 | + name, permission, type, sort, parent_id, | |
| 42 | + path, icon, component, status | |
| 43 | +) | |
| 44 | +VALUES ( | |
| 45 | + '学生删除', 'infra:student:delete', 3, 4, @parentId, | |
| 46 | + '', '', '', 0 | |
| 47 | +); | |
| 48 | +INSERT INTO system_menu( | |
| 49 | + name, permission, type, sort, parent_id, | |
| 50 | + path, icon, component, status | |
| 51 | +) | |
| 52 | +VALUES ( | |
| 53 | + '学生导出', 'infra:student:export', 3, 5, @parentId, | |
| 54 | + '', '', '', 0 | |
| 55 | +); | |
| 0 | 56 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/vue/StudentContactForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <el-form | |
| 4 | + ref="formRef" | |
| 5 | + :model="formData" | |
| 6 | + :rules="formRules" | |
| 7 | + v-loading="formLoading" | |
| 8 | + label-width="0px" | |
| 9 | + :inline-message="true" | |
| 10 | + > | |
| 11 | + <el-table :data="formData" class="-mt-10px"> | |
| 12 | + <el-table-column label="序号" type="index" width="100" /> | |
| 13 | + <el-table-column label="名字" min-width="150"> | |
| 14 | + <template v-slot="{ row, $index }"> | |
| 15 | + <el-form-item :prop="`${$index}.name`" :rules="formRules.name" class="mb-0px!"> | |
| 16 | + <el-input v-model="row.name" placeholder="请输入名字" /> | |
| 17 | + </el-form-item> | |
| 18 | + </template> | |
| 19 | + </el-table-column> | |
| 20 | + <el-table-column label="简介" min-width="200"> | |
| 21 | + <template v-slot="{ row, $index }"> | |
| 22 | + <el-form-item :prop="`${$index}.description`" :rules="formRules.description" class="mb-0px!"> | |
| 23 | + <el-input v-model="row.description" type="textarea" placeholder="请输入简介" /> | |
| 24 | + </el-form-item> | |
| 25 | + </template> | |
| 26 | + </el-table-column> | |
| 27 | + <el-table-column label="出生日期" min-width="150"> | |
| 28 | + <template v-slot="{ row, $index }"> | |
| 29 | + <el-form-item :prop="`${$index}.birthday`" :rules="formRules.birthday" class="mb-0px!"> | |
| 30 | + <el-date-picker clearable v-model="row.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 31 | + </el-form-item> | |
| 32 | + </template> | |
| 33 | + </el-table-column> | |
| 34 | + <el-table-column label="性别" min-width="150"> | |
| 35 | + <template v-slot="{ row, $index }"> | |
| 36 | + <el-form-item :prop="`${$index}.sex`" :rules="formRules.sex" class="mb-0px!"> | |
| 37 | + <el-select v-model="row.sex" placeholder="请选择性别"> | |
| 38 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 39 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 40 | + </el-select> | |
| 41 | + </el-form-item> | |
| 42 | + </template> | |
| 43 | + </el-table-column> | |
| 44 | + <el-table-column label="是否有效" min-width="150"> | |
| 45 | + <template v-slot="{ row, $index }"> | |
| 46 | + <el-form-item :prop="`${$index}.enabled`" :rules="formRules.enabled" class="mb-0px!"> | |
| 47 | + <el-radio-group v-model="row.enabled"> | |
| 48 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 49 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 50 | + </el-radio-group> | |
| 51 | + </el-form-item> | |
| 52 | + </template> | |
| 53 | + </el-table-column> | |
| 54 | + <el-table-column label="头像" min-width="200"> | |
| 55 | + <template v-slot="{ row, $index }"> | |
| 56 | + <el-form-item :prop="`${$index}.avatar`" :rules="formRules.avatar" class="mb-0px!"> | |
| 57 | + <ImageUpload v-model="row.avatar"/> | |
| 58 | + </el-form-item> | |
| 59 | + </template> | |
| 60 | + </el-table-column> | |
| 61 | + <el-table-column label="附件" min-width="200"> | |
| 62 | + <template v-slot="{ row, $index }"> | |
| 63 | + <el-form-item :prop="`${$index}.video`" :rules="formRules.video" class="mb-0px!"> | |
| 64 | + <FileUpload v-model="row.video"/> | |
| 65 | + </el-form-item> | |
| 66 | + </template> | |
| 67 | + </el-table-column> | |
| 68 | + <el-table-column label="备注" min-width="400"> | |
| 69 | + <template v-slot="{ row, $index }"> | |
| 70 | + <el-form-item :prop="`${$index}.memo`" :rules="formRules.memo" class="mb-0px!"> | |
| 71 | + <Editor v-model="row.memo" :min-height="192"/> | |
| 72 | + </el-form-item> | |
| 73 | + </template> | |
| 74 | + </el-table-column> | |
| 75 | + <el-table-column align="center" fixed="right" label="操作" width="60"> | |
| 76 | + <template v-slot="{ $index }"> | |
| 77 | + <el-link @click="handleDelete($index)">—</el-link> | |
| 78 | + </template> | |
| 79 | + </el-table-column> | |
| 80 | + </el-table> | |
| 81 | + </el-form> | |
| 82 | + <el-row justify="center" class="mt-3"> | |
| 83 | + <el-button @click="handleAdd" round>+ 添加学生联系人</el-button> | |
| 84 | + </el-row> | |
| 85 | + </div> | |
| 86 | +</template> | |
| 87 | + | |
| 88 | +<script> | |
| 89 | + import * as StudentApi from '@/api/infra/demo' | |
| 90 | + import ImageUpload from '@/components/ImageUpload'; | |
| 91 | + import FileUpload from '@/components/FileUpload'; | |
| 92 | + import Editor from '@/components/Editor'; | |
| 93 | + export default { | |
| 94 | + name: "StudentContactForm", | |
| 95 | + components: { | |
| 96 | + ImageUpload, | |
| 97 | + FileUpload, | |
| 98 | + Editor, | |
| 99 | + }, | |
| 100 | + props:[ | |
| 101 | + 'studentId' | |
| 102 | + ],// 学生编号(主表的关联字段) | |
| 103 | + data() { | |
| 104 | + return { | |
| 105 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 106 | + formLoading: false, | |
| 107 | + // 表单参数 | |
| 108 | + formData: [], | |
| 109 | + // 表单校验 | |
| 110 | + formRules: { | |
| 111 | + studentId: [{ required: true, message: "学生编号不能为空", trigger: "blur" }], | |
| 112 | + name: [{ required: true, message: "名字不能为空", trigger: "blur" }], | |
| 113 | + description: [{ required: true, message: "简介不能为空", trigger: "blur" }], | |
| 114 | + birthday: [{ required: true, message: "出生日期不能为空", trigger: "blur" }], | |
| 115 | + sex: [{ required: true, message: "性别不能为空", trigger: "change" }], | |
| 116 | + enabled: [{ required: true, message: "是否有效不能为空", trigger: "blur" }], | |
| 117 | + avatar: [{ required: true, message: "头像不能为空", trigger: "blur" }], | |
| 118 | + memo: [{ required: true, message: "备注不能为空", trigger: "blur" }], | |
| 119 | + }, | |
| 120 | + }; | |
| 121 | + }, | |
| 122 | + watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 123 | + studentId:{ | |
| 124 | + handler(val) { | |
| 125 | + // 1. 重置表单 | |
| 126 | + this.formData = [] | |
| 127 | + // 2. val 非空,则加载数据 | |
| 128 | + if (!val) { | |
| 129 | + return; | |
| 130 | + } | |
| 131 | + try { | |
| 132 | + this.formLoading = true; | |
| 133 | + const that = this; | |
| 134 | + StudentApi.getStudentContactListByStudentId(val).then(res=>{ | |
| 135 | + that.formData = res.data; | |
| 136 | + }) | |
| 137 | + } finally { | |
| 138 | + this.formLoading = false; | |
| 139 | + } | |
| 140 | + }, | |
| 141 | + immediate: true | |
| 142 | + } | |
| 143 | + }, | |
| 144 | + methods: { | |
| 145 | + /** 新增按钮操作 */ | |
| 146 | + handleAdd() { | |
| 147 | + const row = { | |
| 148 | + id: undefined, | |
| 149 | + studentId: undefined, | |
| 150 | + name: undefined, | |
| 151 | + description: undefined, | |
| 152 | + birthday: undefined, | |
| 153 | + sex: undefined, | |
| 154 | + enabled: undefined, | |
| 155 | + avatar: undefined, | |
| 156 | + video: undefined, | |
| 157 | + memo: undefined, | |
| 158 | + } | |
| 159 | + row.studentId = this.studentId | |
| 160 | + this.formData.push(row) | |
| 161 | + }, | |
| 162 | + /** 删除按钮操作 */ | |
| 163 | + handleDelete(index) { | |
| 164 | + this.formData.splice(index, 1) | |
| 165 | + }, | |
| 166 | + /** 表单校验 */ | |
| 167 | + validate(){ | |
| 168 | + return this.$refs["formRef"].validate() | |
| 169 | + }, | |
| 170 | + /** 表单值 */ | |
| 171 | + getData(){ | |
| 172 | + return this.formData | |
| 173 | + } | |
| 174 | + } | |
| 175 | + }; | |
| 176 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/vue/StudentContactList
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | |
| 4 | + <el-table-column label="编号" align="center" prop="id" /> | |
| 5 | + <el-table-column label="名字" align="center" prop="name" /> | |
| 6 | + <el-table-column label="简介" align="center" prop="description" /> | |
| 7 | + <el-table-column label="出生日期" align="center" prop="birthday" width="180"> | |
| 8 | + <template v-slot="scope"> | |
| 9 | + <span>{{ parseTime(scope.row.birthday) }}</span> | |
| 10 | + </template> | |
| 11 | + </el-table-column> | |
| 12 | + <el-table-column label="性别" align="center" prop="sex"> | |
| 13 | + <template v-slot="scope"> | |
| 14 | + <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" /> | |
| 15 | + </template> | |
| 16 | + </el-table-column> | |
| 17 | + <el-table-column label="是否有效" align="center" prop="enabled"> | |
| 18 | + <template v-slot="scope"> | |
| 19 | + <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" /> | |
| 20 | + </template> | |
| 21 | + </el-table-column> | |
| 22 | + <el-table-column label="头像" align="center" prop="avatar" /> | |
| 23 | + <el-table-column label="附件" align="center" prop="video" /> | |
| 24 | + <el-table-column label="备注" align="center" prop="memo" /> | |
| 25 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 26 | + <template v-slot="scope"> | |
| 27 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 28 | + </template> | |
| 29 | + </el-table-column> | |
| 30 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 31 | + <template v-slot="scope"> | |
| 32 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)" | |
| 33 | + v-hasPermi="['infra:student:update']">修改</el-button> | |
| 34 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 35 | + v-hasPermi="['infra:student:delete']">删除</el-button> | |
| 36 | + </template> | |
| 37 | + </el-table-column> | |
| 38 | + </el-table> | |
| 39 | + </div> | |
| 40 | +</template> | |
| 41 | + | |
| 42 | +<script> | |
| 43 | + import * as StudentApi from '@/api/infra/demo' | |
| 44 | + export default { | |
| 45 | + name: "StudentContactList", | |
| 46 | + props:[ | |
| 47 | + 'studentId' | |
| 48 | + ],// 学生编号(主表的关联字段) | |
| 49 | + data() { | |
| 50 | + return { | |
| 51 | + // 遮罩层 | |
| 52 | + loading: true, | |
| 53 | + // 列表的数据 | |
| 54 | + list: [], | |
| 55 | + }; | |
| 56 | + }, | |
| 57 | + created() { | |
| 58 | + this.getList(); | |
| 59 | + }, | |
| 60 | + watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 61 | + studentId:{ | |
| 62 | + handler(val) { | |
| 63 | + this.queryParams.studentId = val; | |
| 64 | + if (val){ | |
| 65 | + this.handleQuery(); | |
| 66 | + } | |
| 67 | + }, | |
| 68 | + immediate: true | |
| 69 | + } | |
| 70 | + }, | |
| 71 | + methods: { | |
| 72 | + /** 查询列表 */ | |
| 73 | + getList() { | |
| 74 | + try { | |
| 75 | + this.loading = true; | |
| 76 | + const that = this; | |
| 77 | + StudentApi.getStudentContactListByStudentId(this.studentId).then(response=>{ | |
| 78 | + that.list = response.data; | |
| 79 | + }) | |
| 80 | + } finally { | |
| 81 | + this.loading = false; | |
| 82 | + } | |
| 83 | + }, | |
| 84 | + /** 搜索按钮操作 */ | |
| 85 | + handleQuery() { | |
| 86 | + this.queryParams.pageNo = 1; | |
| 87 | + this.getList(); | |
| 88 | + }, | |
| 89 | + } | |
| 90 | + }; | |
| 91 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/vue/StudentForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 对话框(添加 / 修改) --> | |
| 4 | + <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body> | |
| 5 | + <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px"> | |
| 6 | + <el-form-item label="名字" prop="name"> | |
| 7 | + <el-input v-model="formData.name" placeholder="请输入名字" /> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="简介" prop="description"> | |
| 10 | + <el-input v-model="formData.description" type="textarea" placeholder="请输入内容" /> | |
| 11 | + </el-form-item> | |
| 12 | + <el-form-item label="出生日期" prop="birthday"> | |
| 13 | + <el-date-picker clearable v-model="formData.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 14 | + </el-form-item> | |
| 15 | + <el-form-item label="性别" prop="sex"> | |
| 16 | + <el-select v-model="formData.sex" placeholder="请选择性别"> | |
| 17 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 18 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 19 | + </el-select> | |
| 20 | + </el-form-item> | |
| 21 | + <el-form-item label="是否有效" prop="enabled"> | |
| 22 | + <el-radio-group v-model="formData.enabled"> | |
| 23 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 24 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 25 | + </el-radio-group> | |
| 26 | + </el-form-item> | |
| 27 | + <el-form-item label="头像"> | |
| 28 | + <ImageUpload v-model="formData.avatar"/> | |
| 29 | + </el-form-item> | |
| 30 | + <el-form-item label="附件"> | |
| 31 | + <FileUpload v-model="formData.video"/> | |
| 32 | + </el-form-item> | |
| 33 | + <el-form-item label="备注"> | |
| 34 | + <Editor v-model="formData.memo" :min-height="192"/> | |
| 35 | + </el-form-item> | |
| 36 | + </el-form> | |
| 37 | + <!-- 子表的表单 --> | |
| 38 | + <el-tabs v-model="subTabsName"> | |
| 39 | + <el-tab-pane label="学生联系人" name="studentContact"> | |
| 40 | + <StudentContactForm ref="studentContactFormRef" :student-id="formData.id" /> | |
| 41 | + </el-tab-pane> | |
| 42 | + <el-tab-pane label="学生班主任" name="studentTeacher"> | |
| 43 | + <StudentTeacherForm ref="studentTeacherFormRef" :student-id="formData.id" /> | |
| 44 | + </el-tab-pane> | |
| 45 | + </el-tabs> | |
| 46 | + <div slot="footer" class="dialog-footer"> | |
| 47 | + <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button> | |
| 48 | + <el-button @click="dialogVisible = false">取 消</el-button> | |
| 49 | + </div> | |
| 50 | + </el-dialog> | |
| 51 | + </div> | |
| 52 | +</template> | |
| 53 | + | |
| 54 | +<script> | |
| 55 | + import * as StudentApi from '@/api/infra/demo' | |
| 56 | + import ImageUpload from '@/components/ImageUpload'; | |
| 57 | + import FileUpload from '@/components/FileUpload'; | |
| 58 | + import Editor from '@/components/Editor'; | |
| 59 | + import StudentContactForm from './components/StudentContactForm.vue' | |
| 60 | + import StudentTeacherForm from './components/StudentTeacherForm.vue' | |
| 61 | + export default { | |
| 62 | + name: "StudentForm", | |
| 63 | + components: { | |
| 64 | + ImageUpload, | |
| 65 | + FileUpload, | |
| 66 | + Editor, | |
| 67 | + StudentContactForm, | |
| 68 | + StudentTeacherForm, | |
| 69 | + }, | |
| 70 | + data() { | |
| 71 | + return { | |
| 72 | + // 弹出层标题 | |
| 73 | + dialogTitle: "", | |
| 74 | + // 是否显示弹出层 | |
| 75 | + dialogVisible: false, | |
| 76 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 77 | + formLoading: false, | |
| 78 | + // 表单参数 | |
| 79 | + formData: { | |
| 80 | + id: undefined, | |
| 81 | + name: undefined, | |
| 82 | + description: undefined, | |
| 83 | + birthday: undefined, | |
| 84 | + sex: undefined, | |
| 85 | + enabled: undefined, | |
| 86 | + avatar: undefined, | |
| 87 | + video: undefined, | |
| 88 | + memo: undefined, | |
| 89 | + }, | |
| 90 | + // 表单校验 | |
| 91 | + formRules: { | |
| 92 | + name: [{ required: true, message: '名字不能为空', trigger: 'blur' }], | |
| 93 | + description: [{ required: true, message: '简介不能为空', trigger: 'blur' }], | |
| 94 | + birthday: [{ required: true, message: '出生日期不能为空', trigger: 'blur' }], | |
| 95 | + sex: [{ required: true, message: '性别不能为空', trigger: 'change' }], | |
| 96 | + enabled: [{ required: true, message: '是否有效不能为空', trigger: 'blur' }], | |
| 97 | + avatar: [{ required: true, message: '头像不能为空', trigger: 'blur' }], | |
| 98 | + video: [{ required: true, message: '附件不能为空', trigger: 'blur' }], | |
| 99 | + memo: [{ required: true, message: '备注不能为空', trigger: 'blur' }], | |
| 100 | + }, | |
| 101 | + /** 子表的表单 */ | |
| 102 | + subTabsName: 'studentContact' | |
| 103 | + }; | |
| 104 | + }, | |
| 105 | + methods: { | |
| 106 | + /** 打开弹窗 */ | |
| 107 | + open(id) { | |
| 108 | + this.dialogVisible = true; | |
| 109 | + this.reset(); | |
| 110 | + const that = this; | |
| 111 | + // 修改时,设置数据 | |
| 112 | + if (id) { | |
| 113 | + this.formLoading = true; | |
| 114 | + try { | |
| 115 | + StudentApi.getStudent(id).then(res=>{ | |
| 116 | + that.formData = res.data; | |
| 117 | + that.title = "修改学生"; | |
| 118 | + }) | |
| 119 | + } finally { | |
| 120 | + this.formLoading = false; | |
| 121 | + } | |
| 122 | + } | |
| 123 | + this.title = "新增学生"; | |
| 124 | + }, | |
| 125 | + /** 提交按钮 */ | |
| 126 | + submitForm() { | |
| 127 | + this.formLoading = true; | |
| 128 | + try { | |
| 129 | + const that = this; | |
| 130 | + let data = this.formData; | |
| 131 | + let validate = false; | |
| 132 | + // 校验主表 | |
| 133 | + this.getRef("formRef").validate(valid => { | |
| 134 | + validate = valid; | |
| 135 | + }); | |
| 136 | + // 校验子表 | |
| 137 | + this.validateSubFrom01().then(() => { | |
| 138 | + // 全部校验通过-拼接子表的数据 | |
| 139 | + // 拼接子表的数据 | |
| 140 | + data.studentContacts = that.getRef('studentContactFormRef').getData(); | |
| 141 | + data.studentTeacher = that.getRef('studentTeacherFormRef').getData(); | |
| 142 | + }).catch((err) => { | |
| 143 | + validate = false; | |
| 144 | + that.subTabsName = err.replace("FormRef", ""); // 定位到没有校验通过的子表单 | |
| 145 | + }) | |
| 146 | + // 所有表单校验通过后方可提交 | |
| 147 | + if (!validate) { | |
| 148 | + return; | |
| 149 | + } | |
| 150 | + // 修改的提交 | |
| 151 | + if (data.id) { | |
| 152 | + StudentApi.updateStudent(data).then(response => { | |
| 153 | + that.$modal.msgSuccess("修改成功"); | |
| 154 | + that.dialogVisible = false; | |
| 155 | + that.$emit('success'); | |
| 156 | + }); | |
| 157 | + return; | |
| 158 | + } | |
| 159 | + // 添加的提交 | |
| 160 | + StudentApi.createStudent(data).then(response => { | |
| 161 | + that.$modal.msgSuccess("新增成功"); | |
| 162 | + that.dialogVisible = false; | |
| 163 | + that.$emit('success'); | |
| 164 | + }); | |
| 165 | + }finally { | |
| 166 | + this.formLoading = false; | |
| 167 | + } | |
| 168 | + }, | |
| 169 | + getRef(refName){ | |
| 170 | + return this.$refs[refName]; | |
| 171 | + }, | |
| 172 | + /** 校验子表单 */ | |
| 173 | + validateSubFrom(item) { | |
| 174 | + return new Promise((resolve, reject) => { | |
| 175 | + this.getRef(item).validate() | |
| 176 | + .then(() => { | |
| 177 | + resolve(); | |
| 178 | + }) | |
| 179 | + .catch(() => { | |
| 180 | + reject(item); | |
| 181 | + }) | |
| 182 | + }) | |
| 183 | + }, | |
| 184 | + /** 校验所有子表单 */ | |
| 185 | + validateSubFrom01() { | |
| 186 | + // 需要校验的表单 ref | |
| 187 | + const validFormRefArr = [ | |
| 188 | + "studentContactFormRef", | |
| 189 | + "studentTeacherFormRef", | |
| 190 | + ]; | |
| 191 | + const validArr = []; // 校验 | |
| 192 | + for (const item of validFormRefArr) { | |
| 193 | + validArr.push(this.validateSubFrom(item)); | |
| 194 | + } | |
| 195 | + return new Promise((resolve, reject) => { | |
| 196 | + // 校验所有 | |
| 197 | + Promise.all(validArr).then(() => { | |
| 198 | + resolve(); | |
| 199 | + }).catch((err) => { | |
| 200 | + reject(err); | |
| 201 | + }) | |
| 202 | + }) | |
| 203 | + }, | |
| 204 | + /** 表单重置 */ | |
| 205 | + reset() { | |
| 206 | + this.formData = { | |
| 207 | + id: undefined, | |
| 208 | + name: undefined, | |
| 209 | + description: undefined, | |
| 210 | + birthday: undefined, | |
| 211 | + sex: undefined, | |
| 212 | + enabled: undefined, | |
| 213 | + avatar: undefined, | |
| 214 | + video: undefined, | |
| 215 | + memo: undefined, | |
| 216 | + }; | |
| 217 | + this.resetForm("formRef"); | |
| 218 | + }, | |
| 219 | + } | |
| 220 | + }; | |
| 221 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/vue/StudentTeacherForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <el-form | |
| 4 | + ref="formRef" | |
| 5 | + :model="formData" | |
| 6 | + :rules="formRules" | |
| 7 | + label-width="100px" | |
| 8 | + v-loading="formLoading" | |
| 9 | + > | |
| 10 | + <el-form-item label="名字" prop="name"> | |
| 11 | + <el-input v-model="formData.name" placeholder="请输入名字" /> | |
| 12 | + </el-form-item> | |
| 13 | + <el-form-item label="简介" prop="description"> | |
| 14 | + <el-input v-model="formData.description" type="textarea" placeholder="请输入简介" /> | |
| 15 | + </el-form-item> | |
| 16 | + <el-form-item label="出生日期" prop="birthday"> | |
| 17 | + <el-date-picker clearable v-model="formData.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 18 | + </el-form-item> | |
| 19 | + <el-form-item label="性别" prop="sex"> | |
| 20 | + <el-select v-model="formData.sex" placeholder="请选择性别"> | |
| 21 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 22 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 23 | + </el-select> | |
| 24 | + </el-form-item> | |
| 25 | + <el-form-item label="是否有效" prop="enabled"> | |
| 26 | + <el-radio-group v-model="formData.enabled"> | |
| 27 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 28 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 29 | + </el-radio-group> | |
| 30 | + </el-form-item> | |
| 31 | + <el-form-item label="头像"> | |
| 32 | + <ImageUpload v-model="formData.avatar"/> | |
| 33 | + </el-form-item> | |
| 34 | + <el-form-item label="附件"> | |
| 35 | + <FileUpload v-model="formData.video"/> | |
| 36 | + </el-form-item> | |
| 37 | + <el-form-item label="备注"> | |
| 38 | + <Editor v-model="formData.memo" :min-height="192"/> | |
| 39 | + </el-form-item> | |
| 40 | + </el-form> | |
| 41 | + </div> | |
| 42 | +</template> | |
| 43 | + | |
| 44 | +<script> | |
| 45 | + import * as StudentApi from '@/api/infra/demo' | |
| 46 | + import ImageUpload from '@/components/ImageUpload'; | |
| 47 | + import FileUpload from '@/components/FileUpload'; | |
| 48 | + import Editor from '@/components/Editor'; | |
| 49 | + export default { | |
| 50 | + name: "StudentTeacherForm", | |
| 51 | + components: { | |
| 52 | + ImageUpload, | |
| 53 | + FileUpload, | |
| 54 | + Editor, | |
| 55 | + }, | |
| 56 | + props:[ | |
| 57 | + 'studentId' | |
| 58 | + ],// 学生编号(主表的关联字段) | |
| 59 | + data() { | |
| 60 | + return { | |
| 61 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 62 | + formLoading: false, | |
| 63 | + // 表单参数 | |
| 64 | + formData: [], | |
| 65 | + // 表单校验 | |
| 66 | + formRules: { | |
| 67 | + studentId: [{ required: true, message: "学生编号不能为空", trigger: "blur" }], | |
| 68 | + name: [{ required: true, message: "名字不能为空", trigger: "blur" }], | |
| 69 | + description: [{ required: true, message: "简介不能为空", trigger: "blur" }], | |
| 70 | + birthday: [{ required: true, message: "出生日期不能为空", trigger: "blur" }], | |
| 71 | + sex: [{ required: true, message: "性别不能为空", trigger: "change" }], | |
| 72 | + enabled: [{ required: true, message: "是否有效不能为空", trigger: "blur" }], | |
| 73 | + avatar: [{ required: true, message: "头像不能为空", trigger: "blur" }], | |
| 74 | + memo: [{ required: true, message: "备注不能为空", trigger: "blur" }], | |
| 75 | + }, | |
| 76 | + }; | |
| 77 | + }, | |
| 78 | + watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 79 | + studentId:{ | |
| 80 | + handler(val) { | |
| 81 | + // 1. 重置表单 | |
| 82 | + this.formData = { | |
| 83 | + id: undefined, | |
| 84 | + studentId: undefined, | |
| 85 | + name: undefined, | |
| 86 | + description: undefined, | |
| 87 | + birthday: undefined, | |
| 88 | + sex: undefined, | |
| 89 | + enabled: undefined, | |
| 90 | + avatar: undefined, | |
| 91 | + video: undefined, | |
| 92 | + memo: undefined, | |
| 93 | + } | |
| 94 | + // 2. val 非空,则加载数据 | |
| 95 | + if (!val) { | |
| 96 | + return; | |
| 97 | + } | |
| 98 | + try { | |
| 99 | + this.formLoading = true; | |
| 100 | + const that = this; | |
| 101 | + StudentApi.getStudentTeacherByStudentId(val).then(res=>{ | |
| 102 | + const data = res.data; | |
| 103 | + if (!data) { | |
| 104 | + return | |
| 105 | + } | |
| 106 | + that.formData = data; | |
| 107 | + }) | |
| 108 | + } finally { | |
| 109 | + this.formLoading = false; | |
| 110 | + } | |
| 111 | + }, | |
| 112 | + immediate: true | |
| 113 | + } | |
| 114 | + }, | |
| 115 | + methods: { | |
| 116 | + /** 表单校验 */ | |
| 117 | + validate(){ | |
| 118 | + return this.$refs["formRef"].validate() | |
| 119 | + }, | |
| 120 | + /** 表单值 */ | |
| 121 | + getData(){ | |
| 122 | + return this.formData | |
| 123 | + } | |
| 124 | + } | |
| 125 | + }; | |
| 126 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/vue/StudentTeacherList
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | |
| 4 | + <el-table-column label="编号" align="center" prop="id" /> | |
| 5 | + <el-table-column label="名字" align="center" prop="name" /> | |
| 6 | + <el-table-column label="简介" align="center" prop="description" /> | |
| 7 | + <el-table-column label="出生日期" align="center" prop="birthday" width="180"> | |
| 8 | + <template v-slot="scope"> | |
| 9 | + <span>{{ parseTime(scope.row.birthday) }}</span> | |
| 10 | + </template> | |
| 11 | + </el-table-column> | |
| 12 | + <el-table-column label="性别" align="center" prop="sex"> | |
| 13 | + <template v-slot="scope"> | |
| 14 | + <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" /> | |
| 15 | + </template> | |
| 16 | + </el-table-column> | |
| 17 | + <el-table-column label="是否有效" align="center" prop="enabled"> | |
| 18 | + <template v-slot="scope"> | |
| 19 | + <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" /> | |
| 20 | + </template> | |
| 21 | + </el-table-column> | |
| 22 | + <el-table-column label="头像" align="center" prop="avatar" /> | |
| 23 | + <el-table-column label="附件" align="center" prop="video" /> | |
| 24 | + <el-table-column label="备注" align="center" prop="memo" /> | |
| 25 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 26 | + <template v-slot="scope"> | |
| 27 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 28 | + </template> | |
| 29 | + </el-table-column> | |
| 30 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 31 | + <template v-slot="scope"> | |
| 32 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)" | |
| 33 | + v-hasPermi="['infra:student:update']">修改</el-button> | |
| 34 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 35 | + v-hasPermi="['infra:student:delete']">删除</el-button> | |
| 36 | + </template> | |
| 37 | + </el-table-column> | |
| 38 | + </el-table> | |
| 39 | + </div> | |
| 40 | +</template> | |
| 41 | + | |
| 42 | +<script> | |
| 43 | + import * as StudentApi from '@/api/infra/demo' | |
| 44 | + export default { | |
| 45 | + name: "StudentTeacherList", | |
| 46 | + props:[ | |
| 47 | + 'studentId' | |
| 48 | + ],// 学生编号(主表的关联字段) | |
| 49 | + data() { | |
| 50 | + return { | |
| 51 | + // 遮罩层 | |
| 52 | + loading: true, | |
| 53 | + // 列表的数据 | |
| 54 | + list: [], | |
| 55 | + }; | |
| 56 | + }, | |
| 57 | + created() { | |
| 58 | + this.getList(); | |
| 59 | + }, | |
| 60 | + watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 61 | + studentId:{ | |
| 62 | + handler(val) { | |
| 63 | + this.queryParams.studentId = val; | |
| 64 | + if (val){ | |
| 65 | + this.handleQuery(); | |
| 66 | + } | |
| 67 | + }, | |
| 68 | + immediate: true | |
| 69 | + } | |
| 70 | + }, | |
| 71 | + methods: { | |
| 72 | + /** 查询列表 */ | |
| 73 | + getList() { | |
| 74 | + try { | |
| 75 | + this.loading = true; | |
| 76 | + const that = this; | |
| 77 | + StudentApi.getStudentTeacherByStudentId(this.studentId).then(response=>{ | |
| 78 | + const data = response.data; | |
| 79 | + if (!data) { | |
| 80 | + return | |
| 81 | + } | |
| 82 | + that.list.push(data) | |
| 83 | + }) | |
| 84 | + } finally { | |
| 85 | + this.loading = false; | |
| 86 | + } | |
| 87 | + }, | |
| 88 | + /** 搜索按钮操作 */ | |
| 89 | + handleQuery() { | |
| 90 | + this.queryParams.pageNo = 1; | |
| 91 | + this.getList(); | |
| 92 | + }, | |
| 93 | + } | |
| 94 | + }; | |
| 95 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/vue/index
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + | |
| 4 | + <!-- 搜索工作栏 --> | |
| 5 | + <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> | |
| 6 | + <el-form-item label="名字" prop="name"> | |
| 7 | + <el-input v-model="queryParams.name" placeholder="请输入名字" clearable @keyup.enter.native="handleQuery"/> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="出生日期" prop="birthday"> | |
| 10 | + <el-date-picker clearable v-model="queryParams.birthday" type="date" value-format="yyyy-MM-dd" placeholder="选择出生日期" /> | |
| 11 | + </el-form-item> | |
| 12 | + <el-form-item label="性别" prop="sex"> | |
| 13 | + <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable size="small"> | |
| 14 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 15 | + :key="dict.value" :label="dict.label" :value="dict.value"/> | |
| 16 | + </el-select> | |
| 17 | + </el-form-item> | |
| 18 | + <el-form-item label="是否有效" prop="enabled"> | |
| 19 | + <el-select v-model="queryParams.enabled" placeholder="请选择是否有效" clearable size="small"> | |
| 20 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 21 | + :key="dict.value" :label="dict.label" :value="dict.value"/> | |
| 22 | + </el-select> | |
| 23 | + </el-form-item> | |
| 24 | + <el-form-item label="创建时间" prop="createTime"> | |
| 25 | + <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange" | |
| 26 | + range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" /> | |
| 27 | + </el-form-item> | |
| 28 | + <el-form-item> | |
| 29 | + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button> | |
| 30 | + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button> | |
| 31 | + </el-form-item> | |
| 32 | + </el-form> | |
| 33 | + | |
| 34 | + <!-- 操作工具栏 --> | |
| 35 | + <el-row :gutter="10" class="mb8"> | |
| 36 | + <el-col :span="1.5"> | |
| 37 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)" | |
| 38 | + v-hasPermi="['infra:student:create']">新增</el-button> | |
| 39 | + </el-col> | |
| 40 | + <el-col :span="1.5"> | |
| 41 | + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading" | |
| 42 | + v-hasPermi="['infra:student:export']">导出</el-button> | |
| 43 | + </el-col> | |
| 44 | + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | |
| 45 | + </el-row> | |
| 46 | + | |
| 47 | + <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | |
| 48 | + <!-- 子表的列表 --> | |
| 49 | + <el-table-column type="expand"> | |
| 50 | + <template #default="scope"> | |
| 51 | + <el-tabs value="studentContact"> | |
| 52 | + <el-tab-pane label="学生联系人" name="studentContact"> | |
| 53 | + <StudentContactList :student-id="scope.row.id" /> | |
| 54 | + </el-tab-pane> | |
| 55 | + <el-tab-pane label="学生班主任" name="studentTeacher"> | |
| 56 | + <StudentTeacherList :student-id="scope.row.id" /> | |
| 57 | + </el-tab-pane> | |
| 58 | + </el-tabs> | |
| 59 | + </template> | |
| 60 | + </el-table-column> | |
| 61 | + <el-table-column label="编号" align="center" prop="id"> | |
| 62 | + <template v-slot="scope"> | |
| 63 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.id" /> | |
| 64 | + </template> | |
| 65 | + </el-table-column> | |
| 66 | + <el-table-column label="名字" align="center" prop="name"> | |
| 67 | + <template v-slot="scope"> | |
| 68 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.name" /> | |
| 69 | + </template> | |
| 70 | + </el-table-column> | |
| 71 | + <el-table-column label="简介" align="center" prop="description"> | |
| 72 | + <template v-slot="scope"> | |
| 73 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.description" /> | |
| 74 | + </template> | |
| 75 | + </el-table-column> | |
| 76 | + <el-table-column label="出生日期" align="center" prop="birthday" width="180"> | |
| 77 | + <template v-slot="scope"> | |
| 78 | + <span>{{ parseTime(scope.row.birthday) }}</span> | |
| 79 | + </template> | |
| 80 | + </el-table-column> | |
| 81 | + <el-table-column label="性别" align="center" prop="sex"> | |
| 82 | + <template v-slot="scope"> | |
| 83 | + <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" /> | |
| 84 | + </template> | |
| 85 | + </el-table-column> | |
| 86 | + <el-table-column label="是否有效" align="center" prop="enabled"> | |
| 87 | + <template v-slot="scope"> | |
| 88 | + <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" /> | |
| 89 | + </template> | |
| 90 | + </el-table-column> | |
| 91 | + <el-table-column label="头像" align="center" prop="avatar"> | |
| 92 | + <template v-slot="scope"> | |
| 93 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.avatar" /> | |
| 94 | + </template> | |
| 95 | + </el-table-column> | |
| 96 | + <el-table-column label="附件" align="center" prop="video"> | |
| 97 | + <template v-slot="scope"> | |
| 98 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.video" /> | |
| 99 | + </template> | |
| 100 | + </el-table-column> | |
| 101 | + <el-table-column label="备注" align="center" prop="memo"> | |
| 102 | + <template v-slot="scope"> | |
| 103 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.memo" /> | |
| 104 | + </template> | |
| 105 | + </el-table-column> | |
| 106 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 107 | + <template v-slot="scope"> | |
| 108 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 109 | + </template> | |
| 110 | + </el-table-column> | |
| 111 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 112 | + <template v-slot="scope"> | |
| 113 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)" | |
| 114 | + v-hasPermi="['infra:student:update']">修改</el-button> | |
| 115 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 116 | + v-hasPermi="['infra:student:delete']">删除</el-button> | |
| 117 | + </template> | |
| 118 | + </el-table-column> | |
| 119 | + </el-table> | |
| 120 | + <!-- 分页组件 --> | |
| 121 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | |
| 122 | + @pagination="getList"/> | |
| 123 | + <!-- 对话框(添加 / 修改) --> | |
| 124 | + <StudentForm ref="formRef" @success="getList" /> | |
| 125 | + </div> | |
| 126 | +</template> | |
| 127 | + | |
| 128 | +<script> | |
| 129 | +import * as StudentApi from '@/api/infra/demo'; | |
| 130 | +import StudentForm from './StudentForm.vue'; | |
| 131 | + import StudentContactList from './components/StudentContactList.vue' | |
| 132 | + import StudentTeacherList from './components/StudentTeacherList.vue' | |
| 133 | +export default { | |
| 134 | + name: "Student", | |
| 135 | + components: { | |
| 136 | + StudentForm, | |
| 137 | + StudentContactList, | |
| 138 | + StudentTeacherList, | |
| 139 | + }, | |
| 140 | + data() { | |
| 141 | + return { | |
| 142 | + // 遮罩层 | |
| 143 | + loading: true, | |
| 144 | + // 导出遮罩层 | |
| 145 | + exportLoading: false, | |
| 146 | + // 显示搜索条件 | |
| 147 | + showSearch: true, | |
| 148 | + // 总条数 | |
| 149 | + total: 0, | |
| 150 | + // 学生列表 | |
| 151 | + list: [], | |
| 152 | + // 是否展开,默认全部展开 | |
| 153 | + isExpandAll: true, | |
| 154 | + // 重新渲染表格状态 | |
| 155 | + refreshTable: true, | |
| 156 | + // 选中行 | |
| 157 | + currentRow: {}, | |
| 158 | + // 查询参数 | |
| 159 | + queryParams: { | |
| 160 | + pageNo: 1, | |
| 161 | + pageSize: 10, | |
| 162 | + name: null, | |
| 163 | + birthday: null, | |
| 164 | + sex: null, | |
| 165 | + enabled: null, | |
| 166 | + createTime: [], | |
| 167 | + }, | |
| 168 | + }; | |
| 169 | + }, | |
| 170 | + created() { | |
| 171 | + this.getList(); | |
| 172 | + }, | |
| 173 | + methods: { | |
| 174 | + /** 查询列表 */ | |
| 175 | + getList() { | |
| 176 | + try { | |
| 177 | + this.loading = true; | |
| 178 | + StudentApi.getStudentPage(this.queryParams).then(response => { | |
| 179 | + this.list = response.data.list; | |
| 180 | + this.total = response.data.total; | |
| 181 | + }); | |
| 182 | + } finally { | |
| 183 | + this.loading = false; | |
| 184 | + } | |
| 185 | + }, | |
| 186 | + /** 搜索按钮操作 */ | |
| 187 | + handleQuery() { | |
| 188 | + this.queryParams.pageNo = 1; | |
| 189 | + this.getList(); | |
| 190 | + }, | |
| 191 | + /** 重置按钮操作 */ | |
| 192 | + resetQuery() { | |
| 193 | + this.resetForm("queryForm"); | |
| 194 | + this.handleQuery(); | |
| 195 | + }, | |
| 196 | + /** 添加/修改操作 */ | |
| 197 | + openForm(id) { | |
| 198 | + this.$refs["formRef"].open(id); | |
| 199 | + }, | |
| 200 | + /** 删除按钮操作 */ | |
| 201 | + handleDelete(row) { | |
| 202 | + const that = this; | |
| 203 | + try { | |
| 204 | + const id = row.id; | |
| 205 | + this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?').then(()=>{ | |
| 206 | + return StudentApi.deleteStudent(id); | |
| 207 | + }).then(() => { | |
| 208 | + that.getList(); | |
| 209 | + that.$modal.msgSuccess("删除成功"); | |
| 210 | + }).catch(() => {}); | |
| 211 | + } catch {} | |
| 212 | + }, | |
| 213 | + /** 导出按钮操作 */ | |
| 214 | + handleExport() { | |
| 215 | + const that = this; | |
| 216 | + try { | |
| 217 | + this.$modal.confirm('是否确认导出所有学生数据项?').then(() => { | |
| 218 | + that.exportLoading = true; | |
| 219 | + return StudentApi.exportStudentExcel(params); | |
| 220 | + }).then(response => { | |
| 221 | + that.$download.excel(response, '学生.xls'); | |
| 222 | + }); | |
| 223 | + } catch { | |
| 224 | + } finally { | |
| 225 | + that.exportLoading = false; | |
| 226 | + } | |
| 227 | + }, | |
| 228 | + } | |
| 229 | +}; | |
| 230 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/xml/InfraStudentMapper
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 3 | +<mapper namespace="cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper"> | |
| 4 | + | |
| 5 | + <!-- | |
| 6 | + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 | |
| 7 | + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 | |
| 8 | + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 | |
| 9 | + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ | |
| 10 | + --> | |
| 11 | + | |
| 12 | +</mapper> | |
| 0 | 13 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/assert.json
0 → 100644
| 1 | +[ { | |
| 2 | + "contentPath" : "java/InfraStudentPageReqVO", | |
| 3 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentPageReqVO.java" | |
| 4 | +}, { | |
| 5 | + "contentPath" : "java/InfraStudentRespVO", | |
| 6 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentRespVO.java" | |
| 7 | +}, { | |
| 8 | + "contentPath" : "java/InfraStudentSaveReqVO", | |
| 9 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentSaveReqVO.java" | |
| 10 | +}, { | |
| 11 | + "contentPath" : "java/InfraStudentController", | |
| 12 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/InfraStudentController.java" | |
| 13 | +}, { | |
| 14 | + "contentPath" : "java/InfraStudentDO", | |
| 15 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentDO.java" | |
| 16 | +}, { | |
| 17 | + "contentPath" : "java/InfraStudentContactDO", | |
| 18 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentContactDO.java" | |
| 19 | +}, { | |
| 20 | + "contentPath" : "java/InfraStudentTeacherDO", | |
| 21 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentTeacherDO.java" | |
| 22 | +}, { | |
| 23 | + "contentPath" : "java/InfraStudentMapper", | |
| 24 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentMapper.java" | |
| 25 | +}, { | |
| 26 | + "contentPath" : "java/InfraStudentContactMapper", | |
| 27 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentContactMapper.java" | |
| 28 | +}, { | |
| 29 | + "contentPath" : "java/InfraStudentTeacherMapper", | |
| 30 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentTeacherMapper.java" | |
| 31 | +}, { | |
| 32 | + "contentPath" : "xml/InfraStudentMapper", | |
| 33 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/resources/mapper/demo/InfraStudentMapper.xml" | |
| 34 | +}, { | |
| 35 | + "contentPath" : "java/InfraStudentServiceImpl", | |
| 36 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentServiceImpl.java" | |
| 37 | +}, { | |
| 38 | + "contentPath" : "java/InfraStudentService", | |
| 39 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentService.java" | |
| 40 | +}, { | |
| 41 | + "contentPath" : "java/InfraStudentServiceImplTest", | |
| 42 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentServiceImplTest.java" | |
| 43 | +}, { | |
| 44 | + "contentPath" : "java/ErrorCodeConstants_手动操作", | |
| 45 | + "filePath" : "yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants_手动操作.java" | |
| 46 | +}, { | |
| 47 | + "contentPath" : "sql/sql", | |
| 48 | + "filePath" : "sql/sql.sql" | |
| 49 | +}, { | |
| 50 | + "contentPath" : "sql/h2", | |
| 51 | + "filePath" : "sql/h2.sql" | |
| 52 | +}, { | |
| 53 | + "contentPath" : "vue/index", | |
| 54 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/index.vue" | |
| 55 | +}, { | |
| 56 | + "contentPath" : "js/student", | |
| 57 | + "filePath" : "yudao-ui-admin-vue2/src/api/infra/student.js" | |
| 58 | +}, { | |
| 59 | + "contentPath" : "vue/StudentForm", | |
| 60 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/StudentForm.vue" | |
| 61 | +}, { | |
| 62 | + "contentPath" : "vue/StudentContactForm", | |
| 63 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentContactForm.vue" | |
| 64 | +}, { | |
| 65 | + "contentPath" : "vue/StudentTeacherForm", | |
| 66 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentTeacherForm.vue" | |
| 67 | +} ] | |
| 0 | 68 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/ErrorCodeConstants_手动操作
0 → 100644
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentContactDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生联系人 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student_contact") | |
| 16 | +@KeySequence("infra_student_contact_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentContactDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 学生编号 | |
| 32 | + */ | |
| 33 | + private Long studentId; | |
| 34 | + /** | |
| 35 | + * 名字 | |
| 36 | + */ | |
| 37 | + private String name; | |
| 38 | + /** | |
| 39 | + * 简介 | |
| 40 | + */ | |
| 41 | + private String description; | |
| 42 | + /** | |
| 43 | + * 出生日期 | |
| 44 | + */ | |
| 45 | + private LocalDateTime birthday; | |
| 46 | + /** | |
| 47 | + * 性别 | |
| 48 | + * | |
| 49 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 50 | + */ | |
| 51 | + private Integer sex; | |
| 52 | + /** | |
| 53 | + * 是否有效 | |
| 54 | + * | |
| 55 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 56 | + */ | |
| 57 | + private Boolean enabled; | |
| 58 | + /** | |
| 59 | + * 头像 | |
| 60 | + */ | |
| 61 | + private String avatar; | |
| 62 | + /** | |
| 63 | + * 附件 | |
| 64 | + */ | |
| 65 | + private String video; | |
| 66 | + /** | |
| 67 | + * 备注 | |
| 68 | + */ | |
| 69 | + private String memo; | |
| 70 | + | |
| 71 | +} | |
| 0 | 72 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentContactMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 9 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 10 | +import org.apache.ibatis.annotations.Mapper; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生联系人 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentContactMapper extends BaseMapperX<InfraStudentContactDO> { | |
| 19 | + | |
| 20 | + default List<InfraStudentContactDO> selectListByStudentId(Long studentId) { | |
| 21 | + return selectList(InfraStudentContactDO::getStudentId, studentId); | |
| 22 | + } | |
| 23 | + | |
| 24 | + default int deleteByStudentId(Long studentId) { | |
| 25 | + return delete(InfraStudentContactDO::getStudentId, studentId); | |
| 26 | + } | |
| 27 | + | |
| 28 | +} | |
| 0 | 29 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentController
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo; | |
| 2 | + | |
| 3 | +import org.springframework.web.bind.annotation.*; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 7 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 8 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 9 | +import io.swagger.v3.oas.annotations.Operation; | |
| 10 | + | |
| 11 | +import javax.validation.constraints.*; | |
| 12 | +import javax.validation.*; | |
| 13 | +import javax.servlet.http.*; | |
| 14 | +import java.util.*; | |
| 15 | +import java.io.IOException; | |
| 16 | + | |
| 17 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 18 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 19 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 20 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 21 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 22 | + | |
| 23 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 24 | + | |
| 25 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 26 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | |
| 27 | + | |
| 28 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 29 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 30 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 31 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 32 | +import cn.iocoder.yudao.module.infra.service.demo.InfraStudentService; | |
| 33 | + | |
| 34 | +@Tag(name = "管理后台 - 学生") | |
| 35 | +@RestController | |
| 36 | +@RequestMapping("/infra/student") | |
| 37 | +@Validated | |
| 38 | +public class InfraStudentController { | |
| 39 | + | |
| 40 | + @Resource | |
| 41 | + private InfraStudentService studentService; | |
| 42 | + | |
| 43 | + @PostMapping("/create") | |
| 44 | + @Operation(summary = "创建学生") | |
| 45 | + @PreAuthorize("@ss.hasPermission('infra:student:create')") | |
| 46 | + public CommonResult<Long> createStudent(@Valid @RequestBody InfraStudentSaveReqVO createReqVO) { | |
| 47 | + return success(studentService.createStudent(createReqVO)); | |
| 48 | + } | |
| 49 | + | |
| 50 | + @PutMapping("/update") | |
| 51 | + @Operation(summary = "更新学生") | |
| 52 | + @PreAuthorize("@ss.hasPermission('infra:student:update')") | |
| 53 | + public CommonResult<Boolean> updateStudent(@Valid @RequestBody InfraStudentSaveReqVO updateReqVO) { | |
| 54 | + studentService.updateStudent(updateReqVO); | |
| 55 | + return success(true); | |
| 56 | + } | |
| 57 | + | |
| 58 | + @DeleteMapping("/delete") | |
| 59 | + @Operation(summary = "删除学生") | |
| 60 | + @Parameter(name = "id", description = "编号", required = true) | |
| 61 | + @PreAuthorize("@ss.hasPermission('infra:student:delete')") | |
| 62 | + public CommonResult<Boolean> deleteStudent(@RequestParam("id") Long id) { | |
| 63 | + studentService.deleteStudent(id); | |
| 64 | + return success(true); | |
| 65 | + } | |
| 66 | + | |
| 67 | + @GetMapping("/get") | |
| 68 | + @Operation(summary = "获得学生") | |
| 69 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 70 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 71 | + public CommonResult<InfraStudentRespVO> getStudent(@RequestParam("id") Long id) { | |
| 72 | + InfraStudentDO student = studentService.getStudent(id); | |
| 73 | + return success(BeanUtils.toBean(student, InfraStudentRespVO.class)); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @GetMapping("/page") | |
| 77 | + @Operation(summary = "获得学生分页") | |
| 78 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 79 | + public CommonResult<PageResult<InfraStudentRespVO>> getStudentPage(@Valid InfraStudentPageReqVO pageReqVO) { | |
| 80 | + PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(pageReqVO); | |
| 81 | + return success(BeanUtils.toBean(pageResult, InfraStudentRespVO.class)); | |
| 82 | + } | |
| 83 | + | |
| 84 | + @GetMapping("/export-excel") | |
| 85 | + @Operation(summary = "导出学生 Excel") | |
| 86 | + @PreAuthorize("@ss.hasPermission('infra:student:export')") | |
| 87 | + @OperateLog(type = EXPORT) | |
| 88 | + public void exportStudentExcel(@Valid InfraStudentPageReqVO pageReqVO, | |
| 89 | + HttpServletResponse response) throws IOException { | |
| 90 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 91 | + List<InfraStudentDO> list = studentService.getStudentPage(pageReqVO).getList(); | |
| 92 | + // 导出 Excel | |
| 93 | + ExcelUtils.write(response, "学生.xls", "数据", InfraStudentRespVO.class, | |
| 94 | + BeanUtils.toBean(list, InfraStudentRespVO.class)); | |
| 95 | + } | |
| 96 | + | |
| 97 | + // ==================== 子表(学生联系人) ==================== | |
| 98 | + | |
| 99 | + @GetMapping("/student-contact/list-by-student-id") | |
| 100 | + @Operation(summary = "获得学生联系人列表") | |
| 101 | + @Parameter(name = "studentId", description = "学生编号") | |
| 102 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 103 | + public CommonResult<List<InfraStudentContactDO>> getStudentContactListByStudentId(@RequestParam("studentId") Long studentId) { | |
| 104 | + return success(studentService.getStudentContactListByStudentId(studentId)); | |
| 105 | + } | |
| 106 | + | |
| 107 | + // ==================== 子表(学生班主任) ==================== | |
| 108 | + | |
| 109 | + @GetMapping("/student-teacher/get-by-student-id") | |
| 110 | + @Operation(summary = "获得学生班主任") | |
| 111 | + @Parameter(name = "studentId", description = "学生编号") | |
| 112 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 113 | + public CommonResult<InfraStudentTeacherDO> getStudentTeacherByStudentId(@RequestParam("studentId") Long studentId) { | |
| 114 | + return success(studentService.getStudentTeacherByStudentId(studentId)); | |
| 115 | + } | |
| 116 | + | |
| 117 | +} | |
| 0 | 118 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student") | |
| 16 | +@KeySequence("infra_student_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 名字 | |
| 32 | + */ | |
| 33 | + private String name; | |
| 34 | + /** | |
| 35 | + * 简介 | |
| 36 | + */ | |
| 37 | + private String description; | |
| 38 | + /** | |
| 39 | + * 出生日期 | |
| 40 | + */ | |
| 41 | + private LocalDateTime birthday; | |
| 42 | + /** | |
| 43 | + * 性别 | |
| 44 | + * | |
| 45 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 46 | + */ | |
| 47 | + private Integer sex; | |
| 48 | + /** | |
| 49 | + * 是否有效 | |
| 50 | + * | |
| 51 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 52 | + */ | |
| 53 | + private Boolean enabled; | |
| 54 | + /** | |
| 55 | + * 头像 | |
| 56 | + */ | |
| 57 | + private String avatar; | |
| 58 | + /** | |
| 59 | + * 附件 | |
| 60 | + */ | |
| 61 | + private String video; | |
| 62 | + /** | |
| 63 | + * 备注 | |
| 64 | + */ | |
| 65 | + private String memo; | |
| 66 | + | |
| 67 | +} | |
| 0 | 68 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 9 | +import org.apache.ibatis.annotations.Mapper; | |
| 10 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentMapper extends BaseMapperX<InfraStudentDO> { | |
| 19 | + | |
| 20 | + default PageResult<InfraStudentDO> selectPage(InfraStudentPageReqVO reqVO) { | |
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<InfraStudentDO>() | |
| 22 | + .likeIfPresent(InfraStudentDO::getName, reqVO.getName()) | |
| 23 | + .eqIfPresent(InfraStudentDO::getBirthday, reqVO.getBirthday()) | |
| 24 | + .eqIfPresent(InfraStudentDO::getSex, reqVO.getSex()) | |
| 25 | + .eqIfPresent(InfraStudentDO::getEnabled, reqVO.getEnabled()) | |
| 26 | + .betweenIfPresent(InfraStudentDO::getCreateTime, reqVO.getCreateTime()) | |
| 27 | + .orderByDesc(InfraStudentDO::getId)); | |
| 28 | + } | |
| 29 | + | |
| 30 | +} | |
| 0 | 31 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentPageReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 11 | + | |
| 12 | +@Schema(description = "管理后台 - 学生分页 Request VO") | |
| 13 | +@Data | |
| 14 | +@EqualsAndHashCode(callSuper = true) | |
| 15 | +@ToString(callSuper = true) | |
| 16 | +public class InfraStudentPageReqVO extends PageParam { | |
| 17 | + | |
| 18 | + @Schema(description = "名字", example = "芋头") | |
| 19 | + private String name; | |
| 20 | + | |
| 21 | + @Schema(description = "出生日期") | |
| 22 | + private LocalDateTime birthday; | |
| 23 | + | |
| 24 | + @Schema(description = "性别", example = "1") | |
| 25 | + private Integer sex; | |
| 26 | + | |
| 27 | + @Schema(description = "是否有效", example = "true") | |
| 28 | + private Boolean enabled; | |
| 29 | + | |
| 30 | + @Schema(description = "创建时间") | |
| 31 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 32 | + private LocalDateTime[] createTime; | |
| 33 | + | |
| 34 | +} | |
| 0 | 35 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentRespVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import java.util.*; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | +import com.alibaba.excel.annotation.*; | |
| 10 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 11 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - 学生 Response VO") | |
| 14 | +@Data | |
| 15 | +@ExcelIgnoreUnannotated | |
| 16 | +public class InfraStudentRespVO { | |
| 17 | + | |
| 18 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 19 | + @ExcelProperty("编号") | |
| 20 | + private Long id; | |
| 21 | + | |
| 22 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 23 | + @ExcelProperty("名字") | |
| 24 | + private String name; | |
| 25 | + | |
| 26 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍") | |
| 27 | + @ExcelProperty("简介") | |
| 28 | + private String description; | |
| 29 | + | |
| 30 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 31 | + @ExcelProperty("出生日期") | |
| 32 | + private LocalDateTime birthday; | |
| 33 | + | |
| 34 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 35 | + @ExcelProperty(value = "性别", converter = DictConvert.class) | |
| 36 | + @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 37 | + private Integer sex; | |
| 38 | + | |
| 39 | + @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 40 | + @ExcelProperty(value = "是否有效", converter = DictConvert.class) | |
| 41 | + @DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 42 | + private Boolean enabled; | |
| 43 | + | |
| 44 | + @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 45 | + @ExcelProperty("头像") | |
| 46 | + private String avatar; | |
| 47 | + | |
| 48 | + @Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.mp4") | |
| 49 | + @ExcelProperty("附件") | |
| 50 | + private String video; | |
| 51 | + | |
| 52 | + @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注") | |
| 53 | + @ExcelProperty("备注") | |
| 54 | + private String memo; | |
| 55 | + | |
| 56 | + @Schema(description = "创建时间") | |
| 57 | + @ExcelProperty("创建时间") | |
| 58 | + private LocalDateTime createTime; | |
| 59 | + | |
| 60 | +} | |
| 0 | 61 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentSaveReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import javax.validation.constraints.*; | |
| 7 | +import java.util.*; | |
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | +import java.time.LocalDateTime; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 11 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - 学生新增/修改 Request VO") | |
| 14 | +@Data | |
| 15 | +public class InfraStudentSaveReqVO { | |
| 16 | + | |
| 17 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 18 | + private Long id; | |
| 19 | + | |
| 20 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 21 | + @NotEmpty(message = "名字不能为空") | |
| 22 | + private String name; | |
| 23 | + | |
| 24 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍") | |
| 25 | + @NotEmpty(message = "简介不能为空") | |
| 26 | + private String description; | |
| 27 | + | |
| 28 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 29 | + @NotNull(message = "出生日期不能为空") | |
| 30 | + private LocalDateTime birthday; | |
| 31 | + | |
| 32 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 33 | + @NotNull(message = "性别不能为空") | |
| 34 | + private Integer sex; | |
| 35 | + | |
| 36 | + @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 37 | + @NotNull(message = "是否有效不能为空") | |
| 38 | + private Boolean enabled; | |
| 39 | + | |
| 40 | + @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 41 | + @NotEmpty(message = "头像不能为空") | |
| 42 | + private String avatar; | |
| 43 | + | |
| 44 | + @Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.mp4") | |
| 45 | + @NotEmpty(message = "附件不能为空") | |
| 46 | + private String video; | |
| 47 | + | |
| 48 | + @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注") | |
| 49 | + @NotEmpty(message = "备注不能为空") | |
| 50 | + private String memo; | |
| 51 | + | |
| 52 | + @Schema(description = "学生联系人列表") | |
| 53 | + private List<InfraStudentContactDO> studentContacts; | |
| 54 | + | |
| 55 | + @Schema(description = "学生班主任") | |
| 56 | + private InfraStudentTeacherDO studentTeacher; | |
| 57 | + | |
| 58 | +} | |
| 0 | 59 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentService
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | +import javax.validation.*; | |
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 6 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 7 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 9 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 10 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生 Service 接口 | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +public interface InfraStudentService { | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * 创建学生 | |
| 21 | + * | |
| 22 | + * @param createReqVO 创建信息 | |
| 23 | + * @return 编号 | |
| 24 | + */ | |
| 25 | + Long createStudent(@Valid InfraStudentSaveReqVO createReqVO); | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * 更新学生 | |
| 29 | + * | |
| 30 | + * @param updateReqVO 更新信息 | |
| 31 | + */ | |
| 32 | + void updateStudent(@Valid InfraStudentSaveReqVO updateReqVO); | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * 删除学生 | |
| 36 | + * | |
| 37 | + * @param id 编号 | |
| 38 | + */ | |
| 39 | + void deleteStudent(Long id); | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 获得学生 | |
| 43 | + * | |
| 44 | + * @param id 编号 | |
| 45 | + * @return 学生 | |
| 46 | + */ | |
| 47 | + InfraStudentDO getStudent(Long id); | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * 获得学生分页 | |
| 51 | + * | |
| 52 | + * @param pageReqVO 分页查询 | |
| 53 | + * @return 学生分页 | |
| 54 | + */ | |
| 55 | + PageResult<InfraStudentDO> getStudentPage(InfraStudentPageReqVO pageReqVO); | |
| 56 | + | |
| 57 | + // ==================== 子表(学生联系人) ==================== | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * 获得学生联系人列表 | |
| 61 | + * | |
| 62 | + * @param studentId 学生编号 | |
| 63 | + * @return 学生联系人列表 | |
| 64 | + */ | |
| 65 | + List<InfraStudentContactDO> getStudentContactListByStudentId(Long studentId); | |
| 66 | + | |
| 67 | + // ==================== 子表(学生班主任) ==================== | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * 获得学生班主任 | |
| 71 | + * | |
| 72 | + * @param studentId 学生编号 | |
| 73 | + * @return 学生班主任 | |
| 74 | + */ | |
| 75 | + InfraStudentTeacherDO getStudentTeacherByStudentId(Long studentId); | |
| 76 | + | |
| 77 | +} | |
| 0 | 78 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentServiceImpl
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import org.springframework.stereotype.Service; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.transaction.annotation.Transactional; | |
| 7 | + | |
| 8 | +import java.util.*; | |
| 9 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 11 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 13 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 15 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 16 | + | |
| 17 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper; | |
| 18 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentContactMapper; | |
| 19 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentTeacherMapper; | |
| 20 | + | |
| 21 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 22 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 23 | + | |
| 24 | +/** | |
| 25 | + * 学生 Service 实现类 | |
| 26 | + * | |
| 27 | + * @author 芋道源码 | |
| 28 | + */ | |
| 29 | +@Service | |
| 30 | +@Validated | |
| 31 | +public class InfraStudentServiceImpl implements InfraStudentService { | |
| 32 | + | |
| 33 | + @Resource | |
| 34 | + private InfraStudentMapper studentMapper; | |
| 35 | + @Resource | |
| 36 | + private InfraStudentContactMapper studentContactMapper; | |
| 37 | + @Resource | |
| 38 | + private InfraStudentTeacherMapper studentTeacherMapper; | |
| 39 | + | |
| 40 | + @Override | |
| 41 | + @Transactional(rollbackFor = Exception.class) | |
| 42 | + public Long createStudent(InfraStudentSaveReqVO createReqVO) { | |
| 43 | + // 插入 | |
| 44 | + InfraStudentDO student = BeanUtils.toBean(createReqVO, InfraStudentDO.class); | |
| 45 | + studentMapper.insert(student); | |
| 46 | + | |
| 47 | + // 插入子表 | |
| 48 | + createStudentContactList(student.getId(), createReqVO.getStudentContacts()); | |
| 49 | + createStudentTeacher(student.getId(), createReqVO.getStudentTeacher()); | |
| 50 | + // 返回 | |
| 51 | + return student.getId(); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @Override | |
| 55 | + @Transactional(rollbackFor = Exception.class) | |
| 56 | + public void updateStudent(InfraStudentSaveReqVO updateReqVO) { | |
| 57 | + // 校验存在 | |
| 58 | + validateStudentExists(updateReqVO.getId()); | |
| 59 | + // 更新 | |
| 60 | + InfraStudentDO updateObj = BeanUtils.toBean(updateReqVO, InfraStudentDO.class); | |
| 61 | + studentMapper.updateById(updateObj); | |
| 62 | + | |
| 63 | + // 更新子表 | |
| 64 | + updateStudentContactList(updateReqVO.getId(), updateReqVO.getStudentContacts()); | |
| 65 | + updateStudentTeacher(updateReqVO.getId(), updateReqVO.getStudentTeacher()); | |
| 66 | + } | |
| 67 | + | |
| 68 | + @Override | |
| 69 | + @Transactional(rollbackFor = Exception.class) | |
| 70 | + public void deleteStudent(Long id) { | |
| 71 | + // 校验存在 | |
| 72 | + validateStudentExists(id); | |
| 73 | + // 删除 | |
| 74 | + studentMapper.deleteById(id); | |
| 75 | + | |
| 76 | + // 删除子表 | |
| 77 | + deleteStudentContactByStudentId(id); | |
| 78 | + deleteStudentTeacherByStudentId(id); | |
| 79 | + } | |
| 80 | + | |
| 81 | + private void validateStudentExists(Long id) { | |
| 82 | + if (studentMapper.selectById(id) == null) { | |
| 83 | + throw exception(STUDENT_NOT_EXISTS); | |
| 84 | + } | |
| 85 | + } | |
| 86 | + | |
| 87 | + @Override | |
| 88 | + public InfraStudentDO getStudent(Long id) { | |
| 89 | + return studentMapper.selectById(id); | |
| 90 | + } | |
| 91 | + | |
| 92 | + @Override | |
| 93 | + public PageResult<InfraStudentDO> getStudentPage(InfraStudentPageReqVO pageReqVO) { | |
| 94 | + return studentMapper.selectPage(pageReqVO); | |
| 95 | + } | |
| 96 | + | |
| 97 | + // ==================== 子表(学生联系人) ==================== | |
| 98 | + | |
| 99 | + @Override | |
| 100 | + public List<InfraStudentContactDO> getStudentContactListByStudentId(Long studentId) { | |
| 101 | + return studentContactMapper.selectListByStudentId(studentId); | |
| 102 | + } | |
| 103 | + | |
| 104 | + private void createStudentContactList(Long studentId, List<InfraStudentContactDO> list) { | |
| 105 | + list.forEach(o -> o.setStudentId(studentId)); | |
| 106 | + studentContactMapper.insertBatch(list); | |
| 107 | + } | |
| 108 | + | |
| 109 | + private void updateStudentContactList(Long studentId, List<InfraStudentContactDO> list) { | |
| 110 | + deleteStudentContactByStudentId(studentId); | |
| 111 | + list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下:1)id 冲突;2)updateTime 不更新 | |
| 112 | + createStudentContactList(studentId, list); | |
| 113 | + } | |
| 114 | + | |
| 115 | + private void deleteStudentContactByStudentId(Long studentId) { | |
| 116 | + studentContactMapper.deleteByStudentId(studentId); | |
| 117 | + } | |
| 118 | + | |
| 119 | + // ==================== 子表(学生班主任) ==================== | |
| 120 | + | |
| 121 | + @Override | |
| 122 | + public InfraStudentTeacherDO getStudentTeacherByStudentId(Long studentId) { | |
| 123 | + return studentTeacherMapper.selectByStudentId(studentId); | |
| 124 | + } | |
| 125 | + | |
| 126 | + private void createStudentTeacher(Long studentId, InfraStudentTeacherDO studentTeacher) { | |
| 127 | + if (studentTeacher == null) { | |
| 128 | + return; | |
| 129 | + } | |
| 130 | + studentTeacher.setStudentId(studentId); | |
| 131 | + studentTeacherMapper.insert(studentTeacher); | |
| 132 | + } | |
| 133 | + | |
| 134 | + private void updateStudentTeacher(Long studentId, InfraStudentTeacherDO studentTeacher) { | |
| 135 | + if (studentTeacher == null) { | |
| 136 | + return; | |
| 137 | + } | |
| 138 | + studentTeacher.setStudentId(studentId); | |
| 139 | + studentTeacher.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 | |
| 140 | + studentTeacherMapper.insertOrUpdate(studentTeacher); | |
| 141 | + } | |
| 142 | + | |
| 143 | + private void deleteStudentTeacherByStudentId(Long studentId) { | |
| 144 | + studentTeacherMapper.deleteByStudentId(studentId); | |
| 145 | + } | |
| 146 | + | |
| 147 | +} | |
| 0 | 148 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentServiceImplTest
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import org.junit.jupiter.api.Disabled; | |
| 4 | +import org.junit.jupiter.api.Test; | |
| 5 | +import org.springframework.boot.test.mock.mockito.MockBean; | |
| 6 | + | |
| 7 | +import javax.annotation.Resource; | |
| 8 | + | |
| 9 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | |
| 10 | + | |
| 11 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 13 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper; | |
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 15 | + | |
| 16 | +import javax.annotation.Resource; | |
| 17 | +import org.springframework.context.annotation.Import; | |
| 18 | +import java.util.*; | |
| 19 | +import java.time.LocalDateTime; | |
| 20 | + | |
| 21 | +import static cn.hutool.core.util.RandomUtil.*; | |
| 22 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 23 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; | |
| 24 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | |
| 25 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; | |
| 26 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; | |
| 27 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; | |
| 28 | +import static org.junit.jupiter.api.Assertions.*; | |
| 29 | +import static org.mockito.Mockito.*; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * {@link InfraStudentServiceImpl} 的单元测试类 | |
| 33 | + * | |
| 34 | + * @author 芋道源码 | |
| 35 | + */ | |
| 36 | +@Import(InfraStudentServiceImpl.class) | |
| 37 | +public class InfraStudentServiceImplTest extends BaseDbUnitTest { | |
| 38 | + | |
| 39 | + @Resource | |
| 40 | + private InfraStudentServiceImpl studentService; | |
| 41 | + | |
| 42 | + @Resource | |
| 43 | + private InfraStudentMapper studentMapper; | |
| 44 | + | |
| 45 | + @Test | |
| 46 | + public void testCreateStudent_success() { | |
| 47 | + // 准备参数 | |
| 48 | + InfraStudentSaveReqVO createReqVO = randomPojo(InfraStudentSaveReqVO.class).setId(null); | |
| 49 | + | |
| 50 | + // 调用 | |
| 51 | + Long studentId = studentService.createStudent(createReqVO); | |
| 52 | + // 断言 | |
| 53 | + assertNotNull(studentId); | |
| 54 | + // 校验记录的属性是否正确 | |
| 55 | + InfraStudentDO student = studentMapper.selectById(studentId); | |
| 56 | + assertPojoEquals(createReqVO, student, "id"); | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Test | |
| 60 | + public void testUpdateStudent_success() { | |
| 61 | + // mock 数据 | |
| 62 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class); | |
| 63 | + studentMapper.insert(dbStudent);// @Sql: 先插入出一条存在的数据 | |
| 64 | + // 准备参数 | |
| 65 | + InfraStudentSaveReqVO updateReqVO = randomPojo(InfraStudentSaveReqVO.class, o -> { | |
| 66 | + o.setId(dbStudent.getId()); // 设置更新的 ID | |
| 67 | + }); | |
| 68 | + | |
| 69 | + // 调用 | |
| 70 | + studentService.updateStudent(updateReqVO); | |
| 71 | + // 校验是否更新正确 | |
| 72 | + InfraStudentDO student = studentMapper.selectById(updateReqVO.getId()); // 获取最新的 | |
| 73 | + assertPojoEquals(updateReqVO, student); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Test | |
| 77 | + public void testUpdateStudent_notExists() { | |
| 78 | + // 准备参数 | |
| 79 | + InfraStudentSaveReqVO updateReqVO = randomPojo(InfraStudentSaveReqVO.class); | |
| 80 | + | |
| 81 | + // 调用, 并断言异常 | |
| 82 | + assertServiceException(() -> studentService.updateStudent(updateReqVO), STUDENT_NOT_EXISTS); | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Test | |
| 86 | + public void testDeleteStudent_success() { | |
| 87 | + // mock 数据 | |
| 88 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class); | |
| 89 | + studentMapper.insert(dbStudent);// @Sql: 先插入出一条存在的数据 | |
| 90 | + // 准备参数 | |
| 91 | + Long id = dbStudent.getId(); | |
| 92 | + | |
| 93 | + // 调用 | |
| 94 | + studentService.deleteStudent(id); | |
| 95 | + // 校验数据不存在了 | |
| 96 | + assertNull(studentMapper.selectById(id)); | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Test | |
| 100 | + public void testDeleteStudent_notExists() { | |
| 101 | + // 准备参数 | |
| 102 | + Long id = randomLongId(); | |
| 103 | + | |
| 104 | + // 调用, 并断言异常 | |
| 105 | + assertServiceException(() -> studentService.deleteStudent(id), STUDENT_NOT_EXISTS); | |
| 106 | + } | |
| 107 | + | |
| 108 | + @Test | |
| 109 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 110 | + public void testGetStudentPage() { | |
| 111 | + // mock 数据 | |
| 112 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class, o -> { // 等会查询到 | |
| 113 | + o.setName(null); | |
| 114 | + o.setBirthday(null); | |
| 115 | + o.setSex(null); | |
| 116 | + o.setEnabled(null); | |
| 117 | + o.setCreateTime(null); | |
| 118 | + }); | |
| 119 | + studentMapper.insert(dbStudent); | |
| 120 | + // 测试 name 不匹配 | |
| 121 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setName(null))); | |
| 122 | + // 测试 birthday 不匹配 | |
| 123 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setBirthday(null))); | |
| 124 | + // 测试 sex 不匹配 | |
| 125 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setSex(null))); | |
| 126 | + // 测试 enabled 不匹配 | |
| 127 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setEnabled(null))); | |
| 128 | + // 测试 createTime 不匹配 | |
| 129 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setCreateTime(null))); | |
| 130 | + // 准备参数 | |
| 131 | + InfraStudentPageReqVO reqVO = new InfraStudentPageReqVO(); | |
| 132 | + reqVO.setName(null); | |
| 133 | + reqVO.setBirthday(null); | |
| 134 | + reqVO.setSex(null); | |
| 135 | + reqVO.setEnabled(null); | |
| 136 | + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 137 | + | |
| 138 | + // 调用 | |
| 139 | + PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(reqVO); | |
| 140 | + // 断言 | |
| 141 | + assertEquals(1, pageResult.getTotal()); | |
| 142 | + assertEquals(1, pageResult.getList().size()); | |
| 143 | + assertPojoEquals(dbStudent, pageResult.getList().get(0)); | |
| 144 | + } | |
| 145 | + | |
| 146 | +} | |
| 0 | 147 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentTeacherDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生班主任 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student_teacher") | |
| 16 | +@KeySequence("infra_student_teacher_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentTeacherDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 学生编号 | |
| 32 | + */ | |
| 33 | + private Long studentId; | |
| 34 | + /** | |
| 35 | + * 名字 | |
| 36 | + */ | |
| 37 | + private String name; | |
| 38 | + /** | |
| 39 | + * 简介 | |
| 40 | + */ | |
| 41 | + private String description; | |
| 42 | + /** | |
| 43 | + * 出生日期 | |
| 44 | + */ | |
| 45 | + private LocalDateTime birthday; | |
| 46 | + /** | |
| 47 | + * 性别 | |
| 48 | + * | |
| 49 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 50 | + */ | |
| 51 | + private Integer sex; | |
| 52 | + /** | |
| 53 | + * 是否有效 | |
| 54 | + * | |
| 55 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 56 | + */ | |
| 57 | + private Boolean enabled; | |
| 58 | + /** | |
| 59 | + * 头像 | |
| 60 | + */ | |
| 61 | + private String avatar; | |
| 62 | + /** | |
| 63 | + * 附件 | |
| 64 | + */ | |
| 65 | + private String video; | |
| 66 | + /** | |
| 67 | + * 备注 | |
| 68 | + */ | |
| 69 | + private String memo; | |
| 70 | + | |
| 71 | +} | |
| 0 | 72 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentTeacherMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 9 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 10 | +import org.apache.ibatis.annotations.Mapper; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生班主任 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentTeacherMapper extends BaseMapperX<InfraStudentTeacherDO> { | |
| 19 | + | |
| 20 | + default InfraStudentTeacherDO selectByStudentId(Long studentId) { | |
| 21 | + return selectOne(InfraStudentTeacherDO::getStudentId, studentId); | |
| 22 | + } | |
| 23 | + | |
| 24 | + default int deleteByStudentId(Long studentId) { | |
| 25 | + return delete(InfraStudentTeacherDO::getStudentId, studentId); | |
| 26 | + } | |
| 27 | + | |
| 28 | +} | |
| 0 | 29 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/js/student
0 → 100644
| 1 | +import request from '@/utils/request' | |
| 2 | + | |
| 3 | +// 创建学生 | |
| 4 | +export function createStudent(data) { | |
| 5 | + return request({ | |
| 6 | + url: '/infra/student/create', | |
| 7 | + method: 'post', | |
| 8 | + data: data | |
| 9 | + }) | |
| 10 | +} | |
| 11 | + | |
| 12 | +// 更新学生 | |
| 13 | +export function updateStudent(data) { | |
| 14 | + return request({ | |
| 15 | + url: '/infra/student/update', | |
| 16 | + method: 'put', | |
| 17 | + data: data | |
| 18 | + }) | |
| 19 | +} | |
| 20 | + | |
| 21 | +// 删除学生 | |
| 22 | +export function deleteStudent(id) { | |
| 23 | + return request({ | |
| 24 | + url: '/infra/student/delete?id=' + id, | |
| 25 | + method: 'delete' | |
| 26 | + }) | |
| 27 | +} | |
| 28 | + | |
| 29 | +// 获得学生 | |
| 30 | +export function getStudent(id) { | |
| 31 | + return request({ | |
| 32 | + url: '/infra/student/get?id=' + id, | |
| 33 | + method: 'get' | |
| 34 | + }) | |
| 35 | +} | |
| 36 | + | |
| 37 | +// 获得学生分页 | |
| 38 | +export function getStudentPage(params) { | |
| 39 | + return request({ | |
| 40 | + url: '/infra/student/page', | |
| 41 | + method: 'get', | |
| 42 | + params | |
| 43 | + }) | |
| 44 | +} | |
| 45 | +// 导出学生 Excel | |
| 46 | +export function exportStudentExcel(params) { | |
| 47 | + return request({ | |
| 48 | + url: '/infra/student/export-excel', | |
| 49 | + method: 'get', | |
| 50 | + params, | |
| 51 | + responseType: 'blob' | |
| 52 | + }) | |
| 53 | +} | |
| 54 | + | |
| 55 | +// ==================== 子表(学生联系人) ==================== | |
| 56 | + | |
| 57 | + // 获得学生联系人列表 | |
| 58 | + export function getStudentContactListByStudentId(studentId) { | |
| 59 | + return request({ | |
| 60 | + url: `/infra/student/student-contact/list-by-student-id?studentId=` + studentId, | |
| 61 | + method: 'get' | |
| 62 | + }) | |
| 63 | + } | |
| 64 | + | |
| 65 | +// ==================== 子表(学生班主任) ==================== | |
| 66 | + | |
| 67 | + // 获得学生班主任 | |
| 68 | + export function getStudentTeacherByStudentId(studentId) { | |
| 69 | + return request({ | |
| 70 | + url: `/infra/student/student-teacher/get-by-student-id?studentId=` + studentId, | |
| 71 | + method: 'get' | |
| 72 | + }) | |
| 73 | + } | |
| 74 | + | |
| 0 | 75 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/sql/h2
0 → 100644
| 1 | +-- 将该建表 SQL 语句,添加到 yudao-module-infra-biz 模块的 test/resources/sql/create_tables.sql 文件里 | |
| 2 | +CREATE TABLE IF NOT EXISTS "infra_student" ( | |
| 3 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 4 | + "name" varchar NOT NULL, | |
| 5 | + "description" varchar NOT NULL, | |
| 6 | + "birthday" varchar NOT NULL, | |
| 7 | + "sex" int NOT NULL, | |
| 8 | + "enabled" bit NOT NULL, | |
| 9 | + "avatar" varchar NOT NULL, | |
| 10 | + "video" varchar NOT NULL, | |
| 11 | + "memo" varchar NOT NULL, | |
| 12 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 13 | + PRIMARY KEY ("id") | |
| 14 | +) COMMENT '学生表'; | |
| 15 | + | |
| 16 | +-- 将该删表 SQL 语句,添加到 yudao-module-infra-biz 模块的 test/resources/sql/clean.sql 文件里 | |
| 17 | +DELETE FROM "infra_student"; | |
| 0 | 18 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/sql/sql
0 → 100644
| 1 | +-- 菜单 SQL | |
| 2 | +INSERT INTO system_menu( | |
| 3 | + name, permission, type, sort, parent_id, | |
| 4 | + path, icon, component, status, component_name | |
| 5 | +) | |
| 6 | +VALUES ( | |
| 7 | + '学生管理', '', 2, 0, 888, | |
| 8 | + 'student', '', 'infra/demo/index', 0, 'InfraStudent' | |
| 9 | +); | |
| 10 | + | |
| 11 | +-- 按钮父菜单ID | |
| 12 | +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 | |
| 13 | +SELECT @parentId := LAST_INSERT_ID(); | |
| 14 | + | |
| 15 | +-- 按钮 SQL | |
| 16 | +INSERT INTO system_menu( | |
| 17 | + name, permission, type, sort, parent_id, | |
| 18 | + path, icon, component, status | |
| 19 | +) | |
| 20 | +VALUES ( | |
| 21 | + '学生查询', 'infra:student:query', 3, 1, @parentId, | |
| 22 | + '', '', '', 0 | |
| 23 | +); | |
| 24 | +INSERT INTO system_menu( | |
| 25 | + name, permission, type, sort, parent_id, | |
| 26 | + path, icon, component, status | |
| 27 | +) | |
| 28 | +VALUES ( | |
| 29 | + '学生创建', 'infra:student:create', 3, 2, @parentId, | |
| 30 | + '', '', '', 0 | |
| 31 | +); | |
| 32 | +INSERT INTO system_menu( | |
| 33 | + name, permission, type, sort, parent_id, | |
| 34 | + path, icon, component, status | |
| 35 | +) | |
| 36 | +VALUES ( | |
| 37 | + '学生更新', 'infra:student:update', 3, 3, @parentId, | |
| 38 | + '', '', '', 0 | |
| 39 | +); | |
| 40 | +INSERT INTO system_menu( | |
| 41 | + name, permission, type, sort, parent_id, | |
| 42 | + path, icon, component, status | |
| 43 | +) | |
| 44 | +VALUES ( | |
| 45 | + '学生删除', 'infra:student:delete', 3, 4, @parentId, | |
| 46 | + '', '', '', 0 | |
| 47 | +); | |
| 48 | +INSERT INTO system_menu( | |
| 49 | + name, permission, type, sort, parent_id, | |
| 50 | + path, icon, component, status | |
| 51 | +) | |
| 52 | +VALUES ( | |
| 53 | + '学生导出', 'infra:student:export', 3, 5, @parentId, | |
| 54 | + '', '', '', 0 | |
| 55 | +); | |
| 0 | 56 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/vue/StudentContactForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <el-form | |
| 4 | + ref="formRef" | |
| 5 | + :model="formData" | |
| 6 | + :rules="formRules" | |
| 7 | + v-loading="formLoading" | |
| 8 | + label-width="0px" | |
| 9 | + :inline-message="true" | |
| 10 | + > | |
| 11 | + <el-table :data="formData" class="-mt-10px"> | |
| 12 | + <el-table-column label="序号" type="index" width="100" /> | |
| 13 | + <el-table-column label="名字" min-width="150"> | |
| 14 | + <template v-slot="{ row, $index }"> | |
| 15 | + <el-form-item :prop="`${$index}.name`" :rules="formRules.name" class="mb-0px!"> | |
| 16 | + <el-input v-model="row.name" placeholder="请输入名字" /> | |
| 17 | + </el-form-item> | |
| 18 | + </template> | |
| 19 | + </el-table-column> | |
| 20 | + <el-table-column label="简介" min-width="200"> | |
| 21 | + <template v-slot="{ row, $index }"> | |
| 22 | + <el-form-item :prop="`${$index}.description`" :rules="formRules.description" class="mb-0px!"> | |
| 23 | + <el-input v-model="row.description" type="textarea" placeholder="请输入简介" /> | |
| 24 | + </el-form-item> | |
| 25 | + </template> | |
| 26 | + </el-table-column> | |
| 27 | + <el-table-column label="出生日期" min-width="150"> | |
| 28 | + <template v-slot="{ row, $index }"> | |
| 29 | + <el-form-item :prop="`${$index}.birthday`" :rules="formRules.birthday" class="mb-0px!"> | |
| 30 | + <el-date-picker clearable v-model="row.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 31 | + </el-form-item> | |
| 32 | + </template> | |
| 33 | + </el-table-column> | |
| 34 | + <el-table-column label="性别" min-width="150"> | |
| 35 | + <template v-slot="{ row, $index }"> | |
| 36 | + <el-form-item :prop="`${$index}.sex`" :rules="formRules.sex" class="mb-0px!"> | |
| 37 | + <el-select v-model="row.sex" placeholder="请选择性别"> | |
| 38 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 39 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 40 | + </el-select> | |
| 41 | + </el-form-item> | |
| 42 | + </template> | |
| 43 | + </el-table-column> | |
| 44 | + <el-table-column label="是否有效" min-width="150"> | |
| 45 | + <template v-slot="{ row, $index }"> | |
| 46 | + <el-form-item :prop="`${$index}.enabled`" :rules="formRules.enabled" class="mb-0px!"> | |
| 47 | + <el-radio-group v-model="row.enabled"> | |
| 48 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 49 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 50 | + </el-radio-group> | |
| 51 | + </el-form-item> | |
| 52 | + </template> | |
| 53 | + </el-table-column> | |
| 54 | + <el-table-column label="头像" min-width="200"> | |
| 55 | + <template v-slot="{ row, $index }"> | |
| 56 | + <el-form-item :prop="`${$index}.avatar`" :rules="formRules.avatar" class="mb-0px!"> | |
| 57 | + <ImageUpload v-model="row.avatar"/> | |
| 58 | + </el-form-item> | |
| 59 | + </template> | |
| 60 | + </el-table-column> | |
| 61 | + <el-table-column label="附件" min-width="200"> | |
| 62 | + <template v-slot="{ row, $index }"> | |
| 63 | + <el-form-item :prop="`${$index}.video`" :rules="formRules.video" class="mb-0px!"> | |
| 64 | + <FileUpload v-model="row.video"/> | |
| 65 | + </el-form-item> | |
| 66 | + </template> | |
| 67 | + </el-table-column> | |
| 68 | + <el-table-column label="备注" min-width="400"> | |
| 69 | + <template v-slot="{ row, $index }"> | |
| 70 | + <el-form-item :prop="`${$index}.memo`" :rules="formRules.memo" class="mb-0px!"> | |
| 71 | + <Editor v-model="row.memo" :min-height="192"/> | |
| 72 | + </el-form-item> | |
| 73 | + </template> | |
| 74 | + </el-table-column> | |
| 75 | + <el-table-column align="center" fixed="right" label="操作" width="60"> | |
| 76 | + <template v-slot="{ $index }"> | |
| 77 | + <el-link @click="handleDelete($index)">—</el-link> | |
| 78 | + </template> | |
| 79 | + </el-table-column> | |
| 80 | + </el-table> | |
| 81 | + </el-form> | |
| 82 | + <el-row justify="center" class="mt-3"> | |
| 83 | + <el-button @click="handleAdd" round>+ 添加学生联系人</el-button> | |
| 84 | + </el-row> | |
| 85 | + </div> | |
| 86 | +</template> | |
| 87 | + | |
| 88 | +<script> | |
| 89 | + import * as StudentApi from '@/api/infra/demo' | |
| 90 | + import ImageUpload from '@/components/ImageUpload'; | |
| 91 | + import FileUpload from '@/components/FileUpload'; | |
| 92 | + import Editor from '@/components/Editor'; | |
| 93 | + export default { | |
| 94 | + name: "StudentContactForm", | |
| 95 | + components: { | |
| 96 | + ImageUpload, | |
| 97 | + FileUpload, | |
| 98 | + Editor, | |
| 99 | + }, | |
| 100 | + props:[ | |
| 101 | + 'studentId' | |
| 102 | + ],// 学生编号(主表的关联字段) | |
| 103 | + data() { | |
| 104 | + return { | |
| 105 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 106 | + formLoading: false, | |
| 107 | + // 表单参数 | |
| 108 | + formData: [], | |
| 109 | + // 表单校验 | |
| 110 | + formRules: { | |
| 111 | + studentId: [{ required: true, message: "学生编号不能为空", trigger: "blur" }], | |
| 112 | + name: [{ required: true, message: "名字不能为空", trigger: "blur" }], | |
| 113 | + description: [{ required: true, message: "简介不能为空", trigger: "blur" }], | |
| 114 | + birthday: [{ required: true, message: "出生日期不能为空", trigger: "blur" }], | |
| 115 | + sex: [{ required: true, message: "性别不能为空", trigger: "change" }], | |
| 116 | + enabled: [{ required: true, message: "是否有效不能为空", trigger: "blur" }], | |
| 117 | + avatar: [{ required: true, message: "头像不能为空", trigger: "blur" }], | |
| 118 | + memo: [{ required: true, message: "备注不能为空", trigger: "blur" }], | |
| 119 | + }, | |
| 120 | + }; | |
| 121 | + }, | |
| 122 | + watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 123 | + studentId:{ | |
| 124 | + handler(val) { | |
| 125 | + // 1. 重置表单 | |
| 126 | + this.formData = [] | |
| 127 | + // 2. val 非空,则加载数据 | |
| 128 | + if (!val) { | |
| 129 | + return; | |
| 130 | + } | |
| 131 | + try { | |
| 132 | + this.formLoading = true; | |
| 133 | + const that = this; | |
| 134 | + StudentApi.getStudentContactListByStudentId(val).then(res=>{ | |
| 135 | + that.formData = res.data; | |
| 136 | + }) | |
| 137 | + } finally { | |
| 138 | + this.formLoading = false; | |
| 139 | + } | |
| 140 | + }, | |
| 141 | + immediate: true | |
| 142 | + } | |
| 143 | + }, | |
| 144 | + methods: { | |
| 145 | + /** 新增按钮操作 */ | |
| 146 | + handleAdd() { | |
| 147 | + const row = { | |
| 148 | + id: undefined, | |
| 149 | + studentId: undefined, | |
| 150 | + name: undefined, | |
| 151 | + description: undefined, | |
| 152 | + birthday: undefined, | |
| 153 | + sex: undefined, | |
| 154 | + enabled: undefined, | |
| 155 | + avatar: undefined, | |
| 156 | + video: undefined, | |
| 157 | + memo: undefined, | |
| 158 | + } | |
| 159 | + row.studentId = this.studentId | |
| 160 | + this.formData.push(row) | |
| 161 | + }, | |
| 162 | + /** 删除按钮操作 */ | |
| 163 | + handleDelete(index) { | |
| 164 | + this.formData.splice(index, 1) | |
| 165 | + }, | |
| 166 | + /** 表单校验 */ | |
| 167 | + validate(){ | |
| 168 | + return this.$refs["formRef"].validate() | |
| 169 | + }, | |
| 170 | + /** 表单值 */ | |
| 171 | + getData(){ | |
| 172 | + return this.formData | |
| 173 | + } | |
| 174 | + } | |
| 175 | + }; | |
| 176 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/vue/StudentForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 对话框(添加 / 修改) --> | |
| 4 | + <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body> | |
| 5 | + <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px"> | |
| 6 | + <el-form-item label="名字" prop="name"> | |
| 7 | + <el-input v-model="formData.name" placeholder="请输入名字" /> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="简介" prop="description"> | |
| 10 | + <el-input v-model="formData.description" type="textarea" placeholder="请输入内容" /> | |
| 11 | + </el-form-item> | |
| 12 | + <el-form-item label="出生日期" prop="birthday"> | |
| 13 | + <el-date-picker clearable v-model="formData.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 14 | + </el-form-item> | |
| 15 | + <el-form-item label="性别" prop="sex"> | |
| 16 | + <el-select v-model="formData.sex" placeholder="请选择性别"> | |
| 17 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 18 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 19 | + </el-select> | |
| 20 | + </el-form-item> | |
| 21 | + <el-form-item label="是否有效" prop="enabled"> | |
| 22 | + <el-radio-group v-model="formData.enabled"> | |
| 23 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 24 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 25 | + </el-radio-group> | |
| 26 | + </el-form-item> | |
| 27 | + <el-form-item label="头像"> | |
| 28 | + <ImageUpload v-model="formData.avatar"/> | |
| 29 | + </el-form-item> | |
| 30 | + <el-form-item label="附件"> | |
| 31 | + <FileUpload v-model="formData.video"/> | |
| 32 | + </el-form-item> | |
| 33 | + <el-form-item label="备注"> | |
| 34 | + <Editor v-model="formData.memo" :min-height="192"/> | |
| 35 | + </el-form-item> | |
| 36 | + </el-form> | |
| 37 | + <!-- 子表的表单 --> | |
| 38 | + <el-tabs v-model="subTabsName"> | |
| 39 | + <el-tab-pane label="学生联系人" name="studentContact"> | |
| 40 | + <StudentContactForm ref="studentContactFormRef" :student-id="formData.id" /> | |
| 41 | + </el-tab-pane> | |
| 42 | + <el-tab-pane label="学生班主任" name="studentTeacher"> | |
| 43 | + <StudentTeacherForm ref="studentTeacherFormRef" :student-id="formData.id" /> | |
| 44 | + </el-tab-pane> | |
| 45 | + </el-tabs> | |
| 46 | + <div slot="footer" class="dialog-footer"> | |
| 47 | + <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button> | |
| 48 | + <el-button @click="dialogVisible = false">取 消</el-button> | |
| 49 | + </div> | |
| 50 | + </el-dialog> | |
| 51 | + </div> | |
| 52 | +</template> | |
| 53 | + | |
| 54 | +<script> | |
| 55 | + import * as StudentApi from '@/api/infra/demo' | |
| 56 | + import ImageUpload from '@/components/ImageUpload'; | |
| 57 | + import FileUpload from '@/components/FileUpload'; | |
| 58 | + import Editor from '@/components/Editor'; | |
| 59 | + import StudentContactForm from './components/StudentContactForm.vue' | |
| 60 | + import StudentTeacherForm from './components/StudentTeacherForm.vue' | |
| 61 | + export default { | |
| 62 | + name: "StudentForm", | |
| 63 | + components: { | |
| 64 | + ImageUpload, | |
| 65 | + FileUpload, | |
| 66 | + Editor, | |
| 67 | + StudentContactForm, | |
| 68 | + StudentTeacherForm, | |
| 69 | + }, | |
| 70 | + data() { | |
| 71 | + return { | |
| 72 | + // 弹出层标题 | |
| 73 | + dialogTitle: "", | |
| 74 | + // 是否显示弹出层 | |
| 75 | + dialogVisible: false, | |
| 76 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 77 | + formLoading: false, | |
| 78 | + // 表单参数 | |
| 79 | + formData: { | |
| 80 | + id: undefined, | |
| 81 | + name: undefined, | |
| 82 | + description: undefined, | |
| 83 | + birthday: undefined, | |
| 84 | + sex: undefined, | |
| 85 | + enabled: undefined, | |
| 86 | + avatar: undefined, | |
| 87 | + video: undefined, | |
| 88 | + memo: undefined, | |
| 89 | + }, | |
| 90 | + // 表单校验 | |
| 91 | + formRules: { | |
| 92 | + name: [{ required: true, message: '名字不能为空', trigger: 'blur' }], | |
| 93 | + description: [{ required: true, message: '简介不能为空', trigger: 'blur' }], | |
| 94 | + birthday: [{ required: true, message: '出生日期不能为空', trigger: 'blur' }], | |
| 95 | + sex: [{ required: true, message: '性别不能为空', trigger: 'change' }], | |
| 96 | + enabled: [{ required: true, message: '是否有效不能为空', trigger: 'blur' }], | |
| 97 | + avatar: [{ required: true, message: '头像不能为空', trigger: 'blur' }], | |
| 98 | + video: [{ required: true, message: '附件不能为空', trigger: 'blur' }], | |
| 99 | + memo: [{ required: true, message: '备注不能为空', trigger: 'blur' }], | |
| 100 | + }, | |
| 101 | + /** 子表的表单 */ | |
| 102 | + subTabsName: 'studentContact' | |
| 103 | + }; | |
| 104 | + }, | |
| 105 | + methods: { | |
| 106 | + /** 打开弹窗 */ | |
| 107 | + open(id) { | |
| 108 | + this.dialogVisible = true; | |
| 109 | + this.reset(); | |
| 110 | + const that = this; | |
| 111 | + // 修改时,设置数据 | |
| 112 | + if (id) { | |
| 113 | + this.formLoading = true; | |
| 114 | + try { | |
| 115 | + StudentApi.getStudent(id).then(res=>{ | |
| 116 | + that.formData = res.data; | |
| 117 | + that.title = "修改学生"; | |
| 118 | + }) | |
| 119 | + } finally { | |
| 120 | + this.formLoading = false; | |
| 121 | + } | |
| 122 | + } | |
| 123 | + this.title = "新增学生"; | |
| 124 | + }, | |
| 125 | + /** 提交按钮 */ | |
| 126 | + submitForm() { | |
| 127 | + this.formLoading = true; | |
| 128 | + try { | |
| 129 | + const that = this; | |
| 130 | + let data = this.formData; | |
| 131 | + let validate = false; | |
| 132 | + // 校验主表 | |
| 133 | + this.getRef("formRef").validate(valid => { | |
| 134 | + validate = valid; | |
| 135 | + }); | |
| 136 | + // 校验子表 | |
| 137 | + this.validateSubFrom01().then(() => { | |
| 138 | + // 全部校验通过-拼接子表的数据 | |
| 139 | + // 拼接子表的数据 | |
| 140 | + data.studentContacts = that.getRef('studentContactFormRef').getData(); | |
| 141 | + data.studentTeacher = that.getRef('studentTeacherFormRef').getData(); | |
| 142 | + }).catch((err) => { | |
| 143 | + validate = false; | |
| 144 | + that.subTabsName = err.replace("FormRef", ""); // 定位到没有校验通过的子表单 | |
| 145 | + }) | |
| 146 | + // 所有表单校验通过后方可提交 | |
| 147 | + if (!validate) { | |
| 148 | + return; | |
| 149 | + } | |
| 150 | + // 修改的提交 | |
| 151 | + if (data.id) { | |
| 152 | + StudentApi.updateStudent(data).then(response => { | |
| 153 | + that.$modal.msgSuccess("修改成功"); | |
| 154 | + that.dialogVisible = false; | |
| 155 | + that.$emit('success'); | |
| 156 | + }); | |
| 157 | + return; | |
| 158 | + } | |
| 159 | + // 添加的提交 | |
| 160 | + StudentApi.createStudent(data).then(response => { | |
| 161 | + that.$modal.msgSuccess("新增成功"); | |
| 162 | + that.dialogVisible = false; | |
| 163 | + that.$emit('success'); | |
| 164 | + }); | |
| 165 | + }finally { | |
| 166 | + this.formLoading = false; | |
| 167 | + } | |
| 168 | + }, | |
| 169 | + getRef(refName){ | |
| 170 | + return this.$refs[refName]; | |
| 171 | + }, | |
| 172 | + /** 校验子表单 */ | |
| 173 | + validateSubFrom(item) { | |
| 174 | + return new Promise((resolve, reject) => { | |
| 175 | + this.getRef(item).validate() | |
| 176 | + .then(() => { | |
| 177 | + resolve(); | |
| 178 | + }) | |
| 179 | + .catch(() => { | |
| 180 | + reject(item); | |
| 181 | + }) | |
| 182 | + }) | |
| 183 | + }, | |
| 184 | + /** 校验所有子表单 */ | |
| 185 | + validateSubFrom01() { | |
| 186 | + // 需要校验的表单 ref | |
| 187 | + const validFormRefArr = [ | |
| 188 | + "studentContactFormRef", | |
| 189 | + "studentTeacherFormRef", | |
| 190 | + ]; | |
| 191 | + const validArr = []; // 校验 | |
| 192 | + for (const item of validFormRefArr) { | |
| 193 | + validArr.push(this.validateSubFrom(item)); | |
| 194 | + } | |
| 195 | + return new Promise((resolve, reject) => { | |
| 196 | + // 校验所有 | |
| 197 | + Promise.all(validArr).then(() => { | |
| 198 | + resolve(); | |
| 199 | + }).catch((err) => { | |
| 200 | + reject(err); | |
| 201 | + }) | |
| 202 | + }) | |
| 203 | + }, | |
| 204 | + /** 表单重置 */ | |
| 205 | + reset() { | |
| 206 | + this.formData = { | |
| 207 | + id: undefined, | |
| 208 | + name: undefined, | |
| 209 | + description: undefined, | |
| 210 | + birthday: undefined, | |
| 211 | + sex: undefined, | |
| 212 | + enabled: undefined, | |
| 213 | + avatar: undefined, | |
| 214 | + video: undefined, | |
| 215 | + memo: undefined, | |
| 216 | + }; | |
| 217 | + this.resetForm("formRef"); | |
| 218 | + }, | |
| 219 | + } | |
| 220 | + }; | |
| 221 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/vue/StudentTeacherForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <el-form | |
| 4 | + ref="formRef" | |
| 5 | + :model="formData" | |
| 6 | + :rules="formRules" | |
| 7 | + label-width="100px" | |
| 8 | + v-loading="formLoading" | |
| 9 | + > | |
| 10 | + <el-form-item label="名字" prop="name"> | |
| 11 | + <el-input v-model="formData.name" placeholder="请输入名字" /> | |
| 12 | + </el-form-item> | |
| 13 | + <el-form-item label="简介" prop="description"> | |
| 14 | + <el-input v-model="formData.description" type="textarea" placeholder="请输入简介" /> | |
| 15 | + </el-form-item> | |
| 16 | + <el-form-item label="出生日期" prop="birthday"> | |
| 17 | + <el-date-picker clearable v-model="formData.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 18 | + </el-form-item> | |
| 19 | + <el-form-item label="性别" prop="sex"> | |
| 20 | + <el-select v-model="formData.sex" placeholder="请选择性别"> | |
| 21 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 22 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 23 | + </el-select> | |
| 24 | + </el-form-item> | |
| 25 | + <el-form-item label="是否有效" prop="enabled"> | |
| 26 | + <el-radio-group v-model="formData.enabled"> | |
| 27 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 28 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 29 | + </el-radio-group> | |
| 30 | + </el-form-item> | |
| 31 | + <el-form-item label="头像"> | |
| 32 | + <ImageUpload v-model="formData.avatar"/> | |
| 33 | + </el-form-item> | |
| 34 | + <el-form-item label="附件"> | |
| 35 | + <FileUpload v-model="formData.video"/> | |
| 36 | + </el-form-item> | |
| 37 | + <el-form-item label="备注"> | |
| 38 | + <Editor v-model="formData.memo" :min-height="192"/> | |
| 39 | + </el-form-item> | |
| 40 | + </el-form> | |
| 41 | + </div> | |
| 42 | +</template> | |
| 43 | + | |
| 44 | +<script> | |
| 45 | + import * as StudentApi from '@/api/infra/demo' | |
| 46 | + import ImageUpload from '@/components/ImageUpload'; | |
| 47 | + import FileUpload from '@/components/FileUpload'; | |
| 48 | + import Editor from '@/components/Editor'; | |
| 49 | + export default { | |
| 50 | + name: "StudentTeacherForm", | |
| 51 | + components: { | |
| 52 | + ImageUpload, | |
| 53 | + FileUpload, | |
| 54 | + Editor, | |
| 55 | + }, | |
| 56 | + props:[ | |
| 57 | + 'studentId' | |
| 58 | + ],// 学生编号(主表的关联字段) | |
| 59 | + data() { | |
| 60 | + return { | |
| 61 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 62 | + formLoading: false, | |
| 63 | + // 表单参数 | |
| 64 | + formData: [], | |
| 65 | + // 表单校验 | |
| 66 | + formRules: { | |
| 67 | + studentId: [{ required: true, message: "学生编号不能为空", trigger: "blur" }], | |
| 68 | + name: [{ required: true, message: "名字不能为空", trigger: "blur" }], | |
| 69 | + description: [{ required: true, message: "简介不能为空", trigger: "blur" }], | |
| 70 | + birthday: [{ required: true, message: "出生日期不能为空", trigger: "blur" }], | |
| 71 | + sex: [{ required: true, message: "性别不能为空", trigger: "change" }], | |
| 72 | + enabled: [{ required: true, message: "是否有效不能为空", trigger: "blur" }], | |
| 73 | + avatar: [{ required: true, message: "头像不能为空", trigger: "blur" }], | |
| 74 | + memo: [{ required: true, message: "备注不能为空", trigger: "blur" }], | |
| 75 | + }, | |
| 76 | + }; | |
| 77 | + }, | |
| 78 | + watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 79 | + studentId:{ | |
| 80 | + handler(val) { | |
| 81 | + // 1. 重置表单 | |
| 82 | + this.formData = { | |
| 83 | + id: undefined, | |
| 84 | + studentId: undefined, | |
| 85 | + name: undefined, | |
| 86 | + description: undefined, | |
| 87 | + birthday: undefined, | |
| 88 | + sex: undefined, | |
| 89 | + enabled: undefined, | |
| 90 | + avatar: undefined, | |
| 91 | + video: undefined, | |
| 92 | + memo: undefined, | |
| 93 | + } | |
| 94 | + // 2. val 非空,则加载数据 | |
| 95 | + if (!val) { | |
| 96 | + return; | |
| 97 | + } | |
| 98 | + try { | |
| 99 | + this.formLoading = true; | |
| 100 | + const that = this; | |
| 101 | + StudentApi.getStudentTeacherByStudentId(val).then(res=>{ | |
| 102 | + const data = res.data; | |
| 103 | + if (!data) { | |
| 104 | + return | |
| 105 | + } | |
| 106 | + that.formData = data; | |
| 107 | + }) | |
| 108 | + } finally { | |
| 109 | + this.formLoading = false; | |
| 110 | + } | |
| 111 | + }, | |
| 112 | + immediate: true | |
| 113 | + } | |
| 114 | + }, | |
| 115 | + methods: { | |
| 116 | + /** 表单校验 */ | |
| 117 | + validate(){ | |
| 118 | + return this.$refs["formRef"].validate() | |
| 119 | + }, | |
| 120 | + /** 表单值 */ | |
| 121 | + getData(){ | |
| 122 | + return this.formData | |
| 123 | + } | |
| 124 | + } | |
| 125 | + }; | |
| 126 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/vue/index
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + | |
| 4 | + <!-- 搜索工作栏 --> | |
| 5 | + <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> | |
| 6 | + <el-form-item label="名字" prop="name"> | |
| 7 | + <el-input v-model="queryParams.name" placeholder="请输入名字" clearable @keyup.enter.native="handleQuery"/> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="出生日期" prop="birthday"> | |
| 10 | + <el-date-picker clearable v-model="queryParams.birthday" type="date" value-format="yyyy-MM-dd" placeholder="选择出生日期" /> | |
| 11 | + </el-form-item> | |
| 12 | + <el-form-item label="性别" prop="sex"> | |
| 13 | + <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable size="small"> | |
| 14 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 15 | + :key="dict.value" :label="dict.label" :value="dict.value"/> | |
| 16 | + </el-select> | |
| 17 | + </el-form-item> | |
| 18 | + <el-form-item label="是否有效" prop="enabled"> | |
| 19 | + <el-select v-model="queryParams.enabled" placeholder="请选择是否有效" clearable size="small"> | |
| 20 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 21 | + :key="dict.value" :label="dict.label" :value="dict.value"/> | |
| 22 | + </el-select> | |
| 23 | + </el-form-item> | |
| 24 | + <el-form-item label="创建时间" prop="createTime"> | |
| 25 | + <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange" | |
| 26 | + range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" /> | |
| 27 | + </el-form-item> | |
| 28 | + <el-form-item> | |
| 29 | + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button> | |
| 30 | + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button> | |
| 31 | + </el-form-item> | |
| 32 | + </el-form> | |
| 33 | + | |
| 34 | + <!-- 操作工具栏 --> | |
| 35 | + <el-row :gutter="10" class="mb8"> | |
| 36 | + <el-col :span="1.5"> | |
| 37 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)" | |
| 38 | + v-hasPermi="['infra:student:create']">新增</el-button> | |
| 39 | + </el-col> | |
| 40 | + <el-col :span="1.5"> | |
| 41 | + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading" | |
| 42 | + v-hasPermi="['infra:student:export']">导出</el-button> | |
| 43 | + </el-col> | |
| 44 | + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | |
| 45 | + </el-row> | |
| 46 | + | |
| 47 | + <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | |
| 48 | + <el-table-column label="编号" align="center" prop="id"> | |
| 49 | + <template v-slot="scope"> | |
| 50 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.id" /> | |
| 51 | + </template> | |
| 52 | + </el-table-column> | |
| 53 | + <el-table-column label="名字" align="center" prop="name"> | |
| 54 | + <template v-slot="scope"> | |
| 55 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.name" /> | |
| 56 | + </template> | |
| 57 | + </el-table-column> | |
| 58 | + <el-table-column label="简介" align="center" prop="description"> | |
| 59 | + <template v-slot="scope"> | |
| 60 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.description" /> | |
| 61 | + </template> | |
| 62 | + </el-table-column> | |
| 63 | + <el-table-column label="出生日期" align="center" prop="birthday" width="180"> | |
| 64 | + <template v-slot="scope"> | |
| 65 | + <span>{{ parseTime(scope.row.birthday) }}</span> | |
| 66 | + </template> | |
| 67 | + </el-table-column> | |
| 68 | + <el-table-column label="性别" align="center" prop="sex"> | |
| 69 | + <template v-slot="scope"> | |
| 70 | + <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" /> | |
| 71 | + </template> | |
| 72 | + </el-table-column> | |
| 73 | + <el-table-column label="是否有效" align="center" prop="enabled"> | |
| 74 | + <template v-slot="scope"> | |
| 75 | + <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" /> | |
| 76 | + </template> | |
| 77 | + </el-table-column> | |
| 78 | + <el-table-column label="头像" align="center" prop="avatar"> | |
| 79 | + <template v-slot="scope"> | |
| 80 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.avatar" /> | |
| 81 | + </template> | |
| 82 | + </el-table-column> | |
| 83 | + <el-table-column label="附件" align="center" prop="video"> | |
| 84 | + <template v-slot="scope"> | |
| 85 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.video" /> | |
| 86 | + </template> | |
| 87 | + </el-table-column> | |
| 88 | + <el-table-column label="备注" align="center" prop="memo"> | |
| 89 | + <template v-slot="scope"> | |
| 90 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.memo" /> | |
| 91 | + </template> | |
| 92 | + </el-table-column> | |
| 93 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 94 | + <template v-slot="scope"> | |
| 95 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 96 | + </template> | |
| 97 | + </el-table-column> | |
| 98 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 99 | + <template v-slot="scope"> | |
| 100 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)" | |
| 101 | + v-hasPermi="['infra:student:update']">修改</el-button> | |
| 102 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 103 | + v-hasPermi="['infra:student:delete']">删除</el-button> | |
| 104 | + </template> | |
| 105 | + </el-table-column> | |
| 106 | + </el-table> | |
| 107 | + <!-- 分页组件 --> | |
| 108 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | |
| 109 | + @pagination="getList"/> | |
| 110 | + <!-- 对话框(添加 / 修改) --> | |
| 111 | + <StudentForm ref="formRef" @success="getList" /> | |
| 112 | + </div> | |
| 113 | +</template> | |
| 114 | + | |
| 115 | +<script> | |
| 116 | +import * as StudentApi from '@/api/infra/demo'; | |
| 117 | +import StudentForm from './StudentForm.vue'; | |
| 118 | +export default { | |
| 119 | + name: "Student", | |
| 120 | + components: { | |
| 121 | + StudentForm, | |
| 122 | + }, | |
| 123 | + data() { | |
| 124 | + return { | |
| 125 | + // 遮罩层 | |
| 126 | + loading: true, | |
| 127 | + // 导出遮罩层 | |
| 128 | + exportLoading: false, | |
| 129 | + // 显示搜索条件 | |
| 130 | + showSearch: true, | |
| 131 | + // 总条数 | |
| 132 | + total: 0, | |
| 133 | + // 学生列表 | |
| 134 | + list: [], | |
| 135 | + // 是否展开,默认全部展开 | |
| 136 | + isExpandAll: true, | |
| 137 | + // 重新渲染表格状态 | |
| 138 | + refreshTable: true, | |
| 139 | + // 选中行 | |
| 140 | + currentRow: {}, | |
| 141 | + // 查询参数 | |
| 142 | + queryParams: { | |
| 143 | + pageNo: 1, | |
| 144 | + pageSize: 10, | |
| 145 | + name: null, | |
| 146 | + birthday: null, | |
| 147 | + sex: null, | |
| 148 | + enabled: null, | |
| 149 | + createTime: [], | |
| 150 | + }, | |
| 151 | + }; | |
| 152 | + }, | |
| 153 | + created() { | |
| 154 | + this.getList(); | |
| 155 | + }, | |
| 156 | + methods: { | |
| 157 | + /** 查询列表 */ | |
| 158 | + getList() { | |
| 159 | + try { | |
| 160 | + this.loading = true; | |
| 161 | + StudentApi.getStudentPage(this.queryParams).then(response => { | |
| 162 | + this.list = response.data.list; | |
| 163 | + this.total = response.data.total; | |
| 164 | + }); | |
| 165 | + } finally { | |
| 166 | + this.loading = false; | |
| 167 | + } | |
| 168 | + }, | |
| 169 | + /** 搜索按钮操作 */ | |
| 170 | + handleQuery() { | |
| 171 | + this.queryParams.pageNo = 1; | |
| 172 | + this.getList(); | |
| 173 | + }, | |
| 174 | + /** 重置按钮操作 */ | |
| 175 | + resetQuery() { | |
| 176 | + this.resetForm("queryForm"); | |
| 177 | + this.handleQuery(); | |
| 178 | + }, | |
| 179 | + /** 添加/修改操作 */ | |
| 180 | + openForm(id) { | |
| 181 | + this.$refs["formRef"].open(id); | |
| 182 | + }, | |
| 183 | + /** 删除按钮操作 */ | |
| 184 | + handleDelete(row) { | |
| 185 | + const that = this; | |
| 186 | + try { | |
| 187 | + const id = row.id; | |
| 188 | + this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?').then(()=>{ | |
| 189 | + return StudentApi.deleteStudent(id); | |
| 190 | + }).then(() => { | |
| 191 | + that.getList(); | |
| 192 | + that.$modal.msgSuccess("删除成功"); | |
| 193 | + }).catch(() => {}); | |
| 194 | + } catch {} | |
| 195 | + }, | |
| 196 | + /** 导出按钮操作 */ | |
| 197 | + handleExport() { | |
| 198 | + const that = this; | |
| 199 | + try { | |
| 200 | + this.$modal.confirm('是否确认导出所有学生数据项?').then(() => { | |
| 201 | + that.exportLoading = true; | |
| 202 | + return StudentApi.exportStudentExcel(params); | |
| 203 | + }).then(response => { | |
| 204 | + that.$download.excel(response, '学生.xls'); | |
| 205 | + }); | |
| 206 | + } catch { | |
| 207 | + } finally { | |
| 208 | + that.exportLoading = false; | |
| 209 | + } | |
| 210 | + }, | |
| 211 | + } | |
| 212 | +}; | |
| 213 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/xml/InfraStudentMapper
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 3 | +<mapper namespace="cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper"> | |
| 4 | + | |
| 5 | + <!-- | |
| 6 | + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 | |
| 7 | + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 | |
| 8 | + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 | |
| 9 | + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ | |
| 10 | + --> | |
| 11 | + | |
| 12 | +</mapper> | |
| 0 | 13 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/assert.json
0 → 100644
| 1 | +[ { | |
| 2 | + "contentPath" : "java/InfraStudentPageReqVO", | |
| 3 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentPageReqVO.java" | |
| 4 | +}, { | |
| 5 | + "contentPath" : "java/InfraStudentRespVO", | |
| 6 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentRespVO.java" | |
| 7 | +}, { | |
| 8 | + "contentPath" : "java/InfraStudentSaveReqVO", | |
| 9 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentSaveReqVO.java" | |
| 10 | +}, { | |
| 11 | + "contentPath" : "java/InfraStudentController", | |
| 12 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/InfraStudentController.java" | |
| 13 | +}, { | |
| 14 | + "contentPath" : "java/InfraStudentDO", | |
| 15 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentDO.java" | |
| 16 | +}, { | |
| 17 | + "contentPath" : "java/InfraStudentMapper", | |
| 18 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentMapper.java" | |
| 19 | +}, { | |
| 20 | + "contentPath" : "xml/InfraStudentMapper", | |
| 21 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/resources/mapper/demo/InfraStudentMapper.xml" | |
| 22 | +}, { | |
| 23 | + "contentPath" : "java/InfraStudentServiceImpl", | |
| 24 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentServiceImpl.java" | |
| 25 | +}, { | |
| 26 | + "contentPath" : "java/InfraStudentService", | |
| 27 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentService.java" | |
| 28 | +}, { | |
| 29 | + "contentPath" : "java/InfraStudentServiceImplTest", | |
| 30 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentServiceImplTest.java" | |
| 31 | +}, { | |
| 32 | + "contentPath" : "java/ErrorCodeConstants_手动操作", | |
| 33 | + "filePath" : "yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants_手动操作.java" | |
| 34 | +}, { | |
| 35 | + "contentPath" : "sql/sql", | |
| 36 | + "filePath" : "sql/sql.sql" | |
| 37 | +}, { | |
| 38 | + "contentPath" : "sql/h2", | |
| 39 | + "filePath" : "sql/h2.sql" | |
| 40 | +}, { | |
| 41 | + "contentPath" : "vue/index", | |
| 42 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/index.vue" | |
| 43 | +}, { | |
| 44 | + "contentPath" : "js/student", | |
| 45 | + "filePath" : "yudao-ui-admin-vue2/src/api/infra/student.js" | |
| 46 | +}, { | |
| 47 | + "contentPath" : "vue/StudentForm", | |
| 48 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/StudentForm.vue" | |
| 49 | +} ] | |
| 0 | 50 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/ErrorCodeConstants_手动操作
0 → 100644
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/InfraStudentController
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo; | |
| 2 | + | |
| 3 | +import org.springframework.web.bind.annotation.*; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 7 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 8 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 9 | +import io.swagger.v3.oas.annotations.Operation; | |
| 10 | + | |
| 11 | +import javax.validation.constraints.*; | |
| 12 | +import javax.validation.*; | |
| 13 | +import javax.servlet.http.*; | |
| 14 | +import java.util.*; | |
| 15 | +import java.io.IOException; | |
| 16 | + | |
| 17 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 18 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 19 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 20 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 21 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 22 | + | |
| 23 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 24 | + | |
| 25 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 26 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | |
| 27 | + | |
| 28 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 29 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 30 | +import cn.iocoder.yudao.module.infra.service.demo.InfraStudentService; | |
| 31 | + | |
| 32 | +@Tag(name = "管理后台 - 学生") | |
| 33 | +@RestController | |
| 34 | +@RequestMapping("/infra/student") | |
| 35 | +@Validated | |
| 36 | +public class InfraStudentController { | |
| 37 | + | |
| 38 | + @Resource | |
| 39 | + private InfraStudentService studentService; | |
| 40 | + | |
| 41 | + @PostMapping("/create") | |
| 42 | + @Operation(summary = "创建学生") | |
| 43 | + @PreAuthorize("@ss.hasPermission('infra:student:create')") | |
| 44 | + public CommonResult<Long> createStudent(@Valid @RequestBody InfraStudentSaveReqVO createReqVO) { | |
| 45 | + return success(studentService.createStudent(createReqVO)); | |
| 46 | + } | |
| 47 | + | |
| 48 | + @PutMapping("/update") | |
| 49 | + @Operation(summary = "更新学生") | |
| 50 | + @PreAuthorize("@ss.hasPermission('infra:student:update')") | |
| 51 | + public CommonResult<Boolean> updateStudent(@Valid @RequestBody InfraStudentSaveReqVO updateReqVO) { | |
| 52 | + studentService.updateStudent(updateReqVO); | |
| 53 | + return success(true); | |
| 54 | + } | |
| 55 | + | |
| 56 | + @DeleteMapping("/delete") | |
| 57 | + @Operation(summary = "删除学生") | |
| 58 | + @Parameter(name = "id", description = "编号", required = true) | |
| 59 | + @PreAuthorize("@ss.hasPermission('infra:student:delete')") | |
| 60 | + public CommonResult<Boolean> deleteStudent(@RequestParam("id") Long id) { | |
| 61 | + studentService.deleteStudent(id); | |
| 62 | + return success(true); | |
| 63 | + } | |
| 64 | + | |
| 65 | + @GetMapping("/get") | |
| 66 | + @Operation(summary = "获得学生") | |
| 67 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 68 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 69 | + public CommonResult<InfraStudentRespVO> getStudent(@RequestParam("id") Long id) { | |
| 70 | + InfraStudentDO student = studentService.getStudent(id); | |
| 71 | + return success(BeanUtils.toBean(student, InfraStudentRespVO.class)); | |
| 72 | + } | |
| 73 | + | |
| 74 | + @GetMapping("/page") | |
| 75 | + @Operation(summary = "获得学生分页") | |
| 76 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 77 | + public CommonResult<PageResult<InfraStudentRespVO>> getStudentPage(@Valid InfraStudentPageReqVO pageReqVO) { | |
| 78 | + PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(pageReqVO); | |
| 79 | + return success(BeanUtils.toBean(pageResult, InfraStudentRespVO.class)); | |
| 80 | + } | |
| 81 | + | |
| 82 | + @GetMapping("/export-excel") | |
| 83 | + @Operation(summary = "导出学生 Excel") | |
| 84 | + @PreAuthorize("@ss.hasPermission('infra:student:export')") | |
| 85 | + @OperateLog(type = EXPORT) | |
| 86 | + public void exportStudentExcel(@Valid InfraStudentPageReqVO pageReqVO, | |
| 87 | + HttpServletResponse response) throws IOException { | |
| 88 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 89 | + List<InfraStudentDO> list = studentService.getStudentPage(pageReqVO).getList(); | |
| 90 | + // 导出 Excel | |
| 91 | + ExcelUtils.write(response, "学生.xls", "数据", InfraStudentRespVO.class, | |
| 92 | + BeanUtils.toBean(list, InfraStudentRespVO.class)); | |
| 93 | + } | |
| 94 | + | |
| 95 | +} | |
| 0 | 96 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/InfraStudentDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student") | |
| 16 | +@KeySequence("infra_student_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 名字 | |
| 32 | + */ | |
| 33 | + private String name; | |
| 34 | + /** | |
| 35 | + * 简介 | |
| 36 | + */ | |
| 37 | + private String description; | |
| 38 | + /** | |
| 39 | + * 出生日期 | |
| 40 | + */ | |
| 41 | + private LocalDateTime birthday; | |
| 42 | + /** | |
| 43 | + * 性别 | |
| 44 | + * | |
| 45 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 46 | + */ | |
| 47 | + private Integer sex; | |
| 48 | + /** | |
| 49 | + * 是否有效 | |
| 50 | + * | |
| 51 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 52 | + */ | |
| 53 | + private Boolean enabled; | |
| 54 | + /** | |
| 55 | + * 头像 | |
| 56 | + */ | |
| 57 | + private String avatar; | |
| 58 | + /** | |
| 59 | + * 附件 | |
| 60 | + */ | |
| 61 | + private String video; | |
| 62 | + /** | |
| 63 | + * 备注 | |
| 64 | + */ | |
| 65 | + private String memo; | |
| 66 | + | |
| 67 | +} | |
| 0 | 68 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/InfraStudentMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 9 | +import org.apache.ibatis.annotations.Mapper; | |
| 10 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentMapper extends BaseMapperX<InfraStudentDO> { | |
| 19 | + | |
| 20 | + default PageResult<InfraStudentDO> selectPage(InfraStudentPageReqVO reqVO) { | |
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<InfraStudentDO>() | |
| 22 | + .likeIfPresent(InfraStudentDO::getName, reqVO.getName()) | |
| 23 | + .eqIfPresent(InfraStudentDO::getBirthday, reqVO.getBirthday()) | |
| 24 | + .eqIfPresent(InfraStudentDO::getSex, reqVO.getSex()) | |
| 25 | + .eqIfPresent(InfraStudentDO::getEnabled, reqVO.getEnabled()) | |
| 26 | + .betweenIfPresent(InfraStudentDO::getCreateTime, reqVO.getCreateTime()) | |
| 27 | + .orderByDesc(InfraStudentDO::getId)); | |
| 28 | + } | |
| 29 | + | |
| 30 | +} | |
| 0 | 31 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/InfraStudentPageReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 11 | + | |
| 12 | +@Schema(description = "管理后台 - 学生分页 Request VO") | |
| 13 | +@Data | |
| 14 | +@EqualsAndHashCode(callSuper = true) | |
| 15 | +@ToString(callSuper = true) | |
| 16 | +public class InfraStudentPageReqVO extends PageParam { | |
| 17 | + | |
| 18 | + @Schema(description = "名字", example = "芋头") | |
| 19 | + private String name; | |
| 20 | + | |
| 21 | + @Schema(description = "出生日期") | |
| 22 | + private LocalDateTime birthday; | |
| 23 | + | |
| 24 | + @Schema(description = "性别", example = "1") | |
| 25 | + private Integer sex; | |
| 26 | + | |
| 27 | + @Schema(description = "是否有效", example = "true") | |
| 28 | + private Boolean enabled; | |
| 29 | + | |
| 30 | + @Schema(description = "创建时间") | |
| 31 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 32 | + private LocalDateTime[] createTime; | |
| 33 | + | |
| 34 | +} | |
| 0 | 35 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/InfraStudentRespVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import java.util.*; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | +import com.alibaba.excel.annotation.*; | |
| 10 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 11 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - 学生 Response VO") | |
| 14 | +@Data | |
| 15 | +@ExcelIgnoreUnannotated | |
| 16 | +public class InfraStudentRespVO { | |
| 17 | + | |
| 18 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 19 | + @ExcelProperty("编号") | |
| 20 | + private Long id; | |
| 21 | + | |
| 22 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 23 | + @ExcelProperty("名字") | |
| 24 | + private String name; | |
| 25 | + | |
| 26 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍") | |
| 27 | + @ExcelProperty("简介") | |
| 28 | + private String description; | |
| 29 | + | |
| 30 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 31 | + @ExcelProperty("出生日期") | |
| 32 | + private LocalDateTime birthday; | |
| 33 | + | |
| 34 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 35 | + @ExcelProperty(value = "性别", converter = DictConvert.class) | |
| 36 | + @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 37 | + private Integer sex; | |
| 38 | + | |
| 39 | + @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 40 | + @ExcelProperty(value = "是否有效", converter = DictConvert.class) | |
| 41 | + @DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 42 | + private Boolean enabled; | |
| 43 | + | |
| 44 | + @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 45 | + @ExcelProperty("头像") | |
| 46 | + private String avatar; | |
| 47 | + | |
| 48 | + @Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.mp4") | |
| 49 | + @ExcelProperty("附件") | |
| 50 | + private String video; | |
| 51 | + | |
| 52 | + @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注") | |
| 53 | + @ExcelProperty("备注") | |
| 54 | + private String memo; | |
| 55 | + | |
| 56 | + @Schema(description = "创建时间") | |
| 57 | + @ExcelProperty("创建时间") | |
| 58 | + private LocalDateTime createTime; | |
| 59 | + | |
| 60 | +} | |
| 0 | 61 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/InfraStudentSaveReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import javax.validation.constraints.*; | |
| 7 | +import java.util.*; | |
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | +import java.time.LocalDateTime; | |
| 10 | + | |
| 11 | +@Schema(description = "管理后台 - 学生新增/修改 Request VO") | |
| 12 | +@Data | |
| 13 | +public class InfraStudentSaveReqVO { | |
| 14 | + | |
| 15 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 16 | + private Long id; | |
| 17 | + | |
| 18 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 19 | + @NotEmpty(message = "名字不能为空") | |
| 20 | + private String name; | |
| 21 | + | |
| 22 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍") | |
| 23 | + @NotEmpty(message = "简介不能为空") | |
| 24 | + private String description; | |
| 25 | + | |
| 26 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 27 | + @NotNull(message = "出生日期不能为空") | |
| 28 | + private LocalDateTime birthday; | |
| 29 | + | |
| 30 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 31 | + @NotNull(message = "性别不能为空") | |
| 32 | + private Integer sex; | |
| 33 | + | |
| 34 | + @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 35 | + @NotNull(message = "是否有效不能为空") | |
| 36 | + private Boolean enabled; | |
| 37 | + | |
| 38 | + @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 39 | + @NotEmpty(message = "头像不能为空") | |
| 40 | + private String avatar; | |
| 41 | + | |
| 42 | + @Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.mp4") | |
| 43 | + @NotEmpty(message = "附件不能为空") | |
| 44 | + private String video; | |
| 45 | + | |
| 46 | + @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注") | |
| 47 | + @NotEmpty(message = "备注不能为空") | |
| 48 | + private String memo; | |
| 49 | + | |
| 50 | +} | |
| 0 | 51 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/InfraStudentService
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | +import javax.validation.*; | |
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 6 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 7 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 8 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生 Service 接口 | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +public interface InfraStudentService { | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * 创建学生 | |
| 19 | + * | |
| 20 | + * @param createReqVO 创建信息 | |
| 21 | + * @return 编号 | |
| 22 | + */ | |
| 23 | + Long createStudent(@Valid InfraStudentSaveReqVO createReqVO); | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 更新学生 | |
| 27 | + * | |
| 28 | + * @param updateReqVO 更新信息 | |
| 29 | + */ | |
| 30 | + void updateStudent(@Valid InfraStudentSaveReqVO updateReqVO); | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * 删除学生 | |
| 34 | + * | |
| 35 | + * @param id 编号 | |
| 36 | + */ | |
| 37 | + void deleteStudent(Long id); | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * 获得学生 | |
| 41 | + * | |
| 42 | + * @param id 编号 | |
| 43 | + * @return 学生 | |
| 44 | + */ | |
| 45 | + InfraStudentDO getStudent(Long id); | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * 获得学生分页 | |
| 49 | + * | |
| 50 | + * @param pageReqVO 分页查询 | |
| 51 | + * @return 学生分页 | |
| 52 | + */ | |
| 53 | + PageResult<InfraStudentDO> getStudentPage(InfraStudentPageReqVO pageReqVO); | |
| 54 | + | |
| 55 | +} | |
| 0 | 56 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/InfraStudentServiceImpl
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import org.springframework.stereotype.Service; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.transaction.annotation.Transactional; | |
| 7 | + | |
| 8 | +import java.util.*; | |
| 9 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 11 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 12 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 13 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 14 | + | |
| 15 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper; | |
| 16 | + | |
| 17 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 18 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 19 | + | |
| 20 | +/** | |
| 21 | + * 学生 Service 实现类 | |
| 22 | + * | |
| 23 | + * @author 芋道源码 | |
| 24 | + */ | |
| 25 | +@Service | |
| 26 | +@Validated | |
| 27 | +public class InfraStudentServiceImpl implements InfraStudentService { | |
| 28 | + | |
| 29 | + @Resource | |
| 30 | + private InfraStudentMapper studentMapper; | |
| 31 | + | |
| 32 | + @Override | |
| 33 | + public Long createStudent(InfraStudentSaveReqVO createReqVO) { | |
| 34 | + // 插入 | |
| 35 | + InfraStudentDO student = BeanUtils.toBean(createReqVO, InfraStudentDO.class); | |
| 36 | + studentMapper.insert(student); | |
| 37 | + // 返回 | |
| 38 | + return student.getId(); | |
| 39 | + } | |
| 40 | + | |
| 41 | + @Override | |
| 42 | + public void updateStudent(InfraStudentSaveReqVO updateReqVO) { | |
| 43 | + // 校验存在 | |
| 44 | + validateStudentExists(updateReqVO.getId()); | |
| 45 | + // 更新 | |
| 46 | + InfraStudentDO updateObj = BeanUtils.toBean(updateReqVO, InfraStudentDO.class); | |
| 47 | + studentMapper.updateById(updateObj); | |
| 48 | + } | |
| 49 | + | |
| 50 | + @Override | |
| 51 | + public void deleteStudent(Long id) { | |
| 52 | + // 校验存在 | |
| 53 | + validateStudentExists(id); | |
| 54 | + // 删除 | |
| 55 | + studentMapper.deleteById(id); | |
| 56 | + } | |
| 57 | + | |
| 58 | + private void validateStudentExists(Long id) { | |
| 59 | + if (studentMapper.selectById(id) == null) { | |
| 60 | + throw exception(STUDENT_NOT_EXISTS); | |
| 61 | + } | |
| 62 | + } | |
| 63 | + | |
| 64 | + @Override | |
| 65 | + public InfraStudentDO getStudent(Long id) { | |
| 66 | + return studentMapper.selectById(id); | |
| 67 | + } | |
| 68 | + | |
| 69 | + @Override | |
| 70 | + public PageResult<InfraStudentDO> getStudentPage(InfraStudentPageReqVO pageReqVO) { | |
| 71 | + return studentMapper.selectPage(pageReqVO); | |
| 72 | + } | |
| 73 | + | |
| 74 | +} | |
| 0 | 75 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/InfraStudentServiceImplTest
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import org.junit.jupiter.api.Disabled; | |
| 4 | +import org.junit.jupiter.api.Test; | |
| 5 | +import org.springframework.boot.test.mock.mockito.MockBean; | |
| 6 | + | |
| 7 | +import javax.annotation.Resource; | |
| 8 | + | |
| 9 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | |
| 10 | + | |
| 11 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 13 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper; | |
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 15 | + | |
| 16 | +import javax.annotation.Resource; | |
| 17 | +import org.springframework.context.annotation.Import; | |
| 18 | +import java.util.*; | |
| 19 | +import java.time.LocalDateTime; | |
| 20 | + | |
| 21 | +import static cn.hutool.core.util.RandomUtil.*; | |
| 22 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 23 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; | |
| 24 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | |
| 25 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; | |
| 26 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; | |
| 27 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; | |
| 28 | +import static org.junit.jupiter.api.Assertions.*; | |
| 29 | +import static org.mockito.Mockito.*; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * {@link InfraStudentServiceImpl} 的单元测试类 | |
| 33 | + * | |
| 34 | + * @author 芋道源码 | |
| 35 | + */ | |
| 36 | +@Import(InfraStudentServiceImpl.class) | |
| 37 | +public class InfraStudentServiceImplTest extends BaseDbUnitTest { | |
| 38 | + | |
| 39 | + @Resource | |
| 40 | + private InfraStudentServiceImpl studentService; | |
| 41 | + | |
| 42 | + @Resource | |
| 43 | + private InfraStudentMapper studentMapper; | |
| 44 | + | |
| 45 | + @Test | |
| 46 | + public void testCreateStudent_success() { | |
| 47 | + // 准备参数 | |
| 48 | + InfraStudentSaveReqVO createReqVO = randomPojo(InfraStudentSaveReqVO.class).setId(null); | |
| 49 | + | |
| 50 | + // 调用 | |
| 51 | + Long studentId = studentService.createStudent(createReqVO); | |
| 52 | + // 断言 | |
| 53 | + assertNotNull(studentId); | |
| 54 | + // 校验记录的属性是否正确 | |
| 55 | + InfraStudentDO student = studentMapper.selectById(studentId); | |
| 56 | + assertPojoEquals(createReqVO, student, "id"); | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Test | |
| 60 | + public void testUpdateStudent_success() { | |
| 61 | + // mock 数据 | |
| 62 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class); | |
| 63 | + studentMapper.insert(dbStudent);// @Sql: 先插入出一条存在的数据 | |
| 64 | + // 准备参数 | |
| 65 | + InfraStudentSaveReqVO updateReqVO = randomPojo(InfraStudentSaveReqVO.class, o -> { | |
| 66 | + o.setId(dbStudent.getId()); // 设置更新的 ID | |
| 67 | + }); | |
| 68 | + | |
| 69 | + // 调用 | |
| 70 | + studentService.updateStudent(updateReqVO); | |
| 71 | + // 校验是否更新正确 | |
| 72 | + InfraStudentDO student = studentMapper.selectById(updateReqVO.getId()); // 获取最新的 | |
| 73 | + assertPojoEquals(updateReqVO, student); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Test | |
| 77 | + public void testUpdateStudent_notExists() { | |
| 78 | + // 准备参数 | |
| 79 | + InfraStudentSaveReqVO updateReqVO = randomPojo(InfraStudentSaveReqVO.class); | |
| 80 | + | |
| 81 | + // 调用, 并断言异常 | |
| 82 | + assertServiceException(() -> studentService.updateStudent(updateReqVO), STUDENT_NOT_EXISTS); | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Test | |
| 86 | + public void testDeleteStudent_success() { | |
| 87 | + // mock 数据 | |
| 88 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class); | |
| 89 | + studentMapper.insert(dbStudent);// @Sql: 先插入出一条存在的数据 | |
| 90 | + // 准备参数 | |
| 91 | + Long id = dbStudent.getId(); | |
| 92 | + | |
| 93 | + // 调用 | |
| 94 | + studentService.deleteStudent(id); | |
| 95 | + // 校验数据不存在了 | |
| 96 | + assertNull(studentMapper.selectById(id)); | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Test | |
| 100 | + public void testDeleteStudent_notExists() { | |
| 101 | + // 准备参数 | |
| 102 | + Long id = randomLongId(); | |
| 103 | + | |
| 104 | + // 调用, 并断言异常 | |
| 105 | + assertServiceException(() -> studentService.deleteStudent(id), STUDENT_NOT_EXISTS); | |
| 106 | + } | |
| 107 | + | |
| 108 | + @Test | |
| 109 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 110 | + public void testGetStudentPage() { | |
| 111 | + // mock 数据 | |
| 112 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class, o -> { // 等会查询到 | |
| 113 | + o.setName(null); | |
| 114 | + o.setBirthday(null); | |
| 115 | + o.setSex(null); | |
| 116 | + o.setEnabled(null); | |
| 117 | + o.setCreateTime(null); | |
| 118 | + }); | |
| 119 | + studentMapper.insert(dbStudent); | |
| 120 | + // 测试 name 不匹配 | |
| 121 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setName(null))); | |
| 122 | + // 测试 birthday 不匹配 | |
| 123 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setBirthday(null))); | |
| 124 | + // 测试 sex 不匹配 | |
| 125 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setSex(null))); | |
| 126 | + // 测试 enabled 不匹配 | |
| 127 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setEnabled(null))); | |
| 128 | + // 测试 createTime 不匹配 | |
| 129 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setCreateTime(null))); | |
| 130 | + // 准备参数 | |
| 131 | + InfraStudentPageReqVO reqVO = new InfraStudentPageReqVO(); | |
| 132 | + reqVO.setName(null); | |
| 133 | + reqVO.setBirthday(null); | |
| 134 | + reqVO.setSex(null); | |
| 135 | + reqVO.setEnabled(null); | |
| 136 | + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 137 | + | |
| 138 | + // 调用 | |
| 139 | + PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(reqVO); | |
| 140 | + // 断言 | |
| 141 | + assertEquals(1, pageResult.getTotal()); | |
| 142 | + assertEquals(1, pageResult.getList().size()); | |
| 143 | + assertPojoEquals(dbStudent, pageResult.getList().get(0)); | |
| 144 | + } | |
| 145 | + | |
| 146 | +} | |
| 0 | 147 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/js/student
0 → 100644
| 1 | +import request from '@/utils/request' | |
| 2 | + | |
| 3 | +// 创建学生 | |
| 4 | +export function createStudent(data) { | |
| 5 | + return request({ | |
| 6 | + url: '/infra/student/create', | |
| 7 | + method: 'post', | |
| 8 | + data: data | |
| 9 | + }) | |
| 10 | +} | |
| 11 | + | |
| 12 | +// 更新学生 | |
| 13 | +export function updateStudent(data) { | |
| 14 | + return request({ | |
| 15 | + url: '/infra/student/update', | |
| 16 | + method: 'put', | |
| 17 | + data: data | |
| 18 | + }) | |
| 19 | +} | |
| 20 | + | |
| 21 | +// 删除学生 | |
| 22 | +export function deleteStudent(id) { | |
| 23 | + return request({ | |
| 24 | + url: '/infra/student/delete?id=' + id, | |
| 25 | + method: 'delete' | |
| 26 | + }) | |
| 27 | +} | |
| 28 | + | |
| 29 | +// 获得学生 | |
| 30 | +export function getStudent(id) { | |
| 31 | + return request({ | |
| 32 | + url: '/infra/student/get?id=' + id, | |
| 33 | + method: 'get' | |
| 34 | + }) | |
| 35 | +} | |
| 36 | + | |
| 37 | +// 获得学生分页 | |
| 38 | +export function getStudentPage(params) { | |
| 39 | + return request({ | |
| 40 | + url: '/infra/student/page', | |
| 41 | + method: 'get', | |
| 42 | + params | |
| 43 | + }) | |
| 44 | +} | |
| 45 | +// 导出学生 Excel | |
| 46 | +export function exportStudentExcel(params) { | |
| 47 | + return request({ | |
| 48 | + url: '/infra/student/export-excel', | |
| 49 | + method: 'get', | |
| 50 | + params, | |
| 51 | + responseType: 'blob' | |
| 52 | + }) | |
| 53 | +} | |
| 0 | 54 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/sql/h2
0 → 100644
| 1 | +-- 将该建表 SQL 语句,添加到 yudao-module-infra-biz 模块的 test/resources/sql/create_tables.sql 文件里 | |
| 2 | +CREATE TABLE IF NOT EXISTS "infra_student" ( | |
| 3 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 4 | + "name" varchar NOT NULL, | |
| 5 | + "description" varchar NOT NULL, | |
| 6 | + "birthday" varchar NOT NULL, | |
| 7 | + "sex" int NOT NULL, | |
| 8 | + "enabled" bit NOT NULL, | |
| 9 | + "avatar" varchar NOT NULL, | |
| 10 | + "video" varchar NOT NULL, | |
| 11 | + "memo" varchar NOT NULL, | |
| 12 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 13 | + PRIMARY KEY ("id") | |
| 14 | +) COMMENT '学生表'; | |
| 15 | + | |
| 16 | +-- 将该删表 SQL 语句,添加到 yudao-module-infra-biz 模块的 test/resources/sql/clean.sql 文件里 | |
| 17 | +DELETE FROM "infra_student"; | |
| 0 | 18 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/sql/sql
0 → 100644
| 1 | +-- 菜单 SQL | |
| 2 | +INSERT INTO system_menu( | |
| 3 | + name, permission, type, sort, parent_id, | |
| 4 | + path, icon, component, status, component_name | |
| 5 | +) | |
| 6 | +VALUES ( | |
| 7 | + '学生管理', '', 2, 0, 888, | |
| 8 | + 'student', '', 'infra/demo/index', 0, 'InfraStudent' | |
| 9 | +); | |
| 10 | + | |
| 11 | +-- 按钮父菜单ID | |
| 12 | +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 | |
| 13 | +SELECT @parentId := LAST_INSERT_ID(); | |
| 14 | + | |
| 15 | +-- 按钮 SQL | |
| 16 | +INSERT INTO system_menu( | |
| 17 | + name, permission, type, sort, parent_id, | |
| 18 | + path, icon, component, status | |
| 19 | +) | |
| 20 | +VALUES ( | |
| 21 | + '学生查询', 'infra:student:query', 3, 1, @parentId, | |
| 22 | + '', '', '', 0 | |
| 23 | +); | |
| 24 | +INSERT INTO system_menu( | |
| 25 | + name, permission, type, sort, parent_id, | |
| 26 | + path, icon, component, status | |
| 27 | +) | |
| 28 | +VALUES ( | |
| 29 | + '学生创建', 'infra:student:create', 3, 2, @parentId, | |
| 30 | + '', '', '', 0 | |
| 31 | +); | |
| 32 | +INSERT INTO system_menu( | |
| 33 | + name, permission, type, sort, parent_id, | |
| 34 | + path, icon, component, status | |
| 35 | +) | |
| 36 | +VALUES ( | |
| 37 | + '学生更新', 'infra:student:update', 3, 3, @parentId, | |
| 38 | + '', '', '', 0 | |
| 39 | +); | |
| 40 | +INSERT INTO system_menu( | |
| 41 | + name, permission, type, sort, parent_id, | |
| 42 | + path, icon, component, status | |
| 43 | +) | |
| 44 | +VALUES ( | |
| 45 | + '学生删除', 'infra:student:delete', 3, 4, @parentId, | |
| 46 | + '', '', '', 0 | |
| 47 | +); | |
| 48 | +INSERT INTO system_menu( | |
| 49 | + name, permission, type, sort, parent_id, | |
| 50 | + path, icon, component, status | |
| 51 | +) | |
| 52 | +VALUES ( | |
| 53 | + '学生导出', 'infra:student:export', 3, 5, @parentId, | |
| 54 | + '', '', '', 0 | |
| 55 | +); | |
| 0 | 56 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/vue/StudentForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 对话框(添加 / 修改) --> | |
| 4 | + <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body> | |
| 5 | + <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px"> | |
| 6 | + <el-form-item label="名字" prop="name"> | |
| 7 | + <el-input v-model="formData.name" placeholder="请输入名字" /> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="简介" prop="description"> | |
| 10 | + <el-input v-model="formData.description" type="textarea" placeholder="请输入内容" /> | |
| 11 | + </el-form-item> | |
| 12 | + <el-form-item label="出生日期" prop="birthday"> | |
| 13 | + <el-date-picker clearable v-model="formData.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 14 | + </el-form-item> | |
| 15 | + <el-form-item label="性别" prop="sex"> | |
| 16 | + <el-select v-model="formData.sex" placeholder="请选择性别"> | |
| 17 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 18 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 19 | + </el-select> | |
| 20 | + </el-form-item> | |
| 21 | + <el-form-item label="是否有效" prop="enabled"> | |
| 22 | + <el-radio-group v-model="formData.enabled"> | |
| 23 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 24 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 25 | + </el-radio-group> | |
| 26 | + </el-form-item> | |
| 27 | + <el-form-item label="头像"> | |
| 28 | + <ImageUpload v-model="formData.avatar"/> | |
| 29 | + </el-form-item> | |
| 30 | + <el-form-item label="附件"> | |
| 31 | + <FileUpload v-model="formData.video"/> | |
| 32 | + </el-form-item> | |
| 33 | + <el-form-item label="备注"> | |
| 34 | + <Editor v-model="formData.memo" :min-height="192"/> | |
| 35 | + </el-form-item> | |
| 36 | + </el-form> | |
| 37 | + <div slot="footer" class="dialog-footer"> | |
| 38 | + <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button> | |
| 39 | + <el-button @click="dialogVisible = false">取 消</el-button> | |
| 40 | + </div> | |
| 41 | + </el-dialog> | |
| 42 | + </div> | |
| 43 | +</template> | |
| 44 | + | |
| 45 | +<script> | |
| 46 | + import * as StudentApi from '@/api/infra/demo' | |
| 47 | + import ImageUpload from '@/components/ImageUpload'; | |
| 48 | + import FileUpload from '@/components/FileUpload'; | |
| 49 | + import Editor from '@/components/Editor'; | |
| 50 | + export default { | |
| 51 | + name: "StudentForm", | |
| 52 | + components: { | |
| 53 | + ImageUpload, | |
| 54 | + FileUpload, | |
| 55 | + Editor, | |
| 56 | + }, | |
| 57 | + data() { | |
| 58 | + return { | |
| 59 | + // 弹出层标题 | |
| 60 | + dialogTitle: "", | |
| 61 | + // 是否显示弹出层 | |
| 62 | + dialogVisible: false, | |
| 63 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 64 | + formLoading: false, | |
| 65 | + // 表单参数 | |
| 66 | + formData: { | |
| 67 | + id: undefined, | |
| 68 | + name: undefined, | |
| 69 | + description: undefined, | |
| 70 | + birthday: undefined, | |
| 71 | + sex: undefined, | |
| 72 | + enabled: undefined, | |
| 73 | + avatar: undefined, | |
| 74 | + video: undefined, | |
| 75 | + memo: undefined, | |
| 76 | + }, | |
| 77 | + // 表单校验 | |
| 78 | + formRules: { | |
| 79 | + name: [{ required: true, message: '名字不能为空', trigger: 'blur' }], | |
| 80 | + description: [{ required: true, message: '简介不能为空', trigger: 'blur' }], | |
| 81 | + birthday: [{ required: true, message: '出生日期不能为空', trigger: 'blur' }], | |
| 82 | + sex: [{ required: true, message: '性别不能为空', trigger: 'change' }], | |
| 83 | + enabled: [{ required: true, message: '是否有效不能为空', trigger: 'blur' }], | |
| 84 | + avatar: [{ required: true, message: '头像不能为空', trigger: 'blur' }], | |
| 85 | + video: [{ required: true, message: '附件不能为空', trigger: 'blur' }], | |
| 86 | + memo: [{ required: true, message: '备注不能为空', trigger: 'blur' }], | |
| 87 | + }, | |
| 88 | + }; | |
| 89 | + }, | |
| 90 | + methods: { | |
| 91 | + /** 打开弹窗 */ | |
| 92 | + open(id) { | |
| 93 | + this.dialogVisible = true; | |
| 94 | + this.reset(); | |
| 95 | + const that = this; | |
| 96 | + // 修改时,设置数据 | |
| 97 | + if (id) { | |
| 98 | + this.formLoading = true; | |
| 99 | + try { | |
| 100 | + StudentApi.getStudent(id).then(res=>{ | |
| 101 | + that.formData = res.data; | |
| 102 | + that.title = "修改学生"; | |
| 103 | + }) | |
| 104 | + } finally { | |
| 105 | + this.formLoading = false; | |
| 106 | + } | |
| 107 | + } | |
| 108 | + this.title = "新增学生"; | |
| 109 | + }, | |
| 110 | + /** 提交按钮 */ | |
| 111 | + submitForm() { | |
| 112 | + this.formLoading = true; | |
| 113 | + try { | |
| 114 | + const that = this; | |
| 115 | + let data = this.formData; | |
| 116 | + let validate = false; | |
| 117 | + // 校验主表 | |
| 118 | + this.getRef("formRef").validate(valid => { | |
| 119 | + validate = valid; | |
| 120 | + }); | |
| 121 | + // 所有表单校验通过后方可提交 | |
| 122 | + if (!validate) { | |
| 123 | + return; | |
| 124 | + } | |
| 125 | + // 修改的提交 | |
| 126 | + if (data.id) { | |
| 127 | + StudentApi.updateStudent(data).then(response => { | |
| 128 | + that.$modal.msgSuccess("修改成功"); | |
| 129 | + that.dialogVisible = false; | |
| 130 | + that.$emit('success'); | |
| 131 | + }); | |
| 132 | + return; | |
| 133 | + } | |
| 134 | + // 添加的提交 | |
| 135 | + StudentApi.createStudent(data).then(response => { | |
| 136 | + that.$modal.msgSuccess("新增成功"); | |
| 137 | + that.dialogVisible = false; | |
| 138 | + that.$emit('success'); | |
| 139 | + }); | |
| 140 | + }finally { | |
| 141 | + this.formLoading = false; | |
| 142 | + } | |
| 143 | + }, | |
| 144 | + getRef(refName){ | |
| 145 | + return this.$refs[refName]; | |
| 146 | + }, | |
| 147 | + /** 表单重置 */ | |
| 148 | + reset() { | |
| 149 | + this.formData = { | |
| 150 | + id: undefined, | |
| 151 | + name: undefined, | |
| 152 | + description: undefined, | |
| 153 | + birthday: undefined, | |
| 154 | + sex: undefined, | |
| 155 | + enabled: undefined, | |
| 156 | + avatar: undefined, | |
| 157 | + video: undefined, | |
| 158 | + memo: undefined, | |
| 159 | + }; | |
| 160 | + this.resetForm("formRef"); | |
| 161 | + }, | |
| 162 | + } | |
| 163 | + }; | |
| 164 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/vue/index
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + | |
| 4 | + <!-- 搜索工作栏 --> | |
| 5 | + <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> | |
| 6 | + <el-form-item label="名字" prop="name"> | |
| 7 | + <el-input v-model="queryParams.name" placeholder="请输入名字" clearable @keyup.enter.native="handleQuery"/> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="出生日期" prop="birthday"> | |
| 10 | + <el-date-picker clearable v-model="queryParams.birthday" type="date" value-format="yyyy-MM-dd" placeholder="选择出生日期" /> | |
| 11 | + </el-form-item> | |
| 12 | + <el-form-item label="性别" prop="sex"> | |
| 13 | + <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable size="small"> | |
| 14 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 15 | + :key="dict.value" :label="dict.label" :value="dict.value"/> | |
| 16 | + </el-select> | |
| 17 | + </el-form-item> | |
| 18 | + <el-form-item label="是否有效" prop="enabled"> | |
| 19 | + <el-select v-model="queryParams.enabled" placeholder="请选择是否有效" clearable size="small"> | |
| 20 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 21 | + :key="dict.value" :label="dict.label" :value="dict.value"/> | |
| 22 | + </el-select> | |
| 23 | + </el-form-item> | |
| 24 | + <el-form-item label="创建时间" prop="createTime"> | |
| 25 | + <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange" | |
| 26 | + range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" /> | |
| 27 | + </el-form-item> | |
| 28 | + <el-form-item> | |
| 29 | + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button> | |
| 30 | + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button> | |
| 31 | + </el-form-item> | |
| 32 | + </el-form> | |
| 33 | + | |
| 34 | + <!-- 操作工具栏 --> | |
| 35 | + <el-row :gutter="10" class="mb8"> | |
| 36 | + <el-col :span="1.5"> | |
| 37 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)" | |
| 38 | + v-hasPermi="['infra:student:create']">新增</el-button> | |
| 39 | + </el-col> | |
| 40 | + <el-col :span="1.5"> | |
| 41 | + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading" | |
| 42 | + v-hasPermi="['infra:student:export']">导出</el-button> | |
| 43 | + </el-col> | |
| 44 | + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | |
| 45 | + </el-row> | |
| 46 | + | |
| 47 | + <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | |
| 48 | + <el-table-column label="编号" align="center" prop="id"> | |
| 49 | + <template v-slot="scope"> | |
| 50 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.id" /> | |
| 51 | + </template> | |
| 52 | + </el-table-column> | |
| 53 | + <el-table-column label="名字" align="center" prop="name"> | |
| 54 | + <template v-slot="scope"> | |
| 55 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.name" /> | |
| 56 | + </template> | |
| 57 | + </el-table-column> | |
| 58 | + <el-table-column label="简介" align="center" prop="description"> | |
| 59 | + <template v-slot="scope"> | |
| 60 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.description" /> | |
| 61 | + </template> | |
| 62 | + </el-table-column> | |
| 63 | + <el-table-column label="出生日期" align="center" prop="birthday" width="180"> | |
| 64 | + <template v-slot="scope"> | |
| 65 | + <span>{{ parseTime(scope.row.birthday) }}</span> | |
| 66 | + </template> | |
| 67 | + </el-table-column> | |
| 68 | + <el-table-column label="性别" align="center" prop="sex"> | |
| 69 | + <template v-slot="scope"> | |
| 70 | + <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" /> | |
| 71 | + </template> | |
| 72 | + </el-table-column> | |
| 73 | + <el-table-column label="是否有效" align="center" prop="enabled"> | |
| 74 | + <template v-slot="scope"> | |
| 75 | + <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" /> | |
| 76 | + </template> | |
| 77 | + </el-table-column> | |
| 78 | + <el-table-column label="头像" align="center" prop="avatar"> | |
| 79 | + <template v-slot="scope"> | |
| 80 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.avatar" /> | |
| 81 | + </template> | |
| 82 | + </el-table-column> | |
| 83 | + <el-table-column label="附件" align="center" prop="video"> | |
| 84 | + <template v-slot="scope"> | |
| 85 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.video" /> | |
| 86 | + </template> | |
| 87 | + </el-table-column> | |
| 88 | + <el-table-column label="备注" align="center" prop="memo"> | |
| 89 | + <template v-slot="scope"> | |
| 90 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.memo" /> | |
| 91 | + </template> | |
| 92 | + </el-table-column> | |
| 93 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 94 | + <template v-slot="scope"> | |
| 95 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 96 | + </template> | |
| 97 | + </el-table-column> | |
| 98 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 99 | + <template v-slot="scope"> | |
| 100 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)" | |
| 101 | + v-hasPermi="['infra:student:update']">修改</el-button> | |
| 102 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 103 | + v-hasPermi="['infra:student:delete']">删除</el-button> | |
| 104 | + </template> | |
| 105 | + </el-table-column> | |
| 106 | + </el-table> | |
| 107 | + <!-- 分页组件 --> | |
| 108 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | |
| 109 | + @pagination="getList"/> | |
| 110 | + <!-- 对话框(添加 / 修改) --> | |
| 111 | + <StudentForm ref="formRef" @success="getList" /> | |
| 112 | + </div> | |
| 113 | +</template> | |
| 114 | + | |
| 115 | +<script> | |
| 116 | +import * as StudentApi from '@/api/infra/demo'; | |
| 117 | +import StudentForm from './StudentForm.vue'; | |
| 118 | +export default { | |
| 119 | + name: "Student", | |
| 120 | + components: { | |
| 121 | + StudentForm, | |
| 122 | + }, | |
| 123 | + data() { | |
| 124 | + return { | |
| 125 | + // 遮罩层 | |
| 126 | + loading: true, | |
| 127 | + // 导出遮罩层 | |
| 128 | + exportLoading: false, | |
| 129 | + // 显示搜索条件 | |
| 130 | + showSearch: true, | |
| 131 | + // 总条数 | |
| 132 | + total: 0, | |
| 133 | + // 学生列表 | |
| 134 | + list: [], | |
| 135 | + // 是否展开,默认全部展开 | |
| 136 | + isExpandAll: true, | |
| 137 | + // 重新渲染表格状态 | |
| 138 | + refreshTable: true, | |
| 139 | + // 选中行 | |
| 140 | + currentRow: {}, | |
| 141 | + // 查询参数 | |
| 142 | + queryParams: { | |
| 143 | + pageNo: 1, | |
| 144 | + pageSize: 10, | |
| 145 | + name: null, | |
| 146 | + birthday: null, | |
| 147 | + sex: null, | |
| 148 | + enabled: null, | |
| 149 | + createTime: [], | |
| 150 | + }, | |
| 151 | + }; | |
| 152 | + }, | |
| 153 | + created() { | |
| 154 | + this.getList(); | |
| 155 | + }, | |
| 156 | + methods: { | |
| 157 | + /** 查询列表 */ | |
| 158 | + getList() { | |
| 159 | + try { | |
| 160 | + this.loading = true; | |
| 161 | + StudentApi.getStudentPage(this.queryParams).then(response => { | |
| 162 | + this.list = response.data.list; | |
| 163 | + this.total = response.data.total; | |
| 164 | + }); | |
| 165 | + } finally { | |
| 166 | + this.loading = false; | |
| 167 | + } | |
| 168 | + }, | |
| 169 | + /** 搜索按钮操作 */ | |
| 170 | + handleQuery() { | |
| 171 | + this.queryParams.pageNo = 1; | |
| 172 | + this.getList(); | |
| 173 | + }, | |
| 174 | + /** 重置按钮操作 */ | |
| 175 | + resetQuery() { | |
| 176 | + this.resetForm("queryForm"); | |
| 177 | + this.handleQuery(); | |
| 178 | + }, | |
| 179 | + /** 添加/修改操作 */ | |
| 180 | + openForm(id) { | |
| 181 | + this.$refs["formRef"].open(id); | |
| 182 | + }, | |
| 183 | + /** 删除按钮操作 */ | |
| 184 | + handleDelete(row) { | |
| 185 | + const that = this; | |
| 186 | + try { | |
| 187 | + const id = row.id; | |
| 188 | + this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?').then(()=>{ | |
| 189 | + return StudentApi.deleteStudent(id); | |
| 190 | + }).then(() => { | |
| 191 | + that.getList(); | |
| 192 | + that.$modal.msgSuccess("删除成功"); | |
| 193 | + }).catch(() => {}); | |
| 194 | + } catch {} | |
| 195 | + }, | |
| 196 | + /** 导出按钮操作 */ | |
| 197 | + handleExport() { | |
| 198 | + const that = this; | |
| 199 | + try { | |
| 200 | + this.$modal.confirm('是否确认导出所有学生数据项?').then(() => { | |
| 201 | + that.exportLoading = true; | |
| 202 | + return StudentApi.exportStudentExcel(params); | |
| 203 | + }).then(response => { | |
| 204 | + that.$download.excel(response, '学生.xls'); | |
| 205 | + }); | |
| 206 | + } catch { | |
| 207 | + } finally { | |
| 208 | + that.exportLoading = false; | |
| 209 | + } | |
| 210 | + }, | |
| 211 | + } | |
| 212 | +}; | |
| 213 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/xml/InfraStudentMapper
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 3 | +<mapper namespace="cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper"> | |
| 4 | + | |
| 5 | + <!-- | |
| 6 | + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 | |
| 7 | + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 | |
| 8 | + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 | |
| 9 | + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ | |
| 10 | + --> | |
| 11 | + | |
| 12 | +</mapper> | |
| 0 | 13 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree/assert.json
0 → 100644
| 1 | +[ { | |
| 2 | + "contentPath" : "java/InfraCategoryListReqVO", | |
| 3 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraCategoryListReqVO.java" | |
| 4 | +}, { | |
| 5 | + "contentPath" : "java/InfraCategoryRespVO", | |
| 6 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraCategoryRespVO.java" | |
| 7 | +}, { | |
| 8 | + "contentPath" : "java/InfraCategorySaveReqVO", | |
| 9 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraCategorySaveReqVO.java" | |
| 10 | +}, { | |
| 11 | + "contentPath" : "java/InfraCategoryController", | |
| 12 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/InfraCategoryController.java" | |
| 13 | +}, { | |
| 14 | + "contentPath" : "java/InfraCategoryDO", | |
| 15 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraCategoryDO.java" | |
| 16 | +}, { | |
| 17 | + "contentPath" : "java/InfraCategoryMapper", | |
| 18 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraCategoryMapper.java" | |
| 19 | +}, { | |
| 20 | + "contentPath" : "xml/InfraCategoryMapper", | |
| 21 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/resources/mapper/demo/InfraCategoryMapper.xml" | |
| 22 | +}, { | |
| 23 | + "contentPath" : "java/InfraCategoryServiceImpl", | |
| 24 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/InfraCategoryServiceImpl.java" | |
| 25 | +}, { | |
| 26 | + "contentPath" : "java/InfraCategoryService", | |
| 27 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/InfraCategoryService.java" | |
| 28 | +}, { | |
| 29 | + "contentPath" : "java/InfraCategoryServiceImplTest", | |
| 30 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/demo/InfraCategoryServiceImplTest.java" | |
| 31 | +}, { | |
| 32 | + "contentPath" : "java/ErrorCodeConstants_手动操作", | |
| 33 | + "filePath" : "yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants_手动操作.java" | |
| 34 | +}, { | |
| 35 | + "contentPath" : "sql/sql", | |
| 36 | + "filePath" : "sql/sql.sql" | |
| 37 | +}, { | |
| 38 | + "contentPath" : "sql/h2", | |
| 39 | + "filePath" : "sql/h2.sql" | |
| 40 | +}, { | |
| 41 | + "contentPath" : "vue/index", | |
| 42 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/index.vue" | |
| 43 | +}, { | |
| 44 | + "contentPath" : "js/category", | |
| 45 | + "filePath" : "yudao-ui-admin-vue2/src/api/infra/category.js" | |
| 46 | +}, { | |
| 47 | + "contentPath" : "vue/CategoryForm", | |
| 48 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/CategoryForm.vue" | |
| 49 | +} ] | |
| 0 | 50 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree/java/ErrorCodeConstants_手动操作
0 → 100644
| 1 | +// TODO 待办:请将下面的错误码复制到 yudao-module-infra-api 模块的 ErrorCodeConstants 类中。注意,请给“TODO 补充编号”设置一个错误码编号!!! | |
| 2 | +// ========== 分类 TODO 补充编号 ========== | |
| 3 | +ErrorCode CATEGORY_NOT_EXISTS = new ErrorCode(TODO 补充编号, "分类不存在"); | |
| 4 | +ErrorCode CATEGORY_EXITS_CHILDREN = new ErrorCode(TODO 补充编号, "存在存在子分类,无法删除"); | |
| 5 | +ErrorCode CATEGORY_PARENT_NOT_EXITS = new ErrorCode(TODO 补充编号,"父级分类不存在"); | |
| 6 | +ErrorCode CATEGORY_PARENT_ERROR = new ErrorCode(TODO 补充编号, "不能设置自己为父分类"); | |
| 7 | +ErrorCode CATEGORY_NAME_DUPLICATE = new ErrorCode(TODO 补充编号, "已经存在该名字的分类"); | |
| 8 | +ErrorCode CATEGORY_PARENT_IS_CHILD = new ErrorCode(TODO 补充编号, "不能设置自己的子InfraCategory为父InfraCategory"); | |
| 0 | 9 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree/java/InfraCategoryController
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo; | |
| 2 | + | |
| 3 | +import org.springframework.web.bind.annotation.*; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 7 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 8 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 9 | +import io.swagger.v3.oas.annotations.Operation; | |
| 10 | + | |
| 11 | +import javax.validation.constraints.*; | |
| 12 | +import javax.validation.*; | |
| 13 | +import javax.servlet.http.*; | |
| 14 | +import java.util.*; | |
| 15 | +import java.io.IOException; | |
| 16 | + | |
| 17 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 18 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 19 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 20 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 21 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 22 | + | |
| 23 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 24 | + | |
| 25 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 26 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | |
| 27 | + | |
| 28 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 29 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraCategoryDO; | |
| 30 | +import cn.iocoder.yudao.module.infra.service.demo.InfraCategoryService; | |
| 31 | + | |
| 32 | +@Tag(name = "管理后台 - 分类") | |
| 33 | +@RestController | |
| 34 | +@RequestMapping("/infra/category") | |
| 35 | +@Validated | |
| 36 | +public class InfraCategoryController { | |
| 37 | + | |
| 38 | + @Resource | |
| 39 | + private InfraCategoryService categoryService; | |
| 40 | + | |
| 41 | + @PostMapping("/create") | |
| 42 | + @Operation(summary = "创建分类") | |
| 43 | + @PreAuthorize("@ss.hasPermission('infra:category:create')") | |
| 44 | + public CommonResult<Long> createCategory(@Valid @RequestBody InfraCategorySaveReqVO createReqVO) { | |
| 45 | + return success(categoryService.createCategory(createReqVO)); | |
| 46 | + } | |
| 47 | + | |
| 48 | + @PutMapping("/update") | |
| 49 | + @Operation(summary = "更新分类") | |
| 50 | + @PreAuthorize("@ss.hasPermission('infra:category:update')") | |
| 51 | + public CommonResult<Boolean> updateCategory(@Valid @RequestBody InfraCategorySaveReqVO updateReqVO) { | |
| 52 | + categoryService.updateCategory(updateReqVO); | |
| 53 | + return success(true); | |
| 54 | + } | |
| 55 | + | |
| 56 | + @DeleteMapping("/delete") | |
| 57 | + @Operation(summary = "删除分类") | |
| 58 | + @Parameter(name = "id", description = "编号", required = true) | |
| 59 | + @PreAuthorize("@ss.hasPermission('infra:category:delete')") | |
| 60 | + public CommonResult<Boolean> deleteCategory(@RequestParam("id") Long id) { | |
| 61 | + categoryService.deleteCategory(id); | |
| 62 | + return success(true); | |
| 63 | + } | |
| 64 | + | |
| 65 | + @GetMapping("/get") | |
| 66 | + @Operation(summary = "获得分类") | |
| 67 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 68 | + @PreAuthorize("@ss.hasPermission('infra:category:query')") | |
| 69 | + public CommonResult<InfraCategoryRespVO> getCategory(@RequestParam("id") Long id) { | |
| 70 | + InfraCategoryDO category = categoryService.getCategory(id); | |
| 71 | + return success(BeanUtils.toBean(category, InfraCategoryRespVO.class)); | |
| 72 | + } | |
| 73 | + | |
| 74 | + @GetMapping("/list") | |
| 75 | + @Operation(summary = "获得分类列表") | |
| 76 | + @PreAuthorize("@ss.hasPermission('infra:category:query')") | |
| 77 | + public CommonResult<List<InfraCategoryRespVO>> getCategoryList(@Valid InfraCategoryListReqVO listReqVO) { | |
| 78 | + List<InfraCategoryDO> list = categoryService.getCategoryList(listReqVO); | |
| 79 | + return success(BeanUtils.toBean(list, InfraCategoryRespVO.class)); | |
| 80 | + } | |
| 81 | + | |
| 82 | + @GetMapping("/export-excel") | |
| 83 | + @Operation(summary = "导出分类 Excel") | |
| 84 | + @PreAuthorize("@ss.hasPermission('infra:category:export')") | |
| 85 | + @OperateLog(type = EXPORT) | |
| 86 | + public void exportCategoryExcel(@Valid InfraCategoryListReqVO listReqVO, | |
| 87 | + HttpServletResponse response) throws IOException { | |
| 88 | + List<InfraCategoryDO> list = categoryService.getCategoryList(listReqVO); | |
| 89 | + // 导出 Excel | |
| 90 | + ExcelUtils.write(response, "分类.xls", "数据", InfraCategoryRespVO.class, | |
| 91 | + BeanUtils.toBean(list, InfraCategoryRespVO.class)); | |
| 92 | + } | |
| 93 | + | |
| 94 | +} | |
| 0 | 95 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree/java/InfraCategoryDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import com.baomidou.mybatisplus.annotation.*; | |
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * 分类 DO | |
| 10 | + * | |
| 11 | + * @author 芋道源码 | |
| 12 | + */ | |
| 13 | +@TableName("infra_category") | |
| 14 | +@KeySequence("infra_category_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 15 | +@Data | |
| 16 | +@EqualsAndHashCode(callSuper = true) | |
| 17 | +@ToString(callSuper = true) | |
| 18 | +@Builder | |
| 19 | +@NoArgsConstructor | |
| 20 | +@AllArgsConstructor | |
| 21 | +public class InfraCategoryDO extends BaseDO { | |
| 22 | + | |
| 23 | + public static final Long PARENT_ID_ROOT = 0L; | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 名字 | |
| 32 | + */ | |
| 33 | + private String name; | |
| 34 | + /** | |
| 35 | + * 父编号 | |
| 36 | + */ | |
| 37 | + private Long parentId; | |
| 38 | + | |
| 39 | +} | |
| 0 | 40 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree/java/InfraCategoryListReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | + | |
| 8 | +@Schema(description = "管理后台 - 分类列表 Request VO") | |
| 9 | +@Data | |
| 10 | +public class InfraCategoryListReqVO { | |
| 11 | + | |
| 12 | + @Schema(description = "名字", example = "芋头") | |
| 13 | + private String name; | |
| 14 | + | |
| 15 | +} | |
| 0 | 16 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree/java/InfraCategoryMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraCategoryDO; | |
| 9 | +import org.apache.ibatis.annotations.Mapper; | |
| 10 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 分类 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraCategoryMapper extends BaseMapperX<InfraCategoryDO> { | |
| 19 | + | |
| 20 | + default List<InfraCategoryDO> selectList(InfraCategoryListReqVO reqVO) { | |
| 21 | + return selectList(new LambdaQueryWrapperX<InfraCategoryDO>() | |
| 22 | + .likeIfPresent(InfraCategoryDO::getName, reqVO.getName()) | |
| 23 | + .orderByDesc(InfraCategoryDO::getId)); | |
| 24 | + } | |
| 25 | + | |
| 26 | + default InfraCategoryDO selectByParentIdAndName(Long parentId, String name) { | |
| 27 | + return selectOne(InfraCategoryDO::getParentId, parentId, InfraCategoryDO::getName, name); | |
| 28 | + } | |
| 29 | + | |
| 30 | + default Long selectCountByParentId(Long parentId) { | |
| 31 | + return selectCount(InfraCategoryDO::getParentId, parentId); | |
| 32 | + } | |
| 33 | + | |
| 34 | +} | |
| 0 | 35 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree/java/InfraCategoryRespVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import java.util.*; | |
| 7 | +import com.alibaba.excel.annotation.*; | |
| 8 | + | |
| 9 | +@Schema(description = "管理后台 - 分类 Response VO") | |
| 10 | +@Data | |
| 11 | +@ExcelIgnoreUnannotated | |
| 12 | +public class InfraCategoryRespVO { | |
| 13 | + | |
| 14 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 15 | + @ExcelProperty("编号") | |
| 16 | + private Long id; | |
| 17 | + | |
| 18 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 19 | + @ExcelProperty("名字") | |
| 20 | + private String name; | |
| 21 | + | |
| 22 | + @Schema(description = "父编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") | |
| 23 | + @ExcelProperty("父编号") | |
| 24 | + private Long parentId; | |
| 25 | + | |
| 26 | +} | |
| 0 | 27 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree/java/InfraCategorySaveReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import javax.validation.constraints.*; | |
| 7 | +import java.util.*; | |
| 8 | + | |
| 9 | +@Schema(description = "管理后台 - 分类新增/修改 Request VO") | |
| 10 | +@Data | |
| 11 | +public class InfraCategorySaveReqVO { | |
| 12 | + | |
| 13 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 14 | + private Long id; | |
| 15 | + | |
| 16 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 17 | + @NotEmpty(message = "名字不能为空") | |
| 18 | + private String name; | |
| 19 | + | |
| 20 | + @Schema(description = "父编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") | |
| 21 | + @NotNull(message = "父编号不能为空") | |
| 22 | + private Long parentId; | |
| 23 | + | |
| 24 | +} | |
| 0 | 25 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree/java/InfraCategoryService
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | +import javax.validation.*; | |
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 6 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraCategoryDO; | |
| 7 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 8 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 分类 Service 接口 | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +public interface InfraCategoryService { | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * 创建分类 | |
| 19 | + * | |
| 20 | + * @param createReqVO 创建信息 | |
| 21 | + * @return 编号 | |
| 22 | + */ | |
| 23 | + Long createCategory(@Valid InfraCategorySaveReqVO createReqVO); | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 更新分类 | |
| 27 | + * | |
| 28 | + * @param updateReqVO 更新信息 | |
| 29 | + */ | |
| 30 | + void updateCategory(@Valid InfraCategorySaveReqVO updateReqVO); | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * 删除分类 | |
| 34 | + * | |
| 35 | + * @param id 编号 | |
| 36 | + */ | |
| 37 | + void deleteCategory(Long id); | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * 获得分类 | |
| 41 | + * | |
| 42 | + * @param id 编号 | |
| 43 | + * @return 分类 | |
| 44 | + */ | |
| 45 | + InfraCategoryDO getCategory(Long id); | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * 获得分类列表 | |
| 49 | + * | |
| 50 | + * @param listReqVO 查询条件 | |
| 51 | + * @return 分类列表 | |
| 52 | + */ | |
| 53 | + List<InfraCategoryDO> getCategoryList(InfraCategoryListReqVO listReqVO); | |
| 54 | + | |
| 55 | +} | |
| 0 | 56 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree/java/InfraCategoryServiceImpl
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import org.springframework.stereotype.Service; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.transaction.annotation.Transactional; | |
| 7 | + | |
| 8 | +import java.util.*; | |
| 9 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraCategoryDO; | |
| 11 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 12 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 13 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 14 | + | |
| 15 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraCategoryMapper; | |
| 16 | + | |
| 17 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 18 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 19 | + | |
| 20 | +/** | |
| 21 | + * 分类 Service 实现类 | |
| 22 | + * | |
| 23 | + * @author 芋道源码 | |
| 24 | + */ | |
| 25 | +@Service | |
| 26 | +@Validated | |
| 27 | +public class InfraCategoryServiceImpl implements InfraCategoryService { | |
| 28 | + | |
| 29 | + @Resource | |
| 30 | + private InfraCategoryMapper categoryMapper; | |
| 31 | + | |
| 32 | + @Override | |
| 33 | + public Long createCategory(InfraCategorySaveReqVO createReqVO) { | |
| 34 | + // 校验父编号的有效性 | |
| 35 | + validateParentCategory(null, createReqVO.getParentId()); | |
| 36 | + // 校验名字的唯一性 | |
| 37 | + validateCategoryNameUnique(null, createReqVO.getParentId(), createReqVO.getName()); | |
| 38 | + | |
| 39 | + // 插入 | |
| 40 | + InfraCategoryDO category = BeanUtils.toBean(createReqVO, InfraCategoryDO.class); | |
| 41 | + categoryMapper.insert(category); | |
| 42 | + // 返回 | |
| 43 | + return category.getId(); | |
| 44 | + } | |
| 45 | + | |
| 46 | + @Override | |
| 47 | + public void updateCategory(InfraCategorySaveReqVO updateReqVO) { | |
| 48 | + // 校验存在 | |
| 49 | + validateCategoryExists(updateReqVO.getId()); | |
| 50 | + // 校验父编号的有效性 | |
| 51 | + validateParentCategory(updateReqVO.getId(), updateReqVO.getParentId()); | |
| 52 | + // 校验名字的唯一性 | |
| 53 | + validateCategoryNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName()); | |
| 54 | + | |
| 55 | + // 更新 | |
| 56 | + InfraCategoryDO updateObj = BeanUtils.toBean(updateReqVO, InfraCategoryDO.class); | |
| 57 | + categoryMapper.updateById(updateObj); | |
| 58 | + } | |
| 59 | + | |
| 60 | + @Override | |
| 61 | + public void deleteCategory(Long id) { | |
| 62 | + // 校验存在 | |
| 63 | + validateCategoryExists(id); | |
| 64 | + // 校验是否有子分类 | |
| 65 | + if (categoryMapper.selectCountByParentId(id) > 0) { | |
| 66 | + throw exception(CATEGORY_EXITS_CHILDREN); | |
| 67 | + } | |
| 68 | + // 删除 | |
| 69 | + categoryMapper.deleteById(id); | |
| 70 | + } | |
| 71 | + | |
| 72 | + private void validateCategoryExists(Long id) { | |
| 73 | + if (categoryMapper.selectById(id) == null) { | |
| 74 | + throw exception(CATEGORY_NOT_EXISTS); | |
| 75 | + } | |
| 76 | + } | |
| 77 | + | |
| 78 | + private void validateParentCategory(Long id, Long parentId) { | |
| 79 | + if (parentId == null || CategoryDO.PARENT_ID_ROOT.equals(parentId)) { | |
| 80 | + return; | |
| 81 | + } | |
| 82 | + // 1. 不能设置自己为父分类 | |
| 83 | + if (Objects.equals(id, parentId)) { | |
| 84 | + throw exception(CATEGORY_PARENT_ERROR); | |
| 85 | + } | |
| 86 | + // 2. 父分类不存在 | |
| 87 | + CategoryDO parentCategory = categoryMapper.selectById(parentId); | |
| 88 | + if (parentCategory == null) { | |
| 89 | + throw exception(CATEGORY_PARENT_NOT_EXITS); | |
| 90 | + } | |
| 91 | + // 3. 递归校验父分类,如果父分类是自己的子分类,则报错,避免形成环路 | |
| 92 | + if (id == null) { // id 为空,说明新增,不需要考虑环路 | |
| 93 | + return; | |
| 94 | + } | |
| 95 | + for (int i = 0; i < Short.MAX_VALUE; i++) { | |
| 96 | + // 3.1 校验环路 | |
| 97 | + parentId = parentCategory.getParentId(); | |
| 98 | + if (Objects.equals(id, parentId)) { | |
| 99 | + throw exception(CATEGORY_PARENT_IS_CHILD); | |
| 100 | + } | |
| 101 | + // 3.2 继续递归下一级父分类 | |
| 102 | + if (parentId == null || CategoryDO.PARENT_ID_ROOT.equals(parentId)) { | |
| 103 | + break; | |
| 104 | + } | |
| 105 | + parentCategory = categoryMapper.selectById(parentId); | |
| 106 | + if (parentCategory == null) { | |
| 107 | + break; | |
| 108 | + } | |
| 109 | + } | |
| 110 | + } | |
| 111 | + | |
| 112 | + private void validateCategoryNameUnique(Long id, Long parentId, String name) { | |
| 113 | + CategoryDO category = categoryMapper.selectByParentIdAndName(parentId, name); | |
| 114 | + if (category == null) { | |
| 115 | + return; | |
| 116 | + } | |
| 117 | + // 如果 id 为空,说明不用比较是否为相同 id 的分类 | |
| 118 | + if (id == null) { | |
| 119 | + throw exception(CATEGORY_NAME_DUPLICATE); | |
| 120 | + } | |
| 121 | + if (!Objects.equals(category.getId(), id)) { | |
| 122 | + throw exception(CATEGORY_NAME_DUPLICATE); | |
| 123 | + } | |
| 124 | + } | |
| 125 | + | |
| 126 | + @Override | |
| 127 | + public InfraCategoryDO getCategory(Long id) { | |
| 128 | + return categoryMapper.selectById(id); | |
| 129 | + } | |
| 130 | + | |
| 131 | + @Override | |
| 132 | + public List<InfraCategoryDO> getCategoryList(InfraCategoryListReqVO listReqVO) { | |
| 133 | + return categoryMapper.selectList(listReqVO); | |
| 134 | + } | |
| 135 | + | |
| 136 | +} | |
| 0 | 137 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree/java/InfraCategoryServiceImplTest
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import org.junit.jupiter.api.Disabled; | |
| 4 | +import org.junit.jupiter.api.Test; | |
| 5 | +import org.springframework.boot.test.mock.mockito.MockBean; | |
| 6 | + | |
| 7 | +import javax.annotation.Resource; | |
| 8 | + | |
| 9 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | |
| 10 | + | |
| 11 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraCategoryDO; | |
| 13 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraCategoryMapper; | |
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 15 | + | |
| 16 | +import javax.annotation.Resource; | |
| 17 | +import org.springframework.context.annotation.Import; | |
| 18 | +import java.util.*; | |
| 19 | +import java.time.LocalDateTime; | |
| 20 | + | |
| 21 | +import static cn.hutool.core.util.RandomUtil.*; | |
| 22 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 23 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; | |
| 24 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | |
| 25 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; | |
| 26 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; | |
| 27 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; | |
| 28 | +import static org.junit.jupiter.api.Assertions.*; | |
| 29 | +import static org.mockito.Mockito.*; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * {@link InfraCategoryServiceImpl} 的单元测试类 | |
| 33 | + * | |
| 34 | + * @author 芋道源码 | |
| 35 | + */ | |
| 36 | +@Import(InfraCategoryServiceImpl.class) | |
| 37 | +public class InfraCategoryServiceImplTest extends BaseDbUnitTest { | |
| 38 | + | |
| 39 | + @Resource | |
| 40 | + private InfraCategoryServiceImpl categoryService; | |
| 41 | + | |
| 42 | + @Resource | |
| 43 | + private InfraCategoryMapper categoryMapper; | |
| 44 | + | |
| 45 | + @Test | |
| 46 | + public void testCreateCategory_success() { | |
| 47 | + // 准备参数 | |
| 48 | + InfraCategorySaveReqVO createReqVO = randomPojo(InfraCategorySaveReqVO.class).setId(null); | |
| 49 | + | |
| 50 | + // 调用 | |
| 51 | + Long categoryId = categoryService.createCategory(createReqVO); | |
| 52 | + // 断言 | |
| 53 | + assertNotNull(categoryId); | |
| 54 | + // 校验记录的属性是否正确 | |
| 55 | + InfraCategoryDO category = categoryMapper.selectById(categoryId); | |
| 56 | + assertPojoEquals(createReqVO, category, "id"); | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Test | |
| 60 | + public void testUpdateCategory_success() { | |
| 61 | + // mock 数据 | |
| 62 | + InfraCategoryDO dbCategory = randomPojo(InfraCategoryDO.class); | |
| 63 | + categoryMapper.insert(dbCategory);// @Sql: 先插入出一条存在的数据 | |
| 64 | + // 准备参数 | |
| 65 | + InfraCategorySaveReqVO updateReqVO = randomPojo(InfraCategorySaveReqVO.class, o -> { | |
| 66 | + o.setId(dbCategory.getId()); // 设置更新的 ID | |
| 67 | + }); | |
| 68 | + | |
| 69 | + // 调用 | |
| 70 | + categoryService.updateCategory(updateReqVO); | |
| 71 | + // 校验是否更新正确 | |
| 72 | + InfraCategoryDO category = categoryMapper.selectById(updateReqVO.getId()); // 获取最新的 | |
| 73 | + assertPojoEquals(updateReqVO, category); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Test | |
| 77 | + public void testUpdateCategory_notExists() { | |
| 78 | + // 准备参数 | |
| 79 | + InfraCategorySaveReqVO updateReqVO = randomPojo(InfraCategorySaveReqVO.class); | |
| 80 | + | |
| 81 | + // 调用, 并断言异常 | |
| 82 | + assertServiceException(() -> categoryService.updateCategory(updateReqVO), CATEGORY_NOT_EXISTS); | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Test | |
| 86 | + public void testDeleteCategory_success() { | |
| 87 | + // mock 数据 | |
| 88 | + InfraCategoryDO dbCategory = randomPojo(InfraCategoryDO.class); | |
| 89 | + categoryMapper.insert(dbCategory);// @Sql: 先插入出一条存在的数据 | |
| 90 | + // 准备参数 | |
| 91 | + Long id = dbCategory.getId(); | |
| 92 | + | |
| 93 | + // 调用 | |
| 94 | + categoryService.deleteCategory(id); | |
| 95 | + // 校验数据不存在了 | |
| 96 | + assertNull(categoryMapper.selectById(id)); | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Test | |
| 100 | + public void testDeleteCategory_notExists() { | |
| 101 | + // 准备参数 | |
| 102 | + Long id = randomLongId(); | |
| 103 | + | |
| 104 | + // 调用, 并断言异常 | |
| 105 | + assertServiceException(() -> categoryService.deleteCategory(id), CATEGORY_NOT_EXISTS); | |
| 106 | + } | |
| 107 | + | |
| 108 | + @Test | |
| 109 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 110 | + public void testGetCategoryList() { | |
| 111 | + // mock 数据 | |
| 112 | + InfraCategoryDO dbCategory = randomPojo(InfraCategoryDO.class, o -> { // 等会查询到 | |
| 113 | + o.setName(null); | |
| 114 | + }); | |
| 115 | + categoryMapper.insert(dbCategory); | |
| 116 | + // 测试 name 不匹配 | |
| 117 | + categoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setName(null))); | |
| 118 | + // 准备参数 | |
| 119 | + InfraCategoryListReqVO reqVO = new InfraCategoryListReqVO(); | |
| 120 | + reqVO.setName(null); | |
| 121 | + | |
| 122 | + // 调用 | |
| 123 | + List<InfraCategoryDO> list = categoryService.getCategoryList(reqVO); | |
| 124 | + // 断言 | |
| 125 | + assertEquals(1, list.size()); | |
| 126 | + assertPojoEquals(dbCategory, list.get(0)); | |
| 127 | + } | |
| 128 | + | |
| 129 | +} | |
| 0 | 130 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree/js/category
0 → 100644
| 1 | +import request from '@/utils/request' | |
| 2 | + | |
| 3 | +// 创建分类 | |
| 4 | +export function createCategory(data) { | |
| 5 | + return request({ | |
| 6 | + url: '/infra/category/create', | |
| 7 | + method: 'post', | |
| 8 | + data: data | |
| 9 | + }) | |
| 10 | +} | |
| 11 | + | |
| 12 | +// 更新分类 | |
| 13 | +export function updateCategory(data) { | |
| 14 | + return request({ | |
| 15 | + url: '/infra/category/update', | |
| 16 | + method: 'put', | |
| 17 | + data: data | |
| 18 | + }) | |
| 19 | +} | |
| 20 | + | |
| 21 | +// 删除分类 | |
| 22 | +export function deleteCategory(id) { | |
| 23 | + return request({ | |
| 24 | + url: '/infra/category/delete?id=' + id, | |
| 25 | + method: 'delete' | |
| 26 | + }) | |
| 27 | +} | |
| 28 | + | |
| 29 | +// 获得分类 | |
| 30 | +export function getCategory(id) { | |
| 31 | + return request({ | |
| 32 | + url: '/infra/category/get?id=' + id, | |
| 33 | + method: 'get' | |
| 34 | + }) | |
| 35 | +} | |
| 36 | + | |
| 37 | +// 获得分类列表 | |
| 38 | +export function getCategoryList(params) { | |
| 39 | + return request({ | |
| 40 | + url: '/infra/category/list', | |
| 41 | + method: 'get', | |
| 42 | + params | |
| 43 | + }) | |
| 44 | +} | |
| 45 | +// 导出分类 Excel | |
| 46 | +export function exportCategoryExcel(params) { | |
| 47 | + return request({ | |
| 48 | + url: '/infra/category/export-excel', | |
| 49 | + method: 'get', | |
| 50 | + params, | |
| 51 | + responseType: 'blob' | |
| 52 | + }) | |
| 53 | +} | |
| 0 | 54 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree/sql/h2
0 → 100644
| 1 | +-- 将该建表 SQL 语句,添加到 yudao-module-infra-biz 模块的 test/resources/sql/create_tables.sql 文件里 | |
| 2 | +CREATE TABLE IF NOT EXISTS "infra_category" ( | |
| 3 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 4 | + "name" varchar NOT NULL, | |
| 5 | + "description" bigint NOT NULL, | |
| 6 | + PRIMARY KEY ("id") | |
| 7 | +) COMMENT '分类表'; | |
| 8 | + | |
| 9 | +-- 将该删表 SQL 语句,添加到 yudao-module-infra-biz 模块的 test/resources/sql/clean.sql 文件里 | |
| 10 | +DELETE FROM "infra_category"; | |
| 0 | 11 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree/sql/sql
0 → 100644
| 1 | +-- 菜单 SQL | |
| 2 | +INSERT INTO system_menu( | |
| 3 | + name, permission, type, sort, parent_id, | |
| 4 | + path, icon, component, status, component_name | |
| 5 | +) | |
| 6 | +VALUES ( | |
| 7 | + '分类管理', '', 2, 0, 888, | |
| 8 | + 'category', '', 'infra/demo/index', 0, 'InfraCategory' | |
| 9 | +); | |
| 10 | + | |
| 11 | +-- 按钮父菜单ID | |
| 12 | +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 | |
| 13 | +SELECT @parentId := LAST_INSERT_ID(); | |
| 14 | + | |
| 15 | +-- 按钮 SQL | |
| 16 | +INSERT INTO system_menu( | |
| 17 | + name, permission, type, sort, parent_id, | |
| 18 | + path, icon, component, status | |
| 19 | +) | |
| 20 | +VALUES ( | |
| 21 | + '分类查询', 'infra:category:query', 3, 1, @parentId, | |
| 22 | + '', '', '', 0 | |
| 23 | +); | |
| 24 | +INSERT INTO system_menu( | |
| 25 | + name, permission, type, sort, parent_id, | |
| 26 | + path, icon, component, status | |
| 27 | +) | |
| 28 | +VALUES ( | |
| 29 | + '分类创建', 'infra:category:create', 3, 2, @parentId, | |
| 30 | + '', '', '', 0 | |
| 31 | +); | |
| 32 | +INSERT INTO system_menu( | |
| 33 | + name, permission, type, sort, parent_id, | |
| 34 | + path, icon, component, status | |
| 35 | +) | |
| 36 | +VALUES ( | |
| 37 | + '分类更新', 'infra:category:update', 3, 3, @parentId, | |
| 38 | + '', '', '', 0 | |
| 39 | +); | |
| 40 | +INSERT INTO system_menu( | |
| 41 | + name, permission, type, sort, parent_id, | |
| 42 | + path, icon, component, status | |
| 43 | +) | |
| 44 | +VALUES ( | |
| 45 | + '分类删除', 'infra:category:delete', 3, 4, @parentId, | |
| 46 | + '', '', '', 0 | |
| 47 | +); | |
| 48 | +INSERT INTO system_menu( | |
| 49 | + name, permission, type, sort, parent_id, | |
| 50 | + path, icon, component, status | |
| 51 | +) | |
| 52 | +VALUES ( | |
| 53 | + '分类导出', 'infra:category:export', 3, 5, @parentId, | |
| 54 | + '', '', '', 0 | |
| 55 | +); | |
| 0 | 56 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree/vue/CategoryForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 对话框(添加 / 修改) --> | |
| 4 | + <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body> | |
| 5 | + <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px"> | |
| 6 | + <el-form-item label="名字" prop="name"> | |
| 7 | + <el-input v-model="formData.name" placeholder="请输入名字" /> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="父编号" prop="parentId"> | |
| 10 | + <TreeSelect | |
| 11 | + v-model="formData.parentId" | |
| 12 | + :options="categoryTree" | |
| 13 | + :normalizer="normalizer" | |
| 14 | + placeholder="请选择父编号" | |
| 15 | + /> | |
| 16 | + </el-form-item> | |
| 17 | + </el-form> | |
| 18 | + <div slot="footer" class="dialog-footer"> | |
| 19 | + <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button> | |
| 20 | + <el-button @click="dialogVisible = false">取 消</el-button> | |
| 21 | + </div> | |
| 22 | + </el-dialog> | |
| 23 | + </div> | |
| 24 | +</template> | |
| 25 | + | |
| 26 | +<script> | |
| 27 | + import * as CategoryApi from '@/api/infra/demo' | |
| 28 | + import TreeSelect from "@riophae/vue-treeselect"; | |
| 29 | + import "@riophae/vue-treeselect/dist/vue-treeselect.css"; | |
| 30 | + export default { | |
| 31 | + name: "CategoryForm", | |
| 32 | + components: { | |
| 33 | + TreeSelect, | |
| 34 | + }, | |
| 35 | + data() { | |
| 36 | + return { | |
| 37 | + // 弹出层标题 | |
| 38 | + dialogTitle: "", | |
| 39 | + // 是否显示弹出层 | |
| 40 | + dialogVisible: false, | |
| 41 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 42 | + formLoading: false, | |
| 43 | + // 表单参数 | |
| 44 | + formData: { | |
| 45 | + id: undefined, | |
| 46 | + name: undefined, | |
| 47 | + parentId: undefined, | |
| 48 | + }, | |
| 49 | + // 表单校验 | |
| 50 | + formRules: { | |
| 51 | + name: [{ required: true, message: '名字不能为空', trigger: 'blur' }], | |
| 52 | + parentId: [{ required: true, message: '父编号不能为空', trigger: 'blur' }], | |
| 53 | + }, | |
| 54 | + categoryTree: [], // 树形结构 | |
| 55 | + }; | |
| 56 | + }, | |
| 57 | + methods: { | |
| 58 | + /** 打开弹窗 */ | |
| 59 | + open(id) { | |
| 60 | + this.dialogVisible = true; | |
| 61 | + this.reset(); | |
| 62 | + const that = this; | |
| 63 | + // 修改时,设置数据 | |
| 64 | + if (id) { | |
| 65 | + this.formLoading = true; | |
| 66 | + try { | |
| 67 | + CategoryApi.getCategory(id).then(res=>{ | |
| 68 | + that.formData = res.data; | |
| 69 | + that.title = "修改分类"; | |
| 70 | + }) | |
| 71 | + } finally { | |
| 72 | + this.formLoading = false; | |
| 73 | + } | |
| 74 | + } | |
| 75 | + this.title = "新增分类"; | |
| 76 | + this.getCategoryTree(); | |
| 77 | + }, | |
| 78 | + /** 提交按钮 */ | |
| 79 | + submitForm() { | |
| 80 | + this.formLoading = true; | |
| 81 | + try { | |
| 82 | + const that = this; | |
| 83 | + let data = this.formData; | |
| 84 | + let validate = false; | |
| 85 | + // 校验主表 | |
| 86 | + this.getRef("formRef").validate(valid => { | |
| 87 | + validate = valid; | |
| 88 | + }); | |
| 89 | + // 所有表单校验通过后方可提交 | |
| 90 | + if (!validate) { | |
| 91 | + return; | |
| 92 | + } | |
| 93 | + // 修改的提交 | |
| 94 | + if (data.id) { | |
| 95 | + CategoryApi.updateCategory(data).then(response => { | |
| 96 | + that.$modal.msgSuccess("修改成功"); | |
| 97 | + that.dialogVisible = false; | |
| 98 | + that.$emit('success'); | |
| 99 | + }); | |
| 100 | + return; | |
| 101 | + } | |
| 102 | + // 添加的提交 | |
| 103 | + CategoryApi.createCategory(data).then(response => { | |
| 104 | + that.$modal.msgSuccess("新增成功"); | |
| 105 | + that.dialogVisible = false; | |
| 106 | + that.$emit('success'); | |
| 107 | + }); | |
| 108 | + }finally { | |
| 109 | + this.formLoading = false; | |
| 110 | + } | |
| 111 | + }, | |
| 112 | + getRef(refName){ | |
| 113 | + return this.$refs[refName]; | |
| 114 | + }, | |
| 115 | + /** 获得分类树 */ | |
| 116 | + getCategoryTree() { | |
| 117 | + const that = this; | |
| 118 | + that.categoryTree = []; | |
| 119 | + CategoryApi.getCategoryList().then(res=>{ | |
| 120 | + const root = { id: 0, name: '顶级分类', children: [] }; | |
| 121 | + root.children = this.handleTree(res.data, 'id', 'parentId') | |
| 122 | + that.categoryTree.push(root) | |
| 123 | + }); | |
| 124 | + }, | |
| 125 | + /** 转换分类数据结构 */ | |
| 126 | + normalizer(node) { | |
| 127 | + if (node.children && !node.children.length) { | |
| 128 | + delete node.children; | |
| 129 | + } | |
| 130 | + return { | |
| 131 | + id: node.id, | |
| 132 | + label: node.name, | |
| 133 | + children: node.children | |
| 134 | + }; | |
| 135 | + }, | |
| 136 | + /** 表单重置 */ | |
| 137 | + reset() { | |
| 138 | + this.formData = { | |
| 139 | + id: undefined, | |
| 140 | + name: undefined, | |
| 141 | + parentId: undefined, | |
| 142 | + }; | |
| 143 | + this.resetForm("formRef"); | |
| 144 | + }, | |
| 145 | + } | |
| 146 | + }; | |
| 147 | +</script> | |
| 0 | 148 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree/vue/index
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + | |
| 4 | + <!-- 搜索工作栏 --> | |
| 5 | + <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> | |
| 6 | + <el-form-item label="名字" prop="name"> | |
| 7 | + <el-input v-model="queryParams.name" placeholder="请输入名字" clearable @keyup.enter.native="handleQuery"/> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item> | |
| 10 | + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button> | |
| 11 | + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button> | |
| 12 | + </el-form-item> | |
| 13 | + </el-form> | |
| 14 | + | |
| 15 | + <!-- 操作工具栏 --> | |
| 16 | + <el-row :gutter="10" class="mb8"> | |
| 17 | + <el-col :span="1.5"> | |
| 18 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)" | |
| 19 | + v-hasPermi="['infra:category:create']">新增</el-button> | |
| 20 | + </el-col> | |
| 21 | + <el-col :span="1.5"> | |
| 22 | + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading" | |
| 23 | + v-hasPermi="['infra:category:export']">导出</el-button> | |
| 24 | + </el-col> | |
| 25 | + <el-col :span="1.5"> | |
| 26 | + <el-button type="danger" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll"> | |
| 27 | + 展开/折叠 | |
| 28 | + </el-button> | |
| 29 | + </el-col> | |
| 30 | + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | |
| 31 | + </el-row> | |
| 32 | + | |
| 33 | + <el-table | |
| 34 | + v-loading="loading" | |
| 35 | + :data="list" | |
| 36 | + :stripe="true" | |
| 37 | + :show-overflow-tooltip="true" | |
| 38 | + v-if="refreshTable" | |
| 39 | + row-key="id" | |
| 40 | + :default-expand-all="isExpandAll" | |
| 41 | + :tree-props="{children: 'children', hasChildren: 'hasChildren'}" | |
| 42 | + > | |
| 43 | + <el-table-column label="编号" align="center" prop="id"> | |
| 44 | + <template v-slot="scope"> | |
| 45 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.id" /> | |
| 46 | + </template> | |
| 47 | + </el-table-column> | |
| 48 | + <el-table-column label="名字" align="center" prop="name"> | |
| 49 | + <template v-slot="scope"> | |
| 50 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.name" /> | |
| 51 | + </template> | |
| 52 | + </el-table-column> | |
| 53 | + <el-table-column label="父编号" align="center" prop="parentId"> | |
| 54 | + <template v-slot="scope"> | |
| 55 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.parentId" /> | |
| 56 | + </template> | |
| 57 | + </el-table-column> | |
| 58 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 59 | + <template v-slot="scope"> | |
| 60 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)" | |
| 61 | + v-hasPermi="['infra:category:update']">修改</el-button> | |
| 62 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 63 | + v-hasPermi="['infra:category:delete']">删除</el-button> | |
| 64 | + </template> | |
| 65 | + </el-table-column> | |
| 66 | + </el-table> | |
| 67 | + <!-- 对话框(添加 / 修改) --> | |
| 68 | + <CategoryForm ref="formRef" @success="getList" /> | |
| 69 | + </div> | |
| 70 | +</template> | |
| 71 | + | |
| 72 | +<script> | |
| 73 | +import * as CategoryApi from '@/api/infra/demo'; | |
| 74 | +import CategoryForm from './CategoryForm.vue'; | |
| 75 | +export default { | |
| 76 | + name: "Category", | |
| 77 | + components: { | |
| 78 | + CategoryForm, | |
| 79 | + }, | |
| 80 | + data() { | |
| 81 | + return { | |
| 82 | + // 遮罩层 | |
| 83 | + loading: true, | |
| 84 | + // 导出遮罩层 | |
| 85 | + exportLoading: false, | |
| 86 | + // 显示搜索条件 | |
| 87 | + showSearch: true, | |
| 88 | + // 分类列表 | |
| 89 | + list: [], | |
| 90 | + // 是否展开,默认全部展开 | |
| 91 | + isExpandAll: true, | |
| 92 | + // 重新渲染表格状态 | |
| 93 | + refreshTable: true, | |
| 94 | + // 选中行 | |
| 95 | + currentRow: {}, | |
| 96 | + // 查询参数 | |
| 97 | + queryParams: { | |
| 98 | + name: null, | |
| 99 | + }, | |
| 100 | + }; | |
| 101 | + }, | |
| 102 | + created() { | |
| 103 | + this.getList(); | |
| 104 | + }, | |
| 105 | + methods: { | |
| 106 | + /** 查询列表 */ | |
| 107 | + getList() { | |
| 108 | + try { | |
| 109 | + this.loading = true; | |
| 110 | + CategoryApi.getCategoryList(this.queryParams).then(response => { | |
| 111 | + this.list = this.handleTree(response.data, 'id', 'parentId'); | |
| 112 | + }) | |
| 113 | + } finally { | |
| 114 | + this.loading = false; | |
| 115 | + } | |
| 116 | + }, | |
| 117 | + /** 搜索按钮操作 */ | |
| 118 | + handleQuery() { | |
| 119 | + this.queryParams.pageNo = 1; | |
| 120 | + this.getList(); | |
| 121 | + }, | |
| 122 | + /** 重置按钮操作 */ | |
| 123 | + resetQuery() { | |
| 124 | + this.resetForm("queryForm"); | |
| 125 | + this.handleQuery(); | |
| 126 | + }, | |
| 127 | + /** 添加/修改操作 */ | |
| 128 | + openForm(id) { | |
| 129 | + this.$refs["formRef"].open(id); | |
| 130 | + }, | |
| 131 | + /** 删除按钮操作 */ | |
| 132 | + handleDelete(row) { | |
| 133 | + const that = this; | |
| 134 | + try { | |
| 135 | + const id = row.id; | |
| 136 | + this.$modal.confirm('是否确认删除分类编号为"' + id + '"的数据项?').then(()=>{ | |
| 137 | + return CategoryApi.deleteCategory(id); | |
| 138 | + }).then(() => { | |
| 139 | + that.getList(); | |
| 140 | + that.$modal.msgSuccess("删除成功"); | |
| 141 | + }).catch(() => {}); | |
| 142 | + } catch {} | |
| 143 | + }, | |
| 144 | + /** 导出按钮操作 */ | |
| 145 | + handleExport() { | |
| 146 | + const that = this; | |
| 147 | + try { | |
| 148 | + this.$modal.confirm('是否确认导出所有分类数据项?').then(() => { | |
| 149 | + that.exportLoading = true; | |
| 150 | + return CategoryApi.exportCategoryExcel(params); | |
| 151 | + }).then(response => { | |
| 152 | + that.$download.excel(response, '分类.xls'); | |
| 153 | + }); | |
| 154 | + } catch { | |
| 155 | + } finally { | |
| 156 | + that.exportLoading = false; | |
| 157 | + } | |
| 158 | + }, | |
| 159 | + /** 展开/折叠操作 */ | |
| 160 | + toggleExpandAll() { | |
| 161 | + this.refreshTable = false | |
| 162 | + this.isExpandAll = !this.isExpandAll | |
| 163 | + this.$nextTick(function () { | |
| 164 | + this.refreshTable = true | |
| 165 | + }) | |
| 166 | + } | |
| 167 | + } | |
| 168 | +}; | |
| 169 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree/xml/InfraCategoryMapper
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 3 | +<mapper namespace="cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraCategoryMapper"> | |
| 4 | + | |
| 5 | + <!-- | |
| 6 | + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 | |
| 7 | + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 | |
| 8 | + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 | |
| 9 | + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ | |
| 10 | + --> | |
| 11 | + | |
| 12 | +</mapper> | |
| 0 | 13 | \ No newline at end of file | ... | ... |