| | |
| | | import cn.gistack.system.user.sync.dto.ApiPushDTO; |
| | | import cn.gistack.system.user.sync.exception.ErrorCode; |
| | | import cn.gistack.system.user.sync.util.*; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.core.mp.support.Condition; |
| | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.*; |
| | | |
| | | /** |
| | | * @PROJECT_NAME: skjcmanager |
| | |
| | | List<AccountBean> accountBeanList = JSONArray.parseArray(syncData, AccountBean.class); |
| | | |
| | | // 异步执行用户处理 |
| | | asyncUserGo(accountBeanList); |
| | | |
| | | int pcount = Runtime.getRuntime().availableProcessors(); |
| | | //最大线程数控制 |
| | | int maxthreadNum = accountBeanList.size(); |
| | | ExecutorService executor = new ThreadPoolExecutor(pcount, maxthreadNum, 10, TimeUnit.SECONDS, |
| | | new ArrayBlockingQueue<>(1000), Executors.defaultThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy()); |
| | | System.out.println("开始执行用户处理!!!!!!!!!!!!"); |
| | | //循环list |
| | | for (int i = 0; i < maxthreadNum; i++) { |
| | | final int index = i; |
| | | final AccountBean accountBean = accountBeanList.get(i); |
| | | executor.execute(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | //业务处理 |
| | | System.out.println("当前线程:" + Thread.currentThread().getName() + " " + index); |
| | | System.out.println("当前处理对象:" + JSON.toJSONString(accountBean)); |
| | | asyncUserGo(accountBean); |
| | | } |
| | | }); |
| | | |
| | | }; |
| | | |
| | | ret.put("code", 1000); |
| | | ret.put("msg", "成功"); |
| | | ret.put("data", apiPushDTO.getSign()); |
| | | System.out.println("处理返回了~~~~"); |
| | | return ret; |
| | | } |
| | | |
| | | @Async |
| | | public void asyncUserGo(List<AccountBean> accountBeanList) { |
| | | //循环list |
| | | accountBeanList.forEach(accountBean -> { |
| | | public void asyncUserGo(AccountBean accountBean) { |
| | | //判断手机号是否在库中 |
| | | User params = new User(); |
| | | params.setPhone(accountBean.getPrincipalId()); |
| | |
| | | userService.updateUser(one); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |