| | |
| | | package com.yeshi.fanli.service.impl.money;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.money.UserMoneyDetailMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.share.ShareMapper;
|
| | | import com.yeshi.fanli.dto.money.UserMoneyChangeDTO;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.money.UserMoneyDetail;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.money.UserMoneyService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.cmq.UserMoneyChangeCMQManager;
|
| | |
|
| | | @Service
|
| | | public class UserMoneyServiceImpl implements UserMoneyService {
|
| | |
|
| | | @Resource
|
| | | private ShareMapper shareMapper;
|
| | |
|
| | | @Resource
|
| | | private UserInfoMapper userInfoMapper;
|
| | |
|
| | | @Resource
|
| | | private UserMoneyDetailMapper userMoneyDetailMapper;
|
| | |
|
| | | @Override
|
| | | public BigDecimal getMoneyToday(Long uid) {
|
| | | BigDecimal money = shareMapper.getMoneyToday(uid + "");
|
| | | return money == null ? new BigDecimal(0) : money;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public BigDecimal getMoneyMonth(Long uid) {
|
| | | BigDecimal money = shareMapper.getMoneyMonth(uid + "");
|
| | | return money == null ? new BigDecimal(0) : money;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public BigDecimal getMoneyLastMonth(Long uid) {
|
| | | BigDecimal money = shareMapper.getMoneyLastMonth(uid + "");
|
| | |
|
| | | return money == null ? new BigDecimal(0) : money;
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void subUserMoney(Long uid, BigDecimal money, UserMoneyDetail detail) {
|
| | | userMoneyDetailMapper.insertSelective(detail);
|
| | | userInfoMapper.subHongBaoByUid(uid, money);
|
| | | try {
|
| | | if (!Constant.IS_TEST)
|
| | | UserMoneyChangeCMQManager.getInstance()
|
| | | .addUserMoneyChangeMsg(new UserMoneyChangeDTO(uid, new BigDecimal(0).subtract(money)));
|
| | | } catch (Exception e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void addUserMoney(Long uid, BigDecimal money, UserMoneyDetail detail) {
|
| | | userMoneyDetailMapper.insertSelective(detail);
|
| | | userInfoMapper.addHongBaoByUid(uid, money);
|
| | | try {
|
| | | if (!Constant.IS_TEST)
|
| | | UserMoneyChangeCMQManager.getInstance().addUserMoneyChangeMsg(new UserMoneyChangeDTO(uid, money));
|
| | | } catch (Exception e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | public BigDecimal getBalance(Long uid) {
|
| | | UserInfo userInfo = userInfoMapper.selectByPrimaryKey(uid);
|
| | | if (userInfo == null)
|
| | | return null;
|
| | | return userInfo.getMyHongBao();
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.money; |
| | | |
| | | import com.aliyun.openservices.ons.api.Message; |
| | | import com.yeshi.fanli.dao.mybatis.UserInfoMapper; |
| | | import com.yeshi.fanli.dao.mybatis.money.UserMoneyDetailMapper; |
| | | import com.yeshi.fanli.dao.mybatis.share.ShareMapper; |
| | | import com.yeshi.fanli.dto.money.UserMoneyChangeDTO; |
| | | import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum; |
| | | import com.yeshi.fanli.dto.mq.user.body.UserMoneyChangeMQMsg; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfo; |
| | | import com.yeshi.fanli.entity.money.UserMoneyDetail; |
| | | import com.yeshi.fanli.log.LogHelper; |
| | | import com.yeshi.fanli.service.inter.money.UserMoneyService; |
| | | import com.yeshi.fanli.service.manger.msg.RocketMQManager; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.mq.cmq.UserMoneyChangeCMQManager; |
| | | import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory; |
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | |
| | | @Service |
| | | public class UserMoneyServiceImpl implements UserMoneyService { |
| | | |
| | | @Resource |
| | | private ShareMapper shareMapper; |
| | | |
| | | @Resource |
| | | private UserInfoMapper userInfoMapper; |
| | | |
| | | @Resource |
| | | private UserMoneyDetailMapper userMoneyDetailMapper; |
| | | |
| | | @Resource |
| | | private RocketMQManager rocketMQManager; |
| | | |
| | | @Resource |
| | | private UserMoneyChangeCMQManager userMoneyChangeCMQManager; |
| | | |
| | | @Override |
| | | public BigDecimal getMoneyToday(Long uid) { |
| | | BigDecimal money = shareMapper.getMoneyToday(uid + ""); |
| | | return money == null ? new BigDecimal(0) : money; |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal getMoneyMonth(Long uid) { |
| | | BigDecimal money = shareMapper.getMoneyMonth(uid + ""); |
| | | return money == null ? new BigDecimal(0) : money; |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal getMoneyLastMonth(Long uid) { |
| | | BigDecimal money = shareMapper.getMoneyLastMonth(uid + ""); |
| | | |
| | | return money == null ? new BigDecimal(0) : money; |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public void subUserMoney(Long uid, BigDecimal money, UserMoneyDetail detail) { |
| | | userMoneyDetailMapper.insertSelective(detail); |
| | | userInfoMapper.subHongBaoByUid(uid, money); |
| | | try { |
| | | if (!Constant.IS_TEST) |
| | | userMoneyChangeCMQManager |
| | | .addUserMoneyChangeMsg(new UserMoneyChangeDTO(uid, new BigDecimal(0).subtract(money))); |
| | | } catch (Exception e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public void addUserMoney(Long uid, BigDecimal money, UserMoneyDetail detail) { |
| | | userMoneyDetailMapper.insertSelective(detail); |
| | | userInfoMapper.addHongBaoByUid(uid, money); |
| | | try { |
| | | if (!Constant.IS_TEST) |
| | | userMoneyChangeCMQManager.addUserMoneyChangeMsg(new UserMoneyChangeDTO(uid, money)); |
| | | } catch (Exception e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | // 发送资金到账消息 |
| | | |
| | | if (!Constant.IS_TEST) { |
| | | UserMoneyChangeMQMsg msg = new UserMoneyChangeMQMsg(uid, money, new Date()); |
| | | Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userMoneyAdd, msg); |
| | | rocketMQManager.sendNormalMsg(message, null); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal getBalance(Long uid) { |
| | | UserInfo userInfo = userInfoMapper.selectByPrimaryKey(uid); |
| | | if (userInfo == null) |
| | | return null; |
| | | return userInfo.getMyHongBao(); |
| | | } |
| | | |
| | | } |