admin
2020-11-28 dc5be7d38446f70e6ff86df311119c32b41fe7f8
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderRepairServiceImpl.java
@@ -13,12 +13,12 @@
import javax.annotation.Resource;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import com.yeshi.fanli.entity.SystemEnum;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.dao.mybatis.HongBaoV2Mapper;
import com.yeshi.fanli.dao.mybatis.money.ExtractCheckCompensateMapper;
import com.yeshi.fanli.dao.mybatis.order.CommonOrderGoodsMapper;
import com.yeshi.fanli.dao.mybatis.order.CommonOrderMapper;
import com.yeshi.fanli.dao.mybatis.order.CommonOrderTradeIdMapMapper;
@@ -26,7 +26,9 @@
import com.yeshi.fanli.dao.mybatis.order.OrderRepairHistoryMapper;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
import com.yeshi.fanli.entity.goods.CommonGoods;
import com.yeshi.fanli.entity.money.ExtractCheckCompensate;
import com.yeshi.fanli.entity.money.UserMoneyDetail;
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.entity.order.CommonOrderGoods;
@@ -34,36 +36,44 @@
import com.yeshi.fanli.entity.order.HongBaoOrder;
import com.yeshi.fanli.entity.order.OrderRepairHistory;
import com.yeshi.fanli.entity.order.ShareGoodsActivityOrder;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.push.PushInfo;
import com.yeshi.fanli.entity.push.PushInfo.PushTypeEnum;
import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
import com.yeshi.fanli.exception.HongBaoException;
import com.yeshi.fanli.exception.money.UserMoneyDetailException;
import com.yeshi.fanli.exception.order.HongBaoException;
import com.yeshi.fanli.exception.push.PushException;
import com.yeshi.fanli.exception.push.PushInfoException;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoV2Service;
import com.yeshi.fanli.service.inter.money.UserMoneyService;
import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService;
import com.yeshi.fanli.service.inter.order.CommonOrderService;
import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
import com.yeshi.fanli.service.inter.order.OrderRepairHistoryService;
import com.yeshi.fanli.service.inter.order.OrderRepairService;
import com.yeshi.fanli.service.inter.order.ShareGoodsActivityOrderService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoOrderService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoWeiQuanOrderService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.order.tb.TaoBaoOrderService;
import com.yeshi.fanli.service.inter.order.tb.TaoBaoWeiQuanOrderService;
import com.yeshi.fanli.service.inter.push.PushInfoService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.UserMoneyService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponRecordService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import org.yeshi.utils.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TimeUtil;
import org.yeshi.utils.TimeUtil;
import com.yeshi.fanli.util.factory.CommonOrderGoodsFactory;
import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
import com.yeshi.fanli.util.taobao.TaoBaoOrderUtil;
import com.yeshi.fanli.util.factory.goods.CommonOrderFactory;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import net.sf.json.JSONObject;
@Service
public class OrderRepairServiceImpl implements OrderRepairService {
@@ -120,15 +130,21 @@
   private OrderRepairHistoryService orderRepairHistoryService;
   @Resource
   private DataSourceTransactionManager dataSourceTransactionManager;
   @Resource
   private TaoBaoWeiQuanOrderService taoBaoWeiQuanOrderService;
   @Resource
   private UserMoneyService userMoneyService;
   @Transactional
   @Resource
   private PushInfoService pushInfoService;
   @Resource
   private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
   @Resource
   private ExtractCheckCompensateMapper extractCheckCompensateMapper;
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void repairOrder(String orderId) throws Exception {
      // 比较CommonOrder与TaoBaoOrder的预估收益
@@ -171,7 +187,6 @@
   }
   @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
   private void processLessFanOrder(String orderId) throws Exception {
      List<CommonOrder> commonOrderList = commonOrderMapper.listBySourceTypeAndOrderNo(Constant.SOURCE_TYPE_TAOBAO,
@@ -270,7 +285,7 @@
         wholeOrderState = CommonOrder.STATE_WHOLE_ORDER_BUFENYOUXIAO;
      for (TaoBaoOrder taoBaoOrder : taoBaoOrderList) {
         CommonOrder commonOrder = TaoBaoOrderUtil.convert(taoBaoOrder);
         CommonOrder commonOrder = CommonOrderFactory.create(taoBaoOrder);
         commonOrder.setStateWholeOrder(wholeOrderState);
         commonOrder.setCommonOrderGoods(getCommonOrderGoods(taoBaoOrder.getAuctionId()));
         commonOrder.setUserInfo(new UserInfo(mainUid));
@@ -372,10 +387,12 @@
   }
   // 修改订单信息
   @Transactional
   private void updateOrderInfo(TaoBaoOrder taoBaoOrder, Long commonOrderId) throws Exception {
      HongBaoOrder hongBaoOrder = hongBaoOrderService.selectDetailByCommonOrderId(commonOrderId);
      CommonOrder newCommonOrder = TaoBaoOrderUtil.convert(taoBaoOrder);
      CommonOrder newCommonOrder = CommonOrderFactory.create(taoBaoOrder);
      SystemEnum system=userInfoService.getUserSystem(newCommonOrder.getUserInfo().getId());
      List<CommonOrderGoods> commonGoodsList = commonOrderGoodsMapper
            .listByGoodsIdAndGoodsType(taoBaoOrder.getAuctionId() + "", newCommonOrder.getSourceType());
      CommonOrderGoods cog = null;
@@ -413,7 +430,8 @@
      CommonOrder commonOrder = commonOrderService.selectByPrimaryKey(newCommonOrder.getId());
      if (hongBaoOrder.getHongBaoV2().getType() == HongBaoV2.TYPE_ZIGOU) {
         BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime());
         BigDecimal fanliRate = hongBaoManageService.getFanLiRate(UserLevelEnum.daRen,
               commonOrder.getCreateTime().getTime(),system);
         // 免单处理
         boolean mianDan = false;
         List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO,
@@ -423,7 +441,8 @@
            if (commonOrder.getState() == CommonOrder.STATE_JS)
               payMent = commonOrder.getSettlement();
            if (payMent.compareTo(new BigDecimal(10)) < 0) {
               mianDan = userSystemCouponRecordService.isSuccessMianDan(commonOrder.getOrderNo());
               mianDan = userSystemCouponRecordService.isSuccessMianDan(commonOrder.getSourceType(),
                     commonOrder.getOrderNo());
            }
         }
@@ -450,7 +469,7 @@
            hongBao.setMoney(new BigDecimal(0));
            if (mianDan) {
               try {
                  userSystemCouponService.updateStateByDrawback(commonOrder.getOrderNo());
                  userSystemCouponService.updateStateByDrawback(commonOrder.getOrderNo(),commonOrder.getSourceType());
               } catch (Exception e) {
                  e.printStackTrace();
                  throw new HongBaoException(12, "免单券退款出错");
@@ -470,10 +489,10 @@
               BigDecimal rate = null;
               if (child.getType() == HongBaoV2.TYPE_YIJI) {// 一级分享赚
                  rate = hongBaoManageService.getFirstInviteRate(child.getUrank(),
                        commonOrder.getCreateTime().getTime());
                        commonOrder.getCreateTime().getTime(),system);
               } else if (child.getType() == HongBaoV2.TYPE_ERJI) {// 二级分享赚
                  rate = hongBaoManageService.getSecondInviteRate(child.getUrank(),
                        commonOrder.getCreateTime().getTime());
                        commonOrder.getCreateTime().getTime(),system);
               }
               // 以实际收入为准计算预估收益
@@ -500,7 +519,8 @@
            }
      } else if (hongBaoOrder.getHongBaoV2().getType() == HongBaoV2.TYPE_SHARE_GOODS) {
         BigDecimal fanliRate = hongBaoManageService.getShareRate(commonOrder.getCreateTime().getTime());
         BigDecimal fanliRate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,
               commonOrder.getCreateTime().getTime(),system);
         List<ShareGoodsActivityOrder> list = shareGoodsActivityOrderService
               .listByOrderIdAndUid(commonOrder.getUserInfo().getId(), commonOrder.getOrderNo());
         if (list != null && list.size() > 0) {
@@ -541,9 +561,9 @@
               childUpdate.setUpdateTime(new Date());
               BigDecimal rate = null;
               if (child.getType() == HongBaoV2.TYPE_SHARE_YIJI) {// 一级分享赚
                  rate = hongBaoManageService.getFirstShareRate(1, commonOrder.getCreateTime().getTime());
                  rate = hongBaoManageService.getFirstShareRate(1, commonOrder.getCreateTime().getTime(),system);
               } else if (child.getType() == HongBaoV2.TYPE_SHARE_ERJI) {// 二级分享赚
                  rate = hongBaoManageService.getSecondShareRate(1, commonOrder.getCreateTime().getTime());
                  rate = hongBaoManageService.getSecondShareRate(1, commonOrder.getCreateTime().getTime(),system);
               }
               // 以实际收入为准计算预估收益
@@ -579,7 +599,7 @@
      }
   }
   @Transactional
   @Transactional(rollbackFor = Exception.class)
   public void addOrder(CommonOrder commonOrder, int type, Long firstUid, Long secondUid) throws Exception {
      // 增加commonOrder
      commonOrder.setCreateTime(commonOrder.getThirdCreateTime());
@@ -601,6 +621,8 @@
         commonOrder.setCommonOrderGoods(goods);
      }
      SystemEnum system=userInfoService.getUserSystem(commonOrder.getUserInfo().getId());
      CommonOrder oldCommonOrder = commonOrderMapper.selectBySourceTypeAndTradeId(commonOrder.getSourceType(),
            commonOrder.getTradeId());
      if (oldCommonOrder == null)// 新增
