From 66f151530563e1ae82c98815255e338b6dc5f63d Mon Sep 17 00:00:00 2001 From: yuanye <418471657@qq.com> Date: Fri, 27 Sep 2024 16:21:50 +0800 Subject: [PATCH] 1 --- .../cornucopia/CornucopiaController.java | 27 ++++++- .../cornucopia/BsCornucopiaPoolService.java | 15 +++- .../Impl/BsCornucopiaPoolServiceImpl.java | 73 ++++++++++++++++--- .../sysenum/cornucopia/CornucopiaEnum.java | 46 ++++++++++++ 4 files changed, 149 insertions(+), 12 deletions(-) create mode 100644 service/src/main/java/com/hfkj/sysenum/cornucopia/CornucopiaEnum.java diff --git a/cweb/src/main/java/com/hfkj/controller/cornucopia/CornucopiaController.java b/cweb/src/main/java/com/hfkj/controller/cornucopia/CornucopiaController.java index 63afa0e..f5b21c4 100644 --- a/cweb/src/main/java/com/hfkj/controller/cornucopia/CornucopiaController.java +++ b/cweb/src/main/java/com/hfkj/controller/cornucopia/CornucopiaController.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); + } + } } diff --git a/service/src/main/java/com/hfkj/service/cornucopia/BsCornucopiaPoolService.java b/service/src/main/java/com/hfkj/service/cornucopia/BsCornucopiaPoolService.java index 8f68e8f..c827897 100644 --- a/service/src/main/java/com/hfkj/service/cornucopia/BsCornucopiaPoolService.java +++ b/service/src/main/java/com/hfkj/service/cornucopia/BsCornucopiaPoolService.java @@ -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 diff --git a/service/src/main/java/com/hfkj/service/cornucopia/Impl/BsCornucopiaPoolServiceImpl.java b/service/src/main/java/com/hfkj/service/cornucopia/Impl/BsCornucopiaPoolServiceImpl.java index 6b5e414..562dfba 100644 --- a/service/src/main/java/com/hfkj/service/cornucopia/Impl/BsCornucopiaPoolServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/cornucopia/Impl/BsCornucopiaPoolServiceImpl.java @@ -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 list = bsCornucopiaPoolMapper.selectByExample(example); + + if (!list.isEmpty()) { + return list.get(0); + } + + return null; + } + @Override public List queryAllList(Map 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 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); } } diff --git a/service/src/main/java/com/hfkj/sysenum/cornucopia/CornucopiaEnum.java b/service/src/main/java/com/hfkj/sysenum/cornucopia/CornucopiaEnum.java new file mode 100644 index 0000000..c381dbb --- /dev/null +++ b/service/src/main/java/com/hfkj/sysenum/cornucopia/CornucopiaEnum.java @@ -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; + } +}