package com.example.sjkbf.controller;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.FileReader;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.log.StaticLog;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.sjkbf.common.FileManage;
import com.example.sjkbf.entity.CommonResult;
import com.example.sjkbf.entity.DPSScriptJson;
import com.example.sjkbf.entity.User;
import com.example.sjkbf.entity.UserServerProject;
import com.example.sjkbf.entity.projectconfig.ProjectConfig;
import com.example.sjkbf.service.ProjectPerService;
import com.example.sjkbf.service.UserServerProjectService;
import com.example.sjkbf.service.UserService;
import com.example.sjkbf.service.impl.ProjectPerServiceImpl;
import com.example.sjkbf.util.RSATooL;
import com.example.sjkbf.util.SimpleNutZipCompatible;
import com.example.sjkbf.util.tool;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;

@RestController
@RequestMapping("/script")
public class verifyController {

    @Autowired
    private UserServerProjectService userServerProjectService;

    @Autowired
    private ProjectPerService projectPerService;

    @Autowired
    private FileManage fileManage;

    @Autowired
    private UserService userService;


    public static Map<String,String> ipAndMac=new HashMap<>();



    @RequestMapping("client")
    public ResponseEntity<String> client(String ip,String clientKey,String ve) {

        if (ve == null )ve = "1.0";
        System.out.println( ve);
        StaticLog.info(ip+" client 客户端 请求验证");

        List<UserServerProject> getpro=new ArrayList<>();
//        if (ip.equals("192.168.200.131")){
//            User clientKey1 = userService.getOne(new QueryWrapper<User>().eq("client_key", clientKey));
//
//            getpro = userServerProjectService.getByUserName(clientKey1.getName());
//
//        }else {

            getpro = userServerProjectService.getproAndOpen(ip);
//        }

        int[] key = new int[20];
        StringBuilder keys= new StringBuilder();
        for (int i = 0; i < 20; i++) {
            key[i]=(RandomUtil.randomInt(1, 9));
            keys.append(key[i]);
        }




        List<String> BaseScriptStr = projectPerService.getBaseScriptStrEncrypt(key,ve);


        //如果项目里有cs 就发测试base
        for (UserServerProject userServerProject : getpro) {
            if (userServerProject.getProjectName().equals("cs")){
                BaseScriptStr = projectPerService.getCSBaseScriptStrEncrypt(key,ve);
                break;
            }
        }

        if (!getpro.isEmpty()) {
            for (UserServerProject userServerProject : getpro) {
                String projectName = userServerProject.getProjectName();
                if (projectName.equals("cs"))continue;

                List<String> projectScriptStrEncrypt = projectPerService.getProjectScriptStrEncrypt(projectName, key,ve);
                BaseScriptStr.addAll(projectScriptStrEncrypt);
                System.out.println(projectName + "  加载" + projectScriptStrEncrypt.size() + "个文件");

            }
        }

        System.out.println(BaseScriptStr.size());
        List<String> projectScriptStrEncrypt = projectPerService.getzdy(ip, key,ve);
        if (!projectScriptStrEncrypt.isEmpty()) {
            BaseScriptStr.addAll(projectScriptStrEncrypt);
            System.out.println("加载自定义脚本" + projectScriptStrEncrypt.size() + "个文件");
        }


        System.out.println(BaseScriptStr.size());


        StringBuilder stringBuilder = new StringBuilder();
        for (String s : BaseScriptStr) {


            stringBuilder.append(s);
            stringBuilder.append("$$$$$");
        }




        JSONObject json = new JSONObject();
        json.set("getBaseScriptStr",stringBuilder.toString());
        json.set("key", RSATooL.encryption(keys.toString()));
        String string = json.toString();
        String compress = RSATooL.compress(string);


        return ResponseEntity.ok(compress);
    }


    @RequestMapping("getzdy")
    public String getzdy( HttpServletRequest request,String ve) {
        String ipAddress = request.getRemoteAddr();
        // 如果应用部署在反向代理或负载均衡器后面，可以通过X-Forwarded-For头部获取真实IP地址
        String forwardedFor = request.getHeader("X-Forwarded-For");
        if (forwardedFor != null && !forwardedFor.isEmpty()) {
            ipAddress = forwardedFor.split(",")[0];
        }


        System.out.println(ipAddress + "请求自定义脚本");

        List<String> projectScriptStrEncrypt = projectPerService.getzdy2(ipAddress,ve);
        if (!projectScriptStrEncrypt.isEmpty()) {
            System.out.println("加载自定义脚本" + projectScriptStrEncrypt.size() + "个文件");
        }else {
            return "";
        }


//        StringBuilder stringBuilder = new StringBuilder();
//        for (String s : projectScriptStrEncrypt) {
//
//
//            stringBuilder.append(s);
//            stringBuilder.append("$$$$$");
//        }

        JSONObject json = new JSONObject();
        json.set("getBaseScriptStr",projectScriptStrEncrypt);
        String string = json.toString();

//        String compress = RSATooL.compress(string);//压缩


        return string;
    }


    @RequestMapping("client2")
    public ResponseEntity<Map<String, Object>> client2(String ip,String clientKey,String ve) {
        System.out.println( ve);
        StaticLog.info(ip+"client2 客户端 请求验证");

        List<UserServerProject> getpro=new ArrayList<>();
//        if (ip.equals("192.168.200.131")){
//            User clientKey1 = userService.getOne(new QueryWrapper<User>().eq("client_key", clientKey));
//
//            getpro = userServerProjectService.getByUserName(clientKey1.getName());
//
//        }else {

        getpro = userServerProjectService.getproAndOpen(ip);
//        }

        int[] key = new int[20];
        StringBuilder keys= new StringBuilder();
        for (int i = 0; i < 20; i++) {
            key[i]=(RandomUtil.randomInt(1, 9));
            keys.append(key[i]);
        }

        List<byte[]> BaseScriptStr = projectPerService.getBaseScriptStrEncrypt2(key,ve);

        if (!getpro.isEmpty()) {
            for (UserServerProject userServerProject : getpro) {
                String projectName = userServerProject.getProjectName();
                List<byte[]> projectScriptStrEncrypt = projectPerService.getProjectScriptStrEncrypt2(projectName, key,ve);
                BaseScriptStr.addAll(projectScriptStrEncrypt);
                System.out.println(projectName + "  加载" + projectScriptStrEncrypt.size() + "个文件");
            }
        }


        Map<String, Object> map = new HashMap<>();

        map.put("getBaseScriptStr",BaseScriptStr);
        map.put("key",RSATooL.encryption(keys.toString()));

        return ResponseEntity.ok(map);
    }




    /**
     * 服务端验证
     */
    @PostMapping("getpro")
    public String getpro(HttpServletRequest request, String prot, Long l, String mac, String s){

        String ipAddress = tool.getIpAddress(request);

        long time = DateUtil.date().getTime();

        StaticLog.info(ipAddress+"服务端 请求验证");

        if (Math.abs(time - l)>1000*60*5||mac==null||mac.isEmpty()||prot==null||prot.isEmpty()){

            StaticLog.info(ipAddress+"服务端 请求验证失败");
            StaticLog.info(String.valueOf(Math.abs(time - l)>1000*60*5));
            StaticLog.info(String.valueOf(mac==null||mac.isEmpty()));
            StaticLog.info(String.valueOf(prot==null||prot.isEmpty()));

            return null;
        }

        String s1 = ipAndMac.get(ipAddress);

        if (s1==null||s1.isEmpty()){
            ipAndMac.put(ipAddress,mac);
            s1 = mac;
        }
        if (!s1.equals(mac)){
            //不同的md5值 记录日志
            StaticLog.error("md5值和之前不相同 :" + ipAddress);
        }

        List<UserServerProject> getpro = userServerProjectService.getproAndOpen(ipAddress);
        if (getpro.isEmpty()) {
            StaticLog.error("验证错误" + ipAddress);
            return null;
        }
        StringBuilder pro = new StringBuilder();
        for (UserServerProject userServerProject : getpro) {
            pro.append(userServerProject.getProjectName()).append(",");
        }
        Map<String,Object> body=new HashMap<>();
        body.put("pro", pro.toString());
        body.put("validate",time);
        body.put("ce",s);
        //生成一个唯一的id 作为穿给中间件的验证值 存到redis 中
        String key = IdUtil.simpleUUID();
        body.put("key",key);
        body.put("ip",ipAddress);


        StaticLog.info(ipAddress+"服务端 通过验证");
        String jsonStr = JSONUtil.toJsonStr(body);
        return tool.encryption(jsonStr);
    }


    @RequestMapping("getservice")
    public ResponseEntity<String> getservice( HttpServletRequest request,String ser) throws IOException {
        StaticLog.info("收到服务器的getservice2请求脚本");

        // 获取客户端IP地址
        String ipAddress = request.getRemoteAddr();

        // 如果应用部署在反向代理或负载均衡器后面，可以通过X-Forwarded-For头部获取真实IP地址
        String forwardedFor = request.getHeader("X-Forwarded-For");
        if (forwardedFor != null && !forwardedFor.isEmpty()) {
            ipAddress = forwardedFor.split(",")[0];
        }




        int[] intArray1 = new int[20];
        StringBuilder keys= new StringBuilder();
        for (int i = 0; i < 20; i++) {
            intArray1[i]=(RandomUtil.randomInt(1, 9));
            keys.append(intArray1[i]);
        }


        //项目map
        Map<String, byte[]> stringStringMap=new HashMap<>();
        List<String> stringStringMapSX=new ArrayList<>();


        List<UserServerProject> getpro = userServerProjectService.getproAndOpen(ipAddress);
        

        if (getpro.isEmpty()) {
            //把通用的数据线丢到map中
            List<String> strings333 = FileUtil.readUtf8Lines(fileManage.getDpsScriptfile()+"base2/config");
            for (String s : strings333) {
                File file2 = FileUtil.file(fileManage.getDpsScriptfile()+"base2/" + s);
                FileReader fileReader1 = new FileReader(fileManage.getDpsScriptfile()+"base2/" + s);

                stringStringMap.put(fileManage.getDpsScriptfile()+"base2/" + s, fileReader1.readString().getBytes());
                stringStringMapSX.add(fileManage.getDpsScriptfile()+"base2/" + s);
            }

           System.out.println("通过了 没买插件的验证");

        }else {

            if (ipAddress .equals("112.12.194.152") || ipAddress .equals("202.189.14.166") || ipAddress .equals("45.125.44.2") || ipAddress .equals("110.42.110.159")|| ipAddress .equals("202.189.14.111")){
                //把通用的数据线丢到map中
                List<String> strings333 = FileUtil.readUtf8Lines(fileManage.getDpsScriptfile()+"" +
                        "" +
                        "base3/config");
                for (String s : strings333) {
                    File file2 = FileUtil.file(fileManage.getDpsScriptfile()+"base3/" + s);
                    FileReader fileReader1 = new FileReader(file2);

                    stringStringMap.put(fileManage.getDpsScriptfile()+"base3/" + s, fileReader1 .readString().getBytes());
                    stringStringMapSX.add(fileManage.getDpsScriptfile()+"base3/" + s);
                }
            }else {
                //把通用的数据线丢到map中
                List<String> strings333 = FileUtil.readUtf8Lines(fileManage.getDpsScriptfile()+"base/config");
                for (String s : strings333) {
                    File file2 = FileUtil.file(fileManage.getDpsScriptfile()+"base/" + s);
                    FileReader fileReader1 = new FileReader(file2);

                    stringStringMap.put(fileManage.getDpsScriptfile()+"base/" + s, fileReader1 .readString().getBytes());
                    stringStringMapSX.add(fileManage.getDpsScriptfile()+"base/" + s);
                }

            }


            //从数据库找到所有的插件
            for (UserServerProject user2 : getpro) {
                String chajian = user2.getProjectName();

                String s1 = fileManage.getDpsScriptfile() + "project/" + chajian;
                Path path = Paths.get(s1);
                //根据插件获得服务器的插件路径 然后以路径为key 里面的值为v 存入到map中 之后加密返回
                if (Files.exists(path)) {
                    List<String> strings444 = FileUtil.readUtf8Lines(s1 + "/config");
                    for (String s : strings444) {
                        File file2 = FileUtil.file(s1 + "/" + s);
                        FileReader fileReader1 = new FileReader(file2);
                        stringStringMap.put(s1 + "/" + s, fileReader1.readString().getBytes());
                        stringStringMapSX.add(s1 + "/" + s);
                    }
                }
            }

            File file2 = FileUtil.file(fileManage.getDpsScriptfile() + "user/通用/main.nut");
            FileReader fileReader1 = new FileReader(file2);
            stringStringMap.put(fileManage.getDpsScriptfile() + "user/通用/main.nut", fileReader1.readString().getBytes());
            stringStringMapSX.add(fileManage.getDpsScriptfile() + "user/通用/main.nut");
        }

        if (ipAddress .equals("112.12.194.152") || ipAddress .equals("202.189.14.166") || ipAddress .equals("45.125.44.2") || ipAddress .equals("110.42.110.159")|| ipAddress .equals("202.189.14.111")){
            for (String stringMapSX : stringStringMapSX) {
                System.out.println(stringMapSX);
            }
        }


        //以下代码为从/root/rindro/dpsScript/user/ 目录中加载自定义的服务端脚本
        String s1 = fileManage.getDpsScriptfile() + "user/" + ipAddress;
        Path path = Paths.get(s1);
        if (Files.exists(path)) {
            List<String> strings444 = FileUtil.readUtf8Lines(s1 + "/config");
            for (String s : strings444) {
                File file2 = FileUtil.file(s1 + "/" + s);
                FileReader fileReader1 = new FileReader(file2);
                stringStringMap.put(s1 + "/" + s, fileReader1.readString().getBytes());
                stringStringMapSX.add(s1 + "/" + s);
            }
        }


//        Map<String, byte[]> stringStringMapUser=new HashMap<>();
//        List<String> stringStringMapUserSX=new ArrayList<>();

//        try {
//            List<String> strings2222 = FileUtil.readUtf8Lines("/root/rindro/user/"+ipAddress + "/serConfig");
//
//            for (String s : strings2222) {
//                File file2 = FileUtil.file("/root/rindro/user/"+ipAddress + "/"+s);
//                FileReader fileReader = new FileReader(file2);
//                byte[] bytes = fileReader.readBytes();
//                stringStringMapUser.put("/root/rindro/user/"+ipAddress + "/"+s,bytes);
//                stringStringMapUserSX.add("/root/rindro/user/"+ipAddress + "/"+s);
//            }
//        }catch (Exception e){
//            System.out.println("未找到userip文件，外部用户请求");
//        }



//        对通用文件进行加密处理
        for (Map.Entry<String, byte[]> entry : stringStringMap.entrySet()) {
            byte[] encryptedValue = RSATooL.Makecode(entry.getValue(), intArray1);
            entry.setValue(encryptedValue); // 直接在Map中更新值
        }


//        //对用户文件进行加密处理
//        for (Map.Entry<String, byte[]> entry : stringStringMapUser.entrySet()) {
//            byte[] encryptedValue = Main.Makecode(entry.getValue(), intArray1);
//            entry.setValue(encryptedValue); // 直接在Map中更新值
//        }


        StringBuilder sb=new StringBuilder();
        for (String string : stringStringMapSX) {
            sb.append(string);
            sb.append("$$$$$");
            String string1 = Arrays.toString(stringStringMap.get(string));

            sb.append(string1, 1, string1.length()-1);

            sb.append("$$$$$");
        }

//        for (String string : stringStringMapUserSX) {
//            sb.append(string);
//            sb.append("$$$$");
//            sb.append(Arrays.toString(stringStringMapUser.get(string)));
//            sb.append("$$$$");
//        }
        String substring = sb.toString();
        StaticLog.info(ipAddress+"通过验证 返回dps nut脚本");
        JSONObject json = new JSONObject();
        
        json.set("getBaseScriptStr",substring);
        json.set("key",RSATooL.encryption(keys.toString()));
        String string = json.toString();
        String compress = RSATooL.compress(string);

        return ResponseEntity.ok(compress);
    }

