✨ ERP:增加 ERP 客户的实现
parent
256d243507
commit
7495bb05d1
@ -0,0 +1,102 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.sale;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.customer.ErpCustomerPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.customer.ErpCustomerRespVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.customer.ErpCustomerSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpCustomerDO;
|
||||
import cn.iocoder.yudao.module.erp.service.sale.ErpCustomerService;
|
||||
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.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Tag(name = "管理后台 - ERP 客户")
|
||||
@RestController
|
||||
@RequestMapping("/erp/customer")
|
||||
@Validated
|
||||
public class ErpCustomerController {
|
||||
|
||||
@Resource
|
||||
private ErpCustomerService customerService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建客户")
|
||||
@PreAuthorize("@ss.hasPermission('erp:customer:create')")
|
||||
public CommonResult<Long> createCustomer(@Valid @RequestBody ErpCustomerSaveReqVO createReqVO) {
|
||||
return success(customerService.createCustomer(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新客户")
|
||||
@PreAuthorize("@ss.hasPermission('erp:customer:update')")
|
||||
public CommonResult<Boolean> updateCustomer(@Valid @RequestBody ErpCustomerSaveReqVO updateReqVO) {
|
||||
customerService.updateCustomer(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除客户")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('erp:customer:delete')")
|
||||
public CommonResult<Boolean> deleteCustomer(@RequestParam("id") Long id) {
|
||||
customerService.deleteCustomer(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得客户")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('erp:customer:query')")
|
||||
public CommonResult<ErpCustomerRespVO> getCustomer(@RequestParam("id") Long id) {
|
||||
ErpCustomerDO customer = customerService.getCustomer(id);
|
||||
return success(BeanUtils.toBean(customer, ErpCustomerRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得客户分页")
|
||||
@PreAuthorize("@ss.hasPermission('erp:customer:query')")
|
||||
public CommonResult<PageResult<ErpCustomerRespVO>> getCustomerPage(@Valid ErpCustomerPageReqVO pageReqVO) {
|
||||
PageResult<ErpCustomerDO> pageResult = customerService.getCustomerPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, ErpCustomerRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/simple-list")
|
||||
@Operation(summary = "获得客户精简列表", description = "只包含被开启的客户,主要用于前端的下拉选项")
|
||||
public CommonResult<List<ErpCustomerRespVO>> getCustomerSimpleList() {
|
||||
List<ErpCustomerDO> list = customerService.getCustomerListByStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
return success(convertList(list, customer -> new ErpCustomerRespVO().setId(customer.getId()).setName(customer.getName())));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出客户 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('erp:customer:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportCustomerExcel(@Valid ErpCustomerPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<ErpCustomerDO> list = customerService.getCustomerPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "客户.xls", "数据", ErpCustomerRespVO.class,
|
||||
BeanUtils.toBean(list, ErpCustomerRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.sale.vo.customer;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import java.math.BigDecimal;
|
||||
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 = "管理后台 - ERP 客户分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ErpCustomerPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "客户名称", example = "张三")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "手机号码", example = "15601691300")
|
||||
private String mobile;
|
||||
|
||||
@Schema(description = "联系电话", example = "15601691300")
|
||||
private String telephone;
|
||||
|
||||
}
|
||||
@ -0,0 +1,84 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.sale.vo.customer;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
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 = "管理后台 - ERP 客户 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class ErpCustomerRespVO {
|
||||
|
||||
@Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27520")
|
||||
@ExcelProperty("客户编号")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "客户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
|
||||
@ExcelProperty("客户名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "联系人", example = "老王")
|
||||
@ExcelProperty("联系人")
|
||||
private String contact;
|
||||
|
||||
@Schema(description = "手机号码", example = "15601691300")
|
||||
@ExcelProperty("手机号码")
|
||||
private String mobile;
|
||||
|
||||
@Schema(description = "联系电话", example = "15601691300")
|
||||
@ExcelProperty("联系电话")
|
||||
private String telephone;
|
||||
|
||||
@Schema(description = "电子邮箱", example = "7685323@qq.com")
|
||||
@ExcelProperty("电子邮箱")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "传真", example = "20 7123 4567")
|
||||
@ExcelProperty("传真")
|
||||
private String fax;
|
||||
|
||||
@Schema(description = "备注", example = "你猜")
|
||||
@ExcelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "开启状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty(value = "开启状态", converter = DictConvert.class)
|
||||
@DictFormat("common_status") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||
@ExcelProperty("排序")
|
||||
private Integer sort;
|
||||
|
||||
@Schema(description = "纳税人识别号", example = "91130803MA098BY05W")
|
||||
@ExcelProperty("纳税人识别号")
|
||||
private String taxNo;
|
||||
|
||||
@Schema(description = "税率", example = "10")
|
||||
@ExcelProperty("税率")
|
||||
private BigDecimal taxPercent;
|
||||
|
||||
@Schema(description = "开户行", example = "芋艿")
|
||||
@ExcelProperty("开户行")
|
||||
private String bankName;
|
||||
|
||||
@Schema(description = "开户账号", example = "622908212277228617")
|
||||
@ExcelProperty("开户账号")
|
||||
private String bankAccount;
|
||||
|
||||
@Schema(description = "开户地址", example = "兴业银行浦东支行")
|
||||
@ExcelProperty("开户地址")
|
||||
private String bankAddress;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.sale.vo.customer;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Schema(description = "管理后台 - ERP 客户新增/修改 Request VO")
|
||||
@Data
|
||||
public class ErpCustomerSaveReqVO {
|
||||
|
||||
@Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27520")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "客户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
|
||||
@NotEmpty(message = "客户名称不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "联系人", example = "老王")
|
||||
private String contact;
|
||||
|
||||
@Schema(description = "手机号码", example = "15601691300")
|
||||
private String mobile;
|
||||
|
||||
@Schema(description = "联系电话", example = "15601691300")
|
||||
private String telephone;
|
||||
|
||||
@Schema(description = "电子邮箱", example = "7685323@qq.com")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "传真", example = "20 7123 4567")
|
||||
private String fax;
|
||||
|
||||
@Schema(description = "备注", example = "你猜")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "开启状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "开启状态不能为空")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||
@NotNull(message = "排序不能为空")
|
||||
private Integer sort;
|
||||
|
||||
@Schema(description = "纳税人识别号", example = "91130803MA098BY05W")
|
||||
private String taxNo;
|
||||
|
||||
@Schema(description = "税率", example = "10")
|
||||
private BigDecimal taxPercent;
|
||||
|
||||
@Schema(description = "开户行", example = "芋艿")
|
||||
private String bankName;
|
||||
|
||||
@Schema(description = "开户账号", example = "622908212277228617")
|
||||
private String bankAccount;
|
||||
|
||||
@Schema(description = "开户地址", example = "兴业银行浦东支行")
|
||||
private String bankAddress;
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.dataobject.supplier;
|
||||
package cn.iocoder.yudao.module.erp.dal.dataobject.purchase;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
@ -0,0 +1,90 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.dataobject.sale;
|
||||
|
||||
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.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* ERP 客户 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("erp_customer")
|
||||
@KeySequence("erp_customer_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ErpCustomerDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 客户编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 客户名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 联系人
|
||||
*/
|
||||
private String contact;
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
private String mobile;
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
private String telephone;
|
||||
/**
|
||||
* 电子邮箱
|
||||
*/
|
||||
private String email;
|
||||
/**
|
||||
* 传真
|
||||
*/
|
||||
private String fax;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 开启状态
|
||||
*
|
||||
* 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 纳税人识别号
|
||||
*/
|
||||
private String taxNo;
|
||||
/**
|
||||
* 税率
|
||||
*/
|
||||
private BigDecimal taxPercent;
|
||||
/**
|
||||
* 开户行
|
||||
*/
|
||||
private String bankName;
|
||||
/**
|
||||
* 开户账号
|
||||
*/
|
||||
private String bankAccount;
|
||||
/**
|
||||
* 开户地址
|
||||
*/
|
||||
private String bankAddress;
|
||||
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.mysql.sale;
|
||||
|
||||
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.erp.controller.admin.sale.vo.customer.ErpCustomerPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpCustomerDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ERP 客户 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface ErpCustomerMapper extends BaseMapperX<ErpCustomerDO> {
|
||||
|
||||
default PageResult<ErpCustomerDO> selectPage(ErpCustomerPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<ErpCustomerDO>()
|
||||
.likeIfPresent(ErpCustomerDO::getName, reqVO.getName())
|
||||
.eqIfPresent(ErpCustomerDO::getMobile, reqVO.getMobile())
|
||||
.eqIfPresent(ErpCustomerDO::getTelephone, reqVO.getTelephone())
|
||||
.orderByDesc(ErpCustomerDO::getId));
|
||||
}
|
||||
|
||||
default List<ErpCustomerDO> selectListByStatus(Integer status) {
|
||||
return selectList(ErpCustomerDO::getStatus, status);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,94 @@
|
||||
package cn.iocoder.yudao.module.erp.service.sale;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.customer.ErpCustomerPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.customer.ErpCustomerSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpCustomerDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
|
||||
/**
|
||||
* ERP 客户 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface ErpCustomerService {
|
||||
|
||||
/**
|
||||
* 创建客户
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createCustomer(@Valid ErpCustomerSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新客户
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateCustomer(@Valid ErpCustomerSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除客户
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteCustomer(Long id);
|
||||
|
||||
/**
|
||||
* 获得客户
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 客户
|
||||
*/
|
||||
ErpCustomerDO getCustomer(Long id);
|
||||
|
||||
/**
|
||||
* 校验客户
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 客户
|
||||
*/
|
||||
ErpCustomerDO validateCustomer(Long id);
|
||||
|
||||
/**
|
||||
* 获得客户列表
|
||||
*
|
||||
* @param ids 编号列表
|
||||
* @return 客户列表
|
||||
*/
|
||||
List<ErpCustomerDO> getCustomerList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得客户 Map
|
||||
*
|
||||
* @param ids 编号列表
|
||||
* @return 客户 Map
|
||||
*/
|
||||
default Map<Long, ErpCustomerDO> getCustomerMap(Collection<Long> ids) {
|
||||
return convertMap(getCustomerList(ids), ErpCustomerDO::getId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得客户分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 客户分页
|
||||
*/
|
||||
PageResult<ErpCustomerDO> getCustomerPage(ErpCustomerPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得指定状态的客户列表
|
||||
*
|
||||
* @param status 状态
|
||||
* @return 客户列表
|
||||
*/
|
||||
List<ErpCustomerDO> getCustomerListByStatus(Integer status);
|
||||
|
||||
}
|
||||
@ -0,0 +1,97 @@
|
||||
package cn.iocoder.yudao.module.erp.service.sale;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.customer.ErpCustomerPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.customer.ErpCustomerSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpCustomerDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.sale.ErpCustomerMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.CUSTOMER_NOT_ENABLE;
|
||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.CUSTOMER_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* ERP 客户 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ErpCustomerServiceImpl implements ErpCustomerService {
|
||||
|
||||
@Resource
|
||||
private ErpCustomerMapper customerMapper;
|
||||
|
||||
@Override
|
||||
public Long createCustomer(ErpCustomerSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
ErpCustomerDO customer = BeanUtils.toBean(createReqVO, ErpCustomerDO.class);
|
||||
customerMapper.insert(customer);
|
||||
// 返回
|
||||
return customer.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCustomer(ErpCustomerSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateCustomerExists(updateReqVO.getId());
|
||||
// 更新
|
||||
ErpCustomerDO updateObj = BeanUtils.toBean(updateReqVO, ErpCustomerDO.class);
|
||||
customerMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCustomer(Long id) {
|
||||
// 校验存在
|
||||
validateCustomerExists(id);
|
||||
// 删除
|
||||
customerMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateCustomerExists(Long id) {
|
||||
if (customerMapper.selectById(id) == null) {
|
||||
throw exception(CUSTOMER_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErpCustomerDO getCustomer(Long id) {
|
||||
return customerMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErpCustomerDO validateCustomer(Long id) {
|
||||
ErpCustomerDO customer = customerMapper.selectById(id);
|
||||
if (customer == null) {
|
||||
throw exception(CUSTOMER_NOT_EXISTS);
|
||||
}
|
||||
if (CommonStatusEnum.isDisable(customer.getStatus())) {
|
||||
throw exception(CUSTOMER_NOT_ENABLE, customer.getName());
|
||||
}
|
||||
return customer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ErpCustomerDO> getCustomerList(Collection<Long> ids) {
|
||||
return customerMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ErpCustomerDO> getCustomerPage(ErpCustomerPageReqVO pageReqVO) {
|
||||
return customerMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ErpCustomerDO> getCustomerListByStatus(Integer status) {
|
||||
return customerMapper.selectListByStatus(status);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,131 @@
|
||||
package cn.iocoder.yudao.module.erp.service.sale;
|
||||
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.customer.ErpCustomerPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.customer.ErpCustomerSaveReqVO;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpCustomerDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.sale.ErpCustomerMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import static cn.iocoder.yudao.module.erp.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.object.ObjectUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* {@link ErpCustomerServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Import(ErpCustomerServiceImpl.class)
|
||||
public class ErpCustomerServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private ErpCustomerServiceImpl customerService;
|
||||
|
||||
@Resource
|
||||
private ErpCustomerMapper customerMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateCustomer_success() {
|
||||
// 准备参数
|
||||
ErpCustomerSaveReqVO createReqVO = randomPojo(ErpCustomerSaveReqVO.class).setId(null);
|
||||
|
||||
// 调用
|
||||
Long customerId = customerService.createCustomer(createReqVO);
|
||||
// 断言
|
||||
assertNotNull(customerId);
|
||||
// 校验记录的属性是否正确
|
||||
ErpCustomerDO customer = customerMapper.selectById(customerId);
|
||||
assertPojoEquals(createReqVO, customer, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateCustomer_success() {
|
||||
// mock 数据
|
||||
ErpCustomerDO dbCustomer = randomPojo(ErpCustomerDO.class);
|
||||
customerMapper.insert(dbCustomer);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
ErpCustomerSaveReqVO updateReqVO = randomPojo(ErpCustomerSaveReqVO.class, o -> {
|
||||
o.setId(dbCustomer.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
customerService.updateCustomer(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
ErpCustomerDO customer = customerMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(updateReqVO, customer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateCustomer_notExists() {
|
||||
// 准备参数
|
||||
ErpCustomerSaveReqVO updateReqVO = randomPojo(ErpCustomerSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> customerService.updateCustomer(updateReqVO), CUSTOMER_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCustomer_success() {
|
||||
// mock 数据
|
||||
ErpCustomerDO dbCustomer = randomPojo(ErpCustomerDO.class);
|
||||
customerMapper.insert(dbCustomer);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbCustomer.getId();
|
||||
|
||||
// 调用
|
||||
customerService.deleteCustomer(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(customerMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCustomer_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> customerService.deleteCustomer(id), CUSTOMER_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetCustomerPage() {
|
||||
// mock 数据
|
||||
ErpCustomerDO dbCustomer = randomPojo(ErpCustomerDO.class, o -> { // 等会查询到
|
||||
o.setName(null);
|
||||
o.setMobile(null);
|
||||
o.setTelephone(null);
|
||||
});
|
||||
customerMapper.insert(dbCustomer);
|
||||
// 测试 name 不匹配
|
||||
customerMapper.insert(cloneIgnoreId(dbCustomer, o -> o.setName(null)));
|
||||
// 测试 mobile 不匹配
|
||||
customerMapper.insert(cloneIgnoreId(dbCustomer, o -> o.setMobile(null)));
|
||||
// 测试 telephone 不匹配
|
||||
customerMapper.insert(cloneIgnoreId(dbCustomer, o -> o.setTelephone(null)));
|
||||
// 准备参数
|
||||
ErpCustomerPageReqVO reqVO = new ErpCustomerPageReqVO();
|
||||
reqVO.setName(null);
|
||||
reqVO.setMobile(null);
|
||||
reqVO.setTelephone(null);
|
||||
|
||||
// 调用
|
||||
PageResult<ErpCustomerDO> pageResult = customerService.getCustomerPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbCustomer, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue