package com.cf.imes.module.manage.controller.admin.test;

import com.cf.imes.framework.common.util.json.JsonUtils;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.module.manage.controller.admin.patching.vo.PatchingDetailRespVO;
import com.cf.imes.module.manage.controller.admin.patching.vo.PatchingPlateRespVO;
import com.cf.imes.module.manage.dal.dataobject.process.OrderProcessStepItemNDO;
import com.cf.imes.module.manage.dal.mysql.plate.OrderPlateMapper;
import com.cf.imes.module.manage.dal.mysql.process.ProcessStepItemMapper;
import com.cf.imes.module.manage.dal.mysql.test.TestMapper;
import com.jacob.com.ComThread;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import org.jetbrains.annotations.TestOnly;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.sound.sampled.AudioInputStream;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

import javax.sound.sampled.*;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import java.net.Socket;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.IOException;
import java.util.Random;


/**
 * @author there
 * 测试 controller
 */
@RestController
@RequestMapping("/manage/test")
@Tag(name = "测试")
public class TestController {

    @Resource
    private TestMapper testMapper;




    @GetMapping("/get")
    @PermitAll
    @Operation(summary = "测试")
    public Object get() {
        return testMapper.selectList();
    }


    public class JacobTestController {
        /*        *
         * 语音转文字并播放
         *
         * @param text
         */
        private static void convertTextToSpeech(String text) {


            try {

                //jacob.dll没成功安装，执行这一步会出错
                //构建音频格式 调用注册表应用
                Dispatch spAudioFormat = new ActiveXComponent("Sapi.SpAudioFormat").getObject();
                //音频文件输出流
                Dispatch spFileStream = new ActiveXComponent("Sapi.SpFileStream").getObject();
                //构建音频对象
                Dispatch spVoice = new ActiveXComponent("Sapi.SpVoice").getObject();

                //设置spAudioFormat音频流格式类型22
                Dispatch.put(spAudioFormat, "Type", new Variant(22));
                //设置spFileStream文件输出流的音频格式
                Dispatch.putRef(spFileStream, "Format", spAudioFormat);

                //设置spFileStream文件输出流参数地址等
                Dispatch.call(spFileStream, "Open", new Variant("E:AAAAA\48641486.wav"), new Variant(3), new Variant(true));
                //设置spVoice声音对象的音频输出流为输出文件对象
                Dispatch.putRef(spVoice, "AudioOutputStream", spFileStream);
                //设置spVoice声音对象的音量大小100
                Dispatch.put(spVoice, "Volume", new Variant(100));
                //设置spVoice声音对象的速度 0为正常速度，范围【..-2 -1 0 1 2..】
                Dispatch.put(spVoice, "Rate", new Variant(0));
                //设置spVoice声音对象中的文本内容
                Dispatch.call(spVoice, "Speak", new Variant(text));
                //关闭spFileStream输出文件
                Dispatch.call(spFileStream, "Close");

                //释放资源
                spVoice.safeRelease();
                spAudioFormat.safeRelease();
                spFileStream.safeRelease();

            } catch (Exception e) {
                System.out.println(e.getMessage());

            }
        }

       /* private static XxlJobProperties aabb(){

            XxlJobParameter xxlJobParameter = new XxlJobParameter();

            xxlJobParameter.setEnabled(false);
            xxlJobParameter.setAccessToken("1122");
            xxlJobParameter.setAddresses("五阿里乌");
            xxlJobParameter.setAppName("aaappn");
            XxlJobProperties bean = BeanUtils.toBean(xxlJobParameter, XxlJobProperties.class);
            return bean;

        }*/

    }


    public static void deleteFiles(List<String> filePaths) {
        // 检查文件路径集合是否为空
        if (filePaths == null || filePaths.isEmpty()) {
            System.out.println("文件路径集合为空");
            return;
        }

        for (String filePath : filePaths) {
            // 检查文件路径是否为空
            if (filePath == null || filePath.isEmpty()) {
                System.out.println("文件路径为空");
                continue;
            }

            File file = new File(filePath);

            // 检查文件是否存在
            if (!file.exists()) {
                System.out.println("文件不存在：" + filePath);
                continue;
            }

            // 检查是否是文件
            if (!file.isFile()) {
                System.out.println("路径指向的不是文件：" + filePath);
                continue;
            }

            // 尝试删除文件
            if (file.delete()) {
                System.out.println("文件删除成功：" + filePath);
            } else {
                System.out.println("文件删除失败：" + filePath);
            }
        }
    }


    public  static Integer  aacc(){

        RedisTemplate<Object, Object> re = new RedisTemplate<>();

        int randomInt = new Random(System.currentTimeMillis()).nextInt(900) + 100;// 生成100到999之间的随机数



        return randomInt;

    }



        @TestOnly
        public static void main(String[] args) {





        }


}












