mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-02-01 19:24:57 +08:00
[feat] 新增客户管理模块
This commit is contained in:
parent
442ed6b3a9
commit
2632866955
@ -0,0 +1,12 @@
|
||||
package cn.iocoder.yudao.module.cms.enums;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
||||
|
||||
/**
|
||||
* @author hhyykk
|
||||
* @description 错误码枚举类 1_020_000_000段
|
||||
* @date 2024/7/3
|
||||
*/
|
||||
public interface ErrorCodeConstants {
|
||||
ErrorCode CUSTOMER_COMPANY_NOT_EXISTS = new ErrorCode(1_020_000_000, "客户公司管理不存在");
|
||||
}
|
@ -51,5 +51,10 @@
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<artifactId>yudao-spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
<!-- excel 导入导出 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<artifactId>yudao-spring-boot-starter-excel</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,95 @@
|
||||
package cn.iocoder.yudao.module.cms.controller.admin.customerCompany;
|
||||
|
||||
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 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.cms.controller.admin.customerCompany.vo.*;
|
||||
import cn.iocoder.yudao.module.cms.dal.dataobject.customerCompany.CustomerCompanyDO;
|
||||
import cn.iocoder.yudao.module.cms.service.customerCompany.CustomerCompanyService;
|
||||
|
||||
@Tag(name = "管理后台 - 客户公司")
|
||||
@RestController
|
||||
@RequestMapping("/cms/customer-company")
|
||||
@Validated
|
||||
public class CustomerCompanyController {
|
||||
|
||||
@Resource
|
||||
private CustomerCompanyService customerCompanyService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建客户公司")
|
||||
@PreAuthorize("@ss.hasPermission('cms:customer-company:create')")
|
||||
public CommonResult<Long> createCustomerCompany(@Valid @RequestBody CustomerCompanySaveReqVO createReqVO) {
|
||||
return success(customerCompanyService.createCustomerCompany(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新客户公司")
|
||||
@PreAuthorize("@ss.hasPermission('cms:customer-company:update')")
|
||||
public CommonResult<Boolean> updateCustomerCompany(@Valid @RequestBody CustomerCompanySaveReqVO updateReqVO) {
|
||||
customerCompanyService.updateCustomerCompany(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除客户公司")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('cms:customer-company:delete')")
|
||||
public CommonResult<Boolean> deleteCustomerCompany(@RequestParam("id") Long id) {
|
||||
customerCompanyService.deleteCustomerCompany(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得客户公司")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('cms:customer-company:query')")
|
||||
public CommonResult<CustomerCompanyRespVO> getCustomerCompany(@RequestParam("id") Long id) {
|
||||
CustomerCompanyDO customerCompany = customerCompanyService.getCustomerCompany(id);
|
||||
return success(BeanUtils.toBean(customerCompany, CustomerCompanyRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得客户公司分页")
|
||||
@PreAuthorize("@ss.hasPermission('cms:customer-company:query')")
|
||||
public CommonResult<PageResult<CustomerCompanyRespVO>> getCustomerCompanyPage(@Valid CustomerCompanyPageReqVO pageReqVO) {
|
||||
PageResult<CustomerCompanyDO> pageResult = customerCompanyService.getCustomerCompanyPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, CustomerCompanyRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出客户公司 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('cms:customer-company:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportCustomerCompanyExcel(@Valid CustomerCompanyPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<CustomerCompanyDO> list = customerCompanyService.getCustomerCompanyPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "客户公司.xls", "数据", CustomerCompanyRespVO.class,
|
||||
BeanUtils.toBean(list, CustomerCompanyRespVO.class));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package cn.iocoder.yudao.module.cms.controller.admin.customerCompany.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 客户公司分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CustomerCompanyPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "联系人", example = "张三")
|
||||
private String contacts;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "公司名称", example = "电力公司")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "地址")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "电话")
|
||||
private String phone;
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package cn.iocoder.yudao.module.cms.controller.admin.customerCompany.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 客户公司 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class CustomerCompanyRespVO {
|
||||
|
||||
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "14907")
|
||||
@ExcelProperty("主键")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "联系人", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
|
||||
@ExcelProperty("联系人")
|
||||
private String contacts;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "公司名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "电力公司")
|
||||
@ExcelProperty("公司名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "地址")
|
||||
@ExcelProperty("地址")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "电话")
|
||||
@ExcelProperty("电话")
|
||||
private String phone;
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package cn.iocoder.yudao.module.cms.controller.admin.customerCompany.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 客户公司新增/修改 Request VO")
|
||||
@Data
|
||||
public class CustomerCompanySaveReqVO {
|
||||
|
||||
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "14907")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "联系人", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
|
||||
@NotEmpty(message = "联系人不能为空")
|
||||
private String contacts;
|
||||
|
||||
@Schema(description = "公司名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "电力公司")
|
||||
@NotEmpty(message = "公司名称不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "地址")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "电话")
|
||||
private String phone;
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package cn.iocoder.yudao.module.cms.dal.dataobject.customerCompany;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 客户公司 DO
|
||||
*
|
||||
* @author hhyykk
|
||||
*/
|
||||
@TableName("cms_customer_company")
|
||||
@KeySequence("cms_customer_company_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CustomerCompanyDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 联系人
|
||||
*/
|
||||
private String contacts;
|
||||
/**
|
||||
* 公司名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 地址
|
||||
*/
|
||||
private String address;
|
||||
/**
|
||||
* 电话
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package cn.iocoder.yudao.module.cms.dal.mysql.customerCompany;
|
||||
|
||||
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.cms.dal.dataobject.customerCompany.CustomerCompanyDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.cms.controller.admin.customerCompany.vo.*;
|
||||
|
||||
/**
|
||||
* 客户公司 Mapper
|
||||
*
|
||||
* @author hhyykk
|
||||
*/
|
||||
@Mapper
|
||||
public interface CustomerCompanyMapper extends BaseMapperX<CustomerCompanyDO> {
|
||||
|
||||
default PageResult<CustomerCompanyDO> selectPage(CustomerCompanyPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<CustomerCompanyDO>()
|
||||
.likeIfPresent(CustomerCompanyDO::getContacts, reqVO.getContacts())
|
||||
.eqIfPresent(CustomerCompanyDO::getCreateTime, reqVO.getCreateTime())
|
||||
.likeIfPresent(CustomerCompanyDO::getName, reqVO.getName())
|
||||
.eqIfPresent(CustomerCompanyDO::getAddress, reqVO.getAddress())
|
||||
.eqIfPresent(CustomerCompanyDO::getPhone, reqVO.getPhone())
|
||||
.orderByDesc(CustomerCompanyDO::getId));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package cn.iocoder.yudao.module.cms.service.customerCompany;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
import cn.iocoder.yudao.module.cms.controller.admin.customerCompany.vo.*;
|
||||
import cn.iocoder.yudao.module.cms.dal.dataobject.customerCompany.CustomerCompanyDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 客户公司 Service 接口
|
||||
*
|
||||
* @author hhyykk
|
||||
*/
|
||||
public interface CustomerCompanyService {
|
||||
|
||||
/**
|
||||
* 创建客户公司
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createCustomerCompany(@Valid CustomerCompanySaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新客户公司
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateCustomerCompany(@Valid CustomerCompanySaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除客户公司
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteCustomerCompany(Long id);
|
||||
|
||||
/**
|
||||
* 获得客户公司
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 客户公司
|
||||
*/
|
||||
CustomerCompanyDO getCustomerCompany(Long id);
|
||||
|
||||
/**
|
||||
* 获得客户公司分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 客户公司分页
|
||||
*/
|
||||
PageResult<CustomerCompanyDO> getCustomerCompanyPage(CustomerCompanyPageReqVO pageReqVO);
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package cn.iocoder.yudao.module.cms.service.customerCompany;
|
||||
|
||||
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.cms.controller.admin.customerCompany.vo.*;
|
||||
import cn.iocoder.yudao.module.cms.dal.dataobject.customerCompany.CustomerCompanyDO;
|
||||
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.cms.dal.mysql.customerCompany.CustomerCompanyMapper;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.cms.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 客户公司 Service 实现类
|
||||
*
|
||||
* @author hhyykk
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class CustomerCompanyServiceImpl implements CustomerCompanyService {
|
||||
|
||||
@Resource
|
||||
private CustomerCompanyMapper customerCompanyMapper;
|
||||
|
||||
@Override
|
||||
public Long createCustomerCompany(CustomerCompanySaveReqVO createReqVO) {
|
||||
// 插入
|
||||
CustomerCompanyDO customerCompany = BeanUtils.toBean(createReqVO, CustomerCompanyDO.class);
|
||||
customerCompanyMapper.insert(customerCompany);
|
||||
// 返回
|
||||
return customerCompany.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCustomerCompany(CustomerCompanySaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateCustomerCompanyExists(updateReqVO.getId());
|
||||
// 更新
|
||||
CustomerCompanyDO updateObj = BeanUtils.toBean(updateReqVO, CustomerCompanyDO.class);
|
||||
customerCompanyMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCustomerCompany(Long id) {
|
||||
// 校验存在
|
||||
validateCustomerCompanyExists(id);
|
||||
// 删除
|
||||
customerCompanyMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateCustomerCompanyExists(Long id) {
|
||||
if (customerCompanyMapper.selectById(id) == null) {
|
||||
throw exception(CUSTOMER_COMPANY_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomerCompanyDO getCustomerCompany(Long id) {
|
||||
return customerCompanyMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<CustomerCompanyDO> getCustomerCompanyPage(CustomerCompanyPageReqVO pageReqVO) {
|
||||
return customerCompanyMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
<?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.cms.dal.mysql.customerCompany.CustomerCompanyMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
@ -0,0 +1,146 @@
|
||||
package cn.iocoder.yudao.module.cms.service.customerCompany;
|
||||
|
||||
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.cms.controller.admin.customerCompany.vo.*;
|
||||
import cn.iocoder.yudao.module.cms.dal.dataobject.customerCompany.CustomerCompanyDO;
|
||||
import cn.iocoder.yudao.module.cms.dal.mysql.customerCompany.CustomerCompanyMapper;
|
||||
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.cms.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 CustomerCompanyServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author hhyykk
|
||||
*/
|
||||
@Import(CustomerCompanyServiceImpl.class)
|
||||
public class CustomerCompanyServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private CustomerCompanyServiceImpl customerCompanyService;
|
||||
|
||||
@Resource
|
||||
private CustomerCompanyMapper customerCompanyMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateCustomerCompany_success() {
|
||||
// 准备参数
|
||||
CustomerCompanySaveReqVO createReqVO = randomPojo(CustomerCompanySaveReqVO.class).setId(null);
|
||||
|
||||
// 调用
|
||||
Long customerCompanyId = customerCompanyService.createCustomerCompany(createReqVO);
|
||||
// 断言
|
||||
assertNotNull(customerCompanyId);
|
||||
// 校验记录的属性是否正确
|
||||
CustomerCompanyDO customerCompany = customerCompanyMapper.selectById(customerCompanyId);
|
||||
assertPojoEquals(createReqVO, customerCompany, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateCustomerCompany_success() {
|
||||
// mock 数据
|
||||
CustomerCompanyDO dbCustomerCompany = randomPojo(CustomerCompanyDO.class);
|
||||
customerCompanyMapper.insert(dbCustomerCompany);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
CustomerCompanySaveReqVO updateReqVO = randomPojo(CustomerCompanySaveReqVO.class, o -> {
|
||||
o.setId(dbCustomerCompany.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
customerCompanyService.updateCustomerCompany(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
CustomerCompanyDO customerCompany = customerCompanyMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(updateReqVO, customerCompany);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateCustomerCompany_notExists() {
|
||||
// 准备参数
|
||||
CustomerCompanySaveReqVO updateReqVO = randomPojo(CustomerCompanySaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> customerCompanyService.updateCustomerCompany(updateReqVO), CUSTOMER_COMPANY_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCustomerCompany_success() {
|
||||
// mock 数据
|
||||
CustomerCompanyDO dbCustomerCompany = randomPojo(CustomerCompanyDO.class);
|
||||
customerCompanyMapper.insert(dbCustomerCompany);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbCustomerCompany.getId();
|
||||
|
||||
// 调用
|
||||
customerCompanyService.deleteCustomerCompany(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(customerCompanyMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCustomerCompany_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> customerCompanyService.deleteCustomerCompany(id), CUSTOMER_COMPANY_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetCustomerCompanyPage() {
|
||||
// mock 数据
|
||||
CustomerCompanyDO dbCustomerCompany = randomPojo(CustomerCompanyDO.class, o -> { // 等会查询到
|
||||
o.setContacts(null);
|
||||
o.setCreateTime(null);
|
||||
o.setName(null);
|
||||
o.setAddress(null);
|
||||
o.setPhone(null);
|
||||
});
|
||||
customerCompanyMapper.insert(dbCustomerCompany);
|
||||
// 测试 contacts 不匹配
|
||||
customerCompanyMapper.insert(cloneIgnoreId(dbCustomerCompany, o -> o.setContacts(null)));
|
||||
// 测试 createTime 不匹配
|
||||
customerCompanyMapper.insert(cloneIgnoreId(dbCustomerCompany, o -> o.setCreateTime(null)));
|
||||
// 测试 name 不匹配
|
||||
customerCompanyMapper.insert(cloneIgnoreId(dbCustomerCompany, o -> o.setName(null)));
|
||||
// 测试 address 不匹配
|
||||
customerCompanyMapper.insert(cloneIgnoreId(dbCustomerCompany, o -> o.setAddress(null)));
|
||||
// 测试 phone 不匹配
|
||||
customerCompanyMapper.insert(cloneIgnoreId(dbCustomerCompany, o -> o.setPhone(null)));
|
||||
// 准备参数
|
||||
CustomerCompanyPageReqVO reqVO = new CustomerCompanyPageReqVO();
|
||||
reqVO.setContacts(null);
|
||||
reqVO.setCreateTime(null);
|
||||
reqVO.setName(null);
|
||||
reqVO.setAddress(null);
|
||||
reqVO.setPhone(null);
|
||||
|
||||
// 调用
|
||||
PageResult<CustomerCompanyDO> pageResult = customerCompanyService.getCustomerCompanyPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbCustomerCompany, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
@ -182,7 +182,7 @@ yudao:
|
||||
db-schemas: ${spring.datasource.dynamic.datasource.master.name}
|
||||
front-type: 10 # 前端模版的类型,参见 CodegenFrontTypeEnum 枚举类
|
||||
tenant: # 多租户相关配置项
|
||||
enable: false
|
||||
enable: true
|
||||
ignore-urls:
|
||||
- /admin-api/system/tenant/get-id-by-name # 基于名字获取租户,不许带租户编号
|
||||
- /admin-api/system/tenant/get-by-website # 基于域名获取租户,不许带租户编号
|
||||
|
Loading…
Reference in New Issue
Block a user