|
| 1 | +package com.changyu.test; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.HashMap; |
| 5 | +import java.util.List; |
| 6 | +import java.util.Map; |
| 7 | + |
| 8 | +import org.apache.log4j.Logger; |
| 9 | +import org.junit.Test; |
| 10 | +import org.junit.runner.RunWith; |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; |
| 12 | +import org.springframework.test.context.ContextConfiguration; |
| 13 | +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| 14 | + |
| 15 | +import com.alibaba.fastjson.JSON; |
| 16 | +import com.changyu.foryou.model.SmallOrder; |
| 17 | +import com.changyu.foryou.model.TogetherOrder; |
| 18 | +import com.changyu.foryou.service.OrderService; |
| 19 | +import com.changyu.foryou.tools.Constants; |
| 20 | + |
| 21 | + |
| 22 | +@RunWith(SpringJUnit4ClassRunner.class) |
| 23 | +@ContextConfiguration(locations = { "classpath:spring.xml", "classpath:spring-mybatis.xml" }) |
| 24 | +public class orderTest { |
| 25 | + private static final Logger LOGGER = Logger |
| 26 | + .getLogger(orderTest.class); |
| 27 | + private OrderService orderService; |
| 28 | + |
| 29 | + public OrderService getOrderService() { |
| 30 | + return orderService; |
| 31 | + } |
| 32 | + |
| 33 | + @Autowired |
| 34 | + public void setOrderService(OrderService orderService) { |
| 35 | + this.orderService = orderService; |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + public void getOrderInMine(){ |
| 40 | + |
| 41 | + Map<String, Object> map = new HashMap<String, Object>(); |
| 42 | + |
| 43 | + List<TogetherOrder> togetherOrdersList = new ArrayList<TogetherOrder>(); |
| 44 | + |
| 45 | + try { |
| 46 | + Map<String, Object> paramMap = new HashMap<String, Object>(); |
| 47 | + //case 1 |
| 48 | + paramMap.put("phoneId", "18896554880"); |
| 49 | + paramMap.put("status", "a"); |
| 50 | + |
| 51 | + |
| 52 | + //case 2 |
| 53 | + |
| 54 | + List<String> togetherIds = orderService.getTogetherId(paramMap); |
| 55 | + |
| 56 | + System.out.println(JSON.toJSONString(togetherIds)); |
| 57 | + |
| 58 | + if (togetherIds.size() != 0) { |
| 59 | + for (String togetherId : togetherIds) { |
| 60 | + TogetherOrder togetherOrder = new TogetherOrder(); // 一单 |
| 61 | + togetherOrder.setTogetherId(togetherId); |
| 62 | + |
| 63 | + paramMap.put("togetherId", togetherId); |
| 64 | + List<SmallOrder> orderList = orderService |
| 65 | + .getOrderListInMine(paramMap); // 一单里面的小订单 |
| 66 | + togetherOrder.setSmallOrders(orderList); |
| 67 | + togetherOrder.setPayWay(orderList.get(0).getPayWay()); |
| 68 | + Short totalStatus=0; |
| 69 | + if(orderList.get(0).getStatus()!=4) |
| 70 | + { |
| 71 | + totalStatus=orderList.get(0).getStatus(); |
| 72 | + } |
| 73 | + else |
| 74 | + { |
| 75 | + totalStatus=5; |
| 76 | + for (int i = 0; i < orderList.size(); i++) { |
| 77 | + if (orderList.get(i).getIsRemarked() == 0) { |
| 78 | + totalStatus = 4; |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + togetherOrder.setStatus(totalStatus); |
| 83 | + togetherOrder.setTogetherDate(orderList.get(0) |
| 84 | + .getTogetherDate()); |
| 85 | + togetherOrdersList.add(togetherOrder); |
| 86 | + } |
| 87 | + |
| 88 | + map.put(Constants.STATUS, Constants.SUCCESS); |
| 89 | + map.put(Constants.MESSAGE, "获取订单成功"); |
| 90 | + map.put("orderList", JSON.parse(JSON |
| 91 | + .toJSONStringWithDateFormat(togetherOrdersList, |
| 92 | + "yyyy-MM-dd"))); |
| 93 | + } else { |
| 94 | + map.put(Constants.STATUS, Constants.SUCCESS); |
| 95 | + map.put(Constants.MESSAGE, "暂无订单"); |
| 96 | + } |
| 97 | + |
| 98 | + } catch (Exception e) { |
| 99 | + e.printStackTrace(); |
| 100 | + map.put(Constants.STATUS, Constants.FAILURE); |
| 101 | + map.put(Constants.MESSAGE, "获取订单失败"); |
| 102 | + } |
| 103 | + |
| 104 | + LOGGER.debug("订单为:==================="+JSON.toJSONString(map)); |
| 105 | + return ; |
| 106 | + } |
| 107 | + |
| 108 | +} |
0 commit comments