package com.yeshi.fanli.goods.service.impl.usergoods;
|
|
import java.math.BigDecimal;
|
import java.util.Date;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.fanli.facade.goods.entity.usergoods.UserShareGoodsGroup;
|
import org.fanli.facade.goods.entity.usergoods.UserShareGoodsRecord.ShareSourceTypeEnum;
|
import org.fanli.facade.goods.exception.usergoods.UserShareGoodsRecordException;
|
import org.fanli.facade.goods.service.taobao.CommonGoodsService;
|
import org.fanli.facade.goods.service.usergoods.UserShareGoodsGroupService;
|
import org.fanli.facade.order.entity.hongbao.HongBao;
|
import org.fanli.facade.system.service.hongbao.HongBaoManageService;
|
import org.yeshi.utils.DateUtil;
|
import org.yeshi.utils.MoneyBigDecimalUtil;
|
|
import com.alibaba.dubbo.config.annotation.Service;
|
import com.yeshi.fanli.goods.dao.usergoods.UserShareGoodsGroupMapper;
|
|
@Service(version = "1.0.0")
|
public class UserShareGoodsGroupServiceImpl implements UserShareGoodsGroupService {
|
|
@Resource
|
private HongBaoManageService hongBaoManageService;
|
|
@Resource
|
private CommonGoodsService commonGoodsService;
|
|
@Resource
|
private UserShareGoodsGroupMapper userShareGoodsGroupMapper;
|
|
@Override
|
public int insert(UserShareGoodsGroup record) {
|
return userShareGoodsGroupMapper.insert(record);
|
}
|
|
@Override
|
public int insertSelective(UserShareGoodsGroup record) {
|
return userShareGoodsGroupMapper.insertSelective(record);
|
}
|
|
@Override
|
public UserShareGoodsGroup selectByPrimaryKey(Long id) {
|
return userShareGoodsGroupMapper.selectByPrimaryKey(id);
|
}
|
|
@Override
|
public int updateByPrimaryKeySelective(UserShareGoodsGroup record) {
|
return userShareGoodsGroupMapper.updateByPrimaryKeySelective(record);
|
}
|
|
@Override
|
public int updateByPrimaryKey(UserShareGoodsGroup record) {
|
return userShareGoodsGroupMapper.updateByPrimaryKey(record);
|
}
|
|
@Override
|
public List<UserShareGoodsGroup> listByRecordId(Long recordId) {
|
return userShareGoodsGroupMapper.listByRecordId(recordId);
|
}
|
|
@Override
|
public UserShareGoodsGroup getSingleGoods(Long cid, Long uid) {
|
return userShareGoodsGroupMapper.getSingleGoods(ShareSourceTypeEnum.goodsDetail,cid, uid );
|
}
|
|
@Override
|
public int insertBatch(List<UserShareGoodsGroup> list) {
|
return userShareGoodsGroupMapper.insertBatch(list);
|
}
|
|
@Override
|
public UserShareGoodsGroup getNewestRecord(Long uid, Long auctionId) {
|
return userShareGoodsGroupMapper.getNewestRecord(uid, auctionId);
|
}
|
|
|
/**
|
* 更新订单记录数据
|
* @param uid
|
* @param auctionId
|
*/
|
@Override
|
public void updateOrderRecord (HongBao hongBao) throws UserShareGoodsRecordException{
|
|
if (hongBao == null) {
|
throw new UserShareGoodsRecordException(1, "hongBao不能为空");
|
}
|
|
if (hongBao.getUserInfo() == null) {
|
throw new UserShareGoodsRecordException(1, "用户信息不能为空");
|
}
|
|
Long uid = hongBao.getUserInfo().getId();
|
if (uid == null) {
|
throw new UserShareGoodsRecordException(1, "用户ID不能为空");
|
}
|
|
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();
|
|
if (totalOrder == null) {
|
totalOrder = 0;
|
}
|
shareGoodsGroup.setTotalOrder(totalOrder + 1);
|
|
// 更新预计收益
|
BigDecimal totalMoney = newestRecord.getTotalMoney();
|
if (totalMoney == null) {
|
totalMoney = new BigDecimal(0);
|
}
|
BigDecimal resultMoney = MoneyBigDecimalUtil.add(totalMoney, hongBao.getMoney());
|
shareGoodsGroup.setTotalMoney(resultMoney);
|
|
updateByPrimaryKeySelective(shareGoodsGroup);
|
}
|
}
|
|
|
/**
|
* 更新订单记录数据
|
* @param uid
|
* @param auctionId
|
*/
|
@Override
|
public void updateBrowseRecord (Long uid, Long auctionId, int count)
|
throws UserShareGoodsRecordException{
|
|
if (uid == null) {
|
throw new UserShareGoodsRecordException(1, "用户ID不能为空");
|
}
|
|
if (auctionId == null) {
|
throw new UserShareGoodsRecordException(1, "商品Id不能为空");
|
}
|
|
UserShareGoodsGroup group = getNewestRecord(uid, auctionId);
|
|
if (group != null) {
|
UserShareGoodsGroup shareGoodsGroup = new UserShareGoodsGroup(group.getId());
|
// 累计浏览
|
Integer totalBrowse = group.getTotalBrowse();
|
if (totalBrowse == null) {
|
totalBrowse = 0;
|
}
|
shareGoodsGroup.setTotalBrowse(totalBrowse + count);
|
|
// 今日浏览
|
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);
|
|
userShareGoodsGroupMapper.updateByPrimaryKeySelective(shareGoodsGroup);
|
}
|
}
|
}
|