Merge branch 'feature/resource' of https://gitea.qinmian.online/CY/mcwl-ai into preview

feature/comment
ChenYan 2025-01-04 17:12:37 +08:00
commit 3b4ff9f774
21 changed files with 829 additions and 6 deletions

View File

@ -16,7 +16,11 @@
</description>
<dependencies>
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-easysdk</artifactId>
<version>2.2.0</version>
</dependency>
<!-- spring-boot-devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
@ -73,6 +77,12 @@
<artifactId>mcwl-common</artifactId>
<version>3.8.8</version>
</dependency>
<!-- 支付模块-->
<dependency>
<groupId>com.mcwl</groupId>
<artifactId>mcwl-pay</artifactId>
<version>3.8.8</version>
</dependency>
<!-- 资源中心模块-->
<dependency>
<groupId>com.mcwl</groupId>

View File

@ -0,0 +1,40 @@
package com.mcwl.web.controller.pay;
import com.alipay.easysdk.payment.facetoface.models.AlipayTradePrecreateResponse;
import com.alibaba.fastjson.JSONObject;
import com.alipay.easysdk.factory.Factory;
import com.mcwl.pay.domain.OrderTrade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alipay.easysdk.kernel.Config;
/**
*
*/
@Component
public class AliPayIntegration {
@Autowired
private Config config;
/**
*
*
* @param tradeEntity
* @return url
* @throws Exception
*/
public String pay(OrderTrade tradeEntity) throws Exception {
Factory.setOptions(config);
//调用支付宝的接口
AlipayTradePrecreateResponse payResponse = Factory.Payment.FaceToFace()
.preCreate("商城",
tradeEntity.getCode(),
tradeEntity.getPaymentAmount().toString());
//参照官方文档响应示例,解析返回结果
String httpBodyStr = payResponse.getHttpBody();
JSONObject jsonObject = JSONObject.parseObject(httpBodyStr);
return jsonObject.getJSONObject("alipay_trade_precreate_response").get("qr_code").toString();
}
}

View File

@ -0,0 +1,113 @@
package com.mcwl.web.controller.pay;
import cn.hutool.extra.qrcode.QrCodeUtil;
import com.mcwl.common.core.controller.BaseController;
import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.core.page.TableDataInfo;
import com.mcwl.common.domain.IdsParam;
import com.mcwl.common.interfaces.NoLogin;
import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.pay.domain.OrderTrade;
import com.mcwl.pay.service.OrderTradeService;
import com.mcwl.resource.domain.MallProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Objects;
import static com.mcwl.common.utils.PageUtils.startPage;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.web.controller.pay
* @FilenameOrderTradeController
* @Description
* @Date2025/1/3 14:46
*/
@RestController
@RequestMapping("/web/pay")
@Validated
public class OrderTradeController extends BaseController {
@Autowired
private OrderTradeService orderTradeService;
@Autowired
private AliPayIntegration aliPayIntegration;
/**
*
*/
@GetMapping("/list")
public TableDataInfo list(OrderTrade orderTrade)
{
startPage();
List<OrderTrade> list = orderTradeService.selectMallProductList(orderTrade);
return getDataTable(list);
}
/**
*
*/
@PostMapping("/add")
public AjaxResult add(@RequestBody OrderTrade orderTrade)
{
// 获取当前用户
Long userId = SecurityUtils.getUserId();
if (userId == null) {
return AjaxResult.warn("用户未登录");
}
orderTrade.setUserId(userId);
orderTrade.setCreateBy(getUsername());
return toAjax(orderTradeService.insertMallProduct(orderTrade));
}
/**
*
*/
@PostMapping("/upda")
public AjaxResult upda(@RequestBody OrderTrade orderTrade)
{
// 获取当前用户
Long userId = SecurityUtils.getUserId();
if (userId == null) {
return AjaxResult.warn("用户未登录");
}
orderTrade.setUserId(userId);
orderTrade.setUpdateBy(getUsername());
return toAjax(orderTradeService.updateMallProduct(orderTrade));
}
/**
*
*/
@PostMapping
public AjaxResult remove(@RequestBody IdsParam ids)
{
orderTradeService.deleteMallProductByIds(ids);
return success();
}
/**
*
*
* @param tradeEntity
* @param response
* @throws Exception
*/
@NoLogin
@PostMapping("/doPay")
public void doPay(@RequestBody OrderTrade tradeEntity, HttpServletResponse response) throws Exception {
String qrUrl = aliPayIntegration.pay(tradeEntity);
QrCodeUtil.generate(qrUrl, 300, 300, "png", response.getOutputStream());
}
}

