Compare commits

...

2 Commits

  1. 1
      bweb/src/main/java/com/hfkj/config/AuthConfig.java
  2. 9
      bweb/src/main/java/com/hfkj/controller/cornucopia/CornucopiaController.java
  3. 185
      bweb/src/main/java/com/hfkj/controller/partner/BsPartnerLevelController.java
  4. 81
      bweb/src/main/java/com/hfkj/controller/partner/PartnerController.java
  5. 206
      cweb/src/main/java/com/hfkj/controller/partner/PartnerController.java
  6. 14
      service/src/main/java/com/hfkj/common/utils/PartnerNumUtil.java
  7. 8
      service/src/main/java/com/hfkj/service/cornucopia/Impl/BsCornucopiaLotteryRecordServiceImpl.java
  8. 67
      service/src/main/java/com/hfkj/service/partner/BsPartnerLevelService.java
  9. 68
      service/src/main/java/com/hfkj/service/partner/BsPartnerPoolPreService.java
  10. 78
      service/src/main/java/com/hfkj/service/partner/BsPartnerPoolRecordService.java
  11. 57
      service/src/main/java/com/hfkj/service/partner/BsPartnerPoolService.java
  12. 68
      service/src/main/java/com/hfkj/service/partner/BsPartnerUserRecordService.java
  13. 81
      service/src/main/java/com/hfkj/service/partner/Impl/BsPartnerLevelServiceImpl.java
  14. 116
      service/src/main/java/com/hfkj/service/partner/Impl/BsPartnerPoolPreServiceImpl.java
  15. 87
      service/src/main/java/com/hfkj/service/partner/Impl/BsPartnerPoolRecordServiceImpl.java
  16. 80
      service/src/main/java/com/hfkj/service/partner/Impl/BsPartnerPoolServiceImpl.java
  17. 101
      service/src/main/java/com/hfkj/service/partner/Impl/BsPartnerUserRecordServiceImpl.java
  18. 492
      service/src/main/java/com/hfkj/service/partner/Impl/PartnerServiceImpl.java
  19. 57
      service/src/main/java/com/hfkj/service/partner/PartnerService.java
  20. 56
      service/src/main/java/com/hfkj/sysenum/partner/PartnerEnum.java
  21. 4
      service/src/main/java/com/hfkj/sysenum/user/UserAccountRecordSourceTypeEnum.java

@ -89,6 +89,7 @@ public class AuthConfig implements WebMvcConfigurer {
.excludePathPatterns("/common/*")
.excludePathPatterns("/secUser/*")
.excludePathPatterns("/cornucopia/*")
.excludePathPatterns("/partner/*")
;
}

