Commit 88ca41bf authored by suntao's avatar suntao

异步操作 使用cglib 代理

parent 0c27a4d3
...@@ -15,7 +15,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; ...@@ -15,7 +15,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration @Configuration
@EnableAutoConfiguration @EnableAutoConfiguration
@EnableFeignClients @EnableFeignClients
@EnableAsync @EnableAsync(proxyTargetClass = true)
public class Bootstrap { public class Bootstrap {
public static void main(String[] args) { public static void main(String[] args) {
......
...@@ -4,6 +4,7 @@ import cn.quantgroup.cashloanflowboss.api.login.model.Principal; ...@@ -4,6 +4,7 @@ import cn.quantgroup.cashloanflowboss.api.login.model.Principal;
import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus; import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus;
import cn.quantgroup.cashloanflowboss.api.user.entity.User; import cn.quantgroup.cashloanflowboss.api.user.entity.User;
import cn.quantgroup.cashloanflowboss.api.user.model.UserInfo; import cn.quantgroup.cashloanflowboss.api.user.model.UserInfo;
import cn.quantgroup.cashloanflowboss.api.user.service.UserService;
import cn.quantgroup.cashloanflowboss.api.user.service.UserServiceImpl; import cn.quantgroup.cashloanflowboss.api.user.service.UserServiceImpl;
import cn.quantgroup.cashloanflowboss.core.asserts.Assert; import cn.quantgroup.cashloanflowboss.core.asserts.Assert;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationDictionary; import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationDictionary;
...@@ -28,7 +29,7 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -28,7 +29,7 @@ import java.util.concurrent.ConcurrentHashMap;
public class LoginServiceImpl implements LoginService { public class LoginServiceImpl implements LoginService {
@Autowired @Autowired
private UserServiceImpl userService; private UserService userService;
@Autowired @Autowired
private HttpServletRequest request; private HttpServletRequest request;
......
...@@ -107,6 +107,7 @@ public class OrderServiceImpl implements OrderService{ ...@@ -107,6 +107,7 @@ public class OrderServiceImpl implements OrderService{
private static final String auth = "dXNlcj14dWV6aiZwYXNzd29yZD0xMjMxMjNxd2Vxd2U%3D"; private static final String auth = "dXNlcj14dWV6aiZwYXNzd29yZD0xMjMxMjNxd2Vxd2U%3D";
private static final int CONSCONT_STATUS = 2;
@Override @Override
...@@ -316,7 +317,7 @@ public class OrderServiceImpl implements OrderService{ ...@@ -316,7 +317,7 @@ public class OrderServiceImpl implements OrderService{
// 更新合同状态 // 更新合同状态
Contract conscont= xyqbCenterService.findContractByUserId(orderMapping.getQgUserId()); Contract conscont= xyqbCenterService.findContractByUserId(orderMapping.getQgUserId());
if (conscont != null) { if (conscont != null) {
if (conscont.getGenerateStatus() != 2) { if (conscont.getGenerateStatus() != CONSCONT_STATUS) {
log.info("secondAudit,合同状态不对,channelOrderNumber=".concat(channelOrderNumber)); log.info("secondAudit,合同状态不对,channelOrderNumber=".concat(channelOrderNumber));
// 修改合同状态 // 修改合同状态
ArrayList<String> updateContract = Lists.newArrayList(); ArrayList<String> updateContract = Lists.newArrayList();
......
...@@ -130,8 +130,8 @@ public class UserController { ...@@ -130,8 +130,8 @@ public class UserController {
@PutMapping("/order/clean") @PutMapping("/order/clean")
@Security(authorityId = "User.Order.cleanUserOrder") @Security(authorityId = "User.Order.cleanUserOrder")
public Result<Boolean> cleanUserOrder(@RequestParam @Valid @NotEmpty(message = "无效的用户手机号") String mobile) { public Result<Boolean> cleanUserOrder(@RequestParam @Valid @NotEmpty(message = "无效的用户手机号") String mobile) {
Tuple<Boolean, String> result = userService.cleanUserActiveOrder(mobile); userService.cleanUserActiveOrder(mobile);
return Result.buildSuccess(result.getKey(), result.getValue()); return Result.buildSuccess(true, "异步请求成功");
} }
/** /**
...@@ -143,8 +143,8 @@ public class UserController { ...@@ -143,8 +143,8 @@ public class UserController {
@PutMapping("/info/clean") @PutMapping("/info/clean")
@Security(authorityId = "User.Order.cleanUserInfo") @Security(authorityId = "User.Order.cleanUserInfo")
public Boolean deleteByUserId(@RequestParam @Valid @NotEmpty(message = "无效的用户手机号") String mobile) { public Boolean deleteByUserId(@RequestParam @Valid @NotEmpty(message = "无效的用户手机号") String mobile) {
Tuple<Boolean, String> result = this.xyqbUserService.deleteByUserId(mobile); this.xyqbUserService.deleteByUserId(mobile);
return result.getKey(); return true;
} }
} }
package cn.quantgroup.cashloanflowboss.api.user.service; package cn.quantgroup.cashloanflowboss.api.user.service;
import cn.quantgroup.cashloanflowboss.api.login.model.Principal; import cn.quantgroup.cashloanflowboss.api.login.model.Principal;
import cn.quantgroup.cashloanflowboss.api.optlog.model.OptEnumName;
import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus; import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus;
import cn.quantgroup.cashloanflowboss.api.user.entity.User; import cn.quantgroup.cashloanflowboss.api.user.entity.User;
import cn.quantgroup.cashloanflowboss.api.user.model.QueryUserListModel; import cn.quantgroup.cashloanflowboss.api.user.model.QueryUserListModel;
...@@ -9,7 +8,6 @@ import cn.quantgroup.cashloanflowboss.api.user.model.UserDetailInfo; ...@@ -9,7 +8,6 @@ import cn.quantgroup.cashloanflowboss.api.user.model.UserDetailInfo;
import cn.quantgroup.cashloanflowboss.api.user.model.UserInfoModel; import cn.quantgroup.cashloanflowboss.api.user.model.UserInfoModel;
import cn.quantgroup.cashloanflowboss.api.user.repository.UserRepository; import cn.quantgroup.cashloanflowboss.api.user.repository.UserRepository;
import cn.quantgroup.cashloanflowboss.core.Application; import cn.quantgroup.cashloanflowboss.core.Application;
import cn.quantgroup.cashloanflowboss.core.annotation.opt.OperationAnno;
import cn.quantgroup.cashloanflowboss.core.asserts.Assert; import cn.quantgroup.cashloanflowboss.core.asserts.Assert;
import cn.quantgroup.cashloanflowboss.core.base.Tuple; import cn.quantgroup.cashloanflowboss.core.base.Tuple;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus; import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
...@@ -23,6 +21,7 @@ import org.springframework.beans.BeanUtils; ...@@ -23,6 +21,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
...@@ -191,7 +190,8 @@ public class UserServiceImpl implements UserService{ ...@@ -191,7 +190,8 @@ public class UserServiceImpl implements UserService{
return userRepository.save(user1); return userRepository.save(user1);
} }
@OperationAnno(channelNo = "#this[0]", opt = OptEnumName.USER_ORDER_CLEAN, succSPEL = "#this.key", optDetailSPEL = "#this.value") @Async("commonAsyncExecutor")
//@OperationAnno(channelNo = "#this[0]", opt = OptEnumName.USER_ORDER_CLEAN, succSPEL = "#this.key", optDetailSPEL = "#this.value")
@Override @Override
public Tuple<Boolean,String> cleanUserActiveOrder(String mobile) { public Tuple<Boolean,String> cleanUserActiveOrder(String mobile) {
XUser user = xyqbUserService.findUserByPhoneNo(mobile); XUser user = xyqbUserService.findUserByPhoneNo(mobile);
......
package cn.quantgroup.cashloanflowboss.core.asyncer;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import java.util.concurrent.Executor;
/**
* function:
* date: 2019/12/6
*
* @author: suntao
*/
@Component
public class MyAsyncExecutor {
@Bean(name = "commonAsyncExecutor")
public Executor commonAsyncExecutor() {
return generateThreadPoolTaskExecutor(10, 30, 100, true, 30, true, "commonAsyncExecutor-");
}
/**
* 生成线程池
* @param corePoolSize
* @param maxPoolSize
* @param queueCapacity
* @param waitForCompleteOnShutdown
* @param prefix
* @return
*/
private ThreadPoolTaskExecutor generateThreadPoolTaskExecutor(int corePoolSize, int maxPoolSize, int queueCapacity,
boolean waitForCompleteOnShutdown, int keepAliveSeconds,
boolean allowCoreThreadTimeOut, String prefix) {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
executor.setKeepAliveSeconds(keepAliveSeconds);
executor.setAllowCoreThreadTimeOut(allowCoreThreadTimeOut);
executor.setWaitForTasksToCompleteOnShutdown(waitForCompleteOnShutdown);
executor.setThreadNamePrefix(prefix);
executor.initialize();
return executor ;
}
}
...@@ -31,6 +31,7 @@ public class JolyneServiceImpl implements JolyneService { ...@@ -31,6 +31,7 @@ public class JolyneServiceImpl implements JolyneService {
@Override @Override
public String executeSQL(JolyneDB jolyneDB, String jsonData) { public String executeSQL(JolyneDB jolyneDB, String jsonData) {
return jolyneCenter.executeSQL(jolyneDB.getDbName(), jsonData); return jolyneCenter.executeSQL(jolyneDB.getDbName(), jsonData);
...@@ -42,7 +43,7 @@ public class JolyneServiceImpl implements JolyneService { ...@@ -42,7 +43,7 @@ public class JolyneServiceImpl implements JolyneService {
jolyneCenter.reloadJob(jobName); jolyneCenter.reloadJob(jobName);
} }
@Async @Async("commonAsyncExecutor")
@Override @Override
public String delayUpdateWaitingXyqbSql(Long loanId, Long delayTime) { public String delayUpdateWaitingXyqbSql(Long loanId, Long delayTime) {
...@@ -56,7 +57,7 @@ public class JolyneServiceImpl implements JolyneService { ...@@ -56,7 +57,7 @@ public class JolyneServiceImpl implements JolyneService {
try { try {
Thread.sleep(delayTime); Thread.sleep(delayTime);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); log.error("Thread.sleep error");
} }
loanApplicationHistory = xyqbCenterService.findLoanApplicationHistoryById(loanId); loanApplicationHistory = xyqbCenterService.findLoanApplicationHistoryById(loanId);
...@@ -80,7 +81,7 @@ public class JolyneServiceImpl implements JolyneService { ...@@ -80,7 +81,7 @@ public class JolyneServiceImpl implements JolyneService {
try { try {
Thread.sleep(200); Thread.sleep(200);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); log.error("Thread.sleep error");
} }
reloadJob("cn.qg.clotho.job.FetchDataLoanJob"); reloadJob("cn.qg.clotho.job.FetchDataLoanJob");
...@@ -88,7 +89,7 @@ public class JolyneServiceImpl implements JolyneService { ...@@ -88,7 +89,7 @@ public class JolyneServiceImpl implements JolyneService {
try { try {
Thread.sleep(200); Thread.sleep(200);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); log.error("Thread.sleep error");
} }
reloadJob("cn.qg.clotho.job.LoanDataJob"); reloadJob("cn.qg.clotho.job.LoanDataJob");
......
...@@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory; ...@@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.util.*;
...@@ -130,8 +131,10 @@ public class XyqbUserServiceImpl implements XyqbUserService { ...@@ -130,8 +131,10 @@ public class XyqbUserServiceImpl implements XyqbUserService {
} }
@OperationAnno(channelNo = "#this[0]", opt = OptEnumName.USER_INFO_CLEAN, succSPEL = "#this.key", optDetailSPEL = "#this.value") //@OperationAnno(channelNo = "#this[0]", opt = OptEnumName.USER_INFO_CLEAN, succSPEL = "#this.key", optDetailSPEL = "#this.value")
@Override public Tuple<Boolean,String> deleteByUserId(String phoneNo) { @Async("commonAsyncExecutor")
@Override
public Tuple<Boolean,String> deleteByUserId(String phoneNo) {
try{ try{
UserSysResult<XUser> xUser = userSysService.getService().findUserByPhoneNo(phoneNo); UserSysResult<XUser> xUser = userSysService.getService().findUserByPhoneNo(phoneNo);
if (xUser == null || xUser.getData() == null) { if (xUser == null || xUser.getData() == null) {
...@@ -156,8 +159,8 @@ public class XyqbUserServiceImpl implements XyqbUserService { ...@@ -156,8 +159,8 @@ public class XyqbUserServiceImpl implements XyqbUserService {
if(userKeys!=null){ if(userKeys!=null){
redisTemplate.delete(userKeys); redisTemplate.delete(userKeys);
} }
String token_key = "userid-sessionvalue:cache::"+userId+":xyqb"; String tokenKey = "userid-sessionvalue:cache::"+userId+":xyqb";
String token = redisTemplate.opsForValue().get(token_key); String token = redisTemplate.opsForValue().get(tokenKey);
if(token!=null && redisTemplate.keys(token)!=null){ if(token!=null && redisTemplate.keys(token)!=null){
Set<String> tokenKeys = redisTemplate.keys(token); Set<String> tokenKeys = redisTemplate.keys(token);
redisTemplate.delete(tokenKeys); redisTemplate.delete(tokenKeys);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment