feat(商城): 升级pom依赖

master
wayn 2 years ago
parent 4953fb3372
commit 1ddd86ed34

@ -0,0 +1 @@
FROM maven:3.8.1-openjdk-11

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 wayn111
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -81,8 +81,8 @@ http {
} }
location /monitor { location /boot-admin {
proxy_pass http://localhost:89/; proxy_pass http://localhost:89;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host; proxy_set_header Host $http_host;

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.9</version> <version>2.5.12</version>
</parent> </parent>
<modules> <modules>
<module>waynboot-common</module> <module>waynboot-common</module>
@ -33,35 +33,36 @@
<!-- 阿里云docker容器命名空间 site:https://cr.console.aliyun.com/cn-shanghai/instance/namespaces--> <!-- 阿里云docker容器命名空间 site:https://cr.console.aliyun.com/cn-shanghai/instance/namespaces-->
<aliyun-docker-namespace>wayn111</aliyun-docker-namespace> <aliyun-docker-namespace>wayn111</aliyun-docker-namespace>
<docker-from-image-name>adoptopenjdk:11-jre-openj9</docker-from-image-name> <docker-from-image-name>adoptopenjdk:11-jre-openj9</docker-from-image-name>
<docker-username>填写你的阿里云账号</docker-username> <docker-username>1669738430@qq.com</docker-username>
<docker-passwqrd>填写你的密码site:https://cr.console.aliyun.com/cn-shanghai/instance/credentials</docker-passwqrd> <docker-passwqrd>he201011</docker-passwqrd>
<maven.compiler.source>${java.version}</maven.compiler.source> <maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target> <maven.compiler.target>${java.version}</maven.compiler.target>
<spring-boot.version>2.5.9</spring-boot.version> <spring-boot.version>2.5.12</spring-boot.version>
<mysql.connector.java.version>8.0.25</mysql.connector.java.version> <mysql.connector.java.version>8.0.25</mysql.connector.java.version>
<elasticsearch.version>7.13.4</elasticsearch.version> <elasticsearch.version>7.13.4</elasticsearch.version>
<mybatis-plus.version>3.5.0</mybatis-plus.version> <mybatis-plus.version>3.5.2</mybatis-plus.version>
<druid.version>1.2.8</druid.version> <druid.version>1.2.8</druid.version>
<commons.io.version>2.11.0</commons.io.version> <commons.io.version>2.11.0</commons.io.version>
<commons.collections.version>4.4</commons.collections.version> <commons.collections.version>4.4</commons.collections.version>
<commons.fileupload.version>1.4</commons.fileupload.version> <commons.fileupload.version>1.4</commons.fileupload.version>
<commons-lang3.version>3.12.0</commons-lang3.version> <commons-lang3.version>3.12.0</commons-lang3.version>
<fastjson.version>1.2.79</fastjson.version> <fastjson.version>1.2.83</fastjson.version>
<easy-captcha.version>1.6.2</easy-captcha.version> <easy-captcha.version>1.6.2</easy-captcha.version>
<knife4j.version>3.0.3</knife4j.version> <knife4j.version>3.0.3</knife4j.version>
<easypoi.version>4.4.0</easypoi.version> <easypoi.version>4.4.0</easypoi.version>
<jwt.version>3.18.3</jwt.version> <jwt.version>3.18.3</jwt.version>
<qiniu.version>7.9.1</qiniu.version> <qiniu.version>7.9.3</qiniu.version>
<mail.version>1.4.7</mail.version> <mail.version>1.6.2</mail.version>
<spring-boot-admin.version>2.6.2</spring-boot-admin.version> <spring-boot-admin.version>2.6.2</spring-boot-admin.version>
<xxl-job.version>2.3.0</xxl-job.version> <xxl-job.version>2.3.0</xxl-job.version>
<hutool.version>5.8.3</hutool.version>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
@ -169,12 +170,6 @@
<version>${commons.fileupload.version}</version> <version>${commons.fileupload.version}</version>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons.io.version}</version>
</dependency>
<!-- jwt验证 --> <!-- jwt验证 -->
<dependency> <dependency>
<groupId>com.auth0</groupId> <groupId>com.auth0</groupId>
@ -222,8 +217,8 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.mail</groupId> <groupId>com.sun.mail</groupId>
<artifactId>mail</artifactId> <artifactId>javax.mail</artifactId>
<version>${mail.version}</version> <version>${mail.version}</version>
</dependency> </dependency>
<!-- 分布式任务调度 --> <!-- 分布式任务调度 -->

@ -312,6 +312,43 @@ public void test(){
</plugin> </plugin>
</plugins> </plugins>
``` ```
### 8. 生产环境Redis连接长时间无响应被服务器断开问题通过`lettuceConnectionFactory.resetConnection();`重置redis连接
```java
@Autowired
private LettuceConnectionFactory lettuceConnectionFactory;
/**
* 获得缓存的基本对象。
*
* @param key 缓存键值
* @return 缓存键值对应的数据
*/
public <T> T getCacheObject(final String key) {
try {
ValueOperations<String, T> operation = redisTemplate.opsForValue();
return operation.get(key);
} catch (Exception e) {
log.error(e.getMessage(), e);
return retryGetCacheObject(key, 1);
}
}
public <T> T retryGetCacheObject(final String key, int retryCount) {
try {
log.info("retryGetCacheObject, key:{}, retryCount:{}", key, retryCount);
if (retryCount <= 0) {
return null;
}
lettuceConnectionFactory.resetConnection();
Thread.sleep(200L);
retryCount--;
ValueOperations<String, T> operation = redisTemplate.opsForValue();
return operation.get(key);
} catch (Exception e) {
log.error(e.getMessage(), e);
return retryGetCacheObject(key, retryCount);
}
}
```
- todo - todo

@ -0,0 +1,13 @@
# 该镜像需要依赖的基础镜像
FROM adoptopenjdk:11-jre-openj9
WORKDIR /root/workspace
# 将当前目录下的jar包复制到docker容器的/目录下
ADD waynboot-admin-api/target/waynboot-admin-api-1.1.0.jar /opt/waynboot-mall/waynboot-admin-api-1.1.0.jar
# 运行过程中创建一个mall-tiny-docker-file.jar文件
RUN bash -c 'touch /opt/waynboot-mall/waynboot-admin-api-1.1.0.jar'
# 声明服务运行在8080端口
EXPOSE 81
# 指定docker容器启动时运行jar包
ENTRYPOINT ["sh", "-c", "exec java -jar -Xms812m -Xmx812m -Xss512k /opt/waynboot-mall/waynboot-admin-api-1.1.0.jar"]
# 指定维护者的名字
MAINTAINER wayn111

@ -110,7 +110,7 @@
<dependency> <dependency>
<groupId>com.hierynomus</groupId> <groupId>com.hierynomus</groupId>
<artifactId>sshj</artifactId> <artifactId>sshj</artifactId>
<version>0.32.0</version> <version>0.33.0</version>
</dependency> </dependency>
<dependency> <dependency>

@ -0,0 +1,28 @@
#!/usr/bin/env bash
# 定义应用组名
group_name='waynboot-mall'
# 定义应用名称
app_name='waynboot-admin-api'
app_port=81
# 定义应用版本
app_version='1.1.0'
# 定义应用环境
profile_active='dev'
# coding docker host
coding_docker_host="waynaqua-docker.pkg.coding.net/wayn"
docker stop ${app_name}
echo '----stop container----'
docker rm ${app_name}
echo '----rm container----'
docker rmi ${coding_docker_host}/${group_name}/${app_name}:${app_version}
echo '----rm image----'
# 获取docker镜像
docker pull ${coding_docker_host}/${group_name}/${app_name}:${app_version}
echo '----pull image----'
docker run -p ${app_port}:${app_port} --name ${app_name} \
-e 'spring.profiles.active'=${profile_active} \
-e TZ="Asia/Shanghai" \
-v /etc/localtime:/etc/localtime \
-v /mydata/app/${app_name}/logs:/var/logs \
-d ${coding_docker_host}/${group_name}/${app_name}:${app_version}
echo '----start container----'

@ -29,7 +29,7 @@ public class EmailController {
sendMailVO.setSubject(subject); sendMailVO.setSubject(subject);
sendMailVO.setContent(content); sendMailVO.setContent(content);
sendMailVO.setTos(Arrays.asList(tos)); sendMailVO.setTos(Arrays.asList(tos));
MailUtil.sendMail(emailConfig, sendMailVO, false); MailUtil.sendMail(emailConfig, sendMailVO, false, false);
return R.success(); return R.success();
} }
} }

