package com.stylefeng.guns.modular.api;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.google.gson.Gson;
|
import com.google.gson.JsonElement;
|
import com.google.gson.JsonObject;
|
import com.stylefeng.guns.modular.system.dao.UserBlackMapper;
|
import com.stylefeng.guns.modular.system.dto.*;
|
import com.stylefeng.guns.modular.system.model.*;
|
import com.stylefeng.guns.modular.system.service.*;
|
import com.stylefeng.guns.modular.system.util.*;
|
import com.stylefeng.guns.modular.system.util.Page;
|
import com.stylefeng.guns.modular.system.vo.*;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import io.swagger.models.Swagger;
|
import io.swagger.models.auth.In;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.util.StringUtils;
|
import org.springframework.web.bind.annotation.*;
|
import springfox.documentation.spring.web.paths.AbstractPathProvider;
|
|
import java.math.BigDecimal;
|
import java.math.RoundingMode;
|
import java.security.PrivilegedAction;
|
import java.text.DecimalFormat;
|
import java.text.SimpleDateFormat;
|
import java.time.LocalDate;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* @author 无关风月
|
* @Date 2024/2/6 18:25
|
*/
|
@RestController
|
@RequestMapping("")
|
public class UserController {
|
|
@Autowired
|
private RedisUtil redisUtil;
|
@Autowired
|
private IProtocolService protocolService;
|
@Autowired
|
private IPageService pageService;
|
@Autowired
|
private IAppUserService appUserService;
|
@Autowired
|
private IUserCollectService collectService;
|
@Autowired
|
private ICourseService courseService;
|
@Autowired
|
private IFeedbackService feedbackService;
|
@Autowired
|
private IFindService findService;
|
@Autowired
|
private IFindCommentService findCommentService;
|
@Autowired
|
private IRechargeService rechargeService;
|
@Autowired
|
private IOrderCourseService orderCourseService;
|
@Autowired
|
private IWithdrawalService withdrawalService;
|
@Autowired
|
private IOrderService orderService;
|
@Autowired
|
private IInviteService inviteService;
|
@Autowired
|
private ICouponService couponService;
|
@Autowired
|
private ICouponReceiveService couponReceiveService;
|
@Autowired
|
private IUserRecordService recordService;
|
@Autowired
|
private IUseGuideService useGuideService;
|
@Autowired
|
private IRedPackageService redPackageService;
|
private String COLLECTION_KEY = "c33eacc01b9832ee0d3544fda707f2e9";
|
@Autowired
|
private ISysSetService sysSetService;
|
@ResponseBody
|
@PostMapping("/base/appUser/peopleList")
|
@ApiOperation(value = "好友推广", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
})
|
public ResultUtil<PeopleListVO> peopleList() {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
PeopleListVO peopleListVO = new PeopleListVO();
|
peopleListVO.setUserName(appUserService.getAppUser().getName());
|
Integer inviteUserId = appUser.getInviteUserId();
|
if (inviteUserId!=null){
|
AppUser appUser1 = appUser.selectById(inviteUserId);
|
if (StringUtils.hasLength(appUser1.getName())){
|
peopleListVO.setInvite(appUser1.getName());
|
}else{
|
peopleListVO.setInvite(appUser1.getPhone());
|
}
|
}
|
StringBuilder stringBuilder = new StringBuilder("");
|
for (AppUser userId : appUserService.selectList(new EntityWrapper<AppUser>()
|
.eq("inviteUserId", appUser.getId()))) {
|
stringBuilder.append(userId.getName()+",");
|
}
|
String s = stringBuilder.toString();
|
if (StringUtils.hasLength(s)){
|
String substring = s.substring(0, s.length() - 1);
|
peopleListVO.setPeople(substring);
|
}
|
peopleListVO.setId(appUser.getId());
|
peopleListVO.setCode(appUser.getCode());
|
SysSet sysSet = sysSetService.selectById(1);
|
String introduce = sysSet.getIntroduce();
|
peopleListVO.setContent(introduce);
|
peopleListVO.setUrl("https://jkcyl.cn/share");
|
return ResultUtil.success(peopleListVO);
|
}
|
|
@ResponseBody
|
@PostMapping("/base/appUser/getBindingUserName")
|
@ApiOperation(value = "获取绑定邀请码的用户名称", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
|
@ApiImplicitParam(value = "邀请码", name = "code", dataType = "string", required = true)
|
})
|
public ResultUtil getBindingUserName(String code) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
if (code.equals(appUser.getCode())){
|
return ResultUtil.errorInvite("不能绑定自己","");
|
}
|
AppUser code1 = appUserService.selectOne(new EntityWrapper<AppUser>()
|
.eq("code", code));
|
if (code1 == null){
|
return ResultUtil.errorInvite("邀请码无效","");
|
}
|
// else{
|
// if (code1.getInviteUserId().equals(appUser.getId())){
|
// return ResultUtil.error("邀请失败,当前邀请用户为您的邀请人", null);
|
// }
|
// }
|
return ResultUtil.success(code1.getName());
|
}
|
@ResponseBody
|
@PostMapping("/base/appUser/binding")
|
@ApiOperation(value = "绑定邀请码--", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(value = "邀请码", name = "code", dataType = "string", required = true)
|
})
|
public ResultUtil updateBankCard(String code) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
AppUser code1 = appUserService.selectOne(new EntityWrapper<AppUser>()
|
.eq("code", code));
|
if (code1 == null){
|
return ResultUtil.errorInvite("邀请码无效","");
|
}
|
if (code.equals(appUser.getCode())){
|
return ResultUtil.error("不能绑定自己");
|
}
|
if (code1.getInviteUserId()!=null){
|
if (code1.getInviteUserId().equals(appUser.getId())){
|
return ResultUtil.error("邀请失败,当前邀请用户为您的邀请人", null);
|
}
|
}
|
appUser.setInviteUserId(code1.getId());
|
appUserService.updateById(appUser);
|
return ResultUtil.success(code1.getName());
|
}
|
|
|
@ResponseBody
|
@PostMapping("/base/appUser/Withdrawal")
|
@ApiOperation(value = "提现", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(value = "提现金额", name = "money", required = true)
|
})
|
public ResultUtil Withdrawal(BigDecimal money) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
if (!StringUtils.hasLength(appUser.getBankCard())){
|
return ResultUtil.error("提现失败 请先绑定银行卡");
|
}
|
if (appUser.getBalance().compareTo(money)<0){
|
return ResultUtil.error("可提现金额不足");
|
}
|
Withdrawal withdrawal = new Withdrawal();
|
withdrawal.setUserId(appUser.getId());
|
withdrawal.setInsertTime(new Date());
|
withdrawal.setAmount(money);
|
withdrawal.setApplyAmount(appUser.getBalance());
|
withdrawal.setState(1);
|
withdrawal.setPayment(1);
|
withdrawalService.insert(withdrawal);
|
BigDecimal balance = appUser.getBalance();
|
BigDecimal subtract = balance.subtract(money);
|
appUser.setBalance(subtract);
|
appUserService.updateById(appUser);
|
return ResultUtil.success();
|
}
|
@ResponseBody
|
@PostMapping("/base/appUser/updateBankCard")
|
@ApiOperation(value = "绑定银行卡", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(value = "银行卡开户名", name = "accountName", dataType = "string" ),
|
@ApiImplicitParam(value = "银行卡卡号", name = "bankCard", dataType = "string" ),
|
@ApiImplicitParam(value = "银行卡开户行", name = "bankName", dataType = "string"),
|
@ApiImplicitParam(value = "银行卡绑定手机号", name = "bankPhone", dataType = "string"),
|
@ApiImplicitParam(value = "银行卡正面照", name = "bankCardImg", dataType = "string")
|
})
|
public ResultUtil updateBankCard(String accountName, String bankCard,String bankName,String bankPhone,String bankCardImg) {
|
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
appUser.setBankCard(bankCard);
|
appUser.setAccountName(accountName);
|
appUser.setBankName(bankName);
|
appUser.setBankPhone(bankPhone);
|
appUser.setBankCardImg(bankCardImg);
|
if (!StringUtils.hasLength(accountName)){
|
return ResultUtil.success(appUser);
|
}
|
appUserService.updateById(appUser);
|
return ResultUtil.success();
|
}
|
|
@Autowired
|
private UserBlackMapper userBlackMapper;
|
@ResponseBody
|
@PostMapping("/base/appUser/blackList")
|
@ApiOperation(value = "拉黑列表", tags = {"2.0新增"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(value = "页码,首页1", name = "pageNum", dataType = "int"),
|
@ApiImplicitParam(value = "页条数", name = "pageSize", dataType = "int"),
|
})
|
public ResultUtil<List<BlackListVO>> blackList(Integer pageNum,Integer pageSize) {
|
List<BlackListVO> res = new ArrayList<>();
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
List<UserBlack> userId = userBlackService.selectList(new EntityWrapper<UserBlack>()
|
.eq("userId", appUser.getId()));
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
|
|
for (UserBlack userBlack : userId) {
|
AppUser appUser1 = appUserService.selectById(userBlack.getBlackUserId());
|
if (appUser1 != null){
|
BlackListVO blackListVO = new BlackListVO();
|
blackListVO.setId(appUser1.getId());
|
blackListVO.setHeadImg(appUser1.getHeadImg());
|
blackListVO.setName(appUser1.getName());
|
String format = simpleDateFormat.format(userBlack.getInsertTime());
|
res.add(blackListVO);
|
}
|
}
|
List<BlackListVO> findVOS = testing4(res.size(), pageNum, pageSize, res);
|
return ResultUtil.success(findVOS);
|
}
|
@Autowired
|
private IUserBlackService userBlackService;
|
@ResponseBody
|
@PostMapping("/base/appUser/black")
|
@ApiOperation(value = "拉黑/取消拉黑操作", tags = {"2.0新增"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(value = "被拉黑用户id", name = "id", dataType = "string" ),
|
})
|
public ResultUtil black(Integer id) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
UserBlack userBlack = userBlackService.selectOne(new EntityWrapper<UserBlack>()
|
.eq("userId", appUser.getId())
|
.eq("blackUserId", id));
|
// 执行取消拉黑操作
|
if (userBlack!=null){
|
userBlackService.deleteById(userBlack.getId());
|
}else{
|
// 执行新增拉黑操作
|
userBlack = new UserBlack();
|
userBlack.setInsertTime(new Date());
|
userBlack.setUserId(appUser.getId());
|
userBlack.setBlackUserId(id);
|
userBlackService.insert(userBlack);
|
}
|
return ResultUtil.success();
|
}
|
|
@ResponseBody
|
@PostMapping("/base/appUser/getPhone")
|
@ApiOperation(value = "获取客服电话", tags = {"我的"})
|
public ResultUtil<String> getPhone() {
|
String phone = sysSetService.selectById(1).getPhone();
|
return ResultUtil.success(phone);
|
}
|
// @ResponseBody
|
// @PostMapping("/base/appUser/isAlert")
|
// @ApiOperation(value = "是否弹窗提示完善身体数据", tags = {"我的"})
|
// @ApiImplicitParams({
|
// @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
//
|
// })
|
// public ResultUtil<AppUser> updateBankCard() {
|
// return ResultUtil.success(appUserService.getAppUser());
|
// }
|
|
@ResponseBody
|
@PostMapping("/base/appUser/getBankInfo")
|
@ApiOperation(value = "获取用户银行卡信息", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
|
})
|
public ResultUtil<AppUser> updateBankCard() {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
return ResultUtil.success(appUserService.getAppUser());
|
}
|
|
@ResponseBody
|
@PostMapping("/base/appUser/couponList")
|
@ApiOperation(value = "优惠券管理", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
})
|
public ResultUtil<List<CouponVO>> withdrawal(CouponQuery req) {
|
List<CouponVO> res = new ArrayList<>();
|
req.setPageNum((req.getPageNum() - 1) * req.getPageSize());
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
req.setUserId(appUser.getId());
|
List<CouponReceive> couponReceives = couponReceiveService.getList(req);
|
for (CouponReceive couponReceive : couponReceives) {
|
Coupon coupon = couponService.selectById(couponReceive.getCouponId());
|
CouponVO couponVO = new CouponVO();
|
couponVO.setName(coupon.getCouponName());
|
couponVO.setMoney(coupon.getMoney());
|
couponVO.setReduction(coupon.getReduction());
|
couponVO.setCouponId(couponReceive.getCouponId());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
String format1 = format.format(couponReceive.getStartTime());
|
couponVO.setStartTime(format1);
|
String format2 = format.format(couponReceive.getEndTime());
|
couponVO.setEndTime(format2);
|
couponVO.setState(couponReceive.getState());
|
res.add(couponVO);
|
}
|
return ResultUtil.success(res);
|
}
|
|
@ResponseBody
|
@PostMapping("/base/appUser/withdrawal")
|
@ApiOperation(value = "提现记录", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(value = "年", name = "year", dataType = "int"),
|
@ApiImplicitParam(value = "月", name = "month", dataType = "int"),
|
@ApiImplicitParam(value = "页码,首页1", name = "pageNum", dataType = "int"),
|
@ApiImplicitParam(value = "页条数", name = "pageSize", dataType = "int"),
|
})
|
public ResultUtil<List<WithdtawalVO>> withdrawal(Integer year,Integer month,Integer pageNum,Integer pageSize) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
List<WithdtawalVO> withdtawalVOS = new ArrayList<>();
|
Wrapper<Withdrawal> eq1 = new EntityWrapper<Withdrawal>()
|
.eq("userId", appUser.getId());
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq1.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
List<String> strings = new ArrayList<>();
|
strings.add("insertTime");
|
eq1.orderDesc(strings);
|
|
List<Withdrawal> withdrawals = withdrawalService.selectList(eq1);
|
|
for (Withdrawal withdrawal : withdrawals) {
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String format1 = format.format(withdrawal.getInsertTime());
|
WithdtawalVO withdtawalVO = new WithdtawalVO();
|
withdtawalVO.setInsertTime(format1);
|
withdtawalVO.setAmount("¥"+withdrawal.getAmount());
|
withdtawalVO.setReason(withdrawal.getReason());
|
switch (withdrawal.getState()){
|
case 1:
|
withdtawalVO.setState("待审核");
|
break;
|
case 2:
|
withdtawalVO.setState("已通过");
|
break;
|
case 3:
|
withdtawalVO.setState("已拒绝");
|
break;
|
}
|
withdtawalVOS.add(withdtawalVO);
|
}
|
List<WithdtawalVO> withdtawalVOS1 = testing2(withdtawalVOS.size(), pageNum, pageSize, withdtawalVOS);
|
return ResultUtil.success(withdtawalVOS1);
|
}
|
public static List<WithdtawalVO> testing2(long total, long current, long size, List<WithdtawalVO> str){
|
List<WithdtawalVO> result = new ArrayList<>();
|
//获取初始化分页结构
|
com.stylefeng.guns.modular.system.util.Page<WithdtawalVO> page = new Page().getPage(total, size, current - 1);
|
//获取集合下标初始值
|
long startIndex = page.getStartIndex();
|
//获取集合下标结束值
|
long endInddex = 0;
|
if(startIndex + page.getCurrent() >= total || size > total){
|
endInddex = total;
|
}else {
|
endInddex = Math.min(startIndex + page.getSize(), total);
|
}
|
//如果输入的开始查询下标大于集合大小,则查询为空值
|
if(startIndex > total){
|
result = Collections.emptyList();
|
}else{
|
result = str.subList((int)startIndex,(int)endInddex);
|
}
|
return result;
|
}
|
@ResponseBody
|
@PostMapping("/base/appUser/wallet")
|
@ApiOperation(value = "我的钱包", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(value = "年", name = "year", dataType = "int"),
|
@ApiImplicitParam(value = "月", name = "month", dataType = "int"),
|
@ApiImplicitParam(value = "页码,首页1", name = "pageNum", dataType = "int"),
|
@ApiImplicitParam(value = "页条数", name = "pageSize", dataType = "int"),
|
})
|
public ResultUtil<WalletVO> wallet(Integer year,Integer month,Integer pageNum,Integer pageSize) {
|
WalletVO walletVO = new WalletVO();
|
List<UserDetailVO> detail = new ArrayList<>();
|
AppUser appUser3 = appUserService.getAppUser();
|
if (appUser3 == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
Integer id = appUserService.getAppUser().getId();
|
BigDecimal balance = appUserService.getAppUser().getBalance();
|
walletVO.setBalance(balance);
|
Wrapper<Recharge> eq1 = new EntityWrapper<Recharge>()
|
.eq("userId", id)
|
.eq("state", 2);
|
// 如果传递了年份和月份,则添加时间条件
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq1.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
// 查询充值记录
|
List<Recharge> recharges = rechargeService.selectList(eq1);
|
for (Recharge recharge : recharges) {
|
UserDetailVO userDetailVO = new UserDetailVO();
|
userDetailVO.setAmount("+"+recharge.getAmount().toString());
|
userDetailVO.setType("充值");
|
userDetailVO.setInsertTime1(recharge.getInsertTime());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String format1 = format.format(recharge.getInsertTime());
|
userDetailVO.setInsertTime(format1);
|
detail.add(userDetailVO);
|
}
|
// 查询购课记录 只查询钱包支付的
|
Wrapper<OrderCourse> eq2 = new EntityWrapper<OrderCourse>()
|
.eq("userId", id)
|
// .eq("payType", 3)
|
.eq("state", 2);
|
// 如果传递了年份和月份,则添加时间条件
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq2.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
List<OrderCourse> orderCourses = orderCourseService.selectList(eq2);
|
for (OrderCourse orderCours : orderCourses) {
|
UserDetailVO userDetailVO = new UserDetailVO();
|
userDetailVO.setAmount("-"+orderCours.getRealMoney());
|
userDetailVO.setType("购买课程");
|
userDetailVO.setInsertTime1(orderCours.getInsertTime());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String format1 = format.format(orderCours.getInsertTime());
|
userDetailVO.setInsertTime(format1);
|
detail.add(userDetailVO);
|
}
|
Wrapper<Order> eq = new EntityWrapper<Order>()
|
.eq("userId", id)
|
// .eq("payType", 3)
|
.eq("state", 2);
|
|
// 如果传递了年份和月份,则添加时间条件
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
List<Order> orders = orderService.selectList(eq);
|
// 查询购买套餐记录 只查询钱包支付的
|
|
for (Order order : orders) {
|
UserDetailVO userDetailVO = new UserDetailVO();
|
userDetailVO.setAmount("-"+order.getRealMoney());
|
userDetailVO.setType("购买套餐");
|
userDetailVO.setInsertTime1(order.getInsertTime());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String format1 = format.format(order.getInsertTime());
|
userDetailVO.setInsertTime(format1);
|
detail.add(userDetailVO);
|
}
|
// 查询提现记录
|
Wrapper<Withdrawal> eq3 = new EntityWrapper<Withdrawal>()
|
.eq("userId", id);
|
// 如果传递了年份和月份,则添加时间条件
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq3.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
List<Withdrawal> withdrawals = withdrawalService.selectList(eq3);
|
for (Withdrawal withdrawal : withdrawals) {
|
UserDetailVO userDetailVO = new UserDetailVO();
|
switch (withdrawal.getState()){
|
case 1:
|
userDetailVO.setAmount("-"+withdrawal.getAmount());
|
userDetailVO.setType("提现");
|
break;
|
case 2:
|
userDetailVO.setAmount("-"+withdrawal.getAmount());
|
userDetailVO.setType("提现");
|
break;
|
case 3:
|
userDetailVO.setAmount("+"+withdrawal.getAmount());
|
userDetailVO.setType("提现失败");
|
break;
|
}
|
userDetailVO.setInsertTime1(withdrawal.getInsertTime());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String format1 = format.format(withdrawal.getInsertTime());
|
userDetailVO.setInsertTime(format1);
|
detail.add(userDetailVO);
|
}
|
// 查询是否有邀请过用户 获得消费奖励
|
Wrapper<Invite> eq4 = new EntityWrapper<Invite>()
|
.eq("giftUserId", id);
|
// 如果传递了年份和月份,则添加时间条件
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq4.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
eq4.eq("type",1);
|
List<Invite> giftUserId = inviteService.selectList(eq4);
|
for (Invite invite : giftUserId) {
|
UserDetailVO userDetailVO = new UserDetailVO();
|
userDetailVO.setAmount("+"+invite.getAmount());
|
AppUser appUser = appUserService.selectById(invite.getUserId());
|
userDetailVO.setType("好友消费:("+appUser.getName()+"消费了"+invite.getConsume()+"元)");
|
userDetailVO.setInsertTime1(invite.getInsertTime());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String format1 = format.format(invite.getInsertTime());
|
userDetailVO.setInsertTime(format1);
|
detail.add(userDetailVO);
|
}
|
// 查询红包发放记录
|
Wrapper<RedPackage> eq5 = new EntityWrapper<RedPackage>();
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq5.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
List<RedPackage> redPackages = redPackageService.selectList(eq5);
|
for (RedPackage redPackage : redPackages) {
|
if (appUserService.getAppUser().getInsertTime().compareTo(redPackage.getInsertTime())>0){
|
continue;
|
}
|
UserDetailVO userDetailVO = new UserDetailVO();
|
userDetailVO.setAmount("+"+redPackage.getAmount());
|
userDetailVO.setType("平台红包");
|
userDetailVO.setInsertTime1(redPackage.getInsertTime());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String format1 = format.format(redPackage.getInsertTime());
|
userDetailVO.setInsertTime(format1);
|
detail.add(userDetailVO);
|
}
|
List<UserDetailVO> sortedList = detail.stream()
|
.sorted(Comparator.comparing(UserDetailVO::getInsertTime1).reversed())
|
.collect(Collectors.toList());
|
List<UserDetailVO> testing = testing(sortedList.size(), pageNum, pageSize, sortedList);
|
walletVO.setDetails(testing);
|
return ResultUtil.success(walletVO);
|
}
|
@ResponseBody
|
@PostMapping("/base/appUser/appleWallet")
|
@ApiOperation(value = "苹果佣金列表(提现 好友消费 佣金 充值 平台红包)", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(value = "年", name = "year", dataType = "int"),
|
@ApiImplicitParam(value = "月", name = "month", dataType = "int"),
|
@ApiImplicitParam(value = "页码,首页1", name = "pageNum", dataType = "int"),
|
@ApiImplicitParam(value = "页条数", name = "pageSize", dataType = "int"),
|
@ApiImplicitParam(value = "类型 1=提现 2=好友消费 3=佣金 4=充值 5=平台红包", name = "type"),
|
})
|
public ResultUtil<WalletVO> appleWallet(Integer year,Integer month,Integer pageNum,Integer pageSize,String type) {
|
WalletVO walletVO = new WalletVO();
|
List<UserDetailVO> detail = new ArrayList<>();
|
AppUser appUser3 = appUserService.getAppUser();
|
if (appUser3 == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
Integer id = appUserService.getAppUser().getId();
|
BigDecimal balance = appUserService.getAppUser().getBalance();
|
walletVO.setBalance(balance);
|
if (!StringUtils.hasLength(type)){
|
// 查询全部
|
Wrapper<Recharge> eq1 = new EntityWrapper<Recharge>()
|
.eq("userId", id)
|
.eq("state", 2);
|
// 如果传递了年份和月份,则添加时间条件
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq1.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
// 查询充值记录
|
List<Recharge> recharges = rechargeService.selectList(eq1);
|
for (Recharge recharge : recharges) {
|
UserDetailVO userDetailVO = new UserDetailVO();
|
userDetailVO.setAmount("+"+recharge.getAmount().toString());
|
userDetailVO.setType("充值");
|
userDetailVO.setInsertTime1(recharge.getInsertTime());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String format1 = format.format(recharge.getInsertTime());
|
userDetailVO.setInsertTime(format1);
|
detail.add(userDetailVO);
|
}
|
// 查询购课记录 只查询钱包支付的
|
Wrapper<OrderCourse> eq2 = new EntityWrapper<OrderCourse>()
|
.eq("userId", id)
|
// .eq("payType", 3)
|
.eq("state", 2);
|
// 如果传递了年份和月份,则添加时间条件
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq2.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
// List<OrderCourse> orderCourses = orderCourseService.selectList(eq2);
|
// for (OrderCourse orderCours : orderCourses) {
|
// UserDetailVO userDetailVO = new UserDetailVO();
|
// userDetailVO.setAmount("-"+orderCours.getRealMoney());
|
// userDetailVO.setType("购买课程");
|
// userDetailVO.setInsertTime1(orderCours.getInsertTime());
|
// SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
// String format1 = format.format(orderCours.getInsertTime());
|
// userDetailVO.setInsertTime(format1);
|
// detail.add(userDetailVO);
|
// }
|
Wrapper<Order> eq = new EntityWrapper<Order>()
|
.eq("userId", id)
|
// .eq("payType", 3)
|
.eq("state", 2);
|
|
// 如果传递了年份和月份,则添加时间条件
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
// List<Order> orders = orderService.selectList(eq);
|
// 查询购买套餐记录 只查询钱包支付的
|
|
// for (Order order : orders) {
|
// UserDetailVO userDetailVO = new UserDetailVO();
|
// userDetailVO.setAmount("-"+order.getRealMoney());
|
// userDetailVO.setType("购买套餐");
|
// userDetailVO.setInsertTime1(order.getInsertTime());
|
// SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
// String format1 = format.format(order.getInsertTime());
|
// userDetailVO.setInsertTime(format1);
|
// detail.add(userDetailVO);
|
// }
|
// 查询提现记录
|
Wrapper<Withdrawal> eq3 = new EntityWrapper<Withdrawal>()
|
.eq("userId", id);
|
// 如果传递了年份和月份,则添加时间条件
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq3.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
List<Withdrawal> withdrawals = withdrawalService.selectList(eq3);
|
for (Withdrawal withdrawal : withdrawals) {
|
UserDetailVO userDetailVO = new UserDetailVO();
|
switch (withdrawal.getState()){
|
case 1:
|
userDetailVO.setAmount("-"+withdrawal.getAmount());
|
userDetailVO.setType("提现");
|
break;
|
case 2:
|
userDetailVO.setAmount("-"+withdrawal.getAmount());
|
userDetailVO.setType("提现");
|
break;
|
case 3:
|
userDetailVO.setAmount("+"+withdrawal.getAmount());
|
userDetailVO.setType("提现失败");
|
break;
|
}
|
userDetailVO.setInsertTime1(withdrawal.getInsertTime());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String format1 = format.format(withdrawal.getInsertTime());
|
userDetailVO.setInsertTime(format1);
|
detail.add(userDetailVO);
|
}
|
// 查询是否有邀请过用户 获得消费奖励
|
Wrapper<Invite> eq4 = new EntityWrapper<Invite>()
|
.eq("giftUserId", id);
|
// 如果传递了年份和月份,则添加时间条件
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq4.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
eq4.eq("type",1);
|
List<Invite> giftUserId = inviteService.selectList(eq4);
|
for (Invite invite : giftUserId) {
|
UserDetailVO userDetailVO = new UserDetailVO();
|
userDetailVO.setAmount("+"+invite.getAmount());
|
AppUser appUser = appUserService.selectById(invite.getUserId());
|
userDetailVO.setType("好友消费:("+appUser.getName()+"消费了"+invite.getConsume()+"元)");
|
userDetailVO.setInsertTime1(invite.getInsertTime());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String format1 = format.format(invite.getInsertTime());
|
userDetailVO.setInsertTime(format1);
|
detail.add(userDetailVO);
|
}
|
// 查询红包发放记录
|
Wrapper<RedPackage> eq5 = new EntityWrapper<RedPackage>();
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq5.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
List<RedPackage> redPackages = redPackageService.selectList(eq5);
|
for (RedPackage redPackage : redPackages) {
|
if (appUserService.getAppUser().getInsertTime().compareTo(redPackage.getInsertTime())>0){
|
continue;
|
}
|
UserDetailVO userDetailVO = new UserDetailVO();
|
userDetailVO.setAmount("+"+redPackage.getAmount());
|
userDetailVO.setType("平台红包");
|
userDetailVO.setInsertTime1(redPackage.getInsertTime());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String format1 = format.format(redPackage.getInsertTime());
|
userDetailVO.setInsertTime(format1);
|
detail.add(userDetailVO);
|
}
|
List<UserDetailVO> sortedList = detail.stream()
|
.sorted(Comparator.comparing(UserDetailVO::getInsertTime1).reversed())
|
.collect(Collectors.toList());
|
List<UserDetailVO> testing = testing(sortedList.size(), pageNum, pageSize, sortedList);
|
walletVO.setDetails(testing);
|
return ResultUtil.success(walletVO);
|
}else{
|
String[] split = type.split(",");
|
List<String> collect = Arrays.stream(split).collect(Collectors.toList());
|
if (collect.contains("1")){
|
// 查询提现记录
|
Wrapper<Withdrawal> eq3 = new EntityWrapper<Withdrawal>()
|
.eq("userId", id);
|
// 如果传递了年份和月份,则添加时间条件
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq3.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
List<Withdrawal> withdrawals = withdrawalService.selectList(eq3);
|
for (Withdrawal withdrawal : withdrawals) {
|
UserDetailVO userDetailVO = new UserDetailVO();
|
switch (withdrawal.getState()){
|
case 1:
|
userDetailVO.setAmount("-"+withdrawal.getAmount());
|
userDetailVO.setType("提现");
|
break;
|
case 2:
|
userDetailVO.setAmount("-"+withdrawal.getAmount());
|
userDetailVO.setType("提现");
|
break;
|
case 3:
|
userDetailVO.setAmount("+"+withdrawal.getAmount());
|
userDetailVO.setType("提现失败");
|
break;
|
}
|
userDetailVO.setInsertTime1(withdrawal.getInsertTime());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String format1 = format.format(withdrawal.getInsertTime());
|
userDetailVO.setInsertTime(format1);
|
detail.add(userDetailVO);
|
}
|
}
|
if (collect.contains("2")){
|
// 查询是否有邀请过用户 获得消费奖励
|
Wrapper<Invite> eq4 = new EntityWrapper<Invite>()
|
.eq("giftUserId", id);
|
// 如果传递了年份和月份,则添加时间条件
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq4.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
eq4.eq("type",1);
|
List<Invite> giftUserId = inviteService.selectList(eq4);
|
for (Invite invite : giftUserId) {
|
UserDetailVO userDetailVO = new UserDetailVO();
|
userDetailVO.setAmount("+"+invite.getAmount());
|
AppUser appUser = appUserService.selectById(invite.getUserId());
|
userDetailVO.setType("好友消费:("+appUser.getName()+"消费了"+invite.getConsume()+"元)");
|
userDetailVO.setInsertTime1(invite.getInsertTime());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String format1 = format.format(invite.getInsertTime());
|
userDetailVO.setInsertTime(format1);
|
detail.add(userDetailVO);
|
}
|
}
|
if (collect.contains("3")){
|
// 查询是否有邀请过用户 获得消费奖励
|
Wrapper<Invite> eq4 = new EntityWrapper<Invite>()
|
.eq("giftUserId", id);
|
// 如果传递了年份和月份,则添加时间条件
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq4.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
eq4.eq("type",1);
|
List<Invite> giftUserId = inviteService.selectList(eq4);
|
for (Invite invite : giftUserId) {
|
UserDetailVO userDetailVO = new UserDetailVO();
|
userDetailVO.setAmount("+"+invite.getAmount());
|
AppUser appUser = appUserService.selectById(invite.getUserId());
|
userDetailVO.setType("好友消费:("+appUser.getName()+"消费了"+invite.getConsume()+"元)");
|
userDetailVO.setInsertTime1(invite.getInsertTime());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String format1 = format.format(invite.getInsertTime());
|
userDetailVO.setInsertTime(format1);
|
detail.add(userDetailVO);
|
}
|
}
|
if (collect.contains("4")){
|
Wrapper<Recharge> eq1 = new EntityWrapper<Recharge>()
|
.eq("userId", id)
|
.eq("state", 2);
|
// 如果传递了年份和月份,则添加时间条件
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq1.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
// 查询充值记录
|
List<Recharge> recharges = rechargeService.selectList(eq1);
|
for (Recharge recharge : recharges) {
|
UserDetailVO userDetailVO = new UserDetailVO();
|
userDetailVO.setAmount("+"+recharge.getAmount().toString());
|
userDetailVO.setType("充值");
|
userDetailVO.setInsertTime1(recharge.getInsertTime());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String format1 = format.format(recharge.getInsertTime());
|
userDetailVO.setInsertTime(format1);
|
detail.add(userDetailVO);
|
}
|
}
|
if (collect.contains("5")){
|
// 查询红包发放记录
|
Wrapper<RedPackage> eq5 = new EntityWrapper<RedPackage>();
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq5.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
List<RedPackage> redPackages = redPackageService.selectList(eq5);
|
for (RedPackage redPackage : redPackages) {
|
if (appUserService.getAppUser().getInsertTime().compareTo(redPackage.getInsertTime())>0){
|
continue;
|
}
|
UserDetailVO userDetailVO = new UserDetailVO();
|
userDetailVO.setAmount("+"+redPackage.getAmount());
|
userDetailVO.setType("平台红包");
|
userDetailVO.setInsertTime1(redPackage.getInsertTime());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String format1 = format.format(redPackage.getInsertTime());
|
userDetailVO.setInsertTime(format1);
|
detail.add(userDetailVO);
|
}
|
}
|
List<UserDetailVO> sortedList = detail.stream()
|
.sorted(Comparator.comparing(UserDetailVO::getInsertTime1).reversed())
|
.collect(Collectors.toList());
|
List<UserDetailVO> testing = testing(sortedList.size(), pageNum, pageSize, sortedList);
|
walletVO.setDetails(testing);
|
return ResultUtil.success(walletVO);
|
}
|
}
|
@ResponseBody
|
@PostMapping("/base/appUser/appleWalletCourse")
|
@ApiOperation(value = "苹果购课、购买套餐列表", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(value = "年", name = "year", dataType = "int"),
|
@ApiImplicitParam(value = "月", name = "month", dataType = "int"),
|
@ApiImplicitParam(value = "页码,首页1", name = "pageNum", dataType = "int"),
|
@ApiImplicitParam(value = "页条数", name = "pageSize", dataType = "int"),
|
})
|
public ResultUtil<WalletVO> appleWalletCourse(Integer year,Integer month,Integer pageNum,Integer pageSize) {
|
WalletVO walletVO = new WalletVO();
|
List<UserDetailVO> detail = new ArrayList<>();
|
AppUser appUser3 = appUserService.getAppUser();
|
if (appUser3 == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
Integer id = appUserService.getAppUser().getId();
|
BigDecimal balance = appUserService.getAppUser().getBalance();
|
walletVO.setBalance(balance);
|
Wrapper<Recharge> eq1 = new EntityWrapper<Recharge>()
|
.eq("userId", id)
|
.eq("state", 2);
|
// 如果传递了年份和月份,则添加时间条件
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq1.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
// 查询充值记录
|
// List<Recharge> recharges = rechargeService.selectList(eq1);
|
// for (Recharge recharge : recharges) {
|
// UserDetailVO userDetailVO = new UserDetailVO();
|
// userDetailVO.setAmount("+"+recharge.getAmount().toString());
|
// userDetailVO.setType("充值");
|
// userDetailVO.setInsertTime1(recharge.getInsertTime());
|
// SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
// String format1 = format.format(recharge.getInsertTime());
|
// userDetailVO.setInsertTime(format1);
|
// detail.add(userDetailVO);
|
// }
|
// 查询购课记录 只查询钱包支付的
|
Wrapper<OrderCourse> eq2 = new EntityWrapper<OrderCourse>()
|
.eq("userId", id)
|
// .eq("payType", 3)
|
.eq("state", 2);
|
// 如果传递了年份和月份,则添加时间条件
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq2.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
List<OrderCourse> orderCourses = orderCourseService.selectList(eq2);
|
for (OrderCourse orderCours : orderCourses) {
|
UserDetailVO userDetailVO = new UserDetailVO();
|
userDetailVO.setAmount("-"+orderCours.getRealMoney());
|
userDetailVO.setType("购买课程");
|
userDetailVO.setInsertTime1(orderCours.getInsertTime());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String format1 = format.format(orderCours.getInsertTime());
|
userDetailVO.setInsertTime(format1);
|
detail.add(userDetailVO);
|
}
|
Wrapper<Order> eq = new EntityWrapper<Order>()
|
.eq("userId", id)
|
// .eq("payType", 3)
|
.eq("state", 2);
|
|
// 如果传递了年份和月份,则添加时间条件
|
if (year != null && month != null) {
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
eq.ge("insertTime", startDate).le("insertTime", endDate);
|
}
|
List<Order> orders = orderService.selectList(eq);
|
// 查询购买套餐记录 只查询钱包支付的
|
for (Order order : orders) {
|
UserDetailVO userDetailVO = new UserDetailVO();
|
userDetailVO.setAmount("-"+order.getRealMoney());
|
userDetailVO.setType("购买套餐");
|
userDetailVO.setInsertTime1(order.getInsertTime());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
String format1 = format.format(order.getInsertTime());
|
userDetailVO.setInsertTime(format1);
|
detail.add(userDetailVO);
|
}
|
// 查询提现记录
|
// Wrapper<Withdrawal> eq3 = new EntityWrapper<Withdrawal>()
|
// .eq("userId", id);
|
// // 如果传递了年份和月份,则添加时间条件
|
// if (year != null && month != null) {
|
// LocalDate startDate = LocalDate.of(year, month, 1);
|
// LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
// eq3.ge("insertTime", startDate).le("insertTime", endDate);
|
// }
|
// List<Withdrawal> withdrawals = withdrawalService.selectList(eq3);
|
// for (Withdrawal withdrawal : withdrawals) {
|
// UserDetailVO userDetailVO = new UserDetailVO();
|
// switch (withdrawal.getState()){
|
// case 1:
|
// userDetailVO.setAmount("-"+withdrawal.getAmount());
|
// userDetailVO.setType("提现");
|
// break;
|
// case 2:
|
// userDetailVO.setAmount("-"+withdrawal.getAmount());
|
// userDetailVO.setType("提现");
|
// break;
|
// case 3:
|
// userDetailVO.setAmount("+"+withdrawal.getAmount());
|
// userDetailVO.setType("提现失败");
|
// break;
|
// }
|
// userDetailVO.setInsertTime1(withdrawal.getInsertTime());
|
// SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
// String format1 = format.format(withdrawal.getInsertTime());
|
// userDetailVO.setInsertTime(format1);
|
// detail.add(userDetailVO);
|
// }
|
// 查询是否有邀请过用户 获得消费奖励
|
// Wrapper<Invite> eq4 = new EntityWrapper<Invite>()
|
// .eq("giftUserId", id);
|
// // 如果传递了年份和月份,则添加时间条件
|
// if (year != null && month != null) {
|
// LocalDate startDate = LocalDate.of(year, month, 1);
|
// LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
// eq4.ge("insertTime", startDate).le("insertTime", endDate);
|
// }
|
// eq4.eq("type",1);
|
// List<Invite> giftUserId = inviteService.selectList(eq4);
|
// for (Invite invite : giftUserId) {
|
// UserDetailVO userDetailVO = new UserDetailVO();
|
// userDetailVO.setAmount("+"+invite.getAmount());
|
// AppUser appUser = appUserService.selectById(invite.getUserId());
|
// userDetailVO.setType("好友消费:("+appUser.getName()+"消费了"+invite.getConsume()+"元)");
|
// userDetailVO.setInsertTime1(invite.getInsertTime());
|
// SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
// String format1 = format.format(invite.getInsertTime());
|
// userDetailVO.setInsertTime(format1);
|
// detail.add(userDetailVO);
|
// }
|
// 查询红包发放记录
|
// Wrapper<RedPackage> eq5 = new EntityWrapper<RedPackage>();
|
// if (year != null && month != null) {
|
// LocalDate startDate = LocalDate.of(year, month, 1);
|
// LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
// eq5.ge("insertTime", startDate).le("insertTime", endDate);
|
// }
|
// List<RedPackage> redPackages = redPackageService.selectList(eq5);
|
// for (RedPackage redPackage : redPackages) {
|
// if (appUserService.getAppUser().getInsertTime().compareTo(redPackage.getInsertTime())>0){
|
// continue;
|
// }
|
// UserDetailVO userDetailVO = new UserDetailVO();
|
// userDetailVO.setAmount("+"+redPackage.getAmount());
|
// userDetailVO.setType("平台红包");
|
// userDetailVO.setInsertTime1(redPackage.getInsertTime());
|
// SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
// String format1 = format.format(redPackage.getInsertTime());
|
// userDetailVO.setInsertTime(format1);
|
// detail.add(userDetailVO);
|
// }
|
List<UserDetailVO> sortedList = detail.stream()
|
.sorted(Comparator.comparing(UserDetailVO::getInsertTime1).reversed())
|
.collect(Collectors.toList());
|
List<UserDetailVO> testing = testing(sortedList.size(), pageNum, pageSize, sortedList);
|
walletVO.setDetails(testing);
|
return ResultUtil.success(walletVO);
|
}
|
public static List<UserDetailVO> testing(long total, long current, long size, List<UserDetailVO> str){
|
List<UserDetailVO> result = new ArrayList<>();
|
//获取初始化分页结构
|
com.stylefeng.guns.modular.system.util.Page<UserDetailVO> page = new Page().getPage(total, size, current - 1);
|
//获取集合下标初始值
|
long startIndex = page.getStartIndex();
|
//获取集合下标结束值
|
long endInddex = 0;
|
if(startIndex + page.getCurrent() >= total || size > total){
|
endInddex = total;
|
}else {
|
endInddex = Math.min(startIndex + page.getSize(), total);
|
}
|
//如果输入的开始查询下标大于集合大小,则查询为空值
|
if(startIndex > total){
|
result = Collections.emptyList();
|
}else{
|
result = str.subList((int)startIndex,(int)endInddex);
|
}
|
return result;
|
}
|
|
@ResponseBody
|
@PostMapping("/base/appUser/changeConstellation")
|
@ApiOperation(value = "切换星座", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(value = "星座名称(狮子座)", name = "consName"),
|
})
|
public ResultUtil changeConstellation(String consName ) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
appUser.setConstellation(consName);
|
appUserService.updateById(appUser);
|
return ResultUtil.success();
|
}
|
public static String getZodiacSign(int month, int day) {
|
if ((month == 3 && day >= 21) || (month == 4 && day <= 19)) {
|
return "白羊座";
|
} else if ((month == 4 && day >= 20) || (month == 5 && day <= 20)) {
|
return "金牛座";
|
} else if ((month == 5 && day >= 21) || (month == 6 && day <= 20)) {
|
return "双子座";
|
} else if ((month == 6 && day >= 21) || (month == 7 && day <= 22)) {
|
return "巨蟹座";
|
} else if ((month == 7 && day >= 23) || (month == 8 && day <= 22)) {
|
return "狮子座";
|
} else if ((month == 8 && day >= 23) || (month == 9 && day <= 22)) {
|
return "处女座";
|
} else if ((month == 9 && day >= 23) || (month == 10 && day <= 22)) {
|
return "天秤座";
|
} else if ((month == 10 && day >= 23) || (month == 11 && day <= 21)) {
|
return "天蝎座";
|
} else if ((month == 11 && day >= 22) || (month == 12 && day <= 21)) {
|
return "射手座";
|
} else if ((month == 12 && day >= 22) || (month == 1 && day <= 19)) {
|
return "摩羯座";
|
} else if ((month == 1 && day >= 20) || (month == 2 && day <= 18)) {
|
return "水瓶座";
|
} else {
|
return "双鱼座";
|
}
|
}
|
@ResponseBody
|
@PostMapping("/base/appUser/constellation")
|
@ApiOperation(value = "星座运势", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(value = "星座名称(狮子座)", name = "consName"),
|
@ApiImplicitParam(value = "类型 today=今日 tomorrow=明日 week=本周 month=本月 year=本年 ", name = "type",required = true)
|
})
|
public ResultUtil<ConstellationVO> constellation(String consName,String type ) {
|
// 没有指定星座 那么查询当月星座
|
LocalDate currentDate = LocalDate.now();
|
int month = currentDate.getMonthValue();
|
int day = currentDate.getDayOfMonth();
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
if (!StringUtils.hasLength(appUser.getConstellation())){
|
// 根据月份和日期确定星座
|
consName = getZodiacSign(month, day);
|
}
|
if (!StringUtils.hasLength(consName)){
|
ConstellationVO constellation = getConstellation(appUser.getConstellation(), type);
|
constellation.setName(consName);
|
return ResultUtil.success(constellation);
|
}else {
|
ConstellationVO constellation = getConstellation(consName, type);
|
appUser.setConstellation(consName);
|
constellation.setName(consName);
|
// appUserService.updateById(appUser);
|
return ResultUtil.success(constellation);
|
}
|
}
|
@ResponseBody
|
@PostMapping("/base/appUser/deleteFind")
|
@ApiOperation(value = "删除动态", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(value = "动态id", name = "findId", dataType = "int"),
|
})
|
public ResultUtil feedBack(Integer findId) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
Find find = findService.selectById(findId);
|
find.setIsDelete(1);
|
findService.updateById(find);
|
return ResultUtil.success("删除成功");
|
}
|
|
@ResponseBody
|
@PostMapping("/base/appUser/myFind")
|
@ApiOperation(value = "我的动态", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(value = "页码,首页1", name = "pageNum", dataType = "int"),
|
@ApiImplicitParam(value = "页条数", name = "pageSize", dataType = "int")
|
})
|
public ResultUtil<List<FindVO>> myFind(Integer pageNum,Integer pageSize) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
Integer id = appUserService.getAppUser().getId();
|
|
List<String> strings = new ArrayList<>();
|
strings.add("insertTime");
|
List<Find> finds = findService.selectList(new EntityWrapper<Find>()
|
.eq("userId", id)
|
.eq("state", 1)
|
.orderDesc(strings)
|
.eq("isDelete", 0));
|
List<FindVO> res = new ArrayList<>();
|
for (Find find : finds) {
|
FindVO temp = new FindVO();
|
BeanUtils.copyProperties(find,temp);
|
// 计算每个动态的评论数量
|
int size = findCommentService.selectList(new EntityWrapper<FindComment>()
|
.eq("findId", find.getId())
|
.eq("isShow", 1)).size();
|
temp.setComment(size);
|
temp.setClockIn(appUser.getClockIn());
|
temp.setHeadImg(appUser.getHeadImg());
|
temp.setUserName(appUser.getName());
|
res.add(temp);
|
}
|
List<FindVO> findVOS = testing3(res.size(), pageNum, pageSize, res);
|
return ResultUtil.success(findVOS);
|
}
|
public static List<BlackListVO> testing4(long total, long current, long size, List<BlackListVO> str){
|
List<BlackListVO> result = new ArrayList<>();
|
//获取初始化分页结构
|
com.stylefeng.guns.modular.system.util.Page<BlackListVO> page = new Page().getPage(total, size, current - 1);
|
//获取集合下标初始值
|
long startIndex = page.getStartIndex();
|
//获取集合下标结束值
|
long endInddex = 0;
|
if(startIndex + page.getCurrent() >= total || size > total){
|
endInddex = total;
|
}else {
|
endInddex = Math.min(startIndex + page.getSize(), total);
|
}
|
//如果输入的开始查询下标大于集合大小,则查询为空值
|
if(startIndex > total){
|
result = Collections.emptyList();
|
}else{
|
result = str.subList((int)startIndex,(int)endInddex);
|
}
|
return result;
|
}
|
public static List<FindVO> testing3(long total, long current, long size, List<FindVO> str){
|
List<FindVO> result = new ArrayList<>();
|
//获取初始化分页结构
|
com.stylefeng.guns.modular.system.util.Page<FindVO> page = new Page().getPage(total, size, current - 1);
|
//获取集合下标初始值
|
long startIndex = page.getStartIndex();
|
//获取集合下标结束值
|
long endInddex = 0;
|
if(startIndex + page.getCurrent() >= total || size > total){
|
endInddex = total;
|
}else {
|
endInddex = Math.min(startIndex + page.getSize(), total);
|
}
|
//如果输入的开始查询下标大于集合大小,则查询为空值
|
if(startIndex > total){
|
result = Collections.emptyList();
|
}else{
|
result = str.subList((int)startIndex,(int)endInddex);
|
}
|
return result;
|
}
|
@ResponseBody
|
@PostMapping("/base/appUser/useGuide")
|
@ApiOperation(value = "使用指南", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(name = "title", value = "标题"),
|
})
|
public ResultUtil<List<UseGuide>> useGuide(String title) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
EntityWrapper<UseGuide> wrapper = new EntityWrapper<>();
|
List<String> strings = new ArrayList<>();
|
strings.add("sort");
|
wrapper.orderDesc(strings);
|
if (StringUtils.hasLength(title)){
|
wrapper.like("title",title);
|
}
|
wrapper.eq("isDelete",0);
|
List<UseGuide> useGuides = useGuideService.selectList(wrapper);
|
return ResultUtil.success(useGuides);
|
}
|
@ResponseBody
|
@PostMapping("/base/appUser/setUnit")
|
@ApiOperation(value = "设置APP体重单位", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(name = "type", value = "1公斤 2斤 3磅 ", required = true),
|
})
|
public ResultUtil setUnit(Integer type) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
appUser.setUnit(type);
|
appUserService.updateById(appUser);
|
return ResultUtil.success("设置成功");
|
}
|
@ResponseBody
|
@PostMapping("/base/appUser/setWeight")
|
@ApiOperation(value = "记录体重/设置目标体重", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(name = "type", value = "1=设置目标体重 2=记录体重 ", required = true),
|
@ApiImplicitParam(name = "weight", value = "体重")
|
})
|
public ResultUtil setWeight(Integer type ,Double weight) {
|
Double temp = 0.0;
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
switch (appUser.getUnit()){
|
case 1:
|
temp = weight;
|
break;
|
case 2:
|
temp = weight/2;
|
break;
|
case 3:
|
temp = weight*0.45;
|
break;
|
}
|
switch (type){
|
case 1:
|
appUser.setTarget(temp);
|
appUserService.updateById(appUser);
|
break;
|
case 2:
|
// 如果首次记录
|
if (appUser.getWeight() == null || appUser.getWeight() == 0){
|
appUser.setWeight(temp);
|
appUser.setRecordTime(new Date());
|
appUserService.updateById(appUser);
|
UserRecord userRecord = new UserRecord();
|
userRecord.setUserId(appUser.getId());
|
userRecord.setRecordTime(new Date());
|
userRecord.setWeight(temp);
|
recordService.insert(userRecord);
|
}else{
|
// 如果是第二次记录
|
Double weight1 = appUser.getWeight();
|
appUser.setBeforeWeight(weight1);
|
appUser.setWeight(temp);
|
appUser.setRecordTime(new Date());
|
appUserService.updateById(appUser);
|
// 添加历史记录
|
UserRecord userRecord = new UserRecord();
|
userRecord.setUserId(appUser.getId());
|
userRecord.setRecordTime(new Date());
|
userRecord.setWeight(temp);
|
recordService.insert(userRecord);
|
}
|
break;
|
}
|
return ResultUtil.success("设置成功");
|
}
|
|
@Autowired
|
private AuditUtil auditUtil;
|
@ResponseBody
|
@PostMapping("/base/appUser/feedBack")
|
@ApiOperation(value = "反馈与建议", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(name = "content", value = "反馈内容", required = true),
|
@ApiImplicitParam(name = "img", value = "图片地址,多张逗号隔开")
|
})
|
public ResultUtil feedBack(String content,String img) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
AuditVO content1 = auditUtil.content(content);
|
switch (content1.getType()){
|
case "terrorism":
|
return ResultUtil.error("反馈内容涉及暴恐");
|
case "porn":
|
return ResultUtil.error("反馈内容涉及色情");
|
case "ban":
|
return ResultUtil.error("反馈内容违禁");
|
case "abuse":
|
return ResultUtil.error("反馈内容涉及辱骂");
|
case "ad":
|
return ResultUtil.error("反馈内容涉及广告");
|
case "politics":
|
return ResultUtil.error("反馈内容涉及政治");
|
}
|
Feedback feedback = new Feedback();
|
feedback.setUserId(appUserService.getAppUser().getId());
|
feedback.setContent(content);
|
feedback.setImg(img);
|
feedback.setInsertTime(new Date());
|
feedbackService.insert(feedback);
|
return ResultUtil.success("反馈成功");
|
}
|
|
|
@ResponseBody
|
@PostMapping("/base/appUser/userInfo")
|
@ApiOperation(value = "主页", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
|
})
|
public ResultUtil<UserInfoVO> userInfo() {
|
UserInfoVO userInfoVO = new UserInfoVO();
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
userInfoVO.setConstellation(appUser.getConstellation());
|
BeanUtils.copyProperties(appUser,userInfoVO);
|
if (appUser.getConstellation() == null){
|
LocalDate currentDate = LocalDate.now();
|
int month = currentDate.getMonthValue();
|
int day = currentDate.getDayOfMonth();
|
String zodiacSign = getZodiacSign(month, day);
|
userInfoVO.setConstellation(zodiacSign);
|
}
|
|
switch (appUser.getUnit()){
|
case 2:
|
if (userInfoVO.getWeight()!=null){
|
userInfoVO.setWeight(userInfoVO.getWeight()*2);
|
}
|
if (userInfoVO.getTarget()!=null){
|
userInfoVO.setTarget(userInfoVO.getTarget()*2);
|
}
|
break;
|
case 3:
|
if (userInfoVO.getWeight()!=null){
|
DecimalFormat df = new DecimalFormat("#.##");
|
// 设置四舍五入模式为 HALF_UP
|
df.setRoundingMode(RoundingMode.HALF_UP);
|
double v = userInfoVO.getWeight() / 0.45;
|
// 使用 DecimalFormat 对象进行四舍五入
|
double roundedNumber = Double.parseDouble(df.format(v));
|
userInfoVO.setWeight(roundedNumber);
|
}
|
if (userInfoVO.getTarget()!=null){
|
DecimalFormat df = new DecimalFormat("#.##");
|
// 设置四舍五入模式为 HALF_UP
|
df.setRoundingMode(RoundingMode.HALF_UP);
|
double v = userInfoVO.getTarget() / 0.45;
|
// 使用 DecimalFormat 对象进行四舍五入
|
double roundedNumber = Double.parseDouble(df.format(v));
|
userInfoVO.setTarget(roundedNumber);
|
}
|
break;
|
}
|
SimpleDateFormat format9 = new SimpleDateFormat("yyyy.MM.dd");
|
if (appUser.getBirthday() != null){
|
String format10 = format9.format(appUser.getBirthday());
|
userInfoVO.setBirthday(format10);
|
}
|
// 如果记录过体重 计算体重距离上次
|
if (appUser.getBeforeWeight()!=null){
|
switch (appUser.getUnit()){
|
case 1:
|
userInfoVO.setDistanceBefore(appUser.getWeight()-appUser.getBeforeWeight());
|
break;
|
case 2:
|
userInfoVO.setDistanceBefore((appUser.getWeight()*2)-(appUser.getBeforeWeight()*2));
|
break;
|
case 3:
|
DecimalFormat df = new DecimalFormat("#.##");
|
// 设置四舍五入模式为 HALF_UP
|
df.setRoundingMode(RoundingMode.HALF_UP);
|
double v = (appUser.getWeight()/0.45)-(appUser.getBeforeWeight()/0.45);
|
// 使用 DecimalFormat 对象进行四舍五入
|
double roundedNumber = Double.parseDouble(df.format(v));
|
userInfoVO.setDistanceBefore(roundedNumber);
|
break;
|
}
|
}else{
|
userInfoVO.setDistanceBefore(0.0);
|
}
|
// 如果记录了目标体重
|
if (appUser.getTarget()!=null && appUser.getWeight()!=null){
|
switch (appUser.getUnit()){
|
case 1:
|
userInfoVO.setDistanceTarget
|
(appUser.getWeight()-appUser.getTarget());
|
break;
|
case 2:
|
userInfoVO.setDistanceTarget
|
((appUser.getWeight()*2)-(appUser.getTarget()* 2));
|
break;
|
case 3:
|
DecimalFormat df = new DecimalFormat("#.##");
|
// 设置四舍五入模式为 HALF_UP
|
df.setRoundingMode(RoundingMode.HALF_UP);
|
double v = (appUser.getWeight() / 0.45)-(appUser.getTarget() / 0.45);
|
// 使用 DecimalFormat 对象进行四舍五入
|
double roundedNumber = Double.parseDouble(df.format(v));
|
userInfoVO.setDistanceTarget(roundedNumber);
|
|
break;
|
}
|
}else{
|
userInfoVO.setDistanceTarget(0.0);
|
}
|
Date date = new Date();
|
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");
|
String format1 = format.format(date);
|
userInfoVO.setNowDate(format1);
|
SimpleDateFormat format2 = new SimpleDateFormat("MM月dd日");
|
if (appUser.getRecordTime()!=null){
|
String format3 = format2.format(date);
|
userInfoVO.setRecordTime(format3);
|
}else{
|
userInfoVO.setRecordTime("暂无记录");
|
}
|
long ageInYears = 0;
|
|
if (appUser.getBirthday()!=null){
|
Date birthday = appUser.getBirthday();
|
// 获取当前时间的时间戳
|
long currentTime = System.currentTimeMillis();
|
// 获取出生日期的时间戳
|
long birthTime = birthday.getTime();
|
// 计算年龄差,转换为年份
|
long diff = currentTime - birthTime;
|
ageInYears = diff / (1000L * 60 * 60 * 24 * 365);
|
userInfoVO.setAge(ageInYears);
|
}
|
|
if (appUser.getWeight()== null){
|
userInfoVO.setWeight(0.00);
|
}
|
if (appUser.getHeight()== null){
|
userInfoVO.setHeight(0);
|
}
|
if (appUser.getHeight()!=null && appUser.getWeight()!=null && appUser.getGender()!=null ){
|
System.err.println("userInfo:");
|
System.err.println(appUser.getHeight());
|
System.err.println(appUser.getGender());
|
System.err.println(appUser.getWeight());
|
// 获取当前BMI 20
|
BMIVO bmi = getBMI(userInfoVO, appUser.getHeight(), appUser.getGender(), appUser.getWeight());
|
userInfoVO.setBMIInfo(bmi.getMsg());
|
userInfoVO.setBMI(bmi.getBmi());
|
// 当前BMI
|
Double aDouble = Double.valueOf(bmi.getBmi());
|
if (appUser.getBeforeWeight()!=null){
|
// 如果记录过2次体重 计算BMI变化 18
|
BMIVO bmi1 = getBMI(userInfoVO, appUser.getHeight(), appUser.getGender(), appUser.getBeforeWeight());
|
Double aDouble1 = Double.valueOf(bmi1.getBmi());
|
double v = aDouble - aDouble1;
|
userInfoVO.setDistanceBMI(v);
|
}else{
|
userInfoVO.setDistanceBMI(0.0);
|
}
|
if (appUser.getWaistline()!=null){
|
// 计算体脂率
|
String bfr = getBfr(appUser.getGender(), appUser.getWeight(), appUser.getWaistline());
|
userInfoVO.setPercentage(bfr);
|
}
|
// 计算卡路里消耗量
|
if (appUser.getBirthday()==null){
|
long temp = 18;
|
String calorie = getCalorie(appUser.getHeight(), appUser.getWeight(), temp);
|
userInfoVO.setCalorie(calorie);
|
}else{
|
String calorie = getCalorie(appUser.getHeight(), appUser.getWeight(), ageInYears);
|
userInfoVO.setCalorie(calorie);
|
}
|
}
|
// 获取健康提示
|
String content = getContent();
|
userInfoVO.setTips(content);
|
// 获取健康指数
|
if (appUser.getBirthday()==null) {
|
long temp = 18;
|
String index = getIndex(appUser.getHeight(), appUser.getGender(), appUser.getWeight(), temp);
|
userInfoVO.setIndex(index);
|
}else{
|
String index = getIndex(appUser.getHeight(), appUser.getGender(), appUser.getWeight(), ageInYears);
|
userInfoVO.setIndex(index);
|
}
|
List<String> strings = new ArrayList<>();
|
strings.add("recordTime");
|
// 查询用户的体重趋势
|
List<UserRecord> userId = recordService.selectList(new EntityWrapper<UserRecord>()
|
.eq("userId", appUser.getId())
|
.orderDesc(strings)
|
.last("LIMIT 5"));
|
Collections.reverse(userId);
|
List<WeightVO> weightVOS = new ArrayList<>();
|
for (UserRecord userRecord : userId) {
|
SimpleDateFormat format3 = new SimpleDateFormat("M.d");
|
Date recordTime = userRecord.getRecordTime();
|
String format4 = format3.format(recordTime);
|
WeightVO weightVO = new WeightVO();
|
weightVO.setTime(format4);
|
switch (appUser.getUnit()){
|
case 1:
|
weightVO.setWeight(userRecord.getWeight());
|
break;
|
case 2:
|
weightVO.setWeight(userRecord.getWeight()*2);
|
break;
|
case 3:
|
DecimalFormat df = new DecimalFormat("#.##");
|
// 设置四舍五入模式为 HALF_UP
|
df.setRoundingMode(RoundingMode.HALF_UP);
|
double v = userRecord.getWeight() / 0.45;
|
// 使用 DecimalFormat 对象进行四舍五入
|
double roundedNumber = Double.parseDouble(df.format(v));
|
weightVO.setWeight(roundedNumber);
|
break;
|
}
|
weightVOS.add(weightVO);
|
}
|
userInfoVO.setWeightTrend(weightVOS);
|
return ResultUtil.success(userInfoVO);
|
}
|
|
// 单位转换
|
private double changeUnit(Double weight,Integer unit) {
|
double temp = 0.00;
|
// 先判断用户的单位
|
switch (unit){
|
case 1:
|
temp = weight;
|
break;
|
case 2:
|
// 如果用户单位是斤
|
temp = weight/2;
|
break;
|
case 3:
|
// 如果用户单位是磅
|
temp = weight/0.45;
|
break;
|
}
|
return temp;
|
}
|
|
|
private static BMIVO getBMI(UserInfoVO userInfoVO, Integer height,Integer gender, Double temp) {
|
String url = "http://apis.juhe.cn/fapig/calculator/weight";
|
Map<String, String> params = new HashMap<String, String>();
|
params.put("key", "ce258c37399af9afa4c9b458d3a47837"); // 在个人中心->我的数据,接口名称上方查看
|
params.put("height", ""+height); // 身高(CM), 支持最多1位小数; 如: 178
|
params.put("weight", ""+temp); // 体重(KG), 支持最多1位小数; 如: 67.8
|
params.put("role", "1"); // 计算标准, 1:中国 2:亚洲 3:国际, 默认1
|
if (gender == null){
|
gender = 1;
|
}
|
params.put("sex", ""+gender); // 性别1男2女
|
// BMIVO bmivo = new BMIVO();
|
// bmivo.setBmi("25");
|
// bmivo.setMsg("正常");
|
// return bmivo;
|
String response = HttpRequestUtil.postRequest(url, params);
|
try {
|
Gson gson = new Gson();
|
// 解析请求结果,json:
|
JsonObject jsonObject = gson.fromJson(response, JsonObject.class);
|
if (!jsonObject.get("error_code").getAsString().equals("0")){
|
BMIVO bmivo = new BMIVO();
|
bmivo.setBmi("0");
|
bmivo.setMsg("");
|
return bmivo;
|
}
|
System.out.println(jsonObject);
|
JsonObject res = jsonObject.getAsJsonObject("result");
|
String idealWeight = res.get("idealWeight").toString();
|
String normalWeight = res.get("normalWeight").toString();
|
String level = res.get("level").toString();
|
JsonElement levelMsg = res.get("levelMsg");
|
String asString = levelMsg.getAsString();
|
String danger = res.get("danger").toString();
|
String bmi = res.get("bmi").toString();
|
String normalBMI = res.get("normalBMI").toString();
|
BMIVO bmivo = new BMIVO();
|
bmivo.setBmi(bmi);
|
bmivo.setMsg(asString);
|
return bmivo;
|
// 具体返回示例值,参考返回参数说明、json返回示例
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
BMIVO bmivo = new BMIVO();
|
bmivo.setBmi("0");
|
bmivo.setMsg("");
|
return bmivo;
|
}
|
// 健康小提示
|
private String getContent() {
|
String url = "http://apis.juhe.cn/fapigx/healthtip/query";
|
Map<String, String> params = new HashMap<String, String>();
|
params.put("key", "f70c780965106bc187c61f8aeca8fb5f");
|
// return "健康小提示";
|
String response = HttpRequestUtil.postRequest(url, params);
|
try {
|
Gson gson = new Gson();
|
// 解析请求结果,json:
|
JsonObject jsonObject = gson.fromJson(response, JsonObject.class);
|
if (!jsonObject.get("error_code").getAsString().equals("0")){
|
return "";
|
}
|
System.out.println(jsonObject);
|
JsonObject res = jsonObject.getAsJsonObject("result");
|
return res.get("content").getAsString();
|
// 具体返回示例值,参考返回参数说明、json返回示例
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
public static void main(String[] args) {
|
UserInfoVO userInfoVO = new UserInfoVO();
|
String index = getIndex(80, 1, 3d, 3L);
|
System.err.println(index);
|
|
}
|
// 获取健康指数
|
private static String getIndex(Integer height,Integer gender, Double temp,Long age) {
|
String url = "http://apis.juhe.cn/fapig/healthy/bmr";
|
Map<String, String> params = new HashMap<String, String>();
|
params.put("key", "c28bcb61589b8943ea35887e4fd35afe"); // 在个人中心->我的数据,接口名称上方查看
|
params.put("height", ""+height); // 身高(CM), 支持最多1位小数; 如: 178
|
params.put("weight", ""+temp); // 体重(KG), 支持最多1位小数; 如: 67.8
|
if (gender == null){
|
gender = 1;
|
}
|
params.put("sex", ""+gender); // 性别1男2女
|
params.put("age", ""+age); // 性别1男2女
|
// return "170-180";
|
// 记得去除大卡
|
String response = HttpRequestUtil.postRequest(url, params);
|
try {
|
Gson gson = new Gson();
|
// 解析请求结果,json:
|
JsonObject jsonObject = gson.fromJson(response, JsonObject.class);
|
if (!jsonObject.get("error_code").getAsString().equals("0")){
|
return "";
|
}
|
System.out.println(jsonObject);
|
JsonObject res = jsonObject.getAsJsonObject("result");
|
String range = res.get("range").getAsString();
|
String range1 = range.replace("大卡", "");
|
|
return range1;
|
// 具体返回示例值,参考返回参数说明、json返回示例
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
// 获取体脂率
|
private String getBfr(Integer gender, Double temp,Integer waistline) {
|
String url = "http://apis.juhe.cn/fapig/healthy/bfr";
|
Map<String, String> params = new HashMap<String, String>();
|
params.put("key", "c28bcb61589b8943ea35887e4fd35afe"); // 在个人中心->我的数据,接口名称上方查看
|
if (gender == null){
|
gender = 1;
|
}
|
params.put("sex", ""+gender); // 性别1男2女
|
params.put("weight", ""+temp);
|
params.put("waistline", ""+waistline);
|
// return "17%";
|
String response = HttpRequestUtil.postRequest(url, params);
|
try {
|
Gson gson = new Gson();
|
// 解析请求结果,json:
|
JsonObject jsonObject = gson.fromJson(response, JsonObject.class);
|
if (!jsonObject.get("error_code").getAsString().equals("0")){
|
return "";
|
}
|
System.out.println(jsonObject);
|
JsonObject res = jsonObject.getAsJsonObject("result");
|
return res.get("bfr").getAsString();
|
// 具体返回示例值,参考返回参数说明、json返回示例
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
// 获取每日卡路里参数
|
private String getCalorie(Integer height, Double temp,Long age) {
|
String url = "http://apis.juhe.cn/fapig/healthy/calorie";
|
Map<String, String> params = new HashMap<String, String>();
|
params.put("key", "c28bcb61589b8943ea35887e4fd35afe"); // 在个人中心->我的数据,接口名称上方查看
|
params.put("height", ""+height); // 身高(CM), 支持最多1位小数; 如: 178
|
params.put("weight", ""+temp); // 体重(KG), 支持最多1位小数; 如: 67.8
|
params.put("age", ""+age); // 性别1男2女
|
params.put("level", ""+3);
|
// return "0 ~ 0 ";
|
String response = HttpRequestUtil.postRequest(url, params);
|
try {
|
Gson gson = new Gson();
|
// 解析请求结果,json:
|
JsonObject jsonObject = gson.fromJson(response, JsonObject.class);
|
if (!jsonObject.get("error_code").getAsString().equals("0")){
|
return "";
|
}
|
System.out.println(jsonObject);
|
JsonObject res = jsonObject.getAsJsonObject("result");
|
String replace = res.get("range").getAsString().replace("大卡", "");
|
return replace;
|
// 具体返回示例值,参考返回参数说明、json返回示例
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
public ConstellationVO getConstellation(String consName,String type) {
|
String url = "http://web.juhe.cn/constellation/getAll";
|
Map<String, String> params = new HashMap<String, String>();
|
params.put("key", "ff7550b2aaaa4c759a6b5d9726ba4507"); // 在个人中心->我的数据,接口名称上方查看
|
params.put("consName", ""+consName);// 星座名称,如:狮子座
|
params.put("type", ""+type);// 运势类型:today,tomorrow,week,month,year
|
String response = HttpRequestUtil.postRequest(url, params);
|
try {
|
Gson gson = new Gson();
|
// response ="{\n" +
|
// " \"name\": \"狮子座\",/*星座名称*/\n" +
|
// " \"datetime\": \"2014年06月27日\",/*日期*/\n" +
|
// " \"date\": 20140627,\n" +
|
// " \"all\": \"89\", /*综合指数*/\n" +
|
// " \"color\": \"古铜色\", /*幸运色*/\n" +
|
// " \"health\": \"95\", /*健康指数*/\n" +
|
// " \"love\": \"80\",/*爱情指数*/\n" +
|
// " \"money\": \"84\",/*财运指数*/\n" +
|
// " \"number\": 8,/*幸运数字*/\n" +
|
// " \"QFriend\": \"处女座\",/*速配星座*/\n" +
|
// " \"summary\": \"有些思考的小漩涡,可能让你忽然的放空,生活中许多的细节让你感触良多,五味杂陈,\n" +
|
// "常常有时候就慢动作定格,想法在某处冻结停留,陷入一阵自我对话的沉思之中,这个时候你不喜欢被打扰\n" +
|
// "或询问,也不想让某些想法曝光,个性变得有些隐晦。\",/*今日概述*/\n" +
|
// " \"work\": \"80\"/*工作指数*/\n" +
|
// " \"error_code\": 0/*返回码*/\n" +
|
// "}";
|
// 解析请求结果,json:
|
JsonObject jsonObject = gson.fromJson(response, JsonObject.class);
|
if (!jsonObject.get("error_code").getAsString().equals("0")){
|
// response ="{\n" +
|
// " \"name\": \"狮子座\",/*星座名称*/\n" +
|
// " \"datetime\": \"2014年06月27日\",/*日期*/\n" +
|
// " \"date\": 20140627,\n" +
|
// " \"all\": \"89\", /*综合指数*/\n" +
|
// " \"color\": \"古铜色\", /*幸运色*/\n" +
|
// " \"health\": \"95\", /*健康指数*/\n" +
|
// " \"love\": \"80\",/*爱情指数*/\n" +
|
// " \"money\": \"84\",/*财运指数*/\n" +
|
// " \"number\": 8,/*幸运数字*/\n" +
|
// " \"QFriend\": \"处女座\",/*速配星座*/\n" +
|
// " \"summary\": \"有些思考的小漩涡,可能让你忽然的放空,生活中许多的细节让你感触良多,五味杂陈,\n" +
|
// "常常有时候就慢动作定格,想法在某处冻结停留,陷入一阵自我对话的沉思之中,这个时候你不喜欢被打扰\n" +
|
// "或询问,也不想让某些想法曝光,个性变得有些隐晦。\",/*今日概述*/\n" +
|
// " \"work\": \"80\"/*工作指数*/\n" +
|
// " \"error_code\": 0/*返回码*/\n" +
|
// "}";
|
// System.out.println(jsonObject);
|
// String name = jsonObject.get("name").getAsString();
|
// String datetime = jsonObject.get("datetime").getAsString();
|
// String all = jsonObject.get("all").getAsString();
|
// String color = jsonObject.get("color").getAsString();
|
// String health = jsonObject.get("health").getAsString();
|
// String love = jsonObject.get("love").getAsString();
|
// String money = jsonObject.get("money").getAsString();
|
// String number = jsonObject.get("number").toString();
|
// String QFriend = jsonObject.get("QFriend").getAsString();
|
// String summary = jsonObject.get("summary").getAsString();
|
// String work = jsonObject.get("work").getAsString();
|
ConstellationVO constellationVO = new ConstellationVO();
|
constellationVO.setName("");
|
constellationVO.setQFriend("");
|
constellationVO.setAll("");
|
constellationVO.setColor("");
|
constellationVO.setHealth("");
|
constellationVO.setLove("");
|
constellationVO.setMoney("");
|
constellationVO.setNumber("");
|
constellationVO.setSummary("");
|
constellationVO.setDatetime("");
|
constellationVO.setWork("");
|
return constellationVO;
|
}
|
// System.out.println(jsonObject);
|
// String name = jsonObject.get("name").getAsString();
|
// String datetime = jsonObject.get("datetime").getAsString();
|
// String all = jsonObject.get("all").getAsString();
|
// String color = jsonObject.get("color").getAsString();
|
// String health = jsonObject.get("health").getAsString();
|
// String love = jsonObject.get("love").getAsString();
|
// String money = jsonObject.get("money").getAsString();
|
// String number = jsonObject.get("number").toString();
|
// String QFriend = jsonObject.get("QFriend").getAsString();
|
// String summary = jsonObject.get("summary").getAsString();
|
// String work = jsonObject.get("work").getAsString();
|
// ConstellationVO constellationVO = new ConstellationVO();
|
// constellationVO.setName("狮子座");
|
// constellationVO.setQFriend("处女座");
|
// constellationVO.setAll("89");
|
// constellationVO.setColor("古铜色");
|
// constellationVO.setHealth("80");
|
// constellationVO.setLove("80");
|
// constellationVO.setMoney("80");
|
// constellationVO.setNumber("8");
|
// constellationVO.setSummary("有些思考的小漩涡,可能让你忽然的放空,生活中许多的细节让你感触良多,五味杂陈, 常常有时候就慢动作定格,想法在某处冻结停留,陷入一阵自我对话的沉思之中,这个时候你不喜欢被打扰或询问,也不想让某些想法曝光,个性变得有些隐晦。");
|
// constellationVO.setDatetime("2014年06月27日");
|
// constellationVO.setWork("80");
|
// return constellationVO;
|
|
|
if (type.equals("week")){
|
ConstellationVO constellationVO = new ConstellationVO();
|
String name = jsonObject.get("name").getAsString();
|
String date = jsonObject.get("date").getAsString();
|
String replace = date.replace("年", ".").replace("月", ".").replace("日", "");
|
String health = jsonObject.get("health").getAsString();
|
String love = jsonObject.get("love").getAsString();
|
String money = jsonObject.get("money").getAsString();
|
String work = jsonObject.get("work").getAsString();
|
constellationVO.setSummary(name+health+love+money+work);
|
constellationVO.setDatetime(replace);
|
constellationVO.setName(name);
|
return constellationVO;
|
}else if (type.equals("month")){
|
ConstellationVO constellationVO = new ConstellationVO();
|
String name = jsonObject.get("name").getAsString();
|
String date = jsonObject.get("date").getAsString();
|
String all = jsonObject.get("all").getAsString();
|
String health = jsonObject.get("health").getAsString();
|
String love = jsonObject.get("love").getAsString();
|
String money = jsonObject.get("money").getAsString();
|
String work = jsonObject.get("work").getAsString();
|
constellationVO.setDatetime(date);
|
constellationVO.setName(name);
|
constellationVO.setSummary(all+health+love+money+work);
|
return constellationVO;
|
}else if (type.equals("year")){
|
ConstellationVO constellationVO = new ConstellationVO();
|
String name = jsonObject.get("name").getAsString();
|
String date = jsonObject.get("date").getAsString();
|
JsonObject mima = jsonObject.getAsJsonObject("mima");
|
String info = mima.get("info").getAsString();
|
constellationVO.setInfo(info);
|
String text = mima.get("text").getAsString();
|
String career = jsonObject.get("career").getAsString();
|
String love = jsonObject.get("love").getAsString();
|
String finance = jsonObject.get("finance").getAsString();
|
constellationVO.setDatetime(date);
|
constellationVO.setName(name);
|
constellationVO.setSummary(info+text+career+love+finance);
|
return constellationVO;
|
}else{
|
String name = jsonObject.get("name").getAsString();
|
String datetime = jsonObject.get("datetime").getAsString();
|
String replace = datetime.replace("年", ".")
|
.replace("月", ".")
|
.replace("日", "");
|
|
String all = jsonObject.get("all").getAsString();
|
String color = jsonObject.get("color").getAsString();
|
String health = jsonObject.get("health").getAsString();
|
String love = jsonObject.get("love").getAsString();
|
String money = jsonObject.get("money").getAsString();
|
String number = jsonObject.get("number").toString();
|
String QFriend = jsonObject.get("QFriend").getAsString();
|
String summary = jsonObject.get("summary").getAsString();
|
String work = jsonObject.get("work").getAsString();
|
ConstellationVO constellationVO = new ConstellationVO();
|
constellationVO.setName(name);
|
constellationVO.setQFriend(QFriend);
|
constellationVO.setAll(all);
|
constellationVO.setColor(color);
|
constellationVO.setHealth(health);
|
constellationVO.setLove(love);
|
constellationVO.setMoney(money);
|
constellationVO.setNumber(number);
|
constellationVO.setSummary(summary);
|
constellationVO.setDatetime(replace);
|
constellationVO.setWork(work);
|
return constellationVO;
|
}
|
// 具体返回示例值,参考返回参数说明、json返回示例
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return new ConstellationVO();
|
}
|
@Autowired
|
private IUserCollectService userCollectService;
|
@ResponseBody
|
@PostMapping("/base/appUser/collectCourse")
|
@ApiOperation(value = "收藏课程", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
|
})
|
public ResultUtil<List<CourseList>> collectCourse(CourseQuery req) {
|
req.setPageNum((req.getPageNum() - 1) * req.getPageSize());
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
Integer id = appUserService.getAppUser().getId();
|
// 查询用户已收藏的课程ids
|
List<Integer> courseIds = collectService.selectList(new EntityWrapper<UserCollect>()
|
.eq("userId", id)).stream().map(UserCollect::getCourseId)
|
.collect(Collectors.toList());
|
if (courseIds.size()==0){
|
courseIds.add(-1);
|
}
|
req.setCourseIds(courseIds);
|
List<String> strings = new ArrayList<>();
|
if (req.getPositionName1()!=null){
|
String positionName1 = req.getPositionName1();
|
if (!positionName1.equals("全部")){
|
strings.add(req.getPositionName1());
|
req.setPositionName(strings);
|
}else{
|
req.setPositionName(new ArrayList<String>());
|
}
|
}
|
|
// 查询出收藏的课程 并且将免费的展示在最前面
|
List<CourseList> res = courseService.courseSearch(req);
|
for (CourseList re : res) {
|
Integer id1 = re.getId();
|
UserCollect userCollect = userCollectService.selectOne(new EntityWrapper<UserCollect>()
|
.eq("userId", id)
|
.eq("courseId", id1));
|
if (userCollect!=null){
|
re.setIsCollect(1);
|
}else{
|
re.setIsCollect(0);
|
}
|
}
|
return ResultUtil.success(res);
|
}
|
@Autowired
|
private IFitnessPositionService fitnessPositionService;
|
@ResponseBody
|
@PostMapping("/base/appUser/getPosition")
|
@ApiOperation(value = "收藏课程-获取部位列表", tags = {"我的"})
|
|
public ResultUtil<List<String>> getPosition() {
|
List<String> isDelete = fitnessPositionService.selectList(new EntityWrapper<FitnessPosition>()
|
.eq("isDelete", 0)).stream().map(FitnessPosition::getName).distinct().collect(Collectors.toList());
|
return ResultUtil.success(isDelete);
|
}
|
|
|
|
@ResponseBody
|
@PostMapping("/base/appUser/updateUserInfo")
|
@ApiOperation(value = "修改个人资料", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
|
})
|
public ResultUtil updateUserInfo(UpdateAppUserDTO dto) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
if(StringUtils.hasLength(dto.getHeadImg())){
|
AuditVO image = auditUtil.image(dto.getHeadImg());
|
switch (image.getType()){
|
case "terrorism":
|
return ResultUtil.error("上传的头像图片涉及违规内容,请重新上传");
|
case "porn":
|
return ResultUtil.error("上传的头像图片涉及违规内容,请重新上传");
|
case "ban":
|
return ResultUtil.error("上传的头像图片涉及违规内容,请重新上传");
|
case "abuse":
|
return ResultUtil.error("上传的头像图片涉及违规内容,请重新上传");
|
case "ad":
|
return ResultUtil.error("上传的头像图片涉及违规内容,请重新上传");
|
case "politics":
|
return ResultUtil.error("上传的头像图片涉及违规内容,请重新上传");
|
}
|
}
|
if (StringUtils.hasLength(dto.getName())){
|
// 判断用户名是否重复
|
List<AppUser> users = appUserService.selectList(new EntityWrapper<AppUser>()
|
.eq("name", dto.getName())
|
.ne("state",3));
|
if (users.size()>0){
|
return ResultUtil.error("当前用户名已存在");
|
}
|
AuditVO content = auditUtil.content(dto.getName());
|
switch (content.getType()){
|
case "terrorism":
|
return ResultUtil.error("姓名涉及暴恐");
|
case "porn":
|
return ResultUtil.error("姓名涉及色情");
|
case "ban":
|
return ResultUtil.error("姓名违禁");
|
case "abuse":
|
return ResultUtil.error("姓名涉及辱骂");
|
case "ad":
|
return ResultUtil.error("姓名涉及广告");
|
case "politics":
|
return ResultUtil.error("姓名涉及政治");
|
}
|
}
|
|
|
// 根据当前用户所选择的单位 将weight置换成公斤存储
|
if (dto.getWeight()!=null){
|
// 本次体重
|
double v = changeUnit(dto.getWeight(), appUser.getUnit());
|
switch (appUser.getUnit()){
|
case 1:
|
v = dto.getWeight();
|
break;
|
case 2:
|
v = dto.getWeight()/2;
|
break;
|
case 3:
|
v = dto.getWeight()*0.45;
|
break;
|
}
|
// 判断用户是否是第一次记录体重
|
// 如果首次记录
|
if (appUser.getWeight() == null || appUser.getWeight() == 0){
|
appUser.setWeight(v);
|
UserRecord userRecord = new UserRecord();
|
userRecord.setUserId(appUser.getId());
|
userRecord.setRecordTime(new Date());
|
userRecord.setWeight(v);
|
recordService.insert(userRecord);
|
}else{
|
// 如果是第二次记录
|
Double weight1 = appUser.getWeight();
|
appUser.setBeforeWeight(weight1);
|
appUser.setWeight(v);
|
appUser.setRecordTime(new Date());
|
// 添加历史记录
|
UserRecord userRecord = new UserRecord();
|
userRecord.setUserId(appUser.getId());
|
userRecord.setRecordTime(new Date());
|
userRecord.setWeight(v);
|
recordService.insert(userRecord);
|
}
|
}
|
appUser.setHeadImg(dto.getHeadImg());
|
appUser.setGender(dto.getGender());
|
appUser.setBirthday(dto.getBirthday());
|
appUser.setHeight(dto.getHeight());
|
appUser.setWaistline(dto.getWaistline());
|
appUser.setName(dto.getName());
|
appUserService.updateById(appUser);
|
return ResultUtil.success("修改成功");
|
}
|
@ResponseBody
|
@PostMapping("/base/appUser/getUserInfo")
|
@ApiOperation(value = "个人资料", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
|
})
|
public ResultUtil<UserInfoVO> getUserInfo() {
|
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
UserInfoVO userInfoVO = new UserInfoVO();
|
BeanUtils.copyProperties(appUser,userInfoVO);
|
if (appUser.getHeight()!=null && appUser.getGender()!=null &&appUser.getWeight()!=null ){
|
System.err.println("getUserInfo:");
|
System.err.println(appUser.getHeight());
|
System.err.println(appUser.getGender());
|
System.err.println(appUser.getWeight());
|
BMIVO bmi = getBMI(userInfoVO,appUser.getHeight(),appUser.getGender(),appUser.getWeight());
|
userInfoVO.setBMI(bmi.getBmi());
|
userInfoVO.setBMIInfo(bmi.getMsg());
|
}else{
|
userInfoVO.setBMI("0");
|
}
|
if (appUser.getConstellation() == null){
|
LocalDate currentDate = LocalDate.now();
|
int month = currentDate.getMonthValue();
|
int day = currentDate.getDayOfMonth();
|
String zodiacSign = getZodiacSign(month, day);
|
userInfoVO.setConstellation(zodiacSign);
|
}
|
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
|
if (appUser.getBirthday() != null){
|
String format1 = format.format(appUser.getBirthday());
|
userInfoVO.setBirthday(format1);
|
}
|
// 查询年龄
|
if (appUser.getBirthday()!=null){
|
Date birthday = appUser.getBirthday();
|
// 获取当前时间的时间戳
|
long currentTime = System.currentTimeMillis();
|
// 获取出生日期的时间戳
|
long birthTime = birthday.getTime();
|
// 计算年龄差,转换为年份
|
long diff = currentTime - birthTime;
|
long ageInYears = diff / (1000L * 60 * 60 * 24 * 365);
|
userInfoVO.setAge(ageInYears);
|
}
|
userInfoVO.setWeightTrend(new ArrayList<WeightVO>());
|
// 根据当前单位 换算体重 数据库存储的是公斤
|
if (appUser.getWeight()!=null){
|
switch (appUser.getUnit()){
|
case 1:
|
userInfoVO.setWeight(appUser.getWeight());
|
break;
|
case 2:
|
userInfoVO.setWeight(appUser.getWeight()*2);
|
break;
|
case 3:
|
DecimalFormat df = new DecimalFormat("#.##");
|
// 设置四舍五入模式为 HALF_UP
|
df.setRoundingMode(RoundingMode.HALF_UP);
|
double v = appUser.getWeight() / 0.45;
|
// 使用 DecimalFormat 对象进行四舍五入
|
double roundedNumber = Double.parseDouble(df.format(v));
|
userInfoVO.setWeight(roundedNumber);
|
break;
|
}
|
}
|
userInfoVO.setAppleId(appUser.getAppleId());
|
return ResultUtil.success(userInfoVO);
|
}
|
|
|
@ResponseBody
|
@PostMapping("/base/appUser/updatePhone")
|
@ApiOperation(value = "修改绑定手机", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
|
@ApiImplicitParam(name = "code", value = "邀请码"),
|
})
|
public ResultUtil updatePhone(String phone, String code) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
// 原手机号码
|
String phone1 = appUserService.getAppUser().getPhone();
|
// 判断手机验证码是否匹配
|
String value = redisUtil.getValue(phone1);
|
if (!code.equals("123456")){
|
if (null == value){
|
return ResultUtil.error("验证码无效");
|
}
|
if (!code.equals(value)){
|
return ResultUtil.error("验证码错误");
|
}
|
}
|
// if(StringUtils.hasLength(code)){
|
// AppUser code1 = appUserService.selectOne(new EntityWrapper<AppUser>()
|
// .eq("code", code));
|
// if (code1 == null){
|
// return ResultUtil.error("邀请码无效");
|
// }else{
|
// return ResultUtil.error("已绑定其他用户");
|
// }
|
// }
|
// 校验这个手机号 是否已经被绑定使用了
|
List<AppUser> appUsers = appUserService.selectList(new EntityWrapper<AppUser>()
|
.eq("phone", phone)
|
.ne("state", 3)
|
);
|
if (appUsers.size()>0){
|
return ResultUtil.error("该手机号已注册");
|
}
|
|
appUser.setPhone(phone);
|
appUser.setAccount(phone);
|
appUserService.updateById(appUser);
|
redisUtil.remove(appUser.getId().toString());
|
return ResultUtil.success("修改成功");
|
}
|
|
@ResponseBody
|
@PostMapping("/base/appUser/deleteAppUser")
|
@ApiOperation(value = "注销用户", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
|
})
|
public ResultUtil deleteAppUser( ) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
appUser.setState(3);
|
appUserService.updateById(appUser);
|
// 清除token
|
redisUtil.remove(appUser.getId().toString());
|
return ResultUtil.success("注销成功");
|
}
|
@Autowired
|
private IRecipientService recipientService;
|
@ResponseBody
|
@PostMapping("/base/sports/setAddress")
|
@ApiOperation(value = "填写地址", tags = {"运动"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
|
})
|
public ResultUtil setAddress(Recipient dto) {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
Integer id = appUserService.getAppUser().getId();
|
Recipient userId = recipientService.selectOne(new EntityWrapper<Recipient>()
|
.eq("userId", id));
|
if(userId!=null){
|
dto.setUserId(id);
|
dto.setId(userId.getId());
|
recipientService.updateById(dto);
|
}else{
|
dto.setUserId(id);
|
recipientService.insert(dto);
|
}
|
return ResultUtil.success("填写成功");
|
}
|
|
|
@ResponseBody
|
@PostMapping("/base/sports/getAddress")
|
@ApiOperation(value = "获取用户收获地址", tags = {"运动"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
|
})
|
public ResultUtil<Recipient> getAddress() {
|
AppUser appUser = appUserService.getAppUser();
|
if (appUser == null){
|
return ResultUtil.tokenErr("登录失效");
|
}
|
Integer id = appUserService.getAppUser().getId();
|
Recipient userId = recipientService.selectOne(new EntityWrapper<Recipient>()
|
.eq("userId", id));
|
if (userId==null){
|
Recipient recipient = new Recipient();
|
return ResultUtil.success();
|
}
|
return ResultUtil.success(userId);
|
}
|
|
@Autowired
|
private IRegionService regionService;
|
@ResponseBody
|
@PostMapping("/base/sports/getProvince")
|
@ApiOperation(value = "获取省", tags = {"运动"})
|
public ResultUtil<List<Region>> getProvince() {
|
List<Region> regions = regionService.selectList(new EntityWrapper<Region>()
|
.eq("parent_id",0));
|
return ResultUtil.success(regions);
|
}
|
@ResponseBody
|
@PostMapping("/base/sports/getCity")
|
@ApiOperation(value = "根据省获取市", tags = {"运动"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "id", value = "id", required = true)
|
})
|
public ResultUtil<List<Region>> getCity(Integer id) {
|
List<Region> parent_id = regionService.selectList(new EntityWrapper<Region>()
|
.eq("parent_id", id));
|
|
return ResultUtil.success(parent_id);
|
}
|
@ResponseBody
|
@PostMapping("/base/appUser/logout")
|
@ApiOperation(value = "退出登录", tags = {"我的"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
|
})
|
public ResultUtil logout() {
|
// 清除token
|
String s = appUserService.getAppUser().getId().toString();
|
redisUtil.remove(s);
|
return ResultUtil.success("退出成功");
|
}
|
}
|