智慧保安后台管理-外网
Administrator
2022-03-05 fdf73d9cb067998204935174a8405e9f91495ba7
取消报名修改,异步失效问题修改
10 files modified
105 ■■■■ changed files
src/main/java/org/springblade/Application.java 13 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/common/config/AsyncConfig.java 15 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/qrcode/QrCodeController.java 17 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/mapper/UserMapper.java 7 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/mapper/UserMapper.xml 3 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/service/IUserService.java 7 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/service/MyAsyncService.java 18 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java 10 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/training/controller/TrainingRegistrationController.java 11 ●●●● patch | view | raw | blame | history
src/main/resources/application-test.yml 4 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/Application.java
@@ -21,6 +21,7 @@
import org.springblade.modules.webscoket.WebSocketServer;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
@@ -30,16 +31,18 @@
 */
@EnableScheduling
@SpringBootApplication
public class Application implements CommandLineRunner {
@EnableAsync
//public class Application implements CommandLineRunner {
public class Application{
    public static void main(String[] args) {
        BladeApplication.run(CommonConstant.APPLICATION_NAME, Application.class, args);
    }
    @Override
    public void run(String... args) throws Exception {
        WebSocketServer webSocketServer= new WebSocketServer(2086);
    }
//    @Override
//    public void run(String... args) throws Exception {
//        WebSocketServer webSocketServer= new WebSocketServer(2086);
//    }
}
src/main/java/org/springblade/common/config/AsyncConfig.java
@@ -1,10 +1,14 @@
package org.springblade.common.config;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
/**
@@ -13,21 +17,22 @@
 * @since 2022-02-22
 */
@EnableAsync
public class AsyncConfig {
public class AsyncConfig{
    @Bean
    public TaskExecutor executor(){
    public Executor getAsyncExecutor() {
        ThreadPoolTaskExecutor executor=new ThreadPoolTaskExecutor();
        //核心线程数
        executor.setCorePoolSize(10);
        executor.setCorePoolSize(4);
        //最大线程数
        executor.setMaxPoolSize(20);
        executor.setMaxPoolSize(6);
        //队列大小
        executor.setQueueCapacity(1000);
        //线程最大空闲时间
        executor.setKeepAliveSeconds(300);
        executor.setThreadNamePrefix("fsx-Executor-");
        //指定用于新创建的线程名称的前缀。
        executor.setThreadNamePrefix("fsx-Executor-");
        //设置拒绝策略  CallerRunsPolicy 由调用的线程来处理这个任务
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        //返回
        return executor;
src/main/java/org/springblade/modules/qrcode/QrCodeController.java
@@ -7,6 +7,7 @@
import org.springblade.core.tool.api.R;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.service.IUserService;
import org.springblade.modules.system.service.MyAsyncService;
import org.springblade.modules.system.vo.UserVO;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
@@ -34,6 +35,8 @@
public class QrCodeController {
    private final IUserService userService;
    private final MyAsyncService myAsyncService;
    /**
     * 二维码生成-字节流
@@ -128,4 +131,18 @@
        return userService.getUserInfoBySecurityNumber(securityNumber,cardid);
    }
    /**
     * test
     * 异步调用测试
     */
    @GetMapping("/test")
    public void test(){
        //根据保安员编码查询保安员信息
        for (int i = 0; i < 500; i++) {
            User user = new User();
            user.setCardid("cardid"+i);
            myAsyncService.test(user);
        }
    }
}
src/main/java/org/springblade/modules/system/mapper/UserMapper.java
@@ -264,4 +264,11 @@
     * @return
     */
    List<Integer> getAgeStatistics(@Param("user") UserVO user);
    /**
     * 根据用户 id 查询用户信息
     * @param id
     * @return
     */
    User getUserById(long id);
}
src/main/java/org/springblade/modules/system/mapper/UserMapper.xml
@@ -1126,6 +1126,9 @@
        )
    </select>
    <select id="getUserById" resultType="org.springblade.modules.system.entity.User">
        select * from blade_user where id = #{id}
    </select>
</mapper>
src/main/java/org/springblade/modules/system/service/IUserService.java
@@ -380,4 +380,11 @@
     * @return
     */
    Object getNotUpdatePwdInfo();
    /**
     * 根据用户 id 查询用户信息
     * @param id
     * @return
     */
    User getUserById(String id);
}
src/main/java/org/springblade/modules/system/service/MyAsyncService.java
@@ -110,4 +110,22 @@
    public void FTP(String s) {
        FtpUtil.sqlFileUpload(s);
    }
    /**
     * test
     * @param user
     */
    @Async
    public void test(User user) {
        String requestUrl = qfqkBaseApiUrl + "/blade-user/test";
        //装换为 json
        JSONObject jsonObject = JSONObject.fromObject(user);
        //发送请求
        try {
            HttpClientUtils.httpPostWithjson(requestUrl,jsonObject.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
@@ -1781,4 +1781,14 @@
        }
        return list;
    }
    /**
     * 根据用户 id 查询用户信息
     * @param id
     * @return
     */
    @Override
    public User getUserById(String id) {
        return baseMapper.getUserById(Long.parseLong(id));
    }
}
src/main/java/org/springblade/modules/training/controller/TrainingRegistrationController.java
@@ -86,7 +86,7 @@
    @ApiOperation(value = "新增", notes = "传入trainingRegistration")
    public R save(@RequestBody TrainingRegistration trainingRegistration){
        //查询人员是否已报名
        User user = userService.getById(trainingRegistration.getUserId());
        User user = userService.getUserById(trainingRegistration.getUserId());
        if (null==user.getIsTrain()){
            //已报名
            trainingRegistration.setCancel(1);
@@ -181,7 +181,8 @@
    @PostMapping("/cancelTrain")
    public R cancelApply(@RequestBody TrainingRegistration trainingRegistration){
        //查询人员是否已报名
        User user = userService.getById(trainingRegistration.getUserId());
        User user = userService.getUserById(trainingRegistration.getUserId());
        if(null==user.getIsTrain()){
            trainingRegistration.setCancel(2);
            boolean status = trainingRegistrationService.updateById(trainingRegistration);
@@ -224,7 +225,7 @@
    @PostMapping("/auditSucess")
    public R auditSucess(@RequestBody TrainingRegistration trainingRegistration){
        //查询人员信息
        User user = userService.getById(trainingRegistration.getUserId());
        User user = userService.getUserById(trainingRegistration.getUserId());
        boolean status = false;
        if (null!=user){
            //修改为已报名状态
@@ -249,7 +250,7 @@
    @PostMapping("/cancelTrainAudit")
    public R cancelApplyAudit(@RequestBody TrainingRegistration trainingRegistration){
        //查询人员是否已报名
        User user = userService.getById(trainingRegistration.getUserId());
        User user = userService.getUserById(trainingRegistration.getUserId());
        if(null==user.getIsTrain()){
            trainingRegistration.setCancel(2);
            trainingRegistration.setAuditStatus(2);
@@ -315,7 +316,7 @@
//        AtomicReference<StringBuilder> builder = new AtomicReference<>(new StringBuilder());
        //遍历
        list.forEach(userId ->{
            User user = userService.getById(userId);
            User user = userService.getUserById(userId);
            UserVO userVO = userService.getUserAgeById(Long.parseLong(userId));
            //判断年龄
            if (userVO.getAge()>=18 && userVO.getAge()<=60) {
src/main/resources/application-test.yml
@@ -50,8 +50,8 @@
  jsonUrl: E:\\anbao\\
  username: root
  password: ZHba@0112
#  qfqkBaseApiUrl : http://192.168.0.198:83
  qfqkBaseApiUrl : http://223.82.109.183:2082/api
  qfqkBaseApiUrl : http://192.168.0.198:83
#  qfqkBaseApiUrl : http://223.82.109.183:2082/api
#第三方登陆
social: