From 573c491b4a1ba60e12a5678a01c1546c0077c1ee Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 30 七月 2019 09:07:42 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderServiceImpl.java | 426 +--------------------------------------------------- 1 files changed, 12 insertions(+), 414 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderServiceImpl.java index 4d38958..c67cb3f 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderServiceImpl.java @@ -1,64 +1,22 @@ package com.yeshi.fanli.service.impl.order; -import java.io.Serializable; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.Calendar; -import java.util.Date; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock; import javax.annotation.Resource; -import org.hibernate.HibernateException; -import org.hibernate.Query; -import org.hibernate.SQLQuery; -import org.hibernate.Session; -import org.springframework.orm.hibernate4.HibernateCallback; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; -import com.yeshi.fanli.dao.mybatis.ThreeSaleGiftMapper; -import com.yeshi.fanli.dao.mybatis.order.OrderItemMapper; import com.yeshi.fanli.dao.mybatis.order.OrderMapper; -import com.yeshi.fanli.dao.order.OrderDao; -import com.yeshi.fanli.dao.order.PidOrderDao; -import com.yeshi.fanli.entity.bus.user.HongBao; +import com.yeshi.fanli.entity.bus.user.HongBaoV2; import com.yeshi.fanli.entity.bus.user.Order; -import com.yeshi.fanli.entity.bus.user.OrderItem; -import com.yeshi.fanli.entity.bus.user.ThreeSaleGift; -import com.yeshi.fanli.entity.taobao.PidOrder; -import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder; -import com.yeshi.fanli.exception.ObjectStateException; import com.yeshi.fanli.service.inter.config.ConfigService; -import com.yeshi.fanli.service.inter.hongbao.HongBaoService; -import com.yeshi.fanli.service.inter.hongbao.ThreeSaleGiftService; import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce; -import com.yeshi.fanli.service.inter.order.OrderItemServcie; +import com.yeshi.fanli.service.inter.order.HongBaoOrderService; import com.yeshi.fanli.service.inter.order.OrderService; -import com.yeshi.fanli.service.inter.user.ShareManageService; -import com.yeshi.fanli.util.Constant; -import com.yeshi.fanli.util.TimeUtil; -import com.yeshi.fanli.util.Utils; -import org.yeshi.utils.NumberUtil; @Service public class OrderServiceImpl implements OrderService { - - @Resource - private OrderDao orderDao; - - @Resource - private OrderService orderService; - - @Resource - private ShareManageService shareManageService; - - @Resource - private HongBaoService hongBaoService; @Resource private ConfigService configService; @@ -67,41 +25,13 @@ private ThreeSaleSerivce threeSaleSerivce; @Resource - private OrderItemServcie orderItemService; - - @Resource - private ThreeSaleGiftService threeSaleGiftService; - - @Resource private OrderMapper orderMapper; @Resource - private OrderItemMapper orderItemMapper; + private HongBaoOrderService hongBaoOrderService; - @Resource - private PidOrderDao pidOrderDao; - - @Resource - private ThreeSaleGiftMapper threeSaleGiftMapper; - - public List<Order> getOrderByUid(int index, long uid) { - - int start = index * Constant.PAGE_SIZE; - - return orderDao.list("from Order o where o.userInfo.id=? and o.money>0 order by o.createtime desc", start, - Constant.PAGE_SIZE, new Serializable[] { uid }); - - } - - public long getOrderCountByTime(long startTime, long endTime) { - - long count = orderDao.getCount("select count(*) from Order where createtime >=? and createtime < ?", - new Serializable[] { startTime, endTime }); - - return count; - } - - @Transactional(propagation = Propagation.NESTED, rollbackFor = Exception.class) + // @Transactional(propagation = Propagation.NESTED, rollbackFor = + // Exception.class) public boolean addOrder(Order order) throws Exception { order.setVersion(2); WriteLock writeLock = orderLock.writeLock(); @@ -113,14 +43,11 @@ if (find != null) { return false; } + // 鏌ユ壘鏄惁瀛樺湪鍒嗕韩璧氳鍗� - - List<PidOrder> orderList = pidOrderDao.list("from PidOrder p where p.orderId=?", - new Serializable[] { order.getOrderId() }); - if (orderList != null && orderList.size() > 0) + if (hongBaoOrderService.countByOrderNoAndHongBaoType(order.getOrderId(), HongBaoV2.TYPE_SHARE_GOODS) > 0) return false; - - orderDao.save(order); + orderMapper.insertSelective(order); } finally { writeLock.unlock(); } @@ -151,347 +78,18 @@ return true; } - public boolean isfirstOrder(long uid) { - - List<Order> list = orderDao.list("from Order o where o.userInfo.id = ? and o.state = 1 ", 0, 1, - new Serializable[] { uid }); - if (list.size() == 0) { - return true; - } - return false; - } - - public int getCount(long uid) { - Long lcount = orderDao.getCount("select count(o.id) from Order o where o.userInfo.id = ? ", - new Serializable[] { uid }); - return lcount.intValue(); - } - - public List<Order> getOrderList(String key, int index) { - - int start = index * Constant.PAGE_SIZE; - - boolean b = NumberUtil.isNumeric(key); - if (b) { - long uid = Long.parseLong(key); - return orderDao.list( - "from Order o where o.userInfo.id = ? or o.userInfo.nickName like ? order by o.id desc ", start, - Constant.PAGE_SIZE, new Serializable[] { uid, "%" + key + "%" }); - } - return orderDao.list("from Order o where o.userInfo.nickName like ? order by o.id desc", start, - Constant.PAGE_SIZE, new Serializable[] { "%" + key + "%" }); - - } - - public int getCount() { - Long lcount = orderDao.getCount("select count(o.id) from Order o"); - return lcount.intValue(); - } - - @SuppressWarnings("unchecked") - public Map<String, Integer> getnewOrderByDate(final int days, Date date) { - - final Map<String, Integer> map = new HashMap<String, Integer>(); - long timestampms = date.getTime(); - final long timestamps = timestampms / 1000; - List<String> list = TimeUtil.getEmupDate(days, timestampms); - for (String dataStr : list) { - map.put(dataStr, 0); - } - return (Map<String, Integer>) orderDao.excute(new HibernateCallback<Map<String, Integer>>() { - - public Map<String, Integer> doInHibernate(Session session) throws HibernateException { - SQLQuery sqlQuery = session.createSQLQuery( - "SELECT DATE(FROM_UNIXTIME(createtime/1000)) c,COUNT(*) FROM yeshi_ec_order WHERE DATE_SUB(FROM_UNIXTIME(?), INTERVAL ? DAY) <= DATE(FROM_UNIXTIME(createtime/1000)) AND DATE(FROM_UNIXTIME(createtime/1000)) <= FROM_UNIXTIME(?) GROUP BY c"); - sqlQuery.setParameter(0, timestamps); - sqlQuery.setParameter(1, days); - sqlQuery.setParameter(2, timestamps); - List<Object[]> list = sqlQuery.list(); - for (Object[] objArr : list) { - map.put(TimeUtil.getSimpleDate((Date) objArr[0]), ((BigInteger) objArr[1]).intValue()); - } - return map; - } - }); - } - - @SuppressWarnings("unchecked") - public Map<String, Integer> getnewOrderByMonth(final int months, final Date endDate) { - List<String> monthList = Utils.getDateMonthList(months, endDate); - final Map<String, Integer> map = new HashMap<String, Integer>(); - for (String monthStr : monthList) { - map.put(monthStr, 0); - } - return (Map<String, Integer>) orderDao.excute(new HibernateCallback<Map<String, Integer>>() { - - public Map<String, Integer> doInHibernate(Session session) throws HibernateException { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(endDate); - calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) + 1); - calendar.set(Calendar.DAY_OF_MONTH, 1); - long curTime = (calendar.getTime().getTime()) / 1000; - SQLQuery sqlQuery = session.createSQLQuery( - "SELECT DATE_FORMAT(FROM_UNIXTIME(createtime/1000),'%Y-%m') months,COUNT(*) FROM yeshi_ec_order WHERE DATE(FROM_UNIXTIME(createtime/1000)) >= DATE_SUB(FROM_UNIXTIME(?),INTERVAL ? MONTH) AND DATE(FROM_UNIXTIME(createtime/1000)) < FROM_UNIXTIME(?) GROUP BY months"); - sqlQuery.setParameter(0, curTime); - sqlQuery.setParameter(1, months); - sqlQuery.setParameter(2, curTime); - List<Object[]> list = sqlQuery.list(); - for (Object[] objArr : list) { - map.put((String) objArr[0], ((BigInteger) objArr[1]).intValue()); - } - return map; - } - }); - } - - @SuppressWarnings("unchecked") - public Map<String, Integer> getOrderTotalByDate(int days, Date date) { - - final Map<String, Integer> map = new HashMap<String, Integer>(); - long timestampms = date.getTime(); - final List<String> list = TimeUtil.getEmupDate(days, timestampms); - for (String dataStr : list) { - map.put(dataStr, 0); - } - return (Map<String, Integer>) orderDao.excute(new HibernateCallback<Map<String, Integer>>() { - - public Map<String, Integer> doInHibernate(Session session) throws HibernateException { - StringBuffer sb = new StringBuffer(); - int ii = 0; - for (String day : list) { - if (ii == 0) { - sb.append("SELECT '" + day + "' AS t,IFNULL(SUM(a.s),0) FROM yeshi_ec_order_day a WHERE a.c<= '" - + day + "' "); - } else { - sb.append("UNION ALL SELECT '" + day - + "' AS t,IFNULL(SUM(a.s),0) FROM yeshi_ec_order_day a WHERE a.c<= '" + day + "' "); - } - ii++; - } - - SQLQuery sqlQuery = session.createSQLQuery(sb.toString()); - List<Object[]> list = sqlQuery.list(); - for (Object[] objArr : list) { - map.put(String.valueOf(objArr[0]), ((BigDecimal) objArr[1]).intValue()); - } - return map; - } - }); - } - - @SuppressWarnings("unchecked") - public Map<String, Integer> getOrderTotalByMonth(int months, Date date) { - final List<String> monthList = Utils.getDateMonthList(months, date); - final Map<String, Integer> map = new HashMap<String, Integer>(); - for (String monthStr : monthList) { - map.put(monthStr, 0); - } - return (Map<String, Integer>) orderDao.excute(new HibernateCallback<Map<String, Integer>>() { - - public Map<String, Integer> doInHibernate(Session session) throws HibernateException { - - StringBuffer sb = new StringBuffer(); - int ii = 0; - for (String month : monthList) { - if (ii == 0) { - sb.append("SELECT '" + month - + "' AS t,IFNULL(SUM(a.s),0) FROM yeshi_ec_order_month a WHERE a.months<= '" + month - + "' "); - } else { - sb.append("UNION ALL SELECT '" + month - + "' AS t,IFNULL(SUM(a.s),0) FROM yeshi_ec_order_month a WHERE a.months<= '" + month - + "' "); - } - ii++; - } - - SQLQuery sqlQuery = session.createSQLQuery(sb.toString()); - List<Object[]> list = sqlQuery.list(); - for (Object[] objArr : list) { - map.put((String) objArr[0], ((BigDecimal) objArr[1]).intValue()); - } - return map; - } - }); - } - - public Order getOrder(final String orderid, final int orderType) { - return (Order) orderDao.excute(new HibernateCallback<Order>() { - - public Order doInHibernate(Session session) throws HibernateException { - Query query = session.createQuery("from Order o where o.orderId = ? and o.orderType = ? "); - query.setParameter(0, orderid); - query.setParameter(1, orderType); - List<Order> list = query.list(); - if (list.size() > 0) { - return list.get(0); - } - return null; - } - }); - } - - @Transactional(propagation = Propagation.REQUIRED) - public void failureOrder(final String orderid, final int orderType) throws ObjectStateException { - // 澶辨晥鐨勮鍗� - List<Order> orderList = orderService.setOrderState(orderid, orderType); - if (orderList != null && orderList.size() > 0) { - for (Order order : orderList) { - // 鎵惧埌杩欎釜澶辨晥璁㈠崟浠ュ墠鍙戠殑绾㈠寘 - List<HongBao> hongBaoList = hongBaoService.findHongBaoByOrderList(order.getId()); - if (hongBaoList != null) - for (HongBao hongBao : hongBaoList) - // 鎶婄孩鍖呮悶鎴愬け鏁堢殑,鍒嗛攢鐨勭孩鍖呬篃瑕佹悶澶辨晥 - hongBaoService.relevantInvalid(hongBao.getId()); - } - } - } - - @Transactional - public void failureOrderWithWeiQuan(final String orderid, final int orderType) throws ObjectStateException { - // 澶辨晥鐨勮鍗� - List<Order> orderList = orderService.setOrderState(orderid, orderType); - if (orderList != null && orderList.size() > 0) { - for (Order order : orderList) { - // if (order.getState() == Order.STATE_SHIXIAO) - // continue; - // 鎵惧埌杩欎釜澶辨晥璁㈠崟浠ュ墠鍙戠殑绾㈠寘 - List<HongBao> hongBaoList = hongBaoService.findHongBaoByOrderList(order.getId()); - if (hongBaoList != null) - for (HongBao hongBao : hongBaoList) - // 鎶婄孩鍖呮悶鎴愬け鏁堢殑,鍒嗛攢鐨勭孩鍖呬篃瑕佹悶澶辨晥 - hongBaoService.relevantInvalidVersion2(hongBao.getId()); - - List<OrderItem> orderItremList = orderItemService.findByOrderId(order.getId()); - if (orderItremList != null) - for (OrderItem orderItem : orderItremList) { - OrderItem updateOrderItem = new OrderItem(orderItem.getId()); - - updateOrderItem.setState(OrderItem.STATE_TUIKUAN); - // 鏌ヨ - List<ThreeSaleGift> giftList = threeSaleGiftService.findThreeSaleGiftList(orderItem.getId()); - for (ThreeSaleGift tsg : giftList) { - if (tsg.getState().intValue() != OrderItem.STATE_DAOZHANG - && tsg.getState().intValue() != OrderItem.STATE_SHOUHOU) { - ThreeSaleGift updateTsg = new ThreeSaleGift(); - updateTsg.setId(tsg.getId()); - updateTsg.setState(OrderItem.STATE_TUIKUAN); - threeSaleGiftMapper.updateByPrimaryKeySelective(updateTsg); - } - } - orderItemMapper.updateByPrimaryKeySelective(updateOrderItem); - } - Order updateOrder = new Order(); - updateOrder.setId(order.getId()); - updateOrder.setState(Order.STATE_SHIXIAO); - orderMapper.updateByPrimaryKeySelective(updateOrder); - } - } - } - - @Transactional - public List<Order> setOrderState(final String orderid, final int orderType) { - List<Order> orderList = orderMapper.selectOrderByOrderIdAndOrderType(orderid, orderType); - if (orderList != null) - for (Order order : orderList) { - if (order.getDrawbackTime() == null || order.getDrawbackTime() <= 0) { - Order updateOrder = new Order(); - updateOrder.setId(order.getId()); - updateOrder.setDrawbackTime(java.lang.System.currentTimeMillis()); - updateOrder.setState(Order.STATE_SHIXIAO); - orderMapper.updateByPrimaryKeySelective(updateOrder); - order.setDrawbackTime(updateOrder.getDrawbackTime()); - order.setState(updateOrder.getState()); - } - } - return orderList; - } - - public int getCount(String key) { - if (NumberUtil.isNumeric(key)) { - - if (key.trim().length() < 18) { - long lk = Long.parseLong(key); - return (int) orderDao.getCount( - "select count(*) from Order o where o.userInfo.id = ? or o.userInfo.nickName like ? ", - new Serializable[] { lk, "%" + key + "%" }); - } else { - return (int) orderDao.getCount("select count(*) from Order o where o.orderId like ? ", - new Serializable[] { "%" + key + "%" }); - } - - } else { - return (int) orderDao.getCount("select count(*) from Order o where o.userInfo.nickName like ? ", - new Serializable[] { "%" + key + "%" }); - } - } - - public Order find(long id) { - return orderDao.find(Order.class, id); - } - - public void update(Order findOrder) { - orderDao.update(findOrder); - } - @Override public Order findOrderByOrderIdAndType(String orderId, int type) { - List<Order> list = orderDao.list("from Order o where o.orderId=? and o.orderType=?", 0, 1, - new Serializable[] { orderId, type }); - if (list.size() > 0) { - return list.get(0); - } - return null; - } - - @Override - public Order findOrderByOrderIdAndTypeAndVersion(String orderId, int type, int version) { - List<Order> list = orderDao.list("from Order o where o.orderId=? and o.orderType=? and o.version=?", 0, 1, - new Serializable[] { orderId, type, version }); - if (list.size() > 0) { - return list.get(0); - } - return null; + Order order = orderMapper.selectOrderByOrderIdAndOrderType(orderId, type); + return order; } @Override public Order getSystemOrderByUid(int type, long uid) { - - List<Order> list = orderDao.list( - "from Order o where o.userInfo.id = ? and o.orderType = ? and o.beizhu = '绯荤粺娣诲姞'", 0, 1, - new Serializable[] { uid, type }); - - if (list.size() > 0) { + List<Order> list = orderMapper.listByUidAndOrderTypeAndBeiZhu(uid, type, "绯荤粺娣诲姞"); + if (list != null && list.size() > 0) return list.get(0); - } - return null; - } - - @Override - public List<Order> findOldOrderListAll() { - - List<Order> list = orderDao.list("from Order or where or.version=1"); - - return list; - } - - // 澶勭悊缁存潈璁㈠崟 - @Override - public void update(TaoBaoWeiQuanOrder order) { - try { - failureOrderWithWeiQuan(order.getOrderId(), Order.ORDER_TYPE_TAOBAO); - } catch (ObjectStateException e) { - e.printStackTrace(); - } - } - - @Override - public Order getLatestOrder() { - List<Order> orderList = orderDao.list("from Order order order by order.thirdCreateTime desc", 0, 1, null); - if (orderList == null || orderList.size() == 0) - return null; - return orderList.get(0); } } -- Gitblit v1.8.0