package com.hzya.frame.grpU8.nxproof.oerdjml.controller;


import com.hzya.frame.grpU8.nxproof.oerdjml.entity.OerDjmlEntity;
import com.hzya.frame.grpU8.nxproof.oerdjml.service.IOerDjmlService;
import com.hzya.frame.web.action.DefaultController;
import com.hzya.frame.web.entity.JsonResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author:hecan
 * @Description:费用报销报销明细总
 * @params:
 * @return:
 * @Date: 2023/6/19 15:52
 */
@RequestMapping("/grp/api")
@Controller
public class OerDjmlController extends DefaultController {
    @Autowired
    private IOerDjmlService iOerDjmlService;

    /***
     * @Content:费用报销单发起保存
     * @Author 👻👻👻👻👻👻👻👻 gjh
     * @Date  2023-06-29 11:23
     * @Param [jsonObject]
     * @return java.lang.String
     **/
    /*@ResponseBody
    //@RequestMapping("/saveExpenseDocuments")
    public JsonResultEntity saveExpenseDocuments(@RequestBody JSONObject jsonObject){
        try {
            String result = null;//iOerDjmlService.saveExpenseDocuments(jsonObject);
            return getSuccessMessageEntity("报销单保存成功","报销单保存","报销单单据编号为："+result);
        }catch (Exception e){
           *//* String message="";
            if(e instanceof BaseSystemException){
                message=e.getMessage();
            }*//*
            return getFailureMessageEntity("报销单保存失败，错误原因为:"+e.getMessage(),"报销单保存");
        }

    }*/

    @ResponseBody
    @RequestMapping("/queryOerDjmlEntity")
    public JsonResultEntity test(@RequestBody OerDjmlEntity oerDjmlEntity) throws Exception{
        OerDjmlEntity oerDjmlEntity1 = iOerDjmlService.queryOerDjmlEntity(oerDjmlEntity);
        logger.info("查询出来的Rpt_Rt_content只为:{}",oerDjmlEntity1.getRptRtContent());
        String str=new String(oerDjmlEntity1.getRptRtContent(),"ISO-8859-1");
        /*try {

            // 将byte[]转换成InputStream
            ByteArrayInputStream bais = new ByteArrayInputStream(oerDjmlEntity1.getRptRtContent());

            // 创建ZipInputStream
            ZipInputStream zis = new ZipInputStream(bais);

            // 获取第一个条目
            ZipEntry entry = zis.getNextEntry();

            if (entry != null) {
                // 创建一个新的ByteArrayOutputStream来存储解压缩后的数据
                ByteArrayOutputStream baos = new ByteArrayOutputStream();

                byte[] buffer = new byte[1024];
                int len;

                // 读取解压缩的数据并写入ByteArrayOutputStream
                while ((len = zis.read(buffer)) > 0) {
                    baos.write(buffer, 0, len);
                }

                // 关闭资源
                zis.closeEntry();
                zis.close();
                bais.close();

                // 将解压缩后的数据转换成字符串
                String decompressedString = new String(baos.toByteArray(), "UTF-8");

                System.out.println("Decompressed String: " + decompressedString);
            } else {
                System.out.println("No entries found in the ZIP data.");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }*/

       /* String outputImagePath = "C:\\Users\\笃曙\\Desktop\\项目相关\\南浔卫生局\\image.png"; // 输出图片路径

        try (FileOutputStream fos = new FileOutputStream(outputImagePath)) {
            fos.write(oerDjmlEntity1.getRptRtContent());
            logger.info("图片路径:{}",outputImagePath);
        } catch (IOException e) {
            e.printStackTrace();
        }*/



       /* byte[] data = oerDjmlEntity1.getRptRtContent();
        File file = new File("C:\\Users\\笃曙\\Desktop\\项目相关\\南浔卫生局\\IMG_20181213_154235.png"); // 要写入的文件
        try (FileOutputStream fos = new FileOutputStream(file)) {
            fos.write(data); // 将字节数组写入文件
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("File saved successfully.");*/


        logger.info("转换之后的值：{}",str);

        return getFailureMessageEntity("成功",str);
    }


}