@ -3,13 +3,13 @@ package com.wayn.admin.api.controller.shop;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wayn.common.base.controller.BaseController; import com.wayn.common.base.controller.BaseController;
import com.wayn.common.constant.SysConstants;
import com.wayn.common.core.domain.shop.Goods; import com.wayn.common.core.domain.shop.Goods;
import com.wayn.common.core.domain.vo.GoodsSaveRelatedVO; import com.wayn.common.core.domain.vo.GoodsSaveRelatedVO;
import com.wayn.common.core.service.shop.IGoodsService; import com.wayn.common.core.service.shop.IGoodsService;
import com.wayn.common.enums.ReturnCodeEnum; import com.wayn.common.enums.ReturnCodeEnum;
import com.wayn.common.util.R; import com.wayn.common.util.R;
import com.wayn.common.util.file.FileUtils; import com.wayn.common.util.file.FileUtils;
import com.wayn.data.elastic.constant.EsConstants;
import com.wayn.data.elastic.manager.ElasticDocument; import com.wayn.data.elastic.manager.ElasticDocument;
import com.wayn.data.elastic.manager.ElasticEntity; import com.wayn.data.elastic.manager.ElasticEntity;
import com.wayn.data.redis.manager.RedisCache; import com.wayn.data.redis.manager.RedisCache;
@ -74,15 +74,15 @@ public class GoodsController extends BaseController {
@PostMapping("syncEs") @PostMapping("syncEs")
public R syncEs() { public R syncEs() {
if (redisCache.getCacheObject(SysConstants.ES_GOODS_INDEX_KEY) != null) { if (redisCache.getCacheObject(EsConstants.ES_GOODS_INDEX_KEY) != null) {
return R.error(ReturnCodeEnum.CUSTOM_ERROR.setMsg("正在同步,请稍等")); return R.error(ReturnCodeEnum.CUSTOM_ERROR.setMsg("正在同步,请稍等"));
} }
boolean flag = false; boolean flag = false;
redisCache.setCacheObject(SysConstants.ES_GOODS_INDEX_KEY, true, 3, TimeUnit.MINUTES); redisCache.setCacheObject(EsConstants.ES_GOODS_INDEX_KEY, true, 3, TimeUnit.MINUTES);
try { try {
elasticDocument.deleteIndex(SysConstants.ES_GOODS_INDEX); elasticDocument.deleteIndex(EsConstants.ES_GOODS_INDEX);
InputStream inputStream = this.getClass().getResourceAsStream(SysConstants.ES_INDEX_GOODS_FILENAME); InputStream inputStream = this.getClass().getResourceAsStream(EsConstants.ES_INDEX_GOODS_FILENAME);
if (elasticDocument.createIndex(SysConstants.ES_GOODS_INDEX, FileUtils.getContent(inputStream))) { if (elasticDocument.createIndex(EsConstants.ES_GOODS_INDEX, FileUtils.getContent(inputStream))) {
List<Goods> list = iGoodsService.list(); List<Goods> list = iGoodsService.list();
List<ElasticEntity> entities = new ArrayList<>(); List<ElasticEntity> entities = new ArrayList<>();
for (Goods goods : list) { for (Goods goods : list) {
@ -102,12 +102,12 @@ public class GoodsController extends BaseController {
elasticEntity.setData(map); elasticEntity.setData(map);
entities.add(elasticEntity); entities.add(elasticEntity);
} }
flag = elasticDocument.insertBatch("goods", entities); flag = elasticDocument.insertBatch(EsConstants.ES_GOODS_INDEX, entities);
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} finally { } finally {
redisCache.deleteObject(SysConstants.ES_GOODS_INDEX_KEY); redisCache.deleteObject(EsConstants.ES_GOODS_INDEX_KEY);
} }
return R.result(flag); return R.result(flag);
} }

@ -35,7 +35,7 @@ public class EmailConfigController {
if (!mailConfigService.checkMailConfig(emailConfig)) { if (!mailConfigService.checkMailConfig(emailConfig)) {
return R.error(ReturnCodeEnum.TOOL_EMAIL_ERROR); return R.error(ReturnCodeEnum.TOOL_EMAIL_ERROR);
} }
MailUtil.sendMail(emailConfig, mailVO, false); MailUtil.sendMail(emailConfig, mailVO, false, false);
return R.success(); return R.success();
} }
} }

@ -5,6 +5,7 @@ import com.wayn.common.constant.SysConstants;
import com.wayn.common.core.model.LoginUserDetail; import com.wayn.common.core.model.LoginUserDetail;
import com.wayn.common.core.service.system.IUserService; import com.wayn.common.core.service.system.IUserService;
import com.wayn.common.util.jwt.JwtUtil; import com.wayn.common.util.jwt.JwtUtil;
import com.wayn.data.redis.constant.CacheConstants;
import com.wayn.data.redis.manager.RedisCache; import com.wayn.data.redis.manager.RedisCache;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -66,7 +67,7 @@ public class TokenService {
loginUser.setLoginTime(System.currentTimeMillis()); loginUser.setLoginTime(System.currentTimeMillis());
loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE); loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE);
// 根据uuid将loginUser缓存 // 根据uuid将loginUser缓存
String userKey = SysConstants.LOGIN_TOKEN_KEY + loginUser.getToken(); String userKey = CacheConstants.LOGIN_TOKEN_KEY + loginUser.getToken();
redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES); redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES);
} }
@ -99,7 +100,7 @@ public class TokenService {
* @return tokenkey * @return tokenkey
*/ */
private String getTokenKey(String sign) { private String getTokenKey(String sign) {
return SysConstants.LOGIN_TOKEN_KEY + sign; return CacheConstants.LOGIN_TOKEN_KEY + sign;
} }
} }

@ -23,7 +23,7 @@ spring:
boot: boot:
admin: admin:
client: client:
url: http://localhost:89 url: http://localhost:89/boot-admin
# token配置 # token配置
@ -38,7 +38,7 @@ token:
# 日志配置 # 日志配置
logging: logging:
level: level:
com.wayn: debug com.wayn: info
org.springframework: info org.springframework: info
com.baomidou: info com.baomidou: info
file: file:

@ -98,17 +98,7 @@
<dependency> <dependency>
<groupId>commons-fileupload</groupId> <groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId> <artifactId>commons-fileupload</artifactId>
<exclusions> <version>${commons.fileupload.version}</version>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons.io.version}</version>
</dependency> </dependency>
<!-- jwt验证 --> <!-- jwt验证 -->
@ -150,21 +140,21 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.mail</groupId> <groupId>com.sun.mail</groupId>
<artifactId>mail</artifactId> <artifactId>javax.mail</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.binarywang</groupId> <groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-pay</artifactId> <artifactId>weixin-java-pay</artifactId>
<version>4.2.2.B</version> <version>4.3.5.B</version>
</dependency> </dependency>
<!--支付宝依赖--> <!--支付宝依赖-->
<dependency> <dependency>
<groupId>com.alipay.sdk</groupId> <groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId> <artifactId>alipay-sdk-java</artifactId>
<version>4.22.22.ALL</version> <version>4.31.12.ALL</version>
</dependency> </dependency>
<dependency> <dependency>

