From e633a09a6e03ef22314699acf4fd5d9ab42a07ca Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 26 十二月 2018 15:36:41 +0800
Subject: [PATCH] 新版订单修改

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java |  217 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 214 insertions(+), 3 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java
index cb737e5..6227a29 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java
@@ -1,20 +1,60 @@
 package com.yeshi.fanli.service.impl.hongbao;
 
+import java.math.BigDecimal;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+
 import javax.annotation.Resource;
 
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import com.yeshi.fanli.dao.mybatis.HongBaoV2Mapper;
+import com.yeshi.fanli.dao.mybatis.hongbao.HongBaoMapper;
+import com.yeshi.fanli.dao.mybatis.order.CommonOrderGoodsMapper;
+import com.yeshi.fanli.dao.mybatis.order.CommonOrderMapper;
+import com.yeshi.fanli.dao.mybatis.order.HongBaoOrderMapper;
+import com.yeshi.fanli.dao.mybatis.order.OrderItemMapper;
+import com.yeshi.fanli.dao.mybatis.order.OrderMapper;
+import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoOrderMapper;
+import com.yeshi.fanli.entity.bus.user.HongBao;
 import com.yeshi.fanli.entity.bus.user.HongBaoV2;
+import com.yeshi.fanli.entity.order.CommonOrder;
+import com.yeshi.fanli.entity.order.CommonOrderGoods;
+import com.yeshi.fanli.entity.order.HongBaoOrder;
+import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
 import com.yeshi.fanli.service.inter.hongbao.HongBaoV2Service;
-
+import com.yeshi.fanli.util.Constant;
+import com.yeshi.fanli.util.taobao.TaoBaoOrderUtil;
 
 @Service
 public class HongBaoV2ServiceImpl implements HongBaoV2Service {
-	
+
 	@Resource
 	private HongBaoV2Mapper hongBaoV2Mapper;
 
+	@Resource
+	private HongBaoMapper hongBaoMapper;
+
+	@Resource
+	private TaoBaoOrderMapper taoBaoOrderMapper;
+
+	@Resource
+	private OrderItemMapper orderItemMapper;
+
+	@Resource
+	private CommonOrderMapper commonOrderMapper;
+
+	@Resource
+	private CommonOrderGoodsMapper commonOrderGoodsMapper;
+
+	@Resource
+	private HongBaoOrderMapper hongBaoOrderMapper;
+
+	@Resource
+	private OrderMapper orderMapper;
 
 	@Override
 	public int insert(HongBaoV2 record) {
@@ -45,5 +85,176 @@
 	public HongBaoV2 selectByPrimaryKey(Long id) {
 		return hongBaoV2Mapper.selectByPrimaryKey(id);
 	}
-	
+
+	private HongBaoV2 getHongBaoV2(HongBao hb) {
+		int type = hb.getType().intValue();
+		HongBaoV2 v2 = new HongBaoV2(hb.getId());
+		v2.setCreateTime(new Date(hb.getCreatetime()));
+		if (hb.getGetTime() == null || hb.getGetTime() == 0)
+			v2.setGetTime(null);
+		else
+			v2.setGetTime(new Date(hb.getGetTime()));
+
+		v2.setMoney(hb.getMoney());
+		if (hb.getParent() != null)
+			v2.setParent(new HongBaoV2(hb.getParent().getId()));
+
+		if (hb.getPreGettime() == null || hb.getPreGettime() == 0)
+			v2.setPreGetTime(null);
+		else
+			v2.setPreGetTime(new Date(hb.getPreGettime()));
+
+		v2.setState(hb.getState());
+		v2.setType(type);
+		v2.setUpdateTime(new Date(hb.getCreatetime()));
+		v2.setUrank(hb.getUrank());
+		v2.setUserInfo(hb.getUserInfo());
+		v2.setVersion(hb.getVersion());
+		return v2;
+	}
+
+	@Transactional
+	@Override
+	public void convert(HongBao hb) {
+		if (hb == null || hb.getParent() != null)
+			return;
+
+		int type = hb.getType().intValue();
+		if (type == HongBao.TYPE_TAOBAO || type == HongBao.TYPE_SHARE_GOODS) {// 鑷喘涓庡垎浜禋闇�瑕佹煡璇㈠嚭鎵�鏈夌殑璁㈠崟
+			// 灞炰簬杩斿埄璁㈠崟
+			String orderId = "";
+			if (hb.getOrder() != null) {
+				orderId = hb.getOrder().getOrderId();
+				// 鏌ヨ鍚屼竴璁㈠崟鍙风殑闈炲瓙绾㈠寘
+
+			} else
+				orderId = hb.getOrderId();
+
+			int count = commonOrderMapper.countByOrderNOAndOrderType(orderId, Constant.SOURCE_TYPE_TAOBAO);
+
+			// 宸茬粡鎻掑叆璁㈠崟
+			if (count > 0)
+				return;
+
+			//
+
+			if (hb.getVersion() == 1) {// 寰堣�佺増鏈殑澶勭悊鏂瑰紡,宸瞙ongbao涓轰富
+				if (hongBaoV2Mapper.selectByPrimaryKey(hb.getId()) != null)
+					return;
+				HongBaoV2 hongBaoV2 = getHongBaoV2(hb);
+				hongBaoV2.setBeizhu("璁㈠崟鍙�:" + orderId);
+				hongBaoV2Mapper.insert(hongBaoV2);
+
+				if (hb.getHasChild())// 瀛樺湪瀛愮孩鍖�
+				{
+					List<HongBao> children = hongBaoMapper.selectChildHongBaoByPid(hb.getId());
+					if (children != null)
+						for (HongBao hongBao : children) {
+							HongBaoV2 child = getHongBaoV2(hongBao);
+							hongBaoV2Mapper.insert(child);
+						}
+				}
+
+			} else {// 鏂扮増鏈鐞嗘柟寮�
+
+				List<HongBao> list = hongBaoMapper.selectByOrderId(orderId);
+
+				if (list.size() == 0)
+					list = hongBaoMapper.selectByOid(hb.getOrder().getId());
+				if (list != null)
+					// 鍒犻櫎瀛愮孩鍖�
+					for (int i = 0; i < list.size(); i++) {
+					if (list.get(i).getParent() != null) {
+					list.remove(i);
+					i--;
+					}
+
+					}
+
+				if (list.size() <= 0)
+					return;
+				List<TaoBaoOrder> orderList = taoBaoOrderMapper.selectTaoBaoOrderByOrderId(orderId);
+				if (orderList == null || orderList.size() != list.size()) {
+					System.out.println("绾㈠寘鏁颁笌璁㈠崟鏁颁笉瀵瑰簲");
+					return;
+				}
+
+				// 鎸夌収auctionId,payMoney鎺掑簭
+				Comparator<HongBao> cm = new Comparator<HongBao>() {
+
+					@Override
+					public int compare(HongBao o1, HongBao o2) {
+						return o1.getAuctionId() == o2.getAuctionId()
+								? (o1.getPayMoney().subtract(o2.getPayMoney()).compareTo(new BigDecimal(0)))
+								: (int) (o1.getAuctionId() - o2.getAuctionId());
+					}
+				};
+
+				Collections.sort(list, cm);
+
+				Comparator<TaoBaoOrder> cmOrder = new Comparator<TaoBaoOrder>() {
+
+					@Override
+					public int compare(TaoBaoOrder o1, TaoBaoOrder o2) {
+						return o1.getAuctionId() == o2.getAuctionId()
+								? (o1.getPayment().subtract(o2.getPayment()).compareTo(new BigDecimal(0)))
+								: (int) (o1.getAuctionId() - o2.getAuctionId());
+					}
+				};
+
+				Collections.sort(orderList, cmOrder);
+
+				for (int i = 0; i < list.size(); i++) {
+					CommonOrder commonOrder = TaoBaoOrderUtil.convert(orderList.get(i));
+					CommonOrderGoods goods = new CommonOrderGoods();
+					goods.setGoodsId(orderList.get(i).getAuctionId() + "");
+					goods.setGoodsType(Constant.SOURCE_TYPE_TAOBAO);
+					// 鍟嗗搧鏄惁宸茬粡鎻掑叆
+					List<CommonOrderGoods> commonGoodsList = commonOrderGoodsMapper
+							.listByGoodsIdAndGoodsType(goods.getGoodsId(), goods.getGoodsType());
+					if (commonGoodsList.size() <= 0)// 涓嶅瓨鍦ㄥ氨鎻掑叆鍟嗗搧
+						commonOrderGoodsMapper.insertSelective(goods);
+					else
+						goods.setId(commonGoodsList.get(commonGoodsList.size() - 1).getId());
+					commonOrder.setCommonOrderGoods(goods);
+
+					commonOrder.setUserInfo(list.get(i).getUserInfo());
+
+					commonOrderMapper.insertSelective(commonOrder);
+
+					// 鎻掑叆绾㈠寘
+					HongBaoV2 hongBaoV2 = getHongBaoV2(list.get(i));
+					hongBaoV2.setId(list.get(i).getId());
+					hongBaoV2Mapper.insert(hongBaoV2);
+
+					HongBaoOrder ho = new HongBaoOrder();
+					ho.setCommonOrder(commonOrder);
+					ho.setCreateTime(new Date());
+					ho.setHongBaoV2(hongBaoV2);
+					hongBaoOrderMapper.insertSelective(ho);
+
+					if (list.get(i).getHasChild())// 瀛樺湪瀛愮孩鍖�
+					{
+						List<HongBao> children = hongBaoMapper.selectChildHongBaoByPid(list.get(i).getId());
+						if (children != null)
+							for (HongBao hongBao : children) {
+								HongBaoV2 child = getHongBaoV2(hongBao);
+								hongBaoV2Mapper.insert(child);
+							}
+					}
+				}
+			}
+
+		} else {// 鐩存帴鎻掑叆
+
+			if (type != HongBao.TYPE_ERJI && type != HongBao.TYPE_YIJI && type != HongBao.TYPE_SHARE_YIJI
+					&& type != HongBao.TYPE_SHARE_ERJI) {
+				if (hongBaoV2Mapper.selectByPrimaryKey(hb.getId()) == null)
+					hongBaoV2Mapper.insert(getHongBaoV2(hb));
+			}
+
+		}
+
+	}
+
 }

--
Gitblit v1.8.0