元气优淘服务端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
youtao/cweb/src/main/java/com/hfkj/controller/partner/PartnerController.java

219 lines
8.1 KiB

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 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(@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, "");
}
// 查询上一期
String lotteryNo = DateUtil.date2String(new Date() , DateUtil.YMD);
JSONObject obj = new JSONObject();
// 查询当期用户内容
Map<String , Object> map = new HashMap<>();
map.put("status" , 1);
map.put("level" , level);
map.put("lotteryNo" , lotteryNo);
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() , level);
obj.put("partnerLevel" , 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(@RequestParam(value = "level" , required = true) Integer level) {
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);
Map<String , Object> map = new HashMap<>();
map.put("status" , 1);
map.put("level" , level);
List<BsPartnerPool> list = bsPartnerPoolService.queryAllList(map);
Map<String , Object> userMap = new HashMap<>();
userMap.put("userId" , userSession.getUser().getId());
userMap.put("lotteryNo" , lotteryNo);
Map<String , Object> mapPre = new HashMap<>();
int preLotteryNo = Integer.parseInt(lotteryNo) - 1;
mapPre.put("lotteryNo" , Integer.toString(preLotteryNo));
map.put("level" , level);
List<BsPartnerPoolPre> pres = bsPartnerPoolPreService.queryAllList(mapPre);
JSONObject obj = new JSONObject();
// 插入上一期内容
obj.put("partnerPoolPre" , list);
obj.put("partnerPoolUser" , bsPartnerPoolPreService.queryDetail(userMap));
obj.put("userPoolPre" , pres.stream().filter(s->s.getUserId().equals(userSession.getUser().getId())).filter(s->s.getLevel().equals(level)).findFirst().orElse(null));
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);
}
}
}