@ -5,15 +5,11 @@ import com.github.pagehelper.PageInfo;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.security.SessionObject;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.controller.order.BsOrderController;
import com.hfkj.entity.BsCornucopiaConfig;
import com.hfkj.entity.BsCornucopiaLotteryRecord;
import com.hfkj.entity.BsCornucopiaPool;
import com.hfkj.model.CornucopiaStatisticsModel;
import com.hfkj.model.ResponseData;
import com.hfkj.model.SecUserSessionObject;
import com.hfkj.service.cornucopia.BsCornucopiaConfigService;
import com.hfkj.service.cornucopia.BsCornucopiaLotteryRecordService;
import com.hfkj.service.cornucopia.BsCornucopiaPoolService;
@ -21,8 +17,6 @@ import com.hfkj.service.cornucopia.BsCornucopiaUserRecordService;
import com.hfkj.sysenum.cornucopia.CornucopiaEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
@ -32,7 +26,6 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@Controller
@RequestMapping(value="/cornucopia")
@ -150,6 +143,7 @@ public class CornucopiaController {
@RequestParam(value = "type" , required = false) Integer type,
@RequestParam(value = "lotteryNo" , required = false) String lotteryNo,
@RequestParam(value = "userName" , required = false) String userName,
@RequestParam(value = "userId" , required = false) Long userId,
@RequestParam(value = "pageNum" , required = true) Integer pageNum,
@RequestParam(value = "pageSize" , required = true) Integer pageSize) {
try {
@ -159,6 +153,7 @@ public class CornucopiaController {
map.put("type", type);
map.put("lotteryNo", lotteryNo);
map.put("userName", userName);
map.put("userId", userId);
PageHelper.startPage(pageNum, pageSize);
return ResponseMsgUtil.success(new PageInfo<>(cornucopiaUserRecordService.queryAllList(map)));

@ -0,0 +1,185 @@
package com.hfkj.controller.partner;
import com.alipay.api.internal.util.StringUtils;
import com.github.pagehelper.PageInfo;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.PartnerNumUtil;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.BsPartnerLevel;
import com.hfkj.entity.BsPartnerPool;
import com.hfkj.model.ResponseData;
import com.hfkj.service.partner.BsPartnerLevelService;
import com.hfkj.service.partner.BsPartnerPoolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@Controller
@RequestMapping(value = "/partner")
@Api(value = "合伙人")
public class BsPartnerLevelController {
private static final Logger log = LoggerFactory.getLogger(BsPartnerLevelController.class);
@Resource
private BsPartnerLevelService bsPartnerLevelService;
@Resource
private BsPartnerPoolService bsPartnerPoolService;
@RequestMapping(value="/queryAllList",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询列表")
public ResponseData queryAllList() {
try {
Map<String , Object> map = new HashMap<>();
return ResponseMsgUtil.success(bsPartnerLevelService.queryAllList(map));
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/test",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "测试")
public ResponseData test() {
try {
Map<String , Object> map = new HashMap<>();
List<BsPartnerLevel> list = bsPartnerLevelService.queryAllList(map);
BsPartnerPool partnerPool;
for (BsPartnerLevel bsPartnerLevel : list) {
for (int i = 1; i < bsPartnerLevel.getUserNum() + 1; i++) {
partnerPool = new BsPartnerPool();
partnerPool.setLevel(bsPartnerLevel.getLevel());
partnerPool.setCreateTime(new Date());
partnerPool.setUpdateTime(new Date());
partnerPool.setGoldCoin(new BigDecimal(0));
partnerPool.setNum(StringUtils.leftPad(String.valueOf(i), String.valueOf(bsPartnerLevel.getUserNum()).length(), "0"));
partnerPool.setNumNo(i);
partnerPool.setStatus(1);
bsPartnerPoolService.create(partnerPool);
}
}
return ResponseMsgUtil.success("1");
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/editPartnerLevel",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "编辑合伙人等级")
public ResponseData editPartnerLevel(@RequestBody BsPartnerLevel body) {
try {
if (body == null
|| body.getLevel() == null
|| body.getLevelName() == null
|| body.getIncomePer() == null
|| body.getUserNum() == null
|| body.getDividendsPer() == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
// 查询是否存在当前合伙人等级
BsPartnerLevel partnerLevel = bsPartnerLevelService.queryDetail(body.getLevel());
BsPartnerPool partnerPool;
if (partnerLevel == null) {
partnerLevel = new BsPartnerLevel();
partnerLevel.setStatus(1);
partnerLevel.setCreateTime(new Date());
for (int i = 1; i < partnerLevel.getUserNum() + 1; i++) {
partnerPool = new BsPartnerPool();
partnerPool.setLevel(partnerLevel.getLevel());
partnerPool.setCreateTime(new Date());
partnerPool.setUpdateTime(new Date());
partnerPool.setGoldCoin(new BigDecimal(0));
partnerPool.setNum(StringUtils.leftPad(String.valueOf(i), String.valueOf(partnerLevel.getUserNum()).length(), "0"));
partnerPool.setNumNo(i);
partnerPool.setStatus(1);
bsPartnerPoolService.create(partnerPool);
}
} else {
if (partnerLevel.getUserNum() > body.getUserNum()) {
Map<String , Object> map = new HashMap<>();
map.put("level", partnerLevel.getLevel());
List<BsPartnerPool> list = bsPartnerPoolService.queryAllList(map);
list = list.stream().sorted(Comparator.comparing(BsPartnerPool::getNumNo).reversed()).collect(Collectors.toList());
Integer num = partnerLevel.getUserNum() - body.getUserNum();
for (int i = 0; i < num; i++) {
BsPartnerPool pool = list.get(i);
bsPartnerPoolService.delete(pool.getId() , true);
}
} else {
for (int i = partnerLevel.getUserNum() + 1; i < body.getUserNum() + 1; i++) {
partnerPool = new BsPartnerPool();
partnerPool.setLevel(partnerLevel.getLevel());
partnerPool.setCreateTime(new Date());
partnerPool.setUpdateTime(new Date());
partnerPool.setGoldCoin(new BigDecimal(0));
partnerPool.setNum(StringUtils.leftPad(String.valueOf(i), String.valueOf(partnerLevel.getUserNum()).length(), "0"));
partnerPool.setNumNo(i);
partnerPool.setStatus(1);
bsPartnerPoolService.create(partnerPool);
}
}
}
partnerLevel.setUpdateTime(new Date());
partnerLevel.setLevel(body.getLevel());
partnerLevel.setUserNum(body.getUserNum());
partnerLevel.setLevelName(body.getLevelName());
partnerLevel.setDividendsPer(body.getDividendsPer());
partnerLevel.setIncomePer(body.getIncomePer());
bsPartnerLevelService.edit(partnerLevel);
return ResponseMsgUtil.success(partnerLevel);
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/queryDetailByLevel",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "根据等级类型查询详情")
public ResponseData queryDetailByLevel(
@RequestParam(value = "level" , required = false) Integer level) {
try {
return ResponseMsgUtil.success(bsPartnerLevelService.queryDetail(level));
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
}

@ -0,0 +1,81 @@
package com.hfkj.controller.partner;
import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.security.UserCenter;
import com.hfkj.common.utils.DateUtil;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.BsPartnerLevel;
import com.hfkj.entity.BsPartnerPool;
import com.hfkj.entity.BsPartnerPoolPre;
import com.hfkj.model.ResponseData;
import com.hfkj.model.UserSessionObject;
import com.hfkj.service.partner.BsPartnerLevelService;
import com.hfkj.service.partner.BsPartnerPoolPreService;
import com.hfkj.service.partner.BsPartnerPoolService;
import com.hfkj.service.partner.PartnerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping(value = "/partner")
@Api(value = "合伙人")
public class PartnerController {
private static final Logger log = LoggerFactory.getLogger(PartnerController.class);
@Resource
private UserCenter userCenter;
@Resource
private PartnerService partnerService;
@RequestMapping(value="/partnerData",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "合伙人统计")
public ResponseData partnerData(
@RequestParam(value = "startTime" , required = false) Long startTime,
@RequestParam(value = "endTime" , required = false) Long endTime
) {
try {
return ResponseMsgUtil.success(partnerService.partnerData(startTime , endTime));
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/dividendData",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "分红统计")
public ResponseData dividendData(
@RequestParam(value = "startTime" , required = false) Long startTime,
@RequestParam(value = "endTime" , required = false) Long endTime
) {
try {
return ResponseMsgUtil.success(partnerService.dividendData(startTime , endTime));
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
}

@ -0,0 +1,206 @@
package com.hfkj.controller.partner;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.security.UserCenter;
import com.hfkj.common.utils.DateUtil;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.controller.cornucopia.CornucopiaController;
import com.hfkj.entity.BsPartnerLevel;
import com.hfkj.entity.BsPartnerPool;
import com.hfkj.entity.BsPartnerPoolPre;
import com.hfkj.model.ResponseData;
import com.hfkj.model.UserSessionObject;
import com.hfkj.service.partner.BsPartnerLevelService;
import com.hfkj.service.partner.BsPartnerPoolPreService;
import com.hfkj.service.partner.BsPartnerPoolService;
import com.hfkj.service.partner.PartnerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping(value = "/partner")
@Api(value = "合伙人")
public class PartnerController {
private static final Logger log = LoggerFactory.getLogger(PartnerController.class);
@Resource
private BsPartnerLevelService bsPartnerLevelService;
@Resource
private BsPartnerPoolPreService bsPartnerPoolPreService;
@Resource
private BsPartnerPoolService bsPartnerPoolService;
@Resource
private UserCenter userCenter;
@Resource
private PartnerService partnerService;
@RequestMapping(value="/queryDetailByLevel",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "根据等级类型查询详情")
public ResponseData queryDetailByLevel(
@RequestParam(value = "level" , required = false) Integer level) {
try {
// 用户session
UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class);
if (userSession == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, "");
}
return ResponseMsgUtil.success(bsPartnerLevelService.queryDetail(level));
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/inPartner",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "参与竞选合伙人")
public ResponseData inPartner(@RequestBody JSONObject body) {
try {
// 用户session
UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class);
if (userSession == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, "");
}
if (body == null||
body.getInteger("level") == null ||
body.getBigDecimal("goldCoin") == null
) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
body.put("userId" , userSession.getUser().getId());
body.put("userName" , userSession.getUser().getName());
partnerService.inPartner(body);
return ResponseMsgUtil.success("投入成功");
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/getUserPartner",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询合伙人等级与当期投入总元宝,与用户当前等级")
public ResponseData getUserPartner() {
try {
// 用户session
UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class);
if (userSession == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, "");
}
JSONObject obj = new JSONObject();
// 查询当期用户内容
Map<String , Object> map = new HashMap<>();
map.put("status" , 1);
List<BsPartnerPoolPre> list = bsPartnerPoolPreService.queryAllList(map);
BigDecimal toDayPartner = list.stream().map(BsPartnerPoolPre::getGoldCoin).reduce(BigDecimal.ZERO, BigDecimal::add);
obj.put("toDayPartner" , toDayPartner);
// 查询合伙人等级内容
List<BsPartnerLevel> partnerLevels = bsPartnerLevelService.queryAllList(map);
obj.put("partnerLevels" , partnerLevels);
// 查询用户合伙人等级
BsPartnerPool partnerPool = bsPartnerPoolService.queryDetail(userSession.getUser().getId());
obj.put("partnerPool" , partnerPool);
return ResponseMsgUtil.success(obj);
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/prePartner",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询上一期竞选与竞选排名")
public ResponseData prePartner() {
try {
// 用户session
UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class);
if (userSession == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, "");
}
// 查询上一期
String lotteryNo = DateUtil.date2String(new Date() , DateUtil.YMD);
Integer preLotteryNo = Integer.parseInt(lotteryNo) - 1;
Map<String , Object> map = new HashMap<>();
map.put("status" , 2);
map.put("lotteryNo" , preLotteryNo.toString());
List<BsPartnerPoolPre> list = bsPartnerPoolPreService.queryAllList(map);
JSONObject obj = new JSONObject();
// 插入上一期内容
obj.put("partnerPoolPre" , list);
obj.put("userPoolPre" , list.stream().filter(s->s.getUserId().equals(userSession.getUser().getId())));
return ResponseMsgUtil.success(obj);
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/startCampaign",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "开始竞选")
public ResponseData startCampaign(
@RequestParam(value = "level" , required = false) Integer level) {
try {
partnerService.startCampaign();
System.out.println(new Date());
return ResponseMsgUtil.success(new Date());
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/dividend",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "分红")
public ResponseData dividend() {
try {
partnerService.dividend();
return ResponseMsgUtil.success("");
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
}

@ -0,0 +1,14 @@
package com.hfkj.common.utils;
public class PartnerNumUtil {
public static String numLength(Integer num){
StringBuilder sb = new StringBuilder();
for (int i = 0; i < String.valueOf(num).length() -1; i++) {
sb.append('0');
}
return sb.toString();
}
}

@ -56,11 +56,11 @@ public class BsCornucopiaLotteryRecordServiceImpl implements BsCornucopiaLottery
if (MapUtils.getInteger(map, "type") != null) {
criteria.andTypeEqualTo(MapUtils.getInteger(map, "type"));
}
if (MapUtils.getLong(map, "createTimeS") != null) {
criteria.andCreateTimeGreaterThanOrEqualTo(new Date(MapUtils.getLong(map, "createTimeS")));
if (MapUtils.getLong(map, "startTime") != null) {
criteria.andCreateTimeGreaterThanOrEqualTo(new Date(MapUtils.getLong(map, "startTime")));
}
if (MapUtils.getLong(map, "createTimeE") != null) {
criteria.andCreateTimeLessThan(new Date(MapUtils.getLong(map, "createTimeE")));
if (MapUtils.getLong(map, "endTime") != null) {
criteria.andCreateTimeLessThan(new Date(MapUtils.getLong(map, "endTime")));
}
if (MapUtils.getString(map, "lotteryNo") != null) {
criteria.andLotteryNoLike("%" + MapUtils.getString(map, "lotteryNo") + "%");

@ -0,0 +1,67 @@
package com.hfkj.service.partner;
import com.hfkj.entity.BsPartnerLevel;
import java.util.List;
import java.util.Map;
public interface BsPartnerLevelService {
/**
* @MethodName create
* @Description: 创建
* @param partnerLevel
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
void create(BsPartnerLevel partnerLevel);
/**
* @MethodName update
* @Description: 更新
* @param partnerLevel
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
void edit(BsPartnerLevel partnerLevel);
/**
* @MethodName delete
* @Description: 删除
* @param id
* @param fullDelete
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
void delete(Long id , Boolean fullDelete);
/**
* @MethodName queryDetail
* @Description:查询详情
* @param id
* @return: com.hfkj.entity.BsPartnerLevel
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
BsPartnerLevel queryDetail(Long id);
/**
* @MethodName queryDetail
* @Description:
* @param level
* @return: com.hfkj.entity.BsPartnerLevel
* @Author: Sum1Dream
* @Date: 2024/9/27 下午2:28
*/
BsPartnerLevel queryDetail(Integer level);
/**
* @MethodName queryAllList
* @Description: map
* @param
* @return: java.util.List<com.hfkj.entity.BsPartnerLevel>
* @Author: Sum1Dream
* @Date: 2024/9/27 上午11:42
*/
List<BsPartnerLevel> queryAllList(Map<String , Object> map);
}

@ -0,0 +1,68 @@
package com.hfkj.service.partner;
import com.hfkj.entity.BsPartnerPoolPre;
import java.util.List;
import java.util.Map;
public interface BsPartnerPoolPreService {
/**
* @MethodName create
* @Description: 创建
* @param partnerPoolPre
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
void create(BsPartnerPoolPre partnerPoolPre);
/**
* @MethodName update
* @Description: 更新
* @param partnerPoolPre
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
void edit(BsPartnerPoolPre partnerPoolPre);
/**
* @MethodName delete
* @Description: 删除
* @param id
* @param fullDelete
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
void delete(Long id , Boolean fullDelete);
/**
* @MethodName queryDetail
* @Description:查询详情
* @param userId
* @return: com.hfkj.entity.BsPartnerPoolPre
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
BsPartnerPoolPre queryDetail(Long userId);
/**
* @MethodName queryDetail
* @Description: 查询
* @param map
* @return: com.hfkj.entity.BsPartnerPoolPre
* @Author: Sum1Dream
* @Date: 2024/10/16 上午10:47
*/
BsPartnerPoolPre queryDetail(Map<String,Object> map);
/**
* @MethodName queryAllList
* @Description: map
* @param
* @return: java.util.List<com.hfkj.entity.BsPartnerPoolPre>
* @Author: Sum1Dream
* @Date: 2024/9/27 上午11:42
*/
List<BsPartnerPoolPre> queryAllList(Map<String , Object> map);
}

@ -0,0 +1,78 @@
package com.hfkj.service.partner;
import com.hfkj.entity.BsPartnerPoolRecord;
import java.util.List;
import java.util.Map;
public interface BsPartnerPoolRecordService {
/**
* @MethodName create
* @Description: 创建
* @param partnerPoolRecord
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
void create(BsPartnerPoolRecord partnerPoolRecord);
/**
* @MethodName update
* @Description: 更新
* @param partnerPoolRecord
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
void edit(BsPartnerPoolRecord partnerPoolRecord);
/**
* @MethodName delete
* @Description: 删除
* @param id
* @param fullDelete
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
void delete(Long id , Boolean fullDelete);
/**
* @MethodName queryDetail
* @Description:查询详情
* @param id
* @return: com.hfkj.entity.BsPartnerPoolRecord
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
BsPartnerPoolRecord queryDetail(Long id);
/**
* @MethodName queryDetail
* @Description: 根据期号查询
* @param lotteryNo
* @return: com.hfkj.entity.BsPartnerPoolRecord
* @Author: Sum1Dream
* @Date: 2024/10/17 下午4:09
*/
BsPartnerPoolRecord queryDetail(String lotteryNo);
/**
* @MethodName queryDetail
* @Description:
* @param level
* @return: com.hfkj.entity.BsPartnerPoolRecord
* @Author: Sum1Dream
* @Date: 2024/9/27 下午2:28
*/
BsPartnerPoolRecord queryDetail(Integer level);
/**
* @MethodName queryAllList
* @Description: map
* @param
* @return: java.util.List<com.hfkj.entity.BsPartnerPoolRecord>
* @Author: Sum1Dream
* @Date: 2024/9/27 上午11:42
*/
List<BsPartnerPoolRecord> queryAllList(Map<String , Object> map);
}

@ -0,0 +1,57 @@
package com.hfkj.service.partner;
import com.hfkj.entity.BsPartnerPool;
import java.util.List;
import java.util.Map;
public interface BsPartnerPoolService {
/**
* @MethodName create
* @Description: 创建
* @param partnerPool
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
void create(BsPartnerPool partnerPool);
/**
* @MethodName update
* @Description: 更新
* @param partnerPool
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
void edit(BsPartnerPool partnerPool);
/**
* @MethodName delete
* @Description: 删除
* @param id
* @param fullDelete
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
void delete(Long id , Boolean fullDelete);
/**
* @MethodName queryDetail
* @Description:查询详情
* @param userId
* @return: com.hfkj.entity.BsPartnerPool
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
BsPartnerPool queryDetail(Long userId);
/**
* @MethodName queryAllList
* @Description: map
* @param
* @return: java.util.List<com.hfkj.entity.BsPartnerPool>
* @Author: Sum1Dream
* @Date: 2024/9/27 上午11:42
*/
List<BsPartnerPool> queryAllList(Map<String , Object> map);
}

@ -0,0 +1,68 @@
package com.hfkj.service.partner;
import com.hfkj.entity.BsPartnerUserRecord;
import java.util.List;
import java.util.Map;
public interface BsPartnerUserRecordService {
/**
* @MethodName create
* @Description: 创建
* @param partnerUserRecord
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
void create(BsPartnerUserRecord partnerUserRecord);
/**
* @MethodName update
* @Description: 更新
* @param partnerUserRecord
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
void edit(BsPartnerUserRecord partnerUserRecord);
/**
* @MethodName delete
* @Description: 删除
* @param id
* @param fullDelete
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
void delete(Long id , Boolean fullDelete);
/**
* @MethodName queryDetail
* @Description:查询详情
* @param userId
* @return: com.hfkj.entity.BsPartnerUserRecord
* @Author: Sum1Dream
* @Date: 2024/7/4 下午2:30
*/
BsPartnerUserRecord queryDetail(Long userId);
/**
* @MethodName queryDetail
* @Description:
* @param lotteryNo
* @return: com.hfkj.entity.BsPartnerUserRecord
* @Author: Sum1Dream
* @Date: 2024/10/17 下午5:01
*/
BsPartnerUserRecord queryDetail(String lotteryNo , Long userId);
/**
* @MethodName queryAllList
* @Description: map
* @param
* @return: java.util.List<com.hfkj.entity.BsPartnerUserRecord>
* @Author: Sum1Dream
* @Date: 2024/9/27 上午11:42
*/
List<BsPartnerUserRecord> queryAllList(Map<String , Object> map);
}

@ -0,0 +1,81 @@
package com.hfkj.service.partner.Impl;
import com.alipay.api.internal.util.StringUtils;
import com.hfkj.dao.BsPartnerLevelMapper;
import com.hfkj.entity.BsCornucopiaLotteryRecord;
import com.hfkj.entity.BsPartnerLevel;
import com.hfkj.entity.BsPartnerLevelExample;
import com.hfkj.entity.BsPartnerPool;
import com.hfkj.service.partner.BsPartnerLevelService;
import com.hfkj.service.partner.BsPartnerPoolService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service("bsPartnerLevelService")
public class BsPartnerLevelServiceImpl implements BsPartnerLevelService {
@Resource
private BsPartnerLevelMapper bsPartnerLevelMapper;
@Override
public void create(BsPartnerLevel partnerLevel) {
bsPartnerLevelMapper.insert(partnerLevel);
}
@Override
public void edit(BsPartnerLevel partnerLevel) {
if (partnerLevel.getId() == null) {
bsPartnerLevelMapper.insert(partnerLevel);
} else {
bsPartnerLevelMapper.updateByPrimaryKeySelective(partnerLevel);
}
}
@Override
public void delete(Long id, Boolean fullDelete) {
if (fullDelete) {
bsPartnerLevelMapper.deleteByPrimaryKey(id);
} else {
BsPartnerLevel partnerLevel = queryDetail(id);
partnerLevel.setStatus(0);
partnerLevel.setUpdateTime(new Date());
edit(partnerLevel);
}
}
@Override
public BsPartnerLevel queryDetail(Long id) {
return bsPartnerLevelMapper.selectByPrimaryKey(id);
}
@Override
public BsPartnerLevel queryDetail(Integer level) {
BsPartnerLevelExample example = new BsPartnerLevelExample();
example.createCriteria().andLevelEqualTo(level);
List<BsPartnerLevel> list = bsPartnerLevelMapper.selectByExample(example);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
@Override
public List<BsPartnerLevel> queryAllList(Map<String, Object> map) {
BsPartnerLevelExample example = new BsPartnerLevelExample();
BsPartnerLevelExample.Criteria criteria = example.createCriteria();
criteria.andStatusEqualTo(1);
return bsPartnerLevelMapper.selectByExample(example);
}
}

@ -0,0 +1,116 @@
package com.hfkj.service.partner.Impl;
import com.hfkj.dao.BsPartnerPoolPreMapper;
import com.hfkj.entity.BsPartnerLevel;
import com.hfkj.entity.BsPartnerPoolPre;
import com.hfkj.entity.BsPartnerPoolPreExample;
import com.hfkj.service.partner.BsPartnerPoolPreService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service("bsPartnerPoolPreService")
public class BsPartnerPoolPreServiceImpl implements BsPartnerPoolPreService {
@Resource
private BsPartnerPoolPreMapper bsPartnerPoolPreMapper;
@Override
public void create(BsPartnerPoolPre partnerPoolPre) {
bsPartnerPoolPreMapper.insert(partnerPoolPre);
}
@Override
public void edit(BsPartnerPoolPre partnerPoolPre) {
if (partnerPoolPre.getId() == null) {
bsPartnerPoolPreMapper.insert(partnerPoolPre);
} else {
bsPartnerPoolPreMapper.updateByPrimaryKeySelective(partnerPoolPre);
}
}
@Override
public void delete(Long id, Boolean fullDelete) {
if (fullDelete) {
bsPartnerPoolPreMapper.deleteByPrimaryKey(id);
} else {
BsPartnerPoolPre partnerPoolPre = queryDetail(id);
partnerPoolPre.setStatus(0);
partnerPoolPre.setUpdateTime(new Date());
edit(partnerPoolPre);
}
}
@Override
public BsPartnerPoolPre queryDetail(Long userId) {
BsPartnerPoolPreExample example = new BsPartnerPoolPreExample();
BsPartnerPoolPreExample.Criteria criteria = example.createCriteria();
criteria.andUserIdEqualTo(userId);
List<BsPartnerPoolPre> list = bsPartnerPoolPreMapper.selectByExample(example);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
@Override
public BsPartnerPoolPre queryDetail(Map<String, Object> map) {
BsPartnerPoolPreExample example = new BsPartnerPoolPreExample();
BsPartnerPoolPreExample.Criteria criteria = example.createCriteria();
if (MapUtils.getInteger(map, "level") != null) {
criteria.andLevelEqualTo(MapUtils.getInteger(map, "level"));
}
if (MapUtils.getInteger(map, "userId") != null) {
criteria.andUserIdEqualTo(MapUtils.getLong(map, "userId"));
}
if (MapUtils.getInteger(map, "status") != null) {
criteria.andStatusEqualTo(MapUtils.getInteger(map, "status"));
}
if (MapUtils.getString(map, "num") != null) {
criteria.andLotteryNoLike("%" + MapUtils.getString(map, "num") + "%");
}
List<BsPartnerPoolPre> list = bsPartnerPoolPreMapper.selectByExample(example);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
@Override
public List<BsPartnerPoolPre> queryAllList(Map<String, Object> map) {
BsPartnerPoolPreExample example = new BsPartnerPoolPreExample();
BsPartnerPoolPreExample.Criteria criteria = example.createCriteria();
if (MapUtils.getInteger(map, "level") != null) {
criteria.andLevelEqualTo(MapUtils.getInteger(map, "level"));
}
if (MapUtils.getInteger(map, "userId") != null) {
criteria.andUserIdEqualTo(MapUtils.getLong(map, "userId"));
}
if (MapUtils.getString(map, "num") != null) {
criteria.andLotteryNoLike("%" + MapUtils.getString(map, "num") + "%");
}
if (MapUtils.getInteger(map, "status") != null) {
criteria.andStatusEqualTo(MapUtils.getInteger(map, "status"));
}
if (MapUtils.getLong(map, "startTime") != null) {
criteria.andCreateTimeGreaterThanOrEqualTo(new Date(MapUtils.getLong(map, "startTime")));
}
if (MapUtils.getLong(map, "endTime") != null) {
criteria.andCreateTimeLessThan(new Date(MapUtils.getLong(map, "endTime")));
}
if (MapUtils.getString(map, "lotteryNo") != null) {
criteria.andLotteryNoEqualTo(MapUtils.getString(map, "lotteryNo"));
}
return bsPartnerPoolPreMapper.selectByExample(example);
}
}

@ -0,0 +1,87 @@
package com.hfkj.service.partner.Impl;
import com.hfkj.dao.BsPartnerPoolRecordMapper;
import com.hfkj.entity.BsPartnerPoolRecord;
import com.hfkj.entity.BsPartnerPoolRecordExample;
import com.hfkj.service.partner.BsPartnerPoolRecordService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service("bsPartnerPoolRecordService")
public class BsPartnerPoolRecordServiceImpl implements BsPartnerPoolRecordService {
@Resource
private BsPartnerPoolRecordMapper bsPartnerPoolRecordMapper;
@Override
public void create(BsPartnerPoolRecord partnerPoolRecord) {
bsPartnerPoolRecordMapper.insert(partnerPoolRecord);
}
@Override
public void edit(BsPartnerPoolRecord partnerPoolRecord) {
if (partnerPoolRecord.getId() == null) {
bsPartnerPoolRecordMapper.insert(partnerPoolRecord);
} else {
bsPartnerPoolRecordMapper.updateByPrimaryKeySelective(partnerPoolRecord);
}
}
@Override
public void delete(Long id, Boolean fullDelete) {
if (fullDelete) {
bsPartnerPoolRecordMapper.deleteByPrimaryKey(id);
} else {
BsPartnerPoolRecord bsPartnerPoolRecord = queryDetail(id);
bsPartnerPoolRecord.setStatus(0);
bsPartnerPoolRecord.setUpdateTime(new Date());
edit(bsPartnerPoolRecord);
}
}
@Override
public BsPartnerPoolRecord queryDetail(Long id) {
return bsPartnerPoolRecordMapper.selectByPrimaryKey(id);
}
@Override
public BsPartnerPoolRecord queryDetail(String lotteryNo) {
BsPartnerPoolRecordExample example = new BsPartnerPoolRecordExample();
BsPartnerPoolRecordExample.Criteria criteria = example.createCriteria();
criteria.andLotteryNoEqualTo(lotteryNo);
List<BsPartnerPoolRecord> list = bsPartnerPoolRecordMapper.selectByExample(example);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
@Override
public BsPartnerPoolRecord queryDetail(Integer level) {
return null;
}
@Override
public List<BsPartnerPoolRecord> queryAllList(Map<String, Object> map) {
BsPartnerPoolRecordExample example = new BsPartnerPoolRecordExample();
BsPartnerPoolRecordExample.Criteria criteria = example.createCriteria();
if (MapUtils.getString(map, "lotteryNo") != null) {
criteria.andLotteryNoLike("%" + MapUtils.getString(map, "lotteryNo") + "%");
}
if (MapUtils.getInteger(map, "status") != null) {
criteria.andStatusEqualTo(MapUtils.getInteger(map, "status"));
}
return bsPartnerPoolRecordMapper.selectByExample(example);
}
}

@ -0,0 +1,80 @@
package com.hfkj.service.partner.Impl;
import com.hfkj.dao.BsPartnerPoolMapper;
import com.hfkj.entity.BsPartnerPool;
import com.hfkj.entity.BsPartnerPoolExample;
import com.hfkj.service.partner.BsPartnerPoolService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service("bsPartnerPoolService")
public class BsPartnerPoolServiceImpl implements BsPartnerPoolService {
@Resource
private BsPartnerPoolMapper bsPartnerPoolMapper;
@Override
public void create(BsPartnerPool partnerPool) {
bsPartnerPoolMapper.insert(partnerPool);
}
@Override
public void edit(BsPartnerPool partnerPool) {
if (partnerPool.getId() == null) {
bsPartnerPoolMapper.insert(partnerPool);
} else {
bsPartnerPoolMapper.updateByPrimaryKeySelective(partnerPool);
}
}
@Override
public void delete(Long id, Boolean fullDelete) {
if (fullDelete) {
bsPartnerPoolMapper.deleteByPrimaryKey(id);
} else {
BsPartnerPool partnerPool = queryDetail(id);
partnerPool.setStatus(0);
partnerPool.setUpdateTime(new Date());
edit(partnerPool);
}
}
@Override
public BsPartnerPool queryDetail(Long userId) {
BsPartnerPoolExample example = new BsPartnerPoolExample();
BsPartnerPoolExample.Criteria criteria = example.createCriteria();
criteria.andUserIdEqualTo(userId);
List<BsPartnerPool> list = bsPartnerPoolMapper.selectByExample(example);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
@Override
public List<BsPartnerPool> queryAllList(Map<String, Object> map) {
BsPartnerPoolExample example = new BsPartnerPoolExample();
BsPartnerPoolExample.Criteria criteria = example.createCriteria();
if (MapUtils.getInteger(map, "level") != null) {
criteria.andLevelEqualTo(MapUtils.getInteger(map, "level"));
}
if (MapUtils.getInteger(map, "userId") != null) {
criteria.andUserIdEqualTo(MapUtils.getLong(map, "userId"));
}
if (MapUtils.getString(map, "num") != null) {
criteria.andNumLike("%" + MapUtils.getString(map, "num") + "%");
}
criteria.andStatusEqualTo(1);
return bsPartnerPoolMapper.selectByExample(example);
}
}

@ -0,0 +1,101 @@
package com.hfkj.service.partner.Impl;
import com.hfkj.dao.BsPartnerUserRecordMapper;
import com.hfkj.entity.BsPartnerUserRecord;
import com.hfkj.entity.BsPartnerUserRecordExample;
import com.hfkj.service.partner.BsPartnerUserRecordService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service("bsPartnerUserRecordService")
public class BsPartnerUserRecordServiceImpl implements BsPartnerUserRecordService {
@Resource
private BsPartnerUserRecordMapper bsPartnerUserRecordMapper;
@Override
public void create(BsPartnerUserRecord partnerUserRecord) {
bsPartnerUserRecordMapper.insert(partnerUserRecord);
}
@Override
public void edit(BsPartnerUserRecord partnerUserRecord) {
if (partnerUserRecord.getId() == null) {
bsPartnerUserRecordMapper.insert(partnerUserRecord);
} else {
bsPartnerUserRecordMapper.updateByPrimaryKeySelective(partnerUserRecord);
}
}
@Override
public void delete(Long id, Boolean fullDelete) {
if (fullDelete) {
bsPartnerUserRecordMapper.deleteByPrimaryKey(id);
} else {
BsPartnerUserRecord partnerUserRecord = queryDetail(id);
partnerUserRecord.setStatus(0);
partnerUserRecord.setUpdateTime(new Date());
edit(partnerUserRecord);
}
}
@Override
public BsPartnerUserRecord queryDetail(Long userId) {
return null;
}
@Override
public BsPartnerUserRecord queryDetail(String lotteryNo , Long userId) {
BsPartnerUserRecordExample example = new BsPartnerUserRecordExample();
BsPartnerUserRecordExample.Criteria criteria = example.createCriteria();
criteria.andLotteryNoEqualTo(lotteryNo).andUserIdEqualTo(userId);
List<BsPartnerUserRecord> list = bsPartnerUserRecordMapper.selectByExample(example);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
@Override
public List<BsPartnerUserRecord> queryAllList(Map<String, Object> map) {
BsPartnerUserRecordExample example = new BsPartnerUserRecordExample();
BsPartnerUserRecordExample.Criteria criteria = example.createCriteria();
if (MapUtils.getInteger(map, "level") != null) {
criteria.andLevelEqualTo(MapUtils.getInteger(map, "level"));
}
if (MapUtils.getInteger(map, "userId") != null) {
criteria.andUserIdEqualTo(MapUtils.getLong(map, "userId"));
}
if (MapUtils.getInteger(map, "type") != null) {
criteria.andTypeEqualTo(MapUtils.getInteger(map, "type"));
}
if (MapUtils.getInteger(map, "level") != null) {
criteria.andLevelEqualTo(MapUtils.getInteger(map, "level"));
}
if (MapUtils.getString(map, "userName") != null) {
criteria.andUserNameLike("%" + MapUtils.getString(map, "userName") + "%");
}
if (MapUtils.getLong(map, "startTime") != null) {
criteria.andCreateTimeGreaterThanOrEqualTo(new Date(MapUtils.getLong(map, "startTime")));
}
if (MapUtils.getLong(map, "endTime") != null) {
criteria.andCreateTimeLessThan(new Date(MapUtils.getLong(map, "endTime")));
}
if (MapUtils.getString(map, "lotteryNo") != null) {
criteria.andLotteryNoLike("%" + MapUtils.getString(map, "lotteryNo") + "%");
}
if (MapUtils.getInteger(map, "status") != null) {
criteria.andStatusEqualTo(MapUtils.getInteger(map, "status"));
}
return Collections.emptyList();
}
}

@ -0,0 +1,492 @@
package com.hfkj.service.partner.Impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.hfkj.common.exception.BaseException;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.DateUtil;
import com.hfkj.entity.*;
import com.hfkj.model.CornucopiaLotteryRecordModel;
import com.hfkj.service.partner.*;
import com.hfkj.service.user.BsUserAccountService;
import com.hfkj.service.user.BsUserService;
import com.hfkj.sysenum.cornucopia.CornucopiaEnum;
import com.hfkj.sysenum.partner.PartnerEnum;
import com.hfkj.sysenum.user.UserAccountRecordSourceTypeEnum;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Service("partnerService")
public class PartnerServiceImpl implements PartnerService {
@Resource
private BsPartnerLevelService bsPartnerLevelService;
@Resource
private BsPartnerPoolService bsPartnerPoolService;
@Resource
private BsPartnerPoolRecordService bsPartnerPoolRecordService;
@Resource
private BsPartnerPoolPreService bsPartnerPoolPreService;
@Resource
private BsPartnerUserRecordService bsPartnerUserRecordService;
@Resource
private BsUserAccountService userAccountService;
@Resource
private BsUserService bsUserService;
@Resource
private RedisTemplate<String,Object> redisTemplate;
private final String LOCK_KEY = "PARTNER_LOCK_";
@Override
@Transactional(propagation= Propagation.REQUIRED,rollbackFor= {RuntimeException.class})
public void inPartner(JSONObject jsonObject) throws Exception {
// 查询当期是否存在已经竞选合伙人内容
if (isPartner(jsonObject.getLong("userId"))) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "用户当期已投入!");
}
Long userId = jsonObject.getLong("userId");
BigDecimal goldCoin = jsonObject.getBigDecimal("goldCoin");
// 锁编号
String lockKey = LOCK_KEY + userId;
// 获取锁
Boolean lock = redisTemplate.opsForValue().setIfAbsent(lockKey, "");
if (Boolean.TRUE.equals(lock)) {
try {
// 获取锁成功
// 锁超时时间 10秒
redisTemplate.expire(lockKey, 10, TimeUnit.SECONDS);
// 查询账户
BsUserAccount userAccount = userAccountService.getAccount(userId);
// 判断当前账户余额是否足够投入 true 不够 false 够
Boolean isMeet = userAccount.getGoldCoin().compareTo(goldCoin) < 0;
// 判断是否充足
if (isMeet) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "元宝还差那么一点点哦!");
}
String lotteryNo = DateUtil.date2String(new Date() , DateUtil.YMD);
// 插入投入记录
BsPartnerPoolPre partnerPoolPre = new BsPartnerPoolPre();
partnerPoolPre.setUserId(userId);
partnerPoolPre.setCampaignNo(newRank(jsonObject.getInteger("level")));
partnerPoolPre.setLotteryNo(lotteryNo);
partnerPoolPre.setLevel(jsonObject.getInteger("level"));
partnerPoolPre.setGoldCoin(goldCoin);
partnerPoolPre.setStatus(1);
partnerPoolPre.setCreateTime(new Date());
partnerPoolPre.setUpdateTime(new Date());
bsPartnerPoolPreService.create(partnerPoolPre);
// 查询开奖记录
BsPartnerPoolRecord partnerPoolRecord = bsPartnerPoolRecordService.queryDetail(lotteryNo);
if (partnerPoolRecord == null) {
partnerPoolRecord = new BsPartnerPoolRecord();
partnerPoolRecord.setLotteryNo(lotteryNo);
partnerPoolRecord.setGoldCoin(partnerPoolPre.getGoldCoin());
partnerPoolRecord.setStatus(1);
partnerPoolRecord.setCreateTime(new Date());
partnerPoolRecord.setUpdateTime(new Date());
} else {
partnerPoolRecord.setGoldCoin(partnerPoolPre.getGoldCoin().add(partnerPoolRecord.getGoldCoin()));
}
bsPartnerPoolRecordService.edit(partnerPoolRecord);
// 扣除记录
Map<String, Object> userRechargeParam = new HashMap<>();
userRechargeParam.put("sourceId", partnerPoolPre.getId());
userRechargeParam.put("sourceOrderNo", "");
userRechargeParam.put("sourceContent", jsonObject.getString("userName") + "投入" + PartnerEnum.getDataByType(partnerPoolPre.getLevel()).getName() + goldCoin);
// 用户账户扣账
userAccountService.consume(userId,goldCoin, UserAccountRecordSourceTypeEnum.type4, userRechargeParam);
} catch (BaseException e) {
// 释放锁
redisTemplate.delete(lockKey);
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, e.getErrorMsg());
} catch (Exception e) {
// 释放锁
redisTemplate.delete(lockKey);
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "啊偶~交易出现未知问题!请稍后重试");
}
} else {
Thread.sleep(100);
inPartner(jsonObject);
}
}
@Override
@Transactional(propagation= Propagation.REQUIRED,rollbackFor= {RuntimeException.class})
public void startCampaign() throws Exception {
String lotteryNo = DateUtil.date2String(new Date() , DateUtil.YMD);
// 查询当选的合伙人
List<BsPartnerPool> partnerPools = bsPartnerPoolService.queryAllList(new HashMap<>());
// 获取L1列表
List<BsPartnerPool> partnerPoolsL1 = partnerPools.stream().filter(s-> s.getLevel().equals(1)).collect(Collectors.toList());
// 获取L2列表
List<BsPartnerPool> partnerPoolsL2 = partnerPools.stream().filter(s-> s.getLevel().equals(2)).collect(Collectors.toList());
// 获取L3列表
List<BsPartnerPool> partnerPoolsL3 = partnerPools.stream().filter(s-> s.getLevel().equals(3)).collect(Collectors.toList());
// 获取L4列表
List<BsPartnerPool> partnerPoolsL4 = partnerPools.stream().filter(s-> s.getLevel().equals(4)).collect(Collectors.toList());
// 获取L5列表
List<BsPartnerPool> partnerPoolsL5 = partnerPools.stream().filter(s-> s.getLevel().equals(5)).collect(Collectors.toList());
List<BsPartnerPool> pools = new ArrayList<>();
// 查询当期竞选的合伙人
Map<String , Object> map = new HashMap<>();
map.put("status" , 1);
map.put("lotteryNo" , lotteryNo);
List<BsPartnerPoolPre> partnerPoolPres = bsPartnerPoolPreService.queryAllList(map);
// 获取当期L1列表
List<BsPartnerPoolPre> partnerPoolsPreL1 = partnerPoolPres.stream().filter(s-> s.getLevel().equals(1)).sorted(Comparator.comparing(BsPartnerPoolPre::getCampaignNo)).sorted(Comparator.comparing(BsPartnerPoolPre::getGoldCoin).reversed()).collect(Collectors.toList());
// 获取当期L2列表
List<BsPartnerPoolPre> partnerPoolsPreL2 = partnerPoolPres.stream().filter(s-> s.getLevel().equals(2)).sorted(Comparator.comparing(BsPartnerPoolPre::getCampaignNo)).sorted(Comparator.comparing(BsPartnerPoolPre::getGoldCoin).reversed()).collect(Collectors.toList());
// 获取当期L3列表
List<BsPartnerPoolPre> partnerPoolsPreL3 = partnerPoolPres.stream().filter(s-> s.getLevel().equals(3)).sorted(Comparator.comparing(BsPartnerPoolPre::getCampaignNo)).sorted(Comparator.comparing(BsPartnerPoolPre::getGoldCoin).reversed()).collect(Collectors.toList());
// 获取当期L4列表
List<BsPartnerPoolPre> partnerPoolsPreL4 = partnerPoolPres.stream().filter(s-> s.getLevel().equals(4)).sorted(Comparator.comparing(BsPartnerPoolPre::getCampaignNo)).sorted(Comparator.comparing(BsPartnerPoolPre::getGoldCoin).reversed()).collect(Collectors.toList());
// 获取当期L5列表
List<BsPartnerPoolPre> partnerPoolsPreL5 = partnerPoolPres.stream().filter(s-> s.getLevel().equals(5)).sorted(Comparator.comparing(BsPartnerPoolPre::getCampaignNo)).sorted(Comparator.comparing(BsPartnerPoolPre::getGoldCoin).reversed()).collect(Collectors.toList());
List<BsPartnerPoolPre> pres = new ArrayList<>();
// 查询开奖记录
BsPartnerPoolRecord partnerPoolRecord = bsPartnerPoolRecordService.queryDetail(lotteryNo);
if (partnerPoolRecord != null) {
if (partnerPoolRecord.getStatus().equals(2)) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当期已经竞选结算!");
}
partnerPoolRecord.setStatus(2);
partnerPoolRecord.setLotteryTime(new Date());
bsPartnerPoolRecordService.edit(partnerPoolRecord);
}
// todo 计算当期的时候需要先预站一个位置 如果当前用户大那么顺序往下走
// L1参选
for (BsPartnerPoolPre partnerPoolPre : partnerPoolsPreL1) {
if (partnerPoolPre.getStatus().equals(1)) {
// 查询还未被占位的合伙人位置并且当前合伙人金额大于
List<BsPartnerPool> poolList = partnerPoolsL1.stream().filter(s-> s.getGoldCoin().compareTo(partnerPoolPre.getGoldCoin()) < 0).filter(s->s.getStatus().equals(1)).collect(Collectors.toList());
if (!poolList.isEmpty()) {
BsPartnerPool pool = poolList.get(0);
// 竞选成功
if (pool.getUserId() != null) {
campaignPartner(partnerPoolPre , pool);
}
// 配置参数
pool.setUserId(partnerPoolPre.getUserId());
pool.setGoldCoin(partnerPoolPre.getGoldCoin());
pools.add(pool);
// 竞选成功预展 位置
partnerPoolsL1 = partnerPoolsL1.stream()
.map(s -> {
if (s.getId().equals(pool.getId())) {
s.setStatus(2);
}; // 直接修改原对象状态
return s; // 返回修改后的对象
})
.collect(Collectors.toList());
// 配置预约竞选参数
partnerPoolPre.setStatus(2);
partnerPoolPre.setNum(pool.getNum());
pres.add(partnerPoolPre);
}
}
}
// L2参选
for (BsPartnerPoolPre partnerPoolPre : partnerPoolsPreL2) {
if (partnerPoolPre.getStatus().equals(1)) {
List<BsPartnerPool> poolList = partnerPoolsL2.stream().filter(s-> s.getGoldCoin().compareTo(partnerPoolPre.getGoldCoin()) < 0).filter(s->s.getStatus().equals(1)).collect(Collectors.toList());
if (!poolList.isEmpty()) {
BsPartnerPool pool = poolList.get(0);
if (pool.getUserId() != null) {
campaignPartner(partnerPoolPre , pool);
}
pool.setUserId(partnerPoolPre.getUserId());
pool.setGoldCoin(partnerPoolPre.getGoldCoin());
pools.add(pool);
partnerPoolsL2 = partnerPoolsL2.stream()
.map(s -> {
if (s.getId().equals(pool.getId())) {
s.setStatus(2);
}; // 直接修改原对象状态
return s; // 返回修改后的对象
})
.collect(Collectors.toList());
partnerPoolPre.setStatus(2);
partnerPoolPre.setNum(pool.getNum());
pres.add(partnerPoolPre);
}
}
}
// L3参选
for (BsPartnerPoolPre partnerPoolPre : partnerPoolsPreL3) {
if (partnerPoolPre.getStatus().equals(1)) {
List<BsPartnerPool> poolList = partnerPoolsL3.stream().filter(s-> s.getGoldCoin().compareTo(partnerPoolPre.getGoldCoin()) < 0).filter(s->s.getStatus().equals(1)).collect(Collectors.toList());
if (!poolList.isEmpty()) {
BsPartnerPool pool = poolList.get(0);
if (pool.getUserId() != null) {
campaignPartner(partnerPoolPre , pool);
}
pool.setUserId(partnerPoolPre.getUserId());
pool.setGoldCoin(partnerPoolPre.getGoldCoin());
pools.add(pool);
partnerPoolsL3 = partnerPoolsL3.stream()
.map(s -> {
if (s.getId().equals(pool.getId())) {
s.setStatus(2);
}; // 直接修改原对象状态
return s; // 返回修改后的对象
})
.collect(Collectors.toList());
partnerPoolPre.setStatus(2);
partnerPoolPre.setNum(pool.getNum());
pres.add(partnerPoolPre);
}
}
}
// L4参选
for (BsPartnerPoolPre partnerPoolPre : partnerPoolsPreL4) {
if (partnerPoolPre.getStatus().equals(1)) {
List<BsPartnerPool> poolList = partnerPoolsL4.stream().filter(s-> s.getGoldCoin().compareTo(partnerPoolPre.getGoldCoin()) < 0).filter(s->s.getStatus().equals(1)).collect(Collectors.toList());
if (!poolList.isEmpty()) {
BsPartnerPool pool = poolList.get(0);
if (pool.getUserId() != null) {
campaignPartner(partnerPoolPre , pool);
}
pool.setUserId(partnerPoolPre.getUserId());
pool.setGoldCoin(partnerPoolPre.getGoldCoin());
pools.add(pool);
partnerPoolsL4 = partnerPoolsL4.stream()
.map(s -> {
if (s.getId().equals(pool.getId())) {
s.setStatus(2);
}; // 直接修改原对象状态
return s; // 返回修改后的对象
})
.collect(Collectors.toList());
partnerPoolPre.setStatus(2);
partnerPoolPre.setNum(pool.getNum());
pres.add(partnerPoolPre);
}
}
}
// L5参选
for (BsPartnerPoolPre partnerPoolPre : partnerPoolsPreL5) {
if (partnerPoolPre.getStatus().equals(1)) {
List<BsPartnerPool> poolList = partnerPoolsL5.stream().filter(s-> s.getGoldCoin().compareTo(partnerPoolPre.getGoldCoin()) < 0).filter(s->s.getStatus().equals(1)).collect(Collectors.toList());
if (!poolList.isEmpty()) {
BsPartnerPool pool = poolList.get(0);
if (pool.getUserId() != null) {
campaignPartner(partnerPoolPre , pool);
}
pool.setUserId(partnerPoolPre.getUserId());
pool.setGoldCoin(partnerPoolPre.getGoldCoin());
pools.add(pool);
partnerPoolsL5 = partnerPoolsL5.stream()
.map(s -> {
if (s.getId().equals(pool.getId())) {
s.setStatus(2);
}; // 直接修改原对象状态
return s; // 返回修改后的对象
})
.collect(Collectors.toList());
partnerPoolPre.setStatus(2);
partnerPoolPre.setNum(pool.getNum());
pres.add(partnerPoolPre);
}
}
}
for (BsPartnerPool pool : pools) {
pool.setStatus(1);
pool.setUpdateTime(new Date());
bsPartnerPoolService.edit(pool);
}
for (BsPartnerPoolPre partnerPoolPre: pres) {
if (partnerPoolPre.getStatus().equals(1)) {
partnerPoolPre.setStatus(3);
partnerPoolPre.setUpdateTime(new Date());
BsUser user = bsUserService.getUser(partnerPoolPre.getUserId());
// 收益记录
Map<String, Object> userRechargeParam = new HashMap<>();
userRechargeParam.put("sourceId", partnerPoolPre.getId());
userRechargeParam.put("sourceOrderNo", "");
userRechargeParam.put("sourceContent", user.getName()+ "竞选失败退回" + PartnerEnum.getDataByType(partnerPoolPre.getLevel()).getName() + partnerPoolPre.getGoldCoin());
// 用户账户充值
userAccountService.recharge(user.getId(),partnerPoolPre.getGoldCoin(), UserAccountRecordSourceTypeEnum.type4, userRechargeParam);
}
bsPartnerPoolPreService.edit(partnerPoolPre);
}
}
@Override
public void dividend() throws Exception {
// 查询当选的合伙人
List<BsPartnerPool> partnerPools = bsPartnerPoolService.queryAllList(new HashMap<>());
// 查询分红等级
List<BsPartnerLevel> partnerLevels = bsPartnerLevelService.queryAllList(new HashMap<>());
String lotteryNo = DateUtil.date2String(new Date() , DateUtil.YMD);
for (BsPartnerPool pool : partnerPools) {
if (pool.getGoldCoin().compareTo(new BigDecimal(0)) > 0 && pool.getUserId() != null) {
BsPartnerLevel level = partnerLevels.stream().filter(s-> s.getLevel().equals(pool.getLevel())).findFirst().get();
BsPartnerUserRecord partnerUserRecord = bsPartnerUserRecordService.queryDetail(lotteryNo , pool.getUserId());
BsUser user = bsUserService.getUser(pool.getUserId());
if (partnerUserRecord == null) {
partnerUserRecord = new BsPartnerUserRecord();
partnerUserRecord.setCreateTime(new Date());
partnerUserRecord.setLevel(pool.getLevel());
partnerUserRecord.setLotteryNo(lotteryNo);
partnerUserRecord.setLotteryTime(new Date());
partnerUserRecord.setUserId(pool.getUserId());
partnerUserRecord.setUserName(user.getName());
partnerUserRecord.setGoldCoin(pool.getGoldCoin().multiply(level.getDividendsPer()));
partnerUserRecord.setProportion(level.getDividendsPer());
partnerUserRecord.setType(1);
partnerUserRecord.setStatus(1);
bsPartnerUserRecordService.create(partnerUserRecord);
// 收益记录
Map<String, Object> userRechargeParam = new HashMap<>();
userRechargeParam.put("sourceId", partnerUserRecord.getId());
userRechargeParam.put("sourceOrderNo", "");
userRechargeParam.put("sourceContent", user.getName()+ "收益" + PartnerEnum.getDataByType(pool.getLevel()).getName() + partnerUserRecord.getGoldCoin());
// 用户账户充值
userAccountService.recharge(user.getId(),partnerUserRecord.getGoldCoin(), UserAccountRecordSourceTypeEnum.type4, userRechargeParam);
}
}
}
}
@Override
public List<JSONObject> partnerData(Long startTime, Long endTime) throws Exception {
Map<String, Object> params = new HashMap<>();
params.put("startTime", startTime);
params.put("endTime", endTime);
List<BsPartnerPoolPre> list = bsPartnerPoolPreService.queryAllList(params);
Map<Integer, List<BsPartnerPoolPre>> collect = list.stream().collect(Collectors.groupingBy(BsPartnerPoolPre::getLevel));
List<JSONObject> countRecords = collect.keySet().stream().map(key -> {
JSONObject goodObject = new JSONObject(true);
goodObject.put("level",key);
List<BsPartnerPoolPre> pres = collect.get(key);
goodObject.put("campaignUserNum", pres.size());
goodObject.put("campaignGoldCoin", pres.stream().map(BsPartnerPoolPre::getGoldCoin).reduce(BigDecimal.ZERO, BigDecimal::add));
return goodObject;
}).collect(Collectors.toList());
return countRecords;
}
@Override
public JSONObject dividendData(Long startTime, Long endTime) throws Exception {
Map<String, Object> params = new HashMap<>();
params.put("startTime", startTime);
params.put("endTime", endTime);
List<BsPartnerUserRecord> userRecords = bsPartnerUserRecordService.queryAllList(params);
return null;
}
// 竞选成功返利
private void campaignPartner(BsPartnerPoolPre partnerPoolPre , BsPartnerPool pool) throws Exception {
BsPartnerUserRecord userRecord = new BsPartnerUserRecord();
BsUser bsUser = bsUserService.getUser(pool.getUserId());
// 查询差价
BigDecimal differencePrice = partnerPoolPre.getGoldCoin().subtract(pool.getGoldCoin());
userRecord.setType(2);
userRecord.setStatus(1);
userRecord.setGoldCoin(differencePrice.divide(new BigDecimal(2) , 6 , RoundingMode.DOWN));
userRecord.setLotteryNo(partnerPoolPre.getLotteryNo());
userRecord.setLotteryTime(new Date());
userRecord.setCreateTime(new Date());
userRecord.setUpdateTime(new Date());
userRecord.setLevel(partnerPoolPre.getLevel());
bsPartnerUserRecordService.create(userRecord);
// 原竞选者修改为失败
Map<String , Object> preMap = new HashMap<>();
preMap.put("userId", pool.getUserId());
preMap.put("status", 2);
BsPartnerPoolPre pre = bsPartnerPoolPreService.queryDetail(preMap);
pre.setStatus(4);
pre.setUpdateTime(new Date());
bsPartnerPoolPreService.edit(pre);
// 收益记录
Map<String, Object> userRechargeParam = new HashMap<>();
userRechargeParam.put("sourceId", userRecord.getId());
userRechargeParam.put("sourceOrderNo", "");
userRechargeParam.put("sourceContent", bsUser.getName()+ "收益" + PartnerEnum.getDataByType(pool.getLevel()).getName() + userRecord.getGoldCoin());
// 用户账户充值
userAccountService.recharge(bsUser.getId(),userRecord.getGoldCoin(), UserAccountRecordSourceTypeEnum.type4, userRechargeParam);
userRecord.setUserId(pool.getUserId());
userRecord.setUserName(bsUser.getName());
bsPartnerUserRecordService.create(userRecord);
}
// 判断是否存在已经竞选过
private Boolean isPartner(Long userId) {
// 查询用户是否存在
Map<String ,Object> mapUserPartner = new HashMap<>();
mapUserPartner.put("userId",userId);
mapUserPartner.put("status",1);
BsPartnerPoolPre partnerPoolPre = bsPartnerPoolPreService.queryDetail(mapUserPartner);
return partnerPoolPre != null;
}
// 查询当前类型最新的排名
private Integer newRank(Integer level) {
// 查询当期用户内容
Map<String , Object> map = new HashMap<>();
map.put("status" , 1);
map.put("level" , level);
List<BsPartnerPoolPre> list = bsPartnerPoolPreService.queryAllList(map);
return list.size() +1 ;
}
}

@ -0,0 +1,57 @@
package com.hfkj.service.partner;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
public interface PartnerService {
/**
* @MethodName inPartner
* @Description: 参与竞选合伙人
* @param jsonObject
* @Author: Sum1Dream
* @Date: 2024/10/16 上午10:44
*/
void inPartner(JSONObject jsonObject) throws Exception;
/**
* @MethodName startCampaign
* @Description: 开始竞选
* @param
* @Author: Sum1Dream
* @Date: 2024/10/16 下午3:18
*/
void startCampaign() throws Exception;
/**
* @MethodName dividend
* @Description: 分红
* @param
* @Author: Sum1Dream
* @Date: 2024/10/18 下午2:02
*/
void dividend() throws Exception;
/**
* @MethodName partnerData
* @Description: 合伙人数据统计
* @param startTime
* @param endTime
* @return: com.alibaba.fastjson.JSONObject
* @Author: Sum1Dream
* @Date: 2024/10/18 下午2:06
*/
List<JSONObject> partnerData(Long startTime, Long endTime) throws Exception;
/**
* @MethodName dividendData
* @Description: 分红统计
* @param startTime
* @param endTime
* @return: com.alibaba.fastjson.JSONObject
* @Author: Sum1Dream
* @Date: 2024/10/18 下午2:25
*/
JSONObject dividendData(Long startTime, Long endTime) throws Exception;
}

@ -0,0 +1,56 @@
package com.hfkj.sysenum.partner;
import lombok.Getter;
import java.util.Objects;
/**
* @className: UserStatusEnum
* @author: HuRui
* @date: 2024/5/6
**/
@Getter
public enum PartnerEnum {
/**
* L1
*/
type1(1, "L1"),
/**
* L2
*/
type2(2, "L2"),
/**
* L3
*/
type3(3 ,"L3"),
/**
* L4
*/
type4(4, "L4"),
/**
* L5
*/
type5(5, "L5");
private int code;
private String name;
PartnerEnum(int code, String name) {
this.code = code;
this.name = name;
}
/**
* 查询数据
* @param code
* @return
*/
public static PartnerEnum getDataByType(Integer code) {
for (PartnerEnum ele : values()) {
if (Objects.equals(code,ele.getCode())) return ele;
}
return null;
}
}

@ -20,6 +20,10 @@ public enum UserAccountRecordSourceTypeEnum {
* 聚宝盆
*/
type3(3 , "聚宝盆"),
/**
* 合伙人
*/
type4(4 , "合伙人"),
;
private Integer type;

Loading…
Cancel
Save