From 65eddc63aff153078d6af3f35d2b93601145d961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=AE=E6=A2=A6?= Date: Thu, 24 Aug 2023 17:04:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E7=94=A8=E6=88=B7=E6=94=B6=E4=BB=B6=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E7=AE=A1=E7=90=86=E6=8E=A5=E5=8F=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/address/AddressController.java | 102 ++++++++++++++++++ .../admin/address/vo/AddressBaseVO.java | 37 +++++++ .../admin/address/vo/AddressCreateReqVO.java | 14 +++ .../admin/address/vo/AddressExcelVO.java | 40 +++++++ .../admin/address/vo/AddressExportReqVO.java | 38 +++++++ .../admin/address/vo/AddressPageReqVO.java | 40 +++++++ .../admin/address/vo/AddressRespVO.java | 19 ++++ .../admin/address/vo/AddressUpdateReqVO.java | 18 ++++ .../convert/address/AddressConvert.java | 16 +++ .../dal/mysql/address/AddressMapper.java | 26 +++++ .../service/address/AddressService.java | 59 ++++++++++ .../service/address/AddressServiceImpl.java | 58 ++++++++++ 12 files changed, 467 insertions(+) create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/AddressController.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressBaseVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressCreateReqVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExcelVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExportReqVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressPageReqVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressRespVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressUpdateReqVO.java diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/AddressController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/AddressController.java new file mode 100644 index 000000000..3e6919e83 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/AddressController.java @@ -0,0 +1,102 @@ +package cn.iocoder.yudao.module.member.controller.admin.address; + +import cn.iocoder.yudao.module.member.dal.dataobject.address.MemberAddressDO; +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.member.controller.admin.address.vo.*; +import cn.iocoder.yudao.module.member.convert.address.AddressConvert; +import cn.iocoder.yudao.module.member.service.address.AddressService; + +@Tag(name = "管理后台 - 用户收件地址") +@RestController +@RequestMapping("/member/address") +@Validated +public class AddressController { + + @Resource + private AddressService addressService; + + @PostMapping("/create") + @Operation(summary = "创建用户收件地址") + @PreAuthorize("@ss.hasPermission('member:address:create')") + public CommonResult createAddress(@Valid @RequestBody AddressCreateReqVO createReqVO) { + return success(addressService.createAddress(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新用户收件地址") + @PreAuthorize("@ss.hasPermission('member:address:update')") + public CommonResult updateAddress(@Valid @RequestBody AddressUpdateReqVO updateReqVO) { + addressService.updateAddress(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除用户收件地址") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('member:address:delete')") + public CommonResult deleteAddress(@RequestParam("id") Long id) { + addressService.deleteAddress(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得用户收件地址") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('member:address:query')") + public CommonResult getAddress(@RequestParam("id") Long id) { + MemberAddressDO address = addressService.getAddress(id); + return success(AddressConvert.INSTANCE.convert2(address)); + } + + @GetMapping("/list") + @Operation(summary = "获得用户收件地址列表") + @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") + @PreAuthorize("@ss.hasPermission('member:address:query')") + public CommonResult> getAddressList(@RequestParam("ids") Collection ids) { + List list = addressService.getAddressList(ids); + return success(AddressConvert.INSTANCE.convertList2(list)); + } + + @GetMapping("/page") + @Operation(summary = "获得用户收件地址分页") + @PreAuthorize("@ss.hasPermission('member:address:query')") + public CommonResult> getAddressPage(@Valid AddressPageReqVO pageVO) { + PageResult pageResult = addressService.getAddressPage(pageVO); + return success(AddressConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出用户收件地址 Excel") + @PreAuthorize("@ss.hasPermission('member:address:export')") + @OperateLog(type = EXPORT) + public void exportAddressExcel(@Valid AddressExportReqVO exportReqVO, + HttpServletResponse response) throws IOException { + List list = addressService.getAddressList(exportReqVO); + // 导出 Excel + List datas = AddressConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "用户收件地址.xls", "数据", AddressExcelVO.class, datas); + } + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressBaseVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressBaseVO.java new file mode 100644 index 000000000..5fa2d1ed9 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressBaseVO.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.member.controller.admin.address.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import java.util.*; +import javax.validation.constraints.*; + +/** + * 用户收件地址 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ +@Data +public class AddressBaseVO { + + @Schema(description = "收件人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") + @NotNull(message = "收件人名称不能为空") + private String name; + + @Schema(description = "手机号", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "手机号不能为空") + private String mobile; + + @Schema(description = "地区编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "15716") + @NotNull(message = "地区编码不能为空") + private Long areaId; + + @Schema(description = "收件详细地址", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "收件详细地址不能为空") + private String detailAddress; + + @Schema(description = "是否默认", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @NotNull(message = "是否默认不能为空") + private Boolean defaultStatus; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressCreateReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressCreateReqVO.java new file mode 100644 index 000000000..ac0833ba7 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressCreateReqVO.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.member.controller.admin.address.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 用户收件地址创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AddressCreateReqVO extends AddressBaseVO { + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExcelVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExcelVO.java new file mode 100644 index 000000000..8a0543247 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExcelVO.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.module.member.controller.admin.address.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; + +import com.alibaba.excel.annotation.ExcelProperty; + +/** + * 用户收件地址 Excel VO + * + * @author 绮梦 + */ +@Data +public class AddressExcelVO { + + @ExcelProperty("收件地址编号") + private Long id; + + @ExcelProperty("收件人名称") + private String name; + + @ExcelProperty("手机号") + private String mobile; + + @ExcelProperty("地区编码") + private Long areaId; + + @ExcelProperty("收件详细地址") + private String detailAddress; + + @ExcelProperty("是否默认") + private Boolean defaultStatus; + + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExportReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExportReqVO.java new file mode 100644 index 000000000..214bf952b --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExportReqVO.java @@ -0,0 +1,38 @@ +package cn.iocoder.yudao.module.member.controller.admin.address.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import java.time.LocalDateTime; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 用户收件地址 Excel 导出 Request VO,参数和 AddressPageReqVO 是一致的") +@Data +public class AddressExportReqVO { + + @Schema(description = "用户编号", example = "20369") + private Long userId; + + @Schema(description = "收件人名称", example = "张三") + private String name; + + @Schema(description = "手机号") + private String mobile; + + @Schema(description = "地区编码", example = "15716") + private Long areaId; + + @Schema(description = "收件详细地址") + private String detailAddress; + + @Schema(description = "是否默认", example = "2") + private Boolean defaultStatus; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressPageReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressPageReqVO.java new file mode 100644 index 000000000..32b059448 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressPageReqVO.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.module.member.controller.admin.address.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 AddressPageReqVO extends PageParam { + + @Schema(description = "用户编号", example = "20369") + private Long userId; + + @Schema(description = "收件人名称", example = "张三") + private String name; + + @Schema(description = "手机号") + private String mobile; + + @Schema(description = "地区编码", example = "15716") + private Long areaId; + + @Schema(description = "收件详细地址") + private String detailAddress; + + @Schema(description = "是否默认", example = "2") + private Boolean defaultStatus; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressRespVO.java new file mode 100644 index 000000000..26a4988af --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.member.controller.admin.address.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 用户收件地址 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AddressRespVO extends AddressBaseVO { + + @Schema(description = "收件地址编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "7380") + private Long id; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + private LocalDateTime createTime; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressUpdateReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressUpdateReqVO.java new file mode 100644 index 000000000..4e91579e4 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressUpdateReqVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.member.controller.admin.address.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 用户收件地址更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AddressUpdateReqVO extends AddressBaseVO { + + @Schema(description = "收件地址编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "7380") + @NotNull(message = "收件地址编号不能为空") + private Long id; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/address/AddressConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/address/AddressConvert.java index 8e62de604..e6f56a022 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/address/AddressConvert.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/address/AddressConvert.java @@ -1,7 +1,12 @@ package cn.iocoder.yudao.module.member.convert.address; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressCreateReqVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressExcelVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressRespVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressUpdateReqVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressCreateReqVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressRespVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO; @@ -39,4 +44,15 @@ public interface AddressConvert { return AreaUtils.format(areaId); } + MemberAddressDO convert(AddressCreateReqVO bean); + + MemberAddressDO convert(AddressUpdateReqVO bean); + + AddressRespVO convert2(MemberAddressDO bean); + + List convertList2(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java index db824f6f5..9beb025c0 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java @@ -1,7 +1,10 @@ package cn.iocoder.yudao.module.member.dal.mysql.address; +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.member.controller.admin.address.vo.AddressExportReqVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressPageReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.address.MemberAddressDO; import org.apache.ibatis.annotations.Mapper; @@ -18,5 +21,28 @@ public interface AddressMapper extends BaseMapperX { return selectList(new LambdaQueryWrapperX().eq(MemberAddressDO::getUserId, userId) .eqIfPresent(MemberAddressDO::getDefaultStatus, defaulted)); } + default PageResult selectPage(AddressPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(MemberAddressDO::getUserId, reqVO.getUserId()) + .likeIfPresent(MemberAddressDO::getName, reqVO.getName()) + .eqIfPresent(MemberAddressDO::getMobile, reqVO.getMobile()) + .eqIfPresent(MemberAddressDO::getAreaId, reqVO.getAreaId()) + .eqIfPresent(MemberAddressDO::getDetailAddress, reqVO.getDetailAddress()) + .eqIfPresent(MemberAddressDO::getDefaultStatus, reqVO.getDefaultStatus()) + .betweenIfPresent(MemberAddressDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(MemberAddressDO::getId)); + } + + default List selectList(AddressExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .eqIfPresent(MemberAddressDO::getUserId, reqVO.getUserId()) + .likeIfPresent(MemberAddressDO::getName, reqVO.getName()) + .eqIfPresent(MemberAddressDO::getMobile, reqVO.getMobile()) + .eqIfPresent(MemberAddressDO::getAreaId, reqVO.getAreaId()) + .eqIfPresent(MemberAddressDO::getDetailAddress, reqVO.getDetailAddress()) + .eqIfPresent(MemberAddressDO::getDefaultStatus, reqVO.getDefaultStatus()) + .betweenIfPresent(MemberAddressDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(MemberAddressDO::getId)); + } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java index 099c49c42..260ab7987 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java @@ -1,10 +1,16 @@ package cn.iocoder.yudao.module.member.service.address; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressCreateReqVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressExportReqVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressPageReqVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressUpdateReqVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressCreateReqVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.address.MemberAddressDO; import javax.validation.Valid; +import java.util.Collection; import java.util.List; /** @@ -64,4 +70,57 @@ public interface AddressService { */ MemberAddressDO getDefaultUserAddress(Long userId); + /** + * 创建用户收件地址 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createAddress(@Valid AddressCreateReqVO createReqVO); + + /** + * 更新用户收件地址 + * + * @param updateReqVO 更新信息 + */ + void updateAddress(@Valid AddressUpdateReqVO updateReqVO); + + /** + * 删除用户收件地址 + * + * @param id 编号 + */ + void deleteAddress(Long id); + + /** + * 获得用户收件地址 + * + * @param id 编号 + * @return 用户收件地址 + */ + MemberAddressDO getAddress(Long id); + + /** + * 获得用户收件地址列表 + * + * @param ids 编号 + * @return 用户收件地址列表 + */ + List getAddressList(Collection ids); + + /** + * 获得用户收件地址分页 + * + * @param pageReqVO 分页查询 + * @return 用户收件地址分页 + */ + PageResult getAddressPage(AddressPageReqVO pageReqVO); + + /** + * 获得用户收件地址列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 用户收件地址列表 + */ + List getAddressList(AddressExportReqVO exportReqVO); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java index 2689177ea..79f129b75 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java @@ -1,6 +1,11 @@ package cn.iocoder.yudao.module.member.service.address; import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressCreateReqVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressExportReqVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressPageReqVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressUpdateReqVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressCreateReqVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO; import cn.iocoder.yudao.module.member.convert.address.AddressConvert; @@ -11,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -94,4 +100,56 @@ public class AddressServiceImpl implements AddressService { return CollUtil.getFirst(addresses); } + @Override + public Long createAddress(AddressCreateReqVO createReqVO) { + // 插入 + MemberAddressDO address = AddressConvert.INSTANCE.convert(createReqVO); + addressMapper.insert(address); + // 返回 + return address.getId(); + } + + @Override + public void updateAddress(AddressUpdateReqVO updateReqVO) { + // 校验存在 + validateAddressExists(updateReqVO.getId()); + // 更新 + MemberAddressDO updateObj = AddressConvert.INSTANCE.convert(updateReqVO); + addressMapper.updateById(updateObj); + } + + @Override + public void deleteAddress(Long id) { + // 校验存在 + validateAddressExists(id); + // 删除 + addressMapper.deleteById(id); + } + + private void validateAddressExists(Long id) { + if (addressMapper.selectById(id) == null) { + throw exception(ADDRESS_NOT_EXISTS); + } + } + + @Override + public MemberAddressDO getAddress(Long id) { + return addressMapper.selectById(id); + } + + @Override + public List getAddressList(Collection ids) { + return addressMapper.selectBatchIds(ids); + } + + @Override + public PageResult getAddressPage(AddressPageReqVO pageReqVO) { + return addressMapper.selectPage(pageReqVO); + } + + @Override + public List getAddressList(AddressExportReqVO exportReqVO) { + return addressMapper.selectList(exportReqVO); + } + }