package com.ruoyi.web.controller.errand;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.errand.domain.Order;
|
import com.ruoyi.errand.object.dto.app.AppletLogin;
|
import com.ruoyi.errand.object.dto.app.BirthDayDTO;
|
import com.ruoyi.errand.object.dto.app.MobileLoginDTO;
|
import com.ruoyi.errand.object.dto.app.RegisterDTO;
|
import com.ruoyi.errand.object.dto.sys.AppUserPageListDTO;
|
import com.ruoyi.errand.object.dto.sys.OrderPageListDTO;
|
import com.ruoyi.errand.object.dto.sys.UserStatsDTO;
|
import com.ruoyi.errand.object.vo.app.AppUserInfoVO;
|
import com.ruoyi.errand.object.vo.app.OrderPageVO;
|
import com.ruoyi.errand.object.vo.app.UserTopInfoVO;
|
import com.ruoyi.errand.object.vo.login.LoginVO;
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.errand.object.vo.sys.*;
|
import com.ruoyi.errand.service.AppUserService;
|
import com.ruoyi.errand.utils.RefundCallbackResult;
|
import com.ruoyi.errand.utils.TokenBlacklistService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletResponse;
|
import javax.validation.Valid;
|
import java.io.IOException;
|
import java.io.PrintWriter;
|
import java.time.*;
|
|
|
@RestController
|
@RequestMapping(value = "/app/user")
|
@Api(value = "app用户",tags = "app用户操作控制器")
|
@Slf4j
|
public class AppUserController {
|
|
@Autowired
|
private AppUserService appUserService;
|
|
@Autowired
|
private TokenBlacklistService blacklistService;
|
@GetMapping("/test")
|
@ApiOperation(value = "测试接口" ,tags = "测试")
|
public R<Void> test(@RequestHeader("Authorization") String token) {
|
throw new ServiceException("测试");
|
|
}
|
/**
|
* 登出
|
*/
|
@GetMapping("/logout")
|
@ApiOperation(value = "登出" ,tags = "app用户端")
|
public R<Void> logout(@RequestHeader("Authorization") String token) {
|
// 1. 将令牌加入黑名单
|
blacklistService.addToBlacklist(token);
|
return R.ok();
|
}
|
|
/**
|
* 获取短信验证码
|
*/
|
@GetMapping("/getSMSCode")
|
@ApiOperation(value = "获取短信验证码",tags = "app用户端")
|
public R<Void> getSMSCode(@RequestParam("phone") String phone) {
|
appUserService.getSMSCode(phone);
|
return R.ok();
|
}
|
|
/**
|
* 手机号验证码登录
|
*/
|
@PostMapping("/mobileLogin")
|
@ApiOperation(value = "手机号登录",tags = "app用户端")
|
public R<LoginVO> mobileLogin(@RequestBody @Valid MobileLoginDTO mobileLogin) {
|
return appUserService.mobileLogin(mobileLogin);
|
|
}
|
|
/**
|
* 小程序一键登录
|
*/
|
@PostMapping("/appletLogin")
|
@ApiOperation(value = "小程序一键登录",tags = "app用户端")
|
public R<LoginVO> appletLogin(@RequestBody @Valid AppletLogin appletLogin) {
|
return appUserService.appletLogin(appletLogin);
|
}
|
|
/**
|
* 注册
|
*/
|
@PostMapping("/register")
|
@ApiOperation(value = "注册",tags = "app用户端")
|
public R<Void> register(@RequestBody @Valid RegisterDTO registerDTO) {
|
appUserService.register(registerDTO);
|
return R.ok();
|
}
|
/**
|
* 根据小区id(可选择)
|
* 获取小区名字 以及对应的收货地址 小区价格
|
*/
|
@GetMapping("/getOrderPage")
|
@ApiOperation(value = "获取相关信息",tags = "app用户端-下单页面")
|
public R<OrderPageVO> getOrderPage(@RequestParam(value = "communityId",required = false) Integer communityId) {
|
return R.ok(appUserService.getOrderPage(communityId));
|
}
|
|
/**
|
* 个人中心
|
*/
|
@GetMapping("/getMyInfo")
|
@ApiOperation(value = "获取个人信息",tags = "app用户端-个人信息")
|
public R<AppUserInfoVO> getMyInfo() {
|
return R.ok(appUserService.getMyInfo());
|
}
|
|
/**
|
* 选择性别 1=男,2=女,3=未知
|
*/
|
@PutMapping("/setSex")
|
@ApiOperation(value = "修改性别",tags = "app用户端-个人信息")
|
public R<Void> setSex(@RequestParam Integer sex) {
|
appUserService.setSex(sex);
|
return R.ok();
|
}
|
/**
|
* 修改生日
|
*/
|
@PutMapping("/setBirthDay")
|
@ApiOperation(value = "修改生日",tags = "app用户端-个人信息")
|
public R<Void> setBirthDay(@RequestBody BirthDayDTO birth) {
|
appUserService.setBirthDay(birth);
|
return R.ok();
|
}
|
|
/**
|
* 注销账号 需要修改delFlag?
|
*/
|
@DeleteMapping("/delete")
|
@ApiOperation(value = "注销账号",tags = "app用户端-个人信息")
|
public R<Void> delete(@RequestHeader("Authorization") String token) {
|
appUserService.delete(token);
|
return R.ok();
|
}
|
|
/**
|
* 用户统计
|
*/
|
@GetMapping("/userTopInfo")
|
@PreAuthorize("@ss.hasPermi('system:index:statistics')")
|
@ApiOperation(value = "用户统计-顶部数据", tags = "系统后台-首页")
|
public R<UserTopInfoVO> userTopInfo() {
|
|
LocalDateTime[] dateRange;//日期范围
|
dateRange = new LocalDateTime[]{
|
LocalDateTime.now().with(LocalTime.MIN),
|
LocalDateTime.now().with(LocalTime.MAX)
|
};
|
return R.ok(appUserService.userTopInfo(dateRange[0], dateRange[1]));
|
}
|
|
/**
|
* 用户统计
|
*/
|
@PostMapping("/statistics")
|
@PreAuthorize("@ss.hasPermi('system:index:statistics')")
|
@ApiOperation(value = "用户统计-折线图", tags = "系统后台-首页")
|
public R<UserStatsVO> statistics(@RequestBody @Valid UserStatsDTO userStatsDTO) {
|
LocalDateTime[] dateRange;//日期范围
|
String datePattern;//日期格式
|
|
switch (userStatsDTO.getType()) {
|
case 1: // 今日 当天数据,按小时划分
|
dateRange = new LocalDateTime[]{
|
LocalDateTime.now().with(LocalTime.MIN),
|
LocalDateTime.now().with(LocalTime.MAX)
|
};
|
datePattern = "HH时";
|
break;
|
case 2: // 本周 按星期一、二...划分
|
LocalDate now = LocalDate.now();
|
dateRange = new LocalDateTime[]{
|
now.with(DayOfWeek.MONDAY).atStartOfDay(), // 本周一
|
now.with(DayOfWeek.SUNDAY).atTime(LocalTime.MAX) // 本周日
|
};
|
datePattern = "EEEE";
|
break;
|
case 3: // 本月 按1日至月末划分
|
YearMonth currentMonth = YearMonth.now();
|
dateRange = new LocalDateTime[]{
|
currentMonth.atDay(1).atStartOfDay(), // 本月1日
|
currentMonth.atEndOfMonth().atTime(LocalTime.MAX) // 本月最后一天
|
};
|
datePattern = "dd日";
|
break;
|
case 4: // 本季度 按当前季度的月份划分
|
YearMonth thisMonth = YearMonth.now();
|
YearMonth firstMonthOfQuarter = thisMonth.with(
|
Month.of(((thisMonth.getMonthValue() - 1) / 3) * 3 + 1));
|
YearMonth lastMonthOfQuarter = firstMonthOfQuarter.plusMonths(2);
|
dateRange = new LocalDateTime[]{
|
firstMonthOfQuarter.atDay(1).atStartOfDay(), // 季度第一个月1日
|
lastMonthOfQuarter.atEndOfMonth().atTime(LocalTime.MAX) // 季度最后一个月最后一天
|
};
|
datePattern = "MM月";
|
break;
|
case 5: // 半年 上半年或下半年完整月份
|
YearMonth current = YearMonth.now();
|
YearMonth halfYearStart = current.getMonthValue() <= 6 ?
|
YearMonth.of(current.getYear(), Month.JANUARY) :
|
YearMonth.of(current.getYear(), Month.JULY);
|
YearMonth halfYearEnd = halfYearStart.plusMonths(5);
|
dateRange = new LocalDateTime[]{
|
halfYearStart.atDay(1).atStartOfDay(),
|
halfYearEnd.atEndOfMonth().atTime(LocalTime.MAX)
|
};
|
datePattern = "MM月";
|
break;
|
case 6: // 本年 按1月至12月完整年份
|
int year = Year.now().getValue();
|
dateRange = new LocalDateTime[]{
|
LocalDateTime.of(year, 1, 1, 0, 0), // 1月1日
|
LocalDateTime.of(year, 12, 31, 23, 59, 59) // 12月31日
|
};
|
datePattern = "MM月";
|
break;
|
case 7: // 自定义 按起始时间到终止时间之间的日期划分
|
if (userStatsDTO.getStartDate() == null || userStatsDTO.getEndDate() == null) {
|
throw new ServiceException("自定义时间范围必须指定开始和结束日期");
|
}
|
if (userStatsDTO.getStartDate().isAfter(userStatsDTO.getEndDate())) {
|
throw new ServiceException("开始日期不能晚于结束日期");
|
}
|
dateRange = new LocalDateTime[]{
|
userStatsDTO.getStartDate().atStartOfDay(),
|
userStatsDTO.getEndDate().atTime(LocalTime.MAX)
|
};
|
datePattern = "yyyy-MM-dd";
|
break;
|
default:
|
throw new ServiceException("无效的筛选类型: " + userStatsDTO.getType());
|
}
|
|
return R.ok(appUserService.getUserStats(dateRange[0], dateRange[1], datePattern));
|
}
|
|
/**
|
* 用户管理列表
|
*/
|
@PostMapping("/list")
|
@PreAuthorize("@ss.hasPermi('system:appuser:list')")
|
@ApiOperation(value = "用户管理-分页列表", tags = "系统后台-用户管理")
|
public R<IPage<AppUserPageListVO>> getAppUserPageList(@RequestBody @Valid AppUserPageListDTO appUserPageListDTO) {
|
return R.ok(appUserService.getAppUserPageList(appUserPageListDTO));
|
}
|
/**
|
* 查看详情
|
*/
|
@GetMapping("/detail")
|
@PreAuthorize("@ss.hasPermi('system:appuser:list')")
|
@ApiOperation(value = "用户管理-用户详情", tags = "系统后台-用户管理")
|
public R<AppUserSysDetailVO> detail(@RequestParam("id") Integer id) {
|
return R.ok(appUserService.detail(id));
|
}
|
/**
|
* 冻结/解冻
|
*/
|
@PutMapping("/froze")
|
@PreAuthorize("@ss.hasPermi('system:appuser:list')")
|
@ApiOperation(value = "用户管理-冻结/解冻", tags = "系统后台-用户管理")
|
public R froze(@RequestParam("id") Integer id) {
|
appUserService.froze(id);
|
return R.ok();
|
}
|
/**
|
* 会员退费
|
*/
|
@GetMapping("/refund")
|
@PreAuthorize("@ss.hasPermi('system:appuser:list')")
|
@ApiOperation(value = "用户管理-会员退费", tags = "系统后台-用户管理")
|
public R<Void> refund(@RequestParam("id") Integer id) {
|
appUserService.refund(id);
|
return R.ok();
|
}
|
|
|
/**
|
* 订单取消支付回退
|
*
|
* @param refundCallbackResult
|
* @param response
|
* @return
|
*/
|
@ResponseBody
|
@GetMapping("/refundPayMoneyCallback")
|
public void refundPayMoneyCallback(RefundCallbackResult refundCallbackResult, HttpServletResponse response) {
|
R callback = appUserService.refundPayMoneyCallback(refundCallbackResult);
|
if (callback.getCode() == 200) {
|
response.setStatus(200);
|
PrintWriter out = null;
|
try {
|
out = response.getWriter();
|
} catch (IOException e) {
|
throw new RuntimeException(e);
|
}
|
out.println("success");
|
out.flush();
|
out.close();
|
}
|
}
|
|
}
|