master
袁野 6 months ago
parent 309f6910d5
commit c5a6dea509
  1. 30
      cweb/src/main/java/com/cweb/controller/goods/DeliveryAddressController.java
  2. 16
      service/src/main/java/com/hfkj/service/goods/impl/GoodsUserAddressServiceImpl.java

@ -9,6 +9,7 @@ import com.hfkj.entity.GoodsUserAddress;
import com.hfkj.model.ResponseData; import com.hfkj.model.ResponseData;
import com.hfkj.model.UserSessionObject; import com.hfkj.model.UserSessionObject;
import com.hfkj.service.goods.GoodsUserAddressService; import com.hfkj.service.goods.GoodsUserAddressService;
import com.hfkj.service.goods.impl.GoodsUserAddressServiceImpl;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -29,6 +30,7 @@ public class DeliveryAddressController {
@Resource @Resource
private UserCenter userCenter; private UserCenter userCenter;
private GoodsUserAddressServiceImpl goodsUserAddressService;
@RequestMapping(value = "/getDeliveryAddressList", method = RequestMethod.GET) @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<String , Object> 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);
}
}
} }

@ -41,6 +41,22 @@ public class GoodsUserAddressServiceImpl implements GoodsUserAddressService {
@Override @Override
public GoodsUserAddress queryDetailByMap(Map<String, Object> map) { public GoodsUserAddress queryDetailByMap(Map<String, Object> 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<GoodsUserAddress> list = goodsUserAddressMapper.selectByExample(example);
if (!list.isEmpty()) {
return list.get(0);
}
return null; return null;
} }

Loading…
Cancel
Save