Authored by unknown

代码优化

@@ -4,12 +4,14 @@ import org.apache.ibatis.annotations.Param; @@ -4,12 +4,14 @@ import org.apache.ibatis.annotations.Param;
4 4
5 import com.yoho.unions.dal.model.Orders; 5 import com.yoho.unions.dal.model.Orders;
6 6
  7 +import java.util.List;
  8 +
7 9
8 public interface IOrdersMapper { 10 public interface IOrdersMapper {
9 11
10 Orders selectByUidAndOrderCode(@Param("uid") int uid, @Param("orderCode") long orderCode); 12 Orders selectByUidAndOrderCode(@Param("uid") int uid, @Param("orderCode") long orderCode);
11 13
12 - Orders selectByOrderCode(@Param("orderCode") long orderCode); 14 + List<Orders> selectByOrderCode(@Param("orderCode") long orderCode);
13 15
14 /** 16 /**
15 * 查询某用户一段时间以来的已交寄订单 17 * 查询某用户一段时间以来的已交寄订单
@@ -15,6 +15,8 @@ public interface IUserOrdersDAO { @@ -15,6 +15,8 @@ public interface IUserOrdersDAO {
15 15
16 UserOrders selectByPrimaryKey(Integer id); 16 UserOrders selectByPrimaryKey(Integer id);
17 17
  18 + UserOrders selectByOrderCode(long orderCode);
  19 +
18 int updateByPrimaryKeySelective(UserOrders record); 20 int updateByPrimaryKeySelective(UserOrders record);
19 21
20 int updateByPrimaryKey(UserOrders record); 22 int updateByPrimaryKey(UserOrders record);
@@ -43,7 +43,7 @@ @@ -43,7 +43,7 @@
43 select 43 select
44 <include refid="Base_Column_List"/> 44 <include refid="Base_Column_List"/>
45 from orders 45 from orders
46 - where order_code = #{orderCode,jdbcType=BIGINT} 46 + where parent_order_code = #{orderCode,jdbcType=BIGINT}
47 </select> 47 </select>
48 48
49 <select id="selectCountShipStatusOrderSince" resultType="java.lang.Integer"> 49 <select id="selectCountShipStatusOrderSince" resultType="java.lang.Integer">
@@ -38,6 +38,12 @@ @@ -38,6 +38,12 @@
38 from user_orders 38 from user_orders
39 where id = #{id,jdbcType=INTEGER} 39 where id = #{id,jdbcType=INTEGER}
40 </select> 40 </select>
  41 + <select id="selectByOrderCode" resultMap="BaseResultMap">
  42 + select
  43 + <include refid="Base_Column_List" />
  44 + from user_orders
  45 + where order_code = #{orderCode}
  46 + </select>
41 <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > 47 <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
42 delete from user_orders 48 delete from user_orders
43 where id = #{id,jdbcType=INTEGER} 49 where id = #{id,jdbcType=INTEGER}
@@ -83,53 +83,56 @@ public class UserOrdersServiceImpl implements IUserOrdersService,IBusinessExport @@ -83,53 +83,56 @@ public class UserOrdersServiceImpl implements IUserOrdersService,IBusinessExport
83 if(count>0){ 83 if(count>0){
84 userOrdersList = userOrdersDAO.selectUserOrderList(beginTime,endTime,String.valueOf(orderCode),unionId,idList,reqBO.getStart(),reqBO.getSize()); 84 userOrdersList = userOrdersDAO.selectUserOrderList(beginTime,endTime,String.valueOf(orderCode),unionId,idList,reqBO.getStart(),reqBO.getSize());
85 } 85 }
86 - for(UserOrders userOrders:userOrdersList){ 86 + List<Orders> ordersList = new ArrayList<>();
  87 + for (UserOrders userOrders : userOrdersList) {
87 //根据查询出来的uid,ordercode,查询ERP_ORDERS.Orders 88 //根据查询出来的uid,ordercode,查询ERP_ORDERS.Orders
88 // Orders orders = ordersMapper.selectByUidAndOrderCode(userOrders.getuId(),Long.valueOf(userOrders.getOrderCode())); 89 // Orders orders = ordersMapper.selectByUidAndOrderCode(userOrders.getuId(),Long.valueOf(userOrders.getOrderCode()));
89 - Orders orders = ordersMapper.selectByOrderCode(Long.valueOf(userOrders.getOrderCode())); 90 + List<Orders> order = ordersMapper.selectByOrderCode(Long.valueOf(userOrders.getOrderCode()));
  91 + ordersList.addAll(order);
  92 + }
  93 + for (Orders orders : ordersList) {
90 UnionOrderRspBO orderRspBO = new UnionOrderRspBO(); 94 UnionOrderRspBO orderRspBO = new UnionOrderRspBO();
91 //优惠券金额 95 //优惠券金额
92 - OrdersCoupons ordersCoupons = ordersCouponsMapper.selectByOrderCode(Long.valueOf(userOrders.getOrderCode()));  
93 - if(null!=ordersCoupons){ 96 + OrdersCoupons ordersCoupons = ordersCouponsMapper.selectByOrderCode(Long.valueOf(orders.getOrderCode()));
  97 + if (null != ordersCoupons) {
94 orderRspBO.setCouponAmount(ordersCoupons.getCouponAmount()); 98 orderRspBO.setCouponAmount(ordersCoupons.getCouponAmount());
95 - }else{ 99 + } else {
96 orderRspBO.setCouponAmount(new BigDecimal(0)); 100 orderRspBO.setCouponAmount(new BigDecimal(0));
97 } 101 }
98 //防止订单数据没有在ERP中 102 //防止订单数据没有在ERP中
99 - if(null!=orders){  
100 - //订单金额  
101 - orderRspBO.setOrderAmount(orders.getOrderAmount());  
102 - orderRspBO.setYohoCoinNum(orders.getYohoCoinNum());  
103 - //运费  
104 - orderRspBO.setShipmentAmount(orders.getShippingCost());  
105 - //实际支付金额  
106 - orderRspBO.setRealPayAmount(orders.getLastOrderAmount().subtract(orders.getShippingCost()));  
107 - //订单状态  
108 - orderRspBO.setOrderStatus(OrderStatusEnum.getNameByCode(String.valueOf(orders.getOrderStatus())));  
109 - //附加信息  
110 - orderRspBO.setExetInfmoation(orders.getRemark());  
111 - //支付方式  
112 - orderRspBO.setPayChannel(PaymentTypeEnum.getNameByCode(String.valueOf(orders.getPaymentType())));  
113 - //是否新客---从新的表中获取  
114 - OrdersAccessOry ordersAccessOry = ordersAccessOryMapper.selectByPrimaryKey(Long.valueOf(userOrders.getOrderCode()));  
115 - if(null !=ordersAccessOry){  
116 - orderRspBO.setIsNew(NewUserEnum.getNameByCode(ordersAccessOry.getIsNew()==null?"N":ordersAccessOry.getIsNew()));  
117 - }else {  
118 - orderRspBO.setIsNew(NewUserEnum.getNameByCode("N"));  
119 - }  
120 103
121 - orderRspBO.setUid(orders.getUid()); 104 + //订单金额
  105 + orderRspBO.setOrderAmount(orders.getOrderAmount());
  106 + orderRspBO.setYohoCoinNum(orders.getYohoCoinNum());
  107 + //运费
  108 + orderRspBO.setShipmentAmount(orders.getShippingCost());
  109 + //实际支付金额
  110 + orderRspBO.setRealPayAmount(orders.getLastOrderAmount().subtract(orders.getShippingCost()));
  111 + //订单状态
  112 + orderRspBO.setOrderStatus(OrderStatusEnum.getNameByCode(String.valueOf(orders.getOrderStatus())));
  113 + //附加信息
  114 + orderRspBO.setExetInfmoation(orders.getRemark());
  115 + //支付方式
  116 + orderRspBO.setPayChannel(PaymentTypeEnum.getNameByCode(String.valueOf(orders.getPaymentType())));
  117 + //是否新客---从新的表中获取
  118 + OrdersAccessOry ordersAccessOry = ordersAccessOryMapper.selectByPrimaryKey(Long.valueOf(orders.getOrderCode()));
  119 + if (null != ordersAccessOry) {
  120 + orderRspBO.setIsNew(NewUserEnum.getNameByCode(ordersAccessOry.getIsNew() == null ? "N" : ordersAccessOry.getIsNew()));
  121 + } else {
  122 + orderRspBO.setIsNew(NewUserEnum.getNameByCode("N"));
122 } 123 }
123 -  
124 - orderRspBO.setOrderCode(Integer.valueOf(userOrders.getOrderCode()));  
125 - orderRspBO.setId(userOrders.getId());  
126 - orderRspBO.setOrderTime(DateUtil.long2DateStr(Long.valueOf(userOrders.getCreateTime()) * Long.valueOf(1000), "yyyy-MM-dd"));  
127 - orderRspBO.setUnionId(userOrders.getUid());  
128 - MktMarketingUrl mktMarketingUrl = mktMarketingUrlDAO.selectByPrimaryKey(Long.valueOf(userOrders.getUid()));  
129 - if(mktMarketingUrl!=null){  
130 - orderRspBO.setUnionType(mktMarketingUrl.getName()); 124 + orderRspBO.setUid(orders.getUid());
  125 + orderRspBO.setOrderCode(orders.getOrderCode().intValue());
  126 + orderRspBO.setId(orders.getId());
  127 + orderRspBO.setOrderTime(DateUtil.long2DateStr(Long.valueOf(orders.getCreateTime()) * Long.valueOf(1000), "yyyy-MM-dd"));
  128 + UserOrders userOrders = userOrdersDAO.selectByOrderCode(orders.getParentOrderCode());
  129 + if(userOrders!=null){
  130 + orderRspBO.setUnionId(userOrders.getUid());
  131 + MktMarketingUrl mktMarketingUrl = mktMarketingUrlDAO.selectByPrimaryKey(Long.valueOf(userOrders.getUid()));
  132 + if (mktMarketingUrl != null) {
  133 + orderRspBO.setUnionType(mktMarketingUrl.getName());
  134 + }
131 } 135 }
132 -  
133 unionOrderRspBOList.add(orderRspBO); 136 unionOrderRspBOList.add(orderRspBO);
134 } 137 }
135 PageUnionOrderRspBO pageUnionOrderRspBO = new PageUnionOrderRspBO(); 138 PageUnionOrderRspBO pageUnionOrderRspBO = new PageUnionOrderRspBO();