@ -8,6 +8,12 @@ public class SysConstants {
// ------------------------------------------------ 用户常量 ------------------------------------------------------------------------ // ------------------------------------------------ 用户常量 ------------------------------------------------------------------------
public static final String DEFAULT_AVATAR = "http://cdn.wayn.xin/091fffcf8e8c25ed8d2cb926be60a16a.png"; public static final String DEFAULT_AVATAR = "http://cdn.wayn.xin/091fffcf8e8c25ed8d2cb926be60a16a.png";
/**
* , todo
*/
public static final String CACHE_PREFIX = "waynboot-mall:";
/** /**
* *
*/ */
@ -16,18 +22,10 @@ public class SysConstants {
* *
*/ */
public static final String TOKEN = "token"; public static final String TOKEN = "token";
/**
* redis key
*/
public static final String CAPTCHA_CODE_KEY = "captcha_codes:";
/** /**
* *
*/ */
public static final Integer CAPTCHA_EXPIRATION = 2; public static final Integer CAPTCHA_EXPIRATION = 2;
/**
* redis key
*/
public static final String LOGIN_TOKEN_KEY = "login_tokens:";
/** /**
* key * key
@ -73,19 +71,4 @@ public class SysConstants {
* stringbooleanerror * stringbooleanerror
*/ */
public final static String STRING_FALSE = "false"; public final static String STRING_FALSE = "false";
// ------------------------------------------------ es常量 ------------------------------------------------------------------------
/**
*
*/
public static final String ES_GOODS_INDEX = "goods";
/**
*
*/
public static final String ES_GOODS_INDEX_KEY = "es_goods";
/**
* es
*/
public static String ES_INDEX_GOODS_FILENAME = "/es/index/goods.json";
} }

@ -17,21 +17,31 @@ public class EmailConfig implements Serializable {
@TableId(type = IdType.AUTO) @TableId(type = IdType.AUTO)
private Long id; private Long id;
/** 邮件服务器SMTP地址 */ /**
* SMTP
*/
@NotBlank(message = "邮件服务器SMTP地址不能为空") @NotBlank(message = "邮件服务器SMTP地址不能为空")
private String host; private String host;
/** 邮件服务器SMTP端口 */ /**
* SMTP
*/
@NotBlank(message = "邮件服务器SMTP端口不能为空") @NotBlank(message = "邮件服务器SMTP端口不能为空")
private String port; private Integer port;
private Integer sslPort;
@NotBlank(message = "邮箱密钥不能为空") @NotBlank(message = "邮箱密钥不能为空")
private String pass; private String pass;
/** 发件人邮箱 */ /**
*
*/
@NotBlank(message = "发件人邮箱不能为空") @NotBlank(message = "发件人邮箱不能为空")
private String fromUser; private String fromUser;
/** 发件者用户名 */ /**
*
*/
private String user; private String user;
} }

@ -12,6 +12,7 @@ import com.wayn.common.core.service.shop.*;
import com.wayn.common.enums.ReturnCodeEnum; import com.wayn.common.enums.ReturnCodeEnum;
import com.wayn.common.exception.BusinessException; import com.wayn.common.exception.BusinessException;
import com.wayn.common.util.R; import com.wayn.common.util.R;
import com.wayn.data.elastic.constant.EsConstants;
import com.wayn.data.elastic.manager.ElasticDocument; import com.wayn.data.elastic.manager.ElasticDocument;
import com.wayn.data.elastic.manager.ElasticEntity; import com.wayn.data.elastic.manager.ElasticEntity;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -161,7 +162,7 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
iGoodsAttributeService.remove(new QueryWrapper<GoodsAttribute>().eq("goods_id", goodsId)); iGoodsAttributeService.remove(new QueryWrapper<GoodsAttribute>().eq("goods_id", goodsId));
iGoodsProductService.remove(new QueryWrapper<GoodsProduct>().eq("goods_id", goodsId)); iGoodsProductService.remove(new QueryWrapper<GoodsProduct>().eq("goods_id", goodsId));
// 同步es // 同步es
boolean one = elasticDocument.delete(SysConstants.ES_GOODS_INDEX, goodsId.toString()); boolean one = elasticDocument.delete(EsConstants.ES_GOODS_INDEX, goodsId.toString());
if (!one) { if (!one) {
throw new BusinessException("删除商品同步es失败"); throw new BusinessException("删除商品同步es失败");
} }
@ -263,7 +264,7 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
map.put("isOnSale", goods.getIsOnSale()); map.put("isOnSale", goods.getIsOnSale());
map.put("createTime", goods.getCreateTime()); map.put("createTime", goods.getCreateTime());
elasticEntity.setData(map); elasticEntity.setData(map);
if (!elasticDocument.insertOrUpdateOne(SysConstants.ES_GOODS_INDEX, elasticEntity)) { if (!elasticDocument.insertOrUpdateOne(EsConstants.ES_GOODS_INDEX, elasticEntity)) {
throw new BusinessException("商品同步es失败"); throw new BusinessException("商品同步es失败");
} }
return true; return true;