@@ -618,7 +640,8 @@
      // 添加红包
      if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
         BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime());
         BigDecimal fanliRate = hongBaoManageService.getFanLiRate(UserLevelEnum.daRen,
               commonOrder.getCreateTime().getTime(),system);
         // 查询是否有免单计划
         BigDecimal mianDanMoney = null;
         if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_FK) {
@@ -634,7 +657,7 @@
                  try {
                     if (userSystemCouponService.updateCouponRecordUsed(commonOrder.getUserInfo().getId(),
                           commonOrder.getOrderNo(), payMent, Long.parseLong(goods.getGoodsId())))
                           commonOrder.getOrderNo(), payMent, Long.parseLong(goods.getGoodsId()),commonOrder.getSourceType()))
                        mianDanMoney = payMent;
                  } catch (NumberFormatException e) {
                     throw new HongBaoException(10, "免单商品处理出错");
@@ -646,7 +669,7 @@
            }
         } else if (commonOrder.getState() == CommonOrder.STATE_SX) {// 设置免单券失效
            try {
               userSystemCouponService.updateStateByDrawback(commonOrder.getOrderNo());
               userSystemCouponService.updateStateByDrawback(commonOrder.getOrderNo(),commonOrder.getSourceType());
            } catch (Exception e) {
               e.printStackTrace();
            }
@@ -700,7 +723,7 @@
            // 插入一级子红包
            BigDecimal firstRate = hongBaoManageService
                  .getFirstInviteRate(boss.getRank() == null ? 0 : boss.getRank());
                  .getFirstInviteRate(boss.getRank() == null ? 0 : boss.getRank(),system);
            if (firstRate.compareTo(new BigDecimal(0)) <= 0)
               return;
            HongBaoV2 firstHongbao = new HongBaoV2();
@@ -747,7 +770,7 @@
            if (boss != null) {// 二级BOSS存在
               BigDecimal secondRate = hongBaoManageService
                     .getSecondInviteRate(boss.getRank() == null ? 0 : boss.getRank());
                     .getSecondInviteRate(boss.getRank() == null ? 0 : boss.getRank(),system);
               if (secondRate.compareTo(new BigDecimal(0)) <= 0)
                  return;
               HongBaoV2 secondHongbao = new HongBaoV2();
@@ -794,7 +817,8 @@
         if (commonOrder.getState() == CommonOrder.STATE_SX || commonOrder.getState() == CommonOrder.STATE_WQ)
            return;
         // 分享赚
         BigDecimal shareRate = hongBaoManageService.getShareRate(commonOrder.getCreateTime().getTime());
         BigDecimal shareRate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,
               commonOrder.getCreateTime().getTime(),system);
         HongBaoV2 hongBao = new HongBaoV2();
         hongBao.setBeizhu("2019年7月批量修改");
@@ -837,7 +861,7 @@
               boss = userInfoService.selectByPKey(firstUid);
            if (boss != null) {
               BigDecimal firstLevelRate = hongBaoManageService.getFirstShareRate(1,
                     commonOrder.getThirdCreateTime().getTime());
                     commonOrder.getThirdCreateTime().getTime(),system);
               HongBaoV2 child = new HongBaoV2();
               child.setBeizhu("2019年7月批量修改");
               child.setParent(hongBao);
@@ -878,8 +902,8 @@
   }
   @Transactional(propagation = Propagation.REQUIRED)
   private void deleteByCommonOrderId(Long commonOrderId) {
      commonOrderMapper.deleteByPrimaryKey(commonOrderId);
      HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrderId);
      if (hongBaoOrder == null || hongBaoOrder.getHongBaoV2() == null)
         return;
