当前位置:   article > 正文

使用postman,将excel中的车辆及电池信息,按照PDF附件中,第6大项拼装电池静态信息,发送给PDF附件中的地址_postman调用返回pdf

postman调用返回pdf

思路:

解析excel,读取vin,利用demo json用在线工具生成实体类,组装成一个集合,序列化输出到txt文件中。

程序:

package com.mtons.mblog.reach;




import com.alibaba.fastjson.JSON;
import com.mtons.mblog.BootApplication;
import com.mtons.mblog.base.utils.BeanParseException;
import com.mtons.mblog.base.utils.ExcelUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = BootApplication.class)
@Slf4j
public class TestCalc {

    /**
     * 可以用来读取数据
     * @throws IOException
     * @throws
     */
    @Test
    public void testAtMethod() throws IOException, BeanParseException {
        try {
            Root root = new Root();
            List<BatteryDataDTOList> batteryDataDTOSet = new ArrayList<>();
            //BatteryDataDTOList batteryDataDTOList = new BatteryDataDTOList();
            //把读到的数据写到这个文件中
            //E:\xxx 没有这个文件夹会报错
            PrintStream out = new PrintStream("D:\\reach\\reach.txt");
            //一下代码所有的system.out.println() 输出到xxx.txt文件中
            System.setOut(out);
            //文件夹路径      excel文件
            String[][] strings = ExcelUtil.readFromFile(new File("D:\\yyyy", "vin_import.xlsx"), 9, 2000);
            //r是行数
            for (int r = 1; r < strings.length; r++) {
                //这里0 1 2 列数
                //vin
                String vin = strings[r][0];
                //电池包编码
                String batteryPackageCode = strings[r][1];
                //电池模块编码
                String batteryModuleCode = strings[r][2];
                //电池单体编码 电蕊编码
                String batteryCellCode = strings[r][3];
                BatteryDataDTOList batteryDataDTOList = new BatteryDataDTOList();
                batteryDataDTOList.setVin(vin);
                batteryDataDTOList.setBatteryPackageCode(batteryPackageCode);
                batteryDataDTOList.setBatteryModuleCode(batteryModuleCode);
                batteryDataDTOList.setBatteryCellCode(batteryCellCode);
                batteryDataDTOList.setBatteryType("4");
                batteryDataDTOList.setBatteryCodeType("1");
                batteryDataDTOList.setBatteryPackageCompany("江苏时代新能源科技有限公司");
                batteryDataDTOList.setBatteryPackageVoltage("346");
                batteryDataDTOList.setBatteryPackageCapacity("177");
                if(vin.equals("LHGJ11882M8000015")){
                    batteryDataDTOList.setBatteryPackageDate("2020-04-23");
                }else if(vin.equals("LHGJ11886M8000020")){
                    batteryDataDTOList.setBatteryPackageDate("2020-05-09");
                }else if(vin.equals("LHGJ1188XM8000019")){
                    batteryDataDTOList.setBatteryPackageDate("2020-04-22");
                }else if(vin.equals("LHGJ11880M8000028")){
                    batteryDataDTOList.setBatteryPackageDate("2020-06-07");
                }else if(vin.equals("LHGJ11882M8000029")){
                    batteryDataDTOList.setBatteryPackageDate("2020-06-07");
                }

                batteryDataDTOList.setBatteryModuleVoltage("14.44");
                batteryDataDTOList.setBatteryModuleCapacity("177");
                batteryDataDTOList.setBatteryCellCompany("江苏时代新能源科技有限公司");
                batteryDataDTOList.setBatteryCellVoltage("3.61");
                batteryDataDTOList.setBatteryCellCapacity("177");
                batteryDataDTOSet.add(batteryDataDTOList);
            }
            root.setBatteryDataDTOList(batteryDataDTOSet);
            System.out.println(JSON.toJSONString(root));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws IOException, BeanParseException {
        new TestCalc().testAtMethod();
    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96

输出(部分数据):

{
	"batteryDataDTOList": [{
		"batteryCellCapacity": "177",
		"batteryCellCode": "001CE280000002A4W0702153",
		"batteryCellCompany": "江苏时代新能源科技有限公司",
		"batteryCellVoltage": "3.61",
		"batteryCodeType": "1",
		"batteryModuleCapacity": "177",
		"batteryModuleCode": "001MEAHA000002A660000028",
		"batteryModuleVoltage": "14.44",
		"batteryPackageCapacity": "177",
		"batteryPackageCode": "001PEAEF000002A670300002",
		"batteryPackageCompany": "江苏时代新能源科技有限公司",
		"batteryPackageDate": "2020-06-07",
		"batteryPackageVoltage": "346",
		"batteryType": "4",
		"vin": "LHGJ11880M8000028"
	}, {
		"batteryCellCapacity": "177",
		"batteryCellCode": "001CE280000002A4W0702058",
		"batteryCellCompany": "江苏时代新能源科技有限公司",
		"batteryCellVoltage": "3.61",
		"batteryCodeType": "1",
		"batteryModuleCapacity": "177",
		"batteryModuleCode": "001MEAHA000002A660000028",
		"batteryModuleVoltage": "14.44",
		"batteryPackageCapacity": "177",
		"batteryPackageCode": "001PEAEF000002A670300002",
		"batteryPackageCompany": "江苏时代新能源科技有限公司",
		"batteryPackageDate": "2020-06-07",
		"batteryPackageVoltage": "346",
		"batteryType": "4",
		"vin": "LHGJ11880M8000028"
	}]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

返回:

{
    "code": "0",
    "message": "OK",
    "data": "",
    "recordsFiltered": 0,
    "recordsTotal": 0
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

参考博客:

https://blog.csdn.net/yunfengfengfeng/article/details/106207159

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/560773
推荐阅读
相关标签
  

闽ICP备14008679号