View File

@ -0,0 +1,37 @@
package com.mcwl.web.controller.rabbitmq.config;
import com.alipay.easysdk.kernel.Config;
import com.mcwl.common.config.BusinessConfig;
import com.mcwl.common.domain.AliPayProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.common.config
* @FilenameAliPayConfig
* @Description
* @Date2025/1/3 18:45
*/
@Configuration
public class AliPayConfig {
@Autowired
private BusinessConfig businessConfig;
@Bean
public Config config() {
AliPayProperties aliPayConfig = businessConfig.getAliPayConfig();
Config config = new Config();
config.protocol = aliPayConfig.getProtocol();
config.gatewayHost = aliPayConfig.getGatewayHost();
config.signType = aliPayConfig.getSignType();
config.appId = aliPayConfig.getAppId();
config.merchantPrivateKey = aliPayConfig.getPrivateKey();
config.alipayPublicKey = aliPayConfig.getPublicKey();
config.notifyUrl = aliPayConfig.getNotifyUrl();
return config;
}
}

View File

@ -6,9 +6,11 @@ import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.core.page.TableDataInfo;
import com.mcwl.common.domain.IdsParam;
import com.mcwl.resource.domain.MallProduct;
import com.mcwl.resource.service.MallProductService;
import com.mcwl.resource.domain.vo.MallProductVo;
import com.mcwl.resource.service.MallProductService;
import com.mcwl.web.controller.common.OssUtil;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@ -35,6 +37,51 @@ public class MallProductController extends BaseController {
}
/***
*
*
* @param file
* @return
*/
@PostMapping("/file")
public AjaxResult Malifile(@RequestParam MultipartFile file){
String s = OssUtil.uploadMultipartFile(file);
return AjaxResult.success(s);
}
/***
*
* zip
* @param file
* @return
*/
@PostMapping("/zipUrlFile")
public AjaxResult zipUrlFile(@RequestParam MultipartFile file){
String s = OssUtil.uploadMultipartFile(file);
return AjaxResult.success(s);
}
/***
*
* zip
* @param file
* @return
*/
@PostMapping("/zipUrl")
public AjaxResult zipUrl(@RequestParam MultipartFile file){
String s = OssUtil.uploadMultipartFile(file);
return AjaxResult.success(s);
}
/**
*
*/
@ -50,12 +97,14 @@ public class MallProductController extends BaseController {
/**
*
*/
@GetMapping(value = "/{jobId}")
public AjaxResult getInfo(@PathVariable("jobId") Long jobId)
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long jobId)
{
return success(mallProductRuleInfoService.selectMallProductById(jobId));
}
/**
*
*/

View File

@ -0,0 +1,25 @@
package com.mcwl.web.core.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
/**
*
*/
@Configuration
public class CorsConfig {
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*");
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
return new CorsFilter(urlBasedCorsConfigurationSource);
}
}

View File

