diff --git a/pom.xml b/pom.xml index 177b45cf..98110ef5 100644 --- a/pom.xml +++ b/pom.xml @@ -93,6 +93,11 @@ spring-boot-starter-cache + + org.springframework.boot + spring-boot-starter-data-redis + + com.alibaba easyexcel diff --git a/src/main/java/com/chint/application/out/LocationController.java b/src/main/java/com/chint/application/out/LocationController.java index b9405863..391e551d 100644 --- a/src/main/java/com/chint/application/out/LocationController.java +++ b/src/main/java/com/chint/application/out/LocationController.java @@ -12,6 +12,7 @@ import com.chint.infrastructure.util.Result; import com.chint.infrastructure.util.StringCheck; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -37,6 +38,7 @@ public class LocationController { return Result.Success(SUCCESS, locationRepository.pageQuery(locationParam)); } +// @Cacheable(value = "LocationResByFirstLetter", key = "#locationParam") @ApiOperation("根据查询词查询地理信息") @PostMapping("/query/word") public Result> queryByFirstLetter(@RequestBody LocationParam locationParam) { diff --git a/src/main/java/com/chint/application/services/OrderApplicationService.java b/src/main/java/com/chint/application/services/OrderApplicationService.java index a28fb6f1..a681b224 100644 --- a/src/main/java/com/chint/application/services/OrderApplicationService.java +++ b/src/main/java/com/chint/application/services/OrderApplicationService.java @@ -105,7 +105,7 @@ public class OrderApplicationService { if (order.getOrderStatus() >= ORDER_STATUS_APPROVAL) { leg = legDomainService.addApproveEvent(leg); } - + leg.setRouteId(routeOrder.getRouteId()); legRepository.save(leg); if (!order.getOrderStatus().equals(ORDER_STATUS_PREPARE)) { diff --git a/src/main/java/com/chint/infrastructure/config/redis/RedisConfiguration.java b/src/main/java/com/chint/infrastructure/config/redis/RedisConfiguration.java new file mode 100644 index 00000000..5ae99636 --- /dev/null +++ b/src/main/java/com/chint/infrastructure/config/redis/RedisConfiguration.java @@ -0,0 +1,48 @@ +package com.chint.infrastructure.config.redis; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.cache.RedisCacheConfiguration; +import org.springframework.data.redis.cache.RedisCacheManager; +import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.StringRedisSerializer; +import springfox.documentation.annotations.Cacheable; + +import javax.validation.constraints.NotNull; +import java.time.Duration; + +@EnableCaching +@Configuration +@Slf4j +public class RedisConfiguration { + + @Autowired + private RedisConnectionFactory connectionFactory; + + @Bean + public RedisCacheManager cacheManager() { + RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig() + .entryTtl(Duration.ofHours(1)); // 设置缓存过期时间为1小时 + return RedisCacheManager.builder(connectionFactory) + .cacheDefaults(config) + .build(); + } + + @Bean + public RedisTemplate redisTemplate(){ + log.info("开始创建redis模板对象..."); + RedisTemplate redisTemplate = new RedisTemplate(); + //设置redis的连接工厂对象 + RedisConnection connection = connectionFactory.getConnection(); + System.out.println(connection); + redisTemplate.setConnectionFactory(connectionFactory); + //设置redis key的序列化器 + redisTemplate.setKeySerializer(new StringRedisSerializer()); + return redisTemplate; + } +} \ No newline at end of file diff --git a/src/main/java/com/chint/infrastructure/webconfig/JwtTokenAdminInterceptor.java b/src/main/java/com/chint/infrastructure/config/webconfig/JwtTokenAdminInterceptor.java similarity index 97% rename from src/main/java/com/chint/infrastructure/webconfig/JwtTokenAdminInterceptor.java rename to src/main/java/com/chint/infrastructure/config/webconfig/JwtTokenAdminInterceptor.java index 3fc6cdb7..f835281f 100644 --- a/src/main/java/com/chint/infrastructure/webconfig/JwtTokenAdminInterceptor.java +++ b/src/main/java/com/chint/infrastructure/config/webconfig/JwtTokenAdminInterceptor.java @@ -1,4 +1,4 @@ -package com.chint.infrastructure.webconfig; +package com.chint.infrastructure.config.webconfig; import com.auth0.jwt.exceptions.TokenExpiredException; import com.chint.domain.aggregates.user.User; diff --git a/src/main/java/com/chint/infrastructure/webconfig/WebConfig.java b/src/main/java/com/chint/infrastructure/config/webconfig/WebConfig.java similarity index 91% rename from src/main/java/com/chint/infrastructure/webconfig/WebConfig.java rename to src/main/java/com/chint/infrastructure/config/webconfig/WebConfig.java index 5bdd1252..4732517d 100644 --- a/src/main/java/com/chint/infrastructure/webconfig/WebConfig.java +++ b/src/main/java/com/chint/infrastructure/config/webconfig/WebConfig.java @@ -1,6 +1,5 @@ -package com.chint.infrastructure.webconfig; +package com.chint.infrastructure.config.webconfig; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; diff --git a/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java b/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java index 7024626e..ee37259e 100644 --- a/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java +++ b/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java @@ -12,7 +12,8 @@ import com.chint.infrastructure.constant.SFConstant; import com.chint.infrastructure.util.BaseContext; import com.chint.infrastructure.util.StringCheck; import com.chint.interfaces.rest.base.PostRequest; -import com.chint.interfaces.rest.user.dto.*; +import com.chint.interfaces.rest.user.dto.AccessKeyDTO; +import com.chint.interfaces.rest.user.dto.UserDataDTO; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import lombok.extern.slf4j.Slf4j; @@ -115,71 +116,12 @@ public class UserHttpRequestImpl implements UserHttpRequest { Type type = new TypeToken>() { }.getType(); if (result.getData() != null) { - String companyCode = user.getCompanyCode(); - if (companyCode == null) { - companyCode = BaseContext.getCurrentUser().getUserLoginParam().getCompanyCode(); - } - String newCompanyCode = companyCode; List fromJson = gson.fromJson(result.getData().toString(), type); - - List companyCodeList = fromJson.stream().map(UserDataDTO::getCompany).toList(); - - if (fromJson.size() == 1) { UserDataDTO userData = fromJson.get(0); - user.setCompanyCode(userData.getCompany()); - user.setCompanyName(userData.getCompany_cn()); - user.setWorkStatus(userData.getStatus()); - user.setGender(userData.getGender()); - user.setName(userData.getUname()); - user.setPhoneNumber(userData.getMobilePhone()); - user.setManaLevel(userData.getCust_manaLevel()); - user.setProfLevel(userData.getCust_profLevel()); - user.setQualityLevel(userData.getCust_qualityLevel()); - if (user.getCompanyCode().equals(XN_COMPANY_CODE)) { - user.addXNFssc(FSSC_LOAD_URL, postRequest); - } else { - user.addJTFssc(FSSC_LOAD_URL, postRequest); - } - - if (user.getEmployeeNo().equals("220208013")) { - user.addXNFssc(FSSC_LOAD_URL, postRequest); - } + loadSingleSF(userData, user); } else { - Optional first; - //这里进行判断如果是中文字段的CompanyCode需要用中文名进行匹配 - if (StringCheck.isFirstCharacterChinese(newCompanyCode)) { - first = fromJson.stream() - .filter(userData -> userData.getCompany_cn().equals(newCompanyCode)) - .findFirst(); - - } else { - first = fromJson.stream() - .filter(userData -> userData.getCompany().equals(newCompanyCode)) - .findFirst(); - } - first.ifPresent( - userData -> { - user.setCompanyCode(userData.getCompany()); - user.setWorkStatus(userData.getStatus()); - user.setGender(userData.getGender()); - user.setName(userData.getUname()); - user.setPhoneNumber(userData.getMobilePhone()); - user.setCompanyName(userData.getCompany_cn()); - } - ); - fromJson.stream() - .filter(userData -> userData.getUserId().equals(userData.getPersonIdExternal())) - .findFirst() - .ifPresent(userData -> { - user.setManaLevel(userData.getCust_manaLevel()); - user.setProfLevel(userData.getCust_profLevel()); - user.setQualityLevel(userData.getCust_qualityLevel()); - }); - user.addJTFssc(FSSC_LOAD_URL, postRequest); - if (companyCodeList.contains(XN_COMPANY_CODE) || user.getEmployeeNo().equals("220208013")) { - user.addXNFssc(FSSC_LOAD_URL, postRequest); - } + loadBatchSF(fromJson, user); } return user; } else { @@ -187,10 +129,73 @@ public class UserHttpRequestImpl implements UserHttpRequest { } } - private User loadSingleSF(List userDataDTOS, User user){ + private User loadSingleSF(UserDataDTO userData, User user) { + user.setCompanyCode(userData.getCompany()); + user.setCompanyName(userData.getCompany_cn()); + user.setWorkStatus(userData.getStatus()); + user.setGender(userData.getGender()); + user.setName(userData.getUname()); + user.setPhoneNumber(userData.getMobilePhone()); + user.setManaLevel(userData.getCust_manaLevel()); + user.setProfLevel(userData.getCust_profLevel()); + user.setQualityLevel(userData.getCust_qualityLevel()); + if (user.getCompanyCode().equals(XN_COMPANY_CODE)) { + user.addXNFssc(FSSC_LOAD_URL, postRequest); + } + //如果用户的公司编码属于集团 ,那么加入集团财务共享跳转地址 + if (jtCompanyDomainService.ifCompanyInJT(null, userData.getCompany())) { + user.addJTFssc(FSSC_LOAD_URL, postRequest); + } + return user; + } + private User loadBatchSF(List userDataDTOS, User user) { + //从用户身上获取companyCode , + String companyCode = user.getCompanyCode(); + if (companyCode == null) { + //如果为null,说明用户是登录操作 ,那么从登录参数中获取 companyCode + companyCode = BaseContext.getCurrentUser().getUserLoginParam().getCompanyCode(); + } + String newCompanyCode = companyCode; + List companyCodeList = userDataDTOS.stream().map(UserDataDTO::getCompany).toList(); + Optional first; + if (StringCheck.isFirstCharacterChinese(newCompanyCode)) { + first = userDataDTOS.stream() + .filter(userData -> userData.getCompany_cn().equals(newCompanyCode)) + .findFirst(); + } else { + first = userDataDTOS.stream() + .filter(userData -> userData.getCompany().equals(newCompanyCode)) + .findFirst(); + } + first.ifPresent( + userData -> { + user.setCompanyCode(userData.getCompany()); + user.setWorkStatus(userData.getStatus()); + user.setGender(userData.getGender()); + user.setName(userData.getUname()); + user.setPhoneNumber(userData.getMobilePhone()); + user.setCompanyName(userData.getCompany_cn()); + } + ); + userDataDTOS.stream() + .filter(userData -> userData.getUserId().equals(userData.getPersonIdExternal())) + .findFirst() + .ifPresent(userData -> { + user.setManaLevel(userData.getCust_manaLevel()); + user.setProfLevel(userData.getCust_profLevel()); + user.setQualityLevel(userData.getCust_qualityLevel()); + }); + + //如果用户的公司编码属于集团 ,那么加入集团财务共享跳转地址 + if (jtCompanyDomainService.ifCompanyInJT(null, user.getCompanyCode())) { + user.addJTFssc(FSSC_LOAD_URL, postRequest); + } + if (companyCodeList.contains(XN_COMPANY_CODE)) { + user.addXNFssc(FSSC_LOAD_URL, postRequest); + } return user; } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 10c90953..f6ff4b11 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -12,6 +12,12 @@ chint: username: tripbook password: W@Xgf25d&lRk*L0X# url: https://gxdev03.chint.com/businesstravelhome/ + redis: + host: 10.10.103.131 + port: 6379 + password: Worktask@Redis2023 + database: 4 + logging: level: org.springframework.jdbc.core.JdbcTemplate: DEBUG diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 7f4875a8..d6ccf959 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -11,7 +11,11 @@ chint: username: tripbookpro password: W@Xbf25d&lG5k*L01X# url: https://trip.chint.com/ - + redis: + host: 10.10.103.131 + port: 6379 + password: Worktask@Redis2023 + database: 4 #正式 ly: appId: zhengtai diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 49733827..397752dc 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -23,6 +23,12 @@ chint: username: tripbook password: W@Xgf25d&lRk*L0X# url: https://gxdev03.chint.com/businesstravelhome/ + redis: + host: 10.10.103.131 + port: 6379 + password: Worktask@Redis2023 + database: 4 + logging: level: diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 04736697..6ff5c8c9 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -6,4 +6,9 @@ spring: url: jdbc:mysql://${chint.datasource.host}:${chint.datasource.port}/${chint.datasource.database}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true username: ${chint.datasource.username} password: ${chint.datasource.password} - + data: + redis: + host: ${chint.redis.host} + port: ${chint.redis.port} + password: ${chint.redis.password} + database: ${chint.redis.database}