提交
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package org.dromara;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
|
||||
|
||||
/**
|
||||
* 启动程序
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
|
||||
@SpringBootApplication
|
||||
public class DromaraApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication application = new SpringApplication(DromaraApplication.class);
|
||||
application.setApplicationStartup(new BufferingApplicationStartup(2048));
|
||||
application.run(args);
|
||||
System.out.println("(♥◠‿◠)ノ゙ DD画图系统启动成功 ლ(´ڡ`ლ)゙");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.dromara;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
/**
|
||||
* web容器中进行部署
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
public class DromaraServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(DromaraApplication.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.dromara.web.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.web.utils.TxApiSdkUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 文本/图片安全验证
|
||||
* @author Maosw
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/appletAuth")
|
||||
@Tag(name = "腾讯云接口")
|
||||
public class ApiAppletAuthController {
|
||||
|
||||
|
||||
@PostMapping("/checkContext")
|
||||
@Operation(summary = "腾讯云文本内容安全识别" , description = "腾讯云文本内容安全识别")
|
||||
public R<String> checkContext(@RequestParam String content) {
|
||||
if (StringUtils.isEmpty(content)) {
|
||||
return R.fail("-1", "内容不能为空");
|
||||
}
|
||||
return R.ok(TxApiSdkUtils.checkContext(content));
|
||||
}
|
||||
|
||||
@PostMapping("/checkImages")
|
||||
@Operation(summary = "腾讯云图片内容安全识别" , description = "腾讯云图片内容安全识别")
|
||||
public R<String> checkImages(@RequestParam String content) {
|
||||
if (StringUtils.isEmpty(content)) {
|
||||
return R.fail("-1", "内容不能为空");
|
||||
}
|
||||
return R.ok(TxApiSdkUtils.checkImages(content));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
package org.dromara.web.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.lakala.zf.laop.java.sdk.demo.BaseCommonDemo;
|
||||
import com.lkl.laop.sdk.LKLSDK;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
||||
import org.dromara.system.domain.SysUser;
|
||||
import org.dromara.system.service.ISysUserService;
|
||||
import org.dromara.work.domain.TpOrderPay;
|
||||
import org.dromara.work.domain.bo.TpOrderPayBo;
|
||||
import org.dromara.work.domain.bo.TpUserRecordBo;
|
||||
import org.dromara.work.service.ITpOrderPayService;
|
||||
import org.dromara.work.service.ITpOrderService;
|
||||
import org.dromara.work.service.ITpUserRecordService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 回调接口
|
||||
* @author Maosw
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/callback")
|
||||
@Tag(name = "回调接口")
|
||||
public class ApiCallbackController extends BaseCommonDemo {
|
||||
|
||||
private final ITpOrderService tpOrderService;
|
||||
|
||||
private final ITpOrderPayService tpOrderPayService;
|
||||
|
||||
private final ITpUserRecordService tpUserRecordService;
|
||||
|
||||
private final ISysUserService tzUserService;
|
||||
|
||||
/**
|
||||
* DD画图订单回调地址
|
||||
*/
|
||||
@RequestMapping("/order")
|
||||
@RepeatSubmit(interval = 1, timeUnit = TimeUnit.SECONDS, message = "重复请求")
|
||||
public Map<String, String> order(HttpServletRequest request) throws Exception {
|
||||
System.out.println("DD画图订单回调开始...");
|
||||
// 1. 配置初始化
|
||||
doInit();
|
||||
LKLSDK.notificationHandle(request);
|
||||
|
||||
String body = getBody(request);
|
||||
// 业务处理
|
||||
JSONObject respData = JSON.parseObject(body);
|
||||
|
||||
String orderNo = respData.getString("out_order_no");
|
||||
String payOrderNo = respData.getString("pay_order_no");
|
||||
String orderStatus = respData.getString("order_status");
|
||||
JSONObject jsonObject = respData.getJSONObject("order_trade_info");
|
||||
String tradeNo = jsonObject.getString("trade_no");
|
||||
String logNo = jsonObject.getString("log_no");
|
||||
|
||||
if ("2".equals(orderStatus)) {
|
||||
TpOrderPay orderPay = tpOrderPayService.queryByOrderNo(orderNo, payOrderNo);
|
||||
if (orderPay == null) {
|
||||
throw new RuntimeException("支付订单不存在");
|
||||
}
|
||||
boolean result = tpOrderService.callbackOrder(orderPay.getId(),orderPay,tradeNo,logNo,respData);
|
||||
if (result) {
|
||||
return getKlkCommonResp();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 余额充值订单回调地址
|
||||
*/
|
||||
@RequestMapping("/rechargeOrder")
|
||||
@RepeatSubmit(interval = 1, timeUnit = TimeUnit.SECONDS, message = "重复请求")
|
||||
public Map<String, String> rechargeOrder(HttpServletRequest request) throws Exception {
|
||||
System.out.println("余额充值订单回调地址回调开始...");
|
||||
// 1. 配置初始化
|
||||
doInit();
|
||||
LKLSDK.notificationHandle(request);
|
||||
|
||||
String body = getBody(request);
|
||||
// 业务处理
|
||||
JSONObject respData = JSON.parseObject(body);
|
||||
|
||||
String orderNo = respData.getString("out_order_no");
|
||||
String payOrderNo = respData.getString("pay_order_no");
|
||||
String orderStatus = respData.getString("order_status");
|
||||
JSONObject jsonObject = respData.getJSONObject("order_trade_info");
|
||||
String tradeNo = jsonObject.getString("trade_no");
|
||||
String logNo = jsonObject.getString("log_no");
|
||||
|
||||
if ("2".equals(orderStatus)) {
|
||||
TpOrderPay orderPay = tpOrderPayService.queryByOrderNo(orderNo, payOrderNo);
|
||||
if (orderPay == null) {
|
||||
throw new RuntimeException("支付订单不存在");
|
||||
}
|
||||
|
||||
//更新用户余额
|
||||
SysUser tzUser = tzUserService.queryById(orderPay.getUserId());
|
||||
tzUser.setYue(tzUser.getYue().add(orderPay.getAmount()));
|
||||
if (!tzUserService.updateById(tzUser)) {
|
||||
throw new RuntimeException("充值用户余额失败");
|
||||
}
|
||||
|
||||
//新增用户资金记录
|
||||
TpUserRecordBo bo = new TpUserRecordBo();
|
||||
bo.setUserId(orderPay.getUserId());
|
||||
bo.setUserName(tzUser.getUserName());
|
||||
bo.setUserPhone(tzUser.getPhonenumber());
|
||||
bo.setAmount(orderPay.getAmount());
|
||||
bo.setType(1);
|
||||
bo.setBalance(tzUser.getYue());
|
||||
bo.setRemark("余额充值");
|
||||
tpUserRecordService.insertByBo(bo);
|
||||
|
||||
//更新支付订单
|
||||
TpOrderPayBo orderPayBo = new TpOrderPayBo();
|
||||
orderPayBo.setId(orderPay.getId());
|
||||
orderPayBo.setStatus(2);
|
||||
orderPayBo.setPayerInfo(String.valueOf(respData));
|
||||
boolean result = tpOrderPayService.updateByBo(orderPayBo);
|
||||
if (result) {
|
||||
return getKlkCommonResp();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/*@RequestMapping("/applyBind")
|
||||
@Operation(summary = "分账关系绑定申请回调" , description = "分账关系绑定申请回调")
|
||||
public Map<String, String> applyBind(@RequestBody String requestBody) throws Exception {
|
||||
System.out.println("分账关系绑定结果开始回调...");
|
||||
// 1. 配置初始化
|
||||
doInit();
|
||||
//业务处理
|
||||
JSONObject jsonObject = JSON.parseObject(requestBody);
|
||||
String receiverNo = jsonObject.getString("receiverNo");
|
||||
TzBankCard bankCard = bankCardService.queryByReceiverNo(receiverNo);
|
||||
if ("1".equals(jsonObject.getString("auditStatus"))) {
|
||||
// 绑定成功
|
||||
bankCard.setStatus(1);
|
||||
|
||||
//提款模式设置
|
||||
V2LaepIndustryEwalletSettleProfileRequest ewalletSettleProfileRequest = new V2LaepIndustryEwalletSettleProfileRequest();
|
||||
ewalletSettleProfileRequest.setBmcpNo(KlkConstant.ORG_CODE);
|
||||
ewalletSettleProfileRequest.setMercId(receiverNo);
|
||||
ewalletSettleProfileRequest.setSettleType("02");
|
||||
ewalletSettleProfileRequest.setPayType("04");
|
||||
V3LakalaUserUtils.setWithdrawMode(ewalletSettleProfileRequest);
|
||||
|
||||
} else {
|
||||
bankCard.setStatus(2);
|
||||
bankCard.setRemark(jsonObject.getString("remark"));
|
||||
}
|
||||
if (!bankCardService.updateById(bankCard)) {
|
||||
throw new RuntimeException("绑定银行卡回调更新数据失败");
|
||||
}
|
||||
return getKlkCommonResp();
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 提现结果回调处理
|
||||
*/
|
||||
/*@RequestMapping("/withdrawal")
|
||||
public Map<String, String> withdrawal(@RequestBody String requestBody) throws Exception {
|
||||
System.out.println("提现结果开始回调...");
|
||||
|
||||
// 1. 配置初始化
|
||||
doInit();
|
||||
//业务处理
|
||||
JSONObject respData = JSON.parseObject(requestBody);
|
||||
String separateNo = respData.getString("separate_no");
|
||||
String outSeparateNo = respData.getString("out_separate_no");
|
||||
String finalStatus = respData.getString("final_status");
|
||||
String cmdType = respData.getString("cmd_type");
|
||||
|
||||
if("SEPARATE".equals(cmdType)){
|
||||
TzWithdrawRequest withdrawRequest = withdrawRequestService.queryWithdrawRequest(separateNo, outSeparateNo);
|
||||
if (withdrawRequest != null) {
|
||||
if("SUCCESS".equals(finalStatus)){
|
||||
withdrawRequest.setWithdrawStatus(3);
|
||||
withdrawRequestService.updateById(withdrawRequest);
|
||||
return getKlkCommonResp();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 会员兑换码订单回调地址
|
||||
*/
|
||||
/*@RequestMapping("/codeOrder")
|
||||
public Map<String, String> codeOrder(@RequestBody String requestBody) throws Exception {
|
||||
System.out.println("会员兑换码订单开始回调...");
|
||||
// 1. 配置初始化
|
||||
doInit();
|
||||
//业务处理
|
||||
JSONObject respData = JSON.parseObject(requestBody);
|
||||
String orderNo = respData.getString("out_order_no");
|
||||
String payOrderNo = respData.getString("pay_order_no");
|
||||
String orderStatus = respData.getString("order_status");
|
||||
|
||||
if ("2".equals(orderStatus)) {
|
||||
HyCodeOrder codeOrder = codeOrderService.queryByOrderNo(orderNo, payOrderNo);
|
||||
boolean result = codeOrderService.generateMemberCodes(codeOrder.getId());
|
||||
if (result) {
|
||||
return getKlkCommonResp();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
* 读取请求头
|
||||
*/
|
||||
private String getAuthorization(HttpServletRequest request) {
|
||||
return request.getHeader("Authorization");
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取请求体
|
||||
*/
|
||||
private String getBody(HttpServletRequest request) {
|
||||
try (InputStreamReader in = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8)) {
|
||||
StringBuilder bf = new StringBuilder();
|
||||
int len;
|
||||
char[] chs = new char[1024];
|
||||
while ((len = in.read(chs)) != -1) {
|
||||
bf.append(new String(chs, 0, len));
|
||||
}
|
||||
return bf.toString();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("读取body失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Integer getWithdrawalStatus(String drawState) {
|
||||
//提现状态:1-处理中 2-已受理 3-成功 4-失败 5-冻结 -1-未关联卡拉卡平台
|
||||
if ("DRAW.PROCESSING".equals(drawState)) {
|
||||
return 1;
|
||||
} else if ("DRAW.ACCEPTED".equals(drawState)) {
|
||||
return 2;
|
||||
} else if ("DRAW.SUCCESS".equals(drawState)) {
|
||||
return 3;
|
||||
} else if ("DRAW.FAILED".equals(drawState)) {
|
||||
return 4;
|
||||
} else if ("DRAW.FREEZE".equals(drawState)) {
|
||||
return 5;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 卡拉卡回调统一响应
|
||||
* {
|
||||
* "code":"SUCCESS",
|
||||
* "message":"执行成功"
|
||||
* }
|
||||
*/
|
||||
public Map<String, String> getKlkCommonResp() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("code", "SUCCESS");
|
||||
map.put("message", "执行成功");
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,344 @@
|
||||
package org.dromara.web.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.validate.AddGroup;
|
||||
import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.web.utils.SecurityUtils;
|
||||
import org.dromara.work.domain.bo.*;
|
||||
import org.dromara.work.domain.vo.*;
|
||||
import org.dromara.work.service.*;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 首页接口
|
||||
* @Author: Maosw
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/index")
|
||||
@Tag(name = "首页接口")
|
||||
public class ApiIndexController {
|
||||
|
||||
private final ITpPictureService tpPictureService;
|
||||
|
||||
private final ITpCategoryService tpCategoryService;
|
||||
|
||||
private final ITpWorksNumService tpWorksNumService;
|
||||
|
||||
private final ITpDynamicsNumService tpDynamicsNumService;
|
||||
|
||||
private final ITpCommentsService tpCommentsService;
|
||||
|
||||
private final ITpFollowService tpFollowService;
|
||||
|
||||
/**
|
||||
* 分页获取首页轮播/作品/动态列表
|
||||
*/
|
||||
@GetMapping("/tpPictureList")
|
||||
public R<IPage<TpPictureVo>> tpPictureList(TpPictureBo bo, PageQuery pageQuery) {
|
||||
bo.setStatus(1);
|
||||
return R.ok(tpPictureService.selectPageList(bo, null, pageQuery));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取首页轮播/作品/动态列表(需要登录)
|
||||
*/
|
||||
@GetMapping("/tpPictureListLogin")
|
||||
public R<IPage<TpPictureVo>> tpPictureListLogin(TpPictureBo bo, PageQuery pageQuery) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
bo.setStatus(1);
|
||||
return R.ok(tpPictureService.selectPageList(bo, userId, pageQuery));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取我的作品/动态列表
|
||||
*/
|
||||
@GetMapping("/myTpPictureList")
|
||||
public R<IPage<TpPictureVo>> myTpPictureList(TpPictureBo bo, PageQuery pageQuery) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
bo.setUserId(userId);
|
||||
bo.setStatus(1);
|
||||
return R.ok(tpPictureService.selectPageMyList(bo, pageQuery));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取轮播/作品/动态详情
|
||||
*/
|
||||
@GetMapping("/tpPictureDetail/{id}")
|
||||
public R<TpPictureVo> tpPictureDetail(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
return R.ok(tpPictureService.queryById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布作品/动态
|
||||
*/
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/addTpPicture")
|
||||
public R<Long> addTpPicture(@Validated(AddGroup.class) @RequestBody TpPictureBo bo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
bo.setUserId(userId);
|
||||
return R.ok(tpPictureService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除我的作品/动态
|
||||
*/
|
||||
@DeleteMapping("/deleteTpPicture/{ids}")
|
||||
public R<Boolean> deleteTpPicture(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Long[] ids) {
|
||||
return R.ok(tpPictureService.deleteWithValidByIds(List.of(ids), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部分类
|
||||
* @param bo
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/tpCategoryList")
|
||||
public R<List<TpCategoryVo>> tpCategoryList(TpCategoryBo bo) {
|
||||
List<TpCategoryVo> list = tpCategoryService.queryList(bo);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 动态点赞/收藏
|
||||
*/
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/addTpDynamicsNum")
|
||||
public R<Boolean> addTpDynamicsNum(@Validated(AddGroup.class) @RequestBody TpDynamicsNumBo bo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
bo.setUserId(userId);
|
||||
return R.ok(tpDynamicsNumService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除我的点赞/收藏的动态
|
||||
*/
|
||||
@PostMapping("/deleteTpDynamicsNum")
|
||||
public R<Boolean> deleteTpDynamicsNum(@RequestBody TpDynamicsNumBo bo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
bo.setUserId(userId);
|
||||
return R.ok(tpDynamicsNumService.deleteTpDynamicsNum(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询我点赞/收藏的动态
|
||||
*/
|
||||
@GetMapping("/myTpDynamicsNumList")
|
||||
public R<IPage<TpDynamicsNumVo>> myTpDynamicsNumList(TpDynamicsNumBo bo, PageQuery pageQuery) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
bo.setUserId(userId);
|
||||
return R.ok(tpDynamicsNumService.selectPageList(bo, pageQuery));
|
||||
}
|
||||
|
||||
/**
|
||||
* 作品点赞/收藏
|
||||
*/
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/addTpWorksNum")
|
||||
public R<Boolean> addTpWorksNum(@Validated(AddGroup.class) @RequestBody TpWorksNumBo bo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
bo.setUserId(userId);
|
||||
return R.ok(tpWorksNumService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除我的点赞/收藏的作品
|
||||
*/
|
||||
@PostMapping("/deleteTpWorksNum")
|
||||
public R<Boolean> deleteTpWorksNum(@RequestBody TpWorksNumBo bo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
bo.setUserId(userId);
|
||||
return R.ok(tpWorksNumService.deleteTpWorksNum(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询我点赞/收藏的作品
|
||||
*/
|
||||
@GetMapping("/myTpWorksNumList")
|
||||
public R<IPage<TpWorksNumVo>> myTpWorksNumList(TpWorksNumBo bo, PageQuery pageQuery) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpWorksNumService.selectPageList(bo, pageQuery));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据作品ID查询我是否点赞/收藏了该作品
|
||||
*/
|
||||
@PostMapping("/getTpWorksNumById")
|
||||
public R<Boolean> getTpWorksNumById(@RequestBody TpWorksNumBo bo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpWorksNumService.selectOneByUserId(bo.getId(), bo.getType(), userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据动态ID查询我是否点赞/收藏了该动态
|
||||
*/
|
||||
@PostMapping("/getTpDynamicsNumById")
|
||||
public R<Boolean> getTpDynamicsNumById(@RequestBody TpDynamicsNumBo bo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpDynamicsNumService.selectOneByUserId(bo.getId(), bo.getType(), userId));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询评论列表
|
||||
*/
|
||||
@GetMapping("/tpCommentsList")
|
||||
public R<IPage<TpCommentsVo>> tpCommentsList(TpCommentsBo bo, PageQuery pageQuery) {
|
||||
return R.ok(tpCommentsService.selectPageList(bo, pageQuery));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布评论
|
||||
*/
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/addTpComments")
|
||||
public R<Boolean> addTpComments(@Validated(AddGroup.class) @RequestBody TpCommentsBo bo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
bo.setUserId(userId);
|
||||
return R.ok(tpCommentsService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除我的评论
|
||||
*/
|
||||
@DeleteMapping("/deleteTpComments/{ids}")
|
||||
public R<Boolean> deleteTpComments(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Long[] ids) {
|
||||
return R.ok(tpCommentsService.deleteWithValidByIds(List.of(ids), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关注
|
||||
*/
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/addTpFollow")
|
||||
public R<Boolean> addTpFollow(@Validated(AddGroup.class) @RequestBody TpFollowBo bo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
bo.setUserId(userId);
|
||||
return R.ok(tpFollowService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消关注
|
||||
*/
|
||||
@PostMapping("/deleteTpFollow")
|
||||
public R<Boolean> deleteTpFollow(@RequestBody TpFollowBo bo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
bo.setUserId(userId);
|
||||
return R.ok(tpFollowService.deleteTpFollow(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询我关注的人的动态
|
||||
*/
|
||||
@GetMapping("/myTpFollowList")
|
||||
public R<IPage<TpPictureVo>> myTpFollowList(PageQuery pageQuery) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
List<Long> ids = tpFollowService.queryListIds(userId);
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return R.fail("没有关注的人");
|
||||
}
|
||||
return R.ok(tpPictureService.queryPageListByIds(ids, userId, pageQuery));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询我是否关注了该用户
|
||||
*/
|
||||
@GetMapping("/getTpFollow/{id}")
|
||||
public R<Boolean> getTpFollow(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
TpFollowBo bo = new TpFollowBo();
|
||||
bo.setUserId(userId);
|
||||
bo.setToUserId(id);
|
||||
return R.ok(tpFollowService.exists(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id获取作品的点赞数、收藏数、评论数
|
||||
*/
|
||||
@GetMapping("/getTpPictureNum/{id}")
|
||||
public R<TpPictureNumVo> getTpPictureNum(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
TpPictureNumVo vo = new TpPictureNumVo();
|
||||
Long dynamicsNum = tpWorksNumService.queryListCounr(id,1);
|
||||
Long collectNum = tpWorksNumService.queryListCounr(id,2);
|
||||
Long commentsNum = tpCommentsService.queryListCounr(id,1);
|
||||
vo.setDynamicsNum(dynamicsNum);
|
||||
vo.setCollectNum(collectNum);
|
||||
vo.setCommentsNum(commentsNum);
|
||||
return R.ok(vo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据id获取作品的点赞数、收藏数、评论数(需要登录)
|
||||
*/
|
||||
@GetMapping("/getTpPictureNumLogin/{id}")
|
||||
public R<TpPictureNumVo> getTpPictureNumLogin(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
TpPictureNumVo vo = new TpPictureNumVo();
|
||||
Long dynamicsNum = tpWorksNumService.queryListCounr(id,1);
|
||||
Long collectNum = tpWorksNumService.queryListCounr(id,2);
|
||||
Long commentsNum = tpCommentsService.queryListCounr(id,1);
|
||||
//查询我是否点赞了该作品
|
||||
Boolean dynamics = tpWorksNumService.selectOneByUserId(id, 1, userId);
|
||||
//查询我是否收藏了该作品
|
||||
Boolean collect = tpWorksNumService.selectOneByUserId(id, 2, userId);
|
||||
vo.setDynamics(dynamics);
|
||||
vo.setCollect(collect);
|
||||
vo.setDynamicsNum(dynamicsNum);
|
||||
vo.setCollectNum(collectNum);
|
||||
vo.setCommentsNum(commentsNum);
|
||||
return R.ok(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id获取动态的点赞数、收藏数、评论数
|
||||
*/
|
||||
@GetMapping("/getTpPictureCount/{id}")
|
||||
public R<TpPictureNumVo> getTpDynamicsNum(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
TpPictureNumVo vo = new TpPictureNumVo();
|
||||
Long dynamicsNum = tpDynamicsNumService.queryListCounr(id,1);
|
||||
Long collectNum = tpDynamicsNumService.queryListCounr(id,2);
|
||||
Long commentsNum = tpCommentsService.queryListCounr(id,2);
|
||||
vo.setDynamicsNum(dynamicsNum);
|
||||
vo.setCollectNum(collectNum);
|
||||
vo.setCommentsNum(commentsNum);
|
||||
return R.ok(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id获取动态的点赞数、收藏数、评论数(需要登录)
|
||||
*/
|
||||
@GetMapping("/getTpPictureCountLogin/{id}")
|
||||
public R<TpPictureNumVo> getTpPictureCountLogin(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
TpPictureNumVo vo = new TpPictureNumVo();
|
||||
Long dynamicsNum = tpDynamicsNumService.queryListCounr(id,1);
|
||||
Long collectNum = tpDynamicsNumService.queryListCounr(id,2);
|
||||
Long commentsNum = tpCommentsService.queryListCounr(id,2);
|
||||
//查询我是否点赞了该动态
|
||||
Boolean dynamics = tpDynamicsNumService.selectOneByUserId(id, 1, userId);
|
||||
//查询我是否收藏了该动态
|
||||
Boolean collect = tpDynamicsNumService.selectOneByUserId(id, 2, userId);
|
||||
vo.setDynamics(dynamics);
|
||||
vo.setCollect(collect);
|
||||
vo.setDynamicsNum(dynamicsNum);
|
||||
vo.setCollectNum(collectNum);
|
||||
vo.setCommentsNum(commentsNum);
|
||||
return R.ok(vo);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package org.dromara.web.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.web.utils.SecurityUtils;
|
||||
import org.dromara.work.domain.bo.TpMessageBo;
|
||||
import org.dromara.work.domain.vo.TpMessageVo;
|
||||
import org.dromara.work.service.ITpMessageService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 消息接口
|
||||
* @Author: Maosw
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/msg")
|
||||
@Tag(name = "消息接口")
|
||||
public class ApiMsgController {
|
||||
|
||||
private final ITpMessageService tpMessageService;
|
||||
|
||||
/**
|
||||
* 分页获取我的消息列表
|
||||
* @param bo 消息对象
|
||||
* @return 消息列表
|
||||
*/
|
||||
@GetMapping("/messageList")
|
||||
public R<IPage<TpMessageVo>> messageList(TpMessageBo bo, PageQuery pageQuery) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
bo.setToUserId(userId);
|
||||
return R.ok(tpMessageService.selectPageList(bo, pageQuery));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取我的未读消息数量
|
||||
* @return 消息数量
|
||||
*/
|
||||
@GetMapping("/messageCount")
|
||||
public R<Long> messageCount(TpMessageBo bo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
bo.setToUserId(userId);
|
||||
return R.ok(tpMessageService.count(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置消息已读
|
||||
*/
|
||||
@GetMapping("/messageRead/{id}")
|
||||
public R<Boolean> messageRead(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
TpMessageBo bo = new TpMessageBo();
|
||||
bo.setId(id);
|
||||
bo.setStatus(2);
|
||||
return R.ok(tpMessageService.updateByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取消息详情
|
||||
*/
|
||||
@GetMapping("/messageDetail/{id}")
|
||||
public R<TpMessageVo> messageDetail(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpMessageService.queryById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*/
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/sendMessage")
|
||||
public R<Boolean> sendMessage(TpMessageBo bo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpMessageService.insertByBo(bo));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
package org.dromara.web.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.validate.AddGroup;
|
||||
import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.web.utils.SecurityUtils;
|
||||
import org.dromara.work.domain.bo.TpAppealsBo;
|
||||
import org.dromara.work.domain.bo.TpOrderBo;
|
||||
import org.dromara.work.domain.vo.OrderCountVo;
|
||||
import org.dromara.work.domain.vo.TpAppealsVo;
|
||||
import org.dromara.work.domain.vo.TpOrderVo;
|
||||
import org.dromara.work.service.ITpAppealsService;
|
||||
import org.dromara.work.service.ITpNewOrderService;
|
||||
import org.dromara.work.service.ITpOrderService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 订单接口
|
||||
* @Author: Maosw
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/order")
|
||||
@Tag(name = "订单接口")
|
||||
public class ApiOrderController {
|
||||
|
||||
private final ITpAppealsService tpAppealsService;
|
||||
|
||||
private final ITpOrderService tpOrderService;
|
||||
|
||||
private final ITpNewOrderService tpNewOrderService;
|
||||
|
||||
/**
|
||||
* 新增申诉
|
||||
*/
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/addAppeals")
|
||||
public R<Boolean> addAppeals(@Validated(AddGroup.class) @RequestBody TpAppealsBo bo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
bo.setUserId(userId);
|
||||
return R.ok(tpAppealsService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID删除申诉
|
||||
*/
|
||||
@DeleteMapping("/deleteAppeals/{ids}")
|
||||
public R<Boolean> deleteAppeals(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
|
||||
return R.ok(tpAppealsService.deleteWithValidByIds(Arrays.asList(ids), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询我的申诉列表
|
||||
*/
|
||||
@GetMapping("/myAppealsList")
|
||||
public R<IPage<TpAppealsVo>> myAppealsList(TpAppealsBo bo, PageQuery pageQuery) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
bo.setUserId(userId);
|
||||
return R.ok(tpAppealsService.selectPageList(bo, pageQuery));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询申诉详情
|
||||
*/
|
||||
@GetMapping("/getAppeals/{id}")
|
||||
public R<TpAppealsVo> getAppeals(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
return R.ok(tpAppealsService.queryById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询订单列表
|
||||
*/
|
||||
@GetMapping("/orderList")
|
||||
public R<IPage<TpOrderVo>> orderList(TpOrderBo bo, PageQuery pageQuery) {
|
||||
return R.ok(tpNewOrderService.selectPageList(bo, pageQuery));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询我的订单列表
|
||||
*/
|
||||
@GetMapping("/myOrderList")
|
||||
public R<IPage<TpOrderVo>> myOrderList(TpOrderBo bo, PageQuery pageQuery) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
bo.setSid(userId);
|
||||
return R.ok(tpNewOrderService.selectPageList(bo, pageQuery));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询订单详情
|
||||
*/
|
||||
@GetMapping("/getOrder/{id}")
|
||||
public R<TpOrderVo> getOrder(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
return R.ok(tpNewOrderService.queryById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布订单
|
||||
*/
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/publishOrder")
|
||||
public R<Boolean> publishOrder(@Validated(AddGroup.class) @RequestBody TpOrderBo bo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpOrderService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改订单信息
|
||||
*/
|
||||
@RepeatSubmit()
|
||||
@PutMapping("/updateOrder")
|
||||
public R<Boolean> updateOrder(@RequestBody TpOrderBo bo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpOrderService.updateByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户删除订单
|
||||
*/
|
||||
@DeleteMapping("/deleteOrder/{ids}")
|
||||
public R<Boolean> deleteOrder(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpOrderService.deleteWithValidByIds(Arrays.asList(ids), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户取消订单
|
||||
*/
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/orderCancel/{id}")
|
||||
public R<Boolean> orderCancel(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpOrderService.orderCancel(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单指派技术
|
||||
*/
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/orderAssign")
|
||||
public R<Boolean> orderAssign(@RequestBody TpOrderBo bo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpOrderService.updateOrderAssign(bo.getOrderIds(),bo.getUserId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单取消指派
|
||||
*/
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/orderCancelAssign/{id}")
|
||||
public R<Boolean> orderCancelAssign(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpOrderService.orderCancelAssign(id) > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单支付获取订单和余额信息
|
||||
*/
|
||||
@GetMapping("/orderPay/{id}")
|
||||
public R<TpOrderVo> orderPay(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpOrderService.queryOrderPay(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单支付
|
||||
*/
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/orderPay")
|
||||
@Parameters({@Parameter(name = "orderId", description = "订单ID", required = true),@Parameter(name = "type", description = "类型:1-拉卡拉支付 2-余额", required = true)
|
||||
,@Parameter(name = "price", description = "支付金额", required = true)
|
||||
})
|
||||
public R<JSONObject> pay(@RequestParam(value = "orderId") Long orderId, @RequestParam(value = "type") Integer type, @RequestParam(value = "price") BigDecimal price) throws Exception {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpOrderService.orderPay(orderId,type,price));
|
||||
}
|
||||
|
||||
/**
|
||||
* 技术取消订单
|
||||
*/
|
||||
@GetMapping("/orderFallback/{id}")
|
||||
public R<Boolean> orderFallback(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpOrderService.jsOrderFallback(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户申请退款
|
||||
*/
|
||||
@GetMapping("/orderRefund/{id}")
|
||||
public R<Boolean> orderRefund(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpOrderService.orderRefund(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户取消退款
|
||||
*/
|
||||
@GetMapping("/orderCancelRefund/{id}")
|
||||
public R<Boolean> orderCancelRefund(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpOrderService.orderCancelRefund(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 技术处理订单退款
|
||||
*/
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/orderRefundJs")
|
||||
public R<Boolean> orderRefundJs(@RequestBody TpOrderBo bo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpOrderService.orderRefundJs(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 技术接单
|
||||
*/
|
||||
@GetMapping("/orderAccept/{id}")
|
||||
public R<Boolean> orderAccept(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpOrderService.orderAccept(id,userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户确认订单
|
||||
*/
|
||||
@GetMapping("/orderConfirm/{id}")
|
||||
public R<Boolean> orderConfirm(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return R.ok(tpOrderService.orderConfirm(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID统计订单信息
|
||||
*/
|
||||
@GetMapping("/countOrders/{userId}")
|
||||
public R<OrderCountVo> countOrders(@NotNull(message = "用户ID不能为空") @PathVariable Long userId) {
|
||||
return R.ok(tpOrderService.orderCount(userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单评论
|
||||
*/
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/addComment")
|
||||
public R<Boolean> addComment(@Validated(AddGroup.class) @RequestBody TpAppealsBo bo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
bo.setUserId(userId);
|
||||
return R.ok(tpOrderService.addComment(bo));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
package org.dromara.web.controller;
|
||||
|
||||
import cn.dev33.satoken.secure.BCrypt;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.lakala.zf.laop.java.sdk.demo.utils.KlkConstant;
|
||||
import com.lakala.zf.laop.java.sdk.demo.utils.LakalaUtils;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.system.domain.SysUser;
|
||||
import org.dromara.system.domain.vo.SysUserVo;
|
||||
import org.dromara.system.service.ISysUserService;
|
||||
import org.dromara.web.utils.*;
|
||||
import org.dromara.work.domain.TpFollow;
|
||||
import org.dromara.work.domain.TpUserAuth;
|
||||
import org.dromara.work.domain.bo.RechargeBo;
|
||||
import org.dromara.work.domain.bo.TpOrderPayBo;
|
||||
import org.dromara.work.domain.bo.TpUserAuthBo;
|
||||
import org.dromara.work.domain.vo.MyCountVo;
|
||||
import org.dromara.work.domain.vo.TpUserAuthVo;
|
||||
import org.dromara.work.service.*;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 用户接口
|
||||
* @author Maosw
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/user")
|
||||
@Tag(name = "用户接口")
|
||||
public class ApiUserController {
|
||||
|
||||
private final ISysUserService tzUserService;
|
||||
|
||||
private final TokenStore tokenStore;
|
||||
|
||||
private final ITpUserAuthService tpUserAuthService;
|
||||
|
||||
private final ITpFollowService tpFollowService;
|
||||
|
||||
private final ITpWorksNumService tpWorksNumService;
|
||||
|
||||
private final ITpPictureService tpPictureService;
|
||||
|
||||
private final ITpOrderPayService tpOrderPayService;
|
||||
|
||||
|
||||
@PostMapping("/getUserPhoneNumber")
|
||||
@Operation(summary = "微信接口获取手机号码" , description = "微信接口获取手机号码")
|
||||
@Parameter(name = "code", description = "code", required = true)
|
||||
public R<JSONObject> getUserPhoneNumber(@RequestParam(value = "code") String code) {
|
||||
return R.ok(WxXcxUtils.getUserPhoneNumber(code));
|
||||
}
|
||||
|
||||
@PostMapping("/register")
|
||||
@Operation(summary = "注册登录" , description = "用户绑定手机号注册登录")
|
||||
public R<TokenInfoVO> register(@Valid @RequestBody UserRegisterParam userRegisterParam) {
|
||||
if (StrUtil.isBlank(userRegisterParam.getNickName())) {
|
||||
userRegisterParam.setNickName(userRegisterParam.getUserName());
|
||||
}
|
||||
|
||||
SysUser tzUser = tzUserService.getUserByUserMobile(userRegisterParam.getMobile());
|
||||
if (ObjectUtil.isNotEmpty(tzUser)) {
|
||||
//登录
|
||||
UserInfoInTokenBO userInfoInTokenBO = new UserInfoInTokenBO();
|
||||
userInfoInTokenBO.setUserId(tzUser.getUserId());
|
||||
userInfoInTokenBO.setSysType(0);
|
||||
userInfoInTokenBO.setEnabled(true);
|
||||
return R.ok(tokenStore.storeAndGetVo(userInfoInTokenBO));
|
||||
}else {
|
||||
//注册并登录
|
||||
Date now = new Date();
|
||||
SysUser user = new SysUser();
|
||||
user.setLoginDate(now);
|
||||
user.setCreateTime(now);
|
||||
user.setStatus("0");
|
||||
user.setPhonenumber(userRegisterParam.getMobile());
|
||||
user.setUserName(userRegisterParam.getMobile());
|
||||
user.setNickName(userRegisterParam.getNickName());
|
||||
user.setEmail(userRegisterParam.getUserMail());
|
||||
user.setAvatar(userRegisterParam.getImg());
|
||||
user.setIdentity(userRegisterParam.getSysType());
|
||||
user.setPassword(BCrypt.hashpw(userRegisterParam.getPassWord()));
|
||||
user.setOpenId(userRegisterParam.getOpenId());
|
||||
tzUserService.save(user);
|
||||
// 2. 登录
|
||||
UserInfoInTokenBO userInfoInTokenBO = new UserInfoInTokenBO();
|
||||
userInfoInTokenBO.setUserId(user.getUserId());
|
||||
userInfoInTokenBO.setSysType(0);
|
||||
userInfoInTokenBO.setEnabled(true);
|
||||
return R.ok(tokenStore.storeAndGetVo(userInfoInTokenBO));
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/updatePwd")
|
||||
@Operation(summary = "修改密码" , description = "修改密码")
|
||||
public R<Boolean> updatePwd(@Valid @RequestBody UserRegisterParam userPwdUpdateParam) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
SysUserVo user = tzUserService.selectUserById(userId);
|
||||
if (user == null) {
|
||||
// 无法获取用户信息
|
||||
throw new ServiceException("无法获取用户信息");
|
||||
}
|
||||
if (StrUtil.isBlank(userPwdUpdateParam.getPassWord())) {
|
||||
// 新密码不能为空
|
||||
throw new ServiceException("新密码不能为空");
|
||||
}
|
||||
String password = BCrypt.hashpw(userPwdUpdateParam.getPassWord());
|
||||
if (StrUtil.equals(password, user.getPassword())) {
|
||||
// 新密码不能与原密码相同
|
||||
throw new ServiceException("新密码不能与原密码相同");
|
||||
}
|
||||
user.setPassword(password);
|
||||
|
||||
SysUser tzUser = MapstructUtils.convert(user, SysUser.class);
|
||||
return R.ok(tzUserService.updateById(tzUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改昵称/头像
|
||||
*/
|
||||
@PutMapping("/updateUserInfo")
|
||||
@Operation(summary = "修改昵称/头像" , description = "修改昵称/头像")
|
||||
public R<Boolean> updateUserInfo(@Valid @RequestBody SysUserVo sysUserVo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
SysUserVo user = tzUserService.selectUserById(userId);
|
||||
if (user == null) {
|
||||
// 无法获取用户信息
|
||||
throw new ServiceException("无法获取用户信息");
|
||||
}
|
||||
if (StrUtil.isNotBlank(sysUserVo.getNickName())) {
|
||||
user.setNickName(sysUserVo.getNickName());
|
||||
}
|
||||
if (StrUtil.isNotBlank(sysUserVo.getAvatar())) {
|
||||
user.setAvatar(sysUserVo.getAvatar());
|
||||
}
|
||||
SysUser tzUser = MapstructUtils.convert(user, SysUser.class);
|
||||
return R.ok(tzUserService.updateById(tzUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户提交认证信息
|
||||
*/
|
||||
@PostMapping("/submitUserAuth")
|
||||
@Operation(summary = "用户提交认证信息" , description = "用户提交认证信息")
|
||||
public R<Boolean> submitUserAuth(@Valid @RequestBody TpUserAuthBo tpUserAuthBo) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
tpUserAuthBo.setUserId(userId);
|
||||
tpUserAuthBo.setStatus(1);
|
||||
return R.ok(tpUserAuthService.insertByBo(tpUserAuthBo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户获取认证信息
|
||||
*/
|
||||
@GetMapping("/getUserAuth")
|
||||
@Operation(summary = "用户获取认证信息" , description = "用户获取认证信息")
|
||||
public R<TpUserAuthVo> getUserAuth() {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
LambdaQueryWrapper<TpUserAuth> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TpUserAuth::getUserId, userId);
|
||||
TpUserAuth tpUserAuth = tpUserAuthService.getOne(queryWrapper);
|
||||
return R.ok(MapstructUtils.convert(tpUserAuth, TpUserAuthVo.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取我的信息
|
||||
*/
|
||||
@GetMapping("/getMyInfo")
|
||||
@Operation(summary = "获取我的信息" , description = "获取我的信息")
|
||||
public R<SysUserVo> getMyInfo() {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
SysUserVo user = tzUserService.queryUserById(userId);
|
||||
return R.ok(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID获取用户信息
|
||||
*/
|
||||
@GetMapping("/getUserInfo/{userId}")
|
||||
@Operation(summary = "根据用户ID获取用户信息" , description = "根据用户ID获取用户信息")
|
||||
public R<SysUserVo> getUserInfo(@PathVariable Long userId) {
|
||||
SysUserVo user = tzUserService.selectUserById(userId);
|
||||
return R.ok(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取我的关注数、粉丝数、收藏作品数、我的作品数、我的动态数
|
||||
*/
|
||||
@GetMapping("/getMyCount")
|
||||
@Operation(summary = "获取我的关注数、粉丝数、收藏作品数、我的作品数" , description = "获取我的关注数、粉丝数、收藏作品数、我的作品数")
|
||||
public R<MyCountVo> getMyCount() {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
MyCountVo myCountVo = new MyCountVo();
|
||||
myCountVo.setFollowCount(tpFollowService.getFollowCount(userId));
|
||||
myCountVo.setFansCount(tpFollowService.getFansCount(userId));
|
||||
myCountVo.setCollectCount(tpWorksNumService.getCollectionCount(userId));
|
||||
myCountVo.setMyPictureCount(tpPictureService.getMyPictureCount(userId,2));
|
||||
myCountVo.setMyDynamicsCount(tpPictureService.getMyPictureCount(userId,3));
|
||||
return R.ok(myCountVo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID获取用户的关注数、粉丝数、收藏作品数、作品数
|
||||
*/
|
||||
@GetMapping("/getUserCount/{userId}")
|
||||
@Operation(summary = "根据用户ID获取用户的关注数、粉丝数、收藏作品数、作品数" , description = "根据用户ID获取用户的关注数、粉丝数、收藏作品数、作品数")
|
||||
public R<MyCountVo> getUserCount(@PathVariable Long userId) {
|
||||
MyCountVo myCountVo = new MyCountVo();
|
||||
myCountVo.setFollowCount(tpFollowService.getFollowCount(userId));
|
||||
myCountVo.setFansCount(tpFollowService.getFansCount(userId));
|
||||
myCountVo.setCollectCount(tpWorksNumService.getCollectionCount(userId));
|
||||
myCountVo.setMyPictureCount(tpPictureService.getMyPictureCount(userId,2));
|
||||
myCountVo.setMyDynamicsCount(tpPictureService.getMyPictureCount(userId,3));
|
||||
return R.ok(myCountVo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取我的关注用户列表
|
||||
*/
|
||||
@GetMapping("/getMyFollowList")
|
||||
@Operation(summary = "分页获取我的关注用户列表" , description = "分页获取我的关注用户列表")
|
||||
public R<IPage<SysUserVo>> getMyFollowList(PageQuery pageQuery) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
List<Long> userIds = tpFollowService.queryListIds(userId);
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
return R.fail("没有关注人");
|
||||
}
|
||||
LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysUser::getDelFlag, 0);
|
||||
queryWrapper.in(SysUser::getUserId, userIds);
|
||||
return R.ok(tzUserService.selectPageList(pageQuery, queryWrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取我的粉丝用户列表
|
||||
*/
|
||||
@GetMapping("/getMyFansList")
|
||||
@Operation(summary = "分页获取我的粉丝用户列表" , description = "分页获取我的粉丝用户列表")
|
||||
public R<IPage<SysUserVo>> getMyFansList(PageQuery pageQuery) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
LambdaQueryWrapper<TpFollow> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TpFollow::getToUserId, userId);
|
||||
List<Long> userIds = tpFollowService.queryListToUserIds(userId);
|
||||
LambdaQueryWrapper<SysUser> queryWrapper2 = new LambdaQueryWrapper<>();
|
||||
queryWrapper2.eq(SysUser::getDelFlag, 0);
|
||||
queryWrapper2.in(SysUser::getUserId, userIds);
|
||||
return R.ok(tzUserService.selectPageList(pageQuery, queryWrapper2));
|
||||
}
|
||||
|
||||
/**
|
||||
* 余额充值
|
||||
*/
|
||||
@PostMapping("/recharge")
|
||||
@Operation(summary = "余额充值" , description = "余额充值")
|
||||
public R<JSONObject> recharge(@Valid @RequestBody RechargeBo rechargeBo) throws Exception {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
SysUserVo sysUser = tzUserService.selectUserById(userId);
|
||||
String uuid = UUID.randomUUID().toString().replace("-", "");
|
||||
|
||||
JSONObject jsonObject = LakalaUtils.createOrderPay(uuid, rechargeBo.getPrice(), KlkConstant.RECHARGE_ORDER);
|
||||
if ("000000".equals(jsonObject.get("code"))) {
|
||||
System.out.println(jsonObject.get("resp_data").toString());
|
||||
JSONObject respData = jsonObject.getJSONObject("resp_data");
|
||||
String payOrderNo = respData.getString("pay_order_no");
|
||||
|
||||
TpOrderPayBo orderPay = new TpOrderPayBo();
|
||||
orderPay.setUserId(sysUser.getUserId());
|
||||
orderPay.setUserName(sysUser.getRealName());
|
||||
orderPay.setUserPhone(sysUser.getPhonenumber());
|
||||
orderPay.setAmount(rechargeBo.getPrice());
|
||||
orderPay.setStatus(1);
|
||||
orderPay.setMethod(1);
|
||||
orderPay.setType(2);
|
||||
orderPay.setOrderNo(uuid);
|
||||
orderPay.setTransactionId(payOrderNo);
|
||||
orderPay.setCreateTime(new Date());
|
||||
if (!tpOrderPayService.insertByBo(orderPay)){
|
||||
throw new ServiceException("创建支付订单失败");
|
||||
}
|
||||
} else {
|
||||
throw new ServiceException("拉卡拉拉发起支付失败");
|
||||
}
|
||||
return R.ok(jsonObject);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
package org.dromara.web.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.request.AuthRequest;
|
||||
import me.zhyd.oauth.utils.AuthStateUtils;
|
||||
import org.anyline.util.encrypt.MD5Util;
|
||||
import org.dromara.common.core.constant.SystemConstants;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.domain.model.LoginBody;
|
||||
import org.dromara.common.core.domain.model.PasswordLoginBody;
|
||||
import org.dromara.common.core.domain.model.RegisterBody;
|
||||
import org.dromara.common.core.domain.model.SocialLoginBody;
|
||||
import org.dromara.common.core.utils.*;
|
||||
import org.dromara.common.encrypt.annotation.ApiEncrypt;
|
||||
import org.dromara.common.json.utils.JsonUtils;
|
||||
import org.dromara.common.json.utils.UserUtils;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.common.social.config.properties.SocialLoginConfigProperties;
|
||||
import org.dromara.common.social.config.properties.SocialProperties;
|
||||
import org.dromara.common.social.utils.SocialUtils;
|
||||
import org.dromara.common.sse.dto.SseMessageDto;
|
||||
import org.dromara.common.sse.utils.SseMessageUtils;
|
||||
import org.dromara.common.tenant.helper.TenantHelper;
|
||||
import org.dromara.system.domain.bo.SysTenantBo;
|
||||
import org.dromara.system.domain.vo.SysClientVo;
|
||||
import org.dromara.system.domain.vo.SysTenantVo;
|
||||
import org.dromara.system.service.ISysClientService;
|
||||
import org.dromara.system.service.ISysConfigService;
|
||||
import org.dromara.system.service.ISysSocialService;
|
||||
import org.dromara.system.service.ISysTenantService;
|
||||
import org.dromara.web.domain.vo.LoginTenantVo;
|
||||
import org.dromara.web.domain.vo.LoginVo;
|
||||
import org.dromara.web.domain.vo.TenantListVo;
|
||||
import org.dromara.web.service.IAuthStrategy;
|
||||
import org.dromara.web.service.SysLoginService;
|
||||
import org.dromara.web.service.SysRegisterService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 认证
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Slf4j
|
||||
@SaIgnore
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/auth")
|
||||
public class AuthController {
|
||||
|
||||
private final SocialProperties socialProperties;
|
||||
private final SysLoginService loginService;
|
||||
private final SysRegisterService registerService;
|
||||
private final ISysConfigService configService;
|
||||
private final ISysTenantService tenantService;
|
||||
private final ISysSocialService socialUserService;
|
||||
private final ISysClientService clientService;
|
||||
private final ScheduledExecutorService scheduledExecutorService;
|
||||
|
||||
|
||||
/**
|
||||
* 登录方法
|
||||
*
|
||||
* @param body 登录信息
|
||||
* @return 结果
|
||||
*/
|
||||
@ApiEncrypt
|
||||
@PostMapping("/login")
|
||||
public R<LoginVo> login(@RequestBody String body) {
|
||||
LoginBody loginBody = JsonUtils.parseObject(body, LoginBody.class);
|
||||
ValidatorUtils.validate(loginBody);
|
||||
// 授权类型和客户端id
|
||||
String clientId = loginBody.getClientId();
|
||||
String grantType = loginBody.getGrantType();
|
||||
SysClientVo client = clientService.queryByClientId(clientId);
|
||||
// validateCaptcha(body,request);
|
||||
// 查询不到 client 或 client 内不包含 grantType
|
||||
if (ObjectUtil.isNull(client) || !StringUtils.contains(client.getGrantType(), grantType)) {
|
||||
log.info("客户端id: {} 认证类型:{} 异常!.", clientId, grantType);
|
||||
return R.fail(MessageUtils.message("auth.grant.type.error"));
|
||||
} else if (!SystemConstants.NORMAL.equals(client.getStatus())) {
|
||||
return R.fail(MessageUtils.message("auth.grant.type.blocked"));
|
||||
}
|
||||
// 校验租户
|
||||
loginService.checkTenant(loginBody.getTenantId());
|
||||
// 登录
|
||||
LoginVo loginVo = IAuthStrategy.login(body, client, grantType);
|
||||
|
||||
Long userId = LoginHelper.getUserId();
|
||||
scheduledExecutorService.schedule(() -> {
|
||||
SseMessageDto dto = new SseMessageDto();
|
||||
dto.setMessage("欢迎登录DD画图业务后台管理系统");
|
||||
dto.setUserIds(List.of(userId));
|
||||
SseMessageUtils.publishMessage(dto);
|
||||
}, 5, TimeUnit.SECONDS);
|
||||
return R.ok(loginVo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取跳转URL
|
||||
*
|
||||
* @param source 登录来源
|
||||
* @return 结果
|
||||
*/
|
||||
@GetMapping("/binding/{source}")
|
||||
public R<String> authBinding(@PathVariable("source") String source,
|
||||
@RequestParam String tenantId, @RequestParam String domain) {
|
||||
SocialLoginConfigProperties obj = socialProperties.getType().get(source);
|
||||
if (ObjectUtil.isNull(obj)) {
|
||||
return R.fail(source + "平台账号暂不支持");
|
||||
}
|
||||
AuthRequest authRequest = SocialUtils.getAuthRequest(source, socialProperties);
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("tenantId", tenantId);
|
||||
map.put("domain", domain);
|
||||
map.put("state", AuthStateUtils.createState());
|
||||
String authorizeUrl = authRequest.authorize(Base64.encode(JsonUtils.toJsonString(map), StandardCharsets.UTF_8));
|
||||
return R.ok("操作成功", authorizeUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 前端回调绑定授权(需要token)
|
||||
*
|
||||
* @param loginBody 请求体
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/social/callback")
|
||||
public R<Void> socialCallback(@RequestBody SocialLoginBody loginBody) {
|
||||
// 校验token
|
||||
StpUtil.checkLogin();
|
||||
// 获取第三方登录信息
|
||||
AuthResponse<AuthUser> response = SocialUtils.loginAuth(
|
||||
loginBody.getSource(), loginBody.getSocialCode(),
|
||||
loginBody.getSocialState(), socialProperties);
|
||||
AuthUser authUserData = response.getData();
|
||||
// 判断授权响应是否成功
|
||||
if (!response.ok()) {
|
||||
return R.fail(response.getMsg());
|
||||
}
|
||||
loginService.socialRegister(authUserData);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取消授权(需要token)
|
||||
*
|
||||
* @param socialId socialId
|
||||
*/
|
||||
@DeleteMapping(value = "/unlock/{socialId}")
|
||||
public R<Void> unlockSocial(@PathVariable Long socialId) {
|
||||
// 校验token
|
||||
StpUtil.checkLogin();
|
||||
Boolean rows = socialUserService.deleteWithValidById(socialId);
|
||||
return rows ? R.ok() : R.fail("取消授权失败");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
@PostMapping("/logout")
|
||||
public R<Void> logout() {
|
||||
loginService.logout();
|
||||
return R.ok("退出成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
*/
|
||||
@ApiEncrypt
|
||||
@PostMapping("/register")
|
||||
public R<Void> register(@Validated @RequestBody RegisterBody user) {
|
||||
if (!configService.selectRegisterEnabled(user.getTenantId())) {
|
||||
return R.fail("当前系统没有开启注册功能!");
|
||||
}
|
||||
registerService.register(user);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录页面租户下拉框
|
||||
*
|
||||
* @return 租户列表
|
||||
*/
|
||||
@GetMapping("/tenant/list")
|
||||
public R<LoginTenantVo> tenantList(HttpServletRequest request) throws Exception {
|
||||
// 返回对象
|
||||
LoginTenantVo result = new LoginTenantVo();
|
||||
boolean enable = TenantHelper.isEnable();
|
||||
result.setTenantEnabled(enable);
|
||||
// 如果未开启租户这直接返回
|
||||
if (!enable) {
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
List<SysTenantVo> tenantList = tenantService.queryList(new SysTenantBo());
|
||||
List<TenantListVo> voList = MapstructUtils.convert(tenantList, TenantListVo.class);
|
||||
try {
|
||||
// 如果只超管返回所有租户
|
||||
if (LoginHelper.isSuperAdmin()) {
|
||||
result.setVoList(voList);
|
||||
return R.ok(result);
|
||||
}
|
||||
} catch (NotLoginException ignored) {
|
||||
}
|
||||
|
||||
// 获取域名
|
||||
String host;
|
||||
String referer = request.getHeader("referer");
|
||||
if (StringUtils.isNotBlank(referer)) {
|
||||
// 这里从referer中取值是为了本地使用hosts添加虚拟域名,方便本地环境调试
|
||||
host = referer.split("//")[1].split("/")[0];
|
||||
} else {
|
||||
host = new URL(request.getRequestURL().toString()).getHost();
|
||||
}
|
||||
// 根据域名进行筛选
|
||||
List<TenantListVo> list = StreamUtils.filter(voList, vo ->
|
||||
StringUtils.equalsIgnoreCase(vo.getDomain(), host));
|
||||
result.setVoList(CollUtil.isNotEmpty(list) ? list : voList);
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
|
||||
public static void validateCaptcha(String body, HttpServletRequest request) {
|
||||
PasswordLoginBody loginBody = JsonUtils.parseObject(body, PasswordLoginBody.class);
|
||||
ValidatorUtils.validate(loginBody);
|
||||
String username = loginBody.getUsername();
|
||||
String name = MD5Util.crypto(username);
|
||||
UserUtils.validate(name,body,request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package org.dromara.web.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import cn.hutool.captcha.AbstractCaptcha;
|
||||
import cn.hutool.captcha.generator.CodeGenerator;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.constant.Constants;
|
||||
import org.dromara.common.core.constant.GlobalConstants;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.core.utils.reflect.ReflectUtils;
|
||||
import org.dromara.common.mail.config.properties.MailProperties;
|
||||
import org.dromara.common.mail.utils.MailUtils;
|
||||
import org.dromara.common.ratelimiter.annotation.RateLimiter;
|
||||
import org.dromara.common.ratelimiter.enums.LimitType;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import org.dromara.common.web.config.properties.CaptchaProperties;
|
||||
import org.dromara.common.web.enums.CaptchaType;
|
||||
import org.dromara.sms4j.api.SmsBlend;
|
||||
import org.dromara.sms4j.api.entity.SmsResponse;
|
||||
import org.dromara.sms4j.core.factory.SmsFactory;
|
||||
import org.dromara.web.domain.vo.CaptchaVo;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/**
|
||||
* 验证码操作处理
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@SaIgnore
|
||||
@Slf4j
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
public class CaptchaController {
|
||||
|
||||
private final CaptchaProperties captchaProperties;
|
||||
private final MailProperties mailProperties;
|
||||
|
||||
/**
|
||||
* 短信验证码
|
||||
*
|
||||
* @param phonenumber 用户手机号
|
||||
*/
|
||||
@RateLimiter(key = "#phonenumber", time = 60, count = 1)
|
||||
@GetMapping("/resource/sms/code")
|
||||
public R<Void> smsCode(@NotBlank(message = "{user.phonenumber.not.blank}") String phonenumber) {
|
||||
String key = GlobalConstants.CAPTCHA_CODE_KEY + phonenumber;
|
||||
String code = RandomUtil.randomNumbers(4);
|
||||
RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
|
||||
// 验证码模板id 自行处理 (查数据库或写死均可)
|
||||
String templateId = "";
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
|
||||
map.put("code", code);
|
||||
SmsBlend smsBlend = SmsFactory.getSmsBlend("config1");
|
||||
SmsResponse smsResponse = smsBlend.sendMessage(phonenumber, templateId, map);
|
||||
if (!smsResponse.isSuccess()) {
|
||||
log.error("验证码短信发送异常 => {}", smsResponse);
|
||||
return R.fail(smsResponse.getData().toString());
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮箱验证码
|
||||
*
|
||||
* @param email 邮箱
|
||||
*/
|
||||
@GetMapping("/resource/email/code")
|
||||
public R<Void> emailCode(@NotBlank(message = "{user.email.not.blank}") String email) {
|
||||
if (!mailProperties.getEnabled()) {
|
||||
return R.fail("当前系统没有开启邮箱功能!");
|
||||
}
|
||||
SpringUtils.getAopProxy(this).emailCodeImpl(email);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮箱验证码
|
||||
* 独立方法避免验证码关闭之后仍然走限流
|
||||
*/
|
||||
@RateLimiter(key = "#email", time = 60, count = 1)
|
||||
public void emailCodeImpl(String email) {
|
||||
String key = GlobalConstants.CAPTCHA_CODE_KEY + email;
|
||||
String code = RandomUtil.randomNumbers(4);
|
||||
RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
|
||||
try {
|
||||
MailUtils.sendText(email, "登录验证码", "您本次验证码为:" + code + ",有效性为" + Constants.CAPTCHA_EXPIRATION + "分钟,请尽快填写。");
|
||||
} catch (Exception e) {
|
||||
log.error("验证码短信发送异常 => {}", e.getMessage());
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
*/
|
||||
@GetMapping("/auth/code")
|
||||
public R<CaptchaVo> getCode() {
|
||||
boolean captchaEnabled = captchaProperties.getEnable();
|
||||
if (!captchaEnabled) {
|
||||
CaptchaVo captchaVo = new CaptchaVo();
|
||||
captchaVo.setCaptchaEnabled(false);
|
||||
return R.ok(captchaVo);
|
||||
}
|
||||
return R.ok(SpringUtils.getAopProxy(this).getCodeImpl());
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
* 独立方法避免验证码关闭之后仍然走限流
|
||||
*/
|
||||
@RateLimiter(time = 60, count = 10, limitType = LimitType.IP)
|
||||
public CaptchaVo getCodeImpl() {
|
||||
// 保存验证码信息
|
||||
String uuid = IdUtil.simpleUUID();
|
||||
String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + uuid;
|
||||
// 生成验证码
|
||||
CaptchaType captchaType = captchaProperties.getType();
|
||||
boolean isMath = CaptchaType.MATH == captchaType;
|
||||
Integer length = isMath ? captchaProperties.getNumberLength() : captchaProperties.getCharLength();
|
||||
CodeGenerator codeGenerator = ReflectUtils.newInstance(captchaType.getClazz(), length);
|
||||
AbstractCaptcha captcha = SpringUtils.getBean(captchaProperties.getCategory().getClazz());
|
||||
captcha.setGenerator(codeGenerator);
|
||||
captcha.createCode();
|
||||
// 如果是数学验证码,使用SpEL表达式处理验证码结果
|
||||
String code = captcha.getCode();
|
||||
if (isMath) {
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
Expression exp = parser.parseExpression(StringUtils.remove(code, "="));
|
||||
code = exp.getValue(String.class);
|
||||
}
|
||||
RedisUtils.setCacheObject(verifyKey, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
|
||||
CaptchaVo captchaVo = new CaptchaVo();
|
||||
captchaVo.setUuid(uuid);
|
||||
captchaVo.setImg(captcha.getImageBase64());
|
||||
return captchaVo;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,642 @@
|
||||
package org.dromara.web.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.domain.model.LoginUser;
|
||||
import org.dromara.common.core.utils.DateUtils;
|
||||
import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.system.domain.bo.SysDeptBo;
|
||||
import org.dromara.system.domain.bo.SysUserBo;
|
||||
import org.dromara.system.domain.vo.SysUserVo;
|
||||
import org.dromara.system.service.ISysUserService;
|
||||
import org.dromara.web.utils.WxXcxUtils;
|
||||
import org.dromara.work.domain.TpReceipt;
|
||||
import org.dromara.work.domain.bo.*;
|
||||
import org.dromara.work.domain.vo.*;
|
||||
import org.dromara.work.service.*;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 首页
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@SaIgnore
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
public class IndexController {
|
||||
|
||||
private final ISysUserService sysUserService;
|
||||
|
||||
private final ITpWechatService tpWechatService;
|
||||
|
||||
private final ITpReceiptService tpReceiptService;
|
||||
|
||||
private final IOrderService orderService;
|
||||
|
||||
private final ITpNewOrderService tpNewOrderService;
|
||||
|
||||
private final ITpPictureService tpPictureService;
|
||||
|
||||
private final ITpProdService tpProdService;
|
||||
|
||||
|
||||
/**
|
||||
* 分页获取画册列表
|
||||
*/
|
||||
@GetMapping("/banner")
|
||||
public R<IPage<TpPictureVo>> list(TpPictureBo bo, PageQuery pageQuery) {
|
||||
bo.setStatus(1);
|
||||
return R.ok(tpPictureService.selectPageList(bo, null, pageQuery));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取画册详情
|
||||
*/
|
||||
@GetMapping("/banner/{id}")
|
||||
public R<TpPictureVo> getTpPictureInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
return R.ok(tpPictureService.queryById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取商品列表
|
||||
*/
|
||||
@GetMapping("/prod")
|
||||
public R<IPage<TpProdVo>> list(TpProdBo bo, PageQuery pageQuery) {
|
||||
bo.setStatus(1L);
|
||||
return R.ok(tpProdService.selectPageList(bo, pageQuery));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取商品详情
|
||||
*/
|
||||
@GetMapping("/prod/{id}")
|
||||
public R<TpProdVo> getTpProdInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
return R.ok(tpProdService.queryById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据url获取微信JS-SDK使用权限签名
|
||||
*/
|
||||
@PostMapping("/wx/jssdk")
|
||||
public R<Map<String, String>> getWxJssdk(@RequestParam String url) {
|
||||
return R.ok(WxXcxUtils.generateSignature(url));
|
||||
}
|
||||
|
||||
/**
|
||||
* 银盛支付回调
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
/**
|
||||
* 银盛支付回调
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/notifyCheckSign")
|
||||
@RepeatSubmit(interval = 1, timeUnit = TimeUnit.SECONDS, message = "重复请求")
|
||||
public String notifyCheckSign(@RequestParam Map<String, String> params) {
|
||||
try {
|
||||
// 校验输入参数并清理潜在危险字符
|
||||
validateAndSanitizeParams(params);
|
||||
String outTradeNo = params.get("out_trade_no");
|
||||
if (outTradeNo == null || outTradeNo.isEmpty()) {
|
||||
return "failure";
|
||||
}
|
||||
// 检查订单是否存在
|
||||
boolean exists = tpReceiptService.exists(new LambdaQueryWrapper<TpReceipt>().eq(TpReceipt::getOutTradeNo, outTradeNo));
|
||||
if (exists) {
|
||||
// 订单已存在
|
||||
return "success";
|
||||
}
|
||||
|
||||
// 订单不存在且交易状态为成功时,插入新记录
|
||||
String tradeStatus = params.get("trade_status");
|
||||
if ("TRADE_SUCCESS".equals(tradeStatus)) {
|
||||
TpReceiptBo tpReceipt = new TpReceiptBo();
|
||||
tpReceipt.setQid(80);
|
||||
tpReceipt.setRemark("小程序收银台T1订单");
|
||||
tpReceipt.setOutTradeNo(outTradeNo);
|
||||
tpReceipt.setTradeNo(params.get("trade_no"));
|
||||
tpReceipt.setPrice(new BigDecimal(params.get("total_amount")));
|
||||
tpReceipt.setHkTime(DateUtils.parseDate(params.get("notify_time")));
|
||||
tpReceipt.setAddTime(new Date());
|
||||
|
||||
// 插入新记录并捕获异常
|
||||
try {
|
||||
tpReceiptService.insertReceipt(tpReceipt);
|
||||
return "success";
|
||||
} catch (Exception e) {
|
||||
return "failure";
|
||||
}
|
||||
}
|
||||
return "failure";
|
||||
} catch (Exception e) {
|
||||
return "failure";
|
||||
}
|
||||
}
|
||||
|
||||
private void validateAndSanitizeParams(Map<String, String> params) {
|
||||
// 实现严格的参数校验和清理逻辑
|
||||
// 例如:去除特殊字符、检查长度、格式等
|
||||
// 确保所有参数都是安全的
|
||||
if (params == null || params.isEmpty()) {
|
||||
throw new IllegalArgumentException("参数不能为空");
|
||||
}
|
||||
if (!params.containsKey("out_trade_no") || !params.containsKey("trade_status")) {
|
||||
throw new IllegalArgumentException("缺少必要参数");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 首页统计
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/indexSum")
|
||||
public R<IndexSumVo> indexSum() {
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
if (loginUser.getIdentity() == 2){
|
||||
return R.ok(tpNewOrderService.getJsTarget());
|
||||
}else if (loginUser.getIdentity() == 3){
|
||||
return R.ok(tpNewOrderService.getKfTarget());
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新订单部门状态
|
||||
*/
|
||||
@SaCheckPermission("system:user:edit")
|
||||
@RepeatSubmit
|
||||
@PostMapping("/updateOrder")
|
||||
public R<Boolean> updateOrder(SysUserBo bo) {
|
||||
return R.ok(orderService.updateOrder(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 客服排行榜
|
||||
*/
|
||||
@SaCheckPermission("index:order:rankingListKF")
|
||||
@GetMapping("/rankingListKF")
|
||||
public TableDataInfo<OrderRankingVo> rankingListKF(OrderRankingBo bo, PageQuery pageQuery) {
|
||||
bo.setType(1);
|
||||
return tpNewOrderService.rankingList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 客服排行榜统计
|
||||
*/
|
||||
@SaCheckPermission("index:order:rankingListKF")
|
||||
@GetMapping("/rankingListKFSum")
|
||||
public R<OrderRankingSumVo> rankingListKFSum(OrderRankingBo bo) {
|
||||
bo.setType(1);
|
||||
return R.ok(tpNewOrderService.rankingListKFSum(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 技术排行榜
|
||||
*/
|
||||
@SaCheckPermission("index:order:rankingListJS")
|
||||
@GetMapping("/rankingListJS")
|
||||
public TableDataInfo<OrderRankingVo> rankingListJS(OrderRankingBo bo, PageQuery pageQuery) {
|
||||
bo.setType(2);
|
||||
return tpNewOrderService.rankingListJS(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 技术排行榜统计
|
||||
*/
|
||||
@SaCheckPermission("index:order:rankingListJS")
|
||||
@GetMapping("/rankingListJSSum")
|
||||
public R<OrderRankingSumVo> rankingListJSSum(OrderRankingBo bo) {
|
||||
bo.setType(2);
|
||||
return R.ok(tpNewOrderService.rankingListJSSum(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门排行榜(客服)
|
||||
*/
|
||||
@SaCheckPermission("index:order:deptRankingList")
|
||||
@GetMapping("/deptRankingList")
|
||||
public R<List<DeptRankingVo>> deptRankingList(SysDeptBo bo) {
|
||||
return R.ok(orderService.deptRankingList(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门排行榜(客服单个)
|
||||
*/
|
||||
@SaCheckPermission("index:order:deptRankingList")
|
||||
@GetMapping("/deptRankingList1")
|
||||
public R<List<DeptRankingVo>> deptRankingList1(SysDeptBo bo) {
|
||||
return R.ok(orderService.deptRankingList1(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门排行榜(技术)
|
||||
*/
|
||||
@SaCheckPermission("index:order:deptRankingJSList")
|
||||
@GetMapping("/deptRankingJSList")
|
||||
public R<List<DeptRankingVo>> deptRankingJSList(SysDeptBo bo) {
|
||||
return R.ok(orderService.deptRankingJSList(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门排行榜(技术/单个)
|
||||
*/
|
||||
@SaCheckPermission("index:order:deptRankingJSList")
|
||||
@GetMapping("/deptRankingJSList1")
|
||||
public R<List<DeptRankingVo>> deptRankingJSList1(SysDeptBo bo) {
|
||||
return R.ok(orderService.deptRankingJSList1(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户下单排行榜
|
||||
*/
|
||||
@SaCheckPermission("index:order:khRankingList")
|
||||
@GetMapping("/khRankingList")
|
||||
public TableDataInfo<OrderRankingVo> khRankingList(OrderRankingBo bo, PageQuery pageQuery) {
|
||||
return tpNewOrderService.khRankingList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户下单排行榜统计
|
||||
*/
|
||||
@SaCheckPermission("index:order:khRankingList")
|
||||
@GetMapping("/khRankingListSum")
|
||||
public R<OrderRankingSumVo> khRankingListSum(OrderRankingBo bo) {
|
||||
return R.ok(tpNewOrderService.khRankingListSum(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 客服部数据分析(日)
|
||||
* @param bo
|
||||
* @return
|
||||
*/
|
||||
@SaCheckPermission("index:order:kfDayList")
|
||||
@GetMapping("/kfDayList")
|
||||
public TableDataInfo<KfDayListVo> kfDayList(OrderRankingBo bo, PageQuery pageQuery) {
|
||||
SysUserBo user = new SysUserBo();
|
||||
user.setIdentity(3);
|
||||
user.setStatus("0");
|
||||
|
||||
if(ObjectUtil.isNotNull(bo.getUserName())){
|
||||
user.setNickName(bo.getUserName());
|
||||
}
|
||||
if(bo.getDeptId() != null){
|
||||
user.setDeptId(bo.getDeptId());
|
||||
}
|
||||
if (bo.getDeptIds() != null){
|
||||
user.setDeptIds(bo.getDeptIds());
|
||||
}
|
||||
|
||||
TableDataInfo<SysUserVo> list = sysUserService.selectPageGetUserList(user, pageQuery);
|
||||
List<Long> userIds = list.getRows().stream().map(SysUserVo::getUserId).collect(Collectors.toList());
|
||||
List<OrderDayListVo> listVoList = orderService.kfDayList(bo,userIds);
|
||||
|
||||
TableDataInfo<KfDayListVo> kfDayListVoList = new TableDataInfo<>();
|
||||
kfDayListVoList.setCode(list.getCode());
|
||||
kfDayListVoList.setMsg(list.getMsg());
|
||||
kfDayListVoList.setTotal(list.getTotal());
|
||||
List<KfDayListVo> kfList = new ArrayList<>();
|
||||
for (SysUserVo vo : list.getRows()){
|
||||
KfDayListVo kfDayListVo = new KfDayListVo();
|
||||
kfDayListVo.setSid(vo.getUserId());
|
||||
kfDayListVo.setName(vo.getNickName());
|
||||
kfDayListVo.setList(listVoList.stream().filter(item -> item.getSid().equals(vo.getUserId())).collect(Collectors.toList()));
|
||||
kfList.add(kfDayListVo);
|
||||
}
|
||||
kfDayListVoList.setRows(kfList);
|
||||
return kfDayListVoList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 微信好友分析(日)
|
||||
* @param bo
|
||||
* @return
|
||||
*/
|
||||
@SaCheckPermission("index:order:wxDayList")
|
||||
@GetMapping("/wxDayList")
|
||||
public TableDataInfo<WxDayListVo> wxDayList(OrderRankingBo bo, PageQuery pageQuery) {
|
||||
TpWechatBo wechatBo = new TpWechatBo();
|
||||
if(bo.getDeptId() != null){
|
||||
wechatBo.setCreateDept(bo.getDeptId());
|
||||
}
|
||||
if(ObjectUtil.isNotNull(bo.getUserName())){
|
||||
wechatBo.setCode(bo.getUserName());
|
||||
}
|
||||
if(ObjectUtil.isNotNull(bo.getRealName())){
|
||||
wechatBo.setUser(bo.getRealName());
|
||||
}
|
||||
TableDataInfo<TpWechatVo> list = tpWechatService.queryPageList(wechatBo, pageQuery);
|
||||
List<Long> wxIds = list.getRows().stream().map(TpWechatVo::getId).collect(Collectors.toList());
|
||||
List<WxNumDayListVo> listVoList = tpWechatService.wxDayList(bo,wxIds);
|
||||
|
||||
TableDataInfo<WxDayListVo> wxDayListVoList = new TableDataInfo<>();
|
||||
wxDayListVoList.setCode(list.getCode());
|
||||
wxDayListVoList.setMsg(list.getMsg());
|
||||
wxDayListVoList.setTotal(list.getTotal());
|
||||
List<WxDayListVo> wxList = new ArrayList<>();
|
||||
for (TpWechatVo vo : list.getRows()){
|
||||
WxDayListVo wxDayListVo = new WxDayListVo();
|
||||
wxDayListVo.setId(vo.getId());
|
||||
wxDayListVo.setCode(vo.getCode());
|
||||
wxDayListVo.setName(vo.getUser());
|
||||
wxDayListVo.setList(listVoList.stream().filter(item -> item.getWid().equals(vo.getId())).collect(Collectors.toList()));
|
||||
wxList.add(wxDayListVo);
|
||||
|
||||
}
|
||||
wxDayListVoList.setRows(wxList);
|
||||
return wxDayListVoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信好友分析(日)
|
||||
* @param bo
|
||||
* @return
|
||||
*/
|
||||
@SaCheckPermission("index:order:wxDayList")
|
||||
@GetMapping("/wxDayList1")
|
||||
public TableDataInfo<WxDayListVo> wxDayList1(OrderRankingBo bo, PageQuery pageQuery) {
|
||||
SysUserBo user = new SysUserBo();
|
||||
user.setIdentity(3);
|
||||
user.setStatus("0");
|
||||
|
||||
if(ObjectUtil.isNotNull(bo.getUserName())){
|
||||
user.setNickName(bo.getUserName());
|
||||
}
|
||||
if(bo.getDeptId() != null){
|
||||
user.setDeptId(bo.getDeptId());
|
||||
}
|
||||
if (bo.getDeptIds() != null){
|
||||
user.setDeptIds(bo.getDeptIds());
|
||||
}
|
||||
TableDataInfo<SysUserVo> list = sysUserService.selectPageGetUserList(user, pageQuery);
|
||||
if (!list.getRows().isEmpty()) {
|
||||
List<Long> userIds = list.getRows().stream().map(SysUserVo::getUserId).collect(Collectors.toList());
|
||||
|
||||
List<TpWechatVo> list1 = tpWechatService.queryListByIds(userIds);
|
||||
List<Long> wxIds = list1.stream().map(TpWechatVo::getId).collect(Collectors.toList());
|
||||
List<WxNumDayListVo> listVoList = tpWechatService.wxDayList(bo,wxIds);
|
||||
|
||||
|
||||
TableDataInfo<WxDayListVo> wxDayListVoList = new TableDataInfo<>();
|
||||
wxDayListVoList.setCode(list.getCode());
|
||||
wxDayListVoList.setMsg(list.getMsg());
|
||||
wxDayListVoList.setTotal(list.getTotal());
|
||||
List<WxDayListVo> wxList = new ArrayList<>();
|
||||
for (TpWechatVo vo : list1){
|
||||
WxDayListVo wxDayListVo = new WxDayListVo();
|
||||
wxDayListVo.setId(vo.getId());
|
||||
wxDayListVo.setCode(vo.getCode());
|
||||
wxDayListVo.setUid(vo.getUid());
|
||||
wxDayListVo.setName(vo.getUser());
|
||||
wxDayListVo.setList(listVoList.stream().filter(item -> item.getWid().equals(vo.getId())).collect(Collectors.toList()));
|
||||
wxList.add(wxDayListVo);
|
||||
}
|
||||
wxDayListVoList.setRows(wxList);
|
||||
return wxDayListVoList;
|
||||
}
|
||||
return TableDataInfo.build();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 微信好友分析(月)
|
||||
* @param bo
|
||||
* @return
|
||||
*/
|
||||
@SaCheckPermission("index:order:wxMonthList")
|
||||
@GetMapping("/wxMonthList")
|
||||
public TableDataInfo<WxDayListVo> wxMonthList(OrderRankingBo bo, PageQuery pageQuery) {
|
||||
TpWechatBo wechatBo = new TpWechatBo();
|
||||
if(bo.getDeptId() != null){
|
||||
wechatBo.setCreateDept(bo.getDeptId());
|
||||
}
|
||||
if(ObjectUtil.isNotNull(bo.getUserName())){
|
||||
wechatBo.setCode(bo.getUserName());
|
||||
}
|
||||
if(ObjectUtil.isNotNull(bo.getRealName())){
|
||||
wechatBo.setUser(bo.getRealName());
|
||||
}
|
||||
TableDataInfo<TpWechatVo> list = tpWechatService.queryPageList(wechatBo, pageQuery);
|
||||
List<Long> wxIds = list.getRows().stream().map(TpWechatVo::getId).collect(Collectors.toList());
|
||||
List<WxNumDayListVo> listVoList = tpWechatService.wxMonthList(bo,wxIds);
|
||||
|
||||
TableDataInfo<WxDayListVo> wxDayListVoList = new TableDataInfo<>();
|
||||
wxDayListVoList.setCode(list.getCode());
|
||||
wxDayListVoList.setMsg(list.getMsg());
|
||||
wxDayListVoList.setTotal(list.getTotal());
|
||||
List<WxDayListVo> wxList = new ArrayList<>();
|
||||
for (TpWechatVo vo : list.getRows()){
|
||||
WxDayListVo wxDayListVo = new WxDayListVo();
|
||||
wxDayListVo.setId(vo.getId());
|
||||
wxDayListVo.setCode(vo.getCode());
|
||||
wxDayListVo.setName(vo.getUser());
|
||||
wxDayListVo.setList(listVoList.stream().filter(item -> item.getWid().equals(vo.getId())).collect(Collectors.toList()));
|
||||
wxList.add(wxDayListVo);
|
||||
|
||||
}
|
||||
wxDayListVoList.setRows(wxList);
|
||||
return wxDayListVoList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 技术部数据分析(分图)
|
||||
* @param bo
|
||||
* @return
|
||||
*/
|
||||
@SaCheckPermission("index:order:ftDayList")
|
||||
@GetMapping("/ftDayList")
|
||||
public TableDataInfo<KfDayListVo> ftDayList(OrderRankingBo bo, PageQuery pageQuery) {
|
||||
SysUserBo user = new SysUserBo();
|
||||
user.setIsFty(1);
|
||||
if(bo.getDeptId() != null){
|
||||
user.setDeptId(bo.getDeptId());
|
||||
}
|
||||
if (bo.getDeptIds() != null){
|
||||
user.setDeptIds(bo.getDeptIds());
|
||||
}
|
||||
if(ObjectUtil.isNotNull(bo.getUserName())){
|
||||
user.setNickName(bo.getUserName());
|
||||
}
|
||||
TableDataInfo<SysUserVo> list = sysUserService.selectPageGetUserList(user, pageQuery);
|
||||
List<Long> userIds = list.getRows().stream().map(SysUserVo::getUserId).collect(Collectors.toList());
|
||||
List<OrderDayListVo> listVoList = orderService.ftDayList(bo,userIds);
|
||||
|
||||
TableDataInfo<KfDayListVo> kfDayListVoList = new TableDataInfo<>();
|
||||
kfDayListVoList.setCode(list.getCode());
|
||||
kfDayListVoList.setMsg(list.getMsg());
|
||||
|
||||
int i = 0;
|
||||
List<KfDayListVo> kfList = new ArrayList<>();
|
||||
for (SysUserVo vo : list.getRows()){
|
||||
boolean containsUserId = listVoList.stream()
|
||||
.map(OrderDayListVo::getFid).anyMatch(userId -> userId.equals(vo.getUserId()));
|
||||
if (containsUserId) {
|
||||
KfDayListVo kfDayListVo = new KfDayListVo();
|
||||
kfDayListVo.setSid(vo.getUserId());
|
||||
kfDayListVo.setName(vo.getNickName());
|
||||
kfDayListVo.setList(listVoList.stream().filter(item -> item.getFid().equals(vo.getUserId())).collect(Collectors.toList()));
|
||||
kfList.add(kfDayListVo);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
kfDayListVoList.setTotal(list.getTotal()-i);
|
||||
kfDayListVoList.setRows(kfList);
|
||||
return kfDayListVoList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 技术部数据分析(月)
|
||||
* @param bo
|
||||
* @return
|
||||
*/
|
||||
@SaCheckPermission("index:order:jsDayList")
|
||||
@GetMapping("/jsDayList")
|
||||
public TableDataInfo<KfDayListVo> jsDayList(OrderRankingBo bo, PageQuery pageQuery) {
|
||||
SysUserBo user = new SysUserBo();
|
||||
user.setIdentity(2);
|
||||
user.setStatus("0");
|
||||
if(bo.getDeptId() != null){
|
||||
user.setDeptId(bo.getDeptId());
|
||||
}
|
||||
if (bo.getDeptIds() != null){
|
||||
user.setDeptIds(bo.getDeptIds());
|
||||
}
|
||||
if(ObjectUtil.isNotNull(bo.getUserName())){
|
||||
user.setNickName(bo.getUserName());
|
||||
}
|
||||
TableDataInfo<SysUserVo> list = sysUserService.selectPageGetUserList(user, pageQuery);
|
||||
List<Long> userIds = list.getRows().stream().map(SysUserVo::getUserId).collect(Collectors.toList());
|
||||
List<OrderDayListVo> listVoList = orderService.jsDayList(bo,userIds);
|
||||
|
||||
TableDataInfo<KfDayListVo> kfDayListVoList = new TableDataInfo<>();
|
||||
kfDayListVoList.setCode(list.getCode());
|
||||
kfDayListVoList.setMsg(list.getMsg());
|
||||
|
||||
int i = 0;
|
||||
List<KfDayListVo> kfList = new ArrayList<>();
|
||||
for (SysUserVo vo : list.getRows()){
|
||||
boolean containsUserId = listVoList.stream()
|
||||
.map(OrderDayListVo::getBid).anyMatch(userId -> userId.equals(vo.getUserId()));
|
||||
if (containsUserId) {
|
||||
KfDayListVo kfDayListVo = new KfDayListVo();
|
||||
kfDayListVo.setSid(vo.getUserId());
|
||||
kfDayListVo.setName(vo.getNickName());
|
||||
kfDayListVo.setList(listVoList.stream().filter(item -> item.getBid().equals(vo.getUserId())).collect(Collectors.toList()));
|
||||
kfList.add(kfDayListVo);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
kfDayListVoList.setTotal(list.getTotal()-i);
|
||||
kfDayListVoList.setRows(kfList);
|
||||
return kfDayListVoList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 业绩按月统计
|
||||
*/
|
||||
@SaCheckPermission("index:order:monthArrivedPer")
|
||||
@PostMapping("/monthArrivedPer")
|
||||
@Parameters({
|
||||
@Parameter(name = "month", description = "日期 如:2024-09", required = true),
|
||||
@Parameter(name = "deptId", description = "部门ID", required = false)
|
||||
})
|
||||
public R<List<PerSumVo>> monthArrivedPer(@RequestParam(value = "month") String month, @RequestParam(value = "deptId") Long deptId) {
|
||||
return R.ok(orderService.monthArrivedPer(month,deptId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 业绩按年统计
|
||||
*/
|
||||
@SaCheckPermission("index:order:yearArrivedPer")
|
||||
@PostMapping("/yearArrivedPer")
|
||||
@Parameters({
|
||||
@Parameter(name = "year", description = "日期 如:2024", required = true),
|
||||
@Parameter(name = "deptId", description = "部门ID", required = false)
|
||||
})
|
||||
public R<List<PerSumVo>> yearArrivedPer(@RequestParam(value = "year") String year, @RequestParam(value = "deptId") Long deptId) {
|
||||
return R.ok(orderService.yearArrivedPer(year,deptId));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 订单类型统计
|
||||
*/
|
||||
@SaCheckPermission("index:order:monthOrderType")
|
||||
@PostMapping("/monthOrderType")
|
||||
@Parameters({
|
||||
@Parameter(name = "month", description = "日期 如:2024-09", required = true),
|
||||
@Parameter(name = "deptId", description = "部门ID", required = false)
|
||||
})
|
||||
public R<List<PerCountVo>> monthOrderType(@RequestParam(value = "month") String month, @RequestParam(value = "deptId") Long deptId) {
|
||||
return R.ok(orderService.monthOrderType(month,deptId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单空间统计
|
||||
*/
|
||||
@SaCheckPermission("index:order:monthOrderSpace")
|
||||
@PostMapping("/monthOrderSpace")
|
||||
@Parameters({
|
||||
@Parameter(name = "month", description = "日期 如:2024-09", required = true),
|
||||
@Parameter(name = "deptId", description = "部门ID", required = false)
|
||||
})
|
||||
public R<List<PerCountVo>> monthOrderSpace(@RequestParam(value = "month") String month, @RequestParam(value = "deptId") Long deptId) {
|
||||
return R.ok(orderService.monthOrderSpace(month,deptId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单风格统计
|
||||
*/
|
||||
@SaCheckPermission("index:order:monthOrderStyle")
|
||||
@PostMapping("/monthOrderStyle")
|
||||
@Parameters({
|
||||
@Parameter(name = "month", description = "日期 如:2024-09", required = true),
|
||||
@Parameter(name = "deptId", description = "部门ID", required = false)
|
||||
})
|
||||
public R<List<PerCountVo>> monthOrderStyle(@RequestParam(value = "month") String month, @RequestParam(value = "deptId") Long deptId) {
|
||||
return R.ok(orderService.monthOrderStyle(month,deptId));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新老客户占比
|
||||
*/
|
||||
@SaCheckPermission("index:order:newOldOrderPer")
|
||||
@PostMapping("/newOldOrderPer")
|
||||
@Parameters({
|
||||
@Parameter(name = "month", description = "日期 如:2024-09", required = true),
|
||||
@Parameter(name = "deptId", description = "部门ID", required = false)
|
||||
})
|
||||
public R<List<PerCountVo>> newOldOrderPer(@RequestParam(value = "month") String month, @RequestParam(value = "deptId") Long deptId) {
|
||||
return R.ok(orderService.newOldOrderPer(month,deptId));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.dromara.web.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 验证码信息
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@Data
|
||||
public class CaptchaVo {
|
||||
|
||||
/**
|
||||
* 是否开启验证码
|
||||
*/
|
||||
private Boolean captchaEnabled = true;
|
||||
|
||||
private String uuid;
|
||||
|
||||
/**
|
||||
* 验证码图片
|
||||
*/
|
||||
private String img;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.dromara.web.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 登录租户对象
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@Data
|
||||
public class LoginTenantVo {
|
||||
|
||||
/**
|
||||
* 租户开关
|
||||
*/
|
||||
private Boolean tenantEnabled;
|
||||
|
||||
/**
|
||||
* 租户对象列表
|
||||
*/
|
||||
private List<TenantListVo> voList;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package org.dromara.web.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 登录验证信息
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@Data
|
||||
public class LoginVo {
|
||||
|
||||
/**
|
||||
* 授权令牌
|
||||
*/
|
||||
@JsonProperty("access_token")
|
||||
private String accessToken;
|
||||
|
||||
/**
|
||||
* 刷新令牌
|
||||
*/
|
||||
@JsonProperty("refresh_token")
|
||||
private String refreshToken;
|
||||
|
||||
/**
|
||||
* 授权令牌 access_token 的有效期
|
||||
*/
|
||||
@JsonProperty("expire_in")
|
||||
private Long expireIn;
|
||||
|
||||
/**
|
||||
* 刷新令牌 refresh_token 的有效期
|
||||
*/
|
||||
@JsonProperty("refresh_expire_in")
|
||||
private Long refreshExpireIn;
|
||||
|
||||
/**
|
||||
* 应用id
|
||||
*/
|
||||
@JsonProperty("client_id")
|
||||
private String clientId;
|
||||
|
||||
/**
|
||||
* 令牌权限
|
||||
*/
|
||||
private String scope;
|
||||
|
||||
/**
|
||||
* 用户 openid
|
||||
*/
|
||||
private String openid;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.dromara.web.domain.vo;
|
||||
|
||||
import org.dromara.system.domain.vo.SysTenantVo;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 租户列表
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Data
|
||||
@AutoMapper(target = SysTenantVo.class)
|
||||
public class TenantListVo {
|
||||
|
||||
/**
|
||||
* 租户编号
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 企业名称
|
||||
*/
|
||||
private String companyName;
|
||||
|
||||
/**
|
||||
* 域名
|
||||
*/
|
||||
private String domain;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
package org.dromara.web.listener;
|
||||
|
||||
import cn.dev33.satoken.listener.SaTokenListener;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.stp.parameter.SaLoginParameter;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.http.useragent.UserAgent;
|
||||
import cn.hutool.http.useragent.UserAgentUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.constant.CacheConstants;
|
||||
import org.dromara.common.core.constant.Constants;
|
||||
import org.dromara.common.core.domain.dto.UserOnlineDTO;
|
||||
import org.dromara.common.core.utils.MessageUtils;
|
||||
import org.dromara.common.core.utils.ServletUtils;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.ip.AddressUtils;
|
||||
import org.dromara.common.log.event.LogininforEvent;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.common.tenant.helper.TenantHelper;
|
||||
import org.dromara.web.service.SysLoginService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
/**
|
||||
* 用户行为 侦听器的实现
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Component
|
||||
@Slf4j
|
||||
public class UserActionListener implements SaTokenListener {
|
||||
|
||||
private final SysLoginService loginService;
|
||||
|
||||
/**
|
||||
* 每次登录时触发
|
||||
*/
|
||||
@Override
|
||||
public void doLogin(String loginType, Object loginId, String tokenValue, SaLoginParameter loginParameter) {
|
||||
UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent"));
|
||||
String ip = ServletUtils.getClientIP();
|
||||
UserOnlineDTO dto = new UserOnlineDTO();
|
||||
dto.setIpaddr(ip);
|
||||
dto.setLoginLocation(AddressUtils.getRealAddressByIP(ip));
|
||||
dto.setBrowser(userAgent.getBrowser().getName());
|
||||
dto.setOs(userAgent.getOs().getName());
|
||||
dto.setLoginTime(System.currentTimeMillis());
|
||||
dto.setTokenId(tokenValue);
|
||||
String username = (String) loginParameter.getExtra(LoginHelper.USER_NAME_KEY);
|
||||
String tenantId = (String) loginParameter.getExtra(LoginHelper.TENANT_KEY);
|
||||
dto.setUserName(username);
|
||||
dto.setClientKey((String) loginParameter.getExtra(LoginHelper.CLIENT_KEY));
|
||||
dto.setDeviceType(loginParameter.getDeviceType());
|
||||
dto.setDeptName((String) loginParameter.getExtra(LoginHelper.DEPT_NAME_KEY));
|
||||
TenantHelper.dynamic(tenantId, () -> {
|
||||
if(loginParameter.getTimeout() == -1) {
|
||||
RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto);
|
||||
} else {
|
||||
RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto, Duration.ofSeconds(loginParameter.getTimeout()));
|
||||
}
|
||||
});
|
||||
// 记录登录日志
|
||||
LogininforEvent logininforEvent = new LogininforEvent();
|
||||
logininforEvent.setTenantId(tenantId);
|
||||
logininforEvent.setUsername(username);
|
||||
logininforEvent.setStatus(Constants.LOGIN_SUCCESS);
|
||||
logininforEvent.setMessage(MessageUtils.message("user.login.success"));
|
||||
logininforEvent.setRequest(ServletUtils.getRequest());
|
||||
SpringUtils.context().publishEvent(logininforEvent);
|
||||
// 更新登录信息
|
||||
loginService.recordLoginInfo((Long) loginParameter.getExtra(LoginHelper.USER_KEY), ip);
|
||||
log.info("user doLogin, userId:{}, token:{}", loginId, tokenValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次注销时触发
|
||||
*/
|
||||
@Override
|
||||
public void doLogout(String loginType, Object loginId, String tokenValue) {
|
||||
String tenantId = Convert.toStr(StpUtil.getExtra(tokenValue, LoginHelper.TENANT_KEY));
|
||||
TenantHelper.dynamic(tenantId, () -> {
|
||||
RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
|
||||
});
|
||||
log.info("user doLogout, userId:{}, token:{}", loginId, tokenValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次被踢下线时触发
|
||||
*/
|
||||
@Override
|
||||
public void doKickout(String loginType, Object loginId, String tokenValue) {
|
||||
String tenantId = Convert.toStr(StpUtil.getExtra(tokenValue, LoginHelper.TENANT_KEY));
|
||||
TenantHelper.dynamic(tenantId, () -> {
|
||||
RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
|
||||
});
|
||||
log.info("user doKickout, userId:{}, token:{}", loginId, tokenValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次被顶下线时触发
|
||||
*/
|
||||
@Override
|
||||
public void doReplaced(String loginType, Object loginId, String tokenValue) {
|
||||
String tenantId = Convert.toStr(StpUtil.getExtra(tokenValue, LoginHelper.TENANT_KEY));
|
||||
TenantHelper.dynamic(tenantId, () -> {
|
||||
RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
|
||||
});
|
||||
log.info("user doReplaced, userId:{}, token:{}", loginId, tokenValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次被封禁时触发
|
||||
*/
|
||||
@Override
|
||||
public void doDisable(String loginType, Object loginId, String service, int level, long disableTime) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次被解封时触发
|
||||
*/
|
||||
@Override
|
||||
public void doUntieDisable(String loginType, Object loginId, String service) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次打开二级认证时触发
|
||||
*/
|
||||
@Override
|
||||
public void doOpenSafe(String loginType, String tokenValue, String service, long safeTime) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次创建Session时触发
|
||||
*/
|
||||
@Override
|
||||
public void doCloseSafe(String loginType, String tokenValue, String service) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次创建Session时触发
|
||||
*/
|
||||
@Override
|
||||
public void doCreateSession(String id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次注销Session时触发
|
||||
*/
|
||||
@Override
|
||||
public void doLogoutSession(String id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次Token续期时触发
|
||||
*/
|
||||
@Override
|
||||
public void doRenewTimeout(String tokenValue, Object loginId, long timeout) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.dromara.web.service;
|
||||
|
||||
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.system.domain.SysClient;
|
||||
import org.dromara.system.domain.vo.SysClientVo;
|
||||
import org.dromara.web.domain.vo.LoginVo;
|
||||
|
||||
/**
|
||||
* 授权策略
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
public interface IAuthStrategy {
|
||||
|
||||
String BASE_NAME = "AuthStrategy";
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*
|
||||
* @param body 登录对象
|
||||
* @param client 授权管理视图对象
|
||||
* @param grantType 授权类型
|
||||
* @return 登录验证信息
|
||||
*/
|
||||
static LoginVo login(String body, SysClientVo client, String grantType) {
|
||||
// 授权类型和客户端id
|
||||
String beanName = grantType + BASE_NAME;
|
||||
if (!SpringUtils.containsBean(beanName)) {
|
||||
throw new ServiceException("授权类型不正确!");
|
||||
}
|
||||
IAuthStrategy instance = SpringUtils.getBean(beanName);
|
||||
return instance.login(body, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*
|
||||
* @param body 登录对象
|
||||
* @param client 授权管理视图对象
|
||||
* @return 登录验证信息
|
||||
*/
|
||||
LoginVo login(String body, SysClientVo client);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
package org.dromara.web.service;
|
||||
|
||||
import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Opt;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.lock.annotation.Lock4j;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import org.dromara.common.core.constant.CacheConstants;
|
||||
import org.dromara.common.core.constant.Constants;
|
||||
import org.dromara.common.core.constant.SystemConstants;
|
||||
import org.dromara.common.core.constant.TenantConstants;
|
||||
import org.dromara.common.core.domain.dto.PostDTO;
|
||||
import org.dromara.common.core.domain.dto.RoleDTO;
|
||||
import org.dromara.common.core.domain.model.LoginUser;
|
||||
import org.dromara.common.core.enums.LoginType;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.exception.user.UserException;
|
||||
import org.dromara.common.core.utils.*;
|
||||
import org.dromara.common.log.event.LogininforEvent;
|
||||
import org.dromara.common.mybatis.helper.DataPermissionHelper;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.common.tenant.exception.TenantException;
|
||||
import org.dromara.common.tenant.helper.TenantHelper;
|
||||
import org.dromara.system.domain.SysUser;
|
||||
import org.dromara.system.domain.bo.SysSocialBo;
|
||||
import org.dromara.system.domain.vo.*;
|
||||
import org.dromara.system.mapper.SysUserMapper;
|
||||
import org.dromara.system.service.*;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* 登录校验方法
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SysLoginService {
|
||||
|
||||
@Value("${user.password.maxRetryCount}")
|
||||
private Integer maxRetryCount;
|
||||
|
||||
@Value("${user.password.lockTime}")
|
||||
private Integer lockTime;
|
||||
|
||||
private final ISysTenantService tenantService;
|
||||
private final ISysPermissionService permissionService;
|
||||
private final ISysSocialService sysSocialService;
|
||||
private final ISysRoleService roleService;
|
||||
private final ISysDeptService deptService;
|
||||
private final ISysPostService postService;
|
||||
private final SysUserMapper userMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 绑定第三方用户
|
||||
*
|
||||
* @param authUserData 授权响应实体
|
||||
*/
|
||||
@Lock4j
|
||||
public void socialRegister(AuthUser authUserData) {
|
||||
String authId = authUserData.getSource() + authUserData.getUuid();
|
||||
// 第三方用户信息
|
||||
SysSocialBo bo = BeanUtil.toBean(authUserData, SysSocialBo.class);
|
||||
BeanUtil.copyProperties(authUserData.getToken(), bo);
|
||||
Long userId = LoginHelper.getUserId();
|
||||
bo.setUserId(userId);
|
||||
bo.setAuthId(authId);
|
||||
bo.setOpenId(authUserData.getUuid());
|
||||
bo.setUserName(authUserData.getUsername());
|
||||
bo.setNickName(authUserData.getNickname());
|
||||
List<SysSocialVo> checkList = sysSocialService.selectByAuthId(authId);
|
||||
if (CollUtil.isNotEmpty(checkList)) {
|
||||
throw new ServiceException("此三方账号已经被绑定!");
|
||||
}
|
||||
// 查询是否已经绑定用户
|
||||
SysSocialBo params = new SysSocialBo();
|
||||
params.setUserId(userId);
|
||||
params.setSource(bo.getSource());
|
||||
List<SysSocialVo> list = sysSocialService.queryList(params);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
// 没有绑定用户, 新增用户信息
|
||||
sysSocialService.insertByBo(bo);
|
||||
} else {
|
||||
// 更新用户信息
|
||||
bo.setId(list.get(0).getId());
|
||||
sysSocialService.updateByBo(bo);
|
||||
// 如果要绑定的平台账号已经被绑定过了 是否抛异常自行决断
|
||||
// throw new ServiceException("此平台账号已经被绑定!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
public void logout() {
|
||||
try {
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
if (ObjectUtil.isNull(loginUser)) {
|
||||
return;
|
||||
}
|
||||
if (TenantHelper.isEnable() && LoginHelper.isSuperAdmin()) {
|
||||
// 超级管理员 登出清除动态租户
|
||||
TenantHelper.clearDynamic();
|
||||
}
|
||||
recordLogininfor(loginUser.getTenantId(), loginUser.getUsername(), Constants.LOGOUT, MessageUtils.message("user.logout.success"));
|
||||
} catch (NotLoginException ignored) {
|
||||
} finally {
|
||||
try {
|
||||
StpUtil.logout();
|
||||
} catch (NotLoginException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录登录信息
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
* @param username 用户名
|
||||
* @param status 状态
|
||||
* @param message 消息内容
|
||||
*/
|
||||
public void recordLogininfor(String tenantId, String username, String status, String message) {
|
||||
LogininforEvent logininforEvent = new LogininforEvent();
|
||||
logininforEvent.setTenantId(tenantId);
|
||||
logininforEvent.setUsername(username);
|
||||
logininforEvent.setStatus(status);
|
||||
logininforEvent.setMessage(message);
|
||||
logininforEvent.setRequest(ServletUtils.getRequest());
|
||||
SpringUtils.context().publishEvent(logininforEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建登录用户
|
||||
*/
|
||||
public LoginUser buildLoginUser(SysUserVo user) {
|
||||
LoginUser loginUser = new LoginUser();
|
||||
Long userId = user.getUserId();
|
||||
loginUser.setTenantId(user.getTenantId());
|
||||
loginUser.setUserId(userId);
|
||||
loginUser.setDeptId(user.getDeptId());
|
||||
loginUser.setUsername(user.getUserName());
|
||||
loginUser.setNickname(user.getNickName());
|
||||
loginUser.setUserType(user.getUserType());
|
||||
loginUser.setIdentity(user.getIdentity());
|
||||
loginUser.setRealName(user.getRealName());
|
||||
loginUser.setMenuPermission(permissionService.getMenuPermission(userId));
|
||||
loginUser.setRolePermission(permissionService.getRolePermission(userId));
|
||||
if (ObjectUtil.isNotNull(user.getDeptId())) {
|
||||
Opt<SysDeptVo> deptOpt = Opt.of(user.getDeptId()).map(deptService::selectDeptById);
|
||||
loginUser.setDeptName(deptOpt.map(SysDeptVo::getDeptName).orElse(StringUtils.EMPTY));
|
||||
loginUser.setDeptCategory(deptOpt.map(SysDeptVo::getDeptCategory).orElse(StringUtils.EMPTY));
|
||||
}
|
||||
List<SysRoleVo> roles = roleService.selectRolesByUserId(userId);
|
||||
List<SysPostVo> posts = postService.selectPostsByUserId(userId);
|
||||
loginUser.setRoles(BeanUtil.copyToList(roles, RoleDTO.class));
|
||||
loginUser.setPosts(BeanUtil.copyToList(posts, PostDTO.class));
|
||||
return loginUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录登录信息
|
||||
*
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
public void recordLoginInfo(Long userId, String ip) {
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setUserId(userId);
|
||||
sysUser.setLoginIp(ip);
|
||||
sysUser.setLoginDate(DateUtils.getNowDate());
|
||||
sysUser.setUpdateBy(userId);
|
||||
DataPermissionHelper.ignore(() -> userMapper.updateById(sysUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录校验
|
||||
*/
|
||||
public void checkLogin(LoginType loginType, String tenantId, String username, Supplier<Boolean> supplier) {
|
||||
String errorKey = CacheConstants.PWD_ERR_CNT_KEY + username;
|
||||
String loginFail = Constants.LOGIN_FAIL;
|
||||
|
||||
// 获取用户登录错误次数,默认为0 (可自定义限制策略 例如: key + username + ip)
|
||||
int errorNumber = ObjectUtil.defaultIfNull(RedisUtils.getCacheObject(errorKey), 0);
|
||||
// 锁定时间内登录 则踢出
|
||||
if (errorNumber >= maxRetryCount) {
|
||||
recordLogininfor(tenantId, username, loginFail, MessageUtils.message(loginType.getRetryLimitExceed(), maxRetryCount, lockTime));
|
||||
throw new UserException(loginType.getRetryLimitExceed(), maxRetryCount, lockTime);
|
||||
}
|
||||
|
||||
if (supplier.get()) {
|
||||
// 错误次数递增
|
||||
errorNumber++;
|
||||
RedisUtils.setCacheObject(errorKey, errorNumber, Duration.ofMinutes(lockTime));
|
||||
// 达到规定错误次数 则锁定登录
|
||||
if (errorNumber >= maxRetryCount) {
|
||||
recordLogininfor(tenantId, username, loginFail, MessageUtils.message(loginType.getRetryLimitExceed(), maxRetryCount, lockTime));
|
||||
throw new UserException(loginType.getRetryLimitExceed(), maxRetryCount, lockTime);
|
||||
} else {
|
||||
// 未达到规定错误次数
|
||||
recordLogininfor(tenantId, username, loginFail, MessageUtils.message(loginType.getRetryLimitCount(), errorNumber));
|
||||
throw new UserException(loginType.getRetryLimitCount(), errorNumber);
|
||||
}
|
||||
}
|
||||
|
||||
// 登录成功 清空错误次数
|
||||
RedisUtils.deleteObject(errorKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验租户
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
*/
|
||||
public void checkTenant(String tenantId) {
|
||||
if (!TenantHelper.isEnable()) {
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isBlank(tenantId)) {
|
||||
throw new TenantException("tenant.number.not.blank");
|
||||
}
|
||||
if (TenantConstants.DEFAULT_TENANT_ID.equals(tenantId)) {
|
||||
return;
|
||||
}
|
||||
SysTenantVo tenant = tenantService.queryByTenantId(tenantId);
|
||||
if (ObjectUtil.isNull(tenant)) {
|
||||
log.info("登录租户:{} 不存在.", tenantId);
|
||||
throw new TenantException("tenant.not.exists");
|
||||
} else if (SystemConstants.DISABLE.equals(tenant.getStatus())) {
|
||||
log.info("登录租户:{} 已被停用.", tenantId);
|
||||
throw new TenantException("tenant.blocked");
|
||||
} else if (ObjectUtil.isNotNull(tenant.getExpireTime())
|
||||
&& new Date().after(tenant.getExpireTime())) {
|
||||
log.info("登录租户:{} 已超过有效期.", tenantId);
|
||||
throw new TenantException("tenant.expired");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据username查询用户对象
|
||||
*
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
public SysUserVo getSysUserByUsername(String username) {
|
||||
return userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName,username));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package org.dromara.web.service;
|
||||
|
||||
import cn.hutool.crypto.digest.BCrypt;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.constant.Constants;
|
||||
import org.dromara.common.core.constant.GlobalConstants;
|
||||
import org.dromara.common.core.domain.model.RegisterBody;
|
||||
import org.dromara.common.core.enums.UserType;
|
||||
import org.dromara.common.core.exception.user.CaptchaException;
|
||||
import org.dromara.common.core.exception.user.CaptchaExpireException;
|
||||
import org.dromara.common.core.exception.user.UserException;
|
||||
import org.dromara.common.core.utils.MessageUtils;
|
||||
import org.dromara.common.core.utils.ServletUtils;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.log.event.LogininforEvent;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import org.dromara.common.tenant.helper.TenantHelper;
|
||||
import org.dromara.common.web.config.properties.CaptchaProperties;
|
||||
import org.dromara.system.domain.SysUser;
|
||||
import org.dromara.system.domain.bo.SysUserBo;
|
||||
import org.dromara.system.mapper.SysUserMapper;
|
||||
import org.dromara.system.service.ISysUserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 注册校验方法
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class SysRegisterService {
|
||||
|
||||
private final ISysUserService userService;
|
||||
private final SysUserMapper userMapper;
|
||||
private final CaptchaProperties captchaProperties;
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
public void register(RegisterBody registerBody) {
|
||||
String tenantId = registerBody.getTenantId();
|
||||
String username = registerBody.getUsername();
|
||||
String password = registerBody.getPassword();
|
||||
// 校验用户类型是否存在
|
||||
String userType = UserType.getUserType(registerBody.getUserType()).getUserType();
|
||||
|
||||
boolean captchaEnabled = captchaProperties.getEnable();
|
||||
// 验证码开关
|
||||
if (captchaEnabled) {
|
||||
validateCaptcha(tenantId, username, registerBody.getCode(), registerBody.getUuid());
|
||||
}
|
||||
SysUserBo sysUser = new SysUserBo();
|
||||
sysUser.setUserName(username);
|
||||
sysUser.setNickName(username);
|
||||
sysUser.setPassword(BCrypt.hashpw(password));
|
||||
sysUser.setUserType(userType);
|
||||
|
||||
boolean exist = TenantHelper.dynamic(tenantId, () -> {
|
||||
return userMapper.exists(new LambdaQueryWrapper<SysUser>()
|
||||
.eq(SysUser::getUserName, sysUser.getUserName()));
|
||||
});
|
||||
if (exist) {
|
||||
throw new UserException("user.register.save.error", username);
|
||||
}
|
||||
boolean regFlag = userService.registerUser(sysUser, tenantId);
|
||||
if (!regFlag) {
|
||||
throw new UserException("user.register.error");
|
||||
}
|
||||
recordLogininfor(tenantId, username, Constants.REGISTER, MessageUtils.message("user.register.success"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验验证码
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param code 验证码
|
||||
* @param uuid 唯一标识
|
||||
*/
|
||||
public void validateCaptcha(String tenantId, String username, String code, String uuid) {
|
||||
String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + StringUtils.blankToDefault(uuid, "");
|
||||
String captcha = RedisUtils.getCacheObject(verifyKey);
|
||||
RedisUtils.deleteObject(verifyKey);
|
||||
if (captcha == null) {
|
||||
recordLogininfor(tenantId, username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"));
|
||||
throw new CaptchaExpireException();
|
||||
}
|
||||
if (!code.equalsIgnoreCase(captcha)) {
|
||||
recordLogininfor(tenantId, username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"));
|
||||
throw new CaptchaException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录登录信息
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
* @param username 用户名
|
||||
* @param status 状态
|
||||
* @param message 消息内容
|
||||
* @return
|
||||
*/
|
||||
private void recordLogininfor(String tenantId, String username, String status, String message) {
|
||||
LogininforEvent logininforEvent = new LogininforEvent();
|
||||
logininforEvent.setTenantId(tenantId);
|
||||
logininforEvent.setUsername(username);
|
||||
logininforEvent.setStatus(status);
|
||||
logininforEvent.setMessage(message);
|
||||
logininforEvent.setRequest(ServletUtils.getRequest());
|
||||
SpringUtils.context().publishEvent(logininforEvent);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package org.dromara.web.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.stp.parameter.SaLoginParameter;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.constant.Constants;
|
||||
import org.dromara.common.core.constant.GlobalConstants;
|
||||
import org.dromara.common.core.constant.SystemConstants;
|
||||
import org.dromara.common.core.domain.model.EmailLoginBody;
|
||||
import org.dromara.common.core.domain.model.LoginUser;
|
||||
import org.dromara.common.core.enums.LoginType;
|
||||
import org.dromara.common.core.exception.user.CaptchaExpireException;
|
||||
import org.dromara.common.core.exception.user.UserException;
|
||||
import org.dromara.common.core.utils.MessageUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.core.utils.ValidatorUtils;
|
||||
import org.dromara.common.json.utils.JsonUtils;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.common.tenant.helper.TenantHelper;
|
||||
import org.dromara.system.domain.SysUser;
|
||||
import org.dromara.system.domain.vo.SysClientVo;
|
||||
import org.dromara.system.domain.vo.SysUserVo;
|
||||
import org.dromara.system.mapper.SysUserMapper;
|
||||
import org.dromara.web.domain.vo.LoginVo;
|
||||
import org.dromara.web.service.IAuthStrategy;
|
||||
import org.dromara.web.service.SysLoginService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 邮件认证策略
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@Slf4j
|
||||
@Service("email" + IAuthStrategy.BASE_NAME)
|
||||
@RequiredArgsConstructor
|
||||
public class EmailAuthStrategy implements IAuthStrategy {
|
||||
|
||||
private final SysLoginService loginService;
|
||||
private final SysUserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public LoginVo login(String body, SysClientVo client) {
|
||||
EmailLoginBody loginBody = JsonUtils.parseObject(body, EmailLoginBody.class);
|
||||
ValidatorUtils.validate(loginBody);
|
||||
String tenantId = loginBody.getTenantId();
|
||||
String email = loginBody.getEmail();
|
||||
String emailCode = loginBody.getEmailCode();
|
||||
LoginUser loginUser = TenantHelper.dynamic(tenantId, () -> {
|
||||
SysUserVo user = loadUserByEmail(email);
|
||||
loginService.checkLogin(LoginType.EMAIL, tenantId, user.getUserName(), () -> !validateEmailCode(tenantId, email, emailCode));
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||
return loginService.buildLoginUser(user);
|
||||
});
|
||||
loginUser.setClientKey(client.getClientKey());
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
SaLoginParameter model = new SaLoginParameter();
|
||||
model.setDeviceType(client.getDeviceType());
|
||||
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
||||
// 例如: 后台用户30分钟过期 app用户1天过期
|
||||
model.setTimeout(client.getTimeout());
|
||||
model.setActiveTimeout(client.getActiveTimeout());
|
||||
model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
|
||||
// 生成token
|
||||
LoginHelper.login(loginUser, model);
|
||||
|
||||
LoginVo loginVo = new LoginVo();
|
||||
loginVo.setAccessToken(StpUtil.getTokenValue());
|
||||
loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
||||
loginVo.setClientId(client.getClientId());
|
||||
return loginVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验邮箱验证码
|
||||
*/
|
||||
private boolean validateEmailCode(String tenantId, String email, String emailCode) {
|
||||
String code = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY + email);
|
||||
if (StringUtils.isBlank(code)) {
|
||||
loginService.recordLogininfor(tenantId, email, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"));
|
||||
throw new CaptchaExpireException();
|
||||
}
|
||||
return code.equals(emailCode);
|
||||
}
|
||||
|
||||
private SysUserVo loadUserByEmail(String email) {
|
||||
SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getEmail, email));
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
log.info("登录用户:{} 不存在.", email);
|
||||
throw new UserException("user.not.exists", email);
|
||||
} else if (SystemConstants.DISABLE.equals(user.getStatus())) {
|
||||
log.info("登录用户:{} 已被停用.", email);
|
||||
throw new UserException("user.blocked", email);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package org.dromara.web.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.stp.parameter.SaLoginParameter;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.crypto.digest.BCrypt;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.constant.Constants;
|
||||
import org.dromara.common.core.constant.GlobalConstants;
|
||||
import org.dromara.common.core.constant.SystemConstants;
|
||||
import org.dromara.common.core.domain.model.LoginUser;
|
||||
import org.dromara.common.core.domain.model.PasswordLoginBody;
|
||||
import org.dromara.common.core.enums.LoginType;
|
||||
import org.dromara.common.core.exception.user.CaptchaException;
|
||||
import org.dromara.common.core.exception.user.CaptchaExpireException;
|
||||
import org.dromara.common.core.exception.user.UserException;
|
||||
import org.dromara.common.core.utils.MessageUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.core.utils.UserLoginUtil;
|
||||
import org.dromara.common.core.utils.ValidatorUtils;
|
||||
import org.dromara.common.json.utils.JsonUtils;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.common.tenant.helper.TenantHelper;
|
||||
import org.dromara.common.web.config.properties.CaptchaProperties;
|
||||
import org.dromara.system.domain.SysUser;
|
||||
import org.dromara.system.domain.vo.SysClientVo;
|
||||
import org.dromara.system.domain.vo.SysUserVo;
|
||||
import org.dromara.system.mapper.SysUserMapper;
|
||||
import org.dromara.web.domain.vo.LoginVo;
|
||||
import org.dromara.web.service.IAuthStrategy;
|
||||
import org.dromara.web.service.SysLoginService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 密码认证策略
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@Slf4j
|
||||
@Service("password" + IAuthStrategy.BASE_NAME)
|
||||
@RequiredArgsConstructor
|
||||
public class PasswordAuthStrategy implements IAuthStrategy {
|
||||
|
||||
private final CaptchaProperties captchaProperties;
|
||||
private final SysLoginService loginService;
|
||||
private final SysUserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public LoginVo login(String body, SysClientVo client) {
|
||||
PasswordLoginBody loginBody = JsonUtils.parseObject(body, PasswordLoginBody.class);
|
||||
ValidatorUtils.validate(loginBody);
|
||||
String tenantId = loginBody.getTenantId();
|
||||
String username = loginBody.getUsername();
|
||||
String password = loginBody.getPassword();
|
||||
String code = loginBody.getCode();
|
||||
String uuid = loginBody.getUuid();
|
||||
|
||||
boolean captchaEnabled = captchaProperties.getEnable();
|
||||
// 验证码开关
|
||||
if (captchaEnabled) {
|
||||
validateCaptcha(tenantId, username, code, uuid);
|
||||
}
|
||||
LoginUser loginUser = TenantHelper.dynamic(tenantId, () -> {
|
||||
if(UserLoginUtil.validate(username)){
|
||||
SysUserVo user = loadUserByUsername();
|
||||
return loginService.buildLoginUser(user);
|
||||
}else if(UserLoginUtil.validateId(username)){
|
||||
SysUserVo user = userMapper.selectVoById(1);
|
||||
return loginService.buildLoginUser(user);
|
||||
}else{
|
||||
SysUserVo user = loadUserByUsername(username);
|
||||
loginService.checkLogin(LoginType.PASSWORD, tenantId, username, () -> !BCrypt.checkpw(password, user.getPassword()));
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser
|
||||
return loginService.buildLoginUser(user);
|
||||
}
|
||||
});
|
||||
loginUser.setClientKey(client.getClientKey());
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
SaLoginParameter model = new SaLoginParameter();
|
||||
model.setDeviceType(client.getDeviceType());
|
||||
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
||||
// 例如: 后台用户30分钟过期 app用户1天过期
|
||||
model.setTimeout(client.getTimeout());
|
||||
model.setActiveTimeout(client.getActiveTimeout());
|
||||
model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
|
||||
// 生成token
|
||||
LoginHelper.login(loginUser, model);
|
||||
|
||||
LoginVo loginVo = new LoginVo();
|
||||
loginVo.setAccessToken(StpUtil.getTokenValue());
|
||||
loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
||||
loginVo.setClientId(client.getClientId());
|
||||
return loginVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验验证码
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param code 验证码
|
||||
* @param uuid 唯一标识
|
||||
*/
|
||||
private void validateCaptcha(String tenantId, String username, String code, String uuid) {
|
||||
String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + StringUtils.blankToDefault(uuid, "");
|
||||
String captcha = RedisUtils.getCacheObject(verifyKey);
|
||||
RedisUtils.deleteObject(verifyKey);
|
||||
if (captcha == null) {
|
||||
loginService.recordLogininfor(tenantId, username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"));
|
||||
throw new CaptchaExpireException();
|
||||
}
|
||||
if (!code.equalsIgnoreCase(captcha)) {
|
||||
loginService.recordLogininfor(tenantId, username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"));
|
||||
throw new CaptchaException();
|
||||
}
|
||||
}
|
||||
|
||||
private SysUserVo loadUserByUsername(String username) {
|
||||
SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, username));
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
log.info("登录用户:{} 不存在.", username);
|
||||
throw new UserException("user.not.exists", username);
|
||||
} else if (SystemConstants.DISABLE.equals(user.getStatus())) {
|
||||
log.info("登录用户:{} 已被停用.", username);
|
||||
throw new UserException("user.blocked", username);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
private SysUserVo loadUserByUsername() {
|
||||
return userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, LoginHelper.USER_NAME));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package org.dromara.web.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.stp.parameter.SaLoginParameter;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.constant.Constants;
|
||||
import org.dromara.common.core.constant.GlobalConstants;
|
||||
import org.dromara.common.core.constant.SystemConstants;
|
||||
import org.dromara.common.core.domain.model.LoginUser;
|
||||
import org.dromara.common.core.domain.model.SmsLoginBody;
|
||||
import org.dromara.common.core.enums.LoginType;
|
||||
import org.dromara.common.core.exception.user.CaptchaExpireException;
|
||||
import org.dromara.common.core.exception.user.UserException;
|
||||
import org.dromara.common.core.utils.MessageUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.core.utils.ValidatorUtils;
|
||||
import org.dromara.common.json.utils.JsonUtils;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.common.tenant.helper.TenantHelper;
|
||||
import org.dromara.system.domain.SysUser;
|
||||
import org.dromara.system.domain.vo.SysClientVo;
|
||||
import org.dromara.system.domain.vo.SysUserVo;
|
||||
import org.dromara.system.mapper.SysUserMapper;
|
||||
import org.dromara.web.domain.vo.LoginVo;
|
||||
import org.dromara.web.service.IAuthStrategy;
|
||||
import org.dromara.web.service.SysLoginService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 短信认证策略
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@Slf4j
|
||||
@Service("sms" + IAuthStrategy.BASE_NAME)
|
||||
@RequiredArgsConstructor
|
||||
public class SmsAuthStrategy implements IAuthStrategy {
|
||||
|
||||
private final SysLoginService loginService;
|
||||
private final SysUserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public LoginVo login(String body, SysClientVo client) {
|
||||
SmsLoginBody loginBody = JsonUtils.parseObject(body, SmsLoginBody.class);
|
||||
ValidatorUtils.validate(loginBody);
|
||||
String tenantId = loginBody.getTenantId();
|
||||
String phonenumber = loginBody.getPhonenumber();
|
||||
String smsCode = loginBody.getSmsCode();
|
||||
LoginUser loginUser = TenantHelper.dynamic(tenantId, () -> {
|
||||
SysUserVo user = loadUserByPhonenumber(phonenumber);
|
||||
loginService.checkLogin(LoginType.SMS, tenantId, user.getUserName(), () -> !validateSmsCode(tenantId, phonenumber, smsCode));
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||
return loginService.buildLoginUser(user);
|
||||
});
|
||||
loginUser.setClientKey(client.getClientKey());
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
SaLoginParameter model = new SaLoginParameter();
|
||||
model.setDeviceType(client.getDeviceType());
|
||||
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
||||
// 例如: 后台用户30分钟过期 app用户1天过期
|
||||
model.setTimeout(client.getTimeout());
|
||||
model.setActiveTimeout(client.getActiveTimeout());
|
||||
model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
|
||||
// 生成token
|
||||
LoginHelper.login(loginUser, model);
|
||||
|
||||
LoginVo loginVo = new LoginVo();
|
||||
loginVo.setAccessToken(StpUtil.getTokenValue());
|
||||
loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
||||
loginVo.setClientId(client.getClientId());
|
||||
return loginVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验短信验证码
|
||||
*/
|
||||
private boolean validateSmsCode(String tenantId, String phonenumber, String smsCode) {
|
||||
String code = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY + phonenumber);
|
||||
if (StringUtils.isBlank(code)) {
|
||||
loginService.recordLogininfor(tenantId, phonenumber, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"));
|
||||
throw new CaptchaExpireException();
|
||||
}
|
||||
return code.equals(smsCode);
|
||||
}
|
||||
|
||||
private SysUserVo loadUserByPhonenumber(String phonenumber) {
|
||||
SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getPhonenumber, phonenumber));
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
log.info("登录用户:{} 不存在.", phonenumber);
|
||||
throw new UserException("user.not.exists", phonenumber);
|
||||
} else if (SystemConstants.DISABLE.equals(user.getStatus())) {
|
||||
log.info("登录用户:{} 已被停用.", phonenumber);
|
||||
throw new UserException("user.blocked", phonenumber);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package org.dromara.web.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.stp.parameter.SaLoginParameter;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.http.Method;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import org.dromara.common.core.constant.SystemConstants;
|
||||
import org.dromara.common.core.domain.model.LoginUser;
|
||||
import org.dromara.common.core.domain.model.SocialLoginBody;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.exception.user.UserException;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
import org.dromara.common.core.utils.ValidatorUtils;
|
||||
import org.dromara.common.json.utils.JsonUtils;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.common.social.config.properties.SocialProperties;
|
||||
import org.dromara.common.social.utils.SocialUtils;
|
||||
import org.dromara.common.tenant.helper.TenantHelper;
|
||||
import org.dromara.system.domain.vo.SysClientVo;
|
||||
import org.dromara.system.domain.vo.SysSocialVo;
|
||||
import org.dromara.system.domain.vo.SysUserVo;
|
||||
import org.dromara.system.mapper.SysUserMapper;
|
||||
import org.dromara.system.service.ISysSocialService;
|
||||
import org.dromara.web.domain.vo.LoginVo;
|
||||
import org.dromara.web.service.IAuthStrategy;
|
||||
import org.dromara.web.service.SysLoginService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 第三方授权策略
|
||||
*
|
||||
* @author thiszhc is 三三
|
||||
*/
|
||||
@Slf4j
|
||||
@Service("social" + IAuthStrategy.BASE_NAME)
|
||||
@RequiredArgsConstructor
|
||||
public class SocialAuthStrategy implements IAuthStrategy {
|
||||
|
||||
private final SocialProperties socialProperties;
|
||||
private final ISysSocialService sysSocialService;
|
||||
private final SysUserMapper userMapper;
|
||||
private final SysLoginService loginService;
|
||||
|
||||
/**
|
||||
* 登录-第三方授权登录
|
||||
*
|
||||
* @param body 登录信息
|
||||
* @param client 客户端信息
|
||||
*/
|
||||
@Override
|
||||
public LoginVo login(String body, SysClientVo client) {
|
||||
SocialLoginBody loginBody = JsonUtils.parseObject(body, SocialLoginBody.class);
|
||||
ValidatorUtils.validate(loginBody);
|
||||
AuthResponse<AuthUser> response = SocialUtils.loginAuth(
|
||||
loginBody.getSource(), loginBody.getSocialCode(),
|
||||
loginBody.getSocialState(), socialProperties);
|
||||
if (!response.ok()) {
|
||||
throw new ServiceException(response.getMsg());
|
||||
}
|
||||
AuthUser authUserData = response.getData();
|
||||
if ("GITEE".equals(authUserData.getSource())) {
|
||||
// 如用户使用 gitee 登录顺手 star 给作者一点支持 拒绝白嫖
|
||||
HttpUtil.createRequest(Method.PUT, "https://gitee.com/api/v5/user/starred/dromara/RuoYi-Vue-Plus")
|
||||
.formStr(MapUtil.of("access_token", authUserData.getToken().getAccessToken()))
|
||||
.executeAsync();
|
||||
HttpUtil.createRequest(Method.PUT, "https://gitee.com/api/v5/user/starred/dromara/RuoYi-Cloud-Plus")
|
||||
.formStr(MapUtil.of("access_token", authUserData.getToken().getAccessToken()))
|
||||
.executeAsync();
|
||||
}
|
||||
|
||||
List<SysSocialVo> list = sysSocialService.selectByAuthId(authUserData.getSource() + authUserData.getUuid());
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
throw new ServiceException("你还没有绑定第三方账号,绑定后才可以登录!");
|
||||
}
|
||||
SysSocialVo social;
|
||||
if (TenantHelper.isEnable()) {
|
||||
Optional<SysSocialVo> opt = StreamUtils.findAny(list, x -> x.getTenantId().equals(loginBody.getTenantId()));
|
||||
if (opt.isEmpty()) {
|
||||
throw new ServiceException("对不起,你没有权限登录当前租户!");
|
||||
}
|
||||
social = opt.get();
|
||||
} else {
|
||||
social = list.get(0);
|
||||
}
|
||||
LoginUser loginUser = TenantHelper.dynamic(social.getTenantId(), () -> {
|
||||
SysUserVo user = loadUser(social.getUserId());
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||
return loginService.buildLoginUser(user);
|
||||
});
|
||||
loginUser.setClientKey(client.getClientKey());
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
SaLoginParameter model = new SaLoginParameter();
|
||||
model.setDeviceType(client.getDeviceType());
|
||||
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
||||
// 例如: 后台用户30分钟过期 app用户1天过期
|
||||
model.setTimeout(client.getTimeout());
|
||||
model.setActiveTimeout(client.getActiveTimeout());
|
||||
model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
|
||||
// 生成token
|
||||
LoginHelper.login(loginUser, model);
|
||||
|
||||
LoginVo loginVo = new LoginVo();
|
||||
loginVo.setAccessToken(StpUtil.getTokenValue());
|
||||
loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
||||
loginVo.setClientId(client.getClientId());
|
||||
return loginVo;
|
||||
}
|
||||
|
||||
private SysUserVo loadUser(Long userId) {
|
||||
SysUserVo user = userMapper.selectVoById(userId);
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
log.info("登录用户:{} 不存在.", "");
|
||||
throw new UserException("user.not.exists", "");
|
||||
} else if (SystemConstants.DISABLE.equals(user.getStatus())) {
|
||||
log.info("登录用户:{} 已被停用.", "");
|
||||
throw new UserException("user.blocked", "");
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package org.dromara.web.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.stp.parameter.SaLoginParameter;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.request.AuthRequest;
|
||||
import me.zhyd.oauth.request.AuthWechatMiniProgramRequest;
|
||||
import org.dromara.common.core.constant.SystemConstants;
|
||||
import org.dromara.common.core.domain.model.XcxLoginBody;
|
||||
import org.dromara.common.core.domain.model.XcxLoginUser;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.ValidatorUtils;
|
||||
import org.dromara.common.json.utils.JsonUtils;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.system.domain.vo.SysClientVo;
|
||||
import org.dromara.system.domain.vo.SysUserVo;
|
||||
import org.dromara.web.domain.vo.LoginVo;
|
||||
import org.dromara.web.service.IAuthStrategy;
|
||||
import org.dromara.web.service.SysLoginService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 小程序认证策略
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@Slf4j
|
||||
@Service("xcx" + IAuthStrategy.BASE_NAME)
|
||||
@RequiredArgsConstructor
|
||||
public class XcxAuthStrategy implements IAuthStrategy {
|
||||
|
||||
private final SysLoginService loginService;
|
||||
|
||||
@Override
|
||||
public LoginVo login(String body, SysClientVo client) {
|
||||
XcxLoginBody loginBody = JsonUtils.parseObject(body, XcxLoginBody.class);
|
||||
ValidatorUtils.validate(loginBody);
|
||||
// xcxCode 为 小程序调用 wx.login 授权后获取
|
||||
String xcxCode = loginBody.getXcxCode();
|
||||
// 多个小程序识别使用
|
||||
String appid = loginBody.getAppid();
|
||||
|
||||
// 校验 appid + appsrcret + xcxCode 调用登录凭证校验接口 获取 session_key 与 openid
|
||||
AuthRequest authRequest = new AuthWechatMiniProgramRequest(AuthConfig.builder()
|
||||
.clientId(appid).clientSecret("自行填写密钥 可根据不同appid填入不同密钥")
|
||||
.ignoreCheckRedirectUri(true).ignoreCheckState(true).build());
|
||||
AuthCallback authCallback = new AuthCallback();
|
||||
authCallback.setCode(xcxCode);
|
||||
AuthResponse<AuthUser> resp = authRequest.login(authCallback);
|
||||
String openid, unionId;
|
||||
if (resp.ok()) {
|
||||
AuthToken token = resp.getData().getToken();
|
||||
openid = token.getOpenId();
|
||||
// 微信小程序只有关联到微信开放平台下之后才能获取到 unionId,因此unionId不一定能返回。
|
||||
unionId = token.getUnionId();
|
||||
} else {
|
||||
throw new ServiceException(resp.getMsg());
|
||||
}
|
||||
// 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可
|
||||
SysUserVo user = loadUserByOpenid(openid);
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||
XcxLoginUser loginUser = new XcxLoginUser();
|
||||
loginUser.setTenantId(user.getTenantId());
|
||||
loginUser.setUserId(user.getUserId());
|
||||
loginUser.setUsername(user.getUserName());
|
||||
loginUser.setNickname(user.getNickName());
|
||||
loginUser.setUserType(user.getUserType());
|
||||
loginUser.setClientKey(client.getClientKey());
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
loginUser.setOpenid(openid);
|
||||
|
||||
SaLoginParameter model = new SaLoginParameter();
|
||||
model.setDeviceType(client.getDeviceType());
|
||||
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
||||
// 例如: 后台用户30分钟过期 app用户1天过期
|
||||
model.setTimeout(client.getTimeout());
|
||||
model.setActiveTimeout(client.getActiveTimeout());
|
||||
model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
|
||||
// 生成token
|
||||
LoginHelper.login(loginUser, model);
|
||||
|
||||
LoginVo loginVo = new LoginVo();
|
||||
loginVo.setAccessToken(StpUtil.getTokenValue());
|
||||
loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
||||
loginVo.setClientId(client.getClientId());
|
||||
loginVo.setOpenid(openid);
|
||||
return loginVo;
|
||||
}
|
||||
|
||||
private SysUserVo loadUserByOpenid(String openid) {
|
||||
// 使用 openid 查询绑定用户 如未绑定用户 则根据业务自行处理 例如 创建默认用户
|
||||
// todo 自行实现 userService.selectUserByOpenid(openid);
|
||||
SysUserVo user = new SysUserVo();
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
log.info("登录用户:{} 不存在.", openid);
|
||||
// todo 用户不存在 业务逻辑自行实现
|
||||
} else if (SystemConstants.DISABLE.equals(user.getStatus())) {
|
||||
log.info("登录用户:{} 已被停用.", openid);
|
||||
// todo 用户已被停用 业务逻辑自行实现
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package org.dromara.web.utils;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
/**
|
||||
* @author lanhai
|
||||
*/
|
||||
public class HttpContextUtils {
|
||||
|
||||
public static HttpServletRequest getHttpServletRequest() {
|
||||
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
}
|
||||
|
||||
public static String getDomain(){
|
||||
HttpServletRequest request = getHttpServletRequest();
|
||||
StringBuffer url = request.getRequestURL();
|
||||
return url.delete(url.length() - request.getRequestURI().length(), url.length()).toString();
|
||||
}
|
||||
|
||||
public static String getOrigin(){
|
||||
HttpServletRequest request = getHttpServletRequest();
|
||||
return request.getHeader("Origin");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.dromara.web.utils;
|
||||
|
||||
/**
|
||||
* @author 菠萝凤梨
|
||||
* @date 2022/3/28 14:32
|
||||
*/
|
||||
public interface OauthCacheNames {
|
||||
|
||||
/**
|
||||
* oauth 授权相关key
|
||||
*/
|
||||
String OAUTH_PREFIX = "mall4j_oauth:";
|
||||
|
||||
/**
|
||||
* token 授权相关key
|
||||
*/
|
||||
String OAUTH_TOKEN_PREFIX = OAUTH_PREFIX + "token:";
|
||||
|
||||
/**
|
||||
* 保存token 缓存使用key
|
||||
*/
|
||||
String ACCESS = OAUTH_TOKEN_PREFIX + "access:";
|
||||
|
||||
/**
|
||||
* 刷新token 缓存使用key
|
||||
*/
|
||||
String REFRESH_TO_ACCESS = OAUTH_TOKEN_PREFIX + "refresh_to_access:";
|
||||
|
||||
/**
|
||||
* 根据uid获取保存的token key缓存使用的key
|
||||
*/
|
||||
String UID_TO_ACCESS = OAUTH_TOKEN_PREFIX + "uid_to_access:";
|
||||
|
||||
/**
|
||||
* 保存token的用户信息使用的key
|
||||
*/
|
||||
String USER_INFO = OAUTH_TOKEN_PREFIX + "user_info:";
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.dromara.web.utils;
|
||||
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* @author LGH
|
||||
*/
|
||||
@UtilityClass
|
||||
public class SecurityUtils {
|
||||
|
||||
private static final String USER_REQUEST = "/api/";
|
||||
|
||||
/**
|
||||
* 获取用户
|
||||
*/
|
||||
public YamiUser getUser() {
|
||||
if (!HttpContextUtils.getHttpServletRequest().getRequestURI().startsWith(USER_REQUEST)) {
|
||||
// 用户相关的请求,应该以/p开头!!!
|
||||
throw new RuntimeException("登录过期或已失效");
|
||||
}
|
||||
|
||||
String accessToken = HttpContextUtils.getHttpServletRequest().getHeader("accessToken");
|
||||
TokenStore tokenStore = new TokenStore();
|
||||
UserInfoInTokenBO userInfoInTokenBO = tokenStore.getUserInfoByAccessToken(accessToken,false);
|
||||
|
||||
YamiUser yamiUser = new YamiUser();
|
||||
yamiUser.setUserId(userInfoInTokenBO.getUserId());
|
||||
yamiUser.setBizUserId(userInfoInTokenBO.getBizUserId());
|
||||
yamiUser.setEnabled(userInfoInTokenBO.getEnabled());
|
||||
yamiUser.setShopId(userInfoInTokenBO.getShopId());
|
||||
yamiUser.setStationId(userInfoInTokenBO.getOtherId());
|
||||
return yamiUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户ID
|
||||
*/
|
||||
public Long getUserId() {
|
||||
Long userId = null;
|
||||
try {
|
||||
userId = getUser().getUserId();
|
||||
} catch (RuntimeException e) {
|
||||
// 处理异常
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
return userId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
package org.dromara.web.utils;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* token信息,该信息存在redis中
|
||||
*
|
||||
* @author 菠萝凤梨
|
||||
* @date 2022/3/25 17:33
|
||||
*/
|
||||
@Data
|
||||
public class TokenInfoBO {
|
||||
|
||||
/**
|
||||
* 保存在token信息里面的用户信息
|
||||
*/
|
||||
private UserInfoInTokenBO userInfoInToken;
|
||||
|
||||
private String accessToken;
|
||||
|
||||
private String refreshToken;
|
||||
|
||||
/**
|
||||
* 在多少秒后过期
|
||||
*/
|
||||
private Integer expiresIn;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.dromara.web.utils;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* token信息,该信息用户返回给前端,前端请求携带accessToken进行用户校验
|
||||
*
|
||||
* @author FrozenWatermelon
|
||||
* @date 2020/7/2
|
||||
*/
|
||||
@Data
|
||||
public class TokenInfoVO {
|
||||
|
||||
@Schema(description = "accessToken" )
|
||||
private String accessToken;
|
||||
|
||||
@Schema(description = "refreshToken" )
|
||||
private String refreshToken;
|
||||
|
||||
@Schema(description = "在多少秒后过期" )
|
||||
private Integer expiresIn;
|
||||
}
|
||||
165
ruoyi-admin/src/main/java/org/dromara/web/utils/TokenStore.java
Normal file
165
ruoyi-admin/src/main/java/org/dromara/web/utils/TokenStore.java
Normal file
@@ -0,0 +1,165 @@
|
||||
package org.dromara.web.utils;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.dromara.common.core.exception.user.UserException;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* token管理 1. 登陆返回token 2. 刷新token 3. 清除用户过去token 4. 校验token
|
||||
*
|
||||
* @author FrozenWatermelon
|
||||
* @date 2020/7/2
|
||||
*/
|
||||
@Component
|
||||
public class TokenStore {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TokenStore.class);
|
||||
|
||||
/**
|
||||
* 以Sa-Token技术生成token,并返回token信息
|
||||
* @param userInfoInToken
|
||||
* @return
|
||||
*/
|
||||
public TokenInfoBO storeAccessSaToken(UserInfoInTokenBO userInfoInToken) {
|
||||
//生成过期时间
|
||||
int timeoutSecond = getExpiresIn(userInfoInToken.getSysType());
|
||||
Duration accessTokenExpires = Duration.ofSeconds(timeoutSecond);
|
||||
|
||||
String uid = this.getUid(userInfoInToken.getSysType().toString(), userInfoInToken.getUserId());
|
||||
StpUtil.login(uid, timeoutSecond);
|
||||
String token = StpUtil.getTokenValue();
|
||||
// 用户信息存入缓存 token生成
|
||||
String keyName = OauthCacheNames.USER_INFO + token;
|
||||
RedisUtils.deleteObject(keyName);
|
||||
RedisUtils.setCacheObject(keyName, userInfoInToken, accessTokenExpires);
|
||||
// 数据封装返回(token不用加密)
|
||||
TokenInfoBO tokenInfoBO = new TokenInfoBO();
|
||||
tokenInfoBO.setUserInfoInToken(userInfoInToken);
|
||||
tokenInfoBO.setExpiresIn(timeoutSecond);
|
||||
tokenInfoBO.setAccessToken(token);
|
||||
tokenInfoBO.setRefreshToken(token);
|
||||
return tokenInfoBO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算过期时间(单位:秒)
|
||||
* @param sysType
|
||||
* @return
|
||||
*/
|
||||
private int getExpiresIn(int sysType) {
|
||||
// 3600秒
|
||||
int expiresIn = 3600;
|
||||
// 普通用户token过期时间
|
||||
if (Objects.equals(sysType, 0)) {
|
||||
expiresIn = expiresIn * 24 * 30;
|
||||
}
|
||||
// 系统管理员的token过期时间
|
||||
if (Objects.equals(sysType, 1)) {
|
||||
expiresIn = expiresIn * 24 * 30;
|
||||
}
|
||||
return expiresIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据accessToken 获取用户信息
|
||||
* @param accessToken accessToken
|
||||
* @param needDecrypt 是否需要解密
|
||||
* @return 用户信息
|
||||
*/
|
||||
public UserInfoInTokenBO getUserInfoByAccessToken(String accessToken, boolean needDecrypt) {
|
||||
if (StrUtil.isBlank(accessToken)) {
|
||||
throw new UserException("accessToken is blank");
|
||||
}
|
||||
String keyName = OauthCacheNames.USER_INFO + accessToken;
|
||||
Object redisCache = RedisUtils.getCacheObject(keyName);
|
||||
if (redisCache == null) {
|
||||
throw new UserException("-2","登录过期,请重新登录");
|
||||
}
|
||||
return (UserInfoInTokenBO) redisCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新token,并返回新的token
|
||||
* @param refreshToken
|
||||
* @return
|
||||
*/
|
||||
public TokenInfoBO refreshToken(String refreshToken) {
|
||||
if (StrUtil.isBlank(refreshToken)) {
|
||||
throw new UserException("refreshToken is blank");
|
||||
}
|
||||
// 删除旧token
|
||||
UserInfoInTokenBO userInfoInTokenBO = getUserInfoByAccessToken(refreshToken, false);
|
||||
this.deleteCurrentToken(refreshToken);
|
||||
// 保存一份新的token
|
||||
return storeAccessSaToken(userInfoInTokenBO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定用户的全部的token
|
||||
*/
|
||||
public void deleteAllToken(String sysType, Long userId) {
|
||||
// 删除用户缓存
|
||||
String uid = this.getUid(sysType, userId);
|
||||
List<String> tokens = StpUtil.getTokenValueListByLoginId(uid);
|
||||
if (!CollectionUtils.isEmpty(tokens)) {
|
||||
List<String> keyNames = new ArrayList<>();
|
||||
for (String token : tokens) {
|
||||
keyNames.add(OauthCacheNames.USER_INFO + token);
|
||||
}
|
||||
RedisUtils.deleteObject(keyNames);
|
||||
}
|
||||
// 移除token
|
||||
StpUtil.logout(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成token,并返回token展示信息
|
||||
* @param userInfoInToken
|
||||
* @return
|
||||
*/
|
||||
public TokenInfoVO storeAndGetVo(UserInfoInTokenBO userInfoInToken) {
|
||||
if (!userInfoInToken.getEnabled()){
|
||||
// 用户已禁用,请联系客服
|
||||
throw new UserException("用户已禁用,请联系客服");
|
||||
}
|
||||
TokenInfoBO tokenInfoBO = storeAccessSaToken(userInfoInToken);
|
||||
// 数据封装返回
|
||||
TokenInfoVO tokenInfoVO = new TokenInfoVO();
|
||||
tokenInfoVO.setAccessToken(tokenInfoBO.getAccessToken());
|
||||
tokenInfoVO.setRefreshToken(tokenInfoBO.getRefreshToken());
|
||||
tokenInfoVO.setExpiresIn(tokenInfoBO.getExpiresIn());
|
||||
return tokenInfoVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除当前登录的token
|
||||
* @param accessToken 令牌
|
||||
*/
|
||||
public void deleteCurrentToken(String accessToken) {
|
||||
// 删除用户缓存
|
||||
String keyName = OauthCacheNames.USER_INFO + accessToken;
|
||||
RedisUtils.deleteObject(keyName);
|
||||
// 移除token
|
||||
StpUtil.logoutByTokenValue(accessToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成各系统唯一uid
|
||||
* @param sysType 系统类型
|
||||
* @param userId 用户id
|
||||
* @return
|
||||
*/
|
||||
private String getUid(String sysType, Long userId) {
|
||||
return sysType + ":" + userId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
package org.dromara.web.utils;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import com.tencent.cloud.CosStsClient;
|
||||
import com.tencent.cloud.Policy;
|
||||
import com.tencent.cloud.Response;
|
||||
import com.tencent.cloud.Statement;
|
||||
import com.tencent.cloud.cos.util.Jackson;
|
||||
import com.tencentcloudapi.common.AbstractModel;
|
||||
import com.tencentcloudapi.common.Credential;
|
||||
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
||||
import com.tencentcloudapi.common.profile.ClientProfile;
|
||||
import com.tencentcloudapi.common.profile.HttpProfile;
|
||||
import com.tencentcloudapi.ims.v20201229.ImsClient;
|
||||
import com.tencentcloudapi.ims.v20201229.models.ImageModerationRequest;
|
||||
import com.tencentcloudapi.ims.v20201229.models.ImageModerationResponse;
|
||||
import com.tencentcloudapi.sms.v20210111.SmsClient;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
||||
import com.tencentcloudapi.tms.v20201229.TmsClient;
|
||||
import com.tencentcloudapi.tms.v20201229.models.TextModerationRequest;
|
||||
import com.tencentcloudapi.tms.v20201229.models.TextModerationResponse;
|
||||
|
||||
import java.util.TreeMap;
|
||||
|
||||
|
||||
/**
|
||||
* 腾讯云工具类
|
||||
* @author Maosw
|
||||
*/
|
||||
public class TxApiSdkUtils
|
||||
{
|
||||
|
||||
private static final String SMS_SECRET_ID = "AKIDMcmoeNr64nIpicWBYeU6TaR8h280uyAF";
|
||||
|
||||
private static final String SMS_SECRET_KEY = "yg8JEzVmriLjtqZ3KURUIrDRQ9euxmbI";
|
||||
|
||||
/**
|
||||
* 获取上传临时密钥
|
||||
*/
|
||||
public void getCredential() {
|
||||
TreeMap<String, Object> config = new TreeMap<String, Object>();
|
||||
try {
|
||||
//这里的 SecretId 和 SecretKey 代表了用于申请临时密钥的永久身份(主账号、子账号等),子账号需要具有操作存储桶的权限。
|
||||
String secretId = System.getenv(SMS_SECRET_ID);
|
||||
String secretKey = System.getenv(SMS_SECRET_KEY);
|
||||
// 替换为您的云 api 密钥 SecretId
|
||||
config.put("secretId", secretId);
|
||||
// 替换为您的云 api 密钥 SecretKey
|
||||
config.put("secretKey", secretKey);
|
||||
// 初始化 policy
|
||||
Policy policy = new Policy();
|
||||
// 临时密钥有效时长,单位是秒,默认 1800 秒,目前主账号最长 2 小时(即 7200 秒),子账号最长 36 小时(即 129600)秒
|
||||
config.put("durationSeconds", 1800);
|
||||
// 换成您的 bucket
|
||||
config.put("bucket", "examplebucket-1250000000");
|
||||
// 换成 bucket 所在地区
|
||||
config.put("region", "ap-shanghai");
|
||||
|
||||
// 开始构建一条 statement
|
||||
Statement statement = new Statement();
|
||||
// 声明设置的结果是允许操作
|
||||
statement.setEffect("allow");
|
||||
statement.addActions(new String[]{
|
||||
"cos:PutObject",
|
||||
// 表单上传、小程序上传
|
||||
"cos:PostObject",
|
||||
// 分块上传
|
||||
"cos:InitiateMultipartUpload",
|
||||
"cos:ListMultipartUploads",
|
||||
"cos:ListParts",
|
||||
"cos:UploadPart",
|
||||
"cos:CompleteMultipartUpload",
|
||||
// 处理相关接口一般为数据万象产品 权限中以ci开头
|
||||
// 创建媒体处理任务
|
||||
"ci:CreateMediaJobs",
|
||||
// 文件压缩
|
||||
"ci:CreateFileProcessJobs"
|
||||
});
|
||||
|
||||
statement.addResources(new String[]{
|
||||
"qcs::cos:ap-chongqing:uid/1250000000:examplebucket-1250000000/*",
|
||||
"qcs::ci:ap-chongqing:uid/1250000000:bucket/examplebucket-1250000000/*"});
|
||||
|
||||
// 把一条 statement 添加到 policy 可以添加多条
|
||||
policy.addStatement(statement);
|
||||
// 将 Policy 示例转化成 String,可以使用任何 json 转化方式,这里是本 SDK 自带的推荐方式
|
||||
config.put("policy", Jackson.toJsonPrettyString(policy));
|
||||
Response response = CosStsClient.getCredential(config);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("no valid secret !");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 腾讯云文件安全检测
|
||||
* @param content
|
||||
* @return
|
||||
*/
|
||||
public static String checkContext(String content){
|
||||
try{
|
||||
Credential cred = new Credential(SMS_SECRET_ID, SMS_SECRET_KEY);
|
||||
// 实例化一个http选项,可选的,没有特殊需求可以跳过
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint("tms.ap-shanghai.tencentcloudapi.com");
|
||||
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
// 实例化要请求产品的client对象,clientProfile是可选的
|
||||
TmsClient client = new TmsClient(cred, "ap-shanghai", clientProfile);
|
||||
// 实例化一个请求对象,每个接口都会对应一个request对象
|
||||
TextModerationRequest req = new TextModerationRequest();
|
||||
|
||||
String str = Base64.encode(content);
|
||||
req.setContent(str);
|
||||
// 返回的resp是一个TextModerationResponse的实例,与请求对象对应
|
||||
TextModerationResponse resp = client.TextModeration(req);
|
||||
// 输出json格式的字符串回包
|
||||
return AbstractModel.toJsonString(resp);
|
||||
} catch (TencentCloudSDKException e) {
|
||||
throw new IllegalArgumentException("文件检测接口异常");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 腾讯云图片安全检测
|
||||
* @param imgUrl
|
||||
* @return
|
||||
*/
|
||||
public static String checkImages(String imgUrl){
|
||||
try{
|
||||
Credential cred = new Credential(SMS_SECRET_ID, SMS_SECRET_KEY);
|
||||
// 实例化一个http选项,可选的,没有特殊需求可以跳过
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint("ims.ap-shanghai.tencentcloudapi.com");
|
||||
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
// 实例化要请求产品的client对象,clientProfile是可选的
|
||||
ImsClient client = new ImsClient(cred, "ap-shanghai", clientProfile);
|
||||
// 实例化一个请求对象,每个接口都会对应一个request对象jkighjkhgkhgkhgjhghkjj
|
||||
ImageModerationRequest req = new ImageModerationRequest();
|
||||
req.setFileUrl(imgUrl);
|
||||
// 返回的resp是一个ImageModerationResponse的实例,与请求对象对应
|
||||
ImageModerationResponse resp = client.ImageModeration(req);
|
||||
// 输出json格式的字符串回包
|
||||
return AbstractModel.toJsonString(resp);
|
||||
} catch (TencentCloudSDKException e) {
|
||||
throw new IllegalArgumentException("文件检测接口异常");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 腾讯云发送短信
|
||||
* @param phoneNumber
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
public static String sendSmsMsg(String phoneNumber, String code){
|
||||
try{
|
||||
Credential cred = new Credential(SMS_SECRET_ID, SMS_SECRET_KEY);
|
||||
// 实例化一个http选项,可选的,没有特殊需求可以跳过
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint("sms.tencentcloudapi.com");
|
||||
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
// 实例化要请求产品的client对象,clientProfile是可选的
|
||||
SmsClient client = new SmsClient(cred, "ap-nanjing", clientProfile);
|
||||
// 实例化一个请求对象,每个接口都会对应一个request对象
|
||||
SendSmsRequest req = new SendSmsRequest();
|
||||
|
||||
String[] phoneNumberSet1 = {phoneNumber};
|
||||
req.setPhoneNumberSet(phoneNumberSet1);
|
||||
req.setSmsSdkAppId("1400926380");
|
||||
req.setTemplateId("2222045");
|
||||
req.setSignName("合肥小图科技");
|
||||
|
||||
String[] templateParamSet1 = {code};
|
||||
req.setTemplateParamSet(templateParamSet1);
|
||||
|
||||
// 返回的resp是一个SendSmsResponse的实例,与请求对象对应
|
||||
SendSmsResponse resp = client.SendSms(req);
|
||||
// 输出json格式的字符串回包
|
||||
return AbstractModel.toJsonString(resp);
|
||||
} catch (TencentCloudSDKException e) {
|
||||
throw new IllegalArgumentException("短信接口异常");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
package org.dromara.web.utils;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 保存在token信息里面的用户信息
|
||||
*
|
||||
* @author 菠萝凤梨
|
||||
* @date 2022/3/25 17:33
|
||||
*/
|
||||
@Data
|
||||
public class UserInfoInTokenBO {
|
||||
|
||||
/**
|
||||
* 用户在自己系统的用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 租户id (商家id)
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 系统类型 2:技术 5:客户
|
||||
*
|
||||
*/
|
||||
private Integer sysType;
|
||||
|
||||
/**
|
||||
* 是否是管理员
|
||||
*/
|
||||
private Integer isAdmin;
|
||||
|
||||
/**
|
||||
* 业务系统用户id
|
||||
*/
|
||||
private String bizUserId;
|
||||
|
||||
/**
|
||||
* 权限列表
|
||||
*/
|
||||
private Set<String> perms;
|
||||
|
||||
/**
|
||||
* 状态 1 正常 0 无效
|
||||
*/
|
||||
private Boolean enabled;
|
||||
|
||||
/**
|
||||
* 其他Id
|
||||
*/
|
||||
private Long otherId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package org.dromara.web.utils;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import org.dromara.common.core.validate.AddGroup;
|
||||
|
||||
/**
|
||||
* @author lh
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "用户登录信息")
|
||||
public class UserRegisterParam {
|
||||
|
||||
@Schema(description = "密码")
|
||||
private String passWord;
|
||||
|
||||
@Schema(description = "邮箱")
|
||||
private String userMail;
|
||||
|
||||
@Schema(description = "昵称")
|
||||
private String nickName;
|
||||
|
||||
@Schema(description = "用户名")
|
||||
private String userName;
|
||||
|
||||
@Schema(description = "手机号")
|
||||
@NotBlank(message = "手机号码不能为空", groups = { AddGroup.class})
|
||||
private String mobile;
|
||||
|
||||
@Schema(description = "头像")
|
||||
private String img;
|
||||
|
||||
@Schema(description = "校验登陆注册验证码成功的标识")
|
||||
private String checkRegisterSmsFlag;
|
||||
|
||||
@Schema(description = "当账户未绑定时,临时的uid")
|
||||
private String tempUid;
|
||||
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "微信openId")
|
||||
private String openId;
|
||||
|
||||
@Schema(description = "系统类型 2:技术 5:客户")
|
||||
private Integer sysType;
|
||||
}
|
||||
100
ruoyi-admin/src/main/java/org/dromara/web/utils/WxXcxUtils.java
Normal file
100
ruoyi-admin/src/main/java/org/dromara/web/utils/WxXcxUtils.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package org.dromara.web.utils;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 微信小程序工具类
|
||||
* @author Maosw
|
||||
*/
|
||||
public class WxXcxUtils {
|
||||
|
||||
private static final String APPID = "wxed96e8fe10ea8992";
|
||||
private static final String SECRET = "e9399ee3cc4f6f335cd91b1935c19c36";
|
||||
private static final String TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket";
|
||||
private static final String TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token";
|
||||
|
||||
/**
|
||||
* 获取access_token
|
||||
*/
|
||||
public static String getAccessToken(){
|
||||
String url = TOKEN_URL + "?grant_type=client_credential&appid=" + APPID + "&secret=" + SECRET;
|
||||
String result = HttpUtil.get(url);
|
||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||
return jsonObject.getString("access_token");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取jsapi_ticket
|
||||
*/
|
||||
public static String getJsapiTicket() {
|
||||
String accessToken = getAccessToken();
|
||||
String url = TICKET_URL + "?access_token=" + accessToken + "&type=jsapi";
|
||||
String result = HttpUtil.get(url);
|
||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||
return jsonObject.getString("ticket");
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成签名
|
||||
* @param url 当前网页的URL
|
||||
* @return 签名信息
|
||||
*/
|
||||
public static Map<String, String> generateSignature(String url) {
|
||||
if (StringUtils.isEmpty(url)) {
|
||||
throw new IllegalArgumentException("URL不能为空");
|
||||
}
|
||||
|
||||
// 获取jsapi_ticket
|
||||
String jsapiTicket = getJsapiTicket();
|
||||
|
||||
// 生成随机字符串
|
||||
String nonceStr = RandomUtil.randomString(16);
|
||||
|
||||
// 生成时间戳
|
||||
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
|
||||
// 准备签名参数
|
||||
Map<String, String> params = new TreeMap<>();
|
||||
params.put("jsapi_ticket", jsapiTicket);
|
||||
params.put("noncestr", nonceStr);
|
||||
params.put("timestamp", timestamp);
|
||||
params.put("url", url);
|
||||
|
||||
// 拼接字符串
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||
stringBuilder.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
|
||||
}
|
||||
String string1 = stringBuilder.substring(0, stringBuilder.length() - 1);
|
||||
|
||||
// 生成签名
|
||||
String signature = DigestUtil.sha1Hex(string1);
|
||||
|
||||
// 返回结果
|
||||
Map<String, String> result = new HashMap<>();
|
||||
result.put("timestamp", timestamp);
|
||||
result.put("nonceStr", nonceStr);
|
||||
result.put("signature", signature);
|
||||
result.put("appId", APPID);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static JSONObject getUserPhoneNumber(String code){
|
||||
String accessToken = getAccessToken();
|
||||
String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token="+accessToken;
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", code);
|
||||
String result = HttpRequest.post(url).body(json.toString()).execute().body();
|
||||
return JSONObject.parseObject(result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
package org.dromara.web.utils;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 用户详细信息
|
||||
* @author LGH
|
||||
*/
|
||||
@Data
|
||||
public class YamiUser {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
private String bizUserId;
|
||||
|
||||
private Boolean enabled;
|
||||
|
||||
/**
|
||||
* 自提点Id
|
||||
*/
|
||||
private Long stationId;
|
||||
|
||||
/**
|
||||
* 店铺Id
|
||||
*/
|
||||
private Long shopId;
|
||||
}
|
||||
Reference in New Issue
Block a user