@ -172,3 +172,15 @@ aliyun:
accessKeyId: LTAI5tSHZZ8wHJRP8X4r9TXT
accessKeySecret: F82IVNx0IGJ3AnP6gSIfcyql1HCXIH
policy : https://ybl2112.oss-cn-beijing.aliyuncs.com/
mall:
mgt:
aliPayConfig:
protocol: https
gatewayHost: openapi-sandbox.dl.alipaydev.com
signType: RSA2
appId: 9021000138607290
privateKey: MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCarcUREqQVHIYq4FBuqvcYxOxsuUI3gOphRXcN0k/hIUV7fcfO9ivui99pJihbou9MmC22FM7hzFMHHl4GvZQJuw/GgJlnh9T/SlfS9Awlr0nbzVtXYOd7Os1EM4Jry2PW3zkvaWMvO3DfcYU47bqN8aw+vVBhSVeVhq41zKkH9k8UPw6Ny4WmVUHje84ykf1uBR8AqPxEeDIYD79CGGLtGLECuHoeRsVpGrNmZxwmcen1Bwf8oWiM68+Ein3S/pV69ED6x74+/WDJO71IHUJN+1DclLVXWVGriUenUzTVrAhh8RHgtF5J+t4K24qrGpbsryXzuYJ/p872ieI2oFnLAgMBAAECggEAVfbziiyJAq6qplOqgAcGcz6mgzpm4cAFAvB/XTAgcudx3VMnZA+OlPIpxR+O2Hbydegxp3tjCzzqfA9VhHuCNfI/rzuzhkWIjCV+L+Cwi5UjAETeWe6iV+tzP089UbllEHtZJc91bz+i2JwXxW7h+pdw+iFu9dK0GYcTdRT8cE6FVkBtRikUMA/bAQ4f5umF/vv5yx2XsyfCJddyI2eKIOQQ3FZ27/EEvj+hkWFGj+hcTO0zchCzYudaUyhVanJfPOTMeQrh5J9d13HXQYH0qPT4NYrLSXPjl04zAhWyZQw50kFMpkYnog0i9E9XWESSBXilALd2hITmRAj8MPqi8QKBgQDmJ4P5Fa88nvBoPvpjkevcoOP7EzokvsJuw9QHwr7mKwY5/uTrDkHmgy0iIQJ7BQmYOTW+CcwAcaquQwZrdauxsto5sG+Vle62e9FIGxqsCqrzqRS3bKY2NHUS33Ep43lA9Uz07wYchFHs17e4rTidotaWd+ONhGu2zi44vXZOMwKBgQCsDHr1fDoKplRnJ9Na+YkkpG86lGvHW8R/69dn4ur89mCGhFyexLrSA1NggAMYT9pADg4G2jYvsPa+0ynV4rg8fmvfgpO9dvv3UoOGBxxdzaxNlIdb5LsuyQMN6wcWNSQFH9qDt9nyZ5BLCQXd/DJLMtgLSBpAYi+HZD1E4Zv+CQKBgQCaDZslr+ES56QtcvIwkazZigvvtCf4DoOglo2nADC9adEKItZhi7KKtAUS0huR8oZAkRKq+G3HYk4HxK9YYHQjRn8RnEqkSq51ER29cP8CZ0WUQPmv6Ra8M5KlplBd5Hf2BfuT+yYREnSv3piIEdJSmXufTfJPeHKM8yc3LYIxxwKBgFnjK1qWTLzDqdU7OXGObdh3EKXKZYUCrOcokKH2LE99aXDeNoW8wt52XllMiFFrZtuQfEOYPjcsfb21FWZpzVfNtQ5Ral7Si1HsCks769YWXq8pqo6YMjN/UdkzscAog2kp+0BWDchX00tgq3APEze2mKlMQmrg4XQbKueR964BAoGBAMA5mWyKVfphQ2SsOrYSF5hQ7PBaTT/gLLU2CWBcCXge4oO7dd3MIsd2+7cJG9uYPiSgJdLGqmVfet4pBXNd4znYjHunRr6BukTZzQSNujn0j2fr3SDN46vuqVjYsPF05hGWy3XH5NflrTHq7RO6qkqcqxdaSCRZO7a9G+ckzvx/
publicKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjehzFgsbjUfksMRBGsYGi/ycg5/SMP8jmGMbRWbiVmDVKO8GdVI0StLZvfLi8ozUPcGrJzQL3HaXx+b88JXQPJ2ftUiBvQnoAf+qzWKqsqXo40uuy6DZc+0LAGoxup2WyFp4YcIf+XFMJBSGmQaGSqYs3Lx49/aWI1uFTzBL4YF4X7ckXm6Cl2xr5gD1Gl1twbKIyeDnAZal2Eego4pLwFkcP6jZFaAY0V3YqTfhZLAl5NK+K4BCB2iQPOiK6Qr5XMRhnUVQVeZr5T9PmYf1GyncBIWgUaZlmGNq6Yup2trQW/mEqDqzeek4N3NuoORdZ2JBAnLdqAjQyRBrQAnkbQIDAQAA
notifyUrl: http://susan.net.cn/notify

