袁野 1 month ago
parent 8820c9a7ed
commit 66f1515305
  1. 27
      cweb/src/main/java/com/hfkj/controller/cornucopia/CornucopiaController.java
  2. 15
      service/src/main/java/com/hfkj/service/cornucopia/BsCornucopiaPoolService.java
  3. 71
      service/src/main/java/com/hfkj/service/cornucopia/Impl/BsCornucopiaPoolServiceImpl.java
  4. 46
      service/src/main/java/com/hfkj/sysenum/cornucopia/CornucopiaEnum.java

@ -76,7 +76,7 @@ public class CornucopiaController {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
cornucopiaPoolService.investmentCornucopia(body.getInteger("type") , userModel.getAccount().getId() , body.getBigDecimal("goldCoin"));
cornucopiaPoolService.investmentCornucopia(body.getInteger("type") , userModel.getAccount().getId() , userModel.getAccount().getUserName() , body.getBigDecimal("goldCoin"));
return ResponseMsgUtil.success("投入成功");
@ -86,6 +86,31 @@ public class CornucopiaController {
}
}
@RequestMapping(value="/recoveryGoldCoin",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "回收元宝")
public ResponseData recoveryCornucopia(@RequestBody JSONObject body, HttpServletRequest request) {
try {
SessionObject sessionObject = userCenter.getSessionObject(request);
SecUserSessionObject userModel = (SecUserSessionObject) sessionObject.getObject();
if (body == null||
body.getInteger("type") == null ||
body.getBigDecimal("goldCoin") == null
) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
cornucopiaPoolService.investmentCornucopia(body.getInteger("type") , userModel.getAccount().getId() , userModel.getAccount().getUserName() , body.getBigDecimal("goldCoin"));
return ResponseMsgUtil.success("投入成功");
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
}

@ -17,7 +17,7 @@ public interface BsCornucopiaPoolService {
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
void create(BsCornucopiaPool cornucopiaPool);
void edit(BsCornucopiaPool cornucopiaPool);
/**
* @MethodName update
@ -48,6 +48,17 @@ public interface BsCornucopiaPoolService {
*/
BsCornucopiaPool queryDetail(Long id);
/**
* @MethodName queryDetail
* @Description:
* @param userId
* @param type
* @return: com.hfkj.entity.BsCornucopiaPool
* @Author: Sum1Dream
* @Date: 2024/9/27 下午4:02
*/
BsCornucopiaPool queryDetail(Long userId , Integer type);
/**
* @MethodName queryAllList
* @Description: map
@ -67,7 +78,7 @@ public interface BsCornucopiaPoolService {
* @Author: Sum1Dream
* @Date: 2024/9/27 下午2:50
*/
void investmentCornucopia(Integer type , Long userId , BigDecimal goldCoin) throws Exception;
void investmentCornucopia(Integer type , Long userId , String userName , BigDecimal goldCoin) throws Exception;
/**
* @MethodName create

@ -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) {
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);
}
}

@ -0,0 +1,46 @@
package com.hfkj.sysenum.cornucopia;
import com.hfkj.sysenum.user.UserGradeEnum;
import lombok.Getter;
import java.util.Objects;
/**
* @className: UserStatusEnum
* @author: HuRui
* @date: 2024/5/6
**/
@Getter
public enum CornucopiaEnum {
/**
* 删除
*/
type1(1, "金聚宝盆"),
/**
* 正常
*/
type2(2, "玉聚宝盆");
private int code;
private String name;
CornucopiaEnum(int code, String name) {
this.code = code;
this.name = name;
}
/**
* 查询数据
* @param code
* @return
*/
public static CornucopiaEnum getDataByType(Integer code) {
for (CornucopiaEnum ele : values()) {
if (Objects.equals(code,ele.getCode())) return ele;
}
return null;
}
}
Loading…
Cancel
Save