!589 新增 管理后台 用户收件地址管理接口

Merge pull request !589 from 风狗/管理后台_用户收件地址管理接口
This commit is contained in:
芋道源码 2023-08-25 17:10:45 +00:00 committed by Gitee
commit 3badd5158c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
12 changed files with 467 additions and 0 deletions

View File

@ -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<Long> createAddress(@Valid @RequestBody AddressCreateReqVO createReqVO) {
return success(addressService.createAddress(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新用户收件地址")
@PreAuthorize("@ss.hasPermission('member:address:update')")
public CommonResult<Boolean> 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<Boolean> 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<AddressRespVO> 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<List<AddressRespVO>> getAddressList(@RequestParam("ids") Collection<Long> ids) {
List<MemberAddressDO> list = addressService.getAddressList(ids);
return success(AddressConvert.INSTANCE.convertList2(list));
}
@GetMapping("/page")
@Operation(summary = "获得用户收件地址分页")
@PreAuthorize("@ss.hasPermission('member:address:query')")
public CommonResult<PageResult<AddressRespVO>> getAddressPage(@Valid AddressPageReqVO pageVO) {
PageResult<MemberAddressDO> 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<MemberAddressDO> list = addressService.getAddressList(exportReqVO);
// 导出 Excel
List<AddressExcelVO> datas = AddressConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "用户收件地址.xls", "数据", AddressExcelVO.class, datas);
}
}

View File

@ -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;
}

View File

@ -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 {
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<AddressRespVO> convertList2(List<MemberAddressDO> list);
PageResult<AddressRespVO> convertPage(PageResult<MemberAddressDO> page);
List<AddressExcelVO> convertList02(List<MemberAddressDO> list);
}

View File

@ -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<MemberAddressDO> {
return selectList(new LambdaQueryWrapperX<MemberAddressDO>().eq(MemberAddressDO::getUserId, userId)
.eqIfPresent(MemberAddressDO::getDefaultStatus, defaulted));
}
default PageResult<MemberAddressDO> selectPage(AddressPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<MemberAddressDO>()
.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<MemberAddressDO> selectList(AddressExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<MemberAddressDO>()
.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));
}
}

View File

@ -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<MemberAddressDO> getAddressList(Collection<Long> ids);
/**
* 获得用户收件地址分页
*
* @param pageReqVO 分页查询
* @return 用户收件地址分页
*/
PageResult<MemberAddressDO> getAddressPage(AddressPageReqVO pageReqVO);
/**
* 获得用户收件地址列表, 用于 Excel 导出
*
* @param exportReqVO 查询条件
* @return 用户收件地址列表
*/
List<MemberAddressDO> getAddressList(AddressExportReqVO exportReqVO);
}

View File

@ -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<MemberAddressDO> getAddressList(Collection<Long> ids) {
return addressMapper.selectBatchIds(ids);
}
@Override
public PageResult<MemberAddressDO> getAddressPage(AddressPageReqVO pageReqVO) {
return addressMapper.selectPage(pageReqVO);
}
@Override
public List<MemberAddressDO> getAddressList(AddressExportReqVO exportReqVO) {
return addressMapper.selectList(exportReqVO);
}
}