|  | @@ -4,8 +4,10 @@ import com.ym.mec.auth.api.client.SysUserFeignService;
 | 
	
		
			
				|  |  |  import com.ym.mec.auth.api.entity.SysUser;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.SysUserCashAccountDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.SysUserCashAccountDetailDao;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dao.SysUserCoursesAccountDetailDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.SysUserCashAccount;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.entity.SysUserCoursesAccountDetail;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.DealStatusEnum;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.MessageTypeEnum;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.PlatformCashAccountDetailTypeEnum;
 | 
	
	
		
			
				|  | @@ -18,6 +20,7 @@ import com.ym.mec.common.service.impl.BaseServiceImpl;
 | 
	
		
			
				|  |  |  import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | +import org.springframework.transaction.annotation.Isolation;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Propagation;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -38,6 +41,8 @@ public class SysUserCashAccountServiceImpl extends BaseServiceImpl<Integer, SysU
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@Autowired
 | 
	
		
			
				|  |  |  	private SysUserCashAccountDetailDao sysUserCashAccountDetailDao;
 | 
	
		
			
				|  |  | +	@Autowired
 | 
	
		
			
				|  |  | +	private SysUserCoursesAccountDetailDao sysUserCoursesAccountDetailDao;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@Override
 | 
	
		
			
				|  |  |  	public BaseDAO<Integer, SysUserCashAccount> getDAO() {
 | 
	
	
		
			
				|  | @@ -119,7 +124,8 @@ public class SysUserCashAccountServiceImpl extends BaseServiceImpl<Integer, SysU
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@Override
 | 
	
		
			
				|  |  | -	public boolean updateCourseBalance(Integer userId, BigDecimal decimal) {
 | 
	
		
			
				|  |  | +	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
 | 
	
		
			
				|  |  | +	public boolean updateCourseBalance(Integer userId, BigDecimal decimal, BigDecimal amount, String description) {
 | 
	
		
			
				|  |  |  		SysUserCashAccount cashAccount = sysUserCashAccountDao.getLocked(userId);
 | 
	
		
			
				|  |  |  		if (cashAccount == null) {
 | 
	
		
			
				|  |  |  			throw new BizException("用户[{}]现金账户不存在", userId);
 | 
	
	
		
			
				|  | @@ -130,11 +136,23 @@ public class SysUserCashAccountServiceImpl extends BaseServiceImpl<Integer, SysU
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		sysUserCashAccountDao.update(cashAccount);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +		if(amount.compareTo(BigDecimal.ZERO)!=0){
 | 
	
		
			
				|  |  | +			SysUser sysUser = sysUserFeignService.queryUserById(userId);
 | 
	
		
			
				|  |  | +			SysUserCoursesAccountDetail sysUserCoursesAccountDetail=new SysUserCoursesAccountDetail();
 | 
	
		
			
				|  |  | +			sysUserCoursesAccountDetail.setUserId(userId);
 | 
	
		
			
				|  |  | +			sysUserCoursesAccountDetail.setAmount(amount);
 | 
	
		
			
				|  |  | +			sysUserCoursesAccountDetail.setBalance(decimal);
 | 
	
		
			
				|  |  | +			sysUserCoursesAccountDetail.setDescription(description+"-"+sysUser.getId());
 | 
	
		
			
				|  |  | +			sysUserCoursesAccountDetail.setStatus(DealStatusEnum.SUCCESS);
 | 
	
		
			
				|  |  | +			sysUserCoursesAccountDetailDao.insert(sysUserCoursesAccountDetail);
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  		return true;
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@Override
 | 
	
		
			
				|  |  | -	public boolean appendCourseBalance(Integer userId, BigDecimal decimal) {
 | 
	
		
			
				|  |  | +	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
 | 
	
		
			
				|  |  | +	public boolean appendCourseBalance(Integer userId, BigDecimal decimal, String description) {
 | 
	
		
			
				|  |  |  		SysUserCashAccount cashAccount = sysUserCashAccountDao.getLocked(userId);
 | 
	
		
			
				|  |  |  		if (cashAccount == null) {
 | 
	
		
			
				|  |  |  			throw new BizException("用户[{}]现金账户不存在", userId);
 | 
	
	
		
			
				|  | @@ -151,6 +169,17 @@ public class SysUserCashAccountServiceImpl extends BaseServiceImpl<Integer, SysU
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		sysUserCashAccountDao.update(cashAccount);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +		if(decimal.compareTo(BigDecimal.ZERO)!=0){
 | 
	
		
			
				|  |  | +			SysUser sysUser = sysUserFeignService.queryUserById(userId);
 | 
	
		
			
				|  |  | +			SysUserCoursesAccountDetail sysUserCoursesAccountDetail=new SysUserCoursesAccountDetail();
 | 
	
		
			
				|  |  | +			sysUserCoursesAccountDetail.setUserId(userId);
 | 
	
		
			
				|  |  | +			sysUserCoursesAccountDetail.setAmount(decimal);
 | 
	
		
			
				|  |  | +			sysUserCoursesAccountDetail.setBalance(balance);
 | 
	
		
			
				|  |  | +			sysUserCoursesAccountDetail.setDescription(description+"-"+sysUser.getId());
 | 
	
		
			
				|  |  | +			sysUserCoursesAccountDetail.setStatus(DealStatusEnum.SUCCESS);
 | 
	
		
			
				|  |  | +			sysUserCoursesAccountDetailDao.insert(sysUserCoursesAccountDetail);
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  		return true;
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -185,6 +214,17 @@ public class SysUserCashAccountServiceImpl extends BaseServiceImpl<Integer, SysU
 | 
	
		
			
				|  |  |  		cashAccount.setUpdateTime(date);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		sysUserCashAccountDao.update(cashAccount);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		if(cashAccount.getCourseBalance().compareTo(BigDecimal.ZERO)!=0){
 | 
	
		
			
				|  |  | +			SysUserCoursesAccountDetail sysUserCoursesAccountDetail=new SysUserCoursesAccountDetail();
 | 
	
		
			
				|  |  | +			sysUserCoursesAccountDetail.setUserId(userId);
 | 
	
		
			
				|  |  | +			sysUserCoursesAccountDetail.setAmount(cashAccount.getCourseBalance());
 | 
	
		
			
				|  |  | +			sysUserCoursesAccountDetail.setBalance(new BigDecimal(0));
 | 
	
		
			
				|  |  | +			sysUserCoursesAccountDetail.setDescription("课程余额转账");
 | 
	
		
			
				|  |  | +			sysUserCoursesAccountDetail.setStatus(DealStatusEnum.SUCCESS);
 | 
	
		
			
				|  |  | +			sysUserCoursesAccountDetailDao.insert(sysUserCoursesAccountDetail);
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  		return true;
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 |