diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7aaf326 --- /dev/null +++ b/Dockerfile @@ -0,0 +1 @@ +FROM maven:3.8.1-openjdk-11 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..01be60d --- /dev/null +++ b/LICENSE @@ -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. diff --git a/nginx-conf/nginx.conf b/nginx-conf/nginx.conf index 5ab7e41..a1de27c 100644 --- a/nginx-conf/nginx.conf +++ b/nginx-conf/nginx.conf @@ -81,8 +81,8 @@ http { } - location /monitor { - proxy_pass http://localhost:89/; + location /boot-admin { + proxy_pass http://localhost:89; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; diff --git a/pom.xml b/pom.xml index d28d59f..411ee35 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.springframework.boot spring-boot-starter-parent - 2.5.9 + 2.5.12 waynboot-common @@ -33,35 +33,36 @@ wayn111 adoptopenjdk:11-jre-openj9 - 填写你的阿里云账号 - 填写你的密码,site:https://cr.console.aliyun.com/cn-shanghai/instance/credentials + 1669738430@qq.com + he201011 ${java.version} ${java.version} - 2.5.9 + 2.5.12 8.0.25 7.13.4 - 3.5.0 + 3.5.2 1.2.8 2.11.0 4.4 1.4 3.12.0 - 1.2.79 + 1.2.83 1.6.2 3.0.3 4.4.0 3.18.3 - 7.9.1 - 1.4.7 + 7.9.3 + 1.6.2 2.6.2 2.3.0 + 5.8.3 - org.springframework.boot - spring-boot-starter-actuator + org.springframework.boot + spring-boot-starter-actuator @@ -169,12 +170,6 @@ ${commons.fileupload.version} - - commons-io - commons-io - ${commons.io.version} - - com.auth0 @@ -222,8 +217,8 @@ - javax.mail - mail + com.sun.mail + javax.mail ${mail.version} diff --git a/readme.md b/readme.md index 080b1b9..d496127 100644 --- a/readme.md +++ b/readme.md @@ -312,6 +312,43 @@ public void test(){ ``` +### 8. 生产环境Redis连接,长时间无响应被服务器断开问题,通过`lettuceConnectionFactory.resetConnection();`重置redis连接 +```java + @Autowired + private LettuceConnectionFactory lettuceConnectionFactory; + /** + * 获得缓存的基本对象。 + * + * @param key 缓存键值 + * @return 缓存键值对应的数据 + */ + public T getCacheObject(final String key) { + try { + ValueOperations operation = redisTemplate.opsForValue(); + return operation.get(key); + } catch (Exception e) { + log.error(e.getMessage(), e); + return retryGetCacheObject(key, 1); + } + } + + public 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 operation = redisTemplate.opsForValue(); + return operation.get(key); + } catch (Exception e) { + log.error(e.getMessage(), e); + return retryGetCacheObject(key, retryCount); + } + } +``` - todo diff --git a/waynboot-admin-api/Dockerfile b/waynboot-admin-api/Dockerfile new file mode 100644 index 0000000..fe65e4c --- /dev/null +++ b/waynboot-admin-api/Dockerfile @@ -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 diff --git a/waynboot-admin-api/pom.xml b/waynboot-admin-api/pom.xml index 4ce381a..7a2b792 100644 --- a/waynboot-admin-api/pom.xml +++ b/waynboot-admin-api/pom.xml @@ -110,7 +110,7 @@ com.hierynomus sshj - 0.32.0 + 0.33.0 diff --git a/waynboot-admin-api/run.sh b/waynboot-admin-api/run.sh new file mode 100644 index 0000000..d064b90 --- /dev/null +++ b/waynboot-admin-api/run.sh @@ -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----' diff --git a/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/message/EmailController.java b/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/message/EmailController.java index 486d4db..229484e 100644 --- a/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/message/EmailController.java +++ b/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/message/EmailController.java @@ -29,7 +29,7 @@ public class EmailController { sendMailVO.setSubject(subject); sendMailVO.setContent(content); sendMailVO.setTos(Arrays.asList(tos)); - MailUtil.sendMail(emailConfig, sendMailVO, false); + MailUtil.sendMail(emailConfig, sendMailVO, false, false); return R.success(); } } diff --git a/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/shop/GoodsController.java b/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/shop/GoodsController.java index 782f63d..4ce6068 100644 --- a/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/shop/GoodsController.java +++ b/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/shop/GoodsController.java @@ -3,13 +3,13 @@ package com.wayn.admin.api.controller.shop; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.vo.GoodsSaveRelatedVO; import com.wayn.common.core.service.shop.IGoodsService; import com.wayn.common.enums.ReturnCodeEnum; import com.wayn.common.util.R; 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.ElasticEntity; import com.wayn.data.redis.manager.RedisCache; @@ -74,15 +74,15 @@ public class GoodsController extends BaseController { @PostMapping("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("正在同步,请稍等")); } 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 { - elasticDocument.deleteIndex(SysConstants.ES_GOODS_INDEX); - InputStream inputStream = this.getClass().getResourceAsStream(SysConstants.ES_INDEX_GOODS_FILENAME); - if (elasticDocument.createIndex(SysConstants.ES_GOODS_INDEX, FileUtils.getContent(inputStream))) { + elasticDocument.deleteIndex(EsConstants.ES_GOODS_INDEX); + InputStream inputStream = this.getClass().getResourceAsStream(EsConstants.ES_INDEX_GOODS_FILENAME); + if (elasticDocument.createIndex(EsConstants.ES_GOODS_INDEX, FileUtils.getContent(inputStream))) { List list = iGoodsService.list(); List entities = new ArrayList<>(); for (Goods goods : list) { @@ -102,12 +102,12 @@ public class GoodsController extends BaseController { elasticEntity.setData(map); entities.add(elasticEntity); } - flag = elasticDocument.insertBatch("goods", entities); + flag = elasticDocument.insertBatch(EsConstants.ES_GOODS_INDEX, entities); } } catch (Exception e) { log.error(e.getMessage(), e); } finally { - redisCache.deleteObject(SysConstants.ES_GOODS_INDEX_KEY); + redisCache.deleteObject(EsConstants.ES_GOODS_INDEX_KEY); } return R.result(flag); } diff --git a/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/tool/EmailConfigController.java b/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/tool/EmailConfigController.java index 0367f18..e675db3 100644 --- a/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/tool/EmailConfigController.java +++ b/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/tool/EmailConfigController.java @@ -35,7 +35,7 @@ public class EmailConfigController { if (!mailConfigService.checkMailConfig(emailConfig)) { return R.error(ReturnCodeEnum.TOOL_EMAIL_ERROR); } - MailUtil.sendMail(emailConfig, mailVO, false); + MailUtil.sendMail(emailConfig, mailVO, false, false); return R.success(); } } diff --git a/waynboot-admin-api/src/main/java/com/wayn/admin/framework/security/service/TokenService.java b/waynboot-admin-api/src/main/java/com/wayn/admin/framework/security/service/TokenService.java index 1bbbe7b..109604d 100644 --- a/waynboot-admin-api/src/main/java/com/wayn/admin/framework/security/service/TokenService.java +++ b/waynboot-admin-api/src/main/java/com/wayn/admin/framework/security/service/TokenService.java @@ -5,6 +5,7 @@ import com.wayn.common.constant.SysConstants; import com.wayn.common.core.model.LoginUserDetail; import com.wayn.common.core.service.system.IUserService; import com.wayn.common.util.jwt.JwtUtil; +import com.wayn.data.redis.constant.CacheConstants; import com.wayn.data.redis.manager.RedisCache; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -66,7 +67,7 @@ public class TokenService { loginUser.setLoginTime(System.currentTimeMillis()); loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE); // 根据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); } @@ -99,7 +100,7 @@ public class TokenService { * @return 返回token的key */ private String getTokenKey(String sign) { - return SysConstants.LOGIN_TOKEN_KEY + sign; + return CacheConstants.LOGIN_TOKEN_KEY + sign; } } diff --git a/waynboot-admin-api/src/main/resources/application.yml b/waynboot-admin-api/src/main/resources/application.yml index 2c77192..dd04729 100644 --- a/waynboot-admin-api/src/main/resources/application.yml +++ b/waynboot-admin-api/src/main/resources/application.yml @@ -23,7 +23,7 @@ spring: boot: admin: client: - url: http://localhost:89 + url: http://localhost:89/boot-admin # token配置 @@ -38,7 +38,7 @@ token: # 日志配置 logging: level: - com.wayn: debug + com.wayn: info org.springframework: info com.baomidou: info file: diff --git a/waynboot-common/pom.xml b/waynboot-common/pom.xml index c9b16d6..2ab30b8 100644 --- a/waynboot-common/pom.xml +++ b/waynboot-common/pom.xml @@ -98,17 +98,7 @@ commons-fileupload commons-fileupload - - - org.apache.commons - commons-io - - - - - commons-io - commons-io - ${commons.io.version} + ${commons.fileupload.version} @@ -150,21 +140,21 @@ - javax.mail - mail + com.sun.mail + javax.mail com.github.binarywang weixin-java-pay - 4.2.2.B + 4.3.5.B com.alipay.sdk alipay-sdk-java - 4.22.22.ALL + 4.31.12.ALL diff --git a/waynboot-common/src/main/java/com/wayn/common/constant/SysConstants.java b/waynboot-common/src/main/java/com/wayn/common/constant/SysConstants.java index 08141b9..b838b13 100644 --- a/waynboot-common/src/main/java/com/wayn/common/constant/SysConstants.java +++ b/waynboot-common/src/main/java/com/wayn/common/constant/SysConstants.java @@ -8,6 +8,12 @@ public class SysConstants { // ------------------------------------------------ 用户常量 ------------------------------------------------------------------------ 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"; - /** - * 验证码 redis key - */ - public static final String CAPTCHA_CODE_KEY = "captcha_codes:"; /** * 验证码有效期(分钟) */ public static final Integer CAPTCHA_EXPIRATION = 2; - /** - * 登录用户 redis key - */ - public static final String LOGIN_TOKEN_KEY = "login_tokens:"; /** * 登录用户key @@ -73,19 +71,4 @@ public class SysConstants { * string类型boolean返回值,失败默认为error */ 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"; - } diff --git a/waynboot-common/src/main/java/com/wayn/common/core/domain/tool/EmailConfig.java b/waynboot-common/src/main/java/com/wayn/common/core/domain/tool/EmailConfig.java index 90098a2..155a406 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/domain/tool/EmailConfig.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/domain/tool/EmailConfig.java @@ -17,21 +17,31 @@ public class EmailConfig implements Serializable { @TableId(type = IdType.AUTO) private Long id; - /** 邮件服务器SMTP地址 */ + /** + * 邮件服务器SMTP地址 + */ @NotBlank(message = "邮件服务器SMTP地址不能为空") private String host; - /** 邮件服务器SMTP端口 */ + /** + * 邮件服务器SMTP端口 + */ @NotBlank(message = "邮件服务器SMTP端口不能为空") - private String port; + private Integer port; + + private Integer sslPort; @NotBlank(message = "邮箱密钥不能为空") private String pass; - /** 发件人邮箱 */ + /** + * 发件人邮箱 + */ @NotBlank(message = "发件人邮箱不能为空") private String fromUser; - /** 发件者用户名 */ + /** + * 发件者用户名 + */ private String user; } diff --git a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java index 4e1f880..455c5ce 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java @@ -12,6 +12,7 @@ import com.wayn.common.core.service.shop.*; import com.wayn.common.enums.ReturnCodeEnum; import com.wayn.common.exception.BusinessException; 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.ElasticEntity; import lombok.AllArgsConstructor; @@ -161,7 +162,7 @@ public class GoodsServiceImpl extends ServiceImpl implements iGoodsAttributeService.remove(new QueryWrapper().eq("goods_id", goodsId)); iGoodsProductService.remove(new QueryWrapper().eq("goods_id", goodsId)); // 同步es - boolean one = elasticDocument.delete(SysConstants.ES_GOODS_INDEX, goodsId.toString()); + boolean one = elasticDocument.delete(EsConstants.ES_GOODS_INDEX, goodsId.toString()); if (!one) { throw new BusinessException("删除商品,同步es失败"); } @@ -263,7 +264,7 @@ public class GoodsServiceImpl extends ServiceImpl implements map.put("isOnSale", goods.getIsOnSale()); map.put("createTime", goods.getCreateTime()); elasticEntity.setData(map); - if (!elasticDocument.insertOrUpdateOne(SysConstants.ES_GOODS_INDEX, elasticEntity)) { + if (!elasticDocument.insertOrUpdateOne(EsConstants.ES_GOODS_INDEX, elasticEntity)) { throw new BusinessException("商品同步es失败"); } return true; diff --git a/waynboot-common/src/main/java/com/wayn/common/util/mail/MailUtil.java b/waynboot-common/src/main/java/com/wayn/common/util/mail/MailUtil.java index 64a5710..2ac03f1 100644 --- a/waynboot-common/src/main/java/com/wayn/common/util/mail/MailUtil.java +++ b/waynboot-common/src/main/java/com/wayn/common/util/mail/MailUtil.java @@ -21,7 +21,7 @@ import java.util.Properties; @Slf4j 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 { // 设置发件人 String from = emailConfig.getFromUser(); @@ -32,15 +32,18 @@ public class MailUtil { String host = emailConfig.getHost(); // 获取系统属性 Properties properties = System.getProperties(); + properties.setProperty("mail.smtp.port", String.valueOf(emailConfig.getPort())); // SSL加密 - MailSSLSocketFactory sf = new MailSSLSocketFactory(); - sf.setTrustAllHosts(true); - properties.put("mail.smtp.ssl.enable", "true"); - properties.put("mail.smtp.ssl.socketFactory", sf); + if (ssl) { + MailSSLSocketFactory sf = new MailSSLSocketFactory(); + sf.setTrustAllHosts(true); + 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.transport.protocol", "smtp"); - properties.setProperty("mail.smtp.port", emailConfig.getPort()); properties.put("mail.smtp.auth", "true"); // 获取发送邮件会话、获取第三方登录授权码 Session session = Session.getDefaultInstance(properties, new Authenticator() { @@ -49,7 +52,7 @@ public class MailUtil { return new PasswordAuthentication(from, emailConfig.getPass()); } }); - session.setDebug(true); + session.setDebug(false); // 创建默认的 MimeMessage 对象 MimeMessage message = new MimeMessage(session); 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); + } } diff --git a/waynboot-common/src/main/resources/application-dev.yml b/waynboot-common/src/main/resources/application-dev.yml index 5a3e3db..54a5cb7 100644 --- a/waynboot-common/src/main/resources/application-dev.yml +++ b/waynboot-common/src/main/resources/application-dev.yml @@ -6,7 +6,7 @@ spring: master: url: jdbc:mysql://127.0.0.1:3306/wayn_shop?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root - password: root + password: # 从库数据源 slave: # 从数据源开关/默认关闭 @@ -22,6 +22,8 @@ spring: database: 2 timeout: 5000 expire: 400 + lettuce: + shutdown-timeout: 100ms # cluster: # nodes: # - 127.0.0.1:1681 @@ -32,7 +34,7 @@ spring: # - 127.0.0.1:1686 #配置rabbitMq 服务器 rabbitmq: - host: wayn.ltd + host: 127.0.0.1 port: 5672 username: guest password: guest @@ -43,7 +45,7 @@ spring: publisher-returns: true es: - host: huawei.wayn.ltd + host: 127.0.0.1 port: 9200 scheme: http shards: 3 @@ -57,6 +59,5 @@ alipay: gateway: https://openapi.alipaydev.com/gateway.do charset: UTF-8 format: json - # log_path: /opt/newbeeplus/log - log_path: D://newbeemallplus//log + log-path: ./log signtype: RSA2 diff --git a/waynboot-data/waynboot-data-elastic/src/main/java/com/wayn/data/elastic/constant/EsConstants.java b/waynboot-data/waynboot-data-elastic/src/main/java/com/wayn/data/elastic/constant/EsConstants.java new file mode 100644 index 0000000..a01327d --- /dev/null +++ b/waynboot-data/waynboot-data-elastic/src/main/java/com/wayn/data/elastic/constant/EsConstants.java @@ -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"; + +} diff --git a/waynboot-data/waynboot-data-redis/pom.xml b/waynboot-data/waynboot-data-redis/pom.xml index 827746b..2eace94 100644 --- a/waynboot-data/waynboot-data-redis/pom.xml +++ b/waynboot-data/waynboot-data-redis/pom.xml @@ -14,7 +14,6 @@ org.springframework.boot spring-boot-starter-data-redis - ${spring-boot.version} diff --git a/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/config/CacheConfig.java b/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/config/CacheConfig.java index e9db790..f0f982f 100644 --- a/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/config/CacheConfig.java +++ b/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/config/CacheConfig.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.parser.ParserConfig; import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.support.config.FastJsonConfig; import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer; +import com.wayn.data.redis.constant.CacheConstants; import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CachingConfigurerSupport; @@ -66,7 +67,7 @@ public class CacheConfig extends CachingConfigurerSupport { private RedisCacheConfiguration defaultCacheConfig() { return RedisCacheConfiguration.defaultCacheConfig() - .prefixCacheNameWith("redis:cache") + .prefixCacheNameWith(CacheConstants.CACHE_PREFIX) .entryTtl(Duration.ofSeconds(expire)) .disableCachingNullValues(); } diff --git a/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/constant/CacheConstants.java b/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/constant/CacheConstants.java new file mode 100644 index 0000000..f92edb5 --- /dev/null +++ b/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/constant/CacheConstants.java @@ -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:"; + +} diff --git a/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/manager/RedisCache.java b/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/manager/RedisCache.java index 3d8210a..3b68b0a 100644 --- a/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/manager/RedisCache.java +++ b/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/manager/RedisCache.java @@ -1,6 +1,9 @@ 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.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.HashOperations; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.ValueOperations; @@ -18,12 +21,16 @@ import java.util.concurrent.TimeUnit; * * @author ruoyi **/ +@Slf4j @SuppressWarnings(value = {"unchecked", "rawtypes"}) @Component public class RedisCache { @Autowired public RedisTemplate redisTemplate; + @Autowired + private LettuceConnectionFactory lettuceConnectionFactory; + /** * 缓存基本的对象,Integer、String、实体类等 * @@ -86,10 +93,33 @@ public class RedisCache { * @return 缓存键值对应的数据 */ public T getCacheObject(final String key) { - ValueOperations operation = redisTemplate.opsForValue(); - return operation.get(key); + try { + ValueOperations operation = redisTemplate.opsForValue(); + return operation.get(key); + } catch (Exception e) { + log.error(e.getMessage(), e); + return retryGetCacheObject(key, 1); + } } + public 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 operation = redisTemplate.opsForValue(); + return operation.get(key); + } catch (Exception e) { + log.error(e.getMessage(), e); + return retryGetCacheObject(key, retryCount); + } + } + + /** * 获取多个key的 * diff --git a/waynboot-generator/pom.xml b/waynboot-generator/pom.xml index 85796fd..e2e1b95 100644 --- a/waynboot-generator/pom.xml +++ b/waynboot-generator/pom.xml @@ -49,7 +49,6 @@ org.freemarker freemarker - 2.3.30 diff --git a/waynboot-message-consumer/Dockerfile b/waynboot-message-consumer/Dockerfile new file mode 100644 index 0000000..12177b4 --- /dev/null +++ b/waynboot-message-consumer/Dockerfile @@ -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 diff --git a/waynboot-message-consumer/pom.xml b/waynboot-message-consumer/pom.xml index 8cdd2e5..b4ac30a 100644 --- a/waynboot-message-consumer/pom.xml +++ b/waynboot-message-consumer/pom.xml @@ -108,16 +108,16 @@ - + + <!–配置基本镜像–> ${docker-from-image-name} - + <!–配置最终推送的地址,仓库名,镜像名–> registry.cn-shanghai.aliyuncs.com/${aliyun-docker-namespace}/${project.artifactId} @@ -141,7 +141,7 @@ - + <!– 绑定到maven lifecicle–> package @@ -150,7 +150,7 @@ - + --> diff --git a/waynboot-message-consumer/src/main/resources/application.yml b/waynboot-message-consumer/src/main/resources/application.yml index 16de79f..8ec18c6 100644 --- a/waynboot-message-consumer/src/main/resources/application.yml +++ b/waynboot-message-consumer/src/main/resources/application.yml @@ -29,7 +29,7 @@ spring: boot: admin: client: - url: http://localhost:89 + url: http://localhost:89/boot-admin # 日志配置 diff --git a/waynboot-mobile-api/Dockerfile b/waynboot-mobile-api/Dockerfile new file mode 100644 index 0000000..905cdec --- /dev/null +++ b/waynboot-mobile-api/Dockerfile @@ -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 diff --git a/waynboot-mobile-api/pom.xml b/waynboot-mobile-api/pom.xml index 33ec7b8..1611621 100644 --- a/waynboot-mobile-api/pom.xml +++ b/waynboot-mobile-api/pom.xml @@ -58,7 +58,7 @@ cn.hutool hutool-all - 5.7.19 + ${hutool.version} diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/LoginController.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/LoginController.java index 863a82c..f5c42e2 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/LoginController.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/LoginController.java @@ -110,7 +110,7 @@ public class LoginController { sendMailVO.setSubject("mall商城注册通知"); sendMailVO.setContent("邮箱验证码:" + verCode); sendMailVO.setTos(Collections.singletonList(registryObj.getEmail())); - MailUtil.sendMail(emailConfig, sendMailVO, false); + MailUtil.sendMail(emailConfig, sendMailVO, false, false); return R.success().add("key", key); } } diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/UserController.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/UserController.java index 9056e60..02545cc 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/UserController.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/UserController.java @@ -91,7 +91,7 @@ public class UserController { sendMailVO.setSubject("mall商城重置密码通知"); sendMailVO.setContent("邮箱验证码:" + verCode); sendMailVO.setTos(Collections.singletonList(registryObj.getEmail())); - MailUtil.sendMail(emailConfig, sendMailVO, false); + MailUtil.sendMail(emailConfig, sendMailVO, false, false); return R.success().add("key", key); } diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/message/EmailController.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/message/EmailController.java index 6fe80aa..a623a19 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/message/EmailController.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/message/EmailController.java @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.Arrays; +import java.util.List; @RestController @RequestMapping("message/email") @@ -25,8 +25,8 @@ public class EmailController { SendMailVO sendMailVO = new SendMailVO(); sendMailVO.setSubject(subject); sendMailVO.setContent(content); - sendMailVO.setTos(Arrays.asList(tos)); - MailUtil.sendMail(emailConfig, sendMailVO, false); + sendMailVO.setTos(List.of(tos)); + MailUtil.sendMail(emailConfig, sendMailVO, false, false); return R.success(); } } diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/OrderServiceImpl.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/OrderServiceImpl.java index 78f6acf..a49ffff 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/OrderServiceImpl.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/OrderServiceImpl.java @@ -200,26 +200,6 @@ public class OrderServiceImpl extends ServiceImpl implements } else { checkedGoodsList = iCartService.listByIds(cartIdArr); } - List goodsIds = checkedGoodsList.stream().map(Cart::getGoodsId).collect(Collectors.toList()); - List goodsProducts = iGoodsProductService.list(new QueryWrapper().in("goods_id", goodsIds)); - Map 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"); @@ -252,7 +232,6 @@ public class OrderServiceImpl extends ServiceImpl implements // 异步下单 String uid = IdUtil.getUid(); - System.out.println(uid); CorrelationData correlationData = new CorrelationData(uid); Map map = new HashMap<>(); map.put("order", orderDTO); @@ -292,6 +271,27 @@ public class OrderServiceImpl extends ServiceImpl implements checkedGoodsList = iCartService.listByIds(cartIdArr); } + // 商品货品库存数量减少 + List goodsIds = checkedGoodsList.stream().map(Cart::getGoodsId).collect(Collectors.toList()); + List goodsProducts = iGoodsProductService.list(new QueryWrapper().in("goods_id", goodsIds)); + Map 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"); for (Cart checkGoods : checkedGoodsList) { @@ -342,7 +342,7 @@ public class OrderServiceImpl extends ServiceImpl implements } Long orderId = order.getId(); - List orderGoodsList = new ArrayList<>(); + List orderGoodsList = new ArrayList<>(checkedGoodsList.size()); // 添加订单商品表项 for (Cart cartGoods : checkedGoodsList) { // 订单商品 diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/security/service/TokenService.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/security/service/TokenService.java index b205123..f09a321 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/security/service/TokenService.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/security/service/TokenService.java @@ -4,6 +4,7 @@ import com.auth0.jwt.interfaces.DecodedJWT; import com.wayn.common.constant.SysConstants; import com.wayn.common.core.service.system.IUserService; import com.wayn.common.util.jwt.JwtUtil; +import com.wayn.data.redis.constant.CacheConstants; import com.wayn.data.redis.manager.RedisCache; import com.wayn.mobile.framework.security.LoginUserDetail; import org.apache.commons.lang3.StringUtils; @@ -67,7 +68,7 @@ public class TokenService { loginUser.setLoginTime(System.currentTimeMillis()); loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_DAY); // 根据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); } @@ -100,7 +101,7 @@ public class TokenService { * @return 返回token的key */ private String getTokenKey(String sign) { - return SysConstants.LOGIN_TOKEN_KEY + sign; + return CacheConstants.LOGIN_TOKEN_KEY + sign; } } diff --git a/waynboot-mobile-api/src/main/resources/application.yml b/waynboot-mobile-api/src/main/resources/application.yml index d23efb4..7ba730f 100644 --- a/waynboot-mobile-api/src/main/resources/application.yml +++ b/waynboot-mobile-api/src/main/resources/application.yml @@ -30,7 +30,7 @@ spring: boot: admin: client: - url: http://localhost:89 + url: http://localhost:89/boot-admin # token配置 token: diff --git a/waynboot-monitor/src/main/java/com/wayn/monitor/config/WebSecurityConfigurer.java b/waynboot-monitor/src/main/java/com/wayn/monitor/config/WebSecurityConfigurer.java index c438fde..e512cce 100644 --- a/waynboot-monitor/src/main/java/com/wayn/monitor/config/WebSecurityConfigurer.java +++ b/waynboot-monitor/src/main/java/com/wayn/monitor/config/WebSecurityConfigurer.java @@ -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.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; +import org.springframework.security.web.csrf.CookieCsrfTokenRepository; @Configuration public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter { @@ -36,6 +37,10 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter { .and() .httpBasic().and() .csrf() - .disable(); + .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) + .ignoringAntMatchers( + "/instances", + "/actuator/**" + ); } } diff --git a/waynboot-monitor/src/main/resources/application.yml b/waynboot-monitor/src/main/resources/application.yml index eeffb86..0591273 100644 --- a/waynboot-monitor/src/main/resources/application.yml +++ b/waynboot-monitor/src/main/resources/application.yml @@ -1,9 +1,19 @@ server: port: 89 shutdown: graceful # 优雅关机 - + servlet: + context-path: /boot-admin spring: security: user: name: user password: admin123 + +management: + endpoints: + web: + exposure: + include: "*" + endpoint: + health: + show-details: ALWAYS