【7.0.4】【c】更新C端用户个人信息获取

pull/22/head
fengshuonan 2021-06-08 23:02:24 +08:00
parent e4022ecc3f
commit 12998583cf
13 changed files with 299 additions and 3 deletions

View File

@ -46,7 +46,7 @@ public enum WrapperExceptionEnum implements AbstractExceptionEnum {
/** /**
* *
*/ */
TRANSFER_ERROR(RuleConstants.BUSINESS_ERROR_TYPE_CODE + WrapperConstants.WRAPPER_EXCEPTION_STEP_CODE + "02", "字段包装转化异常"); TRANSFER_ERROR(RuleConstants.BUSINESS_ERROR_TYPE_CODE + WrapperConstants.WRAPPER_EXCEPTION_STEP_CODE + "02", "字段包装转化异常,具体信息:{}");
/** /**
* *

View File

@ -213,7 +213,7 @@ public class WrapperAop {
} }
} catch (Exception e) { } catch (Exception e) {
log.error("原始对象包装过程,字段转化异常:{}", e.getMessage()); log.error("原始对象包装过程,字段转化异常:{}", e.getMessage());
throw new WrapperException(WrapperExceptionEnum.TRANSFER_ERROR); throw new WrapperException(WrapperExceptionEnum.TRANSFER_ERROR, e.getMessage());
} }
return originMap; return originMap;

View File

@ -24,6 +24,8 @@
*/ */
package cn.stylefeng.roses.kernel.customer.api; package cn.stylefeng.roses.kernel.customer.api;
import cn.stylefeng.roses.kernel.customer.api.pojo.CustomerInfo;
/** /**
* Capi * Capi
* *
@ -32,5 +34,12 @@ package cn.stylefeng.roses.kernel.customer.api;
*/ */
public interface CustomerApi { public interface CustomerApi {
/**
* C
*
* @author fengshuonan
* @date 2021/6/8 21:25
*/
CustomerInfo getCustomerInfoById(Long customerId);
} }

View File

@ -42,4 +42,9 @@ public interface CustomerConstants {
*/ */
String CUSTOMER_EXCEPTION_STEP_CODE = "31"; String CUSTOMER_EXCEPTION_STEP_CODE = "31";
/**
* C
*/
String CUSTOMER_CACHE_PREFIX = "customer:";
} }

View File

@ -51,4 +51,34 @@ public class CustomerConfigExpander {
return ConfigContext.me().getSysConfigValueWithDefault("CUSTOMER_RESET_PWD_EMAIL_CONTENT", String.class, "您的验证码是【{}】,此验证码用于修改登录密码,请不要泄露给他人,如果不是您本人操作,请忽略此邮件。"); return ConfigContext.me().getSysConfigValueWithDefault("CUSTOMER_RESET_PWD_EMAIL_CONTENT", String.class, "您的验证码是【{}】,此验证码用于修改登录密码,请不要泄露给他人,如果不是您本人操作,请忽略此邮件。");
} }
/**
* bucket
*
* @author fengshuonan
* @date 2021/6/7 15:42
*/
public static String getCustomerBucket() {
return ConfigContext.me().getSysConfigValueWithDefault("CUSTOMER_FILE_BUCKET", String.class, "customer-bucket");
}
/**
* bucket
*
* @author fengshuonan
* @date 2021/6/7 15:42
*/
public static Long getCustomerBucketExpiredSeconds() {
return ConfigContext.me().getSysConfigValueWithDefault("CUSTOMER_FILE_BUCKET_EXPIRED_SECONDS", Long.class, 600L);
}
/**
*
*
* @author fengshuonan
* @date 2021/6/7 15:42
*/
public static Long getCustomerCacheExpiredSeconds() {
return ConfigContext.me().getSysConfigValueWithDefault("CUSTOMER_CACHE_EXPIRED_SECONDS", Long.class, 3600L);
}
} }

View File

@ -0,0 +1,54 @@
package cn.stylefeng.roses.kernel.customer.api.pojo;
import lombok.Data;
/**
*
*
* @author fengshuonan
* @date 2021/6/8 21:23
*/
@Data
public class CustomerInfo {
/**
* id
*/
private Long customerId;
/**
*
*/
private String account;
/**
*
*/
private String nickName;
/**
*
*/
private String email;
/**
*
*/
private String telephone;
/**
* id
*/
private Long avatar;
/**
* url
*/
private String avatarObjectUrl;
/**
*
*/
private Integer score;
}

View File