@@ -890,7 +914,7 @@
         }
      hongBaoV2Mapper.deleteByPrimaryKey(hongBaoOrder.getHongBaoV2().getId());
      hongBaoOrderMapper.deleteByPrimaryKey(hongBaoOrder.getId());
      commonOrderMapper.deleteByPrimaryKey(commonOrderId);
   }
   @Transactional
@@ -940,8 +964,12 @@
      return orderInfoMap.get(orderId);
   }
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void repireFirstAndSecondLevel(String orderId) throws Exception {
      repireFirstShare(orderId);
      if (1 > 0)
         return;
      OrderInfo info = getOrderInfo(orderId);
      Map<Long, BigDecimal> oldMoneyMap = new HashMap<>();
      if (info.getFirstUid() != null)
@@ -962,8 +990,13 @@
               return;
         }
         for (CommonOrder commonOrder : list) {
                SystemEnum system=userInfoService.getUserSystem(commonOrder.getUserInfo().getId());
            HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
            if (hongBaoOrder == null)
               continue;
            HongBaoV2 hongBao = hongBaoOrder.getHongBaoV2();
            Long firstUid = info.getFirstUid();
            Long secondUid = info.getSecondUid();
@@ -975,7 +1008,7 @@
            if (boss != null && hongBao.getState() != HongBaoV2.STATE_SHIXIAO) {// 1级BOSS存在且红包未失效,免单不支持多级分销
               // 插入一级子红包
               BigDecimal firstRate = hongBaoManageService
                     .getFirstInviteRate(boss.getRank() == null ? 0 : boss.getRank());
                     .getFirstInviteRate(boss.getRank() == null ? 0 : boss.getRank(),system);
               if (firstRate.compareTo(new BigDecimal(0)) <= 0)
                  return;
               HongBaoV2 firstHongbao = new HongBaoV2();
@@ -1020,7 +1053,7 @@
               if (boss != null) {// 二级BOSS存在
                  BigDecimal secondRate = hongBaoManageService
                        .getSecondInviteRate(boss.getRank() == null ? 0 : boss.getRank());
                        .getSecondInviteRate(boss.getRank() == null ? 0 : boss.getRank(),system);
                  if (secondRate.compareTo(new BigDecimal(0)) <= 0)
                     return;
                  HongBaoV2 secondHongbao = new HongBaoV2();
@@ -1061,6 +1094,120 @@
            }
         }
      }
      // 统计修改后的资金
      List<CommonOrder> newCommonOrderList = commonOrderMapper.listBySourceTypeAndOrderNo(Constant.SOURCE_TYPE_TAOBAO,
            orderId);
      Map<Long, BigDecimal> newMap = new HashMap<>();
      if (newCommonOrderList != null)
         for (CommonOrder co : newCommonOrderList) {
            HongBaoOrder newHongBaoOrder = hongBaoOrderService.selectDetailByCommonOrderId(co.getId());
            if (newHongBaoOrder == null)
               continue;
            HongBaoV2 hongBao = newHongBaoOrder.getHongBaoV2();
            List<HongBaoV2> children = hongBaoV2Service.listChildrenById(hongBao.getId());
            if (children != null)
               for (HongBaoV2 child : children) {
                  if (newMap.get(child.getUserInfo().getId()) == null)
                     newMap.put(child.getUserInfo().getId(), new BigDecimal(0));
                  if (child.getState() == HongBaoV2.STATE_YILINGQU)
                     newMap.put(child.getUserInfo().getId(),
                           newMap.get(child.getUserInfo().getId()).add(child.getMoney()));
               }
         }
      for (Iterator<Long> its = newMap.keySet().iterator(); its.hasNext();) {
         Long uid = its.next();
         BigDecimal beforeGetMoney = oldMoneyMap.get(uid);
         BigDecimal afterGetMoney = newMap.get(uid);
         OrderRepairHistory history = new OrderRepairHistory();
         history.setAfterGetMoney(afterGetMoney);
         history.setBeforeGetMoney(beforeGetMoney);
         history.setOrderId(orderId);
         history.setUid(uid);
         orderRepairHistoryService.addOrderRepairHistory(history);
      }
   }
   private void repireFirstShare(String orderId) throws Exception {
      OrderInfo info = getOrderInfo(orderId);
      Long firstUid = info.getFirstUid();
      Map<Long, BigDecimal> oldMoneyMap = new HashMap<>();
      if (info.getFirstUid() != null)
         oldMoneyMap.put(info.getFirstUid(), info.getFirstUidMoney());
      if (info.getSecondUid() != null)
         oldMoneyMap.put(info.getSecondUid(), info.getSecondUidMoney());
      if (info != null) {
         List<CommonOrder> list = commonOrderMapper.listBySourceTypeAndOrderNo(Constant.SOURCE_TYPE_TAOBAO,
               info.getOrderId());
         // 查询是否有子红包
         for (CommonOrder commonOrder : list) {
            HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
            if (hongBaoOrder == null)
               continue;
            List<HongBaoV2> hongBaoList = hongBaoV2Mapper.listChildrenById(hongBaoOrder.getHongBaoV2().getId());
            if (hongBaoList != null && hongBaoList.size() > 0)// 有子红包就不处理了
               return;
         }
         for (CommonOrder commonOrder : list) {
            if (commonOrder.getState() == CommonOrder.STATE_SX || commonOrder.getState() == CommonOrder.STATE_WQ)
               continue;
            // 分享赚
            HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
            if (hongBaoOrder == null)
               continue;
            SystemEnum system=userInfoService.getUserSystem(commonOrder.getUserInfo().getId());
            HongBaoV2 hongBao = hongBaoOrder.getHongBaoV2();
            // 4月17日后才有一级分享赚
            if (commonOrder.getThirdCreateTime().getTime() > TimeUtil.convertToTimeTemp("2019-04-17",
                  "yyyy-MM-dd")) {
               UserInfo boss = null;
               if (firstUid != null)
                  boss = userInfoService.selectByPKey(firstUid);
               if (boss != null) {
                  BigDecimal firstLevelRate = hongBaoManageService.getFirstShareRate(1,
                        commonOrder.getThirdCreateTime().getTime(),system);
                  HongBaoV2 child = new HongBaoV2();
                  child.setBeizhu("2019年7月批量修改");
                  child.setParent(hongBao);
                  child.setType(HongBaoV2.TYPE_SHARE_YIJI);
                  if (commonOrder.getState() == CommonOrder.STATE_FK) {
                     child.setState(HongBaoV2.STATE_BUKELINGQU);
                     child.setMoney(MoneyBigDecimalUtil.mul(commonOrder.getEstimate(),
                           firstLevelRate.divide(new BigDecimal(100))));
                  } else if (commonOrder.getState() == CommonOrder.STATE_JS) {
                     child.setState(HongBaoV2.STATE_KELINGQU);
                     child.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(),
                           firstLevelRate.divide(new BigDecimal(100))));
                     Calendar calendar = Calendar.getInstance();
                     calendar.setTime(commonOrder.getSettleTime());
                     calendar.add(Calendar.MONTH, 1);
                     child.setPreGetTime(new Date(TimeUtil.convertToTimeTemp(
                           calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25",
                           "yyyy-M-dd")));
                     if (child.getPreGetTime().getTime() < System.currentTimeMillis()) {
                        child.setGetTime(child.getPreGetTime());
                        child.setState(HongBaoV2.STATE_YILINGQU);
                     }
                  }
                  child.setUserInfo(boss);
                  child.setUrank(boss.getRank());
                  child.setVersion(2);
                  child.setCreateTime(new Date());
                  hongBaoV2Mapper.insertSelective(child);
               }
            }
         }
      }
      // 统计修改后的资金
@@ -1156,22 +1303,85 @@
   @Override
   public void doMoney(Long uid) {
      List<OrderRepairHistory> historyList = listByUid(uid);
      for (int i = 0; i < historyList.size(); i++) {
         if (historyList.get(i).getCreateTime().getTime() < TimeUtil.convertToTimeTemp("2019-07-15 17:00:38",
               "yyyy-MM-dd HH:mm:ss")) {
            historyList.remove(i);
            i--;
         }
      }
      BigDecimal money = new BigDecimal(0);
      String orders = "";
      for (OrderRepairHistory history : historyList) {
         money.add(history.getAfterGetMoney().subtract(history.getBeforeGetMoney()));
         money = money.add(history.getAfterGetMoney().subtract(history.getBeforeGetMoney()));
         orders += history.getOrderId() + ",";
      }
      if (money.compareTo(new BigDecimal(0)) > 0)// 资金需要增加
      {
         try {
            UserMoneyDetail detail = UserMoneyDetailFactory.createSystemEqualize(null, money, new UserInfo(uid));
            UserMoneyDetail detail = UserMoneyDetailFactory.createSystemEqualize("订单统计异常修复", money,
                  new UserInfo(uid));
            // 系统补齐
            // 加资金
            userMoneyService.addUserMoney(uid, money, detail);
            pushMsg(uid, "关于近期订单与资金异常的排查与修复结果通知",
                  "尊敬的用户,经仔细核对您账户中的订单,发现您账户中有未统计或错误统计的订单,我们已经为您补齐资金,对应资金已经存入您的账户余额中,敬请查收注查收。感谢信任,板栗快省App终将成为您最信任的购物省钱助手。");
            userMoneyMsgNotificationService.systemEqualize(uid, "订单统计异常修复", money, userInfoService.getBalance(uid));
         } catch (UserMoneyDetailException e) {
            e.printStackTrace();
         }
      } else {// 资金需要减少
      } else {// 资金需要减少,不要扣钱
         pushMsg(uid, "关于近期订单与资金异常的排查与修复结果通知",
               "尊敬的用户,经仔细核对您账户中的订单,发现您账户中有错误统计的订单,我们已经为您恢复正常,所涉及订单多统计出来的资金,不会被扣除,即您账户中的资金将保持不变,已提现的资金,也不会收回,敬请知晓。感谢信任,板栗快省App终将成为您最信任的购物省钱助手。");
         // userMoneyMsgNotificationService.systemEqualize(uid, "订单统计异常修复",
         // money, userInfoService.getBalance(uid));
         // 加入提现审核异常保护中
         ExtractCheckCompensate check = new ExtractCheckCompensate();
         check.setBeiZhu("7月订单异常系统处理:" + orders);
         check.setCreateTime(new Date());
         check.setMoney(money);
         check.setUserInfo(new UserInfo(uid));
         check.setUpdateTime(new Date());
         extractCheckCompensateMapper.insertSelective(check);
      }
   }
   private void pushMsg(Long uid, String title, String content) {
      PushInfo pushInfo = new PushInfo();
      pushInfo.setTitle(title);
      pushInfo.setContent(content);
      pushInfo.setUids(uid + "");
      JSONObject jsonData = new JSONObject();
      jsonData.put("url", "");
      jsonData.put("ios", "全推");
      jsonData.put("android", "全推");
      pushInfo.setJsonData(jsonData.toString());
      pushInfo.setType(PushTypeEnum.ZNX);
      pushInfo.setArrayAndroid("[全推]");
      pushInfo.setArrayIOS("[全推]");
      pushInfo.setCreateTime(new Date());
      try {
         pushInfoService.save(pushInfo);
      } catch (PushInfoException e) {
         e.printStackTrace();
      } catch (Exception e) {
         e.printStackTrace();
      }
      try {
         pushInfoService.handPush(pushInfo.getId());
      } catch (PushInfoException e) {
         e.printStackTrace();
      } catch (PushException e) {
         e.printStackTrace();
      } catch (Exception e) {
         e.printStackTrace();
      }
   }