View File

@ -17,12 +17,18 @@
</description>
<dependencies>
<!--OSS-->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.17.4</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>

View File

@ -0,0 +1,38 @@
package com.mcwl.common.config;
import com.mcwl.common.config.properties.QuartzThreadPoolProperties;
import com.mcwl.common.domain.AliPayProperties;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.common.config
* @FilenameBusinessConfig
* @Description TODO
* @Date2025/1/3 18:46
*/
@Data
@Component
@Slf4j
@ConfigurationProperties(prefix = "mall.mgt")
public class BusinessConfig {
/**
* 线
*/
private QuartzThreadPoolProperties QuartzThreadPoolConfig = new QuartzThreadPoolProperties();
/**
* index
*/
private String productEsIndexName = "product-es-index-v1";
/**
*
*/
private AliPayProperties aliPayConfig = new AliPayProperties();
}

View File

@ -0,0 +1,34 @@
package com.mcwl.common.config.properties;
import lombok.Data;
@Data
public class QuartzThreadPoolProperties {
/**
* 线
*/
private int corePoolSize = 8;
/**
* 线
*/
private int maxPoolSize = 10;
/**
*
*/
private int queueSize = 200;
/**
* 线
*/
private int keepAliveSeconds = 30;
/**
* 线
*/
private String threadNamePrefix = "QuartzThread";
}

View File

@ -0,0 +1,23 @@
package com.mcwl.common.domain;
import lombok.Data;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.common.domain
* @FilenameAliPayProperties
* @Description
* @Date2025/1/3 18:45
*/
@Data
public class AliPayProperties {
private String protocol;
private String gatewayHost;
private String signType;
private String appId;
private String privateKey;
private String publicKey;
private String notifyUrl;
}

View File

@ -0,0 +1,16 @@
package com.mcwl.common.interfaces;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
*
*
* @author
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface NoLogin {
}

37
mcwl-pay/pom.xml 100644
View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mcwl</groupId>
<artifactId>mcwl</artifactId>
<version>3.8.8</version>
</parent>
<artifactId>mcwl-pay</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<description>
pay支付模块
</description>
<dependencies>
<!-- 通用工具-->
<dependency>
<groupId>com.mcwl</groupId>
<artifactId>mcwl-common</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,94 @@
package com.mcwl.pay.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mcwl.common.core.domain.BaseEntity;
import com.mcwl.common.interfaces.MaxMoney;
import com.mcwl.common.interfaces.MinMoney;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotNull;
import java.util.Date;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.pay.domain
* @FilenameOrderTrade
* @Description TODO
* @Date2025/1/3 14:15
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
@TableName("order_trade")
public class OrderTrade extends BaseEntity {
/**
* ID
*/
@TableId
private Long id;
/**
*
*/
private String code;
/**
* ID
*/
private Long userId;
/**
* ID
*/
private Integer productId;
/**
*
*/
private String productName;
/**
*
*/
private String userName;
/**
*
*/
private String paymentMethod;
/**
*
*/
private Integer transactionId;
/**
*
*/
@JsonFormat(pattern = "yyyy-mm-dd")
@DateTimeFormat(pattern = "yyyy-mm-dd")
private Date orderTime;
/**
* 1: 2: 3 4
*/
@NotNull(message = "状态不能为空")
private Integer orderStatus;
/**
* 1: 2: 3退
*/
@NotNull(message = "状态不能为空")
private Integer payStatus;
/**
*
*/
@NotNull(message = "总金额不能为空")
@MinMoney(value = 0, message = "总金额不能小于0")
@MaxMoney(value = 100000, message = "总金额必须小于100000")
private Integer totalAmount;
/**
*
*/
@NotNull(message = "付款金额不能为空")
@MinMoney(value = 0, message = "付款金额不能小于0")
@MaxMoney(value = 100000, message = "付款金额必须小于100000")
private Integer paymentAmount;
}