@ -86,6 +86,34 @@
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<!--缓存api-->
<!--用户的查询会使用缓存-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>cache-api</artifactId>
<version>${roses.version}</version>
</dependency>
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>cache-sdk-memory</artifactId>
<version>${roses.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>cache-sdk-redis</artifactId>
<version>${roses.version}</version>
<optional>true</optional>
</dependency>
<!--文件操作的api-->
<!--用在用户头像等文件的操作-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>file-api</artifactId>
<version>${roses.version}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -0,0 +1,49 @@
/*
* Copyright [2020-2030] [https://www.stylefeng.cn]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* GunsAPACHE LICENSE 2.0使
*
* 1.LICENSE
* 2.Guns
* 3.
* 4. https://gitee.com/stylefeng/guns
* 5. https://gitee.com/stylefeng/guns
* 6.
*/
package cn.stylefeng.roses.kernel.customer.modular.cache;
import cn.hutool.cache.impl.TimedCache;
import cn.stylefeng.roses.kernel.cache.memory.AbstractMemoryCacheOperator;
import cn.stylefeng.roses.kernel.customer.api.constants.CustomerConstants;
import cn.stylefeng.roses.kernel.customer.api.pojo.CustomerInfo;
/**
* C
*
* @author fengshuonan
* @date 2021/2/28 10:23
*/
public class CustomerMemoryCache extends AbstractMemoryCacheOperator<CustomerInfo> {
public CustomerMemoryCache(TimedCache<String, CustomerInfo> timedCache) {
super(timedCache);
}
@Override
public String getCommonKeyPrefix() {
return CustomerConstants.CUSTOMER_CACHE_PREFIX;
}
}

View File

@ -0,0 +1,49 @@
/*
* Copyright [2020-2030] [https://www.stylefeng.cn]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* GunsAPACHE LICENSE 2.0使
*
* 1.LICENSE
* 2.Guns
* 3.
* 4. https://gitee.com/stylefeng/guns
* 5. https://gitee.com/stylefeng/guns
* 6.
*/
package cn.stylefeng.roses.kernel.customer.modular.cache;
import cn.stylefeng.roses.kernel.cache.redis.AbstractRedisCacheOperator;
import cn.stylefeng.roses.kernel.customer.api.constants.CustomerConstants;
import cn.stylefeng.roses.kernel.customer.api.pojo.CustomerInfo;
import org.springframework.data.redis.core.RedisTemplate;
/**
* C
*
* @author fengshuonan
* @date 2021/2/28 10:23
*/
public class CustomerRedisCache extends AbstractRedisCacheOperator<CustomerInfo> {
public CustomerRedisCache(RedisTemplate<String, CustomerInfo> redisTemplate) {
super(redisTemplate);
}
@Override
public String getCommonKeyPrefix() {
return CustomerConstants.CUSTOMER_CACHE_PREFIX;
}
}

View File

@ -2,6 +2,7 @@ package cn.stylefeng.roses.kernel.customer.modular.service;
import cn.stylefeng.roses.kernel.auth.api.pojo.auth.LoginRequest; import cn.stylefeng.roses.kernel.auth.api.pojo.auth.LoginRequest;
import cn.stylefeng.roses.kernel.auth.api.pojo.auth.LoginResponse; import cn.stylefeng.roses.kernel.auth.api.pojo.auth.LoginResponse;
import cn.stylefeng.roses.kernel.customer.api.CustomerApi;
import cn.stylefeng.roses.kernel.customer.modular.entity.Customer; import cn.stylefeng.roses.kernel.customer.modular.entity.Customer;
import cn.stylefeng.roses.kernel.customer.modular.request.CustomerRequest; import cn.stylefeng.roses.kernel.customer.modular.request.CustomerRequest;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult; import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
@ -15,7 +16,7 @@ import java.util.List;
* @author fengshuonan * @author fengshuonan
* @date 2021/06/07 11:40 * @date 2021/06/07 11:40
*/ */
public interface CustomerService extends IService<Customer> { public interface CustomerService extends IService<Customer>, CustomerApi {
/** /**
* *

View File

@ -11,8 +11,11 @@ import cn.stylefeng.roses.kernel.auth.api.password.PasswordStoredEncryptApi;
import cn.stylefeng.roses.kernel.auth.api.pojo.auth.LoginRequest; import cn.stylefeng.roses.kernel.auth.api.pojo.auth.LoginRequest;
import cn.stylefeng.roses.kernel.auth.api.pojo.auth.LoginResponse; import cn.stylefeng.roses.kernel.auth.api.pojo.auth.LoginResponse;
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser; import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.customer.api.exception.CustomerException; import cn.stylefeng.roses.kernel.customer.api.exception.CustomerException;
import cn.stylefeng.roses.kernel.customer.api.exception.enums.CustomerExceptionEnum; import cn.stylefeng.roses.kernel.customer.api.exception.enums.CustomerExceptionEnum;
import cn.stylefeng.roses.kernel.customer.api.expander.CustomerConfigExpander;
import cn.stylefeng.roses.kernel.customer.api.pojo.CustomerInfo;
import cn.stylefeng.roses.kernel.customer.modular.entity.Customer; import cn.stylefeng.roses.kernel.customer.modular.entity.Customer;
import cn.stylefeng.roses.kernel.customer.modular.factory.CustomerFactory; import cn.stylefeng.roses.kernel.customer.modular.factory.CustomerFactory;
import cn.stylefeng.roses.kernel.customer.modular.mapper.CustomerMapper; import cn.stylefeng.roses.kernel.customer.modular.mapper.CustomerMapper;
@ -23,6 +26,7 @@ import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult; import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.email.api.MailSenderApi; import cn.stylefeng.roses.kernel.email.api.MailSenderApi;
import cn.stylefeng.roses.kernel.email.api.pojo.SendMailParam; import cn.stylefeng.roses.kernel.email.api.pojo.SendMailParam;
import cn.stylefeng.roses.kernel.file.api.FileOperatorApi;
import cn.stylefeng.roses.kernel.jwt.api.context.JwtContext; import cn.stylefeng.roses.kernel.jwt.api.context.JwtContext;
import cn.stylefeng.roses.kernel.jwt.api.pojo.payload.DefaultJwtPayload; import cn.stylefeng.roses.kernel.jwt.api.pojo.payload.DefaultJwtPayload;
import cn.stylefeng.roses.kernel.log.api.LoginLogServiceApi; import cn.stylefeng.roses.kernel.log.api.LoginLogServiceApi;
@ -73,6 +77,12 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
@Resource @Resource
private LoginLogServiceApi loginLogServiceApi; private LoginLogServiceApi loginLogServiceApi;
@Resource
private CacheOperatorApi<CustomerInfo> customerInfoCacheOperatorApi;
@Resource
private FileOperatorApi fileOperatorApi;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void reg(CustomerRequest customerRequest) { public void reg(CustomerRequest customerRequest) {
@ -250,6 +260,38 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
return this.list(wrapper); return this.list(wrapper);
} }
@Override
public CustomerInfo getCustomerInfoById(Long customerId) {
// 查询缓存中有没有用户信息
String customerIdKey = String.valueOf(customerId);
CustomerInfo customerInfo = customerInfoCacheOperatorApi.get(customerIdKey);
if (customerInfo != null) {
return customerInfo;
}
// 获取C端用户详情
Customer customer = this.getById(customerId);
if (customer == null) {
throw new CustomerException(CustomerExceptionEnum.CANT_FIND_CUSTOMER, customerId);
}
CustomerInfo result = new CustomerInfo();
BeanUtil.copyProperties(customer, result);
// 获取头像的url
String fileAuthUrl = fileOperatorApi.getFileAuthUrl(
CustomerConfigExpander.getCustomerBucket(),
customer.getAvatarObjectName(),
CustomerConfigExpander.getCustomerBucketExpiredSeconds());
result.setAvatarObjectUrl(fileAuthUrl);
// 放入缓存用户信息
customerInfoCacheOperatorApi.put(customerIdKey, result, CustomerConfigExpander.getCustomerCacheExpiredSeconds());
return result;
}
/** /**
* *
* *
@ -319,4 +361,5 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
} }
} }
} }

View File

@ -24,6 +24,13 @@
<version>${roses.version}</version> <version>${roses.version}</version>
</dependency> </dependency>
<!--默认内存缓存使用-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>cache-sdk-memory</artifactId>
<version>${roses.version}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -24,6 +24,14 @@
*/ */
package cn.stylefeng.roses.kernel.customer.starter; package cn.stylefeng.roses.kernel.customer.starter;
import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.customer.api.expander.CustomerConfigExpander;
import cn.stylefeng.roses.kernel.customer.api.pojo.CustomerInfo;
import cn.stylefeng.roses.kernel.customer.modular.cache.CustomerMemoryCache;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
/** /**
@ -35,4 +43,17 @@ import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
public class GunsCustomerAutoConfiguration { public class GunsCustomerAutoConfiguration {
/**
* C
*
* @author fengshuonan
* @date 2021/6/8 22:41
*/
@Bean
@ConditionalOnMissingBean(name = "customerInfoCacheOperatorApi")
public CacheOperatorApi<CustomerInfo> customerInfoCacheOperatorApi() {
TimedCache<String, CustomerInfo> customerInfoTimedCache = CacheUtil.newTimedCache(CustomerConfigExpander.getCustomerCacheExpiredSeconds() * 1000);
return new CustomerMemoryCache(customerInfoTimedCache);
}
} }