Compare commits
10 Commits
888ac7f8f4
...
14576812ae
Author | SHA1 | Date |
---|---|---|
|
14576812ae | |
|
4ebcb60f17 | |
|
90bed7d0b0 | |
|
387b3a0e68 | |
|
2ef2fabc66 | |
|
35ec6d7485 | |
|
5cb6952434 | |
|
43944084c2 | |
|
41d617b26f | |
|
335aaccdbb |
|
@ -0,0 +1,26 @@
|
|||
package com.mcwl.web.controller.mqtt;
|
||||
|
||||
import com.mcwl.common.core.domain.R;
|
||||
import com.mcwl.myInvitation.domain.vo.CommissionRatioVo;
|
||||
import com.mcwl.resource.util.MqttTemplate;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController()
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/mqtt")
|
||||
public class MqttController {
|
||||
|
||||
private final MqttTemplate mqttTemplate;
|
||||
|
||||
@GetMapping("/send")
|
||||
public void list(String topic, String msg) {
|
||||
mqttTemplate.publish(topic, msg);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,303 +1,303 @@
|
|||
package com.mcwl.web.controller.pay.AliPay;
|
||||
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import cn.hutool.extra.qrcode.QrCodeUtil;
|
||||
import com.alipay.api.domain.AlipayAccount;
|
||||
import com.alipay.easysdk.factory.Factory;
|
||||
import com.mcwl.common.annotation.Anonymous;
|
||||
import com.mcwl.common.constant.HttpStatus;
|
||||
import com.mcwl.common.core.controller.BaseController;
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.common.core.domain.R;
|
||||
import com.mcwl.common.core.redis.RedisCache;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.common.utils.ShareCodeUtils;
|
||||
import com.mcwl.pay.config.AliConfig;
|
||||
import com.mcwl.pay.domain.OrderTrade;
|
||||
import com.mcwl.pay.domain.OrderTradeDto;
|
||||
import com.mcwl.pay.domain.vo.PayVo;
|
||||
import com.mcwl.pay.service.AliPayService;
|
||||
import com.mcwl.pay.service.OrderTradeService;
|
||||
import com.mcwl.system.domain.SysUserPayAccount;
|
||||
import com.mcwl.system.service.ISysUserPayAccountService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @Author:ChenYan
|
||||
* @Project:McWl
|
||||
* @Package:com.mcwl.web.controller.pay
|
||||
* @Filename:OrderTradeController
|
||||
* @Description 支付模块
|
||||
* @Date:2025/1/3 14:46
|
||||
*/
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/ali/pay")
|
||||
@Validated
|
||||
@Api(tags = "支付模块")
|
||||
public class AliPayController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private OrderTradeService orderTradeService;
|
||||
|
||||
@Autowired
|
||||
private ISysUserPayAccountService sysUserPayAccountService;
|
||||
|
||||
@Autowired
|
||||
private AliPayService aliPayService;
|
||||
|
||||
@Autowired
|
||||
private AliConfig aliConfig;
|
||||
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Value("${mall.mgt.aliPayConfig.bindUrl}")
|
||||
private String bindUrl;
|
||||
|
||||
|
||||
/**
|
||||
* 授权二维码
|
||||
*
|
||||
* @param response 响应
|
||||
* @throws Exception 抛出异常
|
||||
*/
|
||||
@ApiOperation(value = "支付宝绑定")
|
||||
@GetMapping("/generateQrCode")
|
||||
@ResponseBody
|
||||
public R<String> generateQrCode(HttpServletResponse response) throws Exception {
|
||||
String scope = "auth_user"; // 需要获取用户信息
|
||||
String appId = aliConfig.getAppId();
|
||||
String state = ShareCodeUtils.idToCode(SecurityUtils.getUserId()); // 防止CSRF攻击
|
||||
|
||||
String encodedRedirectUri = URLEncoder.encode(bindUrl, "UTF-8");
|
||||
// 线上
|
||||
//package com.mcwl.web.controller.pay.AliPay;
|
||||
//
|
||||
//import cn.hutool.core.lang.UUID;
|
||||
//import cn.hutool.extra.qrcode.QrCodeUtil;
|
||||
//import com.alipay.api.domain.AlipayAccount;
|
||||
//import com.alipay.easysdk.factory.Factory;
|
||||
//import com.mcwl.common.annotation.Anonymous;
|
||||
//import com.mcwl.common.constant.HttpStatus;
|
||||
//import com.mcwl.common.core.controller.BaseController;
|
||||
//import com.mcwl.common.core.domain.AjaxResult;
|
||||
//import com.mcwl.common.core.domain.R;
|
||||
//import com.mcwl.common.core.redis.RedisCache;
|
||||
//import com.mcwl.common.utils.SecurityUtils;
|
||||
//import com.mcwl.common.utils.ShareCodeUtils;
|
||||
//import com.mcwl.pay.config.AliConfig;
|
||||
//import com.mcwl.pay.domain.OrderTrade;
|
||||
//import com.mcwl.pay.domain.OrderTradeDto;
|
||||
//import com.mcwl.pay.domain.vo.PayVo;
|
||||
//import com.mcwl.pay.service.AliPayService;
|
||||
//import com.mcwl.pay.service.OrderTradeService;
|
||||
//import com.mcwl.system.domain.SysUserPayAccount;
|
||||
//import com.mcwl.system.service.ISysUserPayAccountService;
|
||||
//import io.swagger.annotations.Api;
|
||||
//import io.swagger.annotations.ApiOperation;
|
||||
//import org.apache.ibatis.annotations.Param;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.beans.factory.annotation.Value;
|
||||
//import org.springframework.stereotype.Controller;
|
||||
//import org.springframework.validation.annotation.Validated;
|
||||
//import org.springframework.web.bind.annotation.*;
|
||||
//
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//import javax.validation.Valid;
|
||||
//import javax.validation.constraints.Min;
|
||||
//import javax.validation.constraints.NotBlank;
|
||||
//import javax.validation.constraints.NotNull;
|
||||
//import javax.validation.constraints.Pattern;
|
||||
//import java.io.FileNotFoundException;
|
||||
//import java.net.URLEncoder;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.Map;
|
||||
//import java.util.Objects;
|
||||
//import java.util.Optional;
|
||||
//
|
||||
///**
|
||||
// * @Author:ChenYan
|
||||
// * @Project:McWl
|
||||
// * @Package:com.mcwl.web.controller.pay
|
||||
// * @Filename:OrderTradeController
|
||||
// * @Description 支付模块
|
||||
// * @Date:2025/1/3 14:46
|
||||
// */
|
||||
//
|
||||
//@Controller
|
||||
//@RequestMapping("/ali/pay")
|
||||
//@Validated
|
||||
//@Api(tags = "支付模块")
|
||||
//public class AliPayController extends BaseController {
|
||||
//
|
||||
// @Autowired
|
||||
// private OrderTradeService orderTradeService;
|
||||
//
|
||||
// @Autowired
|
||||
// private ISysUserPayAccountService sysUserPayAccountService;
|
||||
//
|
||||
// @Autowired
|
||||
// private AliPayService aliPayService;
|
||||
//
|
||||
// @Autowired
|
||||
// private AliConfig aliConfig;
|
||||
//
|
||||
//
|
||||
// @Autowired
|
||||
// private RedisCache redisCache;
|
||||
//
|
||||
// @Value("${mall.mgt.aliPayConfig.bindUrl}")
|
||||
// private String bindUrl;
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 授权二维码
|
||||
// *
|
||||
// * @param response 响应
|
||||
// * @throws Exception 抛出异常
|
||||
// */
|
||||
// @ApiOperation(value = "支付宝绑定")
|
||||
// @GetMapping("/generateQrCode")
|
||||
// @ResponseBody
|
||||
// public R<String> generateQrCode(HttpServletResponse response) throws Exception {
|
||||
// String scope = "auth_user"; // 需要获取用户信息
|
||||
// String appId = aliConfig.getAppId();
|
||||
// String state = ShareCodeUtils.idToCode(SecurityUtils.getUserId()); // 防止CSRF攻击
|
||||
//
|
||||
// String encodedRedirectUri = URLEncoder.encode(bindUrl, "UTF-8");
|
||||
// // 线上
|
||||
//// String authUrl = String.format(
|
||||
//// "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=%s&scope=%s&redirect_uri=%s&state=%s",
|
||||
//// appId, scope, encodedRedirectUri, state
|
||||
//// );
|
||||
// // 沙箱
|
||||
// String authUrl = String.format(
|
||||
// "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=%s&scope=%s&redirect_uri=%s&state=%s",
|
||||
// "https://openauth-sandbox.dl.alipaydev.com/oauth2/publicAppAuthorize.htm?app_id=%s&scope=%s&redirect_uri=%s&state=%s",
|
||||
// appId, scope, encodedRedirectUri, state
|
||||
// );
|
||||
// 沙箱
|
||||
String authUrl = String.format(
|
||||
"https://openauth-sandbox.dl.alipaydev.com/oauth2/publicAppAuthorize.htm?app_id=%s&scope=%s&redirect_uri=%s&state=%s",
|
||||
appId, scope, encodedRedirectUri, state
|
||||
);
|
||||
|
||||
// QrCodeUtil.generate(authUrl, 300, 300, "png", response.getOutputStream());
|
||||
return R.ok(authUrl, "成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝绑定状态查询
|
||||
*/
|
||||
@GetMapping("/queryBindStatus")
|
||||
@ApiOperation(value = "支付宝绑定状态查询")
|
||||
@ResponseBody
|
||||
public R<Object> queryTradeStatus() throws Exception {
|
||||
|
||||
return aliPayService.queryBindStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* 授权回调
|
||||
*
|
||||
* @param authCode 授权码
|
||||
*/
|
||||
@GetMapping("/callback")
|
||||
public String callback(@RequestParam("auth_code") String authCode, String state) throws FileNotFoundException {
|
||||
|
||||
System.out.println("authCode = " + authCode);
|
||||
String result = aliPayService.bindingCallback(authCode, state);
|
||||
if ("success".equals(result)) {
|
||||
return "binding-success";
|
||||
} else {
|
||||
return "binding-fail";
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 账户余额查询
|
||||
// */
|
||||
// @GetMapping("/balance")
|
||||
// @ResponseBody
|
||||
// public AjaxResult balance() throws AlipayApiException {
|
||||
// String balance = aliPayService.balance();
|
||||
// return AjaxResult.success(balance);
|
||||
//
|
||||
//// QrCodeUtil.generate(authUrl, 300, 300, "png", response.getOutputStream());
|
||||
// return R.ok(authUrl, "成功");
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 支付接口
|
||||
*
|
||||
* @param orderTradeDto 订单实体
|
||||
* @param response 响应
|
||||
* @throws Exception
|
||||
*/
|
||||
@Anonymous
|
||||
@PostMapping("/doPay")
|
||||
@ApiOperation(value = "支付宝支付")
|
||||
@ResponseBody
|
||||
public R<PayVo> doPay(@Valid
|
||||
@RequestBody
|
||||
OrderTradeDto orderTradeDto,
|
||||
HttpServletResponse response) throws Exception {
|
||||
PayVo payVo = null;
|
||||
|
||||
String type = orderTradeDto.getType();
|
||||
|
||||
if ("member".equalsIgnoreCase(type)) {
|
||||
if (!Optional.ofNullable(orderTradeDto.getProductId()).isPresent()) {
|
||||
return R.fail(HttpStatus.SHOW_ERROR_MSG,"商品id不能为空");
|
||||
}
|
||||
payVo = aliPayService.memberPay(orderTradeDto);
|
||||
// QrCodeUtil.generate(payVo.getUrl(), 300, 300, "png", response.getOutputStream());
|
||||
} else if ("points".equalsIgnoreCase(type)) {
|
||||
payVo = aliPayService.pointsPay(orderTradeDto.getAmount());
|
||||
// QrCodeUtil.generate(payVo.getUrl(), 300, 300, "png", response.getOutputStream());
|
||||
} else if ("wallet".equalsIgnoreCase(type)) {
|
||||
// 充值金额只能是整数
|
||||
if (orderTradeDto.getAmount() % 1 != 0) {
|
||||
return R.fail(HttpStatus.SHOW_ERROR_MSG,"充值金额只能是整数");
|
||||
}
|
||||
payVo = aliPayService.walletPay(orderTradeDto.getAmount());
|
||||
// QrCodeUtil.generate(payVo.getUrl(), 300, 300, "png", response.getOutputStream());
|
||||
} else {
|
||||
return R.fail(HttpStatus.SHOW_ERROR_MSG,"订单类型错误");
|
||||
}
|
||||
|
||||
return R.ok(payVo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现接口
|
||||
*/
|
||||
@Anonymous
|
||||
@GetMapping("/fetch")
|
||||
@ResponseBody
|
||||
@ApiOperation(value = "提现")
|
||||
public R<String> fetch(@Valid
|
||||
@NotNull(message = "提现金额不能为空")
|
||||
@Pattern(regexp = "^(0|(?!0\\d)[1-9]\\d*)(\\.\\d{2})?$", message = "金额格式错误(必须保留两位小数)")
|
||||
String amount) throws Exception {
|
||||
|
||||
SysUserPayAccount sysUserPayAccount = sysUserPayAccountService.lambdaQuery()
|
||||
.eq(SysUserPayAccount::getUserId, SecurityUtils.getUserId())
|
||||
.eq(SysUserPayAccount::getType, 0)
|
||||
.one();
|
||||
|
||||
if (Objects.isNull(sysUserPayAccount)) {
|
||||
return R.fail(HttpStatus.SHOW_ERROR_MSG,"请先绑定支付宝");
|
||||
}
|
||||
|
||||
|
||||
if (Double.parseDouble(amount) < 0.1) {
|
||||
return R.fail(HttpStatus.SHOW_ERROR_MSG,"提现金额最小为0.1");
|
||||
}
|
||||
|
||||
return aliPayService.fetch(amount.toString());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付回调接口
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Anonymous
|
||||
@PostMapping("/notify") // 注意这里必须是POST接口
|
||||
@ResponseBody
|
||||
public String payNotify(HttpServletRequest request) throws Exception {
|
||||
|
||||
|
||||
if (request.getParameter("trade_status").equals("TRADE_SUCCESS")) {
|
||||
System.out.println("=========支付宝异步回调========");
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
Map<String, String[]> requestParams = request.getParameterMap();
|
||||
for (String name : requestParams.keySet()) {
|
||||
params.put(name, request.getParameter(name));
|
||||
// System.out.println(name + " = " + request.getParameter(name));
|
||||
}
|
||||
|
||||
// 支付宝验签
|
||||
if (Factory.Payment.Common().verifyNotify(params)) {
|
||||
// System.out.println("交易名称: " + params.get("subject"));
|
||||
// System.out.println("交易状态: " + params.get("trade_status"));
|
||||
// System.out.println("支付宝交易凭证号: " + params.get("trade_no"));
|
||||
// System.out.println("商户订单号: " + params.get("out_trade_no"));
|
||||
// System.out.println("交易金额: " + params.get("total_amount"));
|
||||
// System.out.println("买家在支付宝唯一id: " + params.get("buyer_id"));
|
||||
// System.out.println("买家付款时间: " + params.get("gmt_payment"));
|
||||
// System.out.println("买家付款金额: " + params.get("buyer_pay_amount"));
|
||||
// 验签通过
|
||||
|
||||
String code = params.get("out_trade_no"); // 商户订单号
|
||||
OrderTrade orderTrade = orderTradeService.lambdaQuery()
|
||||
.eq(OrderTrade::getCode, code)
|
||||
.one();
|
||||
if (Objects.isNull(orderTrade)) {
|
||||
return "failure";
|
||||
}
|
||||
// 获取订单后缀
|
||||
String suffix = code.substring(code.lastIndexOf("_") + 1);
|
||||
|
||||
orderTradeService.orderHandler(orderTrade, suffix, params);
|
||||
|
||||
// 更新订单状态
|
||||
// if (!StringUtils.isEmpty(orderTradeJson)) {
|
||||
// OrderTrade orderTrade = JSONUtil.toBean(orderTradeJson, OrderTrade.class);
|
||||
// // 支付宝交易凭证号
|
||||
// orderTrade.setPaymentMethod(params.get("trade_no"));
|
||||
// orderTrade.setTransactionId(1);
|
||||
// orderTrade.setOrderTime(DateUtils.parseDate(params.get("gmt_payment")));
|
||||
// orderTrade.setOrderStatus(3);
|
||||
// orderTrade.setPayStatus(2);
|
||||
// String totalAmountStr = params.get("total_amount");
|
||||
// if (totalAmountStr != null && !totalAmountStr.isEmpty()) {
|
||||
// BigDecimal totalAmount = new BigDecimal(totalAmountStr);
|
||||
// orderTrade.setTotalAmount(totalAmount.intValue());
|
||||
// }
|
||||
// String buyerPayAmountStr = params.get("buyer_pay_amount");
|
||||
// if (buyerPayAmountStr != null && !buyerPayAmountStr.isEmpty()) {
|
||||
// BigDecimal buyerPayAmount = new BigDecimal(buyerPayAmountStr);
|
||||
// orderTrade.setPaymentAmount(buyerPayAmount.intValue());
|
||||
// }
|
||||
// orderTradeService.save(orderTrade);
|
||||
//
|
||||
// /**
|
||||
// * 支付宝绑定状态查询
|
||||
// */
|
||||
// @GetMapping("/queryBindStatus")
|
||||
// @ApiOperation(value = "支付宝绑定状态查询")
|
||||
// @ResponseBody
|
||||
// public R<Object> queryTradeStatus() throws Exception {
|
||||
//
|
||||
// return aliPayService.queryBindStatus();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 授权回调
|
||||
// *
|
||||
// * @param authCode 授权码
|
||||
// */
|
||||
// @GetMapping("/callback")
|
||||
// public String callback(@RequestParam("auth_code") String authCode, String state) throws FileNotFoundException {
|
||||
//
|
||||
// System.out.println("authCode = " + authCode);
|
||||
// String result = aliPayService.bindingCallback(authCode, state);
|
||||
// if ("success".equals(result)) {
|
||||
// return "binding-success";
|
||||
// } else {
|
||||
// return "binding-fail";
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//// /**
|
||||
//// * 账户余额查询
|
||||
//// */
|
||||
//// @GetMapping("/balance")
|
||||
//// @ResponseBody
|
||||
//// public AjaxResult balance() throws AlipayApiException {
|
||||
//// String balance = aliPayService.balance();
|
||||
//// return AjaxResult.success(balance);
|
||||
//// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 支付接口
|
||||
// *
|
||||
// * @param orderTradeDto 订单实体
|
||||
// * @param response 响应
|
||||
// * @throws Exception
|
||||
// */
|
||||
// @Anonymous
|
||||
// @PostMapping("/doPay")
|
||||
// @ApiOperation(value = "支付宝支付")
|
||||
// @ResponseBody
|
||||
// public R<PayVo> doPay(@Valid
|
||||
// @RequestBody
|
||||
// OrderTradeDto orderTradeDto,
|
||||
// HttpServletResponse response) throws Exception {
|
||||
// PayVo payVo = null;
|
||||
//
|
||||
// String type = orderTradeDto.getType();
|
||||
//
|
||||
// if ("member".equalsIgnoreCase(type)) {
|
||||
// if (!Optional.ofNullable(orderTradeDto.getProductId()).isPresent()) {
|
||||
// return R.fail(HttpStatus.SHOW_ERROR_MSG,"商品id不能为空");
|
||||
// }
|
||||
// payVo = aliPayService.memberPay(orderTradeDto);
|
||||
//// QrCodeUtil.generate(payVo.getUrl(), 300, 300, "png", response.getOutputStream());
|
||||
// } else if ("points".equalsIgnoreCase(type)) {
|
||||
// payVo = aliPayService.pointsPay(orderTradeDto.getAmount());
|
||||
//// QrCodeUtil.generate(payVo.getUrl(), 300, 300, "png", response.getOutputStream());
|
||||
// } else if ("wallet".equalsIgnoreCase(type)) {
|
||||
// // 充值金额只能是整数
|
||||
// if (orderTradeDto.getAmount() % 1 != 0) {
|
||||
// return R.fail(HttpStatus.SHOW_ERROR_MSG,"充值金额只能是整数");
|
||||
// }
|
||||
// payVo = aliPayService.walletPay(orderTradeDto.getAmount());
|
||||
//// QrCodeUtil.generate(payVo.getUrl(), 300, 300, "png", response.getOutputStream());
|
||||
// } else {
|
||||
// return R.fail(HttpStatus.SHOW_ERROR_MSG,"订单类型错误");
|
||||
// }
|
||||
//
|
||||
// return R.ok(payVo);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 提现接口
|
||||
// */
|
||||
// @Anonymous
|
||||
// @GetMapping("/fetch")
|
||||
// @ResponseBody
|
||||
// @ApiOperation(value = "提现")
|
||||
// public R<String> fetch(@Valid
|
||||
// @NotNull(message = "提现金额不能为空")
|
||||
// @Pattern(regexp = "^(0|(?!0\\d)[1-9]\\d*)(\\.\\d{2})?$", message = "金额格式错误(必须保留两位小数)")
|
||||
// String amount) throws Exception {
|
||||
//
|
||||
// SysUserPayAccount sysUserPayAccount = sysUserPayAccountService.lambdaQuery()
|
||||
// .eq(SysUserPayAccount::getUserId, SecurityUtils.getUserId())
|
||||
// .eq(SysUserPayAccount::getType, 0)
|
||||
// .one();
|
||||
//
|
||||
// if (Objects.isNull(sysUserPayAccount)) {
|
||||
// return R.fail(HttpStatus.SHOW_ERROR_MSG,"请先绑定支付宝");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// if (Double.parseDouble(amount) < 0.1) {
|
||||
// return R.fail(HttpStatus.SHOW_ERROR_MSG,"提现金额最小为0.1");
|
||||
// }
|
||||
//
|
||||
// return aliPayService.fetch(amount.toString());
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 支付回调接口
|
||||
// *
|
||||
// * @param request
|
||||
// * @return
|
||||
// * @throws Exception
|
||||
// */
|
||||
// @Anonymous
|
||||
// @PostMapping("/notify") // 注意这里必须是POST接口
|
||||
// @ResponseBody
|
||||
// public String payNotify(HttpServletRequest request) throws Exception {
|
||||
//
|
||||
//
|
||||
// if (request.getParameter("trade_status").equals("TRADE_SUCCESS")) {
|
||||
// System.out.println("=========支付宝异步回调========");
|
||||
//
|
||||
// Map<String, String> params = new HashMap<>();
|
||||
// Map<String, String[]> requestParams = request.getParameterMap();
|
||||
// for (String name : requestParams.keySet()) {
|
||||
// params.put(name, request.getParameter(name));
|
||||
// // System.out.println(name + " = " + request.getParameter(name));
|
||||
// }
|
||||
//
|
||||
// // 支付宝验签
|
||||
// if (Factory.Payment.Common().verifyNotify(params)) {
|
||||
//// System.out.println("交易名称: " + params.get("subject"));
|
||||
//// System.out.println("交易状态: " + params.get("trade_status"));
|
||||
//// System.out.println("支付宝交易凭证号: " + params.get("trade_no"));
|
||||
//// System.out.println("商户订单号: " + params.get("out_trade_no"));
|
||||
//// System.out.println("交易金额: " + params.get("total_amount"));
|
||||
//// System.out.println("买家在支付宝唯一id: " + params.get("buyer_id"));
|
||||
//// System.out.println("买家付款时间: " + params.get("gmt_payment"));
|
||||
//// System.out.println("买家付款金额: " + params.get("buyer_pay_amount"));
|
||||
// // 验签通过
|
||||
//
|
||||
// String code = params.get("out_trade_no"); // 商户订单号
|
||||
// OrderTrade orderTrade = orderTradeService.lambdaQuery()
|
||||
// .eq(OrderTrade::getCode, code)
|
||||
// .one();
|
||||
// if (Objects.isNull(orderTrade)) {
|
||||
// return "failure";
|
||||
// }
|
||||
} else {
|
||||
// 验签失败
|
||||
System.out.println("验签失败");
|
||||
}
|
||||
} else {
|
||||
// 验签失败
|
||||
System.out.println("验签失败");
|
||||
}
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// // 获取订单后缀
|
||||
// String suffix = code.substring(code.lastIndexOf("_") + 1);
|
||||
//
|
||||
// orderTradeService.orderHandler(orderTrade, suffix, params);
|
||||
//
|
||||
// // 更新订单状态
|
||||
//// if (!StringUtils.isEmpty(orderTradeJson)) {
|
||||
//// OrderTrade orderTrade = JSONUtil.toBean(orderTradeJson, OrderTrade.class);
|
||||
//// // 支付宝交易凭证号
|
||||
//// orderTrade.setPaymentMethod(params.get("trade_no"));
|
||||
//// orderTrade.setTransactionId(1);
|
||||
//// orderTrade.setOrderTime(DateUtils.parseDate(params.get("gmt_payment")));
|
||||
//// orderTrade.setOrderStatus(3);
|
||||
//// orderTrade.setPayStatus(2);
|
||||
//// String totalAmountStr = params.get("total_amount");
|
||||
//// if (totalAmountStr != null && !totalAmountStr.isEmpty()) {
|
||||
//// BigDecimal totalAmount = new BigDecimal(totalAmountStr);
|
||||
//// orderTrade.setTotalAmount(totalAmount.intValue());
|
||||
//// }
|
||||
//// String buyerPayAmountStr = params.get("buyer_pay_amount");
|
||||
//// if (buyerPayAmountStr != null && !buyerPayAmountStr.isEmpty()) {
|
||||
//// BigDecimal buyerPayAmount = new BigDecimal(buyerPayAmountStr);
|
||||
//// orderTrade.setPaymentAmount(buyerPayAmount.intValue());
|
||||
//// }
|
||||
//// orderTradeService.save(orderTrade);
|
||||
//// }
|
||||
// } else {
|
||||
// // 验签失败
|
||||
// System.out.println("验签失败");
|
||||
// }
|
||||
// } else {
|
||||
// // 验签失败
|
||||
// System.out.println("验签失败");
|
||||
// }
|
||||
//
|
||||
// return "success";
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,163 +1,163 @@
|
|||
package com.mcwl.web.controller.pay.AliPay;
|
||||
|
||||
import com.alipay.easysdk.factory.Factory;
|
||||
import com.alipay.easysdk.kernel.Config;
|
||||
import com.alipay.easysdk.payment.common.models.AlipayTradeCancelResponse;
|
||||
import com.alipay.easysdk.payment.common.models.AlipayTradeCloseResponse;
|
||||
import com.alipay.easysdk.payment.common.models.AlipayTradeQueryResponse;
|
||||
import com.mcwl.common.JSONUtils;
|
||||
import com.mcwl.common.constant.HttpStatus;
|
||||
import com.mcwl.common.core.controller.BaseController;
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.common.core.domain.R;
|
||||
import com.mcwl.common.core.page.TableDataInfo;
|
||||
import com.mcwl.common.core.redis.RedisCache;
|
||||
import com.mcwl.common.domain.IdsParam;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.pay.domain.OrderTrade;
|
||||
import com.mcwl.pay.service.AliPayService;
|
||||
import com.mcwl.pay.service.OrderTradeService;
|
||||
import com.mcwl.resource.domain.dto.ProductRes;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author:ChenYan
|
||||
* @Project:McWl
|
||||
* @Package:com.mcwl.web.controller.pay
|
||||
* @Filename:OrderTradeController
|
||||
* @Description 支付模块
|
||||
* @Date:2025/1/3 14:46
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/order")
|
||||
@Validated
|
||||
@Api(tags = "订单模块")
|
||||
public class OrderTradeController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private Config config;
|
||||
|
||||
@Autowired
|
||||
private OrderTradeService orderTradeService;
|
||||
|
||||
@Autowired
|
||||
private AliPayService aliPayService;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
|
||||
/**
|
||||
* 购买产品
|
||||
*/
|
||||
@PostMapping("/buy")
|
||||
@ApiOperation(value = "购买产品")
|
||||
public R<Object> buy(@Valid @RequestBody ProductRes productRes) throws Exception {
|
||||
orderTradeService.productHandler(productRes);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation(value = "查询订单列表")
|
||||
public TableDataInfo list(OrderTrade orderTrade) {
|
||||
startPage();
|
||||
List<OrderTrade> list = orderTradeService.selectMallProductList(orderTrade);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
@ApiOperation(value = "新增订单")
|
||||
public R<Object> add(@RequestBody OrderTrade orderTrade) {
|
||||
// 获取当前用户
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
if (userId == null) {
|
||||
return R.fail(HttpStatus.SHOW_ERROR_MSG,"用户未登录");
|
||||
}
|
||||
orderTrade.setUserId(userId);
|
||||
return R.ok(orderTradeService.insertMallProduct(orderTrade));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@ApiOperation(value = "修改订单")
|
||||
public R<Object> update(@RequestBody OrderTrade orderTrade) {
|
||||
// 获取当前用户
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
if (userId == null) {
|
||||
return R.fail(HttpStatus.SHOW_ERROR_MSG,"用户未登录");
|
||||
}
|
||||
orderTrade.setUserId(userId);
|
||||
orderTradeService.updateMallProduct(orderTrade);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping
|
||||
@ApiOperation(value = "删除订单")
|
||||
public R<Object> remove(@RequestBody IdsParam ids) {
|
||||
orderTradeService.deleteMallProductByIds(ids);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询交易状态
|
||||
*/
|
||||
@GetMapping("/queryTradeStatus")
|
||||
@ApiOperation(value = "查询交易状态")
|
||||
public R<Object> queryTradeStatus(@Valid @NotBlank(message = "订单号不能为空") String outTradeNo) throws Exception {
|
||||
return aliPayService.queryTradeStatus(outTradeNo);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 撤销交易
|
||||
*/
|
||||
// @GetMapping("/cancelTrade")
|
||||
// public AjaxResult cancelTrade(String outTradeNo) throws Exception {
|
||||
// // 关闭交易
|
||||
// AlipayTradeCancelResponse cancel = Factory.Payment.Common().cancel(outTradeNo);
|
||||
// if (cancel.getCode().equals("10000")) {
|
||||
// return AjaxResult.success("关闭成功");
|
||||
// }
|
||||
// return AjaxResult.error("关闭失败");
|
||||
//package com.mcwl.web.controller.pay.AliPay;
|
||||
//
|
||||
//import com.alipay.easysdk.factory.Factory;
|
||||
//import com.alipay.easysdk.kernel.Config;
|
||||
//import com.alipay.easysdk.payment.common.models.AlipayTradeCancelResponse;
|
||||
//import com.alipay.easysdk.payment.common.models.AlipayTradeCloseResponse;
|
||||
//import com.alipay.easysdk.payment.common.models.AlipayTradeQueryResponse;
|
||||
//import com.mcwl.common.JSONUtils;
|
||||
//import com.mcwl.common.constant.HttpStatus;
|
||||
//import com.mcwl.common.core.controller.BaseController;
|
||||
//import com.mcwl.common.core.domain.AjaxResult;
|
||||
//import com.mcwl.common.core.domain.R;
|
||||
//import com.mcwl.common.core.page.TableDataInfo;
|
||||
//import com.mcwl.common.core.redis.RedisCache;
|
||||
//import com.mcwl.common.domain.IdsParam;
|
||||
//import com.mcwl.common.utils.SecurityUtils;
|
||||
//import com.mcwl.pay.domain.OrderTrade;
|
||||
//import com.mcwl.pay.service.AliPayService;
|
||||
//import com.mcwl.pay.service.OrderTradeService;
|
||||
//import com.mcwl.resource.domain.dto.ProductRes;
|
||||
//import io.swagger.annotations.Api;
|
||||
//import io.swagger.annotations.ApiOperation;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.validation.annotation.Validated;
|
||||
//import org.springframework.web.bind.annotation.*;
|
||||
//
|
||||
//import javax.validation.Valid;
|
||||
//import javax.validation.constraints.NotBlank;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//
|
||||
///**
|
||||
// * @Author:ChenYan
|
||||
// * @Project:McWl
|
||||
// * @Package:com.mcwl.web.controller.pay
|
||||
// * @Filename:OrderTradeController
|
||||
// * @Description 支付模块
|
||||
// * @Date:2025/1/3 14:46
|
||||
// */
|
||||
//
|
||||
//@RestController
|
||||
//@RequestMapping("/order")
|
||||
//@Validated
|
||||
//@Api(tags = "订单模块")
|
||||
//public class OrderTradeController extends BaseController {
|
||||
//
|
||||
// @Autowired
|
||||
// private Config config;
|
||||
//
|
||||
// @Autowired
|
||||
// private OrderTradeService orderTradeService;
|
||||
//
|
||||
// @Autowired
|
||||
// private AliPayService aliPayService;
|
||||
//
|
||||
// @Autowired
|
||||
// private RedisCache redisCache;
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 购买产品
|
||||
// */
|
||||
// @PostMapping("/buy")
|
||||
// @ApiOperation(value = "购买产品")
|
||||
// public R<Object> buy(@Valid @RequestBody ProductRes productRes) throws Exception {
|
||||
// orderTradeService.productHandler(productRes);
|
||||
// return R.ok();
|
||||
// }
|
||||
|
||||
/**
|
||||
* 关闭交易
|
||||
*/
|
||||
// @GetMapping("/closeTrade")
|
||||
// public AjaxResult closeTrade(String outTradeNo) throws Exception {
|
||||
// // 关闭交易
|
||||
// AlipayTradeCloseResponse close = Factory.Payment.Common().close(outTradeNo);
|
||||
// if (close.getCode().equals("10000")) {
|
||||
// return AjaxResult.success("关闭成功");
|
||||
// }
|
||||
// return AjaxResult.error("关闭失败");
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 查询列表
|
||||
// */
|
||||
// @GetMapping("/list")
|
||||
// @ApiOperation(value = "查询订单列表")
|
||||
// public TableDataInfo list(OrderTrade orderTrade) {
|
||||
// startPage();
|
||||
// List<OrderTrade> list = orderTradeService.selectMallProductList(orderTrade);
|
||||
// return getDataTable(list);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
//
|
||||
// /**
|
||||
// * 新增
|
||||
// */
|
||||
// @PostMapping("/add")
|
||||
// @ApiOperation(value = "新增订单")
|
||||
// public R<Object> add(@RequestBody OrderTrade orderTrade) {
|
||||
// // 获取当前用户
|
||||
// Long userId = SecurityUtils.getUserId();
|
||||
// if (userId == null) {
|
||||
// return R.fail(HttpStatus.SHOW_ERROR_MSG,"用户未登录");
|
||||
// }
|
||||
// orderTrade.setUserId(userId);
|
||||
// return R.ok(orderTradeService.insertMallProduct(orderTrade));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 修改
|
||||
// */
|
||||
// @PostMapping("/update")
|
||||
// @ApiOperation(value = "修改订单")
|
||||
// public R<Object> update(@RequestBody OrderTrade orderTrade) {
|
||||
// // 获取当前用户
|
||||
// Long userId = SecurityUtils.getUserId();
|
||||
// if (userId == null) {
|
||||
// return R.fail(HttpStatus.SHOW_ERROR_MSG,"用户未登录");
|
||||
// }
|
||||
// orderTrade.setUserId(userId);
|
||||
// orderTradeService.updateMallProduct(orderTrade);
|
||||
// return R.ok();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 删除
|
||||
// */
|
||||
// @PostMapping
|
||||
// @ApiOperation(value = "删除订单")
|
||||
// public R<Object> remove(@RequestBody IdsParam ids) {
|
||||
// orderTradeService.deleteMallProductByIds(ids);
|
||||
// return R.ok();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 查询交易状态
|
||||
// */
|
||||
// @GetMapping("/queryTradeStatus")
|
||||
// @ApiOperation(value = "查询交易状态")
|
||||
// public R<Object> queryTradeStatus(@Valid @NotBlank(message = "订单号不能为空") String outTradeNo) throws Exception {
|
||||
// return aliPayService.queryTradeStatus(outTradeNo);
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 撤销交易
|
||||
// */
|
||||
//// @GetMapping("/cancelTrade")
|
||||
//// public AjaxResult cancelTrade(String outTradeNo) throws Exception {
|
||||
//// // 关闭交易
|
||||
//// AlipayTradeCancelResponse cancel = Factory.Payment.Common().cancel(outTradeNo);
|
||||
//// if (cancel.getCode().equals("10000")) {
|
||||
//// return AjaxResult.success("关闭成功");
|
||||
//// }
|
||||
//// return AjaxResult.error("关闭失败");
|
||||
//// }
|
||||
//
|
||||
// /**
|
||||
// * 关闭交易
|
||||
// */
|
||||
//// @GetMapping("/closeTrade")
|
||||
//// public AjaxResult closeTrade(String outTradeNo) throws Exception {
|
||||
//// // 关闭交易
|
||||
//// AlipayTradeCloseResponse close = Factory.Payment.Common().close(outTradeNo);
|
||||
//// if (close.getCode().equals("10000")) {
|
||||
//// return AjaxResult.success("关闭成功");
|
||||
//// }
|
||||
//// return AjaxResult.error("关闭失败");
|
||||
//// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -78,10 +78,11 @@ spring:
|
|||
multi-statement-allow: true
|
||||
# redis 配置
|
||||
redis:
|
||||
# 地址
|
||||
host: 1.13.246.108
|
||||
# 地址 旧测试环境
|
||||
# host: 113.45.9.111
|
||||
host: 113.45.190.154
|
||||
# 端口,默认为6379
|
||||
port: 6370
|
||||
port: 6379
|
||||
# 数据库索引
|
||||
database: 0
|
||||
# 密码
|
||||
|
@ -98,7 +99,6 @@ spring:
|
|||
max-active: 1000
|
||||
# #连接池最大阻塞等待时间(使用负值表示没有限制)
|
||||
max-wait: -1ms
|
||||
time-between-eviction-runs: 6000
|
||||
|
||||
|
||||
# token配置
|
||||
|
@ -117,7 +117,7 @@ wechat:
|
|||
# 应用密钥
|
||||
secret: 11218568b79e2c5eb10459ef8c0374bd
|
||||
|
||||
#公众号配置
|
||||
#公众号配置
|
||||
#wechat:
|
||||
# # 应用ID
|
||||
# appid: wx82d4c3c96f0ffa5b
|
||||
|
@ -144,12 +144,12 @@ mall:
|
|||
appId: 9021000135682614
|
||||
# 沙箱应用私钥
|
||||
privateKey: MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCQxmQGcaiKjOhayWi+zNTvpp8B5YT8jFFkjLzrD+W+T2Dwf2GfFR4p95zsCJxYeoLWdghMPA6/GMFrLbuVFpaEjuTm4icqA9N8n5d3W0j7gh+wMjZoqyJclAIeb09ut7rY6mWzilA9kWmZnUG7MOWIU70RVRYrfJectCFw/odM9lG4XIVe13X2h+1ecTQyQzLWmnvKFCfo7dQjE7fIYiWfud1ZGUneNs3u73pNWMB6ThGTTCbs0atcgM3fYOg3q7fTxIu9VcaUCJiJ/kNbL9sVEyOrSyx2f2o6w06zdEaOiQFsuDeS8QPYGMg7pf42wAfqCO6hqxQiQT5vp1hvB0o1AgMBAAECggEAIhaEYLwMSispXo8D2cES9iaOU/z91hUX6Qv2Q4anuqqoEZh8nN91Db6etTjFz1NxURvTklelxTsH97t56n26DRY0MWTYgd0Kw9Iz8MeOpKGb4nnAM97vpUq4QQBGfLRIC2ENdzu+7vA5JBFR88hsky/cWaNmJ/EbJauIIDneE7GigMR2HF7kfzdZzOBN4ZEh/ef5NKeCnEieRJJhWRgrgNXVZ44Tqi67AM7ey9pyUtBe7fgzxXtrWXBN9yKaVxxSXm3KJXFQqA6mcilFVZaxMNlAySc4MPTW8lq0ozOCOCunoeIphNz/OVIxGu3/voXFXlBfOKqOkYMVZxMY6OrvtQKBgQD0nIlXK4VW72VaGpz9kxQkRNzJV/yqaqet1GOSlPM2l0RCRFOVVdnvbQdHGPe6+HxHL1dh5MP8T/aHoP+4UXkkQCc8moS2FZxJvFH2QTSZBcSSdGL7GMpROqs38J+XlJzrhNcB20lrW6D7yMeQa4YEcXwdbD8Er/YaIqODBWYYewKBgQCXg+16RLDArciwwhf0TBWZPor2iYFDdwU5UPu7CKOhU1MLfQhG85gGpXHjB6G8cMUi/ezxh/FEl+sWOZegpkPwL5/BQS9tNYWIaC4kipPF/a5Up4DMYUHVAuuPwNqqXpvgU+rGjCns0wtPRnjrkghLkc3oTSID7o7pzUwIk2whDwKBgAys3+EIfExY82OL5X6uVGjcuKQmTw11oWK8krxRw5iclgjpCXu/ix+BAtOIU634mlgF9/02oYE9k4TLrvSaJDDgsifNyfq1e/fGLmkYT+VuCxWbulVQn4s+AwlPCrYMGWWK6KlL9638fYcOjGjLaZJpXwkXRtyzUYlhKh/r87JpAoGBAIavRp2mi/xrPvgpQQPv0k9L8llfOCHRnjoqC+thrZsNp8eRmJcBmMVnskofEZ2iHQuS71pw/n58EQTLo0ayJbhPjVJL8K3CovXzrfjbmqqoa5xi3bJQTiXdF6rMw1QpD6Uk05E1LVuQ6v/IZFr7kBYlAQWb8z3NhQq+bPU+nyLvAoGAGpBbSM8gPzdWQqkHoos0icu3cj0GhN3MU7+1Eb/rsXyh/lk5wtZTEnHjwhdUOUtwVNjvrv7CzA7unhOoaM6YcE/Zpd4zt8pjqH1Mhds7UHf4Xg+A+J4G6meYnhSwfBpOub02ncsqfBlXE0qhFv6AvcMewWndyLb8EYaUUXTYkG0=
|
||||
# 沙箱应用公钥证书
|
||||
appCertPath: /opt/cert/dev/appPublicCert.crt
|
||||
# 沙箱支付宝公钥证书路径
|
||||
alipayCertPath: /opt/cert/dev/alipayPublicCert.crt
|
||||
# 沙箱支付宝根证书路径
|
||||
alipayRootCertPath: /opt/cert/dev/alipayRootCert.crt
|
||||
# # 线上应用公钥证书
|
||||
# appCertPath: /opt/cert/pro/appCertPublicKey_2021005119630093.crt
|
||||
# # 线上支付宝公钥证书路径
|
||||
# alipayCertPath: /opt/cert/pro/alipayCertPublicKey_RSA2.crt
|
||||
# # 线上支付宝根证书路径
|
||||
# alipayRootCertPath: /opt/cert/pro/alipayRootCert.crt
|
||||
# # 沙箱应用公钥证书
|
||||
# appCertPath: D:\workspace\mochuang\mcwl-ai\mcwl-admin\src\main\resources\cert\dev\alipayPublicCert.crt
|
||||
# # 沙箱支付宝公钥证书路径
|
||||
|
@ -170,4 +170,11 @@ huawei:
|
|||
upload:
|
||||
endPoint: obs.cn-south-1.myhuaweicloud.com
|
||||
|
||||
mqtt:
|
||||
broker-url: tcp://192.168.136.128:1883
|
||||
client-id-prefix: emqx-client
|
||||
connection-timeout: 30
|
||||
keep-alive-interval: 60
|
||||
max-reconnect-attempts: 5
|
||||
clean-session: true
|
||||
|
||||
|
|
|
@ -157,4 +157,11 @@ huawei:
|
|||
upload:
|
||||
endPoint: obs.cn-south-1.myhuaweicloud.com
|
||||
|
||||
mqtt:
|
||||
broker-url: tcp://192.168.136.128:1883
|
||||
client-id-prefix: emqx-client
|
||||
connection-timeout: 30
|
||||
keep-alive-interval: 60
|
||||
max-reconnect-attempts: 5
|
||||
clean-session: true
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.mcwl.framework.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
@ -24,6 +25,16 @@ import java.time.Duration;
|
|||
@EnableCaching
|
||||
public class RedisConfig extends CachingConfigurerSupport
|
||||
{
|
||||
|
||||
@Value("${spring.redis.host}")
|
||||
private String host;
|
||||
|
||||
@Value("${spring.redis.port}")
|
||||
private int port;
|
||||
|
||||
@Value("${spring.redis.password}")
|
||||
private String password;
|
||||
|
||||
@Bean
|
||||
@SuppressWarnings(value = { "unchecked", "rawtypes" })
|
||||
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory)
|
||||
|
@ -80,8 +91,8 @@ public class RedisConfig extends CachingConfigurerSupport
|
|||
*/
|
||||
@Bean
|
||||
public LettuceConnectionFactory redisConnectionFactory() {
|
||||
RedisStandaloneConfiguration standaloneConfig = new RedisStandaloneConfiguration("1.13.246.108", 6370);
|
||||
standaloneConfig.setPassword(RedisPassword.of("MuYu_Cloud@Redis"));
|
||||
RedisStandaloneConfiguration standaloneConfig = new RedisStandaloneConfiguration(host, port);
|
||||
standaloneConfig.setPassword(RedisPassword.of(password));
|
||||
|
||||
LettuceClientConfiguration lettuceClientConfig = LettuceClientConfiguration.builder()
|
||||
.commandTimeout(Duration.ofSeconds(10))
|
||||
|
|
|
@ -30,8 +30,10 @@ public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, S
|
|||
throws IOException
|
||||
{
|
||||
int code = HttpStatus.UNAUTHORIZED;
|
||||
if (e.getCause() instanceof RedisCommandTimeoutException) {
|
||||
ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.warn("网络超时,请检查网络稍后重试")));
|
||||
if (e.getCause() != null) {
|
||||
if (e.getCause() instanceof RedisCommandTimeoutException) {
|
||||
ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.warn("网络超时,请检查网络稍后重试")));
|
||||
}
|
||||
}
|
||||
String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI());
|
||||
ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg)));
|
||||
|
|
|
@ -94,7 +94,7 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> impleme
|
|||
// 设置会员开始时间和结束时间
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(endDate);
|
||||
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
||||
// calendar.add(Calendar.DAY_OF_MONTH, 1);
|
||||
member.setStartDate(calendar.getTime());
|
||||
member.setEndDate(this.getEndDate(memberLevel.getSubscriptionPeriod(), calendar));
|
||||
} else {
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
package com.mcwl.pay.config;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@Component
|
||||
public class AliConfig {
|
||||
@Value("${mall.mgt.aliPayConfig.protocol}")
|
||||
private String protocol;
|
||||
@Value("${mall.mgt.aliPayConfig.gatewayHost}")
|
||||
private String gatewayHost;
|
||||
@Value("${mall.mgt.aliPayConfig.signType}")
|
||||
private String signType;
|
||||
@Value("${mall.mgt.aliPayConfig.appId}")
|
||||
private String appId;
|
||||
@Value("${mall.mgt.aliPayConfig.privateKey}")
|
||||
private String privateKey;
|
||||
@Value("${mall.mgt.aliPayConfig.appCertPath}")
|
||||
private String appCertPath;
|
||||
@Value("${mall.mgt.aliPayConfig.alipayCertPath}")
|
||||
private String alipayCertPath;
|
||||
@Value("${mall.mgt.aliPayConfig.alipayRootCertPath}")
|
||||
private String alipayRootCertPath;
|
||||
@Value("${mall.mgt.aliPayConfig.gatewayUrl}")
|
||||
private String gatewayUrl;
|
||||
@Value("${mall.mgt.aliPayConfig.notifyUrl}")
|
||||
private String notifyUrl;
|
||||
}
|
||||
//package com.mcwl.pay.config;
|
||||
//
|
||||
//
|
||||
//import lombok.Data;
|
||||
//import org.springframework.beans.factory.annotation.Value;
|
||||
//import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//@Data
|
||||
//@Configuration
|
||||
//@Component
|
||||
//public class AliConfig {
|
||||
// @Value("${mall.mgt.aliPayConfig.protocol}")
|
||||
// private String protocol;
|
||||
// @Value("${mall.mgt.aliPayConfig.gatewayHost}")
|
||||
// private String gatewayHost;
|
||||
// @Value("${mall.mgt.aliPayConfig.signType}")
|
||||
// private String signType;
|
||||
// @Value("${mall.mgt.aliPayConfig.appId}")
|
||||
// private String appId;
|
||||
// @Value("${mall.mgt.aliPayConfig.privateKey}")
|
||||
// private String privateKey;
|
||||
// @Value("${mall.mgt.aliPayConfig.appCertPath}")
|
||||
// private String appCertPath;
|
||||
// @Value("${mall.mgt.aliPayConfig.alipayCertPath}")
|
||||
// private String alipayCertPath;
|
||||
// @Value("${mall.mgt.aliPayConfig.alipayRootCertPath}")
|
||||
// private String alipayRootCertPath;
|
||||
// @Value("${mall.mgt.aliPayConfig.gatewayUrl}")
|
||||
// private String gatewayUrl;
|
||||
// @Value("${mall.mgt.aliPayConfig.notifyUrl}")
|
||||
// private String notifyUrl;
|
||||
//}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
package com.mcwl.pay.service;
|
||||
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.common.core.domain.R;
|
||||
import com.mcwl.pay.domain.OrderTradeDto;
|
||||
import com.mcwl.pay.domain.vo.PayVo;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
public interface AliPayService {
|
||||
String bindingCallback(String authCode, String state) throws FileNotFoundException;
|
||||
|
||||
PayVo memberPay(OrderTradeDto orderTradeDto) throws Exception;
|
||||
|
||||
PayVo pointsPay(Double paymentAmount) throws Exception;
|
||||
|
||||
R<String> fetch(String amount) throws AlipayApiException, FileNotFoundException;
|
||||
|
||||
// 查询订单状态
|
||||
R<Object> queryTradeStatus(String outTradeNo) throws Exception;
|
||||
|
||||
PayVo walletPay(Double amount) throws Exception;
|
||||
|
||||
R<Object> queryBindStatus();
|
||||
}
|
||||
//package com.mcwl.pay.service;
|
||||
//
|
||||
//import com.alipay.api.AlipayApiException;
|
||||
//import com.mcwl.common.core.domain.AjaxResult;
|
||||
//import com.mcwl.common.core.domain.R;
|
||||
//import com.mcwl.pay.domain.OrderTradeDto;
|
||||
//import com.mcwl.pay.domain.vo.PayVo;
|
||||
//
|
||||
//import javax.validation.constraints.NotNull;
|
||||
//import java.io.FileNotFoundException;
|
||||
//
|
||||
//public interface AliPayService {
|
||||
// String bindingCallback(String authCode, String state) throws FileNotFoundException;
|
||||
//
|
||||
// PayVo memberPay(OrderTradeDto orderTradeDto) throws Exception;
|
||||
//
|
||||
// PayVo pointsPay(Double paymentAmount) throws Exception;
|
||||
//
|
||||
// R<String> fetch(String amount) throws AlipayApiException, FileNotFoundException;
|
||||
//
|
||||
// // 查询订单状态
|
||||
// R<Object> queryTradeStatus(String outTradeNo) throws Exception;
|
||||
//
|
||||
// PayVo walletPay(Double amount) throws Exception;
|
||||
//
|
||||
// R<Object> queryBindStatus();
|
||||
//}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,45 +1,45 @@
|
|||
package com.mcwl.pay.task;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.mcwl.common.constant.QueueConstants;
|
||||
import com.mcwl.memberCenter.domain.Member;
|
||||
import com.mcwl.pay.domain.OrderTrade;
|
||||
import com.mcwl.pay.service.AliPayService;
|
||||
import com.mcwl.pay.service.OrderTradeService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.joda.time.LocalDateTime;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Component("payTask")
|
||||
@RequiredArgsConstructor
|
||||
public class PayTask {
|
||||
|
||||
private final OrderTradeService orderTradeService;
|
||||
|
||||
|
||||
/**
|
||||
* 删除失效订单 间隔1h检查 0 0 0/1 * * ?
|
||||
*/
|
||||
public void deleteInvalidOrderTask() {
|
||||
|
||||
Date date = LocalDateTime.now().plusMinutes(-15).toDate();
|
||||
|
||||
List<OrderTrade> orderTradeList = orderTradeService.lambdaQuery()
|
||||
.le(OrderTrade::getCreateTime, date)
|
||||
.and(wrapper -> wrapper
|
||||
.eq(OrderTrade::getOrderStatus, 4)
|
||||
.or()
|
||||
.eq(OrderTrade::getPayStatus, 1)
|
||||
)
|
||||
.list();
|
||||
|
||||
orderTradeService.removeBatchByIds(orderTradeList);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//package com.mcwl.pay.task;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
//import com.mcwl.common.constant.QueueConstants;
|
||||
//import com.mcwl.memberCenter.domain.Member;
|
||||
//import com.mcwl.pay.domain.OrderTrade;
|
||||
//import com.mcwl.pay.service.AliPayService;
|
||||
//import com.mcwl.pay.service.OrderTradeService;
|
||||
//import lombok.RequiredArgsConstructor;
|
||||
//import org.joda.time.LocalDateTime;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.util.Date;
|
||||
//import java.util.List;
|
||||
//import java.util.function.Consumer;
|
||||
//
|
||||
//@Component("payTask")
|
||||
//@RequiredArgsConstructor
|
||||
//public class PayTask {
|
||||
//
|
||||
// private final OrderTradeService orderTradeService;
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 删除失效订单 间隔1h检查 0 0 0/1 * * ?
|
||||
// */
|
||||
// public void deleteInvalidOrderTask() {
|
||||
//
|
||||
// Date date = LocalDateTime.now().plusMinutes(-15).toDate();
|
||||
//
|
||||
// List<OrderTrade> orderTradeList = orderTradeService.lambdaQuery()
|
||||
// .le(OrderTrade::getCreateTime, date)
|
||||
// .and(wrapper -> wrapper
|
||||
// .eq(OrderTrade::getOrderStatus, 4)
|
||||
// .or()
|
||||
// .eq(OrderTrade::getPayStatus, 1)
|
||||
// )
|
||||
// .list();
|
||||
//
|
||||
// orderTradeService.removeBatchByIds(orderTradeList);
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -39,5 +39,11 @@
|
|||
<version>3.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.2.2</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -45,6 +45,11 @@ public class ModelImageLikeVo {
|
|||
*/
|
||||
@ApiModelProperty(value = "点赞数")
|
||||
private Integer likeNum;
|
||||
/**
|
||||
* 下载数
|
||||
*/
|
||||
@ApiModelProperty(value = "下载数")
|
||||
private Long downloadNumber;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -42,6 +42,12 @@ public class ModelLikeVo {
|
|||
*/
|
||||
@ApiModelProperty(value = "封面图")
|
||||
private String surfaceUrl;
|
||||
/**
|
||||
* 下载数
|
||||
*/
|
||||
@ApiModelProperty(value = "下载数")
|
||||
private Long downloadNumber;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -42,6 +42,12 @@ public class WorkFlowLikeVo {
|
|||
*/
|
||||
@ApiModelProperty(value = "点赞数")
|
||||
private Integer likeNum;
|
||||
/**
|
||||
* 下载数
|
||||
*/
|
||||
@ApiModelProperty(value = "下载数")
|
||||
private Long downloadNumber;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package com.mcwl.resource.handler;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public interface IMessageHandler {
|
||||
void handleMessage(String topic, MqttMessage message);
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Topic {
|
||||
String value();
|
||||
int qos() default 1;
|
||||
}
|
||||
|
||||
default List<TopicSubscription> getTopics() {
|
||||
Topic annotation = this.getClass().getAnnotation(Topic.class);
|
||||
if (annotation != null) {
|
||||
return Collections.singletonList(
|
||||
new TopicSubscription(annotation.value(), annotation.qos())
|
||||
);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
class TopicSubscription {
|
||||
private String topicFilter;
|
||||
private int qos;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
package com.mcwl.resource.handler.impl;
|
||||
|
||||
import cn.hutool.json.JSON;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.resource.domain.ModelImageComment;
|
||||
import com.mcwl.resource.domain.ModelImageCommentLike;
|
||||
import com.mcwl.resource.domain.SysAdvice;
|
||||
import com.mcwl.resource.handler.IMessageHandler;
|
||||
import com.mcwl.resource.mapper.ModelImageCommentLikeMapper;
|
||||
import com.mcwl.resource.mapper.ModelImageCommentMapper;
|
||||
import com.mcwl.resource.mapper.WorkFlowCommentLikeMapper;
|
||||
import com.mcwl.resource.mapper.WorkFlowCommentMapper;
|
||||
import com.mcwl.resource.service.ISysAdviceService;
|
||||
import com.mcwl.system.domain.enums.AdviceEnum;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@IMessageHandler.Topic(value = "imageCommentLike/#", qos = 1)
|
||||
@RequiredArgsConstructor
|
||||
public class ImageCommentLikeHandler implements IMessageHandler {
|
||||
|
||||
private final ModelImageCommentMapper modelImageCommentMapper;
|
||||
|
||||
private final ModelImageCommentLikeMapper modelImageCommentLikeMapper;
|
||||
|
||||
private final ISysUserService userService;
|
||||
|
||||
private final ISysAdviceService adviceService;
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void handleMessage(String topic, MqttMessage message) {
|
||||
String payload = new String(message.getPayload());
|
||||
log.info("图片评论点赞: {} - {}", payload, message);
|
||||
|
||||
JSON parse = JSONUtil.parse(payload);
|
||||
Long commentId = Long.parseLong(parse.getByPath("commentId").toString());
|
||||
Long userId = Long.parseLong(parse.getByPath("userId").toString());
|
||||
|
||||
|
||||
|
||||
this.like(userId, commentId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void like(Long userId, Long commentId) {
|
||||
ModelImageComment modelImageComment = modelImageCommentMapper.selectById(commentId);
|
||||
if (Objects.isNull(modelImageComment)) {
|
||||
throw new ServiceException("该评论不存在");
|
||||
}
|
||||
ModelImageCommentLike modelImageCommentLike = modelImageCommentLikeMapper.getLikeImageComment(userId, commentId);
|
||||
if (Objects.nonNull(modelImageCommentLike)) {
|
||||
if (Objects.equals(modelImageCommentLike.getDelFlag(), "0")) {
|
||||
modelImageCommentLike.setDelFlag("2");
|
||||
int likeNum = modelImageComment.getLikeNum() - 1;
|
||||
likeNum = Math.max(likeNum, 0);
|
||||
modelImageComment.setLikeNum(likeNum);
|
||||
} else {
|
||||
modelImageCommentLike.setDelFlag("0");
|
||||
modelImageComment.setLikeNum(modelImageComment.getLikeNum() + 1);
|
||||
this.addLikeAdvice(modelImageComment, userId);
|
||||
}
|
||||
// 更新点赞记录
|
||||
modelImageCommentLikeMapper.updateDelFlagById(modelImageCommentLike);
|
||||
// 更新图片评论点赞数
|
||||
modelImageCommentMapper.updateById(modelImageComment);
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加点赞记录
|
||||
modelImageCommentLike = new ModelImageCommentLike();
|
||||
modelImageCommentLike.setUserId(userId);
|
||||
modelImageCommentLike.setModelImageCommentId(commentId);
|
||||
modelImageCommentLikeMapper.insert(modelImageCommentLike);
|
||||
|
||||
// 更新图片点赞数
|
||||
modelImageComment.setLikeNum(modelImageComment.getLikeNum() + 1);
|
||||
modelImageCommentMapper.updateById(modelImageComment);
|
||||
|
||||
this.addLikeAdvice(modelImageComment, userId);
|
||||
}
|
||||
|
||||
|
||||
private void addLikeAdvice(ModelImageComment modelImageComment, Long userId) {
|
||||
|
||||
Long receiverUserId = modelImageComment.getUserId();
|
||||
|
||||
if (Objects.equals(userId, receiverUserId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SysUser sysUser = userService.selectUserById(userId);
|
||||
|
||||
String content = StringUtils.format("恭喜!{}点赞了您的评论",
|
||||
sysUser.getNickName());
|
||||
|
||||
SysAdvice sysAdvice = new SysAdvice();
|
||||
sysAdvice.setSenderId(userId);
|
||||
sysAdvice.setReceiverId(receiverUserId);
|
||||
sysAdvice.setContent(content);
|
||||
sysAdvice.setProductId(modelImageComment.getModelImageId());
|
||||
sysAdvice.setProductType(2);
|
||||
sysAdvice.setCommentId(modelImageComment.getId());
|
||||
sysAdvice.setIsRead(0);
|
||||
sysAdvice.setType(AdviceEnum.LIKE_REMIND);
|
||||
adviceService.save(sysAdvice);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
package com.mcwl.resource.handler.impl;
|
||||
|
||||
import cn.hutool.json.JSON;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.resource.domain.ModelImage;
|
||||
import com.mcwl.resource.domain.ModelImageLike;
|
||||
import com.mcwl.resource.domain.SysAdvice;
|
||||
import com.mcwl.resource.handler.IMessageHandler;
|
||||
import com.mcwl.resource.mapper.ModelImageLikeMapper;
|
||||
import com.mcwl.resource.mapper.ModelImageMapper;
|
||||
import com.mcwl.resource.mapper.WorkFlowLikeMapper;
|
||||
import com.mcwl.resource.mapper.WorkFlowMapper;
|
||||
import com.mcwl.resource.service.ISysAdviceService;
|
||||
import com.mcwl.system.domain.enums.AdviceEnum;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@IMessageHandler.Topic(value = "imageLike/#", qos = 1)
|
||||
@RequiredArgsConstructor
|
||||
public class ImageLikeHandler implements IMessageHandler {
|
||||
|
||||
|
||||
private final ModelImageMapper modelImageMapper;
|
||||
|
||||
private final ModelImageLikeMapper modelImageLikeMapper;
|
||||
|
||||
private final ISysUserService userService;
|
||||
|
||||
private final ISysAdviceService adviceService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void handleMessage(String topic, MqttMessage message) {
|
||||
String payload = new String(message.getPayload());
|
||||
log.info("图片点赞: {}", payload);
|
||||
|
||||
JSON parse = JSONUtil.parse(payload);
|
||||
Long commentId = Long.parseLong(parse.getByPath("commentId").toString());
|
||||
Long userId = Long.parseLong(parse.getByPath("userId").toString());
|
||||
|
||||
this.like(userId, commentId);
|
||||
}
|
||||
|
||||
private void like(Long userId, Long imageId) {
|
||||
ModelImage modelImage = modelImageMapper.selectById(imageId);
|
||||
if (Objects.isNull(modelImage)) {
|
||||
throw new ServiceException("该图片不存在或已下架");
|
||||
}
|
||||
ModelImageLike modelImageLike = modelImageLikeMapper.getLikeImage(userId, imageId);
|
||||
if (Objects.nonNull(modelImageLike)) {
|
||||
if (Objects.equals(modelImageLike.getDelFlag(), "0")) {
|
||||
modelImageLike.setDelFlag("2");
|
||||
int likeNum = modelImage.getLikeNum() - 1;
|
||||
likeNum = Math.max(likeNum, 0);
|
||||
modelImage.setLikeNum(likeNum);
|
||||
} else {
|
||||
modelImageLike.setDelFlag("0");
|
||||
modelImage.setLikeNum(modelImage.getLikeNum() + 1);
|
||||
this.addLikeAdvice(modelImage, userId);
|
||||
}
|
||||
// 更新点赞记录
|
||||
modelImageLikeMapper.updateDelFlagById(modelImageLike);
|
||||
// 更新图片点赞数
|
||||
modelImageMapper.updateById(modelImage);
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加点赞记录
|
||||
modelImageLike = new ModelImageLike();
|
||||
modelImageLike.setUserId(userId);
|
||||
modelImageLike.setModelImageId(imageId);
|
||||
modelImageLikeMapper.insert(modelImageLike);
|
||||
|
||||
// 更新图片点赞数
|
||||
modelImage.setLikeNum(modelImage.getLikeNum() + 1);
|
||||
modelImageMapper.updateById(modelImage);
|
||||
|
||||
this.addLikeAdvice(modelImage, userId);
|
||||
}
|
||||
|
||||
|
||||
private void addLikeAdvice(ModelImage modelImage, Long userId) {
|
||||
|
||||
Long receiverUserId = modelImage.getUserId();
|
||||
|
||||
if (Objects.equals(userId, receiverUserId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SysUser sysUser = userService.selectUserById(userId);
|
||||
|
||||
|
||||
String content = StringUtils.format("恭喜!{}点赞了您的图片:{}",
|
||||
sysUser.getNickName(), modelImage.getTitle());
|
||||
|
||||
SysAdvice sysAdvice = new SysAdvice();
|
||||
sysAdvice.setSenderId(userId);
|
||||
sysAdvice.setReceiverId(receiverUserId);
|
||||
sysAdvice.setContent(content);
|
||||
sysAdvice.setProductId(modelImage.getId());
|
||||
sysAdvice.setProductType(2);
|
||||
sysAdvice.setIsRead(0);
|
||||
sysAdvice.setType(AdviceEnum.LIKE_REMIND);
|
||||
adviceService.save(sysAdvice);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
package com.mcwl.resource.handler.impl;
|
||||
|
||||
import cn.hutool.json.JSON;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.resource.domain.*;
|
||||
import com.mcwl.resource.handler.IMessageHandler;
|
||||
import com.mcwl.resource.mapper.ModelCommentLikeMapper;
|
||||
import com.mcwl.resource.mapper.ModelCommentMapper;
|
||||
import com.mcwl.resource.mapper.WorkFlowCommentLikeMapper;
|
||||
import com.mcwl.resource.mapper.WorkFlowCommentMapper;
|
||||
import com.mcwl.resource.service.ISysAdviceService;
|
||||
import com.mcwl.system.domain.enums.AdviceEnum;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@IMessageHandler.Topic(value = "modelCommentLike/#", qos = 1)
|
||||
@RequiredArgsConstructor
|
||||
public class ModelCommentLikeHandler implements IMessageHandler {
|
||||
|
||||
|
||||
private final ModelCommentMapper modelCommentMapper;
|
||||
|
||||
private final ModelCommentLikeMapper modelCommentLikeMapper;
|
||||
|
||||
private final ISysUserService userService;
|
||||
|
||||
private final ISysAdviceService adviceService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void handleMessage(String topic, MqttMessage message) {
|
||||
String payload = new String(message.getPayload());
|
||||
log.info("模型评论点赞: {} - {}", payload, message);
|
||||
|
||||
JSON parse = JSONUtil.parse(payload);
|
||||
Long commentId = Long.parseLong(parse.getByPath("commentId").toString());
|
||||
Long userId = Long.parseLong(parse.getByPath("userId").toString());
|
||||
|
||||
|
||||
this.like(userId, commentId);
|
||||
}
|
||||
|
||||
private void like(Long userId, Long commentId) {
|
||||
ModelComment modelComment = modelCommentMapper.selectById(commentId);
|
||||
if (Objects.isNull(modelComment)) {
|
||||
throw new ServiceException("该评论不存在");
|
||||
}
|
||||
ModelCommentLike modelCommentLike = modelCommentLikeMapper.getLikeComment(userId, commentId);
|
||||
if (Objects.nonNull(modelCommentLike)) {
|
||||
if (Objects.equals(modelCommentLike.getDelFlag(), "0")) {
|
||||
modelCommentLike.setDelFlag("2");
|
||||
int likeNum = modelComment.getLikeNum() - 1;
|
||||
likeNum = Math.max(likeNum, 0);
|
||||
modelComment.setLikeNum(likeNum);
|
||||
} else {
|
||||
modelCommentLike.setDelFlag("0");
|
||||
modelComment.setLikeNum(modelComment.getLikeNum() + 1);
|
||||
this.addLikeAdvice(modelComment, userId);
|
||||
}
|
||||
// 更新点赞记录
|
||||
modelCommentLikeMapper.updateDelFlagById(modelCommentLike);
|
||||
// 更新图片评论点赞数
|
||||
modelCommentMapper.updateById(modelComment);
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加点赞记录
|
||||
modelCommentLike = new ModelCommentLike();
|
||||
modelCommentLike.setUserId(userId);
|
||||
modelCommentLike.setModelCommentId(commentId);
|
||||
modelCommentLikeMapper.insert(modelCommentLike);
|
||||
|
||||
// 更新模型点赞数
|
||||
modelComment.setLikeNum(modelComment.getLikeNum() + 1);
|
||||
modelCommentMapper.updateById(modelComment);
|
||||
|
||||
this.addLikeAdvice(modelComment, userId);
|
||||
}
|
||||
|
||||
|
||||
private void addLikeAdvice(ModelComment modelComment, Long userId) {
|
||||
|
||||
Long receiverUserId = modelComment.getUserId();
|
||||
|
||||
if (Objects.equals(userId, receiverUserId)) {
|
||||
return;
|
||||
}
|
||||
SysUser sysUser = userService.selectUserById(userId);
|
||||
|
||||
String content = StringUtils.format("恭喜!{}点赞了您的评论",
|
||||
sysUser.getNickName());
|
||||
|
||||
SysAdvice sysAdvice = new SysAdvice();
|
||||
sysAdvice.setSenderId(userId);
|
||||
sysAdvice.setReceiverId(receiverUserId);
|
||||
sysAdvice.setContent(content);
|
||||
sysAdvice.setProductId(modelComment.getModelId());
|
||||
sysAdvice.setProductType(0);
|
||||
sysAdvice.setCommentId(modelComment.getId());
|
||||
sysAdvice.setIsRead(0);
|
||||
sysAdvice.setType(AdviceEnum.LIKE_REMIND);
|
||||
adviceService.save(sysAdvice);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
package com.mcwl.resource.handler.impl;
|
||||
|
||||
import cn.hutool.json.JSON;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.resource.domain.*;
|
||||
import com.mcwl.resource.handler.IMessageHandler;
|
||||
import com.mcwl.resource.mapper.ModelLikeMapper;
|
||||
import com.mcwl.resource.mapper.ModelMapper;
|
||||
import com.mcwl.resource.mapper.WorkFlowLikeMapper;
|
||||
import com.mcwl.resource.mapper.WorkFlowMapper;
|
||||
import com.mcwl.resource.service.ISysAdviceService;
|
||||
import com.mcwl.system.domain.enums.AdviceEnum;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@IMessageHandler.Topic(value = "modelLike/#", qos = 1)
|
||||
@RequiredArgsConstructor
|
||||
public class ModelLikeHandler implements IMessageHandler {
|
||||
|
||||
private final ModelMapper modelMapper;
|
||||
|
||||
|
||||
private final ModelLikeMapper modelLikeMapper;
|
||||
|
||||
private final ISysUserService userService;
|
||||
|
||||
private final ISysAdviceService adviceService;
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void handleMessage(String topic, MqttMessage message) {
|
||||
String payload = new String(message.getPayload());
|
||||
log.info("模型点赞: {}", payload);
|
||||
|
||||
JSON parse = JSONUtil.parse(payload);
|
||||
Long commentId = Long.parseLong(parse.getByPath("commentId").toString());
|
||||
Long userId = Long.parseLong(parse.getByPath("userId").toString());
|
||||
|
||||
|
||||
this.like(userId, commentId);
|
||||
}
|
||||
|
||||
private void like(Long userId, Long modelId) {
|
||||
ModelProduct model = modelMapper.selectById(modelId);
|
||||
if (Objects.isNull(model)) {
|
||||
throw new ServiceException("该模型不存在或已下架");
|
||||
}
|
||||
ModelLike modelLike = modelLikeMapper.getLike(userId, modelId);
|
||||
if (Objects.nonNull(modelLike)) {
|
||||
if (Objects.equals(modelLike.getDelFlag(), "0")) {
|
||||
modelLike.setDelFlag("2");
|
||||
int likeNum = model.getLikeNum() - 1;
|
||||
likeNum = Math.max(likeNum, 0);
|
||||
model.setLikeNum(likeNum);
|
||||
} else {
|
||||
modelLike.setDelFlag("0");
|
||||
model.setLikeNum(model.getLikeNum() + 1);
|
||||
this.addLikeAdvice(model, userId);
|
||||
}
|
||||
// 更新点赞记录
|
||||
modelLikeMapper.updateDelFlagById(modelLike);
|
||||
// 更新图片点赞数
|
||||
modelMapper.updateById(model);
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加点赞记录
|
||||
modelLike = new ModelLike();
|
||||
modelLike.setUserId(userId);
|
||||
modelLike.setModelId(modelId);
|
||||
modelLikeMapper.insert(modelLike);
|
||||
|
||||
// 更新图片点赞数
|
||||
model.setNumbers(model.getLikeNum() + 1);
|
||||
modelMapper.updateById(model);
|
||||
|
||||
this.addLikeAdvice(model, userId);
|
||||
}
|
||||
|
||||
|
||||
private void addLikeAdvice(ModelProduct model, Long userId) {
|
||||
|
||||
Long receiverUserId = model.getUserId();
|
||||
|
||||
if (Objects.equals(userId, receiverUserId)) {
|
||||
return;
|
||||
}
|
||||
SysUser sysUser = userService.selectUserById(userId);
|
||||
|
||||
String content = StringUtils.format("恭喜!{}点赞了您的模型:{}",
|
||||
sysUser.getNickName(), model.getModelName());
|
||||
|
||||
SysAdvice sysAdvice = new SysAdvice();
|
||||
sysAdvice.setSenderId(userId);
|
||||
sysAdvice.setReceiverId(receiverUserId);
|
||||
sysAdvice.setContent(content);
|
||||
sysAdvice.setProductId(model.getId());
|
||||
sysAdvice.setProductType(0);
|
||||
sysAdvice.setIsRead(0);
|
||||
sysAdvice.setType(AdviceEnum.LIKE_REMIND);
|
||||
adviceService.save(sysAdvice);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package com.mcwl.resource.handler.impl;
|
||||
|
||||
import cn.hutool.json.JSON;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.resource.domain.SysAdvice;
|
||||
import com.mcwl.resource.domain.WorkFlowComment;
|
||||
import com.mcwl.resource.domain.WorkFlowCommentLike;
|
||||
import com.mcwl.resource.handler.IMessageHandler;
|
||||
import com.mcwl.resource.mapper.WorkFlowCommentLikeMapper;
|
||||
import com.mcwl.resource.mapper.WorkFlowCommentMapper;
|
||||
import com.mcwl.resource.service.ISysAdviceService;
|
||||
import com.mcwl.system.domain.enums.AdviceEnum;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@IMessageHandler.Topic(value = "workFlowCommentLike/#", qos = 1)
|
||||
@RequiredArgsConstructor
|
||||
public class WorkFlowCommentLikeHandler implements IMessageHandler {
|
||||
|
||||
|
||||
private final WorkFlowCommentMapper workFlowCommentMapper;
|
||||
|
||||
|
||||
private final WorkFlowCommentLikeMapper workFlowCommentLikeMapper;
|
||||
|
||||
private final ISysUserService userService;
|
||||
|
||||
private final ISysAdviceService adviceService;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void handleMessage(String topic, MqttMessage message) {
|
||||
String payload = new String(message.getPayload());
|
||||
log.info("工作流评论点赞: {} - {}", topic, payload);
|
||||
|
||||
JSON parse = JSONUtil.parse(payload);
|
||||
Long commentId = Long.parseLong(parse.getByPath("commentId").toString());
|
||||
Long userId = Long.parseLong(parse.getByPath("userId").toString());
|
||||
|
||||
|
||||
this.like(userId, commentId);
|
||||
}
|
||||
|
||||
private void like(Long userId, Long commentId) {
|
||||
WorkFlowComment workFlowComment = workFlowCommentMapper.selectById(commentId);
|
||||
if (Objects.isNull(workFlowComment)) {
|
||||
throw new ServiceException("该评论不存在");
|
||||
}
|
||||
WorkFlowCommentLike workFlowCommentLike = workFlowCommentLikeMapper.getLikeComment(userId, commentId);
|
||||
if (Objects.nonNull(workFlowCommentLike)) {
|
||||
if (Objects.equals(workFlowCommentLike.getDelFlag(), "0")) {
|
||||
workFlowCommentLike.setDelFlag("2");
|
||||
int likeNum = workFlowComment.getLikeNum() - 1;
|
||||
likeNum = Math.max(likeNum, 0);
|
||||
workFlowComment.setLikeNum(likeNum);
|
||||
} else {
|
||||
workFlowCommentLike.setDelFlag("0");
|
||||
workFlowComment.setLikeNum(workFlowComment.getLikeNum() + 1);
|
||||
this.addLikeAdvice(workFlowComment, userId);
|
||||
}
|
||||
// 更新点赞记录
|
||||
workFlowCommentLikeMapper.updateDelFlagById(workFlowCommentLike);
|
||||
// 更新图片评论点赞数
|
||||
workFlowCommentMapper.updateById(workFlowComment);
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加点赞记录
|
||||
workFlowCommentLike = new WorkFlowCommentLike();
|
||||
workFlowCommentLike.setUserId(userId);
|
||||
workFlowCommentLike.setWorkFlowCommentId(commentId);
|
||||
workFlowCommentLikeMapper.insert(workFlowCommentLike);
|
||||
|
||||
// 更新模型点赞数
|
||||
workFlowComment.setLikeNum(workFlowComment.getLikeNum() + 1);
|
||||
workFlowCommentMapper.updateById(workFlowComment);
|
||||
|
||||
this.addLikeAdvice(workFlowComment, userId);
|
||||
}
|
||||
|
||||
|
||||
private void addLikeAdvice(WorkFlowComment workFlowComment, Long userId) {
|
||||
|
||||
Long receiverUserId = workFlowComment.getUserId();
|
||||
|
||||
if (Objects.equals(userId, receiverUserId)) {
|
||||
return;
|
||||
}
|
||||
SysUser sysUser = userService.selectUserById(userId);
|
||||
|
||||
String content = StringUtils.format("恭喜!{}点赞了您的评论",
|
||||
sysUser.getNickName());
|
||||
|
||||
SysAdvice sysAdvice = new SysAdvice();
|
||||
sysAdvice.setSenderId(userId);
|
||||
sysAdvice.setReceiverId(receiverUserId);
|
||||
sysAdvice.setContent(content);
|
||||
sysAdvice.setProductId(workFlowComment.getWorkFlowId());
|
||||
sysAdvice.setProductType(1);
|
||||
sysAdvice.setCommentId(workFlowComment.getId());
|
||||
sysAdvice.setIsRead(0);
|
||||
sysAdvice.setType(AdviceEnum.LIKE_REMIND);
|
||||
adviceService.save(sysAdvice);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
package com.mcwl.resource.handler.impl;
|
||||
|
||||
import cn.hutool.json.JSON;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.resource.domain.SysAdvice;
|
||||
import com.mcwl.resource.domain.WorkFlow;
|
||||
import com.mcwl.resource.domain.WorkFlowLike;
|
||||
import com.mcwl.resource.handler.IMessageHandler;
|
||||
import com.mcwl.resource.mapper.WorkFlowLikeMapper;
|
||||
import com.mcwl.resource.mapper.WorkFlowMapper;
|
||||
import com.mcwl.resource.service.ISysAdviceService;
|
||||
import com.mcwl.system.domain.enums.AdviceEnum;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@IMessageHandler.Topic(value = "workFlowLike/#", qos = 1)
|
||||
@RequiredArgsConstructor
|
||||
public class WorkFlowLikeHandler implements IMessageHandler {
|
||||
|
||||
private final WorkFlowMapper workFlowMapper;
|
||||
|
||||
private final WorkFlowLikeMapper workFlowLikeMapper;
|
||||
|
||||
private final ISysUserService userService;
|
||||
|
||||
private final ISysAdviceService adviceService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void handleMessage(String topic, MqttMessage message) {
|
||||
String payload = new String(message.getPayload());
|
||||
log.info("工作流点赞: {} - {}", topic, payload);
|
||||
|
||||
JSON parse = JSONUtil.parse(payload);
|
||||
Long commentId = Long.parseLong(parse.getByPath("commentId").toString());
|
||||
Long userId = Long.parseLong(parse.getByPath("userId").toString());
|
||||
|
||||
|
||||
this.like(userId, commentId);
|
||||
}
|
||||
|
||||
private void like(Long userId, Long modelId) {
|
||||
WorkFlow workFlow = workFlowMapper.selectById(modelId);
|
||||
if (Objects.isNull(workFlow)) {
|
||||
throw new ServiceException("该工作流不存在或已下架");
|
||||
}
|
||||
WorkFlowLike workFlowLike = workFlowLikeMapper.getLike(userId, modelId);
|
||||
if (Objects.nonNull(workFlowLike)) {
|
||||
if (Objects.equals(workFlowLike.getDelFlag(), "0")) {
|
||||
workFlowLike.setDelFlag("2");
|
||||
int likeCount = workFlow.getLikeNum() - 1;
|
||||
likeCount = Math.max(likeCount, 0);
|
||||
workFlow.setLikeNum(likeCount);
|
||||
} else {
|
||||
workFlowLike.setDelFlag("0");
|
||||
workFlow.setLikeNum(workFlow.getLikeNum() + 1);
|
||||
this.addLikeAdvice(workFlow, userId);
|
||||
}
|
||||
// 更新点赞记录
|
||||
workFlowLikeMapper.updateStatus(workFlowLike);
|
||||
// 更新图片点赞数
|
||||
workFlowMapper.updateById(workFlow);
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加点赞记录
|
||||
workFlowLike = new WorkFlowLike();
|
||||
workFlowLike.setUserId(userId);
|
||||
workFlowLike.setWorkFlowId(modelId);
|
||||
workFlowLikeMapper.insert(workFlowLike);
|
||||
|
||||
// 更新图片点赞数
|
||||
workFlow.setLikeNum(workFlow.getLikeNum() + 1);
|
||||
workFlowMapper.updateById(workFlow);
|
||||
|
||||
this.addLikeAdvice(workFlow, userId);
|
||||
}
|
||||
|
||||
|
||||
private void addLikeAdvice(WorkFlow workFlow, Long userId) {
|
||||
|
||||
Long receiverUserId = workFlow.getUserId();
|
||||
|
||||
if (Objects.equals(userId, receiverUserId)) {
|
||||
return;
|
||||
}
|
||||
SysUser sysUser = userService.selectUserById(userId);
|
||||
|
||||
String content = StringUtils.format("恭喜!{}点赞了您的工作流:{}",
|
||||
sysUser.getNickName(), workFlow.getWorkflowName());
|
||||
|
||||
SysAdvice sysAdvice = new SysAdvice();
|
||||
sysAdvice.setSenderId(userId);
|
||||
sysAdvice.setReceiverId(receiverUserId);
|
||||
sysAdvice.setContent(content);
|
||||
sysAdvice.setProductId(workFlow.getId());
|
||||
sysAdvice.setProductType(1);
|
||||
sysAdvice.setIsRead(0);
|
||||
sysAdvice.setType(AdviceEnum.LIKE_REMIND);
|
||||
adviceService.save(sysAdvice);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,22 +1,18 @@
|
|||
package com.mcwl.resource.service.impl;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.resource.domain.ModelComment;
|
||||
import com.mcwl.resource.domain.ModelCommentLike;
|
||||
import com.mcwl.resource.domain.SysAdvice;
|
||||
import com.mcwl.resource.mapper.ModelCommentLikeMapper;
|
||||
import com.mcwl.resource.mapper.ModelCommentMapper;
|
||||
import com.mcwl.resource.service.ModelCommentLikeService;
|
||||
import com.mcwl.system.domain.enums.AdviceEnum;
|
||||
import com.mcwl.resource.util.MqttTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 模型评论点赞
|
||||
|
@ -25,72 +21,14 @@ import java.util.Objects;
|
|||
public class ModelCommentLikeServiceImpl extends ServiceImpl<ModelCommentLikeMapper, ModelCommentLike> implements ModelCommentLikeService {
|
||||
|
||||
@Autowired
|
||||
private ModelCommentMapper modelCommentMapper;
|
||||
private MqttTemplate mqttTemplate;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void like(Long commentId) {
|
||||
ModelComment modelComment = modelCommentMapper.selectById(commentId);
|
||||
if (Objects.isNull(modelComment)) {
|
||||
throw new ServiceException("该评论不存在");
|
||||
}
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
ModelCommentLike modelCommentLike = baseMapper.getLikeComment(userId, commentId);
|
||||
if (Objects.nonNull(modelCommentLike)) {
|
||||
if (Objects.equals(modelCommentLike.getDelFlag(), "0")) {
|
||||
modelCommentLike.setDelFlag("2");
|
||||
int likeNum = modelComment.getLikeNum() - 1;
|
||||
likeNum = Math.max(likeNum, 0);
|
||||
modelComment.setLikeNum(likeNum);
|
||||
} else {
|
||||
modelCommentLike.setDelFlag("0");
|
||||
modelComment.setLikeNum(modelComment.getLikeNum() + 1);
|
||||
this.addLikeAdvice(modelComment);
|
||||
}
|
||||
// 更新点赞记录
|
||||
baseMapper.updateDelFlagById(modelCommentLike);
|
||||
// 更新图片评论点赞数
|
||||
modelCommentMapper.updateById(modelComment);
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加点赞记录
|
||||
modelCommentLike = new ModelCommentLike();
|
||||
modelCommentLike.setUserId(userId);
|
||||
modelCommentLike.setModelCommentId(commentId);
|
||||
baseMapper.insert(modelCommentLike);
|
||||
|
||||
// 更新模型点赞数
|
||||
modelComment.setLikeNum(modelComment.getLikeNum() + 1);
|
||||
modelCommentMapper.updateById(modelComment);
|
||||
|
||||
this.addLikeAdvice(modelComment);
|
||||
}
|
||||
|
||||
|
||||
private void addLikeAdvice(ModelComment modelComment) {
|
||||
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
Long receiverUserId = modelComment.getUserId();
|
||||
|
||||
if (Objects.equals(userId, receiverUserId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String content = StringUtils.format("恭喜!{}点赞了您的评论",
|
||||
SecurityUtils.getLoginUser().getUser().getNickName());
|
||||
|
||||
SysAdvice sysAdvice = new SysAdvice();
|
||||
sysAdvice.setSenderId(userId);
|
||||
sysAdvice.setReceiverId(receiverUserId);
|
||||
sysAdvice.setContent(content);
|
||||
sysAdvice.setProductId(modelComment.getModelId());
|
||||
sysAdvice.setProductType(0);
|
||||
sysAdvice.setCommentId(modelComment.getId());
|
||||
sysAdvice.setIsRead(0);
|
||||
sysAdvice.setType(AdviceEnum.LIKE_REMIND);
|
||||
|
||||
|
||||
Map<String, Long> map = new HashMap<>();
|
||||
map.put("userId", SecurityUtils.getUserId());
|
||||
map.put("commentId", commentId);
|
||||
mqttTemplate.publish("modelCommentLike", JSONUtil.toJsonStr(map), 0);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,22 +1,19 @@
|
|||
package com.mcwl.resource.service.impl;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.resource.domain.ModelImageComment;
|
||||
import com.mcwl.resource.domain.ModelImageCommentLike;
|
||||
import com.mcwl.resource.domain.SysAdvice;
|
||||
import com.mcwl.resource.mapper.ModelImageCommentLikeMapper;
|
||||
import com.mcwl.resource.mapper.ModelImageCommentMapper;
|
||||
import com.mcwl.resource.service.ModelImageCommentLikeService;
|
||||
import com.mcwl.system.domain.enums.AdviceEnum;
|
||||
import com.mcwl.resource.util.MqttTemplate;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 图片评论点赞
|
||||
|
@ -25,72 +22,15 @@ import java.util.Objects;
|
|||
@RequiredArgsConstructor
|
||||
public class ModelImageCommentLikeServiceImpl extends ServiceImpl<ModelImageCommentLikeMapper, ModelImageCommentLike> implements ModelImageCommentLikeService {
|
||||
|
||||
private final ModelImageCommentMapper modelImageCommentMapper;
|
||||
@Autowired
|
||||
private MqttTemplate mqttTemplate;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void like(Long commentId) {
|
||||
ModelImageComment modelImageComment = modelImageCommentMapper.selectById(commentId);
|
||||
if (Objects.isNull(modelImageComment)) {
|
||||
throw new ServiceException("该评论不存在");
|
||||
}
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
ModelImageCommentLike modelImageCommentLike = baseMapper.getLikeImageComment(userId, commentId);
|
||||
if (Objects.nonNull(modelImageCommentLike)) {
|
||||
if (Objects.equals(modelImageCommentLike.getDelFlag(), "0")) {
|
||||
modelImageCommentLike.setDelFlag("2");
|
||||
int likeNum = modelImageComment.getLikeNum() - 1;
|
||||
likeNum = Math.max(likeNum, 0);
|
||||
modelImageComment.setLikeNum(likeNum);
|
||||
} else {
|
||||
modelImageCommentLike.setDelFlag("0");
|
||||
modelImageComment.setLikeNum(modelImageComment.getLikeNum() + 1);
|
||||
this.addLikeAdvice(modelImageComment);
|
||||
}
|
||||
// 更新点赞记录
|
||||
baseMapper.updateDelFlagById(modelImageCommentLike);
|
||||
// 更新图片评论点赞数
|
||||
modelImageCommentMapper.updateById(modelImageComment);
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加点赞记录
|
||||
modelImageCommentLike = new ModelImageCommentLike();
|
||||
modelImageCommentLike.setUserId(userId);
|
||||
modelImageCommentLike.setModelImageCommentId(commentId);
|
||||
baseMapper.insert(modelImageCommentLike);
|
||||
|
||||
// 更新图片点赞数
|
||||
modelImageComment.setLikeNum(modelImageComment.getLikeNum() + 1);
|
||||
modelImageCommentMapper.updateById(modelImageComment);
|
||||
|
||||
this.addLikeAdvice(modelImageComment);
|
||||
}
|
||||
|
||||
|
||||
private void addLikeAdvice(ModelImageComment modelImageComment) {
|
||||
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
Long receiverUserId = modelImageComment.getUserId();
|
||||
|
||||
if (Objects.equals(userId, receiverUserId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String content = StringUtils.format("恭喜!{}点赞了您的评论",
|
||||
SecurityUtils.getLoginUser().getUser().getNickName());
|
||||
|
||||
SysAdvice sysAdvice = new SysAdvice();
|
||||
sysAdvice.setSenderId(userId);
|
||||
sysAdvice.setReceiverId(receiverUserId);
|
||||
sysAdvice.setContent(content);
|
||||
sysAdvice.setProductId(modelImageComment.getModelImageId());
|
||||
sysAdvice.setProductType(2);
|
||||
sysAdvice.setCommentId(modelImageComment.getId());
|
||||
sysAdvice.setIsRead(0);
|
||||
sysAdvice.setType(AdviceEnum.LIKE_REMIND);
|
||||
|
||||
|
||||
Map<String, Long> map = new HashMap<>();
|
||||
map.put("userId", SecurityUtils.getUserId());
|
||||
map.put("commentId", commentId);
|
||||
mqttTemplate.publish("imageCommentLike", JSONUtil.toJsonStr(map),0);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.mcwl.resource.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
@ -11,7 +12,6 @@ import com.mcwl.common.constant.HttpStatus;
|
|||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.core.page.PageDomain;
|
||||
import com.mcwl.common.core.page.TableDataInfo;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.resource.domain.ModelImage;
|
||||
|
@ -23,16 +23,14 @@ import com.mcwl.resource.domain.vo.PageVo;
|
|||
import com.mcwl.resource.mapper.ModelImageLikeMapper;
|
||||
import com.mcwl.resource.mapper.ModelImageMapper;
|
||||
import com.mcwl.resource.service.ModelImageLikeService;
|
||||
import com.mcwl.resource.util.MqttTemplate;
|
||||
import com.mcwl.system.domain.enums.AdviceEnum;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 图片点赞实现
|
||||
|
@ -45,44 +43,15 @@ public class ModelImageLikeServiceImpl extends ServiceImpl<ModelImageLikeMapper,
|
|||
|
||||
private final ISysUserService sysUserService;
|
||||
|
||||
@Autowired
|
||||
private MqttTemplate mqttTemplate;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void like(Long imageId) {
|
||||
ModelImage modelImage = modelImageMapper.selectById(imageId);
|
||||
if (Objects.isNull(modelImage)) {
|
||||
throw new ServiceException("该图片不存在或已下架");
|
||||
}
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
ModelImageLike modelImageLike = baseMapper.getLikeImage(userId, imageId);
|
||||
if (Objects.nonNull(modelImageLike)) {
|
||||
if (Objects.equals(modelImageLike.getDelFlag(), "0")) {
|
||||
modelImageLike.setDelFlag("2");
|
||||
int likeNum = modelImage.getLikeNum() - 1;
|
||||
likeNum = Math.max(likeNum, 0);
|
||||
modelImage.setLikeNum(likeNum);
|
||||
} else {
|
||||
modelImageLike.setDelFlag("0");
|
||||
modelImage.setLikeNum(modelImage.getLikeNum() + 1);
|
||||
this.addLikeAdvice(modelImage);
|
||||
}
|
||||
// 更新点赞记录
|
||||
baseMapper.updateDelFlagById(modelImageLike);
|
||||
// 更新图片点赞数
|
||||
modelImageMapper.updateById(modelImage);
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加点赞记录
|
||||
modelImageLike = new ModelImageLike();
|
||||
modelImageLike.setUserId(userId);
|
||||
modelImageLike.setModelImageId(imageId);
|
||||
baseMapper.insert(modelImageLike);
|
||||
|
||||
// 更新图片点赞数
|
||||
modelImage.setLikeNum(modelImage.getLikeNum() + 1);
|
||||
modelImageMapper.updateById(modelImage);
|
||||
|
||||
this.addLikeAdvice(modelImage);
|
||||
Map<String, Long> map = new HashMap<>();
|
||||
map.put("userId", SecurityUtils.getUserId());
|
||||
map.put("commentId", imageId);
|
||||
mqttTemplate.publish("imageLike", JSONUtil.toJsonStr(map),0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -141,6 +110,7 @@ public class ModelImageLikeServiceImpl extends ServiceImpl<ModelImageLikeMapper,
|
|||
page.setTotal(page.getTotal() - 1);
|
||||
continue;
|
||||
}
|
||||
modelImageLikeVo.setDownloadNumber(Long.valueOf(modelImage.getDownloadNum()));
|
||||
modelImageLikeVo.setImagePaths(modelImage.getImagePaths());
|
||||
modelImageLikeVo.setLikeNum(modelImage.getLikeNum());
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.mcwl.resource.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
@ -9,26 +10,20 @@ import com.mcwl.common.constant.HttpStatus;
|
|||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.core.page.PageDomain;
|
||||
import com.mcwl.common.core.page.TableDataInfo;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.resource.domain.ModelLike;
|
||||
import com.mcwl.resource.domain.ModelProduct;
|
||||
import com.mcwl.resource.domain.SysAdvice;
|
||||
import com.mcwl.resource.domain.vo.ModelLikeVo;
|
||||
import com.mcwl.resource.mapper.ModelLikeMapper;
|
||||
import com.mcwl.resource.mapper.ModelMapper;
|
||||
import com.mcwl.resource.service.ModelLikeService;
|
||||
import com.mcwl.system.domain.enums.AdviceEnum;
|
||||
import com.mcwl.resource.util.MqttTemplate;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 模型点赞
|
||||
|
@ -43,45 +38,16 @@ public class ModelLikeServiceImpl extends ServiceImpl<ModelLikeMapper, ModelLike
|
|||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
|
||||
@Autowired
|
||||
private MqttTemplate mqttTemplate;
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void like(Long modelId) {
|
||||
ModelProduct model = modelMapper.selectById(modelId);
|
||||
if (Objects.isNull(model)) {
|
||||
throw new ServiceException("该模型不存在或已下架");
|
||||
}
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
ModelLike modelLike = baseMapper.getLike(userId, modelId);
|
||||
if (Objects.nonNull(modelLike)) {
|
||||
if (Objects.equals(modelLike.getDelFlag(), "0")) {
|
||||
modelLike.setDelFlag("2");
|
||||
int likeNum = model.getLikeNum() - 1;
|
||||
likeNum = Math.max(likeNum, 0);
|
||||
model.setLikeNum(likeNum);
|
||||
} else {
|
||||
modelLike.setDelFlag("0");
|
||||
model.setLikeNum(model.getLikeNum() + 1);
|
||||
this.addLikeAdvice(model);
|
||||
}
|
||||
// 更新点赞记录
|
||||
baseMapper.updateDelFlagById(modelLike);
|
||||
// 更新图片点赞数
|
||||
modelMapper.updateById(model);
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加点赞记录
|
||||
modelLike = new ModelLike();
|
||||
modelLike.setUserId(userId);
|
||||
modelLike.setModelId(modelId);
|
||||
baseMapper.insert(modelLike);
|
||||
|
||||
// 更新图片点赞数
|
||||
model.setNumbers(model.getLikeNum() + 1);
|
||||
modelMapper.updateById(model);
|
||||
|
||||
this.addLikeAdvice(model);
|
||||
Map<String, Long> map = new HashMap<>();
|
||||
map.put("userId", SecurityUtils.getUserId());
|
||||
map.put("commentId", modelId);
|
||||
mqttTemplate.publish("modelLike", JSONUtil.toJsonStr(map),0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -113,6 +79,7 @@ public class ModelLikeServiceImpl extends ServiceImpl<ModelLikeMapper, ModelLike
|
|||
page.setTotal(page.getTotal() - 1);
|
||||
continue;
|
||||
}
|
||||
modelLikeVo.setDownloadNumber(Long.valueOf(modelProduct.getNumbers()));
|
||||
modelLikeVo.setSurfaceUrl(modelProduct.getSurfaceUrl());
|
||||
modelLikeVo.setModelName(modelProduct.getModelName());
|
||||
|
||||
|
@ -132,31 +99,6 @@ public class ModelLikeServiceImpl extends ServiceImpl<ModelLikeMapper, ModelLike
|
|||
}
|
||||
|
||||
|
||||
|
||||
private void addLikeAdvice(ModelProduct model) {
|
||||
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
Long receiverUserId = model.getUserId();
|
||||
|
||||
if (Objects.equals(userId, receiverUserId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String content = StringUtils.format("恭喜!{}点赞了您的模型:{}",
|
||||
SecurityUtils.getLoginUser().getUser().getNickName(), model.getModelName());
|
||||
|
||||
SysAdvice sysAdvice = new SysAdvice();
|
||||
sysAdvice.setSenderId(userId);
|
||||
sysAdvice.setReceiverId(receiverUserId);
|
||||
sysAdvice.setContent(content);
|
||||
sysAdvice.setProductId(model.getId());
|
||||
sysAdvice.setProductType(0);
|
||||
sysAdvice.setIsRead(0);
|
||||
sysAdvice.setType(AdviceEnum.LIKE_REMIND);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private Page<ModelLike> initPage(PageDomain pageDomain) {
|
||||
Page<ModelLike> page = new Page<>(pageDomain.getPageNum(), pageDomain.getPageSize());
|
||||
if (StringUtils.isBlank(pageDomain.getOrderByColumn())) {
|
||||
|
|
|
@ -1,22 +1,18 @@
|
|||
package com.mcwl.resource.service.impl;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.resource.domain.SysAdvice;
|
||||
import com.mcwl.resource.domain.WorkFlowComment;
|
||||
import com.mcwl.resource.domain.WorkFlowCommentLike;
|
||||
import com.mcwl.resource.mapper.WorkFlowCommentLikeMapper;
|
||||
import com.mcwl.resource.mapper.WorkFlowCommentMapper;
|
||||
import com.mcwl.resource.service.WorkFlowCommentLikeService;
|
||||
import com.mcwl.system.domain.enums.AdviceEnum;
|
||||
import com.mcwl.resource.util.MqttTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author:ChenYan
|
||||
|
@ -30,72 +26,15 @@ import java.util.Objects;
|
|||
public class WorkFlowCommentLikeServiceImpl extends ServiceImpl<WorkFlowCommentLikeMapper, WorkFlowCommentLike> implements WorkFlowCommentLikeService {
|
||||
|
||||
@Autowired
|
||||
private WorkFlowCommentMapper workFlowCommentMapper;
|
||||
private MqttTemplate mqttTemplate;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void like(Long commentId) {
|
||||
WorkFlowComment workFlowComment = workFlowCommentMapper.selectById(commentId);
|
||||
if (Objects.isNull(workFlowComment)) {
|
||||
throw new ServiceException("该评论不存在");
|
||||
}
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
WorkFlowCommentLike workFlowCommentLike = baseMapper.getLikeComment(userId, commentId);
|
||||
if (Objects.nonNull(workFlowCommentLike)) {
|
||||
if (Objects.equals(workFlowCommentLike.getDelFlag(), "0")) {
|
||||
workFlowCommentLike.setDelFlag("2");
|
||||
int likeNum = workFlowComment.getLikeNum() - 1;
|
||||
likeNum = Math.max(likeNum, 0);
|
||||
workFlowComment.setLikeNum(likeNum);
|
||||
} else {
|
||||
workFlowCommentLike.setDelFlag("0");
|
||||
workFlowComment.setLikeNum(workFlowComment.getLikeNum() + 1);
|
||||
this.addLikeAdvice(workFlowComment);
|
||||
}
|
||||
// 更新点赞记录
|
||||
baseMapper.updateDelFlagById(workFlowCommentLike);
|
||||
// 更新图片评论点赞数
|
||||
workFlowCommentMapper.updateById(workFlowComment);
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加点赞记录
|
||||
workFlowCommentLike = new WorkFlowCommentLike();
|
||||
workFlowCommentLike.setUserId(userId);
|
||||
workFlowCommentLike.setWorkFlowCommentId(commentId);
|
||||
baseMapper.insert(workFlowCommentLike);
|
||||
|
||||
// 更新模型点赞数
|
||||
workFlowComment.setLikeNum(workFlowComment.getLikeNum() + 1);
|
||||
workFlowCommentMapper.updateById(workFlowComment);
|
||||
|
||||
this.addLikeAdvice(workFlowComment);
|
||||
Map<String, Long> map = new HashMap<>();
|
||||
map.put("userId", SecurityUtils.getUserId());
|
||||
map.put("commentId", commentId);
|
||||
mqttTemplate.publish("workFlowCommentLike", JSONUtil.toJsonStr(map),0);
|
||||
}
|
||||
|
||||
|
||||
private void addLikeAdvice(WorkFlowComment workFlowComment) {
|
||||
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
Long receiverUserId = workFlowComment.getUserId();
|
||||
|
||||
if (Objects.equals(userId, receiverUserId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String content = StringUtils.format("恭喜!{}点赞了您的评论",
|
||||
SecurityUtils.getLoginUser().getUser().getNickName());
|
||||
|
||||
SysAdvice sysAdvice = new SysAdvice();
|
||||
sysAdvice.setSenderId(userId);
|
||||
sysAdvice.setReceiverId(receiverUserId);
|
||||
sysAdvice.setContent(content);
|
||||
sysAdvice.setProductId(workFlowComment.getWorkFlowId());
|
||||
sysAdvice.setProductType(1);
|
||||
sysAdvice.setCommentId(workFlowComment.getId());
|
||||
sysAdvice.setIsRead(0);
|
||||
sysAdvice.setType(AdviceEnum.LIKE_REMIND);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.mcwl.resource.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
@ -9,25 +10,21 @@ import com.mcwl.common.constant.HttpStatus;
|
|||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.core.page.PageDomain;
|
||||
import com.mcwl.common.core.page.TableDataInfo;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.resource.domain.SysAdvice;
|
||||
import com.mcwl.resource.domain.WorkFlow;
|
||||
import com.mcwl.resource.domain.WorkFlowLike;
|
||||
import com.mcwl.resource.domain.vo.WorkFlowLikeVo;
|
||||
import com.mcwl.resource.mapper.WorkFlowLikeMapper;
|
||||
import com.mcwl.resource.mapper.WorkFlowMapper;
|
||||
import com.mcwl.resource.service.WorkFlowLikeService;
|
||||
import com.mcwl.system.domain.enums.AdviceEnum;
|
||||
import com.mcwl.resource.util.MqttTemplate;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 工作流点赞
|
||||
|
@ -48,44 +45,15 @@ public class WorkFlowLikeServiceImpl extends ServiceImpl<WorkFlowLikeMapper, Wor
|
|||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
|
||||
@Autowired
|
||||
private MqttTemplate mqttTemplate;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void like(Long modelId) {
|
||||
WorkFlow workFlow = workFlowMapper.selectById(modelId);
|
||||
if (Objects.isNull(workFlow)) {
|
||||
throw new ServiceException("该工作流不存在或已下架");
|
||||
}
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
WorkFlowLike workFlowLike = baseMapper.getLike(userId, modelId);
|
||||
if (Objects.nonNull(workFlowLike)) {
|
||||
if (Objects.equals(workFlowLike.getDelFlag(), "0")) {
|
||||
workFlowLike.setDelFlag("2");
|
||||
int likeCount = workFlow.getLikeNum() - 1;
|
||||
likeCount = Math.max(likeCount, 0);
|
||||
workFlow.setLikeNum(likeCount);
|
||||
} else {
|
||||
workFlowLike.setDelFlag("0");
|
||||
workFlow.setLikeNum(workFlow.getLikeNum() + 1);
|
||||
this.addLikeAdvice(workFlow);
|
||||
}
|
||||
// 更新点赞记录
|
||||
baseMapper.updateStatus(workFlowLike);
|
||||
// 更新图片点赞数
|
||||
workFlowMapper.updateById(workFlow);
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加点赞记录
|
||||
workFlowLike = new WorkFlowLike();
|
||||
workFlowLike.setUserId(userId);
|
||||
workFlowLike.setWorkFlowId(modelId);
|
||||
baseMapper.insert(workFlowLike);
|
||||
|
||||
// 更新图片点赞数
|
||||
workFlow.setLikeNum(workFlow.getLikeNum() + 1);
|
||||
workFlowMapper.updateById(workFlow);
|
||||
|
||||
this.addLikeAdvice(workFlow);
|
||||
Map<String, Long> map = new HashMap<>();
|
||||
map.put("userId", SecurityUtils.getUserId());
|
||||
map.put("commentId", modelId);
|
||||
mqttTemplate.publish("workFlowLike", JSONUtil.toJsonStr(map),0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -118,6 +86,7 @@ public class WorkFlowLikeServiceImpl extends ServiceImpl<WorkFlowLikeMapper, Wor
|
|||
page.setTotal(page.getTotal() - 1);
|
||||
continue;
|
||||
}
|
||||
workFlowLikeVo.setDownloadNumber(workFlow.getDownloadNumber());
|
||||
workFlowLikeVo.setCoverPath(workFlow.getCoverPath());
|
||||
workFlowLikeVo.setLikeNum(workFlow.getLikeNum());
|
||||
|
||||
|
@ -145,29 +114,7 @@ public class WorkFlowLikeServiceImpl extends ServiceImpl<WorkFlowLikeMapper, Wor
|
|||
}
|
||||
|
||||
|
||||
private void addLikeAdvice(WorkFlow workFlow) {
|
||||
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
Long receiverUserId = workFlow.getUserId();
|
||||
|
||||
if (Objects.equals(userId, receiverUserId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String content = StringUtils.format("恭喜!{}点赞了您的工作流:{}",
|
||||
SecurityUtils.getLoginUser().getUser().getNickName(), workFlow.getWorkflowName());
|
||||
|
||||
SysAdvice sysAdvice = new SysAdvice();
|
||||
sysAdvice.setSenderId(userId);
|
||||
sysAdvice.setReceiverId(receiverUserId);
|
||||
sysAdvice.setContent(content);
|
||||
sysAdvice.setProductId(workFlow.getId());
|
||||
sysAdvice.setProductType(1);
|
||||
sysAdvice.setIsRead(0);
|
||||
sysAdvice.setType(AdviceEnum.LIKE_REMIND);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private Page<WorkFlowLike> initPage(PageDomain pageDomain) {
|
||||
|
|
|
@ -0,0 +1,264 @@
|
|||
package com.mcwl.resource.util;
|
||||
|
||||
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.resource.handler.IMessageHandler;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.mcwl.common.utils.Threads.sleep;
|
||||
|
||||
@Slf4j
|
||||
@Getter
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "mqtt")
|
||||
public class MqttTemplate implements MqttCallbackExtended, DisposableBean {
|
||||
|
||||
@Value("${mqtt.broker-url}")
|
||||
private String brokerUrl;
|
||||
|
||||
@Value("${mqtt.client-id-prefix}")
|
||||
private String clientIdPrefix;
|
||||
|
||||
@Value("${mqtt.connection-timeout}")
|
||||
private int connectionTimeout;
|
||||
|
||||
@Value("${mqtt.keep-alive-interval}")
|
||||
private int keepAliveInterval;
|
||||
|
||||
@Value("${mqtt.max-reconnect-attempts}")
|
||||
private int maxReconnectAttempts;
|
||||
|
||||
@Value("${mqtt.clean-session}")
|
||||
private boolean cleanSession;
|
||||
|
||||
private String clientId;
|
||||
|
||||
private MqttAsyncClient client;
|
||||
private final Map<String, List<IMessageHandler>> topicHandlers = new ConcurrentHashMap<>();
|
||||
private final ScheduledExecutorService reconnectExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||
private volatile boolean isConnecting;
|
||||
private final ApplicationContext context;
|
||||
|
||||
public MqttTemplate(ApplicationContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() throws MqttException {
|
||||
if (StringUtils.isBlank(clientId)) {
|
||||
clientId = clientIdPrefix + UUID.randomUUID().toString().substring(0, 8);
|
||||
}
|
||||
|
||||
client = new MqttAsyncClient(brokerUrl, clientId, new MemoryPersistence());
|
||||
client.setCallback(this);
|
||||
connect();
|
||||
// autoRegisterHandlers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
if (client != null && client.isConnected()) {
|
||||
client.disconnect();
|
||||
}
|
||||
reconnectExecutor.shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接管理
|
||||
*
|
||||
* @throws MqttException 连接失败
|
||||
*/
|
||||
private void connect() throws MqttException {
|
||||
MqttConnectOptions options = new MqttConnectOptions();
|
||||
options.setCleanSession(cleanSession);
|
||||
options.setConnectionTimeout(connectionTimeout);
|
||||
options.setKeepAliveInterval(keepAliveInterval);
|
||||
options.setAutomaticReconnect(false); // 手动控制重连
|
||||
|
||||
client.connect(options, null, new IMqttActionListener() {
|
||||
@Override
|
||||
public void onSuccess(IMqttToken asyncActionToken) {
|
||||
log.info("MQTT连接成功");
|
||||
resubscribeAllTopics();
|
||||
autoRegisterHandlers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
|
||||
log.error("初始连接失败", exception);
|
||||
scheduleReconnect(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 重连管理
|
||||
* @param attempt 重连次数
|
||||
*/
|
||||
private void scheduleReconnect(int attempt) {
|
||||
if (attempt > maxReconnectAttempts) {
|
||||
log.error("达到最大重连次数: {}", maxReconnectAttempts);
|
||||
return;
|
||||
}
|
||||
|
||||
long delay = (long) Math.min(1000 * Math.pow(2, attempt), 30000);
|
||||
reconnectExecutor.schedule(() -> {
|
||||
try {
|
||||
log.info("尝试第{}次重连", attempt);
|
||||
if (client != null && client.isConnected()) {
|
||||
client.disconnectForcibly(); // 强制断开旧连接
|
||||
client.close(true);
|
||||
}
|
||||
// 重新初始化客户端
|
||||
client = new MqttAsyncClient(brokerUrl, clientId, new MemoryPersistence());
|
||||
client.setCallback(this); // 关键:重新绑定回调
|
||||
client.reconnect();
|
||||
resubscribeAllTopics(); // 重连后立即订阅
|
||||
log.info("重连成功");
|
||||
} catch (MqttException e) {
|
||||
log.error("重连失败", e);
|
||||
scheduleReconnect(attempt + 1);
|
||||
}
|
||||
}, delay, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布消息
|
||||
* @param topic 主题
|
||||
* @param payload 消息体
|
||||
* @param qos QoS等级
|
||||
*/
|
||||
@Async
|
||||
public void publish(String topic, String payload, int qos) {
|
||||
try {
|
||||
if (!client.isConnected()) {
|
||||
throw new MqttException(MqttException.REASON_CODE_CLIENT_NOT_CONNECTED);
|
||||
}
|
||||
client.publish(topic, payload.getBytes(), qos, false);
|
||||
} catch (MqttException e) {
|
||||
log.error("消息发送失败 [topic: {}]", topic, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Async
|
||||
public void publish(String topic, String payload) {
|
||||
try {
|
||||
if (!client.isConnected()) {
|
||||
throw new MqttException(MqttException.REASON_CODE_CLIENT_NOT_CONNECTED);
|
||||
}
|
||||
client.publish(topic, payload.getBytes(), 1, false);
|
||||
} catch (MqttException e) {
|
||||
log.error("消息发送失败 [topic: {}]", topic, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 订阅主题
|
||||
* @param topicFilter 主题过滤器
|
||||
* @param qos QoS等级
|
||||
* @param handler 消息处理器
|
||||
*/
|
||||
public void subscribe(String topicFilter, int qos, IMessageHandler handler) {
|
||||
try {
|
||||
if (!client.isConnected()) {
|
||||
log.warn("客户端未连接,延迟订阅 [topic: {}]", topicFilter);
|
||||
return;
|
||||
}
|
||||
client.subscribe(topicFilter, qos);
|
||||
topicHandlers.computeIfAbsent(topicFilter, k -> new ArrayList<>())
|
||||
.add(handler);
|
||||
log.info("订阅成功: {}", topicFilter);
|
||||
} catch (MqttException e) {
|
||||
log.error("订阅失败 [topic: {}]", topicFilter);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void resubscribeAllTopics() {
|
||||
topicHandlers.forEach((topic, handlers) -> {
|
||||
int retry = 0;
|
||||
while (retry < 3) {
|
||||
try {
|
||||
client.subscribe(topic, 1);
|
||||
log.info("主题重新订阅成功: {}", topic);
|
||||
break;
|
||||
} catch (MqttException e) {
|
||||
retry++;
|
||||
log.error("重新订阅失败 [topic: {}], 重试 {}/3", topic, retry);
|
||||
sleep(1000L * retry);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息到达处理
|
||||
* @param topic 主题
|
||||
* @param message 消息
|
||||
*/
|
||||
@Override
|
||||
public void messageArrived(String topic, MqttMessage message) {
|
||||
|
||||
topicHandlers.entrySet().stream()
|
||||
.filter(entry -> MqttTopic.isMatched(entry.getKey(), topic))
|
||||
.flatMap(entry -> entry.getValue().stream())
|
||||
.forEach(handler -> {
|
||||
try {
|
||||
handler.handleMessage(topic, message);
|
||||
} catch (Exception e) {
|
||||
log.error("消息处理异常 [handler: {}]", handler.getClass(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionLost(Throwable cause) {
|
||||
log.error("连接丢失", cause);
|
||||
scheduleReconnect(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deliveryComplete(IMqttDeliveryToken token) {
|
||||
// QoS处理逻辑
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectComplete(boolean reconnect, String serverURI) {
|
||||
log.info("连接已建立 [reconnect: {}]", reconnect);
|
||||
if (reconnect) {
|
||||
resubscribeAllTopics();
|
||||
autoRegisterHandlers();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动注册处理器
|
||||
*/
|
||||
private void autoRegisterHandlers() {
|
||||
context.getBeansOfType(IMessageHandler.class).values()
|
||||
.forEach(handler -> {
|
||||
handler.getTopics().forEach(topic ->
|
||||
subscribe(topic.getTopicFilter(), topic.getQos(), handler));
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue