diff --git a/mall-oms/oms-boot/pom.xml b/mall-oms/oms-boot/pom.xml index 2741410f9..df4d0e066 100644 --- a/mall-oms/oms-boot/pom.xml +++ b/mall-oms/oms-boot/pom.xml @@ -13,12 +13,6 @@ - - - org.springframework.boot - spring-boot-starter-web - - org.springframework.cloud @@ -106,11 +100,6 @@ common-rabbitmq - - com.youlai - common-log - ${youlai.version} - com.github.binarywang diff --git a/mall-pms/pms-boot/pom.xml b/mall-pms/pms-boot/pom.xml index 50bdd3e6c..cda29ce6f 100644 --- a/mall-pms/pms-boot/pom.xml +++ b/mall-pms/pms-boot/pom.xml @@ -12,13 +12,6 @@ pms-boot - - - - org.springframework.boot - spring-boot-starter-web - - org.springframework.boot @@ -30,6 +23,12 @@ org.springframework.boot spring-boot-starter-test test + + + asm + org.ow2.asm + + @@ -71,6 +70,12 @@ io.seata seata-all + + + caffeine + com.github.ben-manes.caffeine + + @@ -100,11 +105,6 @@ common-redis - - com.youlai - common-log - ${youlai.version} - com.youlai diff --git a/mall-sms/sms-boot/pom.xml b/mall-sms/sms-boot/pom.xml index 5f48069b4..f429072ce 100644 --- a/mall-sms/sms-boot/pom.xml +++ b/mall-sms/sms-boot/pom.xml @@ -15,12 +15,6 @@ - - - org.springframework.boot - spring-boot-starter-web - - org.springframework.boot @@ -87,6 +81,13 @@ ${youlai.version} + + com.github.dozermapper + dozer-core + ${dozer.version} + + + diff --git a/youlai-common/common-core/src/main/java/com/youlai/common/base/BasePageQuery.java b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/common/base/BasePageQuery.java similarity index 90% rename from youlai-common/common-core/src/main/java/com/youlai/common/base/BasePageQuery.java rename to mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/common/base/BasePageQuery.java index 21a88dbd5..753b982f0 100644 --- a/youlai-common/common-core/src/main/java/com/youlai/common/base/BasePageQuery.java +++ b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/common/base/BasePageQuery.java @@ -1,4 +1,4 @@ -package com.youlai.common.base; +package com.youlai.mall.sms.common.base; import io.swagger.annotations.ApiModelProperty; import lombok.Data; diff --git a/youlai-common/common-web/src/main/java/com/youlai/common/web/util/BeanMapperUtils.java b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/common/util/BeanMapperUtils.java similarity index 97% rename from youlai-common/common-web/src/main/java/com/youlai/common/web/util/BeanMapperUtils.java rename to mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/common/util/BeanMapperUtils.java index 4bf5f09e9..e40e0cc78 100644 --- a/youlai-common/common-web/src/main/java/com/youlai/common/web/util/BeanMapperUtils.java +++ b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/common/util/BeanMapperUtils.java @@ -1,4 +1,4 @@ -package com.youlai.common.web.util; +package com.youlai.mall.sms.common.util; import org.dozer.DozerBeanMapperBuilder; import org.dozer.Mapper; diff --git a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/utils/PageMapperUtils.java b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/common/util/PageMapperUtils.java similarity index 88% rename from youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/utils/PageMapperUtils.java rename to mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/common/util/PageMapperUtils.java index 2db20e9ba..cc7344e9c 100644 --- a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/utils/PageMapperUtils.java +++ b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/common/util/PageMapperUtils.java @@ -1,8 +1,7 @@ -package com.youlai.common.mybatis.utils; +package com.youlai.mall.sms.common.util; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.youlai.common.web.util.BeanMapperUtils; /** * @author xinyi diff --git a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/controller/admin/CouponRecordController.java b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/controller/admin/CouponRecordController.java index 4662bf4ed..981aad96e 100644 --- a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/controller/admin/CouponRecordController.java +++ b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/controller/admin/CouponRecordController.java @@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.youlai.common.base.BasePageQuery; +import com.youlai.mall.sms.common.base.BasePageQuery; import com.youlai.common.result.Result; import com.youlai.common.web.util.JwtUtils; import com.youlai.mall.sms.pojo.domain.SmsCouponRecord; diff --git a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/controller/app/AppCouponController.java b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/controller/app/AppCouponController.java index 0d9f9627d..8c1a4c07d 100644 --- a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/controller/app/AppCouponController.java +++ b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/controller/app/AppCouponController.java @@ -1,7 +1,7 @@ package com.youlai.mall.sms.controller.app; import com.youlai.common.result.Result; -import com.youlai.common.web.util.BeanMapperUtils; +import com.youlai.mall.sms.common.util.BeanMapperUtils; import com.youlai.common.web.util.JwtUtils; import com.youlai.mall.sms.pojo.domain.SmsCoupon; import com.youlai.mall.sms.pojo.vo.CouponTemplateVO; diff --git a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/SeckillServiceImpl.java b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/SeckillServiceImpl.java index 3b29bf170..70a52bd8c 100644 --- a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/SeckillServiceImpl.java +++ b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/SeckillServiceImpl.java @@ -5,7 +5,7 @@ import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.RandomUtil; import com.youlai.common.redis.utils.RedisUtils; -import com.youlai.common.web.util.BeanMapperUtils; +import com.youlai.mall.sms.common.util.BeanMapperUtils; import com.youlai.mall.sms.pojo.domain.SmsSeckillSession; import com.youlai.mall.sms.pojo.domain.SmsSeckillSkuRelation; import com.youlai.mall.sms.pojo.to.SeckillSkuRedisTO; diff --git a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/SmsCouponServiceImpl.java b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/SmsCouponServiceImpl.java index 9b29054ee..f4861f583 100644 --- a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/SmsCouponServiceImpl.java +++ b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/SmsCouponServiceImpl.java @@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.youlai.common.web.exception.BizException; -import com.youlai.common.web.util.BeanMapperUtils; +import com.youlai.mall.sms.common.util.BeanMapperUtils; import com.youlai.common.web.util.JwtUtils; import com.youlai.mall.sms.mapper.SmsCouponMapper; import com.youlai.mall.sms.pojo.domain.CouponTemplateRule; diff --git a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/SmsCouponTemplateServiceImpl.java b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/SmsCouponTemplateServiceImpl.java index 37cc4835e..0b647ac9c 100644 --- a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/SmsCouponTemplateServiceImpl.java +++ b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/SmsCouponTemplateServiceImpl.java @@ -7,9 +7,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.youlai.common.mybatis.utils.PageMapperUtils; import com.youlai.common.web.exception.BizException; -import com.youlai.common.web.util.BeanMapperUtils; +import com.youlai.mall.sms.common.util.BeanMapperUtils; import com.youlai.mall.sms.mapper.SmsCouponTemplateMapper; import com.youlai.mall.sms.pojo.domain.CouponTemplateRule; import com.youlai.mall.sms.pojo.domain.SmsCouponTemplate; @@ -22,6 +21,7 @@ import com.youlai.mall.sms.pojo.vo.SmsCouponTemplateInfoVO; import com.youlai.mall.sms.pojo.vo.SmsCouponTemplateVO; import com.youlai.mall.sms.service.IAsyncService; import com.youlai.mall.sms.service.ISmsCouponTemplateService; +import com.youlai.mall.sms.common.util.PageMapperUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; diff --git a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/TemplateBaseServiceImpl.java b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/TemplateBaseServiceImpl.java index 5bba40ef0..a2fd01749 100644 --- a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/TemplateBaseServiceImpl.java +++ b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/TemplateBaseServiceImpl.java @@ -3,7 +3,7 @@ package com.youlai.mall.sms.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.map.MapUtil; import com.youlai.common.web.exception.BizException; -import com.youlai.common.web.util.BeanMapperUtils; +import com.youlai.mall.sms.common.util.BeanMapperUtils; import com.youlai.mall.sms.pojo.domain.SmsCouponTemplate; import com.youlai.mall.sms.pojo.vo.CouponTemplateVO; import com.youlai.mall.sms.service.ISmsCouponTemplateService; diff --git a/mall-ums/ums-boot/pom.xml b/mall-ums/ums-boot/pom.xml index c65606244..42ececcce 100644 --- a/mall-ums/ums-boot/pom.xml +++ b/mall-ums/ums-boot/pom.xml @@ -16,13 +16,6 @@ - - - - org.springframework.boot - spring-boot-starter-web - - org.springframework.boot @@ -73,6 +66,12 @@ io.seata seata-all + + + caffeine + com.github.ben-manes.caffeine + + io.seata @@ -100,11 +99,6 @@ common-redis - - com.youlai - common-log - ${youlai.version} - diff --git a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/domain/LoginRecord.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/domain/LoginRecord.java deleted file mode 100644 index 8fc7048bf..000000000 --- a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/domain/LoginRecord.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.youlai.admin.pojo.domain; - -import com.youlai.common.base.BaseDocument; -import lombok.Data; - -/** - * @author hxr - * @date 2021-03-09 - */ -@Data -public class LoginRecord extends BaseDocument { - - private String clientIP; - - private long elapsedTime; - - private Object message; - - private String token; - - private String username; - - private String loginTime; - - private String region; - - /** - * 会话状态 0-离线 1-在线 - */ - private Integer status; - -} diff --git a/youlai-common/common-core/src/main/java/com/youlai/common/pojo/vo/CascadeVO.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/vo/CascadeVO.java similarity index 91% rename from youlai-common/common-core/src/main/java/com/youlai/common/pojo/vo/CascadeVO.java rename to youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/vo/CascadeVO.java index dfea6ff41..52990b445 100644 --- a/youlai-common/common-core/src/main/java/com/youlai/common/pojo/vo/CascadeVO.java +++ b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/vo/CascadeVO.java @@ -1,4 +1,4 @@ -package com.youlai.common.pojo.vo; +package com.youlai.admin.pojo.vo; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Data; diff --git a/youlai-admin/admin-boot/pom.xml b/youlai-admin/admin-boot/pom.xml index f102b99e2..9a993de2c 100644 --- a/youlai-admin/admin-boot/pom.xml +++ b/youlai-admin/admin-boot/pom.xml @@ -17,11 +17,6 @@ - - org.springframework.boot - spring-boot-starter-web - - org.springframework.boot @@ -45,6 +40,12 @@ com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery + + + jsr305 + com.google.code.findbugs + + @@ -79,6 +80,12 @@ io.minio minio + + + guava + com.google.guava + + @@ -96,11 +103,6 @@ common-es - - com.youlai - common-log - ${youlai.version} - com.youlai diff --git a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/common/util/JWTUtils.java b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/common/util/JWTUtils.java deleted file mode 100644 index b3f06bd91..000000000 --- a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/common/util/JWTUtils.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.youlai.admin.common.util; - -import cn.hutool.json.JSONUtil; -import com.nimbusds.jose.JWSObject; -import com.youlai.common.constant.AuthConstants; -import com.youlai.common.pojo.JwtPayload; -import lombok.SneakyThrows; -import org.apache.logging.log4j.util.Strings; - -/** - * @author hxr - * @date 2021-03-10 - */ -public class JWTUtils { - - - /** - * 获取JWT的载体 - * @param token - * @return - */ - @SneakyThrows - public static JwtPayload getJWTPayload(String token) { - token = token.replace(AuthConstants.AUTHORIZATION_PREFIX, Strings.EMPTY); - JWSObject jwsObject = JWSObject.parse(token); - JwtPayload payload = JSONUtil.toBean(jwsObject.getPayload().toString(), JwtPayload.class); - return payload; - } - - /** - * 判断token是否过期 - * @param token - * @return - */ - public static boolean isExpired(String token) { - JwtPayload payload = getJWTPayload(token); - // 计算是否过期 - long currentTimeSeconds = System.currentTimeMillis() / 1000; - Long exp = payload.getExp(); - if (exp < currentTimeSeconds) { // token已过期,无需加入黑名单 - return true; - } - return false; - } - - - -} diff --git a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/controller/DashboardController.java b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/controller/DashboardController.java deleted file mode 100644 index 772c1c2bf..000000000 --- a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/controller/DashboardController.java +++ /dev/null @@ -1,205 +0,0 @@ -package com.youlai.admin.controller; - -import cn.hutool.core.convert.Convert; -import cn.hutool.core.util.StrUtil; -import com.youlai.admin.pojo.domain.LoginRecord; -import com.youlai.admin.service.ITokenService; -import com.youlai.common.base.BaseDocument; -import com.youlai.common.elasticsearch.service.ElasticSearchService; -import com.youlai.common.result.Result; -import com.youlai.common.web.util.IPUtils; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; -import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.elasticsearch.index.query.BoolQueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.index.query.RangeQueryBuilder; -import org.elasticsearch.index.query.TermQueryBuilder; -import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; -import org.elasticsearch.search.sort.FieldSortBuilder; -import org.elasticsearch.search.sort.SortOrder; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; -import javax.servlet.http.HttpServletRequest; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @description 首页控制台 - * @author hxr - * @date 2021-03-08 - */ -@Api(tags = "首页控制台") -@RestController -@RequestMapping("/api/v1/dashboard") -@Slf4j -@AllArgsConstructor -public class DashboardController { - - ITokenService tokenService; - ElasticSearchService elasticSearchService; - - @ApiOperation(value = "控制台数据") - @GetMapping - public Result data() { - Map data = new HashMap<>(); - - // 今日IP数 - long todayIpCount = getTodayIpCount(); - data.put("todayIpCount", todayIpCount); - - // 总IP数 - long totalIpCount = getTotalIpCount(); - data.put("totalIpCount", totalIpCount); - - // 登录统计 - int days = 10; // 统计天数 - Map loginCount = getLoginCount(days); - data.put("loginCount", loginCount); - - return Result.success(data); - } - - - private long getTodayIpCount() { - String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); - TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery("date", date); - String indexName = "youlai-auth-login-" + date; //索引名称 - long todayIpCount = elasticSearchService.countDistinct(termQueryBuilder, "clientIP.keyword", indexName); - return todayIpCount; - } - - private long getTotalIpCount() { - long totalIpCount = elasticSearchService.countDistinct(null, "clientIP.keyword", "youlai-auth-login-*"); - return totalIpCount; - } - - private Map getLoginCount(int days) { - - LocalDateTime now = LocalDateTime.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - - String startDate = now.plusDays(-days).format(formatter); - String endDate = now.format(formatter); - - String[] indices = new String[days]; // 查询ES索引数组 - String[] xData = new String[days]; // 柱状图x轴数据 - for (int i = 0; i < days; i++) { - String date = now.plusDays(-i).format(formatter); - xData[i] = date; - indices[i] = "youlai-auth-login-"+ date; - } - - // 查询条件,范围内日期统计 - RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery("date").from(startDate).to(endDate); - BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery() - .must(rangeQueryBuilder); - - - // 总数统计 - Map totalCountMap = elasticSearchService.dateHistogram( - boolQueryBuilder, - "date", // 根据date字段聚合统计登录数 logback-spring.xml 中的自定义扩展字段 date - DateHistogramInterval.days(1), - indices); - - // 当前用户统计 - HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); - String clientIP = IPUtils.getIpAddr(request); - - boolQueryBuilder.must(QueryBuilders.termQuery("clientIP", clientIP)); - Map myCountMap = elasticSearchService.dateHistogram(boolQueryBuilder, "date", DateHistogramInterval.days(1), indices); - - - // 组装echarts数据 - Long[] totalCount = new Long[days]; - Long[] myCount = new Long[days]; - - Arrays.sort(xData);// 默认升序 - for (int i = 0; i < days; i++) { - String key = xData[i]; - totalCount[i] = Convert.toLong(totalCountMap.get(key), 0l); - myCount[i] = Convert.toLong(myCountMap.get(key), 0l); - } - Map map = new HashMap<>(4); - - map.put("xData", xData); // x轴坐标 - map.put("totalCount", totalCount); // 总数 - map.put("myCount", myCount); // 我的 - - return map; - } - - - - @ApiOperation(value = "列表分页") - @ApiImplicitParams({ - @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "Long"), - @ApiImplicitParam(name = "limit", value = "每页数量", defaultValue = "10", paramType = "query", dataType = "Long"), - @ApiImplicitParam(name = "startDate", value = "开始日期", paramType = "query", dataType = "String"), - @ApiImplicitParam(name = "endDate", value = "结束日期", paramType = "query", dataType = "String"), - @ApiImplicitParam(name = "clientIP", value = "客户端IP", paramType = "query", dataType = "String") - }) - @GetMapping("/login-records") - public Result list( - Integer page, - Integer limit, - String startDate, - String endDate, - String clientIP - ) { - - // 日期范围 - RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery("date"); - - if (StrUtil.isNotBlank(startDate)) { - rangeQueryBuilder.from(startDate); - } - if (StrUtil.isNotBlank(endDate)) { - rangeQueryBuilder.to(endDate); - } - - BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery().must(rangeQueryBuilder); - - if (StrUtil.isNotBlank(clientIP)) { - queryBuilder.must(QueryBuilders.wildcardQuery("clientIP", "*" + clientIP + "*")); - } - // 总记录数 - long count = elasticSearchService.count(queryBuilder, "youlai-auth-login-*"); - - // 排序 - FieldSortBuilder sortBuilder = new FieldSortBuilder("@timestamp").order(SortOrder.DESC); - - // 分页查询 - List list = elasticSearchService.search(queryBuilder, sortBuilder, page, limit, LoginRecord.class, "youlai-auth-login-*"); - - // 遍历获取会话状态 - list.forEach(item -> { - String token = item.getToken(); - int tokenStatus = 0; - if (StrUtil.isNotBlank(token)) { - tokenStatus = tokenService.getTokenStatus(item.getToken()); - } - item.setStatus(tokenStatus); - }); - - return Result.success(list, count); - } - - - @ApiOperation(value = "删除登录记录") - @ApiImplicitParam(name = "ids", value = "id集合", required = true, paramType = "query", dataType = "String") - @DeleteMapping("/login-records") - public Result delete(@RequestBody List documents) { - documents.forEach(document -> elasticSearchService.deleteById(document.getId(), document.getIndex())); - return Result.success(); - } -} diff --git a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/controller/TokenController.java b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/controller/TokenController.java deleted file mode 100644 index 32e636bfb..000000000 --- a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/controller/TokenController.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.youlai.admin.controller; - -import com.youlai.admin.service.ITokenService; -import com.youlai.common.result.Result; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - - -/** - * @author hxr - * @date 2021-03-09 - */ - -@Api(tags = "令牌接口") -@RestController -@RequestMapping("/api/v1/tokens") -@Slf4j -@AllArgsConstructor -public class TokenController { - - ITokenService tokenService; - - @ApiOperation(value = "强制下线") - @ApiImplicitParam(name = "token", value = "访问令牌", required = true, paramType = "query", dataType = "String") - @PostMapping("/{token}/_invalidate") - @SneakyThrows - public Result invalidateToken(@PathVariable String token) { - boolean status = tokenService.invalidateToken(token); - return Result.judge(status); - } - -} diff --git a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/service/ITokenService.java b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/service/ITokenService.java deleted file mode 100644 index 5f2e25797..000000000 --- a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/service/ITokenService.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.youlai.admin.service; - - -import java.text.ParseException; - -public interface ITokenService { - - - /** - * 使令牌token失效 - * - * @param token - * @return - */ - boolean invalidateToken(String token) throws ParseException; - - - /** - * 获取token状态 - * @param token - * @return 1-有效,0-失效(过期或被加入黑名单) - */ - int getTokenStatus(String token); -} diff --git a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/service/impl/TokenServiceImpl.java b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/service/impl/TokenServiceImpl.java deleted file mode 100644 index c08326225..000000000 --- a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/service/impl/TokenServiceImpl.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.youlai.admin.service.impl; - - -import com.youlai.admin.common.util.JWTUtils; -import com.youlai.admin.service.ITokenService; -import com.youlai.common.constant.AuthConstants; -import com.youlai.common.pojo.JwtPayload; -import lombok.AllArgsConstructor; -import lombok.SneakyThrows; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; - -import java.util.concurrent.TimeUnit; - -/** - * @author haoxr - * @date 2021-03-10 - */ -@Service -@AllArgsConstructor -public class TokenServiceImpl implements ITokenService { - - - RedisTemplate redisTemplate; - - @Override - @SneakyThrows - public boolean invalidateToken(String token) { - - JwtPayload payload = JWTUtils.getJWTPayload(token); - - // 计算是否过期 - long currentTimeSeconds = System.currentTimeMillis() / 1000; - Long exp = payload.getExp(); - if (exp < currentTimeSeconds) { // token已过期,无需加入黑名单 - return true; - } - // 添加至黑名单使其失效 - redisTemplate.opsForValue().set(AuthConstants.TOKEN_BLACKLIST_PREFIX + payload.getJti(), null, (exp - currentTimeSeconds), TimeUnit.SECONDS); - return true; - } - - @Override - public int getTokenStatus(String token) { - JwtPayload payload = JWTUtils.getJWTPayload(token); - - // 计算是否过期 - long currentTimeSeconds = System.currentTimeMillis() / 1000; - Long exp = payload.getExp(); - if (exp < currentTimeSeconds) { // token已过期 返回失效 - return 0; - } - - // 判断是否存在黑名单 - String jti = payload.getJti(); - Boolean isExists = redisTemplate.hasKey(AuthConstants.TOKEN_BLACKLIST_PREFIX + jti); - if (isExists == true) { // 被添加到黑名单 返回失效 - return 0; - } - return 1; - } - -} diff --git a/youlai-auth/pom.xml b/youlai-auth/pom.xml index c16acb6b4..e9e581586 100644 --- a/youlai-auth/pom.xml +++ b/youlai-auth/pom.xml @@ -16,13 +16,6 @@ - - - - org.springframework.boot - spring-boot-starter-web - - org.springframework.boot @@ -114,11 +107,6 @@ com.github.xiaoymin knife4j-micro-spring-boot-starter - - com.youlai - common-log - ${youlai.version} - diff --git a/youlai-common/common-core/pom.xml b/youlai-common/common-core/pom.xml index 56a54924c..bb86125fd 100644 --- a/youlai-common/common-core/pom.xml +++ b/youlai-common/common-core/pom.xml @@ -12,12 +12,16 @@ common-core - + - org.springframework.boot - spring-boot-starter-web - true + com.fasterxml.jackson.core + jackson-databind + + com.fasterxml.jackson.core + jackson-core + + @@ -26,17 +30,6 @@ true - - org.hibernate.validator - hibernate-validator - - - - com.github.dozermapper - dozer-core - ${dozer.version} - - io.swagger swagger-annotations @@ -47,6 +40,11 @@ spring-data-redis + + org.springframework.boot + spring-boot-starter-validation + + diff --git a/youlai-common/common-core/src/main/java/com/youlai/common/base/BaseDocument.java b/youlai-common/common-core/src/main/java/com/youlai/common/base/BaseDocument.java deleted file mode 100644 index ffa054d4d..000000000 --- a/youlai-common/common-core/src/main/java/com/youlai/common/base/BaseDocument.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.youlai.common.base; - -import lombok.Data; - -/** - * @description document 是 ES 里的一个 JSON 对象,包括零个或多个field,类比关系数据库的一行记录 - * @author haoxr - * @createTime 2021/3/9 22:14 - */ -@Data -public class BaseDocument { - - /** - * 数据唯一标识 - */ - private String id; - - /** - * 索引名称 - */ - private String index; -} diff --git a/youlai-common/common-core/src/main/java/com/youlai/common/pojo/JwtPayload.java b/youlai-common/common-core/src/main/java/com/youlai/common/pojo/JwtPayload.java deleted file mode 100644 index 56a64eba4..000000000 --- a/youlai-common/common-core/src/main/java/com/youlai/common/pojo/JwtPayload.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.youlai.common.pojo; - -import lombok.Data; - -/** - * JWT载体 - * - * @author hxr - * @date 2021-03-10 - */ -@Data -public class JwtPayload { - - private String jti; - - private Long exp; -} diff --git a/youlai-common/common-es/src/main/java/com/youlai/common/elasticsearch/service/ElasticSearchService.java b/youlai-common/common-es/src/main/java/com/youlai/common/elasticsearch/service/ElasticSearchService.java index 4ac389cf1..f0c59312b 100644 --- a/youlai-common/common-es/src/main/java/com/youlai/common/elasticsearch/service/ElasticSearchService.java +++ b/youlai-common/common-es/src/main/java/com/youlai/common/elasticsearch/service/ElasticSearchService.java @@ -2,8 +2,9 @@ package com.youlai.common.elasticsearch.service; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.json.JSONUtil; -import com.youlai.common.base.BaseDocument; import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.delete.DeleteResponse; @@ -38,10 +39,10 @@ import java.util.Map; * @date 2021-03-05 */ @Service -@AllArgsConstructor +@RequiredArgsConstructor public class ElasticSearchService { - private RestHighLevelClient client; + private final RestHighLevelClient client; @SneakyThrows @@ -169,9 +170,50 @@ public class ElasticSearchService { @SneakyThrows public boolean deleteById(String id, String index) { - DeleteRequest deleteRequest = new DeleteRequest(index,id); + DeleteRequest deleteRequest = new DeleteRequest(index, id); DeleteResponse deleteResponse = client.delete(deleteRequest, RequestOptions.DEFAULT); return true; } + + @Data + public static class BaseDocument { + + /** + * 数据唯一标识 + */ + private String id; + + /** + * 索引名称 + */ + private String index; + } + + + @Data + public class LoginRecord extends BaseDocument { + + private String clientIP; + + private long elapsedTime; + + private Object message; + + private String token; + + private String username; + + private String loginTime; + + private String region; + + /** + * 会话状态 0-离线 1-在线 + */ + private Integer status; + + } + + } diff --git a/youlai-common/common-log/pom.xml b/youlai-common/common-log/pom.xml deleted file mode 100644 index 538306002..000000000 --- a/youlai-common/common-log/pom.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - youlai-common - com.youlai - 2.0.0 - - 4.0.0 - - common-log - - - 8 - 8 - - - diff --git a/youlai-common/common-mybatis/pom.xml b/youlai-common/common-mybatis/pom.xml index 7b926c52b..a1a11cc20 100644 --- a/youlai-common/common-mybatis/pom.xml +++ b/youlai-common/common-mybatis/pom.xml @@ -13,8 +13,13 @@ - com.youlai - common-web + com.fasterxml.jackson.core + jackson-core + + + + com.fasterxml.jackson.core + jackson-databind diff --git a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/config/MybatisPlusConfig.java b/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/config/MybatisPlusConfig.java index 122cda4f7..6e17e04df 100644 --- a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/config/MybatisPlusConfig.java +++ b/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/config/MybatisPlusConfig.java @@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer; import com.baomidou.mybatisplus.core.config.GlobalConfig; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; -import com.youlai.common.mybatis.handler.FieldFillHandler; +import com.youlai.common.mybatis.handler.MyMetaObjectHandler; import com.youlai.common.mybatis.handler.IntegerArrayJsonTypeHandler; import com.youlai.common.mybatis.handler.LongArrayJsonTypeHandler; @@ -52,7 +52,7 @@ public class MybatisPlusConfig { @Bean public GlobalConfig globalConfig() { GlobalConfig globalConfig = new GlobalConfig(); - globalConfig.setMetaObjectHandler(new FieldFillHandler()); + globalConfig.setMetaObjectHandler(new MyMetaObjectHandler()); return globalConfig; } diff --git a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/FieldFillHandler.java b/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/FieldFillHandler.java deleted file mode 100644 index 23065dbb5..000000000 --- a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/FieldFillHandler.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.youlai.common.mybatis.handler; - -import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; -import lombok.extern.slf4j.Slf4j; -import org.apache.ibatis.reflection.MetaObject; -import org.springframework.stereotype.Component; - -import java.util.Date; - -@Component -@Slf4j -public class FieldFillHandler implements MetaObjectHandler { - - @Override - public void insertFill(MetaObject metaObject) { - - this.setFieldValByName("gmtCreate", new Date(), metaObject); - this.setFieldValByName("gmtModified", new Date(), metaObject); - } - - @Override - public void updateFill(MetaObject metaObject) { - this.setFieldValByName("gmtModified", new Date(), metaObject); - } - -} diff --git a/youlai-common/common-mybatis/src/main/resources/META-INF/spring.factories b/youlai-common/common-mybatis/src/main/resources/META-INF/spring.factories index 3c446f0cb..36c975b0d 100644 --- a/youlai-common/common-mybatis/src/main/resources/META-INF/spring.factories +++ b/youlai-common/common-mybatis/src/main/resources/META-INF/spring.factories @@ -1,4 +1,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.youlai.common.mybatis.config.MybatisPlusConfig,\ - com.youlai.common.mybatis.handler.FieldFillHandler + com.youlai.common.mybatis.handler.MyMetaObjectHandler diff --git a/youlai-common/common-redis/pom.xml b/youlai-common/common-redis/pom.xml index a9d580ec2..cd663d1bd 100644 --- a/youlai-common/common-redis/pom.xml +++ b/youlai-common/common-redis/pom.xml @@ -36,14 +36,6 @@ redisson - - com.fasterxml.jackson.core - jackson-databind - - - com.fasterxml.jackson.core - jackson-core - com.fasterxml.jackson.core jackson-annotations diff --git a/youlai-common/common-web/pom.xml b/youlai-common/common-web/pom.xml index 6a30c8468..d00cbad5d 100644 --- a/youlai-common/common-web/pom.xml +++ b/youlai-common/common-web/pom.xml @@ -19,13 +19,30 @@ org.springframework.boot - spring-boot-starter-validation + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-logging + + + + + + + org.springframework.boot + spring-boot-starter-log4j2 - org.springframework.boot - spring-boot-starter-web - true + io.github.openfeign + feign-core + + + + io.github.openfeign + feign-httpclient @@ -49,20 +66,6 @@ ip2region - - com.github.dozermapper - dozer-core - - - - io.github.openfeign - feign-core - - - - io.github.openfeign - feign-httpclient - diff --git a/youlai-common/common-web/src/main/java/com/youlai/common/web/aspect/LoginLogAspect.java b/youlai-common/common-web/src/main/java/com/youlai/common/web/aspect/LoginLogAspect.java index 2247284a1..888e48b08 100644 --- a/youlai-common/common-web/src/main/java/com/youlai/common/web/aspect/LoginLogAspect.java +++ b/youlai-common/common-web/src/main/java/com/youlai/common/web/aspect/LoginLogAspect.java @@ -4,19 +4,13 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.youlai.common.constant.AuthConstants; -import com.youlai.common.web.util.IPUtils; import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; import org.apache.logging.log4j.util.Strings; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.MethodSignature; import org.slf4j.MDC; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -74,17 +68,14 @@ public class LoginLogAspect { token = jsonObject.getStr("value"); } - String clientIP = IPUtils.getIpAddr(request); // 客户端请求IP(注意:如果使用Nginx代理需配置) - String region = IPUtils.getCityInfo(clientIP); // IP对应的城市信息 - // MDC 扩展logback字段,具体请看logback-spring.xml的自定义日志输出格式 MDC.put("elapsedTime", StrUtil.toString(elapsedTime)); - MDC.put("description", description); + /* MDC.put("description", description); MDC.put("region", region); MDC.put("username", username); MDC.put("date", date); MDC.put("token", token); - MDC.put("clientIP", clientIP); + MDC.put("clientIP", clientIP);*/ //log.info("{} 登录,耗费时间 {} 毫秒", username, elapsedTime); // 收集日志这里必须打印一条日志,内容随便吧,记录在message字段,具体看logback-spring.xml文件 return result; diff --git a/youlai-common/common-web/src/main/java/com/youlai/common/web/util/IPUtils.java b/youlai-common/common-web/src/main/java/com/youlai/common/web/util/IPUtils.java deleted file mode 100644 index f92d09405..000000000 --- a/youlai-common/common-web/src/main/java/com/youlai/common/web/util/IPUtils.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.youlai.common.web.util; - -import cn.hutool.core.util.StrUtil; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.io.FileUtils; -import org.apache.logging.log4j.util.Strings; -import org.lionsoul.ip2region.DataBlock; -import org.lionsoul.ip2region.DbConfig; -import org.lionsoul.ip2region.DbSearcher; -import org.lionsoul.ip2region.Util; - -import javax.servlet.http.HttpServletRequest; -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Method; -import java.net.InetAddress; -import java.net.UnknownHostException; - -/** - * IP工具类 - */ -@Slf4j -public class IPUtils { - - private static String LOCAL_IP = "127.0.0.1"; - - /** - * 获取IP地址 - * 使用Nginx等反向代理软件, 则不能通过request.getRemoteAddr()获取IP地址 - * 如果使用了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP地址,X-Forwarded-For中第一个非unknown的有效IP字符串,则为真实IP地址 - */ - public static String getIpAddr(HttpServletRequest request) { - String ip = null; - try { - if (request == null) { - return ""; - } - ip = request.getHeader("x-forwarded-for"); - if (checkIp(ip)) { - ip = request.getHeader("Proxy-Client-IP"); - } - if (checkIp(ip)) { - ip = request.getHeader("WL-Proxy-Client-IP"); - } - if (checkIp(ip)) { - ip = request.getHeader("HTTP_CLIENT_IP"); - } - if (checkIp(ip)) { - ip = request.getHeader("HTTP_X_FORWARDED_FOR"); - } - if (checkIp(ip)) { - ip = request.getRemoteAddr(); - if ("127.0.0.1".equals(ip) || "0:0:0:0:0:0:0:1".equals(ip)) { - // 根据网卡取本机配置的IP - ip = getLocalAddr(); - } - } - } catch (Exception e) { - log.error("IPUtils ERROR, {}", e.getMessage()); - } - - //使用代理,则获取第一个IP地址 - if (StrUtil.isNotBlank(ip) && ip.indexOf(",") > 0) { - ip = ip.substring(0, ip.indexOf(",")); - } - - return ip; - } - - private static boolean checkIp(String ip) { - String unknown = "unknown"; - return StrUtil.isEmpty(ip) || ip.length() == 0 || unknown.equalsIgnoreCase(ip); - } - - /** - * 获取本机的IP地址 - */ - private static String getLocalAddr() { - try { - return InetAddress.getLocalHost().getHostAddress(); - } catch (UnknownHostException e) { - log.error("InetAddress.getLocalHost()-error, {}", e.getMessage()); - } - return null; - } - - - /** - * 根据IP获取城市信息 - * @param ip - * @return - */ - public static String getCityInfo(String ip) { - return getCityInfo(ip, DbSearcher.BTREE_ALGORITHM); - } - - public static String getCityInfo(String ip, Integer algorithm) { - if (Util.isIpAddress(ip) == false) { - return Strings.EMPTY; - } - - if (LOCAL_IP.equals(ip)) { - return "本地访问"; - } - - String dbPath = IPUtils.class.getResource("/ip2region.db").getPath(); - File file = new File(dbPath); - - // 打成jar包时,ip2region.db文件路径发生变化,导致File无法读取,通过stream流方式复制生成临时的ip2region.db文件 - - if (file.exists() == false) { - String tmpdir = System.getProperties().getProperty("java.io.tmpdir"); - dbPath = tmpdir + "/ip2region.db"; - file = new File(dbPath); - if (file.exists() == false) { - try { - FileUtils.copyInputStreamToFile(IPUtils.class.getClassLoader() - .getResourceAsStream("classpath:ip2region.db"), file); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - try { - DbConfig config = new DbConfig(); - DbSearcher searcher = new DbSearcher(config, dbPath); - Method method; - switch (algorithm) { - case DbSearcher.BTREE_ALGORITHM: - method = searcher.getClass().getMethod("btreeSearch", String.class); - break; - case DbSearcher.BINARY_ALGORITHM: - method = searcher.getClass().getMethod("binarySearch", String.class); - break; - case DbSearcher.MEMORY_ALGORITYM: - method = searcher.getClass().getMethod("memorySearch", String.class); - break; - default: - method = searcher.getClass().getMethod("memorySearch", String.class); - break; - } - DataBlock dataBlock = (DataBlock) method.invoke(searcher, ip); - searcher.close(); - return dataBlock.getRegion(); - - } catch (Exception e) { - e.printStackTrace(); - } - return Strings.EMPTY; - } - -} diff --git a/youlai-common/pom.xml b/youlai-common/pom.xml index efb1bb8d4..565a4d88a 100644 --- a/youlai-common/pom.xml +++ b/youlai-common/pom.xml @@ -20,6 +20,5 @@ common-mybatis common-rabbitmq common-es - common-log diff --git a/youlai-gateway/pom.xml b/youlai-gateway/pom.xml index 0545ed688..fcd92f095 100644 --- a/youlai-gateway/pom.xml +++ b/youlai-gateway/pom.xml @@ -97,11 +97,6 @@ common-redis - - com.youlai - common-log - ${youlai.version} - diff --git a/youlai-gateway/src/main/java/com/youlai/gateway/swagger/SwaggerHeaderFilter.java b/youlai-gateway/src/main/java/com/youlai/gateway/swagger/SwaggerHeaderFilter.java deleted file mode 100644 index 422e2509a..000000000 --- a/youlai-gateway/src/main/java/com/youlai/gateway/swagger/SwaggerHeaderFilter.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.youlai.gateway.swagger; - -import org.apache.commons.lang3.StringUtils; -import org.springframework.cloud.gateway.filter.GatewayFilter; -import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; -import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.stereotype.Component; -import org.springframework.web.server.ServerWebExchange; - -/** - * @link https://gitee.com/xiaoym/swagger-bootstrap-ui-demo/blob/master/knife4j-spring-cloud-gateway/service-doc/src/main/java/com/xiaominfo/swagger/service/doc/config/SwaggerHeaderFilter.java - * @auth xianrui - * @date 2021-02-25 16:29 - */ -@Component -public class SwaggerHeaderFilter extends AbstractGatewayFilterFactory { - - private static final String HEADER_NAME = "X-Forwarded-Prefix"; - - private static final String URI = "/v2/api-docs"; - - @Override - public GatewayFilter apply(Object config) { - return (exchange, chain) -> { - ServerHttpRequest request = exchange.getRequest(); - String path = request.getURI().getPath(); - if (!StringUtils.endsWithIgnoreCase(path,URI )) { - return chain.filter(exchange); - } - String basePath = path.substring(0, path.lastIndexOf(URI)); - ServerHttpRequest newRequest = request.mutate().header(HEADER_NAME, basePath).build(); - ServerWebExchange newExchange = exchange.mutate().request(newRequest).build(); - return chain.filter(newExchange); - }; - } -}