View File

@ -0,0 +1,102 @@
package com.mcwl.pay.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Map;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.pay.domain
* @FilenamePaymentResult
* @Description TODO
* @Date2025/1/3 17:30
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
public class PaymentResult {
private boolean success;
private String message;
private String transactionId;
private String errorCode;
private BigDecimal amount;
private String currency;
private String paymentMethod;
private LocalDateTime timestamp;
private Map<String, Object> extraData;
public static class Builder {
private final PaymentResult result = new PaymentResult();
public Builder setSuccess(boolean success) {
result.success = success;
return this;
}
public Builder setMessage(String message) {
result.message = message;
return this;
}
public Builder setTransactionId(String transactionId) {
result.transactionId = transactionId;
return this;
}
public Builder setErrorCode(String errorCode) {
result.errorCode = errorCode;
return this;
}
public Builder setAmount(BigDecimal amount) {
result.amount = amount;
return this;
}
public Builder setCurrency(String currency) {
result.currency = currency;
return this;
}
public Builder setPaymentMethod(String paymentMethod) {
result.paymentMethod = paymentMethod;
return this;
}
public Builder setTimestamp(LocalDateTime timestamp) {
result.timestamp = timestamp;
return this;
}
public Builder setExtraData(Map<String, Object> extraData) {
result.extraData = extraData;
return this;
}
public PaymentResult build() {
return result;
}
}
@Override
public String toString() {
return "PaymentResult{" +
"success=" + success +
", message='" + message + '\'' +
", transactionId='" + transactionId + '\'' +
", errorCode='" + errorCode + '\'' +
", amount=" + amount +
", currency='" + currency + '\'' +
", paymentMethod='" + paymentMethod + '\'' +
", timestamp=" + timestamp +
", extraData=" + extraData +
'}';
}
}

View File

