Merge remote-tracking branch 'origin/master'

This commit is contained in:
YunaiV 2019-04-16 23:27:03 +08:00
commit 4aac5bd2c6
12 changed files with 127 additions and 23 deletions

View File

@ -5,6 +5,7 @@ import cn.iocoder.mall.admin.api.bo.DataDictBO;
import cn.iocoder.mall.admin.api.dto.DataDictAddDTO;
import cn.iocoder.mall.admin.api.dto.DataDictUpdateDTO;
import java.util.Collection;
import java.util.List;
public interface DataDictService {
@ -17,5 +18,25 @@ public interface DataDictService {
CommonResult<Boolean> deleteDataDict(Integer adminId, Integer dataDictId);
/**
* 获取字典值 - 单个
*
* 注意: dictValue:Object 为了方便调用会自动转换为 dictValue:String
*
* @param dictKey
* @param dictValue
* @return
*/
CommonResult<DataDictBO> getDataDict(String dictKey, Object dictValue);
/**
* 获取字典值 - 多个
*
* 注意dictValueList:? 为了方便调用会自动转换为 Set:String
*
* @param dictKey
* @param dictValueList
* @return
*/
CommonResult<List<DataDictBO>> getDataDictList(String dictKey, Collection<?> dictValueList);
}

View File

@ -4,6 +4,7 @@ import cn.iocoder.mall.admin.dataobject.DataDictDO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.List;
@Repository
@ -11,8 +12,16 @@ public interface DataDictMapper {
DataDictDO selectById(@Param("id") Integer id);
DataDictDO selectByEnumValueAndValue(@Param("enumValue") String enumValue,
@Param("value") String value);
DataDictDO selectByEnumValueAndValue(
@Param("enumValue") String enumValue,
@Param("value") String value
);
List<DataDictDO> selectByEnumValueAndValues(
@Param("enumValue") String enumValue,
@Param("values") Collection<String> values
);
List<DataDictDO> selectList();

View File

@ -14,8 +14,11 @@ import cn.iocoder.mall.admin.dataobject.DataDictDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 数据字典 Service
@ -93,4 +96,12 @@ public class DataDictServiceImpl implements DataDictService {
DataDictBO dataDictBO = DataDictConvert.INSTANCE.convert(dataDictDO);
return CommonResult.success(dataDictBO);
}
@Override
public CommonResult<List<DataDictBO>> getDataDictList(String dictKey, Collection<?> dictValueList) {
Set<String> convertDictValueList = dictValueList.stream().map(o -> String.valueOf(o)).collect(Collectors.toSet());
List<DataDictDO> dataDictDOList = dataDictMapper.selectByEnumValueAndValues(dictKey, convertDictValueList);
List<DataDictBO> dataDictBOList = DataDictConvert.INSTANCE.convert(dataDictDOList);
return CommonResult.success(dataDictBOList);
}
}

View File

@ -17,6 +17,19 @@
LIMIT 1
</select>
<select id="selectByEnumValueAndValues" resultType="cn.iocoder.mall.admin.dataobject.DataDictDO">
SELECT
<include refid="FIELDS"/>
FROM data_dict
WHERE deleted = 0
AND enum_value = #{enumValue}
AND `value` IN
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</select>
<select id="selectById" resultType="DataDictDO">
SELECT
<include refid="FIELDS"/>

View File

@ -8,7 +8,7 @@
<van-tabs>
<van-tab v-for="(item, index) in logistics" :key="index" :title="'包裹' + (index + 1)">
<van-cell-group>
<van-cell title="快递方式" :value="item.logistics + 'TODO 字典值'"/>
<van-cell title="快递方式" :value="item.logisticsText"/>
<van-cell title="快递单号" :value="item.logisticsNo"/>
</van-cell-group>
<van-steps direction="vertical" :active="0" active-color="#f60" style="margin-top: 15px;">

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>
<!--