lxw
2023-02-10 bcd7202db10b9dc9600660230b0d8b39b6c68c6c
修改
2个文件已添加
3个文件已修改
200 ■■■■ 已修改文件
src/main/java/com/whyc/controller/TestController.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/fbo/FboDataHeadStart.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/fbo/FboDataInf.java 72 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/FboDataInfService.java 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/util/StaticInf.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/TestController.java
@@ -5,10 +5,13 @@
import com.whyc.fbo.FboDataHeadStop;
import com.whyc.fbo.FboDataInf;
import com.whyc.pojo.Response;
import com.whyc.service.FboDataInfService;
import com.whyc.util.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.misc.BASE64Decoder;
@@ -21,13 +24,14 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
@RestController
@Api(tags = "解析文件")
@RequestMapping("test")
public class TestController {
    //@Autowired
    //private FboDataInf fboDataInf;
    @Autowired
    private FboDataInfService service;
    @GetMapping("/hello")
    public Response hello(){
@@ -35,20 +39,30 @@
    }
    @PostMapping("/readFboFile")
    @ApiOperation(value = "根据文件后缀解析不同的文件")
    public Response readFboFile(@RequestParam String filePath){
        //log.info("接口readFboFile开始");
        FboDataInf fboDataInf = new FboDataInf();
        //log.info("fboDataInf:"+fboDataInf);
       // log.info("filePath:"+filePath);
        //String filePath1 = java.net.URLDecoder.decode(filePath,"utf-8");
        fboDataInf.readFboFile(filePath);
       // log.info(fboDataInf.fboData.toString());
       // log.info("读取结束");
//        fileUrl = filePath;
        return new Response().set(1,fboDataInf,filePath);
        String suffix=filePath.substring(filePath.lastIndexOf(".")+1).toLowerCase(Locale.ROOT);
        Response response=new Response();
        switch (suffix){
            case "fbx":FboDataInf fboDataInf = service.readFboFile(filePath);
                       response.set(1,fboDataInf,filePath);
                       break;
            case "bres":response.set(1,filePath);
                       break;
            case "alm":response.set(1,filePath);
                       break;
            case "mcp":response.set(1,filePath);
                       break;
            case "mch":response.set(1,filePath);
                      break;
            default:response.set(1,false,filePath);
        }
        return response;
    }
    @PostMapping("/export")
    @ApiOperation(value = "文件导出")
    public void export(HttpServletRequest req, HttpServletResponse resp){
        String curr_echart = req.getParameter("curr_echart");        //电池电流折线图
@@ -61,8 +75,7 @@
        String filePath = req.getParameter("filePath");
        FboDataInf  fboDataInf = new FboDataInf();
        fboDataInf.readFboFile(filePath);
        FboDataInf  fboDataInf=service.readFboFile(filePath);
//        if (fboDataInf==null){
//            fboDataInf = new FboDataInf();
//            if (filePath==null || "".equals(filePath)){
src/main/java/com/whyc/fbo/FboDataHeadStart.java
@@ -122,11 +122,9 @@
        batt_std_cte = (float) ComBase.changeShortToInt(bf.getShort())/10;          //标称电导                                2
        batt_mon_num = ComBase.changeShortToInt(bf.getShort());             //单体数量                                1
        batt_mon_vol = (float) ComBase.changeShortToInt(bf.getShort())/10;           //单体电压 0.1                            2        =100
        //System.out.println("单体电压:"+batt_mon_vol);
        TestStartTime.setDateTime(bf);;                                        //放电开始的时间                        6
        testStartTime = TestStartTime.getFBODateTime();
        Device = ComBase.changeShortToInt(bf.getShort());                   //仪表类型 未使用                        1
        //System.out.println("仪表类型:"+getDeviceType(Device));
        DataVersion = ComBase.changeShortToInt(bf.getShort());              //数据版本                                1
        DataType = ComBase.changeByteToInt(bf.get());                        //数据类型;0xFD表示放电,0xFC表示充电            1
        HourRate = ComBase.changeByteToInt(bf.get());                        //小时率 未使用                            1
@@ -136,7 +134,6 @@
        MVLLimitCount = ComBase.changeShortToInt(bf.getShort());            //单体下限个数 未使用                    2
        for(int i=0;i<module_mon_num.length;i++) {
            module_mon_num[i] = ComBase.changeShortToInt(bf.getShort());    //每个组压模块单体节数 目前只用5个        20
            //System.out.println((i+1)+":单体数目:"+module_mon_num[i]);
        }
        GrpVol_H_Limit = (float) ComBase.changeShortToFloat(bf.getShort())/10;        //组端电压上限                            2
        GrpVol_L_Limit = (float) ComBase.changeShortToFloat(bf.getShort())/10;        //组端电压下限                            2
@@ -153,11 +150,8 @@
        for(int i =0;i<StandBy.length;i++) {
            StandBy[i] =  ComBase.changeShortToInt(bf.getShort());              //保留备用                                20        179
        }
        //System.out.println(this);
        
        fboHeadStop.setFboStopData(bf);
        //System.out.println("avg_curr:"+avg_curr);
        //realcap = BattCapFactory.GetMonomerCap(STDCap,HourRate, TestCap, SMaxVol[0], MonomerVol, SMinVol[0], BattCapFactory.CapType_Real);
    }
    
    
@@ -165,7 +159,6 @@
        byte[] batt_brand_tmp = new byte[batt_brand_len];
        System.arraycopy(this.batt_brand, 0, batt_brand_tmp, 0, batt_brand_tmp.length);
        this.battBrandStr = new String(batt_brand_tmp);
        //System.out.println(this.battBrandStr);
        
    }
