From dabd9f5f7594169c73a0336812ed699475635bf9 Mon Sep 17 00:00:00 2001 From: sin <2943460818@qq.com> Date: Tue, 16 Apr 2019 20:20:54 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E7=89=A9=E6=B5=81=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=AD=97=E5=85=B8=E5=80=BC=E8=BD=AC=E6=8D=A2=20-=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=B8=80=E4=BA=9Bbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../users/OrderLogisticsController.java | 43 ++++++++++++++++++- .../users/UsersOrderController.java | 4 +- .../order/api/bo/OrderLogisticsInfoBO.java | 4 ++ .../order/api/constant/DictKeyConstants.java | 19 ++++++++ .../order/api/constant/DictKeysConstants.java | 15 ------- .../api/constant/OrderErrorCodeEnum.java | 3 ++ .../resources/mapper/OrderLogisticsMapper.xml | 2 +- 7 files changed, 70 insertions(+), 20 deletions(-) create mode 100644 order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/DictKeyConstants.java delete mode 100644 order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/DictKeysConstants.java diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderLogisticsController.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderLogisticsController.java index edab5e743..f868c9d4b 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderLogisticsController.java +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderLogisticsController.java @@ -1,18 +1,27 @@ package cn.iocoder.mall.order.application.controller.users; +import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.admin.api.DataDictService; +import cn.iocoder.mall.admin.api.bo.DataDictBO; import cn.iocoder.mall.order.api.OrderLogisticsService; import cn.iocoder.mall.order.api.bo.OrderLogisticsInfoBO; +import cn.iocoder.mall.order.api.constant.DictKeyConstants; +import cn.iocoder.mall.order.api.constant.OrderErrorCodeEnum; import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder; import com.alibaba.dubbo.config.annotation.Reference; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + /** * 订单物流 controller * @@ -26,11 +35,41 @@ public class OrderLogisticsController { @Reference(validation = "true") private OrderLogisticsService orderLogisticsService; + @Reference(validation = "true") + private DataDictService dataDictService; @GetMapping("logistics_info") @ApiOperation("物流详细 - 返回订单所关联的所有物流信息") public CommonResult logisticsInfo(@RequestParam("orderId") Integer orderId) { Integer userId = UserSecurityContextHolder.getContext().getUserId(); - return orderLogisticsService.logisticsInfo(userId, orderId); + CommonResult commonResult = orderLogisticsService.logisticsInfo(userId, orderId); + if (commonResult.isSuccess()) { + OrderLogisticsInfoBO orderLogisticsInfoBO = commonResult.getData(); + List logisticsList = orderLogisticsInfoBO.getLogistics(); + + // 获取字典值 + Set dictValues = logisticsList.stream().map(o -> o.getLogistics()).collect(Collectors.toSet()); + CommonResult> dictResult = dataDictService + .getDataDictList(DictKeyConstants.ORDER_LOGISTICS_COMPANY, dictValues); + + if (dictResult.isError()) { + // 错误情况 + return ServiceExceptionUtil.error(OrderErrorCodeEnum.DICT_SERVER_INVOKING_FAIL.getCode()); + } + + // 转换结果字典值 + Map dataDictBOMap = dictResult.getData() + .stream().collect(Collectors.toMap(o -> o.getValue(), o -> o)); + + logisticsList.stream().map(o -> { + String dicValue = o.getLogistics().toString(); + if (dataDictBOMap.containsKey(dicValue)) { + o.setLogisticsText(dataDictBOMap.get(dicValue).getDisplayName()); + } + return o; + }).collect(Collectors.toList()); + } + + return commonResult; } } diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersOrderController.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersOrderController.java index dbd2bf63b..d83aa1638 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersOrderController.java +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersOrderController.java @@ -8,7 +8,7 @@ import cn.iocoder.mall.admin.api.bo.DataDictBO; import cn.iocoder.mall.order.api.CartService; import cn.iocoder.mall.order.api.OrderService; import cn.iocoder.mall.order.api.bo.*; -import cn.iocoder.mall.order.api.constant.DictKeysConstants; +import cn.iocoder.mall.order.api.constant.DictKeyConstants; import cn.iocoder.mall.order.api.constant.OrderErrorCodeEnum; import cn.iocoder.mall.order.api.dto.CalcOrderPriceDTO; import cn.iocoder.mall.order.api.dto.OrderCreateDTO; @@ -120,7 +120,7 @@ public class UsersOrderController { OrderInfoBO orderInfoBO = commonResult.getData(); CommonResult dictResult = dataDictService - .getDataDict(DictKeysConstants.ORDER_STATUS_KEY, orderInfoBO.getStatus()); + .getDataDict(DictKeyConstants.ORDER_STATUS, orderInfoBO.getStatus()); orderInfoBO.setStatusText(dictResult.getData().getDisplayName()); return commonResult; } diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderLogisticsInfoBO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderLogisticsInfoBO.java index 940245f65..b2fdce3a5 100644 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderLogisticsInfoBO.java +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderLogisticsInfoBO.java @@ -58,6 +58,10 @@ public class OrderLogisticsInfoBO implements Serializable { * 物流 (字典) */ private Integer logistics; + /** + * 物流 (字典) 转换后的值 + */ + private String logisticsText; /** * 物流编号 */ diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/DictKeyConstants.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/DictKeyConstants.java new file mode 100644 index 000000000..eb0341415 --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/DictKeyConstants.java @@ -0,0 +1,19 @@ +package cn.iocoder.mall.order.api.constant; + +/** + * 字典 keys 定义 + * + * @author Sin + * @time 2019-04-14 17:46 + */ +public class DictKeyConstants { + + /** + * 订单 - status + */ + public static final String ORDER_STATUS = "order_status"; + /** + * 订单 - 物流商家 + */ + public static final String ORDER_LOGISTICS_COMPANY = "logistics_company"; +} diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/DictKeysConstants.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/DictKeysConstants.java deleted file mode 100644 index a51a4d533..000000000 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/DictKeysConstants.java +++ /dev/null @@ -1,15 +0,0 @@ -package cn.iocoder.mall.order.api.constant; - -/** - * 字典 keys 定义 - * - * @author Sin - * @time 2019-04-14 17:46 - */ -public class DictKeysConstants { - - /** - * 订单 - status - */ - public static final String ORDER_STATUS_KEY = "order_status"; -} diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderErrorCodeEnum.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderErrorCodeEnum.java index 2363f78ee..22caa4866 100644 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderErrorCodeEnum.java +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderErrorCodeEnum.java @@ -31,11 +31,14 @@ public enum OrderErrorCodeEnum { ORDER_ITEM_SOME_NOT_EXISTS(1008000201, "有不存在的商品!"), + // ========== 购物车 ========== CARD_ITEM_NOT_FOUND(1008003000, "购物车项不存在"), CARD_ITEM_SKU_NOT_FOUND(1008003001, "商品不存在"), CARD_ITEM_SKU_QUANTITY_NOT_ENOUGH(1008003002, "商品库存不足"), + // 工具类服务 1008004000 + DICT_SERVER_INVOKING_FAIL(1008004000, "字典服务调用失败!"), ; private final int code; diff --git a/order/order-service-impl/src/main/resources/mapper/OrderLogisticsMapper.xml b/order/order-service-impl/src/main/resources/mapper/OrderLogisticsMapper.xml index 2125591da..90f86c340 100644 --- a/order/order-service-impl/src/main/resources/mapper/OrderLogisticsMapper.xml +++ b/order/order-service-impl/src/main/resources/mapper/OrderLogisticsMapper.xml @@ -3,7 +3,7 @@ - id, area_no, `name`, mobile, address, logistics_no, create_time, update_time + id, area_no, `name`, mobile, address, logistics, logistics_no, create_time, update_time