|  | @@ -1,34 +1,38 @@
 | 
	
		
			
				|  |  |  package com.ym.mec.biz.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import com.google.common.collect.Lists;
 | 
	
		
			
				|  |  | -import com.ym.mec.auth.api.client.SysUserFeignService;
 | 
	
		
			
				|  |  | -import com.ym.mec.auth.api.entity.SysUser;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dao.StudentWithdrawDao;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dao.SysUserCashAccountDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dto.CashAccountDetail;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dto.WithdrawDto;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dto.WithdrawInfoDto;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.entity.StudentWithdraw;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.SysUserCashAccount;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.PlatformCashAccountDetailTypeEnum;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.enums.PlatformCashAccountStatusEnum;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.enums.TransTypeEnum;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.service.StudentWithdrawService;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.service.SysUserCashAccountDetailService;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.service.SysUserCashAccountService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.enums.TransTypeEnum;
 | 
	
		
			
				|  |  | +import com.ym.mec.common.dal.BaseDAO;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.exception.BizException;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.page.PageInfo;
 | 
	
		
			
				|  |  | +import com.ym.mec.common.service.impl.BaseServiceImpl;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.date.DateUtil;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.string.IdWorker;
 | 
	
		
			
				|  |  | +import org.apache.commons.lang3.RandomStringUtils;
 | 
	
		
			
				|  |  |  import org.slf4j.Logger;
 | 
	
		
			
				|  |  |  import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  |  import org.springframework.beans.BeanUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.StudentWithdrawDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.StudentWithdraw;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.StudentWithdrawService;
 | 
	
		
			
				|  |  | -import com.ym.mec.common.dal.BaseDAO;
 | 
	
		
			
				|  |  | -import com.ym.mec.common.service.impl.BaseServiceImpl;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  import java.math.BigDecimal;
 | 
	
		
			
				|  |  | -import java.util.*;
 | 
	
		
			
				|  |  | +import java.util.Date;
 | 
	
		
			
				|  |  | +import java.util.List;
 | 
	
		
			
				|  |  | +import java.util.Objects;
 | 
	
		
			
				|  |  |  import java.util.concurrent.locks.Lock;
 | 
	
		
			
				|  |  |  import java.util.concurrent.locks.ReentrantLock;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -37,6 +41,8 @@ public class StudentWithdrawServiceImpl extends BaseServiceImpl<String, StudentW
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@Autowired
 | 
	
		
			
				|  |  |  	private StudentWithdrawDao studentWithdrawDao;
 | 
	
		
			
				|  |  | +	@Autowired
 | 
	
		
			
				|  |  | +	private SysUserCashAccountDao sysUserCashAccountDao;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@Override
 | 
	
		
			
				|  |  |  	public BaseDAO<String, StudentWithdraw> getDAO() {
 | 
	
	
		
			
				|  | @@ -97,7 +103,7 @@ public class StudentWithdrawServiceImpl extends BaseServiceImpl<String, StudentW
 | 
	
		
			
				|  |  |  		accountDetailPageInfo.getRows().forEach(data ->{
 | 
	
		
			
				|  |  |  			WithdrawInfoDto withdrawInfoDto = new WithdrawInfoDto();
 | 
	
		
			
				|  |  |  			StudentWithdraw studentWithdraw = studentWithdrawDao.getByUserId(data.getUserId().longValue());
 | 
	
		
			
				|  |  | -			withdrawInfoDto.setWithdrawId(studentWithdraw.getId());
 | 
	
		
			
				|  |  | +			withdrawInfoDto.setWithdrawId(studentWithdraw.getWithdrawNo());
 | 
	
		
			
				|  |  |  			withdrawInfoDto.setDateTime(DateUtil.date2ChineseDate(studentWithdraw.getCreateTime()));
 | 
	
		
			
				|  |  |  			withdrawInfoDto.setAmount(data.getAmount());
 | 
	
		
			
				|  |  |  			withdrawInfoDto.setBalance(data.getBalance());
 | 
	
	
		
			
				|  | @@ -112,6 +118,38 @@ public class StudentWithdrawServiceImpl extends BaseServiceImpl<String, StudentW
 | 
	
		
			
				|  |  |  		return result;
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +	@Override
 | 
	
		
			
				|  |  | +	@Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | +	public void add(StudentWithdraw withdraw) throws Exception {
 | 
	
		
			
				|  |  | +		SysUserCashAccount account = sysUserCashAccountDao.get(withdraw.getUserId());
 | 
	
		
			
				|  |  | +		//账户状态正常
 | 
	
		
			
				|  |  | +		if(account != null && account.getStatus() == PlatformCashAccountStatusEnum.NORMAL){
 | 
	
		
			
				|  |  | +			//提现金额不大于账户可用余额
 | 
	
		
			
				|  |  | +			if(withdraw.getAmount().compareTo(account.getBalance()) < 1){
 | 
	
		
			
				|  |  | +				//修改账户余额
 | 
	
		
			
				|  |  | +				BigDecimal subtract = account.getBalance().subtract(withdraw.getAmount());
 | 
	
		
			
				|  |  | +				account.setBalance(subtract);
 | 
	
		
			
				|  |  | +				account.setFrozenAmount(account.getFrozenAmount().add(withdraw.getAmount()));
 | 
	
		
			
				|  |  | +				Date date = new Date();
 | 
	
		
			
				|  |  | +				account.setUpdateTime(date);
 | 
	
		
			
				|  |  | +				sysUserCashAccountDao.update(account);
 | 
	
		
			
				|  |  | +				SysUserCashAccountDetail cashAccountDetail = new SysUserCashAccountDetail();
 | 
	
		
			
				|  |  | +				cashAccountDetail.setUserId(account.getUserId());
 | 
	
		
			
				|  |  | +				cashAccountDetail.setType(PlatformCashAccountDetailTypeEnum.WITHDRAW);
 | 
	
		
			
				|  |  | +				cashAccountDetail.setAmount(withdraw.getAmount());
 | 
	
		
			
				|  |  | +				cashAccountDetail.setBalance(subtract);
 | 
	
		
			
				|  |  | +				cashAccountDetail.setCreateTime(date);
 | 
	
		
			
				|  |  | +				cashAccountDetailService.insert(cashAccountDetail);
 | 
	
		
			
				|  |  | +				withdraw.setWithdrawNo(RandomStringUtils.random(8));
 | 
	
		
			
				|  |  | +				studentWithdrawDao.insert(withdraw);
 | 
	
		
			
				|  |  | +			}else {
 | 
	
		
			
				|  |  | +				throw new Exception("账户余额不足");
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +		}else {
 | 
	
		
			
				|  |  | +			throw new Exception("账户状态异常");
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	/**
 | 
	
		
			
				|  |  |  	 * 修改用户账户余额,保存账户明细
 | 
	
		
			
				|  |  |  	 *
 | 
	
	
		
			
				|  | @@ -141,8 +179,8 @@ public class StudentWithdrawServiceImpl extends BaseServiceImpl<String, StudentW
 | 
	
		
			
				|  |  |  	private void saveStudentWithdraw(WithdrawDto withdrawDto) {
 | 
	
		
			
				|  |  |  		IdWorker idWorker = new IdWorker(0, 0);
 | 
	
		
			
				|  |  |  		StudentWithdraw studentWithdraw = new StudentWithdraw();
 | 
	
		
			
				|  |  | -		studentWithdraw.setId(idWorker.nextId());
 | 
	
		
			
				|  |  | -		studentWithdraw.setUserId(withdrawDto.getUserId().longValue());
 | 
	
		
			
				|  |  | +		studentWithdraw.setWithdrawNo(idWorker.nextId());
 | 
	
		
			
				|  |  | +		studentWithdraw.setUserId(withdrawDto.getUserId());
 | 
	
		
			
				|  |  |  		studentWithdraw.setBankCardNo(withdrawDto.getBankCardNo());
 | 
	
		
			
				|  |  |  		studentWithdraw.setAmount(withdrawDto.getAmount());
 | 
	
		
			
				|  |  |  		studentWithdraw.setCreateTime(new Date());
 |