parent
209725a25b
commit
fa5ea5dfd9
@ -0,0 +1,35 @@
|
||||
package cn.iocoder.mall.order.application.controller.users;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.order.api.OrderLogisticsService;
|
||||
import cn.iocoder.mall.order.api.bo.OrderLogisticsInfoBO;
|
||||
import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 订单物流 controller
|
||||
*
|
||||
* @author Sin
|
||||
* @time 2019-04-12 22:24
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("users/order_logistics")
|
||||
@Api(description = "订单物流信息")
|
||||
public class OrderLogisticsController {
|
||||
|
||||
@Autowired
|
||||
private OrderLogisticsService orderLogisticsService;
|
||||
|
||||
@GetMapping("logistics_info")
|
||||
@ApiOperation("物流详细 - 返回订单所关联的所有物流信息")
|
||||
public CommonResult<OrderLogisticsInfoBO> logisticsInfo(@RequestParam("orderId") Integer orderId) {
|
||||
Integer userId = UserSecurityContextHolder.getContext().getUserId();
|
||||
return orderLogisticsService.logisticsInfo(userId, orderId);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package cn.iocoder.mall.order.api;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.order.api.bo.OrderLogisticsBO;
|
||||
import cn.iocoder.mall.order.api.bo.OrderLogisticsInfoBO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单物流信息
|
||||
*
|
||||
* @author Sin
|
||||
* @time 2019-04-12 21:29
|
||||
*/
|
||||
public interface OrderLogisticsService {
|
||||
|
||||
/**
|
||||
* 物流信息
|
||||
*
|
||||
* @param userId
|
||||
* @param orderId
|
||||
* @return
|
||||
*/
|
||||
CommonResult<OrderLogisticsInfoBO> logisticsInfo(Integer userId, Integer orderId);
|
||||
|
||||
}
|
||||
@ -0,0 +1,96 @@
|
||||
package cn.iocoder.mall.order.api.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单物流 - 详细信息
|
||||
*
|
||||
* @author Sin
|
||||
* @time 2019-04-12 22:03
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class OrderLogisticsInfoBO implements Serializable {
|
||||
|
||||
/**
|
||||
* 订单id
|
||||
*/
|
||||
private Integer orderId;
|
||||
/**
|
||||
* 订单编号
|
||||
*/
|
||||
private String orderNo;
|
||||
/**
|
||||
* 物流信息
|
||||
*/
|
||||
private List<Logistics> logistics;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class Logistics {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 收件区域编号
|
||||
*/
|
||||
private String areaNo;
|
||||
/**
|
||||
* 收件人名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 收件手机号
|
||||
*/
|
||||
private String mobile;
|
||||
/**
|
||||
* 收件详细地址
|
||||
*/
|
||||
private String address;
|
||||
/**
|
||||
* 物流 (字典)
|
||||
*/
|
||||
private Integer logistics;
|
||||
/**
|
||||
* 物流编号
|
||||
*/
|
||||
private String logisticsNo;
|
||||
|
||||
///
|
||||
/// 物流信息
|
||||
|
||||
private List<LogisticsDetail> details;
|
||||
}
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class LogisticsDetail {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 物流id
|
||||
*/
|
||||
private Integer orderLogisticsId;
|
||||
/**
|
||||
* 物流时间
|
||||
*/
|
||||
private Date logisticsTime;
|
||||
/**
|
||||
* 物流时间 text
|
||||
*/
|
||||
private String logisticsTimeText;
|
||||
/**
|
||||
* 物流信息
|
||||
*/
|
||||
private String logisticsInformation;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package cn.iocoder.mall.order.biz.convert;
|
||||
|
||||
import cn.iocoder.mall.order.api.bo.OrderLogisticsInfoBO;
|
||||
import cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDetailDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单物流 convert
|
||||
*
|
||||
* @author Sin
|
||||
* @time 2019-03-23 14:39
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderLogisticsDetailConvert {
|
||||
|
||||
OrderLogisticsDetailConvert INSTANCE = Mappers.getMapper(OrderLogisticsDetailConvert.class);
|
||||
|
||||
@Mappings({})
|
||||
List<OrderLogisticsInfoBO.LogisticsDetail> convertLogisticsDetail(List<OrderLogisticsDetailDO> orderLogisticsDOList);
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package cn.iocoder.mall.order.biz.dao;
|
||||
|
||||
import cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDetailDO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单物流 - 物流详细信息
|
||||
*
|
||||
* @author Sin
|
||||
* @time 2019-04-12 21:35
|
||||
*/
|
||||
@Repository
|
||||
public interface OrderLogisticsDetailMapper {
|
||||
|
||||
/**
|
||||
* 插入
|
||||
*
|
||||
* @param orderLogisticsDetailDO
|
||||
* @return
|
||||
*/
|
||||
int insert(OrderLogisticsDetailDO orderLogisticsDetailDO);
|
||||
|
||||
/**
|
||||
* 查询 - 根据 物流id
|
||||
*
|
||||
* @param orderLogisticsId
|
||||
* @return
|
||||
*/
|
||||
List<OrderLogisticsDetailDO> selectByOrderLogisticsId(
|
||||
@Param("orderLogisticsId") Integer orderLogisticsId
|
||||
);
|
||||
|
||||
/**
|
||||
* 查询 - 根据 物流ids
|
||||
*
|
||||
* @param orderLogisticsIds
|
||||
* @return
|
||||
*/
|
||||
List<OrderLogisticsDetailDO> selectByOrderLogisticsIds(
|
||||
@Param("orderLogisticsIds") Collection<Integer> orderLogisticsIds
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,111 @@
|
||||
package cn.iocoder.mall.order.biz.service;
|
||||
|
||||
import cn.iocoder.common.framework.constant.DeletedStatusEnum;
|
||||
import cn.iocoder.common.framework.util.DateUtil;
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.order.api.OrderLogisticsService;
|
||||
import cn.iocoder.mall.order.api.bo.OrderLogisticsBO;
|
||||
import cn.iocoder.mall.order.api.bo.OrderLogisticsInfoBO;
|
||||
import cn.iocoder.mall.order.api.constant.OrderErrorCodeEnum;
|
||||
import cn.iocoder.mall.order.biz.convert.OrderLogisticsConvert;
|
||||
import cn.iocoder.mall.order.biz.convert.OrderLogisticsDetailConvert;
|
||||
import cn.iocoder.mall.order.biz.dao.OrderItemMapper;
|
||||
import cn.iocoder.mall.order.biz.dao.OrderLogisticsDetailMapper;
|
||||
import cn.iocoder.mall.order.biz.dao.OrderLogisticsMapper;
|
||||
import cn.iocoder.mall.order.biz.dao.OrderMapper;
|
||||
import cn.iocoder.mall.order.biz.dataobject.OrderDO;
|
||||
import cn.iocoder.mall.order.biz.dataobject.OrderItemDO;
|
||||
import cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDO;
|
||||
import cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDetailDO;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 订单物流
|
||||
*
|
||||
* @author Sin
|
||||
* @time 2019-04-12 21:32
|
||||
*/
|
||||
@Service
|
||||
public class OrderLogisticsServiceImpl implements OrderLogisticsService {
|
||||
|
||||
@Autowired
|
||||
private OrderMapper orderMapper;
|
||||
@Autowired
|
||||
private OrderItemMapper orderItemMapper;
|
||||
@Autowired
|
||||
private OrderLogisticsMapper orderLogisticsMapper;
|
||||
@Autowired
|
||||
private OrderLogisticsDetailMapper orderLogisticsDetailMapper;
|
||||
|
||||
@Override
|
||||
public CommonResult<OrderLogisticsInfoBO> logisticsInfo(Integer userId, Integer orderId) {
|
||||
OrderDO orderDO = orderMapper.selectById(orderId);
|
||||
|
||||
if (orderDO == null) {
|
||||
return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_NOT_EXISTENT.getCode());
|
||||
}
|
||||
|
||||
if (!userId.equals(orderDO.getUserId())) {
|
||||
return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_NOT_USER_ORDER.getCode());
|
||||
}
|
||||
|
||||
// 获取订单所发货的订单 id
|
||||
List<OrderItemDO> orderItemDOList = orderItemMapper.selectByDeletedAndOrderId(
|
||||
orderId, DeletedStatusEnum.DELETED_NO.getValue());
|
||||
|
||||
// 获取物流 信息
|
||||
Set<Integer> orderLogisticsIds = orderItemDOList.stream()
|
||||
.map(o -> o.getOrderLogisticsId()).collect(Collectors.toSet());
|
||||
|
||||
List<OrderLogisticsDO> orderLogisticsDOList = orderLogisticsMapper.selectByIds(orderLogisticsIds);
|
||||
|
||||
List<OrderLogisticsDetailDO> orderLogisticsDetailDOList
|
||||
= orderLogisticsDetailMapper.selectByOrderLogisticsIds(orderLogisticsIds);
|
||||
|
||||
// 转换 return 的数据
|
||||
List<OrderLogisticsInfoBO.Logistics> logistics
|
||||
= OrderLogisticsConvert.INSTANCE.convertLogistics(orderLogisticsDOList);
|
||||
|
||||
List<OrderLogisticsInfoBO.LogisticsDetail> logisticsDetails
|
||||
= OrderLogisticsDetailConvert.INSTANCE.convertLogisticsDetail(orderLogisticsDetailDOList);
|
||||
|
||||
logisticsDetails.stream().map(o -> {
|
||||
o.setLogisticsTimeText(DateUtil.format(o.getLogisticsTime(), "yyyy-MM-dd HH:mm"));
|
||||
return o;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
Map<Integer, List<OrderLogisticsInfoBO.LogisticsDetail>> logisticsDetailMultimap
|
||||
= logisticsDetails.stream().collect(
|
||||
Collectors.toMap(
|
||||
o -> o.getOrderLogisticsId(),
|
||||
item -> Lists.newArrayList(item),
|
||||
(oldVal, newVal) -> {
|
||||
oldVal.addAll(newVal);
|
||||
return oldVal;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
logistics.stream().map(o -> {
|
||||
if (logisticsDetailMultimap.containsKey(o.getId())) {
|
||||
o.setDetails(logisticsDetailMultimap.get(o.getId()));
|
||||
}
|
||||
return o;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return CommonResult.success(
|
||||
new OrderLogisticsInfoBO()
|
||||
.setOrderId(orderId)
|
||||
.setOrderNo(orderDO.getOrderNo())
|
||||
.setLogistics(logistics)
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.mall.order.biz.dao.OrderLogisticsDetailMapper">
|
||||
|
||||
<sql id="FIELDS">
|
||||
id
|
||||
,
|
||||
order_logistics_id,
|
||||
logistics_time,
|
||||
logistics_information,
|
||||
create_time,
|
||||
update_time
|
||||
</sql>
|
||||
|
||||
<!--
|
||||
插入
|
||||
-->
|
||||
<insert id="insert" parameterType="CartItemDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
||||
INSERT INTO cart_item (order_logistics_id, logistics_time, logistics_information,
|
||||
create_time, update_time)
|
||||
VALUES (#{orderLogisticsId}, #{logisticsTime}, #{logisticsInformation},
|
||||
#{createTime}, #{updateTime})
|
||||
</insert>
|
||||
|
||||
<!--
|
||||
查询 - 根据 物流id
|
||||
-->
|
||||
<select id="selectByOrderLogisticsId"
|
||||
resultType="cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDetailDO">
|
||||
SELECT
|
||||
<include refid="FIELDS"/>
|
||||
FROM order_logistics_detail
|
||||
WHERE order_logistics_id = #{orderLogisticsId}
|
||||
</select>
|
||||
|
||||
<!--
|
||||
查询 - 根据 物流ids
|
||||
-->
|
||||
<select id="selectByOrderLogisticsIds"
|
||||
resultType="cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDetailDO">
|
||||
SELECT
|
||||
<include refid="FIELDS"/>
|
||||
FROM order_logistics_detail
|
||||
WHERE order_logistics_id IN
|
||||
<foreach collection="orderLogisticsIds" item="orderLogisticsId" separator="," open="(" close=")">
|
||||
#{orderLogisticsId}
|
||||
</foreach>
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in new issue