From 283a9bd5ef71fef25831ea72ea31564688a094c7 Mon Sep 17 00:00:00 2001 From: yuanye <418471657@qq.com> Date: Mon, 20 May 2024 10:03:03 +0800 Subject: [PATCH] Changes --- .../goods/DeliveryAddressController.java | 30 +++++++++++++++++++ .../impl/GoodsUserAddressServiceImpl.java | 16 ++++++++++ 2 files changed, 46 insertions(+) diff --git a/cweb/src/main/java/com/cweb/controller/goods/DeliveryAddressController.java b/cweb/src/main/java/com/cweb/controller/goods/DeliveryAddressController.java index e44cc61..bcffc1d 100644 --- a/cweb/src/main/java/com/cweb/controller/goods/DeliveryAddressController.java +++ b/cweb/src/main/java/com/cweb/controller/goods/DeliveryAddressController.java @@ -9,6 +9,7 @@ import com.hfkj.entity.GoodsUserAddress; import com.hfkj.model.ResponseData; import com.hfkj.model.UserSessionObject; import com.hfkj.service.goods.GoodsUserAddressService; +import com.hfkj.service.goods.impl.GoodsUserAddressServiceImpl; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; @@ -29,6 +30,7 @@ public class DeliveryAddressController { @Resource private UserCenter userCenter; + private GoodsUserAddressServiceImpl goodsUserAddressService; @RequestMapping(value = "/getDeliveryAddressList", method = RequestMethod.GET) @@ -197,4 +199,32 @@ public class DeliveryAddressController { } } + @RequestMapping(value = "/getUserAddress", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "获取默认地址") + public ResponseData getUserAddress() { + try { + + // 用户session + UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); + + Map map = new HashMap<>(); + map.put("userId" , userSession.getUser().getId()); + map.put("whetherDefault" , true); + + GoodsUserAddress userAddress = goodsUserAddressService.queryDetailByMap(map); + + if (userAddress == null) { + log.error("GoodsDetailController -> findGoodsDetailById() error!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到相信息"); + } + + return ResponseMsgUtil.success(userAddress); + + } catch (Exception e) { + log.error("GoodsDetailController --> findGoodsDetailById() error!", e); + return ResponseMsgUtil.exception(e); + } + } + } diff --git a/service/src/main/java/com/hfkj/service/goods/impl/GoodsUserAddressServiceImpl.java b/service/src/main/java/com/hfkj/service/goods/impl/GoodsUserAddressServiceImpl.java index 048aedd..fe526f1 100644 --- a/service/src/main/java/com/hfkj/service/goods/impl/GoodsUserAddressServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/goods/impl/GoodsUserAddressServiceImpl.java @@ -41,6 +41,22 @@ public class GoodsUserAddressServiceImpl implements GoodsUserAddressService { @Override public GoodsUserAddress queryDetailByMap(Map map) { + GoodsUserAddressExample example = new GoodsUserAddressExample(); + GoodsUserAddressExample.Criteria criteria = example.createCriteria(); + + if (MapUtils.getLong(map, "userId") != null) { + criteria.andUserIdEqualTo(MapUtils.getLong(map, "userId")); + } + if (MapUtils.getBoolean(map, "whetherDefault") != null) { + criteria.andWhetherDefaultEqualTo(MapUtils.getBoolean(map, "whetherDefault")); + } + + List list = goodsUserAddressMapper.selectByExample(example); + + if (!list.isEmpty()) { + return list.get(0); + } + return null; }