feat: 用户地址
parent
30605f87cc
commit
7a2c291bfb
|
|
@ -1,18 +1,21 @@
|
|||
package com.ruoyi.web.controller.xkt;
|
||||
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.ruoyi.common.core.controller.XktBaseController;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.xkt.domain.UserAddress;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.web.controller.xkt.vo.IdVO;
|
||||
import com.ruoyi.web.controller.xkt.vo.express.UserAddressCreateVO;
|
||||
import com.ruoyi.web.controller.xkt.vo.express.UserAddressInfoVO;
|
||||
import com.ruoyi.web.controller.xkt.vo.express.UserAddressModifyVO;
|
||||
import com.ruoyi.xkt.dto.express.UserAddressInfoDTO;
|
||||
import com.ruoyi.xkt.service.IUserAddressService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -21,71 +24,58 @@ import java.util.List;
|
|||
* @author ruoyi
|
||||
* @date 2025-03-26
|
||||
*/
|
||||
@Api(tags = "用户收货地址")
|
||||
@RestController
|
||||
@RequestMapping("/rest/v1/user-addrs")
|
||||
@RequestMapping("/rest/v1/user-address")
|
||||
public class UserAddressController extends XktBaseController {
|
||||
@Autowired
|
||||
private IUserAddressService userAddressService;
|
||||
|
||||
/**
|
||||
* 查询用户收货地址列表
|
||||
*/
|
||||
// @PreAuthorize("@ss.hasPermi('system:address:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(UserAddress userAddress) {
|
||||
startPage();
|
||||
List<UserAddress> list = userAddressService.selectUserAddressList(userAddress);
|
||||
return getDataTable(list);
|
||||
@ApiOperation("创建用户收货地址")
|
||||
@PostMapping("create")
|
||||
public R<UserAddressInfoVO> create(@Valid @RequestBody UserAddressCreateVO vo) {
|
||||
UserAddressInfoDTO dto = BeanUtil.toBean(vo, UserAddressInfoDTO.class);
|
||||
dto.setUserId(SecurityUtils.getUserId());
|
||||
return success(BeanUtil.toBean(userAddressService.createUserAddress(dto), UserAddressInfoVO.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出用户收货地址列表
|
||||
*/
|
||||
// @PreAuthorize("@ss.hasPermi('system:address:export')")
|
||||
@Log(title = "用户收货地址", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, UserAddress userAddress) {
|
||||
List<UserAddress> list = userAddressService.selectUserAddressList(userAddress);
|
||||
ExcelUtil<UserAddress> util = new ExcelUtil<UserAddress>(UserAddress.class);
|
||||
util.exportExcel(response, list, "用户收货地址数据");
|
||||
@ApiOperation("修改用户收货地址")
|
||||
@PostMapping("edit")
|
||||
public R<UserAddressInfoVO> edit(@Valid @RequestBody UserAddressModifyVO vo) {
|
||||
UserAddressInfoDTO dto = BeanUtil.toBean(vo, UserAddressInfoDTO.class);
|
||||
dto.setUserId(SecurityUtils.getUserId());
|
||||
//TODO 非本人不允许修改
|
||||
return success(BeanUtil.toBean(userAddressService.modifyUserAddress(dto), UserAddressInfoVO.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户收货地址详细信息
|
||||
*/
|
||||
// @PreAuthorize("@ss.hasPermi('system:address:query')")
|
||||
@GetMapping(value = "/{userAddrId}")
|
||||
public R getInfo(@PathVariable("userAddrId") Long userAddrId) {
|
||||
return success(userAddressService.selectUserAddressByUserAddrId(userAddrId));
|
||||
@ApiOperation("复制用户收货地址")
|
||||
@PostMapping("copy")
|
||||
public R<UserAddressInfoVO> copy(@Valid @RequestBody IdVO vo) {
|
||||
UserAddressInfoDTO dto = userAddressService.copyUserAddress(vo.getId());
|
||||
return success(BeanUtil.toBean(dto, UserAddressInfoVO.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户收货地址
|
||||
*/
|
||||
// @PreAuthorize("@ss.hasPermi('system:address:add')")
|
||||
@Log(title = "用户收货地址", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public R add(@RequestBody UserAddress userAddress) {
|
||||
return success(userAddressService.insertUserAddress(userAddress));
|
||||
@ApiOperation("删除用户收货地址")
|
||||
@PostMapping("delete")
|
||||
public R delete(@Valid @RequestBody IdVO vo) {
|
||||
userAddressService.deleteUserAddress(vo.getId());
|
||||
return success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户收货地址
|
||||
*/
|
||||
// @PreAuthorize("@ss.hasPermi('system:address:edit')")
|
||||
@Log(title = "用户收货地址", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public R edit(@RequestBody UserAddress userAddress) {
|
||||
return success(userAddressService.updateUserAddress(userAddress));
|
||||
@ApiOperation(value = "用户收货地址详情")
|
||||
@GetMapping("/{id}")
|
||||
public R<UserAddressInfoVO> getInfo(@PathVariable("id") Long id) {
|
||||
UserAddressInfoDTO infoDTO = userAddressService.getUserAddress(id);
|
||||
//TODO 非本人不允许查询
|
||||
return success(BeanUtil.toBean(infoDTO, UserAddressInfoVO.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户收货地址
|
||||
*/
|
||||
// @PreAuthorize("@ss.hasPermi('system:address:remove')")
|
||||
@Log(title = "用户收货地址", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{userAddrIds}")
|
||||
public R remove(@PathVariable Long[] userAddrIds) {
|
||||
return success(userAddressService.deleteUserAddressByUserAddrIds(userAddrIds));
|
||||
@ApiOperation(value = "用户收货地址列表")
|
||||
@PostMapping("/list")
|
||||
public R<List<UserAddressInfoVO>> list() {
|
||||
List<UserAddressInfoDTO> dtoList = userAddressService.listByUser(SecurityUtils.getUserId());
|
||||
return success(BeanUtil.copyToList(dtoList, UserAddressInfoVO.class));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
package com.ruoyi.web.controller.xkt.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @author liangyq
|
||||
* @date 2025-05-11 23:46
|
||||
*/
|
||||
@ApiModel
|
||||
@Data
|
||||
public class IdVO {
|
||||
|
||||
@NotNull(message = "ID不能为空")
|
||||
@ApiModelProperty("ID")
|
||||
private Long id;
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.ruoyi.web.controller.xkt.vo.express;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
/**
|
||||
* @author liangyq
|
||||
* @date 2025-05-11 23:19
|
||||
*/
|
||||
@ApiModel
|
||||
@Data
|
||||
public class UserAddressCreateVO {
|
||||
|
||||
@NotEmpty
|
||||
@ApiModelProperty(value = "收件人名称")
|
||||
private String receiveName;
|
||||
|
||||
@NotEmpty
|
||||
@ApiModelProperty(value = "收件人电话")
|
||||
private String receivePhone;
|
||||
|
||||
@NotEmpty
|
||||
@ApiModelProperty(value = "收件人完整地址")
|
||||
private String address;
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package com.ruoyi.web.controller.xkt.vo.express;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author liangyq
|
||||
* @date 2025-05-11 23:19
|
||||
*/
|
||||
@ApiModel
|
||||
@Data
|
||||
public class UserAddressInfoVO {
|
||||
|
||||
@ApiModelProperty(value = "ID")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "收件人名称")
|
||||
private String receiveName;
|
||||
|
||||
@ApiModelProperty(value = "收件人电话")
|
||||
private String receivePhone;
|
||||
|
||||
@ApiModelProperty(value = "省编码")
|
||||
private String provinceCode;
|
||||
|
||||
@ApiModelProperty(value = "省名称")
|
||||
private String provinceName;
|
||||
|
||||
@ApiModelProperty(value = "市名称")
|
||||
private String cityCode;
|
||||
|
||||
@ApiModelProperty(value = "市编码")
|
||||
private String cityName;
|
||||
|
||||
@ApiModelProperty(value = "区县编码")
|
||||
private String countyCode;
|
||||
|
||||
@ApiModelProperty(value = "区县名称")
|
||||
private String countyName;
|
||||
|
||||
@ApiModelProperty(value = "详细地址")
|
||||
private String detailAddress;
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.ruoyi.web.controller.xkt.vo.express;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @author liangyq
|
||||
* @date 2025-05-11 23:19
|
||||
*/
|
||||
@ApiModel
|
||||
@Data
|
||||
public class UserAddressModifyVO {
|
||||
|
||||
@NotNull
|
||||
@ApiModelProperty(value = "ID")
|
||||
private Long id;
|
||||
|
||||
@NotEmpty
|
||||
@ApiModelProperty(value = "收件人名称")
|
||||
private String receiveName;
|
||||
|
||||
@NotEmpty
|
||||
@ApiModelProperty(value = "收件人电话")
|
||||
private String receivePhone;
|
||||
|
||||
@NotEmpty
|
||||
@ApiModelProperty(value = "收件人完整地址")
|
||||
private String address;
|
||||
}
|
||||
|
|
@ -212,6 +212,7 @@ public class Constants
|
|||
* 行政区划缓存
|
||||
*/
|
||||
public static final String EXPRESS_REGION_MAP_CACHE_KEY = "EXPRESS_REGION_MAP";
|
||||
public static final String EXPRESS_REGION_NAME_MAP_CACHE_KEY = "EXPRESS_REGION_NAME_MAP";
|
||||
public static final String EXPRESS_REGION_LIST_CACHE_KEY = "EXPRESS_REGION_LIST";
|
||||
public static final String EXPRESS_REGION_TREE_CACHE_KEY = "EXPRESS_REGION_TREE";
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
package com.ruoyi.xkt.dto.express;
|
||||
|
||||
import com.ruoyi.xkt.domain.UserAddress;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* @author liangyq
|
||||
* @date 2025-05-11 22:39
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class UserAddressInfoDTO extends UserAddress {
|
||||
/**
|
||||
* 省
|
||||
*/
|
||||
private String provinceName;
|
||||
|
||||
/**
|
||||
* 市
|
||||
*/
|
||||
private String cityName;
|
||||
|
||||
/**
|
||||
* 区县
|
||||
*/
|
||||
private String districtName;
|
||||
|
||||
/**
|
||||
* 区县
|
||||
*/
|
||||
private String countyCode;
|
||||
|
||||
/**
|
||||
* 区县
|
||||
*/
|
||||
private String countyName;
|
||||
|
||||
/**
|
||||
* 完整地址,新增/修改接口使用
|
||||
*/
|
||||
private String address;
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package com.ruoyi.xkt.mapper;
|
|||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.ruoyi.xkt.domain.UserAddress;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -11,6 +12,7 @@ import java.util.List;
|
|||
* @author ruoyi
|
||||
* @date 2025-03-26
|
||||
*/
|
||||
@Repository
|
||||
public interface UserAddressMapper extends BaseMapper<UserAddress> {
|
||||
/**
|
||||
* 查询用户收货地址
|
||||
|
|
|
|||
|
|
@ -90,6 +90,13 @@ public interface IExpressService {
|
|||
*/
|
||||
Map<String, ExpressRegionDTO> getRegionMapCache();
|
||||
|
||||
/**
|
||||
* 获取缓存的行政区划名称
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Map<String, String> getRegionNameMapCache();
|
||||
|
||||
/**
|
||||
* 获取缓存的行政编码
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.ruoyi.xkt.service;
|
||||
|
||||
import com.ruoyi.xkt.domain.UserAddress;
|
||||
import com.ruoyi.xkt.dto.express.UserAddressInfoDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -12,50 +12,49 @@ import java.util.List;
|
|||
*/
|
||||
public interface IUserAddressService {
|
||||
/**
|
||||
* 查询用户收货地址
|
||||
* 新增
|
||||
*
|
||||
* @param userAddrId 用户收货地址主键
|
||||
* @return 用户收货地址
|
||||
* @param userAddressInfoDTO
|
||||
* @return
|
||||
*/
|
||||
public UserAddress selectUserAddressByUserAddrId(Long userAddrId);
|
||||
UserAddressInfoDTO createUserAddress(UserAddressInfoDTO userAddressInfoDTO);
|
||||
|
||||
/**
|
||||
* 查询用户收货地址列表
|
||||
* 复制
|
||||
*
|
||||
* @param userAddress 用户收货地址
|
||||
* @return 用户收货地址集合
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public List<UserAddress> selectUserAddressList(UserAddress userAddress);
|
||||
UserAddressInfoDTO copyUserAddress(Long id);
|
||||
|
||||
/**
|
||||
* 新增用户收货地址
|
||||
* 获取详情
|
||||
*
|
||||
* @param userAddress 用户收货地址
|
||||
* @return 结果
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public int insertUserAddress(UserAddress userAddress);
|
||||
UserAddressInfoDTO getUserAddress(Long id);
|
||||
|
||||
/**
|
||||
* 修改用户收货地址
|
||||
* 列表
|
||||
*
|
||||
* @param userAddress 用户收货地址
|
||||
* @return 结果
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
public int updateUserAddress(UserAddress userAddress);
|
||||
List<UserAddressInfoDTO> listByUser(Long userId);
|
||||
|
||||
/**
|
||||
* 批量删除用户收货地址
|
||||
* 修改
|
||||
*
|
||||
* @param userAddrIds 需要删除的用户收货地址主键集合
|
||||
* @return 结果
|
||||
* @param userAddressInfoDTO
|
||||
* @return
|
||||
*/
|
||||
public int deleteUserAddressByUserAddrIds(Long[] userAddrIds);
|
||||
UserAddressInfoDTO modifyUserAddress(UserAddressInfoDTO userAddressInfoDTO);
|
||||
|
||||
/**
|
||||
* 删除用户收货地址信息
|
||||
* 删除
|
||||
*
|
||||
* @param userAddrId 用户收货地址主键
|
||||
* @return 结果
|
||||
* @param id
|
||||
*/
|
||||
public int deleteUserAddressByUserAddrId(Long userAddrId);
|
||||
void deleteUserAddress(Long id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ import java.util.stream.Collectors;
|
|||
@Service
|
||||
public class ExpressServiceImpl implements IExpressService {
|
||||
|
||||
private ExpressRegionDTO emptyRegion = new ExpressRegionDTO();
|
||||
@Value("${express.default.province:510000}")
|
||||
private String expressDefaultProvince;
|
||||
@Value("${express.default.city:510100}")
|
||||
|
|
@ -187,6 +186,17 @@ public class ExpressServiceImpl implements IExpressService {
|
|||
return regionMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getRegionNameMapCache() {
|
||||
Map<String, String> regionNameMap = redisCache.getCacheMap(Constants.EXPRESS_REGION_NAME_MAP_CACHE_KEY);
|
||||
if (regionNameMap == null || regionNameMap.isEmpty()) {
|
||||
regionNameMap = getRegionListCache().stream()
|
||||
.collect(Collectors.toMap(ExpressRegionDTO::getRegionCode, ExpressRegionDTO::getRegionName));
|
||||
redisCache.setCacheMap(Constants.EXPRESS_REGION_NAME_MAP_CACHE_KEY, regionNameMap);
|
||||
}
|
||||
return regionNameMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExpressRegionTreeNodeDTO> getRegionTreeCache() {
|
||||
List<ExpressRegionTreeNodeDTO> treeNodeList = redisCache.getCacheList(Constants.EXPRESS_REGION_TREE_CACHE_KEY);
|
||||
|
|
@ -235,16 +245,16 @@ public class ExpressServiceImpl implements IExpressService {
|
|||
// Assert.notEmpty(detailAddress, "获取详细地址失败");
|
||||
// Assert.notEmpty(name, "获取联系人失败");
|
||||
// Assert.isTrue(PhoneUtil.isPhone(phone), "获取联系电话失败");
|
||||
Map<String, ExpressRegionDTO> regionMap = getRegionMapCache();
|
||||
Map<String, String> regionMap = getRegionNameMapCache();
|
||||
return ExpressStructAddressDTO.builder()
|
||||
.contactName(name)
|
||||
.contactPhoneNumber(phone)
|
||||
.provinceCode(provinceCode)
|
||||
.provinceName(regionMap.getOrDefault(provinceCode, emptyRegion).getRegionName())
|
||||
.provinceName(regionMap.get(provinceCode))
|
||||
.cityCode(cityCode)
|
||||
.cityName(regionMap.getOrDefault(cityCode, emptyRegion).getRegionName())
|
||||
.cityName(regionMap.get(cityCode))
|
||||
.countyCode(countyCode)
|
||||
.countyName(regionMap.getOrDefault(countyCode, emptyRegion).getRegionName())
|
||||
.countyName(regionMap.get(countyCode))
|
||||
.detailAddress(detailAddress)
|
||||
.build();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,25 @@
|
|||
package com.ruoyi.xkt.service.impl;
|
||||
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.core.domain.XktBaseEntity;
|
||||
import com.ruoyi.xkt.domain.UserAddress;
|
||||
import com.ruoyi.xkt.dto.express.ExpressStructAddressDTO;
|
||||
import com.ruoyi.xkt.dto.express.UserAddressInfoDTO;
|
||||
import com.ruoyi.xkt.mapper.UserAddressMapper;
|
||||
import com.ruoyi.xkt.service.IExpressService;
|
||||
import com.ruoyi.xkt.service.IUserAddressService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 用户收货地址Service业务层处理
|
||||
|
|
@ -20,76 +31,115 @@ import java.util.List;
|
|||
public class UserAddressServiceImpl implements IUserAddressService {
|
||||
@Autowired
|
||||
private UserAddressMapper userAddressMapper;
|
||||
@Autowired
|
||||
private IExpressService expressService;
|
||||
|
||||
/**
|
||||
* 查询用户收货地址
|
||||
*
|
||||
* @param userAddrId 用户收货地址主键
|
||||
* @return 用户收货地址
|
||||
*/
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public UserAddress selectUserAddressByUserAddrId(Long userAddrId) {
|
||||
return userAddressMapper.selectUserAddressByUserAddrId(userAddrId);
|
||||
public UserAddressInfoDTO createUserAddress(UserAddressInfoDTO userAddressInfoDTO) {
|
||||
Assert.notNull(userAddressInfoDTO.getUserId());
|
||||
Assert.notEmpty(userAddressInfoDTO.getReceiveName());
|
||||
Assert.notEmpty(userAddressInfoDTO.getReceivePhone());
|
||||
Assert.notEmpty(userAddressInfoDTO.getAddress());
|
||||
UserAddress userAddress = BeanUtil.toBean(userAddressInfoDTO, UserAddress.class);
|
||||
ExpressStructAddressDTO structAddressDTO = expressService.parseNamePhoneAddress(userAddressInfoDTO.getAddress());
|
||||
Assert.notEmpty(structAddressDTO.getProvinceCode(), "省编码异常");
|
||||
Assert.notEmpty(structAddressDTO.getProvinceName(), "省名称异常");
|
||||
Assert.notEmpty(structAddressDTO.getCityCode(), "市编码异常");
|
||||
Assert.notEmpty(structAddressDTO.getCityName(), "市名称异常");
|
||||
Assert.notEmpty(structAddressDTO.getCountyCode(), "区县编码异常");
|
||||
Assert.notEmpty(structAddressDTO.getCountyName(), "区县名称异常");
|
||||
Assert.notEmpty(structAddressDTO.getDetailAddress(), "详细地址异常");
|
||||
userAddress.setProvinceCode(structAddressDTO.getProvinceCode());
|
||||
userAddress.setCityCode(structAddressDTO.getCityCode());
|
||||
userAddress.setDistrictCode(structAddressDTO.getCountyCode());
|
||||
userAddress.setDetailAddress(structAddressDTO.getDetailAddress());
|
||||
userAddressMapper.insert(userAddress);
|
||||
return getUserAddress(userAddress.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户收货地址列表
|
||||
*
|
||||
* @param userAddress 用户收货地址
|
||||
* @return 用户收货地址
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<UserAddress> selectUserAddressList(UserAddress userAddress) {
|
||||
return userAddressMapper.selectUserAddressList(userAddress);
|
||||
public UserAddressInfoDTO copyUserAddress(Long id) {
|
||||
UserAddress userAddress = userAddressMapper.selectById(id);
|
||||
Assert.notNull(userAddress);
|
||||
userAddress.setId(null);
|
||||
userAddressMapper.insert(userAddress);
|
||||
return getUserAddress(userAddress.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户收货地址
|
||||
*
|
||||
* @param userAddress 用户收货地址
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int insertUserAddress(UserAddress userAddress) {
|
||||
userAddress.setCreateTime(DateUtils.getNowDate());
|
||||
return userAddressMapper.insertUserAddress(userAddress);
|
||||
public UserAddressInfoDTO getUserAddress(Long id) {
|
||||
Assert.notNull(id);
|
||||
UserAddress userAddress = userAddressMapper.selectById(id);
|
||||
UserAddressInfoDTO info = BeanUtil.toBean(userAddress, UserAddressInfoDTO.class);
|
||||
Map<String, String> regionNameMap = expressService.getRegionNameMapCache();
|
||||
info.setProvinceName(regionNameMap.get(info.getProvinceCode()));
|
||||
info.setCityName(regionNameMap.get(info.getCityCode()));
|
||||
info.setDistrictName(regionNameMap.get(info.getDistrictCode()));
|
||||
info.setCountyCode(info.getDistrictCode());
|
||||
info.setCountyName(regionNameMap.get(info.getCountyCode()));
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户收货地址
|
||||
*
|
||||
* @param userAddress 用户收货地址
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int updateUserAddress(UserAddress userAddress) {
|
||||
userAddress.setUpdateTime(DateUtils.getNowDate());
|
||||
return userAddressMapper.updateUserAddress(userAddress);
|
||||
public List<UserAddressInfoDTO> listByUser(Long userId) {
|
||||
Assert.notNull(userId);
|
||||
List<UserAddress> userAddressList = userAddressMapper.selectList(Wrappers.lambdaQuery(UserAddress.class)
|
||||
.eq(UserAddress::getUserId, userId)
|
||||
.eq(XktBaseEntity::getDelFlag, Constants.UNDELETED));
|
||||
if (CollUtil.isEmpty(userAddressList)) {
|
||||
return ListUtil.empty();
|
||||
}
|
||||
Map<String, String> regionNameMap = expressService.getRegionNameMapCache();
|
||||
return userAddressList.stream().map(o -> {
|
||||
UserAddressInfoDTO info = BeanUtil.toBean(o, UserAddressInfoDTO.class);
|
||||
info.setProvinceName(regionNameMap.get(info.getProvinceCode()));
|
||||
info.setCityName(regionNameMap.get(info.getCityCode()));
|
||||
info.setDistrictName(regionNameMap.get(info.getDistrictCode()));
|
||||
info.setCountyCode(info.getDistrictCode());
|
||||
info.setCountyName(regionNameMap.get(info.getCountyCode()));
|
||||
return info;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除用户收货地址
|
||||
*
|
||||
* @param userAddrIds 需要删除的用户收货地址主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public int deleteUserAddressByUserAddrIds(Long[] userAddrIds) {
|
||||
return userAddressMapper.deleteUserAddressByUserAddrIds(userAddrIds);
|
||||
public UserAddressInfoDTO modifyUserAddress(UserAddressInfoDTO userAddressInfoDTO) {
|
||||
Assert.notNull(userAddressInfoDTO.getId());
|
||||
Assert.notNull(userAddressInfoDTO.getUserId());
|
||||
Assert.notEmpty(userAddressInfoDTO.getReceiveName());
|
||||
Assert.notEmpty(userAddressInfoDTO.getReceivePhone());
|
||||
Assert.notEmpty(userAddressInfoDTO.getAddress());
|
||||
UserAddress userAddress = userAddressMapper.selectById(userAddressInfoDTO.getId());
|
||||
Assert.notNull(userAddress);
|
||||
ExpressStructAddressDTO structAddressDTO = expressService.parseNamePhoneAddress(userAddressInfoDTO.getAddress());
|
||||
Assert.notEmpty(structAddressDTO.getProvinceCode(), "省编码异常");
|
||||
Assert.notEmpty(structAddressDTO.getProvinceName(), "省名称异常");
|
||||
Assert.notEmpty(structAddressDTO.getCityCode(), "市编码异常");
|
||||
Assert.notEmpty(structAddressDTO.getCityName(), "市名称异常");
|
||||
Assert.notEmpty(structAddressDTO.getCountyCode(), "区县编码异常");
|
||||
Assert.notEmpty(structAddressDTO.getCountyName(), "区县名称异常");
|
||||
Assert.notEmpty(structAddressDTO.getDetailAddress(), "详细地址异常");
|
||||
userAddress.setUserId(userAddressInfoDTO.getUserId());
|
||||
userAddress.setReceiveName(userAddressInfoDTO.getReceiveName());
|
||||
userAddress.setReceivePhone(userAddressInfoDTO.getReceivePhone());
|
||||
userAddress.setProvinceCode(structAddressDTO.getProvinceCode());
|
||||
userAddress.setCityCode(structAddressDTO.getCityCode());
|
||||
userAddress.setDistrictCode(structAddressDTO.getCountyCode());
|
||||
userAddress.setDetailAddress(structAddressDTO.getDetailAddress());
|
||||
userAddressMapper.updateById(userAddress);
|
||||
return getUserAddress(userAddress.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户收货地址信息
|
||||
*
|
||||
* @param userAddrId 用户收货地址主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public int deleteUserAddressByUserAddrId(Long userAddrId) {
|
||||
return userAddressMapper.deleteUserAddressByUserAddrId(userAddrId);
|
||||
public void deleteUserAddress(Long id) {
|
||||
Assert.notNull(id);
|
||||
UserAddress userAddress = new UserAddress();
|
||||
userAddress.setId(id);
|
||||
userAddress.setDelFlag(Constants.DELETED);
|
||||
userAddressMapper.updateById(userAddress);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue