yangys
2024-03-28 13ada1093cb8de6e31a718d2222429ded70133c8
smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/service/impl/InitServiceImpl.java
@@ -30,6 +30,7 @@
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.redis.cache.BladeRedis;
import com.qianwen.core.tool.api.ResultCode;
import com.qianwen.core.tool.utils.DigestUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.cps.enums.AppEnum;
@@ -42,6 +43,7 @@
import com.qianwen.smartman.modules.cps.vo.ConfigVO;
import com.qianwen.smartman.modules.cps.vo.InitSettingVO;
import com.qianwen.smartman.modules.system.dto.LicenseDetailDTO;
import com.qianwen.smartman.modules.system.entity.Application;
import com.qianwen.smartman.modules.system.service.IApplicationService;
import com.qianwen.smartman.modules.visual.entity.VisualConfig;
import com.qianwen.smartman.modules.visual.service.IVisualConfigService;
@@ -67,46 +69,6 @@
    private final ThreadPoolTaskExecutor taskExecutor;
    private final Environment environment;
    private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
        String implMethodName = lambda.getImplMethodName();
        boolean z = true;
        switch (implMethodName.hashCode()) {
            case -75622813:
                if (implMethodName.equals("getCode")) {
                    z = true;
                    break;
                }
                break;
            case 643007317:
                if (implMethodName.equals("getDomainUrl")) {
                    z = false;
                    break;
                }
                break;
        }
        switch (z) {
            case false:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/Application") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getDomainUrl();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/Application") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getCode();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/Application") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getCode();
                    };
                }
                break;
        }
        throw new IllegalArgumentException("Invalid lambda deserialization");
    }
    public InitServiceImpl(final InitMapper initMapper, final ConfigVO configVO, final TdengineMapper tdengineMapper, final DataSource dataSource, final IInitBusinessService initBusinessService, final BladeRedis bladeRedis, final IVisualConfigService visualConfigService, final IApplicationService applicationService, final ThreadPoolTaskExecutor taskExecutor, final Environment environment) {
        this.initMapper = initMapper;
@@ -151,48 +113,53 @@
    @Override // org.springblade.modules.cps.service.IInitService
    @Transactional(rollbackFor = {Exception.class})
    public Boolean initSystem(InitSettingVO initSettingVO) {
        if (!initSettingVO.getPassword().equals(initSettingVO.getConfirmPassword())) {
            throw new ServiceException(MessageUtils.message("init.system.inconsistent.password", new Object[0]));
        }
        initSettingVO.setPassword(DigestUtil.encrypt(initSettingVO.getPassword()));
        Connection conn = this.dataSource.getConnection();
        ScriptRunner runner = new ScriptRunner(conn);
        runner.setStopOnError(true);
        File file = new File(System.getProperty("java.io.tmpdir") + File.separator + "common.sql");
        FileUtils.copyToFile(new ClassPathResource("sql" + File.separator + this.configVO.getType() + File.separator + "common.sql").getInputStream(), file);
        runner.runScript(new FileReader(file));
        FileUtils.copyToFile(new ClassPathResource("sql" + File.separator + this.configVO.getType() + File.separator + "xxl_job.sql").getInputStream(), file);
        runner.runScript(new FileReader(file));
        List<Integer> appIds = (List) initSettingVO.getAppList().stream().sorted().collect(Collectors.toList());
        for (Integer appId : appIds) {
            Future<?> asyncResult = this.taskExecutor.submit(() -> {
                try {
                    this.initBusinessService.initApp(appId, this.configVO);
                } catch (Exception e) {
                    throw new ServiceException(e.getMessage());
                }
            });
            while (!asyncResult.isDone()) {
                TimeUnit.NANOSECONDS.sleep(2L);
            }
        }
        initAdapter(initSettingVO, this.configVO.getUrl(), this.configVO.getType());
        replaceJumuUrl();
        this.initMapper.replaceUrlJiMu(initSettingVO);
        if (CommonConstant.ORACLE.equals(this.configVO.getType()) && Func.isNotEmpty(initSettingVO.getAppList()) && initSettingVO.getAppList().contains(AppEnum.VISUAL.getCode())) {
            try {
                VisualConfig visualConfig = new VisualConfig();
                visualConfig.setId(1510135236368261122L);
                visualConfig.setVisualId(1510135236343095298L);
                visualConfig.setDetail(FileUtil.getFileString(new ClassPathResource("constant" + File.separator + "VisualDetail.txt")));
                visualConfig.setComponent(FileUtil.getFileString(new ClassPathResource("constant" + File.separator + "VisualComponent.txt")));
                this.visualConfigService.save(visualConfig);
            } catch (Exception e) {
                throw new ServiceException(e.getMessage());
            }
        }
        IoUtil.close(conn);
        return true;
       try {
           if (!initSettingVO.getPassword().equals(initSettingVO.getConfirmPassword())) {
               throw new ServiceException(MessageUtils.message("init.system.inconsistent.password", new Object[0]));
           }
           initSettingVO.setPassword(DigestUtil.encrypt(initSettingVO.getPassword()));
           Connection conn = this.dataSource.getConnection();
           ScriptRunner runner = new ScriptRunner(conn);
           runner.setStopOnError(true);
           File file = new File(System.getProperty("java.io.tmpdir") + File.separator + "common.sql");
           FileUtils.copyToFile(new ClassPathResource("sql" + File.separator + this.configVO.getType() + File.separator + "common.sql").getInputStream(), file);
           runner.runScript(new FileReader(file));
           FileUtils.copyToFile(new ClassPathResource("sql" + File.separator + this.configVO.getType() + File.separator + "xxl_job.sql").getInputStream(), file);
           runner.runScript(new FileReader(file));
           List<Integer> appIds = initSettingVO.getAppList().stream().sorted().collect(Collectors.toList());
           for (Integer appId : appIds) {
               Future<?> asyncResult = this.taskExecutor.submit(() -> {
                   try {
                       this.initBusinessService.initApp(appId, this.configVO);
                   } catch (Exception e) {
                       throw new ServiceException(e.getMessage());
                   }
               });
               while (!asyncResult.isDone()) {
                   TimeUnit.NANOSECONDS.sleep(2L);
               }
           }
           initAdapter(initSettingVO, this.configVO.getUrl(), this.configVO.getType());
           replaceJumuUrl();
           this.initMapper.replaceUrlJiMu(initSettingVO);
           if (CommonConstant.ORACLE.equals(this.configVO.getType()) && Func.isNotEmpty(initSettingVO.getAppList()) && initSettingVO.getAppList().contains(AppEnum.VISUAL.getCode())) {
               try {
                   VisualConfig visualConfig = new VisualConfig();
                   visualConfig.setId(1510135236368261122L);
                   visualConfig.setVisualId(1510135236343095298L);
                   visualConfig.setDetail(FileUtil.getFileString(new ClassPathResource("constant" + File.separator + "VisualDetail.txt")));
                   visualConfig.setComponent(FileUtil.getFileString(new ClassPathResource("constant" + File.separator + "VisualComponent.txt")));
                   this.visualConfigService.save(visualConfig);
               } catch (Exception e) {
                   throw new ServiceException(e.getMessage());
               }
           }
           IoUtil.close(conn);
           return true;
       }catch(Exception ex) {
          log.error("初始化系统失败",ex);
          throw new ServiceException(ResultCode.FAILURE,ex);
       }
    }
    @Override // org.springblade.modules.cps.service.IInitService
@@ -224,15 +191,16 @@
            List<String> list = new ArrayList<>();
            list.addAll(applicationCodes);
            list.add("HMI");
            this.applicationService.remove(Wrappers.<Application>lambdaQuery().notIn(Application::getCode, list));
            /*
            this.applicationService.remove((Wrapper) Wrappers.lambdaQuery().notIn((v0) -> {
                return v0.getCode();
            }, list));
            initSettingVO.getApplicationList().forEach(k, v -> {
                this.applicationService.update((Wrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().set((v0) -> {
                    return v0.getDomainUrl();
                }, v)).eq((v0) -> {
                    return v0.getCode();
                }, k));
            Application::getDomainUrl
            */
            initSettingVO.getApplicationList().forEach((k, v) -> {
                this.applicationService.update(Wrappers.<Application>lambdaUpdate().set(Application::getDomainUrl, v).eq(Application::getCode, k));
            });
        }
        System.setProperty("blade.system.need_init", FmsConstant.MANUAL);