    Map<String,JSONObject> jsonObject=new HashMap<>();
    @RequestMapping ("getBaseUpdateTime")
    public ResponseEntity<String> getBaseUpdateTime(String ve) {


        if (ve == null) ve = "1.0";

        // 1. 构建 base 目录路径（避免硬编码拼接，用 File 构造方法更安全）
        String baseDirPath = fileManage.getFile() + "/DP-S_Script/Script"+ve+"/_DPS_";
        File baseDir = new File(baseDirPath);

        // 2. 校验目录合法性（不存在/不是目录直接返回 0）
        if (!baseDir.exists() || !baseDir.isDirectory()) {
            return ResponseEntity.ok("0");
        }

        // 3. 递归遍历所有文件，获取最新修改时间
        long latestModifyTime = traverseAllFiles(baseDir);

        // 4. 返回结果（时间戳转字符串）
        return ResponseEntity.ok(String.valueOf(latestModifyTime));
    }


    @RequestMapping("getBaseSutZip")
    public ResponseEntity<Object> getBaseSut(HttpServletRequest request,@RequestParam(value = "ve", required = false) String ve) {
        nut_sut(ve);


        String file =  fileManage.getFile() +"sut.tar.gz";

        Path baseDir = Paths.get(file).toAbsolutePath().normalize();
        Resource resource = new FileSystemResource(baseDir);

        // 设置响应头
        HttpHeaders headers = new HttpHeaders();
        headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "\"");

