diff --git a/bawei-base/base-es/base-es-common/src/main/java/com/bawei/common/domain/FuzzyQuery.java b/bawei-base/base-es/base-es-common/src/main/java/com/bawei/common/domain/FuzzyQuery.java new file mode 100644 index 0000000..5dd3ce2 --- /dev/null +++ b/bawei-base/base-es/base-es-common/src/main/java/com/bawei/common/domain/FuzzyQuery.java @@ -0,0 +1,23 @@ +package com.bawei.common.domain; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 模糊查询对象 + * + * @program: mall_cloud + * @ClassName: FuzzyQuery + * @author: Gyc + * @create: 2024-04-28 20:37 + **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class FuzzyQuery { + //根据多个字段查询 + private String[] fields; + //值 + private String value; +} diff --git a/bawei-base/base-es/base-es-common/src/main/java/com/bawei/common/domain/MultiQuery.java b/bawei-base/base-es/base-es-common/src/main/java/com/bawei/common/domain/MultiQuery.java new file mode 100644 index 0000000..accb77c --- /dev/null +++ b/bawei-base/base-es/base-es-common/src/main/java/com/bawei/common/domain/MultiQuery.java @@ -0,0 +1,27 @@ +package com.bawei.common.domain; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @program: mall_cloud + * @ClassName: MultiQuery + * @author: Gyc + * @create: 2024-04-28 12:27 + **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class MultiQuery { + + private String indexName; + //模糊查询对象 + private FuzzyQuery fuzzyQuery; + //精确查询对象 + private PreciseQuery preciseQuery; + //区间查询对象 + private SectionQuery sectionQuery; + //排序对象 + private Sort sort; +} diff --git a/bawei-base/base-es/base-es-common/src/main/java/com/bawei/common/domain/PreciseQuery.java b/bawei-base/base-es/base-es-common/src/main/java/com/bawei/common/domain/PreciseQuery.java new file mode 100644 index 0000000..f61b1ed --- /dev/null +++ b/bawei-base/base-es/base-es-common/src/main/java/com/bawei/common/domain/PreciseQuery.java @@ -0,0 +1,25 @@ +package com.bawei.common.domain; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * 精确查询对象 + * + * @program: mall_cloud + * @ClassName: PreciseQuery + * @author: Gyc + * @create: 2024-04-28 20:37 + **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class PreciseQuery { + //字段 + private String field; + //值 + private String value; +} diff --git a/bawei-base/base-es/base-es-common/src/main/java/com/bawei/common/domain/SectionQuery.java b/bawei-base/base-es/base-es-common/src/main/java/com/bawei/common/domain/SectionQuery.java new file mode 100644 index 0000000..25bd265 --- /dev/null +++ b/bawei-base/base-es/base-es-common/src/main/java/com/bawei/common/domain/SectionQuery.java @@ -0,0 +1,27 @@ +package com.bawei.common.domain; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 区间查询对象 + * + * @program: mall_cloud + * @ClassName: SectionQuery + * @author: Gyc + * @create: 2024-04-28 12:21 + **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class SectionQuery { + //对多个字段进行区间查询 + private String field; + //区间查询的起始值 + private Object start; + //区间查询的结束值 + private Object end; + + +} diff --git a/bawei-base/base-es/base-es-common/src/main/java/com/bawei/common/domain/Sort.java b/bawei-base/base-es/base-es-common/src/main/java/com/bawei/common/domain/Sort.java new file mode 100644 index 0000000..589ff05 --- /dev/null +++ b/bawei-base/base-es/base-es-common/src/main/java/com/bawei/common/domain/Sort.java @@ -0,0 +1,23 @@ +package com.bawei.common.domain; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 排序对象 + * + * @program: mall_cloud + * @ClassName: Sort + * @author: Gyc + * @create: 2024-04-28 20:38 + **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class Sort { + // 排序字段 + private Integer pageNum=1; + // 每页显示条数 + private Integer pageSize = 10 ; +} diff --git a/bawei-base/base-es/base-es-server/pom.xml b/bawei-base/base-es/base-es-server/pom.xml index e1b2fe7..b47f2cc 100644 --- a/bawei-base/base-es/base-es-server/pom.xml +++ b/bawei-base/base-es/base-es-server/pom.xml @@ -18,6 +18,12 @@ UTF-8 + + + org.apache.httpcomponents + httpclient + 4.5.3 + com.github.xiaoymin knife4j-openapi3-spring-boot-starter diff --git a/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/config/HttpComponentsClientRestfulHttpRequestFactory.java b/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/config/HttpComponentsClientRestfulHttpRequestFactory.java new file mode 100644 index 0000000..a8c0aeb --- /dev/null +++ b/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/config/HttpComponentsClientRestfulHttpRequestFactory.java @@ -0,0 +1,35 @@ +package com.bawei.es.config; + +import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; +import org.apache.http.client.methods.HttpUriRequest; +import org.springframework.http.HttpMethod; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; + +import java.net.URI; + +public class HttpComponentsClientRestfulHttpRequestFactory extends HttpComponentsClientHttpRequestFactory { + @Override + protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) { + + if (httpMethod == HttpMethod.GET) { + return new HttpGetRequestWithEntity(uri); + } + return super.createHttpUriRequest(httpMethod, uri); + } + + /** + * 定义HttpGetRequestWithEntity实现HttpEntityEnclosingRequestBase抽象类,以支持GET请求携带body数据 + */ + private static final class HttpGetRequestWithEntity extends HttpEntityEnclosingRequestBase { + public HttpGetRequestWithEntity(final URI uri) { + super.setURI(uri); + } + + @Override + public String getMethod() { + return HttpMethod.GET.name(); + + } + } +} + diff --git a/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/config/RestTemplateConfig.java b/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/config/RestTemplateConfig.java new file mode 100644 index 0000000..602598c --- /dev/null +++ b/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/config/RestTemplateConfig.java @@ -0,0 +1,31 @@ +package com.bawei.es.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.http.client.ClientHttpRequestFactory; +import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +@Component +public class RestTemplateConfig { + + @Bean + public RestTemplate restTemplate(){ + RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory()); + //支持http请求get方式以json对象的形式请求 + restTemplate.setRequestFactory(new HttpComponentsClientRestfulHttpRequestFactory()); + return restTemplate; + } + + // 设置超时时间 + public ClientHttpRequestFactory clientHttpRequestFactory(){ + //创建一个httpClient简单工厂 + SimpleClientHttpRequestFactory factory=new SimpleClientHttpRequestFactory(); + //设置连接超时时间,单位ms + factory.setConnectTimeout(15000); + //设置读取超时时间,单位ms + factory.setReadTimeout(10000); + return factory; + } +} + diff --git a/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/demo/demo.java b/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/demo/demo.java new file mode 100644 index 0000000..91d39c5 --- /dev/null +++ b/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/demo/demo.java @@ -0,0 +1,19 @@ +package com.bawei.es.demo; + +import com.bawei.es.config.RestTemplateConfig; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * @program: mall_cloud + * @ClassName: demo + * @author: Gyc + * @create: 2024-04-29 12:28 + **/ +public class demo { + public static void main(String[] args) { + + + + + } +} diff --git a/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/demo/pojo/User.java b/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/demo/pojo/User.java new file mode 100644 index 0000000..fbe732a --- /dev/null +++ b/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/demo/pojo/User.java @@ -0,0 +1,18 @@ +package com.bawei.es.demo.pojo; + +import lombok.Data; + +/** + * @program: mall_cloud + * @ClassName: User + * @author: Gyc + * @create: 2024-05-01 14:08 + **/ +@Data +public class User { + private String name; + private Integer age; + + + +} diff --git a/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/service/impl/EsDocServiceImpl.java b/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/service/impl/EsDocServiceImpl.java index c017c59..872703b 100644 --- a/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/service/impl/EsDocServiceImpl.java +++ b/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/service/impl/EsDocServiceImpl.java @@ -41,7 +41,11 @@ import java.util.*; public class EsDocServiceImpl implements EsDocService { @Autowired private RestHighLevelClient restHighLevelClient; - + /** + * 批量添加文档 + * @param indexName + * @param docMsg + */ @Override public void batchAddDoc(String indexName, Map docMsg) { BulkRequest bulkRequest = new BulkRequest(); @@ -62,6 +66,11 @@ public class EsDocServiceImpl implements EsDocService { } } + /** + * 批量删除 + * @param indexName + * @param ids + */ @Override public void bathDeleteDoc(String indexName, List ids) { BulkRequest bulkRequest = new BulkRequest(); @@ -83,6 +92,12 @@ public class EsDocServiceImpl implements EsDocService { } + /** + * 搜索 + * @param indexName + * @param docMsg + * @return + */ @Override public R queryList(String indexName, Map docMsg) { // 验证索引名称 @@ -103,6 +118,11 @@ public class EsDocServiceImpl implements EsDocService { return R.ok(response); } + /** + * 搜索请求 + * @param searchResponse + * @return + */ private ConmtMap processSearchResponse(SearchResponse searchResponse) { ConmtMap conmtMap = new ConmtMap(); long total = searchResponse.getHits().getTotalHits().value; @@ -124,6 +144,11 @@ public class EsDocServiceImpl implements EsDocService { return conmtMap; } + /** + * 高亮请求 + * @param highlightFields + * @param parsedObject + */ private void addHighlightedFields(Map highlightFields, Map parsedObject) { if (!highlightFields.isEmpty()) { for (Map.Entry entry : highlightFields.entrySet()) { @@ -151,7 +176,8 @@ public class EsDocServiceImpl implements EsDocService { // 设置排序参数 setSortParameters(docMsg,sourceBuilder); - + //精确查找 + setFuzzyParameters(docMsg,sourceBuilder); // 设置高亮参数 setHighlightParameters(docMsg,sourceBuilder); @@ -162,6 +188,17 @@ public class EsDocServiceImpl implements EsDocService { return request; } + private void setFuzzyParameters(Map docMsg, SearchSourceBuilder sourceBuilder) { + + Map fuzzy = (Map) docMsg.get("fuzzy"); + if (fuzzy!=null){ + BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder(); + boolQueryBuilder.must(QueryBuilders.termQuery((String) fuzzy.get("field"),(String) fuzzy.get("value"))); + sourceBuilder.query(boolQueryBuilder); + } + + } + private void setHighlightParameters(Map docMsg, SearchSourceBuilder sourceBuilder) { // 获取高亮参数 Map highlight = (Map) docMsg.get("highlight"); diff --git a/bawei-base/base-es/base-es-server/src/main/resources/bootstrap.yml b/bawei-base/base-es/base-es-server/src/main/resources/bootstrap.yml index da77dc3..7511026 100644 --- a/bawei-base/base-es/base-es-server/src/main/resources/bootstrap.yml +++ b/bawei-base/base-es/base-es-server/src/main/resources/bootstrap.yml @@ -51,11 +51,3 @@ feign: min-request-size: 8192 response: enabled: true -# feign 配置 -feign: - compression: - request: - enabled: true - min-request-size: 8192 - response: - enabled: true diff --git a/bawei-common/bawei-common-security/src/main/java/com/bawei/common/security/utils/SecurityUtils.java b/bawei-common/bawei-common-security/src/main/java/com/bawei/common/security/utils/SecurityUtils.java index 4ae0c32..9c71b8c 100644 --- a/bawei-common/bawei-common-security/src/main/java/com/bawei/common/security/utils/SecurityUtils.java +++ b/bawei-common/bawei-common-security/src/main/java/com/bawei/common/security/utils/SecurityUtils.java @@ -8,6 +8,7 @@ import com.bawei.common.core.context.SecurityContextHolder; import com.bawei.common.core.utils.ServletUtils; import com.bawei.common.core.utils.StringUtils; import com.bawei.system.domain.model.LoginUser; +import org.springframework.stereotype.Component; /** * 权限获取工具类 diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-common/pom.xml b/bawei-mall/bawei-mall-car/bawei-mall-car-common/pom.xml new file mode 100644 index 0000000..a64b611 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-common/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + + com.bawei + bawei-mall-car + 3.6.0 + + + bawei-mall-car-common + + + 17 + 17 + UTF-8 + + + + + com.bawei + bawei-common-core + + + + diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/config/AlipayConfig.java b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/config/AlipayConfig.java new file mode 100644 index 0000000..5842997 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/config/AlipayConfig.java @@ -0,0 +1,47 @@ +package com.bawei.mall.car.config; + +import org.springframework.stereotype.Component; + +/** + * @author GYC + */ /* * + *类名:AlipayConfig + *功能:基础配置类 + *详细:设置帐户有关信息及返回路径 + *修改日期:2017-04-05 + *说明: + *以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。 + *该代码仅供学习和研究支付宝接口使用,只是提供一个参考。 + */ +public class AlipayConfig { + +//↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ + + // 应用ID,您的APPID,收款账号既是您的APPID对应支付宝账号 + public static String app_id = "9021000136694024"; + + // 商户私钥,您的PKCS8格式RSA2私钥 + public static String merchant_private_key = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCFz/238QvZGbGw9EXAihMzA/wBLprkwCZN2PlZAWBJRI28L+rO8xAtgeC6AVarRGF6e0qMZ4LLWtOgL1RyfxOL2I/Ny+F8jmY0wEZABt6WKI1/l9HliZ/hxNoko4IHo6tf7NEhZJMmAce088PB3IVmFWv1aaSOL7/WaZlSiz/80ZA2v7oHzntblVm1FHFok7kCumndzdj8SgaPtZRA964lx3zhQHWV2O22ThhqN6zksJzXsQoPFvIv8Ic5ymYPzCvnSs7U5jyHMwQ1btYXgUMbv1Uqo9It2U0Gq3P4rZFMjfPn5FSdLaWepTpSg69Ittqo3YCzBmlKZjVmBc5W9thHAgMBAAECggEAF3AJ2akP0TPt6reua/4DROFCx5Y5LS32x5XkftF94vdt9/NQpnTudXoVOZ84ZgExLbngod0TjLjY7mq72N4nN0x0S7CVSzLJ9h1jcJ2DaTurJRkbe5/ycCIBr38wLFRflQquyrGKEJMpPqmftRoCB5Ji+XZKi1kTueN/JnUbfRWavAagK6YK8qlZYAiQr+PXiLcF2U3qcB7BgqVb7BJU5g/IiotHE+0ijtqWcT+X9ElIqw5mgmkvRZBPy5iVeD/b2F5b4Mbr9MvQkaICzt+P8QZCTKyd31GOhSV6zYguaisN16uC5DKRNZ4d1nbWOSR5ifCu1FH8t1cGy+OstVFzIQKBgQDFP9ZKc1wo5U/+zL8Bz9JteWEs1X6NzHu9yF62pgHg6G8L+YnQhFUtR8yQ1f782Fkdsl6YyXv89PXAcYHQJJax5JK2ONQD+tb6BUhOt2kq1d2ZJhX4nDeUJfpsKuaXnbsRc5A9D/HmUlZvsAxZoZ367WOi6WudP6DwDlG0g58xlwKBgQCtqx99lENuTQ0K8qNuSwWvQb+APf6zlGdqT7G1rQTPtNJ79ZyECQNUC9FzsIstQIWvLQO6PzYpa/aTZst44sWFPtyqTY0+ECUO5/KC/Ap5AROuy1/rMEaUQ93hT54TTLVm0g3fwnUCOJX9iUXJk63gxXCdyCi+8ZkLNEcwWa8E0QKBgBNJUqKk9PXqtg+r5WE/+MtLevzvQxiKTe8YkGo7gSOElpcNJzSEO+/ZfV8MDYqbfNsyfZ1i1gS9zumqL48yhKmQN+gpVlGtTSfVLGTF+jp9/tTirHNKkwShUgMRjsp0Wb4zFn9h970Vf+4bwJli/Bd07rEXMbaGai4OuF52IDKxAoGAHeN4jPVKUZ5jI0I1DFNPDCWFnr2Mqz1cOviyPfEkBdc57mmL4VFnyDwsdPuqSER1fXuCy7f7S0+wZRfo5sooclEqSwkDyO2gYxtaKl7UMpUT3R5VSLXLP9MaSZ+ZNfsasTJvftYJqzMv5S2N3C5VW3y/b/g1wv7zdvEtW03kCDECgYEAnY21ReTt6HtLcX4iGAX1PKfGU251b5a2Kw4xcX/oNkzWHeVL9URDmlB93paNLg6QuskeSiwgPmitUGtKWNAfyZnWESAfCZkGza0+aJjni4LbxcnFHJcYMmuWMZxLB6IaOlDPnneKv0DWSydIkotDCDnFz4BPnim962ilILRLnWY="; + + // 支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。 + public static String alipay_public_key = ""; + + // 服务器异步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问 + public static String notify_url = ""; + + // 页面跳转同步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问 + public static String return_url = ""; + + // 签名方式 + public static String sign_type = "RSA2"; + + // 字符编码格式 + public static String charset = "utf-8"; + + // 支付宝网关 + public static String gatewayUrl = "https://openapi.alipay.com/gateway.do"; + + // 支付宝网关 + public static String log_path = "C:\\"; +} + diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/Car.java b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/Car.java new file mode 100644 index 0000000..9e20422 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/Car.java @@ -0,0 +1,24 @@ +package com.bawei.mall.car.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @program: mall_cloud + * @ClassName: Car + * @author: Gyc + * @create: 2024-05-06 15:55 + **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class Car { + @ApiModelProperty(value = "主键") + private Integer id; + @ApiModelProperty(value = "购物车id") + private String carId; + @ApiModelProperty(value = "用户id") + private Integer userId; +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/CarBySku.java b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/CarBySku.java new file mode 100644 index 0000000..68358a5 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/CarBySku.java @@ -0,0 +1,38 @@ +package com.bawei.mall.car.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +/** + * 中间表 + * + * @program: mall_cloud + * @ClassName: CarBySku + * @author: Gyc + * @create: 2024-05-06 15:58 + **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class CarBySku { + @ApiModelProperty(value = "主键") + private Integer id; + @ApiModelProperty(value = "购物车id") + private String carId; + @ApiModelProperty(value = "skuId") + private Integer skuId; + @ApiModelProperty(value = "数量") + private Integer number; + @ApiModelProperty(value = "创建人") + private Integer createBy; + @ApiModelProperty(value = "创建时间") + private Date createTime; + @ApiModelProperty(value = "更新人") + private Integer updateBy; + @ApiModelProperty(value = "更新时间") + private Date updateTime; +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/MallProductSkuCarInfo.java b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/MallProductSkuCarInfo.java new file mode 100644 index 0000000..ae47baf --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/MallProductSkuCarInfo.java @@ -0,0 +1,28 @@ +package com.bawei.mall.car.domain; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.util.List; + +/** + * 购物车 + * + * @program: mall_cloud + * @ClassName: MallProductSkuCarInfo + * @author: Gyc + * @create: 2024-05-08 10:30 + **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class MallProductSkuCarInfo { + + private List productSkuInfo; + + private ProductPrices productPrices; + + +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/Order.java b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/Order.java new file mode 100644 index 0000000..20acaaa --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/Order.java @@ -0,0 +1,43 @@ +package com.bawei.mall.car.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * 订单表 + * + * @program: mall_cloud + * @ClassName: Order + * @author: Gyc + * @create: 2024-05-10 15:20 + **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class Order { + //主键 + private Integer id; + //skuId + private Integer skuId; + //订单号 + private String orderId; + //商品名称 + private String productName; + //商品sku名称 + private String productSku; + //商品图片 + private String productUrl; + //商品价格 + private BigDecimal productPrice; + //商品数量 + private Integer productNum; + //购买数量 + private Integer buyNumber; + +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/OrderByUser.java b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/OrderByUser.java new file mode 100644 index 0000000..3599967 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/OrderByUser.java @@ -0,0 +1,74 @@ +package com.bawei.mall.car.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * 订单用户关联表 + * + * @program: mall_cloud + * @ClassName: OrderByUser + * @author: Gyc + * @create: 2024-05-10 19:32 + **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class OrderByUser { + private Integer id; + private String orderId; + private Integer userId; + private Integer discountId; + //订单状态 0未支付 1已支付 2已取消 3已退款 4已过期 + private Integer status; + //购买数量 + private Integer number; + //订单创建时间 + private Date createTime; + //订单支付时间 + private Date payTime; + //订单总金额 + private BigDecimal totalPrice; + //订单支付类型 + private Integer payType; + //优惠金额 + private BigDecimal discountPrice; + //订单实际支付金额 + private BigDecimal payPrice; + //支付积分 + private Integer payIntegral; + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/OrderByUserInfo.java b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/OrderByUserInfo.java new file mode 100644 index 0000000..1d9478b --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/OrderByUserInfo.java @@ -0,0 +1,24 @@ +package com.bawei.mall.car.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @program: mall_cloud + * @ClassName: OrderByUserInfo + * @author: Gyc + * @create: 2024-05-10 12:43 + **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class OrderByUserInfo { + private List orderList; + private OrderByUser orderByUser; + +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/OrderInfo.java b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/OrderInfo.java new file mode 100644 index 0000000..7ec32d7 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/OrderInfo.java @@ -0,0 +1,25 @@ +package com.bawei.mall.car.domain; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @program: mall_cloud + * @ClassName: OrderInfo + * @author: Gyc + * @create: 2024-05-10 20:03 + **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class OrderInfo { + //订单编号 + private Integer orderId; + //订单状态 + private Integer productStatus; + //商品信息 + private ProductSkuInfo productSkuInfo; + //订单价格 + private ProductPrices productPrices; +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/ProductPrices.java b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/ProductPrices.java new file mode 100644 index 0000000..1ea230e --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/ProductPrices.java @@ -0,0 +1,26 @@ +package com.bawei.mall.car.domain; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +/** + * @program: mall_cloud + * @ClassName: ProductPrices + * @author: Gyc + * @create: 2024-05-08 14:01 + **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ProductPrices { + //总价格 + private BigDecimal price; + //优惠 + private BigDecimal specialOffer; + //优惠后价格 + private BigDecimal afterDiscounts; + +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/ProductSkuInfo.java b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/ProductSkuInfo.java new file mode 100644 index 0000000..113e6b3 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-common/src/main/java/com/bawei/mall/car/domain/ProductSkuInfo.java @@ -0,0 +1,40 @@ +package com.bawei.mall.car.domain; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.math.BigDecimal; + +/** + * @program: mall_cloud + * @ClassName: ProductSkuInfo + * @author: Gyc + * @create: 2024-05-08 10:31 + **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ProductSkuInfo implements Serializable { + //skuId + private Long skuId; + //购物车编号 + private String carId; + //sku名称 + private String skuName; + //价格 + private BigDecimal skuPrice; + //商品名称 + private String title; + //主图 + private String image; + //商品数量 + private Integer buyNumber; + //购买数量 + private Integer number; + + + + +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/pom.xml b/bawei-mall/bawei-mall-car/bawei-mall-car-server/pom.xml new file mode 100644 index 0000000..e59f58f --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/pom.xml @@ -0,0 +1,109 @@ + + + 4.0.0 + + com.bawei + bawei-mall-car + 3.6.0 + + + bawei-mall-car-server + + + 8 + 8 + UTF-8 + + + + com.alipay.sdk + alipay-sdk-java + 4.39.70.ALL + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + io.springfox + springfox-swagger-ui + ${swagger.fox.version} + + + + + mysql + mysql-connector-java + + + + + com.bawei + bawei-common-datasource + + + + + com.bawei + bawei-common-datascope + + + + + com.bawei + bawei-common-log + + + + + com.bawei + bawei-common-swagger + + + + com.bawei + bawei-mall-car-common + 3.6.0 + + + org.springframework.data + spring-data-redis + + + com.bawei + bawei-common-security + + + com.bawei + bawei-common-swagger + + + com.bawei + bawei-mall-product-common + + + + diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/BaweiMallCarApplication.java b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/BaweiMallCarApplication.java new file mode 100644 index 0000000..08778fa --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/BaweiMallCarApplication.java @@ -0,0 +1,26 @@ +package com.bawei.mall.car; + +import com.bawei.common.security.annotation.EnableCustomConfig; +import com.bawei.common.security.annotation.EnableRyFeignClients; +import com.bawei.common.swagger.annotation.EnableCustomSwagger2; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; + +/** + * @program: mall_cloud + * @ClassName: BaweiMallCarApplication + * @author: Gyc + * @create: 2024-05-06 11:54 + **/ +@EnableCustomConfig +@EnableCustomSwagger2 +@EnableRyFeignClients +@SpringBootApplication +@EnableScheduling +public class BaweiMallCarApplication { + public static void main(String[] args) { + SpringApplication.run(BaweiMallCarApplication.class,args); + System.out.println("(♥◠‿◠)ノ゙ 购物车模块启动成功 ლ(´ڡ`ლ)゙ "); + } +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/controller/CarController.java b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/controller/CarController.java new file mode 100644 index 0000000..fa74d40 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/controller/CarController.java @@ -0,0 +1,59 @@ +package com.bawei.mall.car.controller; + +import com.bawei.common.core.domain.R; +import com.bawei.mall.car.service.CarService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.lang.reflect.Array; +import java.util.List; + + +/** + * 购物车控制层 + * + * @program: mall_cloud + * @ClassName: CarController + * @author: Gyc + * @create: 2024-05-06 16:02 + **/ +@RestController +public class CarController { + @Autowired + private CarService carService; + + @PostMapping("/addCar") + public R addCar(@RequestParam Integer skuId,@RequestParam Integer status){ + carService.addCar(skuId, status); + return R.ok(); + } + + @PostMapping("/updCar") + public R updCar(@RequestParam Integer skuId, @RequestParam Integer num){ + carService.updCar(skuId, num); + return R.ok(); + } + + @PostMapping("/cleanCar") + public R delCar(){ + carService.delCar(); + return R.ok(); + } + + @PostMapping("/delById") + public R delById(@RequestParam("skuIds") String skuIds){ + carService.delById(skuIds); + return R.ok(); + } + + //查询接口 + @PostMapping("/calculate") + public R calculate(){ + return R.ok(carService.calculate()); + } + + + +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/controller/OrderController.java b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/controller/OrderController.java new file mode 100644 index 0000000..9fb3846 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/controller/OrderController.java @@ -0,0 +1,31 @@ +package com.bawei.mall.car.controller; + +import com.bawei.common.core.domain.R; +import com.bawei.mall.car.service.OrderService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * 订单控制层 + * + * @program: mall_cloud + * @ClassName: OrderController + * @author: Gyc + * @create: 2024-05-10 19:33 + **/ +@RestController +public class OrderController { + @Autowired + private OrderService orderService; + + @PostMapping("/addOrder") + public R addOrder(@RequestBody List skuIds) { + return R.ok( orderService.addOrder(skuIds)); + + } +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/controller/PaymentController.java b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/controller/PaymentController.java new file mode 100644 index 0000000..50a0ba2 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/controller/PaymentController.java @@ -0,0 +1,33 @@ +package com.bawei.mall.car.controller; + +import com.bawei.mall.car.service.PaymentService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 支付控制层 + * + * @program: mall_cloud + * @ClassName: PaymentController + * @author: Gyc + * @create: 2024-05-12 16:24 + **/ +@RestController +public class PaymentController { + @Autowired + private PaymentService paymentService; + + @GetMapping("/pay/{orderId}") + public String pay(@PathVariable String orderId) { + return paymentService.pay(orderId); + } + + + + + + +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/demo/demo.java b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/demo/demo.java new file mode 100644 index 0000000..a54a385 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/demo/demo.java @@ -0,0 +1,73 @@ +package com.bawei.mall.car.demo; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.alipay.api.AlipayApiException; +import com.alipay.api.AlipayClient; +import com.alipay.api.DefaultAlipayClient; +import com.alipay.api.request.AlipayTradePagePayRequest; +import com.alipay.api.response.AlipayTradePagePayResponse; + +/** + * @program: mall_cloud + * @ClassName: demo + * @author: Gyc + * @create: 2024-05-12 15:54 + **/ +public class demo { + public static void main(String[] args) throws Exception { + AlipayClient alipayClient = new DefaultAlipayClient("https://openapi-sandbox.dl.alipaydev.com/gateway.do", + "9021000136694024", + "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCFz/238QvZGbGw9EXAihMzA/wBLprkwCZN2PlZAWBJRI28L+rO8xAtgeC6AVarRGF6e0qMZ4LLWtOgL1RyfxOL2I/Ny+F8jmY0wEZABt6WKI1/l9HliZ/hxNoko4IHo6tf7NEhZJMmAce088PB3IVmFWv1aaSOL7/WaZlSiz/80ZA2v7oHzntblVm1FHFok7kCumndzdj8SgaPtZRA964lx3zhQHWV2O22ThhqN6zksJzXsQoPFvIv8Ic5ymYPzCvnSs7U5jyHMwQ1btYXgUMbv1Uqo9It2U0Gq3P4rZFMjfPn5FSdLaWepTpSg69Ittqo3YCzBmlKZjVmBc5W9thHAgMBAAECggEAF3AJ2akP0TPt6reua/4DROFCx5Y5LS32x5XkftF94vdt9/NQpnTudXoVOZ84ZgExLbngod0TjLjY7mq72N4nN0x0S7CVSzLJ9h1jcJ2DaTurJRkbe5/ycCIBr38wLFRflQquyrGKEJMpPqmftRoCB5Ji+XZKi1kTueN/JnUbfRWavAagK6YK8qlZYAiQr+PXiLcF2U3qcB7BgqVb7BJU5g/IiotHE+0ijtqWcT+X9ElIqw5mgmkvRZBPy5iVeD/b2F5b4Mbr9MvQkaICzt+P8QZCTKyd31GOhSV6zYguaisN16uC5DKRNZ4d1nbWOSR5ifCu1FH8t1cGy+OstVFzIQKBgQDFP9ZKc1wo5U/+zL8Bz9JteWEs1X6NzHu9yF62pgHg6G8L+YnQhFUtR8yQ1f782Fkdsl6YyXv89PXAcYHQJJax5JK2ONQD+tb6BUhOt2kq1d2ZJhX4nDeUJfpsKuaXnbsRc5A9D/HmUlZvsAxZoZ367WOi6WudP6DwDlG0g58xlwKBgQCtqx99lENuTQ0K8qNuSwWvQb+APf6zlGdqT7G1rQTPtNJ79ZyECQNUC9FzsIstQIWvLQO6PzYpa/aTZst44sWFPtyqTY0+ECUO5/KC/Ap5AROuy1/rMEaUQ93hT54TTLVm0g3fwnUCOJX9iUXJk63gxXCdyCi+8ZkLNEcwWa8E0QKBgBNJUqKk9PXqtg+r5WE/+MtLevzvQxiKTe8YkGo7gSOElpcNJzSEO+/ZfV8MDYqbfNsyfZ1i1gS9zumqL48yhKmQN+gpVlGtTSfVLGTF+jp9/tTirHNKkwShUgMRjsp0Wb4zFn9h970Vf+4bwJli/Bd07rEXMbaGai4OuF52IDKxAoGAHeN4jPVKUZ5jI0I1DFNPDCWFnr2Mqz1cOviyPfEkBdc57mmL4VFnyDwsdPuqSER1fXuCy7f7S0+wZRfo5sooclEqSwkDyO2gYxtaKl7UMpUT3R5VSLXLP9MaSZ+ZNfsasTJvftYJqzMv5S2N3C5VW3y/b/g1wv7zdvEtW03kCDECgYEAnY21ReTt6HtLcX4iGAX1PKfGU251b5a2Kw4xcX/oNkzWHeVL9URDmlB93paNLg6QuskeSiwgPmitUGtKWNAfyZnWESAfCZkGza0+aJjni4LbxcnFHJcYMmuWMZxLB6IaOlDPnneKv0DWSydIkotDCDnFz4BPnim962ilILRLnWY=", + "json", + "UTF-8", + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApxRIYvq+Kr7RLyD3gWevRWKfIM7vGGNtCmQ7yP/Gooz6i8GzLWCZgrp5j1bazhECaPvCsvuZPU6DHd3rETWuaDGrFPvGwPl+VUX7NlYIG8QdKdMmBHA+/UbqvytEIrRqkP3/s+yrbRGzGmN8Ht8wNmPEn51IlTZVcvi2cxs1CY0CY9k70pkWnZBmhxxOG3EvgM1dV/61aWQkJk3OFhITSIWlf9FQBxH1E1RfciSoEWgjew/KoWyKp83rqKuUtHehILdNsfqHFHO/lzDp2XhVBPKNqafIQvAhcWyBwhGD9Cs83YvLldvJ9DE2LGFi8eF+IvVbcFrCfkkxrT4kBoxGYwIDAQAB", + "RSA2"); + AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); +//异步接收地址,仅支持http/https,公网可访问 + request.setNotifyUrl(""); +//同步跳转地址,仅支持http/https + request.setReturnUrl(""); +/******必传参数******/ + JSONObject bizContent = new JSONObject(); +//商户订单号,商家自定义,保持唯一性 + bizContent.put("out_trade_no", "20210817010101006"); +//支付金额,最小值0.01元 + bizContent.put("total_amount", 200.00); +//订单标题,不可使用特殊符号 + bizContent.put("subject", "测试商品"); +//电脑网站支付场景固定传值FAST_INSTANT_TRADE_PAY + bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY"); + +/******可选参数******/ +//bizContent.put("time_expire", "2022-08-01 22:00:00"); + +////// 商品明细信息,按需传入 +//JSONArray goodsDetail = new JSONArray(); +//JSONObject goods1 = new JSONObject(); +//goods1.put("goods_id", "goodsNo1"); +//goods1.put("goods_name", "子商品1"); +//goods1.put("quantity", 1); +//goods1.put("price", 200.00); +//goodsDetail.add(goods1); +//bizContent.put("goods_detail", goodsDetail); + +//// 扩展信息,按需传入 +//JSONObject extendParams = new JSONObject(); +//extendParams.put("sys_service_provider_id", "2088511833207846"); +//bizContent.put("extend_params", extendParams); + + request.setBizContent(bizContent.toString()); + AlipayTradePagePayResponse response = alipayClient.pageExecute(request,"POST"); +// 如果需要返回GET请求,请使用 +// AlipayTradePagePayResponse response = alipayClient.pageExecute(request,"GET"); + String pageRedirectionData = response.getBody(); + System.out.println(pageRedirectionData); + + if(response.isSuccess()){ + System.out.println("调用成功"); + } else { + System.out.println("调用失败"); + } + } +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/mapper/CarMapper.java b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/mapper/CarMapper.java new file mode 100644 index 0000000..6eff3ba --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/mapper/CarMapper.java @@ -0,0 +1,48 @@ +package com.bawei.mall.car.mapper; + +import com.bawei.mall.car.domain.Car; +import com.bawei.mall.car.domain.CarBySku; +import com.bawei.mall.car.domain.ProductSkuInfo; +import com.bawei.mall.product.domain.MallProductSkuInfo; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @program: mall_cloud + * @ClassName: CarMapper + * @author: Gyc + * @create: 2024-05-06 16:03 + **/ +@Mapper +public interface CarMapper { + + + String queryCar(Long userId); + + + void insertCar(@Param("userId") Long userId, @Param("carId") String carId); + + void addCarBySkuId(@Param("skuId") Integer skuId, @Param("carId") String carId, @Param("userId") Long userId); + + CarBySku showCarBySkuId(@Param("skuId") Integer skuId, @Param("carId") String carId); + + void updCarBySkuId(@Param("skuId") Integer skuId, @Param("carId") String carId, @Param("i") int i); + + void delCarBySkuId(String carId); + + void delCar(Long userId); + + void delCarBySkuIdInfo(@Param("skuId") Integer skuId, @Param("carId") String carId); + //查询这个用户所有的skuId + List querySkuId(String carId); + + MallProductSkuInfo querySku(Integer skuId); + //查询所有的sku和商品表 + List querySkus(@Param("skuIds") List skuIds, @Param("carId") String carId); + + List ProductBySkuIdList(); + + Car queryCarByCarId(String carId); +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/mapper/OrderMapper.java b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/mapper/OrderMapper.java new file mode 100644 index 0000000..d58a6a1 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/mapper/OrderMapper.java @@ -0,0 +1,23 @@ +package com.bawei.mall.car.mapper; + +import com.bawei.mall.car.domain.Order; +import com.bawei.mall.car.domain.OrderByUser; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @program: mall_cloud + * @ClassName: OrderMapper + * @author: Gyc + * @create: 2024-05-10 19:35 + **/ +@Mapper +public interface OrderMapper { + + + void insertOrder(@Param("orderList") List orderList); + + void insertOrderByUser( OrderByUser build); +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/service/CarService.java b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/service/CarService.java new file mode 100644 index 0000000..14f01f2 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/service/CarService.java @@ -0,0 +1,21 @@ +package com.bawei.mall.car.service; + +import com.bawei.mall.car.domain.MallProductSkuCarInfo; + +/** + * @program: mall_cloud + * @ClassName: CarService + * @author: Gyc + * @create: 2024-05-06 16:03 + **/ +public interface CarService { + void addCar(Integer skuId, Integer status); + + void updCar(Integer skuId, Integer num); + + void delCar(); + + void delById(String skuIds); + + MallProductSkuCarInfo calculate(); +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/service/OrderService.java b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/service/OrderService.java new file mode 100644 index 0000000..6841c6e --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/service/OrderService.java @@ -0,0 +1,13 @@ +package com.bawei.mall.car.service; + +import java.util.List; + +/** + * @program: mall_cloud + * @ClassName: OrderService + * @author: Gyc + * @create: 2024-05-10 19:34 + **/ +public interface OrderService { + Object addOrder(List skuIds); +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/service/PaymentService.java b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/service/PaymentService.java new file mode 100644 index 0000000..895c146 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/service/PaymentService.java @@ -0,0 +1,12 @@ +package com.bawei.mall.car.service; + +/** + * @program: mall_cloud + * @ClassName: PaymentService + * @author: Gyc + * @create: 2024-05-12 16:24 + **/ +public interface PaymentService { + String pay(String orderId); + +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/service/impl/CarServiceImpl.java b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/service/impl/CarServiceImpl.java new file mode 100644 index 0000000..a980fe9 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/service/impl/CarServiceImpl.java @@ -0,0 +1,299 @@ +package com.bawei.mall.car.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.bawei.common.core.utils.JwtUtils; +import com.bawei.common.security.utils.SecurityUtils; +import com.bawei.mall.car.domain.CarBySku; +import com.bawei.mall.car.domain.MallProductSkuCarInfo; +import com.bawei.mall.car.domain.ProductPrices; +import com.bawei.mall.car.domain.ProductSkuInfo; +import com.bawei.mall.car.mapper.CarMapper; +import com.bawei.mall.car.service.CarService; +import com.bawei.mall.product.domain.MallProductSkuInfo; +import com.fasterxml.jackson.core.type.TypeReference; +import io.jsonwebtoken.Claims; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + + +/** + * 购物车服务实现类 + */ +@Service +@Log4j2 +public class CarServiceImpl implements CarService { + /** + * 购物车Mapper依赖注入 + */ + @Autowired + private CarMapper carMapper; + @Autowired + private RedisTemplate redisTemplate; + /** + * 添加商品到购物车 + * + * @param skuId 商品ID + * @param status 状态(0:添加,非0:删除) + */ + @Override + public void addCar(Integer skuId, Integer status) { + if (skuId == null || skuId==0||skuId<0) { + throw new RuntimeException("商品ID不能为空"); + } + if (status==null||status<0){ + throw new RuntimeException("状态不能为空"); + } + + String token = queryUserId(); + // 获取用户ID + Long userId = Long.valueOf(JwtUtils.getUserId(token)); + //查询sku + MallProductSkuInfo mallProductSkuInfo=carMapper.querySku(skuId); + if (mallProductSkuInfo==null){ + throw new RuntimeException("商品不存在"); + } + // 查询购物车 + String carId = carMapper.queryCar(userId); + if (carId == null) { + carId= UUID.randomUUID().toString().replaceAll("-", ""); + // 新增购物车 + carMapper.insertCar(userId, carId); + // 将商品信息和购物车ID进行关联 + carMapper.addCarBySkuId(skuId, carId, userId); + } + //查询购物车 + CarBySku carBySku = carMapper.showCarBySkuId(skuId, carId); + if (carBySku==null){ + carMapper.addCarBySkuId(skuId,carId,userId); + }else { + // 根据状态进行操作 + if (status == 0) { + toAddCar(skuId, carId); + } else { + toDelCar(skuId, carId); + } + } + + + } + + /** + * 减少商品数量(从购物车中删除商品) + * + * @param skuId 商品ID + * @param carId 购物车ID + */ + private void toDelCar(Integer skuId, String carId) { + // 查询购物车数量 + CarBySku carBySku = carMapper.showCarBySkuId(skuId, carId); + // 判断购物车数量 + if (carBySku.getNumber() <= 1) { + throw new RuntimeException("购物车数量为1,不能再减了"); + } else { + // 更新购物车商品数量 + carMapper.updCarBySkuId(skuId, carId, carBySku.getNumber() - 1); + } + } + + /** + * 增加商品数量(向购物车中添加商品) + * + * @param skuId 商品ID + * @param carId 购物车ID + */ + private void toAddCar(Integer skuId, String carId) { + // 查询购物车商品信息 + CarBySku carBySku = carMapper.showCarBySkuId(skuId, carId); + if (carBySku==null){ + throw new RuntimeException("购物车商品不存在"); + } + // 更新购物车商品数量 + carMapper.updCarBySkuId(skuId, carId, carBySku.getNumber() + 1); + } + + /** + * 获取当前登录用户ID + * + * @return 用户ID + */ + private String queryUserId() { + // 获取用户ID + String token = SecurityUtils.getToken(); + JwtUtils.parseToken(token); + return token; + } + + + /** + * 更新购物车商品数量 + * + * @param skuId 商品ID + * @param num 商品数量 + */ + @Override + public void updCar(Integer skuId, Integer num) { + String token = queryUserId(); + // 获取用户ID + Long userId = Long.valueOf(JwtUtils.getUserId(token)); + + // 查询购物车 + String carId = carMapper.queryCar(userId); + if (carId == null) { + throw new RuntimeException("购物车错误"); + } + // 更新购物车商品数量 + carMapper.updCarBySkuId(skuId, carId, num); + } + + /** + * 删除整个购物车 + */ + @Override + public void delCar() { + String token = queryUserId(); + // 获取用户ID + Long userId = Long.valueOf(JwtUtils.getUserId(token)); + // 查询购物车 + String carId = carMapper.queryCar(userId); + if (carId == null) { + throw new RuntimeException("购物车不存在"); + } + // 删除购物车关联记录 + carMapper.delCarBySkuId(carId); + // 删除购物车记录 + carMapper.delCar(userId); + } + + /** + * 根据商品ID列表批量删除购物车商品 + * + * @param skuIds 商品ID列表 + */ + @Override + public void delById(String skuIds) { + // 检查商品ID列表是否为空 + if (skuIds.isEmpty()) { + throw new RuntimeException("skuIds不能为空"); + } + + String token = queryUserId(); + // 获取用户ID + Long userId = Long.valueOf(JwtUtils.getUserId(token)); + String carId = carMapper.queryCar(userId); + String[] split = skuIds.split(","); + // 遍历商品ID列表并删除购物车关联记录 + for (String skuId : split) { + carMapper.delCarBySkuIdInfo(Integer.valueOf(skuId), carId); + } + } + + @Override + public MallProductSkuCarInfo calculate() { + MallProductSkuCarInfo mallProductSkuCarInfo = new MallProductSkuCarInfo(); + List productSkuInfos = new ArrayList<>(); + ProductPrices productPrices = new ProductPrices(); + String token = queryUserId(); + Long userId = Long.valueOf(JwtUtils.getUserId(token)); + String carId = carMapper.queryCar(userId); + List skuIds = carMapper.querySkuId(carId); + if (skuIds.size()==0){ + throw new RuntimeException("购物车为空"); + } + //查询reids里面的数据,如果redis里面没有就去数据库查 + if (redisTemplate.hasKey("car")){ + List car = redisTemplate.opsForList().range("car", 0, -1); + productSkuInfos = car.stream() + .map(carProductInfo -> JSON.parseObject(carProductInfo,ProductSkuInfo.class)) + .collect(Collectors.toList()); + mallProductSkuCarInfo.setProductSkuInfo(productSkuInfos); + }else { + productSkuInfos = carMapper.querySkus(skuIds,carId); + redisTemplate.opsForList().rightPushAll("car",JSON.toJSONString(productSkuInfos)); + } + + if (productSkuInfos.size()==0){ + throw new RuntimeException("购物车商品不存在"); + } + mallProductSkuCarInfo.setProductSkuInfo(productSkuInfos); + productPrices.setPrice(new BigDecimal(0)); + productPrices.setSpecialOffer(new BigDecimal(0)); + productPrices.setAfterDiscounts(new BigDecimal(0)); + BigDecimal bigDecimal = new BigDecimal(0); + for (ProductSkuInfo productSkuInfo : productSkuInfos) { + BigDecimal skuPrice = productSkuInfo.getSkuPrice(); + BigDecimal number = BigDecimal.valueOf(productSkuInfo.getNumber()); + + // 使用bigDecimal的add()方法,并将结果保存回bigDecimal + bigDecimal = bigDecimal.add(skuPrice.multiply(number)); + } + productPrices.setPrice(bigDecimal); + + //TODO 假设有个VIP + Claims claims = JwtUtils.parseToken(token); + log.info("claims:{}",claims); + String VIP="admin"; + if (VIP.equals(JwtUtils.getUserName(claims))){ + getVIP(productPrices); + } + mallProductSkuCarInfo.setProductPrices(productPrices); + return mallProductSkuCarInfo; + } + + private void getVIP(ProductPrices productPrices) { + // 计算VIP折扣后的价格 + BigDecimal vipDiscountRate = new BigDecimal("0.9"); + BigDecimal afterDiscounts = productPrices.getPrice().multiply(vipDiscountRate); + productPrices.setAfterDiscounts(afterDiscounts); + + // 计算VIP优惠与原价的差距 + BigDecimal specialOffer = productPrices.getPrice().subtract(afterDiscounts); + productPrices.setSpecialOffer(specialOffer); + } + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/service/impl/OrderServiceImpl.java b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/service/impl/OrderServiceImpl.java new file mode 100644 index 0000000..6ade84a --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/service/impl/OrderServiceImpl.java @@ -0,0 +1,203 @@ +package com.bawei.mall.car.service.impl; + +import com.bawei.common.core.utils.JwtUtils; +import com.bawei.common.security.utils.SecurityUtils; +import com.bawei.mall.car.domain.*; +import com.bawei.mall.car.mapper.CarMapper; +import com.bawei.mall.car.mapper.OrderMapper; +import com.bawei.mall.car.service.OrderService; +import io.jsonwebtoken.Claims; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.time.Instant; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Random; +import java.util.stream.Collectors; + +/** + * @program: mall_cloud + * @ClassName: OrderServiceImpl + * @author: Gyc + * @create: 2024-05-10 19:34 + **/ +@Service +public class OrderServiceImpl implements OrderService { + private static final Logger log = LoggerFactory.getLogger(OrderServiceImpl.class); + @Autowired + private OrderMapper orderMolder; + @Autowired + private CarMapper carMapper; + @Autowired + private OrderMapper orderMapper; + + @Override + public Object addOrder(List skuIds) { + String token = SecurityUtils.getToken(); + String userId = JwtUtils.getUserId(token); + String carId = carMapper.queryCar(Long.valueOf(userId)); + if (carId == null){ + throw new RuntimeException("购物车为空"); + } + String orderId = generateOrderId(); + ArrayList carBySkus = new ArrayList<>(); + List productSkuInfoList = carMapper.querySkus(skuIds, carId); + List orderList = productSkuInfoList.stream() + .map(productSkuInfo -> { + Order order = new Order(); + Order build = order.builder() + .skuId(Math.toIntExact(productSkuInfo.getSkuId())) + .productUrl(productSkuInfo.getImage()) + .productPrice(productSkuInfo.getSkuPrice()) + .productName(productSkuInfo.getTitle()) + .productSku(productSkuInfo.getSkuName()) + .orderId(orderId) + .productNum(productSkuInfo.getNumber()) + .buyNumber(productSkuInfo.getBuyNumber()) + .build(); + return build; + }) + .collect(Collectors.toList()); + orderMolder.insertOrder(orderList); + //查询需要购买的数量 + skuIds.forEach(skuId -> { + CarBySku carBySku = carMapper.showCarBySkuId(skuId, carId); + carBySkus.add(carBySku); + }); + for (int i = 0; i < carBySkus.size() - 1; i++) { + //比较商品数量 + if (carBySkus.get(i).getNumber()>orderList.get(i).getBuyNumber()){ + throw new RuntimeException("商品数量不足"); + } + } +// orderMapper.insertOrderByUser(orderId,userId); + + OrderByUser orderByUser = new OrderByUser(); + OrderByUser build = orderByUser.builder() + .orderId(orderId) + .userId(Integer.valueOf(userId)) + .status(0) + .createTime(new Date()) + //TODO 没有优惠卷 + .discountId(0) + .build(); + getVIP(orderList,build); + OrderByUserInfo orderByUserInfo = new OrderByUserInfo(); + orderByUserInfo.setOrderList(orderList); + orderByUserInfo.setOrderByUser(build); + orderMapper.insertOrderByUser(build); + return orderByUserInfo; + } + + /** + * 计算价格 + * + * @param orderList + * @param orderByUser + */ + private void getVIP(List orderList, OrderByUser orderByUser) { + orderByUser.setTotalPrice(new BigDecimal(0)); + orderByUser.setDiscountPrice(new BigDecimal(0)); + orderByUser.setPayPrice(new BigDecimal(0)); + BigDecimal bigDecimal = new BigDecimal(0); + for (Order order : orderList) { + BigDecimal skuPrice = order.getProductPrice(); + BigDecimal number = BigDecimal.valueOf(order.getProductNum()); + // 使用bigDecimal的add()方法,并将结果保存回bigDecimal + bigDecimal = bigDecimal.add(skuPrice.multiply(number)); + orderByUser.setTotalPrice(bigDecimal); + + } + if (orderByUser.getDiscountId()!=0){ + //TODO 进行优惠 + } + //TODO 假设有个VIP + String token = SecurityUtils.getToken(); + Claims claims = JwtUtils.parseToken(token); + log.info("claims:{}",claims); + String VIP="admin"; + if (VIP.equals(JwtUtils.getUserName(claims))){ + // 计算VIP折扣后的价格 + BigDecimal vipDiscountRate = new BigDecimal("0.99"); + BigDecimal afterDiscounts =orderByUser.getTotalPrice().multiply(vipDiscountRate); + orderByUser.setPayPrice(afterDiscounts); + + // 计算VIP优惠与原价的差距 + BigDecimal specialOffer = orderByUser.getTotalPrice().subtract(afterDiscounts); + orderByUser.setDiscountPrice(specialOffer); + } + + } + + /** + * 生成基于时间戳和十个随机数字的订单ID。 + * + * @return 订单ID字符串 + */ + public static String generateOrderId() { + // 获取当前时间的毫秒时间戳 + long timestamp = Instant.now().toEpochMilli(); + + // 创建一个随机数生成器 + Random random = new Random(); + + // 生成十个0-9之间的随机数字,拼接成一个字符串 + StringBuilder randomNumbers = new StringBuilder(); + for (int i = 0; i < 4; i++) { + randomNumbers.append(random.nextInt(10)); + } + + // 将时间戳和随机数字拼接成订单ID,这里以某种格式组合,例如:时间戳_随机数 + // 注意根据实际需要调整格式,确保唯一性和长度控制 + String orderId = timestamp + randomNumbers.toString(); + + return orderId; + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/service/impl/PaymentServiceImpl.java b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/service/impl/PaymentServiceImpl.java new file mode 100644 index 0000000..a5d61a0 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/service/impl/PaymentServiceImpl.java @@ -0,0 +1,83 @@ +package com.bawei.mall.car.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.alipay.api.AlipayClient; +import com.alipay.api.DefaultAlipayClient; +import com.alipay.api.request.AlipayTradePagePayRequest; +import com.alipay.api.response.AlipayTradePagePayResponse; +import com.bawei.mall.car.service.PaymentService; +import lombok.SneakyThrows; +import org.springframework.stereotype.Service; + +/** + * @program: mall_cloud + * @ClassName: PaymentServiceImpl + * @author: Gyc + * @create: 2024-05-12 16:24 + **/ +@Service +public class PaymentServiceImpl implements PaymentService { + + + @SneakyThrows + @Override + public String pay(String orderId) { + + AlipayClient alipayClient = new DefaultAlipayClient("https://openapi-sandbox.dl.alipaydev.com/gateway.do", + "9021000136694024", + "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCFz/238QvZGbGw9EXAihMzA/wBLprkwCZN2PlZAWBJRI28L+rO8xAtgeC6AVarRGF6e0qMZ4LLWtOgL1RyfxOL2I/Ny+F8jmY0wEZABt6WKI1/l9HliZ/hxNoko4IHo6tf7NEhZJMmAce088PB3IVmFWv1aaSOL7/WaZlSiz/80ZA2v7oHzntblVm1FHFok7kCumndzdj8SgaPtZRA964lx3zhQHWV2O22ThhqN6zksJzXsQoPFvIv8Ic5ymYPzCvnSs7U5jyHMwQ1btYXgUMbv1Uqo9It2U0Gq3P4rZFMjfPn5FSdLaWepTpSg69Ittqo3YCzBmlKZjVmBc5W9thHAgMBAAECggEAF3AJ2akP0TPt6reua/4DROFCx5Y5LS32x5XkftF94vdt9/NQpnTudXoVOZ84ZgExLbngod0TjLjY7mq72N4nN0x0S7CVSzLJ9h1jcJ2DaTurJRkbe5/ycCIBr38wLFRflQquyrGKEJMpPqmftRoCB5Ji+XZKi1kTueN/JnUbfRWavAagK6YK8qlZYAiQr+PXiLcF2U3qcB7BgqVb7BJU5g/IiotHE+0ijtqWcT+X9ElIqw5mgmkvRZBPy5iVeD/b2F5b4Mbr9MvQkaICzt+P8QZCTKyd31GOhSV6zYguaisN16uC5DKRNZ4d1nbWOSR5ifCu1FH8t1cGy+OstVFzIQKBgQDFP9ZKc1wo5U/+zL8Bz9JteWEs1X6NzHu9yF62pgHg6G8L+YnQhFUtR8yQ1f782Fkdsl6YyXv89PXAcYHQJJax5JK2ONQD+tb6BUhOt2kq1d2ZJhX4nDeUJfpsKuaXnbsRc5A9D/HmUlZvsAxZoZ367WOi6WudP6DwDlG0g58xlwKBgQCtqx99lENuTQ0K8qNuSwWvQb+APf6zlGdqT7G1rQTPtNJ79ZyECQNUC9FzsIstQIWvLQO6PzYpa/aTZst44sWFPtyqTY0+ECUO5/KC/Ap5AROuy1/rMEaUQ93hT54TTLVm0g3fwnUCOJX9iUXJk63gxXCdyCi+8ZkLNEcwWa8E0QKBgBNJUqKk9PXqtg+r5WE/+MtLevzvQxiKTe8YkGo7gSOElpcNJzSEO+/ZfV8MDYqbfNsyfZ1i1gS9zumqL48yhKmQN+gpVlGtTSfVLGTF+jp9/tTirHNKkwShUgMRjsp0Wb4zFn9h970Vf+4bwJli/Bd07rEXMbaGai4OuF52IDKxAoGAHeN4jPVKUZ5jI0I1DFNPDCWFnr2Mqz1cOviyPfEkBdc57mmL4VFnyDwsdPuqSER1fXuCy7f7S0+wZRfo5sooclEqSwkDyO2gYxtaKl7UMpUT3R5VSLXLP9MaSZ+ZNfsasTJvftYJqzMv5S2N3C5VW3y/b/g1wv7zdvEtW03kCDECgYEAnY21ReTt6HtLcX4iGAX1PKfGU251b5a2Kw4xcX/oNkzWHeVL9URDmlB93paNLg6QuskeSiwgPmitUGtKWNAfyZnWESAfCZkGza0+aJjni4LbxcnFHJcYMmuWMZxLB6IaOlDPnneKv0DWSydIkotDCDnFz4BPnim962ilILRLnWY=", + "json", + "UTF-8", + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApxRIYvq+Kr7RLyD3gWevRWKfIM7vGGNtCmQ7yP/Gooz6i8GzLWCZgrp5j1bazhECaPvCsvuZPU6DHd3rETWuaDGrFPvGwPl+VUX7NlYIG8QdKdMmBHA+/UbqvytEIrRqkP3/s+yrbRGzGmN8Ht8wNmPEn51IlTZVcvi2cxs1CY0CY9k70pkWnZBmhxxOG3EvgM1dV/61aWQkJk3OFhITSIWlf9FQBxH1E1RfciSoEWgjew/KoWyKp83rqKuUtHehILdNsfqHFHO/lzDp2XhVBPKNqafIQvAhcWyBwhGD9Cs83YvLldvJ9DE2LGFi8eF+IvVbcFrCfkkxrT4kBoxGYwIDAQAB", + "RSA2"); + AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); + //异步接收地址,仅支持http/https,公网可访问 + request.setNotifyUrl(""); + //同步跳转地址,仅支持http/https + request.setReturnUrl(""); + /******必传参数******/ + JSONObject bizContent = new JSONObject(); + //商户订单号,商家自定义,保持唯一性 + bizContent.put("out_trade_no",orderId); + //支付金额,最小值0.01元 + bizContent.put("total_amount", 200.00); + //订单标题,不可使用特殊符号 + bizContent.put("subject", "测试商品"); + //电脑网站支付场景固定传值FAST_INSTANT_TRADE_PAY + bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY"); + + /******可选参数******/ + //bizContent.put("time_expire", "2022-08-01 22:00:00"); + + ////// 商品明细信息,按需传入 + //JSONArray goodsDetail = new JSONArray(); + //JSONObject goods1 = new JSONObject(); + //goods1.put("goods_id", "goodsNo1"); + //goods1.put("goods_name", "子商品1"); + //goods1.put("quantity", 1); + //goods1.put("price", 200.00); + //goodsDetail.add(goods1); + //bizContent.put("goods_detail", goodsDetail); + + //// 扩展信息,按需传入 + //JSONObject extendParams = new JSONObject(); + //extendParams.put("sys_service_provider_id", "2088511833207846"); + //bizContent.put("extend_params", extendParams); + + request.setBizContent(bizContent.toString()); + AlipayTradePagePayResponse response = alipayClient.pageExecute(request,"POST"); + // 如果需要返回GET请求,请使用 + // AlipayTradePagePayResponse response = alipayClient.pageExecute(request,"GET"); + String pageRedirectionData = response.getBody(); + System.out.println(pageRedirectionData); + + if(response.isSuccess()){ + System.out.println("调用成功"); + } else { + System.out.println("调用失败"); + } + + + return ""; + } +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/utils/RedisTiming.java b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/utils/RedisTiming.java new file mode 100644 index 0000000..1bf3e13 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/java/com/bawei/mall/car/utils/RedisTiming.java @@ -0,0 +1,74 @@ +package com.bawei.mall.car.utils; + +import com.alibaba.fastjson.JSON; +import com.bawei.common.redis.service.RedisService; +import com.bawei.mall.car.domain.Car; +import com.bawei.mall.car.domain.CarBySku; +import com.bawei.mall.car.domain.ProductSkuInfo; +import com.bawei.mall.car.mapper.CarMapper; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import static com.fasterxml.jackson.databind.type.LogicalType.Collection; + +/** + * @program: mall_cloud + * @ClassName: RedisTiming + * @author: Gyc + * @create: 2024-05-08 15:12 + **/ +@Component +@Log4j2 +public class RedisTiming { + @Autowired + private RedisTemplate redisTemplate; + @Autowired + private CarMapper carMapper; + //定时存 + @Scheduled(cron = "0 0/30 * * * ?") + public void timingSave() { + //编写一个定时任务,将redis的购物车信息,更新到mysql数据库 + List car = redisTemplate.opsForList().range("car", 0, -1); + List productSkuInfos = car.stream() + .map(carProductInfo -> JSON.parseObject(carProductInfo,ProductSkuInfo.class)) + .collect(Collectors.toList()); + + if (productSkuInfos.size() == 0){ + return; + }else { + productSkuInfos.forEach(productSkuInfo -> { + carMapper.delCarBySkuIdInfo(Math.toIntExact(productSkuInfo.getSkuId()), productSkuInfo.getCarId()); + carMapper.addCarBySkuId(Math.toIntExact(productSkuInfo.getSkuId()), productSkuInfo.getCarId(), 0L); + }); + } + + } + + //定时取 + @Scheduled(cron = "0 0/15 * * * ? ") + public void timingGet() { + if (redisTemplate.hasKey("car")){ + redisTemplate.delete("car"); + } + //编写一个定时任务,将mysql数据库的购物车信息,更新到redis + List productSkuInfos = carMapper.ProductBySkuIdList(); + productSkuInfos.forEach(productSkuInfo -> { + redisTemplate.opsForList().rightPushAll("car",JSON.toJSONString(productSkuInfo)); + }); + + } + + + + + + + +} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/resources/banner.txt b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/resources/banner.txt new file mode 100644 index 0000000..0dd5eee --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/resources/banner.txt @@ -0,0 +1,2 @@ +Spring Boot Version: ${spring-boot.version} +Spring Application Name: ${spring.application.name} diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/resources/bootstrap.yml b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..7c6d198 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/resources/bootstrap.yml @@ -0,0 +1,47 @@ +# Tomcat +server: + port: 9303 + # Spring +spring: + application: + # 应用名称 + name: mall-car + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 127.0.0.1:8848 + namespace: 12345678 + config: + # 配置中心地址 + server-addr: 127.0.0.1:8848 + namespace: 12345678 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + rabbitmq: + host: 127.0.0.1 +api-docs: + path: v3/api-docs # 指定生成文档的路径,网关会访问这个路径来拉取文档 + group-configs: + - group: 'default' + paths-to-match: '/**' + packages-to-scan: com.keyl1me.edu.controller # 指定要扫描的包 + +knife4j: + enable: true # 开启knife4j接口文档美化 + setting: + language: zh_cn # 指定语言 +# feign 配置 +feign: + compression: + request: + enabled: true + min-request-size: 8192 + response: + enabled: true diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/resources/logback.xml b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/resources/logback.xml new file mode 100644 index 0000000..82e7f18 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/resources/logback.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + ${log.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + ERROR + + ACCEPT + + DENY + + + + + + + + + + + + + + + + + + diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/resources/mapper/MallCarBrandInfoMapper.xml b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/resources/mapper/MallCarBrandInfoMapper.xml new file mode 100644 index 0000000..19bbd42 --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/resources/mapper/MallCarBrandInfoMapper.xml @@ -0,0 +1,75 @@ + + + + + + update mall_sku_car_info set number=#{i} where sku_id=#{skuId} and car_id=#{carId} + + + delete from mall_sku_car_info where car_id= #{carId} + + + delete from mall_product_car where user_id= #{userId} + + + delete from mall_sku_car_info where sku_id= #{skuId} and car_id= #{carId} + + + + + + + + + + + + + insert into mall_product_car(car_id,user_id) values(#{carId},#{userId}) + + + insert into mall_sku_car_info (car_id,sku_id,number,create_by,create_time) values(#{carId},#{skuId},1,#{userId},now()) + + diff --git a/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/resources/mapper/OrderMapper.xml b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/resources/mapper/OrderMapper.xml new file mode 100644 index 0000000..3323afa --- /dev/null +++ b/bawei-mall/bawei-mall-car/bawei-mall-car-server/src/main/resources/mapper/OrderMapper.xml @@ -0,0 +1,41 @@ + + + + + + + INSERT INTO `mall-product-gyc`.`mall_order_user_info` + ( `order_id`, + `user_id`, + `discount_id`, + `status`, + `total_price`, + `discount_price`, + `pay_price`, + `payt_time`, + `create_time`) + VALUES (#{orderId}, + #{userId}, + #{discountId}, + #{status}, + #{totalPrice}, + #{discountPrice}, + #{payPrice}, + #{payTime}, + #{createTime}); + + + + + + INSERT INTO `mall-product-gyc`.`mall_product_order` ( `order_id`, sku_id, `product_name`, product_sku, `product_url`, `product_price`, `product_num`,number) + VALUES + + ( #{order.orderId},#{order.skuId}, #{order.productName},#{order.productSku}, #{order.productUrl}, #{order.productPrice}, #{order.productNum},#{order.buyNumber}) + + + + + diff --git a/bawei-mall/bawei-mall-car/pom.xml b/bawei-mall/bawei-mall-car/pom.xml new file mode 100644 index 0000000..fdb30d1 --- /dev/null +++ b/bawei-mall/bawei-mall-car/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + com.bawei + bawei-mall + 3.6.0 + + + bawei-mall-car + pom + + bawei-mall-car-server + bawei-mall-car-common + + + + 8 + 8 + UTF-8 + + + diff --git a/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/controller/EsProductInfoController.java b/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/controller/EsProductInfoController.java new file mode 100644 index 0000000..c098723 --- /dev/null +++ b/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/controller/EsProductInfoController.java @@ -0,0 +1,37 @@ +package com.bawei.mall.product.controller; + +import com.bawei.common.core.web.controller.BaseController; +import com.bawei.mall.product.service.EsProductInfoService; +import io.swagger.annotations.Api; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * es查询 + * + * @program: mall_cloud + * @ClassName: EsProductInfoController + * @author: Gyc + * @create: 2024-04-28 20:31 + **/ +@RestController +@RequestMapping("/es") +@Api("es查询") +public class EsProductInfoController extends BaseController { + @Autowired + private EsProductInfoService esProductInfoService; + + public void add(){ + + + + + } + + + + + + +} diff --git a/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/service/EsProductInfoService.java b/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/service/EsProductInfoService.java new file mode 100644 index 0000000..e73b0d8 --- /dev/null +++ b/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/service/EsProductInfoService.java @@ -0,0 +1,10 @@ +package com.bawei.mall.product.service; + +/** + * @program: mall_cloud + * @ClassName: EsProductInfoService + * @author: Gyc + * @create: 2024-04-28 20:33 + **/ +public interface EsProductInfoService { +} diff --git a/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/service/impl/EsProductInfoServiceImpl.java b/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/service/impl/EsProductInfoServiceImpl.java new file mode 100644 index 0000000..216fbeb --- /dev/null +++ b/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/service/impl/EsProductInfoServiceImpl.java @@ -0,0 +1,37 @@ +package com.bawei.mall.product.service.impl; + +import com.bawei.es.remote.EsDocRemoteService; +import com.bawei.es.remote.EsIndexRemoteService; +import com.bawei.mall.product.service.EsProductInfoService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @program: mall_cloud + * @ClassName: EsProductInfoServiceImpl + * @author: Gyc + * @create: 2024-04-28 20:34 + **/ +@Service +public class EsProductInfoServiceImpl implements EsProductInfoService { + @Autowired + private EsIndexRemoteService esIndexRemoteService; + @Autowired + private EsDocRemoteService esDocRemoteService; + + + + + + + + + + + + + + + + +} diff --git a/bawei-mall/pom.xml b/bawei-mall/pom.xml index 439f51d..c5ef738 100644 --- a/bawei-mall/pom.xml +++ b/bawei-mall/pom.xml @@ -14,6 +14,7 @@ bawei-mall-product bawei-mall-search + bawei-mall-car