@ -0,0 +1,33 @@
package com.mcwl.pay.domain.enums;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.pay.domain
* @FilenamePaymentStatus
* @Description TODO
* @Date2025/1/3 17:24
*/
public enum PaymentStatus {
PENDING("待支付"),
COMPLETED("已支付"),
FAILED("支付失败"),
REFUNDED("已退款");
private final String description;
PaymentStatus(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
@Override
public String toString() {
return name() + "(" + description + ")";
}
}

View File

@ -0,0 +1,21 @@
package com.mcwl.pay.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mcwl.pay.domain.OrderTrade;
import com.mcwl.pay.domain.PaymentResult;
import org.apache.ibatis.annotations.Mapper;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.pay.mapper
* @FilenameOrderTradeMapper
* @Description TODO
* @Date2025/1/3 14:51
*/
@Mapper
public interface OrderTradeMapper extends BaseMapper<OrderTrade> {
PaymentResult chargeCard(Integer totalAmount, String paymentMethod);
}

View File

@ -0,0 +1,28 @@
package com.mcwl.pay.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.mcwl.common.domain.IdsParam;
import com.mcwl.pay.domain.OrderTrade;
import java.util.List;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.pay.service
* @FilenameOrderTradeService
* @Description TODO
* @Date2025/1/3 14:51
*/
public interface OrderTradeService extends IService<OrderTrade> {
List<OrderTrade> selectMallProductList(OrderTrade orderTrade);
int insertMallProduct(OrderTrade orderTrade);
void deleteMallProductByIds(IdsParam ids);
int updateMallProduct(OrderTrade orderTrade);
}

View File

@ -0,0 +1,104 @@
package com.mcwl.pay.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mcwl.common.domain.IdsParam;
import com.mcwl.common.utils.StringUtils;
import com.mcwl.pay.domain.OrderTrade;
import com.mcwl.pay.domain.PaymentResult;
import com.mcwl.pay.domain.enums.PaymentStatus;
import com.mcwl.pay.mapper.OrderTradeMapper;
import com.mcwl.pay.service.OrderTradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.pay.service.impl
* @FilenameOrderTradeServiceImpl
* @Description TODO
* @Date2025/1/3 14:51
*/
@Service
public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTrade> implements OrderTradeService {
@Autowired
private OrderTradeMapper orderTradeMapper;
@Override
public List<OrderTrade> selectMallProductList(OrderTrade orderTrade) {
// 创建一个 LambdaQueryWrapper 实例
LambdaQueryWrapper<OrderTrade> queryWrapper = new LambdaQueryWrapper<>();
// 使用非空检查来添加查询条件
if (StringUtils.isNotNull(orderTrade.getCode())) {
queryWrapper.eq(OrderTrade::getCode, orderTrade.getCode());
}
if (StringUtils.isNotNull(orderTrade.getUserId())) {
queryWrapper.eq(OrderTrade::getUserId, orderTrade.getUserId());
}
if (StringUtils.isNotNull(orderTrade.getProductId())) {
queryWrapper.eq(OrderTrade::getProductId, orderTrade.getProductId());
}
if (StringUtils.isNotNull(orderTrade.getProductName())) {
queryWrapper.like(OrderTrade::getProductName, orderTrade.getProductName());
}
if (StringUtils.isNotNull(orderTrade.getUserName())) {
queryWrapper.eq(OrderTrade::getUserName, orderTrade.getUserName());
}
if (StringUtils.isNotNull(orderTrade.getOrderTime())) {
queryWrapper.eq(OrderTrade::getOrderTime, orderTrade.getOrderTime());
}
if (StringUtils.isNotNull(orderTrade.getOrderStatus())) {
queryWrapper.eq(OrderTrade::getOrderStatus, orderTrade.getOrderStatus());
}
if (StringUtils.isNotNull(orderTrade.getPayStatus())) {
queryWrapper.eq(OrderTrade::getPayStatus, orderTrade.getPayStatus());
}
if (StringUtils.isNotNull(orderTrade.getTotalAmount())) {
queryWrapper.eq(OrderTrade::getTotalAmount, orderTrade.getTotalAmount());
}
if (StringUtils.isNotNull(orderTrade.getPaymentAmount())) {
queryWrapper.eq(OrderTrade::getPaymentAmount, orderTrade.getPaymentAmount());
}
return orderTradeMapper.selectList(queryWrapper);
}
@Override
public int insertMallProduct(OrderTrade orderTrade) {
PaymentResult paymentResult = orderTradeMapper.chargeCard(orderTrade.getTotalAmount(), orderTrade.getPaymentMethod());
if (paymentResult.isSuccess()) {
// 支付成功后的处理:更新订单状态、生成激活码、更新用户权限等
orderTrade.setOrderStatus(PaymentStatus.COMPLETED.ordinal());
// 保存订单
return orderTradeMapper.insert(orderTrade);
} else {
// 支付失败处理...
orderTrade.setOrderStatus(PaymentStatus.FAILED.ordinal());
}
return 0;
}
@Override
public void deleteMallProductByIds(IdsParam ids) {
orderTradeMapper.deleteBatchIds(ids.getIds());
}
@Override
public int updateMallProduct(OrderTrade orderTrade) {
return orderTradeMapper.updateById(orderTrade);
}
}

View File

@ -28,11 +28,11 @@ public class MallProduct extends BaseEntity {
* ID
*/
@TableId
private Integer productId;
private Long productId;
/**
* ID
*/
private Integer userId;
private Long userId;
/**
*
*/

View File

@ -239,6 +239,7 @@
<module>mcwl-myInvitation</module>
<module>mcwl-resource</module>
<module>mcwl-memberCenter</module>
<module>mcwl-pay</module>
</modules>
<packaging>pom</packaging>