        // 返回包含文件资源的通用结果
        return ResponseEntity.ok()
                .header("Content-Disposition",
                        "attachment; filename=\"" + resource.getFilename() + "\"")
                .body(resource);
    }

    Map<String,Long> updateTime=new HashMap<>();


    public void nut_sut(String bb) {
        if (bb ==null) bb = "1.0";
        String baseDirPath = fileManage.getFile() + "/DP-S_Script/Script"+bb+"/_DPS_";
        File baseDir = new File(baseDirPath);
        long latestModifyTime = traverseAllFiles(baseDir);

        System.out.println("最新修改时间：" + latestModifyTime);
        System.out.println("updateTime：" + updateTime.get(bb));
        if (  updateTime.get(bb) == null || latestModifyTime > updateTime.get(bb)){
            //重新加密压缩

            String targetPath = fileManage.getFile()+"sut.tar.gz";
            String key = "Rindro-Aurora";
            SimpleNutZipCompatible.encryptAndZip(baseDirPath, targetPath, key);


            updateTime.put(bb,traverseAllFiles(baseDir));


            FileReader fileReader = new FileReader(fileManage.getFile() + "/DP-S_Script/Script"+bb+"/_DPS_" + "/FileConfig.json");
            String result5 = fileReader.readString();
            //转json
            JSONObject jsonObject1 = new JSONObject(result5);
            jsonObject.put(bb,jsonObject1);
        }
    }



    @RequestMapping("getservicenew")
    public ResponseEntity<String> getservicenew( HttpServletRequest request,String ser,String ve) throws IOException {


        if (ve == null ){
            ve = request.getHeader("ve");
            if ( ve == null) {
                StaticLog.info("版本 为空");
                ve = "1.0";
            }
        }

        // 获取客户端IP地址
        String ipAddress = request.getRemoteAddr();



        // 如果应用部署在反向代理或负载均衡器后面，可以通过X-Forwarded-For头部获取真实IP地址
        String forwardedFor = request.getHeader("X-Forwarded-For");
        if (forwardedFor != null && !forwardedFor.isEmpty()) {
            ipAddress = forwardedFor.split(",")[0];
        }
        StaticLog.info("收到服务器"+ipAddress+" 的getservicenew请求脚本 当前版本" +  ve);



        int[] intArray1 = new int[20];
        StringBuilder keys= new StringBuilder();
        for (int i = 0; i < 20; i++) {
            intArray1[i]=(RandomUtil.randomInt(1, 9));
            keys.append(intArray1[i]);
        }


        //项目map
        Map<String, byte[]> stringStringMap=new HashMap<>();
        List<String> stringStringMapSX=new ArrayList<>();


        List<UserServerProject> getpro = userServerProjectService.getproAndOpen(ipAddress);


        if (getpro.isEmpty()) {

            return ResponseEntity.ok("没有项目");

        }else {



            //从数据库找到所有的插件
            for (UserServerProject user2 : getpro) {
                String chajian = user2.getProjectName();
                if (jsonObject.get(ve) ==null){
                    nut_sut(ve);
                    System.out.println(jsonObject.get(ve));
                }

                DPSScriptJson bean = jsonObject.get(ve).toBean(DPSScriptJson.class);
                DPSScriptJson.ProjectScriptItem projectScriptItem = bean.getProjectScript().get(chajian);
                if (projectScriptItem == null) {

                    StaticLog.info("版本"  + ve);
                    StaticLog.info("没有项目"  + chajian);
                    continue;
                }
                for (String s : projectScriptItem.getScript()) {

                    String s1 = fileManage.getFile() + "/DP-S_Script/Script"+ve+"/_DPS_" + "/_BuiltProject/" + s;


                    File file2 = FileUtil.file(s1 );
                    FileReader fileReader1 = new FileReader(file2);
                    stringStringMap.put(s1 , fileReader1.readString().getBytes());
                    stringStringMapSX.add(s1 );

                }
                StaticLog.info("加入" +chajian +"插件");

            }

//            File file2 = FileUtil.file(fileManage.getDpsScriptfile() + "user/通用/main.nut");
//            FileReader fileReader1 = new FileReader(file2);
//            stringStringMap.put(fileManage.getDpsScriptfile() + "user/通用/main.nut", fileReader1.readString().getBytes());
//            stringStringMapSX.add(fileManage.getDpsScriptfile() + "user/通用/main.nut");
        }



        //以下代码为从/root/rindro/dpsScript/user/ 目录中加载自定义的服务端脚本
        String s1 = fileManage.getDpsScriptfile() + "user/" + ipAddress;
        Path path = Paths.get(s1);
        if (Files.exists(path)) {
            List<String> strings444 = FileUtil.readUtf8Lines(s1 + "/config");
            for (String s : strings444) {
                File file2 = FileUtil.file(s1 + "/" + s);
                FileReader fileReader1 = new FileReader(file2);
                stringStringMap.put(s1 + "/" + s, fileReader1.readString().getBytes());
                stringStringMapSX.add(s1 + "/" + s);
            }
        }




//        对通用文件进行加密处理
        for (Map.Entry<String, byte[]> entry : stringStringMap.entrySet()) {
            byte[] encryptedValue = RSATooL.Makecode(entry.getValue(), intArray1);
            entry.setValue(encryptedValue); // 直接在Map中更新值
        }



        StringBuilder sb=new StringBuilder();
        for (String string : stringStringMapSX) {
            sb.append(string);
            sb.append("$$$$$");
            String string1 = Arrays.toString(stringStringMap.get(string));

            sb.append(string1, 1, string1.length()-1);

            sb.append("$$$$$");
        }


        String substring = sb.toString();
        StaticLog.info(ipAddress+"通过验证 返回dps nut脚本");
        JSONObject json = new JSONObject();

        json.set("getBaseScriptStr",substring);
        json.set("key",RSATooL.encryption(keys.toString()));
        String string = json.toString();
        String compress = RSATooL.compress(string);

        return ResponseEntity.ok(compress);
    }



    /**
     * 递归遍历目录下所有文件（含所有层级子目录），返回最新修改时间
     * @param dir 要遍历的目录
     * @return 最新文件修改时间（毫秒级时间戳），无文件时返回 0
     */
    private long traverseAllFiles(File dir) {
        long latestTime = 0;
        // 用原生 listFiles() 替代 FileUtil.ls，减少第三方依赖，同时处理 null 情况
        File[] files = dir.listFiles();
        if (files == null) {
            return latestTime; // 目录无权限访问或异常，返回当前最新时间
        }

        for (File file : files) {
            if (file.isDirectory()) {
                // 递归遍历子目录
                latestTime = Math.max(latestTime, traverseAllFiles(file));
            } else {
                // 对比文件修改时间，更新最新时间
                latestTime = Math.max(latestTime, file.lastModified());
            }
        }
        return latestTime;
    }


    public static void main(String[] args) {
//        String decompress = RSATooL.encryption("https://dps-ma.senzo.online");
//            System.out.println(decompress);

        System.out.println((3860+1730 -150-180-240-(40+37+94+20)) *0.7)  ;

        System.out.println(3380 -100 -381-850-60-50-100-400-100-40-150-250-175 -100);
    }


}
