/** * 添加收藏信息 * * @param memberFavorite用户收藏对象 */ @Override @Transactional( readOnly = false, rollbackFor = Exception.class, propagation = Propagation.REQUIRED) public void create(Merchant merchant, User user) throws BusinessException { // 判断该收藏对象是否已经存在 UserFavMerchant userFavMerchant = get(merchant, user); if (userFavMerchant != null) { return; } userFavMerchant = new UserFavMerchant(); userFavMerchant.setMerchant(merchant); userFavMerchant.setUser(user); userFavMerchant.setCreateDate(new Date()); MerchantReferenceStatistic mrs = merchant.getMerchantReferenceStatistic(); mrs.setFavCount(mrs.getFavCount() + 1); merchantStatisticDao.saveOrUpdate(mrs); userFavMerchantDao.save(userFavMerchant); }
/** * 用户删除收藏信息 * * @param memberFavorite 用户收藏对象 */ @Override @Transactional( readOnly = false, rollbackFor = Exception.class, propagation = Propagation.REQUIRED) public void delete(UserFavMerchant userFavMerchant) { if (userFavMerchant == null) { return; } Merchant merchant = userFavMerchant.getMerchant(); MerchantReferenceStatistic mrs = merchant.getMerchantReferenceStatistic(); mrs.setFavCount(mrs.getFavCount() - 1); merchantStatisticDao.saveOrUpdate(mrs); userFavMerchantDao.delete(userFavMerchant); }