@@ -174,14 +167,12 @@
        byte[] batt = new byte[battname_len];
        System.arraycopy(this.battname, 0, batt, 0, batt.length);
        this.battNameStr = new String(batt);
        //System.out.println(this.battNameStr);
    }
    public void checkBattDate() {
        byte[] date = new byte[batt_date_len];
        System.arraycopy(this.batt_date, 0, date, 0, date.length);
        this.batt_date_str = new String(date);
        //System.out.println(this.batt_date_str);
    }
    
    public String getDeviceType(int device) {
src/main/java/com/whyc/fbo/FboDataInf.java
@@ -1,19 +1,12 @@
package com.whyc.fbo;
import lombok.extern.slf4j.Slf4j;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Data
public class FboDataInf {
    public static final int DataType_Dis     = 0xFD;            //放电
    public static final int DataType_Char     = 0xFC;            //充电
    public static final int DataType_Peac     = 0xFB;            //常规
    
    public List<FboData> fboData;
    public FboDataHeadStart fboDataStart;
@@ -25,63 +18,4 @@
        fboDataStop = new FboDataHeadStop();
    }
    public void readFboFile(String filePath)
    {
        FileInputStream fis = null;
        try {
            File f = new File(filePath);
            if(!f.exists()) {
                System.out.println("文件不存在..........");
            }
            fis = new FileInputStream(f);
            byte[] buf = new byte[256];
            if(fis.read(buf, 0, buf.length) == 256)
            {
                this.fboDataStart.setDataInf(buf,this.fboDataStop);
                FboData.DataType mType = new FboData().new DataType();
                while(true)
                {
                    int tag = mType.checkDataHead(fis);
                    if((0xFD == tag) || (0xFC == tag) || (0xFB == tag))
                    {
                        byte[] databuf = new byte[this.fboDataStart.BattGroup*14 + 40];
                        if(fis.read(databuf) == databuf.length)
                        {
                            FboData m_FboData = new FboData(this.fboDataStart.BattGroup);
                            m_FboData.m_DataType = mType.clone();
                            m_FboData.setData(databuf);
                            fboData.add(m_FboData);
                        }
                    }
                    if(tag == 1)
                        break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            //log.error(e.toString());
        } finally {
            if(null != fis)
            {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    //log.error(e.toString());
                }
            }
        }
    }
    public static void main(String[] args) {
        FboDataInf fbo = new FboDataInf();
        //fbo.readFboFile("D:/test/F2022-03-09 11.26.12.FBX");
        //fbo.readFboFile("D:/test/F2022-03-09 16.22.37.FBX");
        //fbo.readFboFile("D:/test/F2022-03-10 11.12.30.FBX");
        fbo.readFboFile("C:\\Users\\Administrator\\Desktop\\F2022-05-09 10.45.12.FBX");
    }
}
src/main/java/com/whyc/service/FboDataInfService.java
New file
@@ -0,0 +1,71 @@
package com.whyc.service;
import com.whyc.fbo.FboData;
import com.whyc.fbo.FboDataInf;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@Service
public class FboDataInfService {
    public FboDataInf readFboFile(String filePath)
    {
        FboDataInf fboDataInf=new FboDataInf();
        FileInputStream fis = null;
        try {
            File f = new File(filePath);
            if(!f.exists()) {
                System.out.println("文件不存在..........");
            }
            fis = new FileInputStream(f);
            byte[] buf = new byte[256];
            if(fis.read(buf, 0, buf.length) == 256)
            {
                fboDataInf.fboDataStart.setDataInf(buf,fboDataInf.fboDataStop);
                FboData.DataType mType = new FboData().new DataType();
                while(true)
                {
                    int tag = mType.checkDataHead(fis);
                    if((0xFD == tag) || (0xFC == tag) || (0xFB == tag))
                    {
                        byte[] databuf = new byte[fboDataInf.fboDataStart.BattGroup*14 + 40];
                        if(fis.read(databuf) == databuf.length)
                        {
                            FboData m_FboData = new FboData(fboDataInf.fboDataStart.BattGroup);
                            m_FboData.m_DataType = mType.clone();
                            m_FboData.setData(databuf);
                            fboDataInf.getFboData().add(m_FboData);
                        }
                    }
                    if(tag == 1)
                        break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(null != fis)
            {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return  fboDataInf;
    }
    public static void main(String[] args) {
        FboDataInfService service = new FboDataInfService();
        //service.readFboFile("D:/test/F2022-03-09 11.26.12.FBX");
        //service.readFboFile("D:/test/F2022-03-09 16.22.37.FBX");
        //service.readFboFile("D:/test/F2022-03-10 11.12.30.FBX");
        service.readFboFile("C:\\Users\\Administrator\\Desktop\\F2022-05-09 10.45.12.FBX");
    }
}
src/main/java/com/whyc/util/StaticInf.java
New file
@@ -0,0 +1,7 @@
package com.whyc.util;
public class StaticInf {
    public static final int DataType_Dis     = 0xFD;            //放电
    public static final int DataType_Char     = 0xFC;            //充电
    public static final int DataType_Peac     = 0xFB;            //常规
}