Feat: haoka init demo
This commit is contained in:
parent
cbc1b5cec6
commit
9f8622656a
2
pom.xml
2
pom.xml
|
@ -20,7 +20,7 @@
|
|||
<!-- <module>yudao-module-bpm</module>-->
|
||||
<!-- <module>yudao-module-report</module>-->
|
||||
<!-- <module>yudao-module-mp</module>-->
|
||||
<!-- <module>yudao-module-pay</module>-->
|
||||
<module>yudao-module-pay</module>
|
||||
<!-- <module>yudao-module-mall</module>-->
|
||||
<!-- <module>yudao-module-crm</module>-->
|
||||
<!-- <module>yudao-module-erp</module>-->
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
Navicat Premium Dump SQL
|
||||
|
||||
Source Server : 120.46.194.67
|
||||
Source Server Type : MySQL
|
||||
Source Server Version : 50744 (5.7.44)
|
||||
Source Host : 120.46.194.67:3306
|
||||
Source Schema : haoka
|
||||
|
||||
Target Server Type : MySQL
|
||||
Target Server Version : 50744 (5.7.44)
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 11/12/2024 13:56:34
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for haoka_demo
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `haoka_demo`;
|
||||
CREATE TABLE `haoka_demo` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '编号',
|
||||
`name` text CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL COMMENT '名字',
|
||||
`age` int(11) NOT NULL COMMENT '年龄',
|
||||
`agent` tinyint(4) NOT NULL COMMENT '性别',
|
||||
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
|
||||
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
|
||||
`tenant_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '租户编号',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = latin1 COLLATE = latin1_swedish_ci COMMENT = '好卡案例' ROW_FORMAT = Dynamic;
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
|
@ -10,14 +10,13 @@
|
|||
</parent>
|
||||
|
||||
<artifactId>yudao-module-haoka-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<packaging>jar</packaging> <!-- 2. 新增 packaging 为 jar -->
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
<name>${project.artifactId}</name> <!-- 3. 新增 name 为 ${project.artifactId} -->
|
||||
<description> <!-- 4. 新增 description 为该模块的描述 -->
|
||||
haoka api 模块 API,暴露给其它模块调用
|
||||
demo 模块 API,暴露给其它模块调用
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<dependencies> <!-- 5. 新增 yudao-common 依赖 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<artifactId>yudao-common</artifactId>
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
<description>
|
||||
haoka biz 模块,主要实现haoka 等功能。
|
||||
</description>
|
||||
|
||||
<dependencies> <!-- 5. 新增依赖,这里引入的都是比较常用的业务组件、技术组件 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
|
|
|
@ -1,52 +1,54 @@
|
|||
package cn.iocoder.yudao.module.haoka.controller.admin.demo;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import jakarta.validation.constraints.*;
|
||||
import jakarta.validation.*;
|
||||
import jakarta.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.module.haoka.controller.admin.demo.vo.DemoPageReqVO;
|
||||
import cn.iocoder.yudao.module.haoka.controller.admin.demo.vo.DemoRespVO;
|
||||
import cn.iocoder.yudao.module.haoka.controller.admin.demo.vo.DemoSaveReqVO;
|
||||
import cn.iocoder.yudao.module.haoka.dal.dataobject.demo.DemoDO;
|
||||
import cn.iocoder.yudao.module.haoka.service.demo.DemoService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import cn.iocoder.yudao.module.haoka.controller.admin.demo.vo.*;
|
||||
import cn.iocoder.yudao.module.haoka.dal.dataobject.demo.HaokaDemoDO;
|
||||
import cn.iocoder.yudao.module.haoka.service.demo.HaokaDemoService;
|
||||
|
||||
@Tag(name = "管理后台 - 好卡案例")
|
||||
@RestController
|
||||
@RequestMapping("/haoka/demo")
|
||||
@Validated
|
||||
public class DemoController {
|
||||
public class HaokaDemoController {
|
||||
|
||||
@Resource
|
||||
private DemoService demoService;
|
||||
private HaokaDemoService demoService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建好卡案例")
|
||||
@PreAuthorize("@ss.hasPermission('haoka:demo:create')")
|
||||
public CommonResult<Long> createDemo(@Valid @RequestBody DemoSaveReqVO createReqVO) {
|
||||
public CommonResult<Long> createDemo(@Valid @RequestBody HaokaDemoSaveReqVO createReqVO) {
|
||||
return success(demoService.createDemo(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新好卡案例")
|
||||
@PreAuthorize("@ss.hasPermission('haoka:demo:update')")
|
||||
public CommonResult<Boolean> updateDemo(@Valid @RequestBody DemoSaveReqVO updateReqVO) {
|
||||
public CommonResult<Boolean> updateDemo(@Valid @RequestBody HaokaDemoSaveReqVO updateReqVO) {
|
||||
demoService.updateDemo(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
@ -64,30 +66,30 @@ public class DemoController {
|
|||
@Operation(summary = "获得好卡案例")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('haoka:demo:query')")
|
||||
public CommonResult<DemoRespVO> getDemo(@RequestParam("id") Long id) {
|
||||
DemoDO demo = demoService.getDemo(id);
|
||||
return success(BeanUtils.toBean(demo, DemoRespVO.class));
|
||||
public CommonResult<HaokaDemoRespVO> getDemo(@RequestParam("id") Long id) {
|
||||
HaokaDemoDO demo = demoService.getDemo(id);
|
||||
return success(BeanUtils.toBean(demo, HaokaDemoRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得好卡案例分页")
|
||||
@PreAuthorize("@ss.hasPermission('haoka:demo:query')")
|
||||
public CommonResult<PageResult<DemoRespVO>> getDemoPage(@Valid DemoPageReqVO pageReqVO) {
|
||||
PageResult<DemoDO> pageResult = demoService.getDemoPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, DemoRespVO.class));
|
||||
public CommonResult<PageResult<HaokaDemoRespVO>> getDemoPage(@Valid HaokaDemoPageReqVO pageReqVO) {
|
||||
PageResult<HaokaDemoDO> pageResult = demoService.getDemoPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, HaokaDemoRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出好卡案例 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('haoka:demo:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportDemoExcel(@Valid DemoPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
public void exportDemoExcel(@Valid HaokaDemoPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<DemoDO> list = demoService.getDemoPage(pageReqVO).getList();
|
||||
List<HaokaDemoDO> list = demoService.getDemoPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "好卡案例.xls", "数据", DemoRespVO.class,
|
||||
BeanUtils.toBean(list, DemoRespVO.class));
|
||||
ExcelUtils.write(response, "好卡案例.xls", "数据", HaokaDemoRespVO.class,
|
||||
BeanUtils.toBean(list, HaokaDemoRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,12 +1,10 @@
|
|||
package cn.iocoder.yudao.module.haoka.controller.admin.demo.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
@ -15,9 +13,9 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
|||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class DemoPageReqVO extends PageParam {
|
||||
public class HaokaDemoPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "名字", example = "芋艿")
|
||||
@Schema(description = "名字", example = "李四")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "年龄")
|
||||
|
@ -30,4 +28,4 @@ public class DemoPageReqVO extends PageParam {
|
|||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
||||
}
|
|
@ -1,22 +1,24 @@
|
|||
package cn.iocoder.yudao.module.haoka.controller.admin.demo.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
|
||||
@Schema(description = "管理后台 - 好卡案例 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class DemoRespVO {
|
||||
public class HaokaDemoRespVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "21448")
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "28384")
|
||||
@ExcelProperty("编号")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
||||
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
|
||||
@ExcelProperty("名字")
|
||||
private String name;
|
||||
|
||||
|
@ -25,11 +27,12 @@ public class DemoRespVO {
|
|||
private Integer age;
|
||||
|
||||
@Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("性别")
|
||||
@ExcelProperty(value = "性别", converter = DictConvert.class)
|
||||
@DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private Integer agent;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
}
|
|
@ -1,18 +1,18 @@
|
|||
package cn.iocoder.yudao.module.haoka.controller.admin.demo.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 好卡案例新增/修改 Request VO")
|
||||
@Data
|
||||
public class DemoSaveReqVO {
|
||||
public class HaokaDemoSaveReqVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "21448")
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "28384")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
||||
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
|
||||
@NotEmpty(message = "名字不能为空")
|
||||
private String name;
|
||||
|
||||
|
@ -24,4 +24,4 @@ public class DemoSaveReqVO {
|
|||
@NotNull(message = "性别不能为空")
|
||||
private Integer agent;
|
||||
|
||||
}
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
package cn.iocoder.yudao.module.haoka.dal.dataobject.demo;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 好卡案例 DO
|
||||
|
@ -19,7 +20,7 @@ import lombok.*;
|
|||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DemoDO extends BaseDO {
|
||||
public class HaokaDemoDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
|
@ -36,7 +37,9 @@ public class DemoDO extends BaseDO {
|
|||
private Integer age;
|
||||
/**
|
||||
* 性别
|
||||
*
|
||||
* 枚举 {@link TODO system_user_sex 对应的类}
|
||||
*/
|
||||
private Integer agent;
|
||||
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package cn.iocoder.yudao.module.haoka.dal.mysql.demo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.haoka.controller.admin.demo.vo.DemoPageReqVO;
|
||||
import cn.iocoder.yudao.module.haoka.dal.dataobject.demo.DemoDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 好卡案例 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface DemoMapper extends BaseMapperX<DemoDO> {
|
||||
|
||||
default PageResult<DemoDO> selectPage(DemoPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<DemoDO>()
|
||||
.likeIfPresent(DemoDO::getName, reqVO.getName())
|
||||
.eqIfPresent(DemoDO::getAge, reqVO.getAge())
|
||||
.eqIfPresent(DemoDO::getAgent, reqVO.getAgent())
|
||||
.betweenIfPresent(DemoDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(DemoDO::getId));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package cn.iocoder.yudao.module.haoka.dal.mysql.demo;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.haoka.dal.dataobject.demo.HaokaDemoDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.haoka.controller.admin.demo.vo.*;
|
||||
|
||||
/**
|
||||
* 好卡案例 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface HaokaDemoMapper extends BaseMapperX<HaokaDemoDO> {
|
||||
|
||||
default PageResult<HaokaDemoDO> selectPage(HaokaDemoPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<HaokaDemoDO>()
|
||||
.likeIfPresent(HaokaDemoDO::getName, reqVO.getName())
|
||||
.eqIfPresent(HaokaDemoDO::getAge, reqVO.getAge())
|
||||
.eqIfPresent(HaokaDemoDO::getAgent, reqVO.getAgent())
|
||||
.betweenIfPresent(HaokaDemoDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(HaokaDemoDO::getId));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,10 @@
|
|||
/**
|
||||
* haoka system
|
||||
* erp 包下,企业资源管理(Enterprise Resource Planning)。
|
||||
* 例如说:采购、销售、库存、财务、产品等等
|
||||
*
|
||||
* 1. Controller URL:以 /erp/ 开头,避免和其它 Module 冲突
|
||||
* 2. DataObject 表名:以 erp_ 开头,方便在数据库中区分
|
||||
*
|
||||
* 注意,由于 Erp 模块下,容易和其它模块重名,所以类名都加载 Erp 的前缀~
|
||||
*/
|
||||
package cn.iocoder.yudao.module.haoka;
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
package cn.iocoder.yudao.module.haoka.service.demo;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
import cn.iocoder.yudao.module.haoka.controller.admin.demo.vo.*;
|
||||
import cn.iocoder.yudao.module.haoka.dal.dataobject.demo.HaokaDemoDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.haoka.controller.admin.demo.vo.DemoPageReqVO;
|
||||
import cn.iocoder.yudao.module.haoka.controller.admin.demo.vo.DemoSaveReqVO;
|
||||
import cn.iocoder.yudao.module.haoka.dal.dataobject.demo.DemoDO;
|
||||
import jakarta.validation.Valid;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 好卡案例 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface DemoService {
|
||||
public interface HaokaDemoService {
|
||||
|
||||
/**
|
||||
* 创建好卡案例
|
||||
|
@ -19,14 +20,14 @@ public interface DemoService {
|
|||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createDemo(@Valid DemoSaveReqVO createReqVO);
|
||||
Long createDemo(@Valid HaokaDemoSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新好卡案例
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateDemo(@Valid DemoSaveReqVO updateReqVO);
|
||||
void updateDemo(@Valid HaokaDemoSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除好卡案例
|
||||
|
@ -41,7 +42,7 @@ public interface DemoService {
|
|||
* @param id 编号
|
||||
* @return 好卡案例
|
||||
*/
|
||||
DemoDO getDemo(Long id);
|
||||
HaokaDemoDO getDemo(Long id);
|
||||
|
||||
/**
|
||||
* 获得好卡案例分页
|
||||
|
@ -49,6 +50,6 @@ public interface DemoService {
|
|||
* @param pageReqVO 分页查询
|
||||
* @return 好卡案例分页
|
||||
*/
|
||||
PageResult<DemoDO> getDemoPage(DemoPageReqVO pageReqVO);
|
||||
PageResult<HaokaDemoDO> getDemoPage(HaokaDemoPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
}
|
|
@ -1,17 +1,21 @@
|
|||
package cn.iocoder.yudao.module.haoka.service.demo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.haoka.controller.admin.demo.vo.DemoPageReqVO;
|
||||
import cn.iocoder.yudao.module.haoka.controller.admin.demo.vo.DemoSaveReqVO;
|
||||
import cn.iocoder.yudao.module.haoka.dal.dataobject.demo.DemoDO;
|
||||
import cn.iocoder.yudao.module.haoka.dal.mysql.demo.DemoMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import cn.iocoder.yudao.module.haoka.controller.admin.demo.vo.*;
|
||||
import cn.iocoder.yudao.module.haoka.dal.dataobject.demo.HaokaDemoDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
|
||||
import cn.iocoder.yudao.module.haoka.dal.mysql.demo.HaokaDemoMapper;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.haoka.enums.ErrorCodeConstants.DEMO_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.module.haoka.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 好卡案例 Service 实现类
|
||||
|
@ -20,26 +24,26 @@ import static cn.iocoder.yudao.module.haoka.enums.ErrorCodeConstants.DEMO_NOT_EX
|
|||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class DemoServiceImpl implements DemoService {
|
||||
public class HaokaDemoServiceImpl implements HaokaDemoService {
|
||||
|
||||
@Resource
|
||||
private DemoMapper demoMapper;
|
||||
private HaokaDemoMapper demoMapper;
|
||||
|
||||
@Override
|
||||
public Long createDemo(DemoSaveReqVO createReqVO) {
|
||||
public Long createDemo(HaokaDemoSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
DemoDO demo = BeanUtils.toBean(createReqVO, DemoDO.class);
|
||||
HaokaDemoDO demo = BeanUtils.toBean(createReqVO, HaokaDemoDO.class);
|
||||
demoMapper.insert(demo);
|
||||
// 返回
|
||||
return demo.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDemo(DemoSaveReqVO updateReqVO) {
|
||||
public void updateDemo(HaokaDemoSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateDemoExists(updateReqVO.getId());
|
||||
// 更新
|
||||
DemoDO updateObj = BeanUtils.toBean(updateReqVO, DemoDO.class);
|
||||
HaokaDemoDO updateObj = BeanUtils.toBean(updateReqVO, HaokaDemoDO.class);
|
||||
demoMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
|
@ -58,13 +62,13 @@ public class DemoServiceImpl implements DemoService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public DemoDO getDemo(Long id) {
|
||||
public HaokaDemoDO getDemo(Long id) {
|
||||
return demoMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<DemoDO> getDemoPage(DemoPageReqVO pageReqVO) {
|
||||
public PageResult<HaokaDemoDO> getDemoPage(HaokaDemoPageReqVO pageReqVO) {
|
||||
return demoMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.yudao.module.haoka.dal.mysql.demo.DemoMapper">
|
||||
<mapper namespace="cn.iocoder.yudao.module.haoka.dal.mysql.demo.HaokaDemoMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
|
@ -0,0 +1,142 @@
|
|||
package cn.iocoder.yudao.module.haoka.service.demo;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.haoka.controller.admin.demo.vo.*;
|
||||
import cn.iocoder.yudao.module.haoka.dal.dataobject.demo.HaokaDemoDO;
|
||||
import cn.iocoder.yudao.module.haoka.dal.mysql.demo.HaokaDemoMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static cn.iocoder.yudao.module.haoka.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link HaokaDemoServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Import(HaokaDemoServiceImpl.class)
|
||||
public class HaokaDemoServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private HaokaDemoServiceImpl demoService;
|
||||
|
||||
@Resource
|
||||
private HaokaDemoMapper demoMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateDemo_success() {
|
||||
// 准备参数
|
||||
HaokaDemoSaveReqVO createReqVO = randomPojo(HaokaDemoSaveReqVO.class).setId(null);
|
||||
|
||||
// 调用
|
||||
Long demoId = demoService.createDemo(createReqVO);
|
||||
// 断言
|
||||
assertNotNull(demoId);
|
||||
// 校验记录的属性是否正确
|
||||
HaokaDemoDO demo = demoMapper.selectById(demoId);
|
||||
assertPojoEquals(createReqVO, demo, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDemo_success() {
|
||||
// mock 数据
|
||||
HaokaDemoDO dbDemo = randomPojo(HaokaDemoDO.class);
|
||||
demoMapper.insert(dbDemo);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
HaokaDemoSaveReqVO updateReqVO = randomPojo(HaokaDemoSaveReqVO.class, o -> {
|
||||
o.setId(dbDemo.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
demoService.updateDemo(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
HaokaDemoDO demo = demoMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(updateReqVO, demo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDemo_notExists() {
|
||||
// 准备参数
|
||||
HaokaDemoSaveReqVO updateReqVO = randomPojo(HaokaDemoSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> demoService.updateDemo(updateReqVO), DEMO_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteDemo_success() {
|
||||
// mock 数据
|
||||
HaokaDemoDO dbDemo = randomPojo(HaokaDemoDO.class);
|
||||
demoMapper.insert(dbDemo);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbDemo.getId();
|
||||
|
||||
// 调用
|
||||
demoService.deleteDemo(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(demoMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteDemo_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> demoService.deleteDemo(id), DEMO_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetDemoPage() {
|
||||
// mock 数据
|
||||
HaokaDemoDO dbDemo = randomPojo(HaokaDemoDO.class, o -> { // 等会查询到
|
||||
o.setName(null);
|
||||
o.setAge(null);
|
||||
o.setAgent(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
demoMapper.insert(dbDemo);
|
||||
// 测试 name 不匹配
|
||||
demoMapper.insert(cloneIgnoreId(dbDemo, o -> o.setName(null)));
|
||||
// 测试 age 不匹配
|
||||
demoMapper.insert(cloneIgnoreId(dbDemo, o -> o.setAge(null)));
|
||||
// 测试 agent 不匹配
|
||||
demoMapper.insert(cloneIgnoreId(dbDemo, o -> o.setAgent(null)));
|
||||
// 测试 createTime 不匹配
|
||||
demoMapper.insert(cloneIgnoreId(dbDemo, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
HaokaDemoPageReqVO reqVO = new HaokaDemoPageReqVO();
|
||||
reqVO.setName(null);
|
||||
reqVO.setAge(null);
|
||||
reqVO.setAgent(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
PageResult<HaokaDemoDO> pageResult = demoService.getDemoPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbDemo, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
spring:
|
||||
main:
|
||||
lazy-initialization: true # 开启懒加载,加快速度
|
||||
banner-mode: off # 单元测试,禁用 Banner
|
||||
|
||||
--- #################### 数据库相关配置 ####################
|
||||
|
||||
spring:
|
||||
# 数据源配置项
|
||||
datasource:
|
||||
name: ruoyi-vue-pro
|
||||
url: jdbc:h2:mem:testdb;MODE=MYSQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=value; # MODE 使用 MySQL 模式;DATABASE_TO_UPPER 配置表和字段使用小写
|
||||
driver-class-name: org.h2.Driver
|
||||
username: sa
|
||||
password:
|
||||
druid:
|
||||
async-init: true # 单元测试,异步初始化 Druid 连接池,提升启动速度
|
||||
initial-size: 1 # 单元测试,配置为 1,提升启动速度
|
||||
sql:
|
||||
init:
|
||||
schema-locations: classpath:/sql/create_tables.sql
|
||||
|
||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||
data:
|
||||
redis:
|
||||
host: 127.0.0.1 # 地址
|
||||
port: 16379 # 端口(单元测试,使用 16379 端口)
|
||||
database: 0 # 数据库索引
|
||||
|
||||
mybatis-plus:
|
||||
lazy-initialization: true # 单元测试,设置 MyBatis Mapper 延迟加载,加速每个单元测试
|
||||
type-aliases-package: ${yudao.info.base-package}.module.*.dal.dataobject
|
||||
|
||||
--- #################### 定时任务相关配置 ####################
|
||||
|
||||
--- #################### 配置中心相关配置 ####################
|
||||
|
||||
--- #################### 服务保障相关配置 ####################
|
||||
|
||||
# Lock4j 配置项(单元测试,禁用 Lock4j)
|
||||
|
||||
--- #################### 监控相关配置 ####################
|
||||
|
||||
--- #################### 芋道相关配置 ####################
|
||||
|
||||
# 芋道配置项,设置当前项目所有自定义的配置
|
||||
yudao:
|
||||
info:
|
||||
base-package: cn.iocoder.yudao
|
|
@ -0,0 +1,3 @@
|
|||
-- 将该删表 SQL 语句,添加到 yudao-module-haoka-biz 模块的 test/resources/sql/clean.sql 文件里
|
||||
DELETE
|
||||
FROM "haoka_demo";
|
|
@ -0,0 +1,65 @@
|
|||
-- 将该建表 SQL 语句,添加到 yudao-module-haoka-biz 模块的 test/resources/sql/create_tables.sql 文件里
|
||||
CREATE TABLE IF NOT EXISTS "haoka_demo"
|
||||
(
|
||||
"id"
|
||||
bigint
|
||||
NOT
|
||||
NULL
|
||||
GENERATED
|
||||
BY
|
||||
DEFAULT AS
|
||||
IDENTITY,
|
||||
"name"
|
||||
varchar
|
||||
NOT
|
||||
NULL,
|
||||
"age"
|
||||
int
|
||||
NOT
|
||||
NULL,
|
||||
"agent"
|
||||
int
|
||||
NOT
|
||||
NULL,
|
||||
"creator"
|
||||
varchar
|
||||
DEFAULT
|
||||
'',
|
||||
"create_time"
|
||||
datetime
|
||||
NOT
|
||||
NULL
|
||||
DEFAULT
|
||||
CURRENT_TIMESTAMP,
|
||||
"updater"
|
||||
varchar
|
||||
DEFAULT
|
||||
'',
|
||||
"update_time"
|
||||
datetime
|
||||
NOT
|
||||
NULL
|
||||
DEFAULT
|
||||
CURRENT_TIMESTAMP
|
||||
ON
|
||||
UPDATE
|
||||
CURRENT_TIMESTAMP,
|
||||
"deleted"
|
||||
bit
|
||||
NOT
|
||||
NULL
|
||||
DEFAULT
|
||||
FALSE,
|
||||
"tenant_id"
|
||||
bigint
|
||||
NOT
|
||||
NULL
|
||||
DEFAULT
|
||||
0,
|
||||
PRIMARY
|
||||
KEY
|
||||
(
|
||||
"id"
|
||||
)
|
||||
) COMMENT '好卡案例';
|
||||
|
|
@ -246,7 +246,7 @@ yudao:
|
|||
base-package: ${yudao.info.base-package}
|
||||
db-schemas: ${spring.datasource.dynamic.datasource.master.name}
|
||||
front-type: 20 # 前端模版的类型,参见 CodegenFrontTypeEnum 枚举类
|
||||
unit-test-enable: false # 是否生成单元测试
|
||||
unit-test-enable: true # 是否生成单元测试
|
||||
tenant: # 多租户相关配置项
|
||||
enable: true
|
||||
ignore-urls:
|
||||
|
@ -329,4 +329,4 @@ yudao:
|
|||
key: pLXUGAwK5305
|
||||
customer: E77DF18BE109F454A5CD319E44BF5177
|
||||
|
||||
debug: false
|
||||
debug: false
|
||||
|
|
Loading…
Reference in New Issue