|
|
|
@ -9,7 +9,10 @@ import com.hfkj.dao.BsCornucopiaPoolRecordMapper; |
|
|
|
|
import com.hfkj.entity.*; |
|
|
|
|
import com.hfkj.service.cornucopia.BsCornucopiaPoolService; |
|
|
|
|
import com.hfkj.service.user.BsUserAccountService; |
|
|
|
|
import com.hfkj.sysenum.cornucopia.CornucopiaEnum; |
|
|
|
|
import com.hfkj.sysenum.user.UserAccountRecordSourceTypeEnum; |
|
|
|
|
import com.hfkj.sysenum.user.UserAccountRecordTypeEnum; |
|
|
|
|
import com.hfkj.sysenum.user.UserGradeEnum; |
|
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
@ -18,10 +21,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
|
@Service("bsCornucopiaPoolService") |
|
|
|
@ -42,8 +42,12 @@ public class BsCornucopiaPoolServiceImpl implements BsCornucopiaPoolService { |
|
|
|
|
private final String LOCK_KEY = "POOL_TRADE_LOCK_"; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void create(BsCornucopiaPool cornucopiaPool) { |
|
|
|
|
bsCornucopiaPoolMapper.insert(cornucopiaPool); |
|
|
|
|
public void edit(BsCornucopiaPool cornucopiaPool) { |
|
|
|
|
if (cornucopiaPool.getId() == null) { |
|
|
|
|
bsCornucopiaPoolMapper.insert(cornucopiaPool); |
|
|
|
|
} else { |
|
|
|
|
bsCornucopiaPoolMapper.updateByPrimaryKeySelective(cornucopiaPool); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -68,6 +72,21 @@ public class BsCornucopiaPoolServiceImpl implements BsCornucopiaPoolService { |
|
|
|
|
return bsCornucopiaPoolMapper.selectByPrimaryKey(id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public BsCornucopiaPool queryDetail(Long userId, Integer type) { |
|
|
|
|
BsCornucopiaPoolExample example = new BsCornucopiaPoolExample(); |
|
|
|
|
BsCornucopiaPoolExample.Criteria criteria = example.createCriteria(); |
|
|
|
|
criteria.andUserIdEqualTo(userId).andTypeEqualTo(type); |
|
|
|
|
|
|
|
|
|
List<BsCornucopiaPool> list = bsCornucopiaPoolMapper.selectByExample(example); |
|
|
|
|
|
|
|
|
|
if (!list.isEmpty()) { |
|
|
|
|
return list.get(0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<BsCornucopiaPool> queryAllList(Map<String, Object> map) { |
|
|
|
|
|
|
|
|
@ -93,7 +112,7 @@ public class BsCornucopiaPoolServiceImpl implements BsCornucopiaPoolService { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional(propagation= Propagation.REQUIRED,rollbackFor= {RuntimeException.class}) |
|
|
|
|
public void investmentCornucopia(Integer type, Long userId, BigDecimal goldCoin) throws Exception { |
|
|
|
|
public void investmentCornucopia(Integer type, Long userId, String userName , BigDecimal goldCoin) throws Exception { |
|
|
|
|
// 锁编号
|
|
|
|
|
String lockKey = LOCK_KEY+userId; |
|
|
|
|
// 获取锁
|
|
|
|
@ -110,8 +129,44 @@ public class BsCornucopiaPoolServiceImpl implements BsCornucopiaPoolService { |
|
|
|
|
|
|
|
|
|
// 判断是否充足
|
|
|
|
|
if (isMeet) { |
|
|
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "元宝还差那么一点点哦!"); |
|
|
|
|
} |
|
|
|
|
// 插入投入记录
|
|
|
|
|
BsCornucopiaPoolRecord record = new BsCornucopiaPoolRecord(); |
|
|
|
|
record.setUserId(userId); |
|
|
|
|
record.setType(type); |
|
|
|
|
record.setGoldCoin(goldCoin); |
|
|
|
|
record.setStatus(1); |
|
|
|
|
record.setCreateTime(new Date()); |
|
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
|
record.setUserName(userName); |
|
|
|
|
create(record); |
|
|
|
|
|
|
|
|
|
// 查询是否第一次投入
|
|
|
|
|
BsCornucopiaPool cornucopiaPool = queryDetail(userId , type); |
|
|
|
|
|
|
|
|
|
// 判断是否存在
|
|
|
|
|
if (cornucopiaPool != null) { |
|
|
|
|
cornucopiaPool.setGoldCoin(cornucopiaPool.getGoldCoin().add(goldCoin)); |
|
|
|
|
} else { |
|
|
|
|
// 插入用户投入金额
|
|
|
|
|
cornucopiaPool = new BsCornucopiaPool(); |
|
|
|
|
cornucopiaPool.setUserId(userId); |
|
|
|
|
cornucopiaPool.setType(type); |
|
|
|
|
cornucopiaPool.setGoldCoin(goldCoin); |
|
|
|
|
cornucopiaPool.setStatus(1); |
|
|
|
|
cornucopiaPool.setCreateTime(new Date()); |
|
|
|
|
cornucopiaPool.setUpdateTime(new Date()); |
|
|
|
|
cornucopiaPool.setUserName(userName); |
|
|
|
|
} |
|
|
|
|
edit(cornucopiaPool); |
|
|
|
|
// 扣除记录
|
|
|
|
|
Map<String, Object> userRechargeParam = new HashMap<>(); |
|
|
|
|
userRechargeParam.put("sourceId", record.getId()); |
|
|
|
|
userRechargeParam.put("sourceOrderNo", ""); |
|
|
|
|
userRechargeParam.put("sourceContent", userName + "投入" + CornucopiaEnum.getDataByType(type).getName() + goldCoin); |
|
|
|
|
// 用户账户扣账
|
|
|
|
|
userAccountService.consume(userId,goldCoin, UserAccountRecordSourceTypeEnum.type3, userRechargeParam); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (BaseException e) { |
|
|
|
@ -125,7 +180,7 @@ public class BsCornucopiaPoolServiceImpl implements BsCornucopiaPoolService { |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
Thread.sleep(100); |
|
|
|
|
investmentCornucopia(type , userId ,goldCoin); |
|
|
|
|
investmentCornucopia(type , userId , userName ,goldCoin); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|