From e5ade1fdbd87e085f5be5460c6e3f0adb47704e6 Mon Sep 17 00:00:00 2001
From: yujian <yujian>
Date: 星期三, 16 一月 2019 09:02:58 +0800
Subject: [PATCH] 后端统计+文件上传统一方式
---
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsGroupServiceImpl.java | 106 ++++++++++++++++++++++++++++++-----------------------
1 files changed, 60 insertions(+), 46 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsGroupServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsGroupServiceImpl.java
index cf4a6de..2b1a085 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsGroupServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsGroupServiceImpl.java
@@ -1,7 +1,6 @@
package com.yeshi.fanli.service.impl.user;
import java.math.BigDecimal;
-import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -12,13 +11,13 @@
import com.yeshi.fanli.dao.mybatis.share.UserShareGoodsGroupMapper;
import com.yeshi.fanli.entity.bus.share.UserShareGoodsGroup;
-import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
+import com.yeshi.fanli.entity.bus.share.UserShareGoodsRecord.ShareSourceTypeEnum;
+import com.yeshi.fanli.entity.bus.user.HongBao;
import com.yeshi.fanli.exception.share.UserShareGoodsRecordException;
import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.user.UserShareGoodsGroupService;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
-import com.yeshi.fanli.util.taobao.TaoBaoUtil;
@Service
public class UserShareGoodsGroupServiceImpl implements UserShareGoodsGroupService {
@@ -64,7 +63,7 @@
@Override
public UserShareGoodsGroup getSingleGoods(Long cid, Long uid) {
- return userShareGoodsGroupMapper.getSingleGoods(cid, uid);
+ return userShareGoodsGroupMapper.getSingleGoods(ShareSourceTypeEnum.goodsDetail,cid, uid );
}
@Override
@@ -79,43 +78,52 @@
/**
- * 鏇存柊娴忚璁板綍鏁版嵁
- * @param shareId 鍒嗕韩id
- * @param count 娴忚娆℃暟
+ * 鏇存柊璁㈠崟璁板綍鏁版嵁
+ * @param uid
+ * @param auctionId
*/
@Override
- public void updateBrowseRecord (Long shareId, int count) throws UserShareGoodsRecordException{
-
- if (shareId == null) {
- throw new UserShareGoodsRecordException(1, "鍒嗕韩id涓虹┖");
+ public void updateOrderRecord (HongBao hongBao) throws UserShareGoodsRecordException{
+
+ if (hongBao == null) {
+ throw new UserShareGoodsRecordException(1, "hongBao涓嶈兘涓虹┖");
}
- List<UserShareGoodsGroup> list = listByRecordId(shareId);
- if (list == null || list.size() == 0) {
- throw new UserShareGoodsRecordException(1, "鍒嗕韩鍟嗗搧宸蹭笉瀛樺湪");
+ if (hongBao.getUserInfo() == null) {
+ throw new UserShareGoodsRecordException(1, "鐢ㄦ埛淇℃伅涓嶈兘涓虹┖");
}
- List<UserShareGoodsGroup> listUpdate = new ArrayList<UserShareGoodsGroup>();
+ Long uid = hongBao.getUserInfo().getId();
+ if (uid == null) {
+ throw new UserShareGoodsRecordException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖");
+ }
- for (UserShareGoodsGroup group: list) {
- // 娉ㄦ剰锛� 淇敼璁板綍鏁版嵁銆佷絾涓嶅彲淇敼鏇存柊璁剧疆
- UserShareGoodsGroup shareGoodsGroup = new UserShareGoodsGroup(group.getId());
+ if (hongBao.getAuctionId() == null) {
+ throw new UserShareGoodsRecordException(1, "鍟嗗搧ID涓嶈兘涓虹┖");
+ }
+
+ UserShareGoodsGroup newestRecord = getNewestRecord(uid, hongBao.getAuctionId());
+
+ if (newestRecord != null) {
+ // 鏇存柊璁㈠崟鏁伴噺
+ UserShareGoodsGroup shareGoodsGroup = new UserShareGoodsGroup(newestRecord.getId());
+ Integer totalOrder = newestRecord.getTotalOrder();
- shareGoodsGroup.setTotalBrowse(group.getTotalBrowse() + count);
-
- Date browseTime = group.getBrowseTime();
- if (DateUtil.isSameDay(browseTime, new Date())) {
- shareGoodsGroup.setTodayBrowse(group.getTodayBrowse() + count);
- } else {
- shareGoodsGroup.setTodayBrowse(count);
- shareGoodsGroup.setBrowseTime(new Date());
+ if (totalOrder == null) {
+ totalOrder = 0;
}
+ shareGoodsGroup.setTotalOrder(totalOrder + 1);
- listUpdate.add(shareGoodsGroup);
+ // 鏇存柊棰勮鏀剁泭
+ BigDecimal totalMoney = newestRecord.getTotalMoney();
+ if (totalMoney == null) {
+ totalMoney = new BigDecimal(0);
+ }
+ BigDecimal resultMoney = MoneyBigDecimalUtil.add(totalMoney, hongBao.getMoney());
+ shareGoodsGroup.setTotalMoney(resultMoney);
+
+ updateByPrimaryKeySelective(shareGoodsGroup);
}
-
- userShareGoodsGroupMapper.updateBatchSelective(listUpdate);
-
}
@@ -125,33 +133,39 @@
* @param auctionId
*/
@Override
- public void updateOrderRecord (Long uid, TaoBaoGoodsBrief taoBaoGoodsBrief, int count)
+ public void updateBrowseRecord (Long uid, Long auctionId, int count)
throws UserShareGoodsRecordException{
if (uid == null) {
throw new UserShareGoodsRecordException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖");
}
- if (taoBaoGoodsBrief == null) {
- throw new UserShareGoodsRecordException(1, "鍟嗗搧涓嶈兘涓虹┖");
+ if (auctionId == null) {
+ throw new UserShareGoodsRecordException(1, "鍟嗗搧Id涓嶈兘涓虹┖");
}
- UserShareGoodsGroup newestRecord = getNewestRecord(uid, taoBaoGoodsBrief.getAuctionId());
+ UserShareGoodsGroup group = getNewestRecord(uid, auctionId);
- if (newestRecord != null) {
- // 娉ㄦ剰锛� 淇敼璁板綍鏁版嵁銆佷絾涓嶅彲淇敼鏇存柊璁剧疆
- UserShareGoodsGroup shareGoodsGroup = new UserShareGoodsGroup(newestRecord.getId());
- shareGoodsGroup.setTotalOrder(newestRecord.getTotalOrder() + count);
+ if (group != null) {
+ UserShareGoodsGroup shareGoodsGroup = new UserShareGoodsGroup(group.getId());
+ // 绱娴忚
+ Integer totalBrowse = group.getTotalBrowse();
+ if (totalBrowse == null) {
+ totalBrowse = 0;
+ }
+ shareGoodsGroup.setTotalBrowse(totalBrowse + count);
- // 鍗曚釜鍟嗗搧棰勮閲戦
- String rateStr = hongBaoManageService.get("hongbao_goods_proportion");
- BigDecimal money = TaoBaoUtil.getGoodsHongBaoMoney(taoBaoGoodsBrief, new BigDecimal(rateStr));
+ // 浠婃棩娴忚
+ Date date = new Date();
+ Date browseTime = group.getBrowseTime();
+ if (DateUtil.isSameDay(browseTime, date)) {
+ shareGoodsGroup.setTodayBrowse(group.getTodayBrowse() + count);
+ } else {
+ shareGoodsGroup.setTodayBrowse(count);
+ }
+ shareGoodsGroup.setBrowseTime(date);
- // 鏇存柊棰勮鏀剁泭
- BigDecimal resultMoney = MoneyBigDecimalUtil.mul(new BigDecimal(shareGoodsGroup.getTotalOrder()), money);
- shareGoodsGroup.setTotalMoney(resultMoney);
-
- updateByPrimaryKeySelective(shareGoodsGroup);
+ userShareGoodsGroupMapper.updateByPrimaryKeySelective(shareGoodsGroup);
}
}
}
--
Gitblit v1.8.0