@ -21,7 +21,7 @@ import java.util.Properties;
@Slf4j @Slf4j
public class MailUtil { public class MailUtil {
public static void sendMail(EmailConfig emailConfig, SendMailVO mailVO, boolean isHtml) { public static void sendMail(EmailConfig emailConfig, SendMailVO mailVO, boolean isHtml, boolean ssl) {
try { try {
// 设置发件人 // 设置发件人
String from = emailConfig.getFromUser(); String from = emailConfig.getFromUser();
@ -32,15 +32,18 @@ public class MailUtil {
String host = emailConfig.getHost(); String host = emailConfig.getHost();
// 获取系统属性 // 获取系统属性
Properties properties = System.getProperties(); Properties properties = System.getProperties();
properties.setProperty("mail.smtp.port", String.valueOf(emailConfig.getPort()));
// SSL加密 // SSL加密
MailSSLSocketFactory sf = new MailSSLSocketFactory(); if (ssl) {
sf.setTrustAllHosts(true); MailSSLSocketFactory sf = new MailSSLSocketFactory();
properties.put("mail.smtp.ssl.enable", "true"); sf.setTrustAllHosts(true);
properties.put("mail.smtp.ssl.socketFactory", sf); properties.put("mail.smtp.ssl.enable", "true");
properties.put("mail.smtp.ssl.socketFactory", sf);
properties.setProperty("mail.smtp.port", String.valueOf(emailConfig.getSslPort()));
}
// 设置系统属性 // 设置系统属性
properties.setProperty("mail.smtp.host", host); properties.setProperty("mail.smtp.host", host);
properties.setProperty("mail.transport.protocol", "smtp"); properties.setProperty("mail.transport.protocol", "smtp");
properties.setProperty("mail.smtp.port", emailConfig.getPort());
properties.put("mail.smtp.auth", "true"); properties.put("mail.smtp.auth", "true");
// 获取发送邮件会话、获取第三方登录授权码 // 获取发送邮件会话、获取第三方登录授权码
Session session = Session.getDefaultInstance(properties, new Authenticator() { Session session = Session.getDefaultInstance(properties, new Authenticator() {
@ -49,7 +52,7 @@ public class MailUtil {
return new PasswordAuthentication(from, emailConfig.getPass()); return new PasswordAuthentication(from, emailConfig.getPass());
} }
}); });
session.setDebug(true); session.setDebug(false);
// 创建默认的 MimeMessage 对象 // 创建默认的 MimeMessage 对象
MimeMessage message = new MimeMessage(session); MimeMessage message = new MimeMessage(session);
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8"); MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
@ -69,4 +72,18 @@ public class MailUtil {
} }
} }
public static void main(String[] args) {
EmailConfig emailConfig = new EmailConfig();
emailConfig.setFromUser("1669738430@qq.com");
emailConfig.setHost("smtp.qq.com");
emailConfig.setPass("vxhduzllgqfnjiif");
emailConfig.setPort(25);
emailConfig.setUser("wayn");
SendMailVO sendMailVO = new SendMailVO();
sendMailVO.setContent("123");
sendMailVO.setSubject("title");
sendMailVO.setTos(List.of("1669738430@qq.com"));
sendMail(emailConfig, sendMailVO, false, false);
}
} }

@ -6,7 +6,7 @@ spring:
master: master:
url: jdbc:mysql://127.0.0.1:3306/wayn_shop?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 url: jdbc:mysql://127.0.0.1:3306/wayn_shop?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root username: root
password: root password:
# 从库数据源 # 从库数据源
slave: slave:
# 从数据源开关/默认关闭 # 从数据源开关/默认关闭
@ -22,6 +22,8 @@ spring:
database: 2 database: 2
timeout: 5000 timeout: 5000
expire: 400 expire: 400
lettuce:
shutdown-timeout: 100ms
# cluster: # cluster:
# nodes: # nodes:
# - 127.0.0.1:1681 # - 127.0.0.1:1681
@ -32,7 +34,7 @@ spring:
# - 127.0.0.1:1686 # - 127.0.0.1:1686
#配置rabbitMq 服务器 #配置rabbitMq 服务器
rabbitmq: rabbitmq:
host: wayn.ltd host: 127.0.0.1
port: 5672 port: 5672
username: guest username: guest
password: guest password: guest
@ -43,7 +45,7 @@ spring:
publisher-returns: true publisher-returns: true
es: es:
host: huawei.wayn.ltd host: 127.0.0.1
port: 9200 port: 9200
scheme: http scheme: http
shards: 3 shards: 3
@ -57,6 +59,5 @@ alipay:
gateway: https://openapi.alipaydev.com/gateway.do gateway: https://openapi.alipaydev.com/gateway.do
charset: UTF-8 charset: UTF-8
format: json format: json
# log_path: /opt/newbeeplus/log log-path: ./log
log_path: D://newbeemallplus//log
signtype: RSA2 signtype: RSA2

@ -0,0 +1,18 @@
package com.wayn.data.elastic.constant;
public class EsConstants {
/**
*
*/
public static final String ES_GOODS_INDEX = "goods";
/**
*
*/
public static final String ES_GOODS_INDEX_KEY = "es_goods";
/**
* es
*/
public static String ES_INDEX_GOODS_FILENAME = "/es/index/goods.json";
}

@ -14,7 +14,6 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>
<version>${spring-boot.version}</version>
</dependency> </dependency>
<dependency> <dependency>

@ -4,6 +4,7 @@ import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig; import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer; import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer;
import com.wayn.data.redis.constant.CacheConstants;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager; import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.CachingConfigurerSupport;
@ -66,7 +67,7 @@ public class CacheConfig extends CachingConfigurerSupport {
private RedisCacheConfiguration defaultCacheConfig() { private RedisCacheConfiguration defaultCacheConfig() {
return RedisCacheConfiguration.defaultCacheConfig() return RedisCacheConfiguration.defaultCacheConfig()
.prefixCacheNameWith("redis:cache") .prefixCacheNameWith(CacheConstants.CACHE_PREFIX)
.entryTtl(Duration.ofSeconds(expire)) .entryTtl(Duration.ofSeconds(expire))
.disableCachingNullValues(); .disableCachingNullValues();
} }

@ -0,0 +1,18 @@
package com.wayn.data.redis.constant;
/**
*
*/
public class CacheConstants {
/**
* ,
*/
public static final String CACHE_PREFIX = "waynboot-mall:";
/**
* redis key
*/
public static final String LOGIN_TOKEN_KEY = CACHE_PREFIX + "login_tokens:";
}

@ -1,6 +1,9 @@
package com.wayn.data.redis.manager; package com.wayn.data.redis.manager;
import io.lettuce.core.RedisClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.HashOperations; import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations; import org.springframework.data.redis.core.ValueOperations;
@ -18,12 +21,16 @@ import java.util.concurrent.TimeUnit;
* *
* @author ruoyi * @author ruoyi
**/ **/
@Slf4j
@SuppressWarnings(value = {"unchecked", "rawtypes"}) @SuppressWarnings(value = {"unchecked", "rawtypes"})
@Component @Component
public class RedisCache { public class RedisCache {
@Autowired @Autowired
public RedisTemplate redisTemplate; public RedisTemplate redisTemplate;
@Autowired
private LettuceConnectionFactory lettuceConnectionFactory;
/** /**
* IntegerString * IntegerString
* *
@ -86,10 +93,33 @@ public class RedisCache {
* @return * @return
*/ */
public <T> T getCacheObject(final String key) { public <T> T getCacheObject(final String key) {
ValueOperations<String, T> operation = redisTemplate.opsForValue(); try {
return operation.get(key); ValueOperations<String, T> operation = redisTemplate.opsForValue();
return operation.get(key);
} catch (Exception e) {
log.error(e.getMessage(), e);
return retryGetCacheObject(key, 1);
}
} }
public <T> T retryGetCacheObject(final String key, int retryCount) {
try {
log.info("retryGetCacheObject, key:{}, retryCount:{}", key, retryCount);
if (retryCount <= 0) {
return null;
}
lettuceConnectionFactory.resetConnection();
Thread.sleep(200L);
retryCount--;
ValueOperations<String, T> operation = redisTemplate.opsForValue();
return operation.get(key);
} catch (Exception e) {
log.error(e.getMessage(), e);
return retryGetCacheObject(key, retryCount);
}
}
/** /**
* key * key
* *

@ -49,7 +49,6 @@
<dependency> <dependency>
<groupId>org.freemarker</groupId> <groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId> <artifactId>freemarker</artifactId>
<version>2.3.30</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

@ -0,0 +1,13 @@
# 该镜像需要依赖的基础镜像
FROM adoptopenjdk:11-jre-openj9
WORKDIR /root/workspace
# 将当前目录下的jar包复制到docker容器的/目录下
ADD waynboot-message-consumer/target/waynboot-message-consumer-1.1.0.jar /opt/waynboot-mall/waynboot-message-consumer-1.1.0.jar
# 运行过程中创建一个mall-tiny-docker-file.jar文件
RUN bash -c 'touch /opt/waynboot-mall/waynboot-message-consumer-1.1.0.jar'
# 声明服务运行在8080端口
EXPOSE 85
# 指定docker容器启动时运行jar包
ENTRYPOINT ["sh", "-c", "exec java -jar -Xms812m -Xmx812m -Xss512k /opt/waynboot-mall/waynboot-message-consumer-1.1.0.jar"]
# 指定维护者的名字
MAINTAINER wayn111

@ -108,16 +108,16 @@
</executions> </executions>
</plugin> </plugin>
<plugin> <!--<plugin>
<groupId>com.google.cloud.tools</groupId> <groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId> <artifactId>jib-maven-plugin</artifactId>
<version>3.0.0</version> <version>3.0.0</version>
<configuration> <configuration>
<!--配置基本镜像--> &lt;!&ndash;配置基本镜像&ndash;&gt;
<from> <from>
<image>${docker-from-image-name}</image> <image>${docker-from-image-name}</image>
</from> </from>
<!--配置最终推送的地址,仓库名,镜像名--> &lt;!&ndash;配置最终推送的地址,仓库名,镜像名&ndash;&gt;
<to> <to>
<image>registry.cn-shanghai.aliyuncs.com/${aliyun-docker-namespace}/${project.artifactId} <image>registry.cn-shanghai.aliyuncs.com/${aliyun-docker-namespace}/${project.artifactId}
</image> </image>
@ -141,7 +141,7 @@
</container> </container>
</configuration> </configuration>
<!-- 绑定到maven lifecicle--> &lt;!&ndash; 绑定到maven lifecicle&ndash;&gt;
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
@ -150,7 +150,7 @@
</goals> </goals>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>-->
</plugins> </plugins>
</build> </build>

@ -29,7 +29,7 @@ spring:
boot: boot:
admin: admin:
client: client:
url: http://localhost:89 url: http://localhost:89/boot-admin
# 日志配置 # 日志配置

@ -0,0 +1,13 @@
# 该镜像需要依赖的基础镜像
FROM adoptopenjdk:11-jre-openj9
WORKDIR /root/workspace
# 将当前目录下的jar包复制到docker容器的/目录下
ADD waynboot-mobile-api/target/waynboot-mobile-api-1.1.0.jar /opt/waynboot-mall/waynboot-mobile-api-1.1.0.jar
# 运行过程中创建一个mall-tiny-docker-file.jar文件
RUN bash -c 'touch /opt/waynboot-mall/waynboot-mobile-api-1.1.0.jar'
# 声明服务运行在8080端口
EXPOSE 82
# 指定docker容器启动时运行jar包
ENTRYPOINT ["sh", "-c", "exec java -jar -Xms1024m -Xmx1024m -Xss512k /opt/waynboot-mall/waynboot-mobile-api-1.1.0.jar"]
# 指定维护者的名字
MAINTAINER wayn111

@ -58,7 +58,7 @@
<dependency> <dependency>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
<version>5.7.19</version> <version>${hutool.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>

@ -110,7 +110,7 @@ public class LoginController {
sendMailVO.setSubject("mall商城注册通知"); sendMailVO.setSubject("mall商城注册通知");
sendMailVO.setContent("邮箱验证码:" + verCode); sendMailVO.setContent("邮箱验证码:" + verCode);
sendMailVO.setTos(Collections.singletonList(registryObj.getEmail())); sendMailVO.setTos(Collections.singletonList(registryObj.getEmail()));
MailUtil.sendMail(emailConfig, sendMailVO, false); MailUtil.sendMail(emailConfig, sendMailVO, false, false);
return R.success().add("key", key); return R.success().add("key", key);
} }
} }

@ -91,7 +91,7 @@ public class UserController {
sendMailVO.setSubject("mall商城重置密码通知"); sendMailVO.setSubject("mall商城重置密码通知");
sendMailVO.setContent("邮箱验证码:" + verCode); sendMailVO.setContent("邮箱验证码:" + verCode);
sendMailVO.setTos(Collections.singletonList(registryObj.getEmail())); sendMailVO.setTos(Collections.singletonList(registryObj.getEmail()));
MailUtil.sendMail(emailConfig, sendMailVO, false); MailUtil.sendMail(emailConfig, sendMailVO, false, false);
return R.success().add("key", key); return R.success().add("key", key);
} }

@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays; import java.util.List;
@RestController @RestController
@RequestMapping("message/email") @RequestMapping("message/email")
@ -25,8 +25,8 @@ public class EmailController {
SendMailVO sendMailVO = new SendMailVO(); SendMailVO sendMailVO = new SendMailVO();
sendMailVO.setSubject(subject); sendMailVO.setSubject(subject);
sendMailVO.setContent(content); sendMailVO.setContent(content);
sendMailVO.setTos(Arrays.asList(tos)); sendMailVO.setTos(List.of(tos));
MailUtil.sendMail(emailConfig, sendMailVO, false); MailUtil.sendMail(emailConfig, sendMailVO, false, false);
return R.success(); return R.success();
} }
} }

@ -200,26 +200,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
} else { } else {
checkedGoodsList = iCartService.listByIds(cartIdArr); checkedGoodsList = iCartService.listByIds(cartIdArr);
} }
List<Long> goodsIds = checkedGoodsList.stream().map(Cart::getGoodsId).collect(Collectors.toList());
List<GoodsProduct> goodsProducts = iGoodsProductService.list(new QueryWrapper<GoodsProduct>().in("goods_id", goodsIds));
Map<Long, GoodsProduct> goodsIdMap = goodsProducts.stream().collect(
Collectors.toMap(GoodsProduct::getId, goodsProduct -> goodsProduct));
// 商品货品数量减少
for (Cart checkGoods : checkedGoodsList) {
Long productId = checkGoods.getProductId();
Long goodsId = checkGoods.getGoodsId();
GoodsProduct product = goodsIdMap.get(productId);
int remainNumber = product.getNumber() - checkGoods.getNumber();
if (remainNumber < 0) {
Goods goods = iGoodsService.getById(goodsId);
String goodsName = goods.getName();
String[] specifications = product.getSpecifications();
throw new BusinessException(String.format("%s,%s 库存不足", goodsName, StringUtils.join(specifications, " ")));
}
if (!iGoodsProductService.reduceStock(productId, checkGoods.getNumber())) {
throw new BusinessException("商品货品库存减少失败");
}
}
// 商品费用 // 商品费用
BigDecimal checkedGoodsPrice = new BigDecimal("0.00"); BigDecimal checkedGoodsPrice = new BigDecimal("0.00");
@ -252,7 +232,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
// 异步下单 // 异步下单
String uid = IdUtil.getUid(); String uid = IdUtil.getUid();
System.out.println(uid);
CorrelationData correlationData = new CorrelationData(uid); CorrelationData correlationData = new CorrelationData(uid);
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("order", orderDTO); map.put("order", orderDTO);
@ -292,6 +271,27 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
checkedGoodsList = iCartService.listByIds(cartIdArr); checkedGoodsList = iCartService.listByIds(cartIdArr);
} }
// 商品货品库存数量减少
List<Long> goodsIds = checkedGoodsList.stream().map(Cart::getGoodsId).collect(Collectors.toList());
List<GoodsProduct> goodsProducts = iGoodsProductService.list(new QueryWrapper<GoodsProduct>().in("goods_id", goodsIds));
Map<Long, GoodsProduct> goodsIdMap = goodsProducts.stream().collect(
Collectors.toMap(GoodsProduct::getId, goodsProduct -> goodsProduct));
for (Cart checkGoods : checkedGoodsList) {
Long productId = checkGoods.getProductId();
Long goodsId = checkGoods.getGoodsId();
GoodsProduct product = goodsIdMap.get(productId);
int remainNumber = product.getNumber() - checkGoods.getNumber();
if (remainNumber < 0) {
Goods goods = iGoodsService.getById(goodsId);
String goodsName = goods.getName();
String[] specifications = product.getSpecifications();
throw new BusinessException(String.format("%s,%s 库存不足", goodsName, StringUtils.join(specifications, " ")));
}
if (!iGoodsProductService.reduceStock(productId, checkGoods.getNumber())) {
throw new BusinessException("商品货品库存减少失败");
}
}
// 商品费用 // 商品费用
BigDecimal checkedGoodsPrice = new BigDecimal("0.00"); BigDecimal checkedGoodsPrice = new BigDecimal("0.00");
for (Cart checkGoods : checkedGoodsList) { for (Cart checkGoods : checkedGoodsList) {
@ -342,7 +342,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
} }
Long orderId = order.getId(); Long orderId = order.getId();
List<OrderGoods> orderGoodsList = new ArrayList<>(); List<OrderGoods> orderGoodsList = new ArrayList<>(checkedGoodsList.size());
// 添加订单商品表项 // 添加订单商品表项
for (Cart cartGoods : checkedGoodsList) { for (Cart cartGoods : checkedGoodsList) {
// 订单商品 // 订单商品

@ -4,6 +4,7 @@ import com.auth0.jwt.interfaces.DecodedJWT;
import com.wayn.common.constant.SysConstants; import com.wayn.common.constant.SysConstants;
import com.wayn.common.core.service.system.IUserService; import com.wayn.common.core.service.system.IUserService;
import com.wayn.common.util.jwt.JwtUtil; import com.wayn.common.util.jwt.JwtUtil;
import com.wayn.data.redis.constant.CacheConstants;
import com.wayn.data.redis.manager.RedisCache; import com.wayn.data.redis.manager.RedisCache;
import com.wayn.mobile.framework.security.LoginUserDetail; import com.wayn.mobile.framework.security.LoginUserDetail;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -67,7 +68,7 @@ public class TokenService {
loginUser.setLoginTime(System.currentTimeMillis()); loginUser.setLoginTime(System.currentTimeMillis());
loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_DAY); loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_DAY);
// 根据uuid将loginUser缓存 // 根据uuid将loginUser缓存
String userKey = SysConstants.LOGIN_TOKEN_KEY + loginUser.getToken(); String userKey = CacheConstants.LOGIN_TOKEN_KEY + loginUser.getToken();
redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.DAYS); redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.DAYS);
} }
@ -100,7 +101,7 @@ public class TokenService {
* @return tokenkey * @return tokenkey
*/ */
private String getTokenKey(String sign) { private String getTokenKey(String sign) {
return SysConstants.LOGIN_TOKEN_KEY + sign; return CacheConstants.LOGIN_TOKEN_KEY + sign;
} }
} }

@ -30,7 +30,7 @@ spring:
boot: boot:
admin: admin:
client: client:
url: http://localhost:89 url: http://localhost:89/boot-admin
# token配置 # token配置
token: token:

@ -5,6 +5,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
@Configuration @Configuration
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter { public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
@ -36,6 +37,10 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
.and() .and()
.httpBasic().and() .httpBasic().and()
.csrf() .csrf()
.disable(); .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.ignoringAntMatchers(
"/instances",
"/actuator/**"
);
} }
} }

@ -1,9 +1,19 @@
server: server:
port: 89 port: 89
shutdown: graceful # 优雅关机 shutdown: graceful # 优雅关机
servlet:
context-path: /boot-admin
spring: spring:
security: security:
user: user:
name: user name: user
password: admin123 password: admin123
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS

Loading…
Cancel
Save