- 物流信息字典值转换

- 优化一些bug
This commit is contained in:
sin 2019-04-16 20:20:54 +08:00
parent d30aeea6ab
commit dabd9f5f75
7 changed files with 70 additions and 20 deletions

View File

@ -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<OrderLogisticsInfoBO> logisticsInfo(@RequestParam("orderId") Integer orderId) {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
return orderLogisticsService.logisticsInfo(userId, orderId);
CommonResult<OrderLogisticsInfoBO> commonResult = orderLogisticsService.logisticsInfo(userId, orderId);
if (commonResult.isSuccess()) {
OrderLogisticsInfoBO orderLogisticsInfoBO = commonResult.getData();
List<OrderLogisticsInfoBO.Logistics> logisticsList = orderLogisticsInfoBO.getLogistics();
// 获取字典值
Set<Integer> dictValues = logisticsList.stream().map(o -> o.getLogistics()).collect(Collectors.toSet());
CommonResult<List<DataDictBO>> dictResult = dataDictService
.getDataDictList(DictKeyConstants.ORDER_LOGISTICS_COMPANY, dictValues);
if (dictResult.isError()) {
// 错误情况
return ServiceExceptionUtil.error(OrderErrorCodeEnum.DICT_SERVER_INVOKING_FAIL.getCode());
}
// 转换结果字典值
Map<String, DataDictBO> 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;
}
}

View File

@ -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<DataDictBO> dictResult = dataDictService
.getDataDict(DictKeysConstants.ORDER_STATUS_KEY, orderInfoBO.getStatus());
.getDataDict(DictKeyConstants.ORDER_STATUS, orderInfoBO.getStatus());
orderInfoBO.setStatusText(dictResult.getData().getDisplayName());
return commonResult;
}

View File

@ -58,6 +58,10 @@ public class OrderLogisticsInfoBO implements Serializable {
* 物流 (字典)
*/
private Integer logistics;
/**
* 物流 (字典) 转换后的值
*/
private String logisticsText;
/**
* 物流编号
*/

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@
<mapper namespace="cn.iocoder.mall.order.biz.dao.OrderLogisticsMapper">
<sql id="FIELDS">
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
</sql>
<!--