From fed0a447df51e633ab6453261dc6e3d8a906d4a2 Mon Sep 17 00:00:00 2001 From: DELL <1525436766@qq.com> Date: 星期一, 23 十二月 2024 14:08:25 +0800 Subject: [PATCH] 添加注释 --- src/main/java/com/whyc/controller/TestController.java | 270 +++++++++++------------------------------------------ 1 files changed, 56 insertions(+), 214 deletions(-) diff --git a/src/main/java/com/whyc/controller/TestController.java b/src/main/java/com/whyc/controller/TestController.java index 7a68ff1..b96bb12 100644 --- a/src/main/java/com/whyc/controller/TestController.java +++ b/src/main/java/com/whyc/controller/TestController.java @@ -1,11 +1,15 @@ package com.whyc.controller; +import com.whyc.bts.BTS_ChargeData; +import com.whyc.bts.BTS_DisChargeData; import com.whyc.fbo.FboData; import com.whyc.fbo.FboDataHeadStart; import com.whyc.fbo.FboDataHeadStop; import com.whyc.fbo.FboDataInf; +import com.whyc.mcp.TestDataInfo; import com.whyc.pojo.Response; -import com.whyc.service.FboDataInfService; +import com.whyc.res.RESDataInfo; +import com.whyc.service.*; import com.whyc.util.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -31,30 +35,57 @@ @RequestMapping("test") public class TestController { @Autowired - private FboDataInfService service; + private FboDataInfService fboService; + + @Autowired + private ExcelExportService exportService; + + @Autowired + private RESDataInfoService resService; + + @Autowired + private TestDataInfoService testDataInfoService; + + @Autowired + private BtsDisChargeService disDataService; + + @Autowired + private BtsChargeDataService chargeDataService; @GetMapping("/hello") public Response hello(){ return new Response().set(1,"hello"); } - @PostMapping("/readFboFile") + @GetMapping("/readFboFile") @ApiOperation(value = "鏍规嵁鏂囦欢鍚庣紑瑙f瀽涓嶅悓鐨勬枃浠�") public Response readFboFile(@RequestParam String filePath){ String suffix=filePath.substring(filePath.lastIndexOf(".")+1).toLowerCase(Locale.ROOT); Response response=new Response(); switch (suffix){ - case "fbx":FboDataInf fboDataInf = service.readFboFile(filePath); + case "fbx": + FboDataInf fboDataInf = fboService.readFboFile(filePath); response.set(1,fboDataInf,filePath); break; - case "bres":response.set(1,filePath); + case "bres": + RESDataInfo resDataInfo =resService.readFileData(filePath); + response.set(1,resDataInfo,filePath); break; case "alm":response.set(1,filePath); break; - case "mcp":response.set(1,filePath); + case "mcp": + TestDataInfo testDataInfoMcp=testDataInfoService.readFileData(filePath); + response.set(1,testDataInfoMcp,filePath); break; - case "mch":response.set(1,filePath); - break; + case "mch":TestDataInfo testDataInfoMch=testDataInfoService.readFileData(filePath); + response.set(1,testDataInfoMch,filePath); + break; + case "bcp": BTS_DisChargeData disData=disDataService.getDisData(filePath); + response.set(1,disData,filePath); + break; + case "chr":BTS_ChargeData chargeData=chargeDataService.getChrData(filePath); + response.set(1,chargeData,filePath); + break; default:response.set(1,false,filePath); } @@ -63,215 +94,26 @@ @PostMapping("/export") @ApiOperation(value = "鏂囦欢瀵煎嚭") - public void export(HttpServletRequest req, HttpServletResponse resp){ - - String curr_echart = req.getParameter("curr_echart"); //鐢垫睜鐢垫祦鎶樼嚎鍥� - String groupVol_echart = req.getParameter("groupVol_echart"); //缁勭鐢靛帇鎶樼嚎鍥� - String cap_echart = req.getParameter("cap_echart"); //娴嬭瘯瀹归噺鎶樼嚎鍥� - //String actualCap_echart = req.getParameter("actualCap_echart"); //瀹為檯瀹归噺鎶樼嚎鍥� - String vol_echart = req.getParameter("vol_echart"); //鍗曚綋鐢靛帇鎶樼嚎鍥� - String tempEnvi_echart = req.getParameter("tempEnvi_echart");//鐜娓╁害鎶樼嚎鍥� - String humiEnvi_echart = req.getParameter("humiEnvi_echart");//鐜婀垮害鎶樼嚎鍥� - - + public void export(HttpServletRequest req, HttpServletResponse resp ){ String filePath = req.getParameter("filePath"); - FboDataInf fboDataInf=service.readFboFile(filePath); -// if (fboDataInf==null){ -// fboDataInf = new FboDataInf(); -// if (filePath==null || "".equals(filePath)){ -// filePath = fileUrl; -// } -// fboDataInf.readFboFile(filePath); -// } - //浠庢枃浠朵腑鑾峰彇鏁版嵁 - List<FboData> list = fboDataInf.fboData; - //鍥剧墖base64鍚庣殑鏁版嵁 - List<byte[]> bytes = new ArrayList<>(); - try { - if (ServletUtils.isNotNull(curr_echart)) { - String[] url = curr_echart.split(","); - bytes.add(new BASE64Decoder().decodeBuffer(url[1])); - } - if (ServletUtils.isNotNull(groupVol_echart)) { - String[] url = groupVol_echart.split(","); - bytes.add(new BASE64Decoder().decodeBuffer(url[1])); - } - if (ServletUtils.isNotNull(cap_echart)) { - String[] url = cap_echart.split(","); - bytes.add(new BASE64Decoder().decodeBuffer(url[1])); - } - //if (ServletUtils.isNotNull(actualCap_echart)) { - // String[] url = actualCap_echart.split(","); - // bytes.add(new BASE64Decoder().decodeBuffer(url[1])); - //} - if (ServletUtils.isNotNull(vol_echart)) { - String[] url = vol_echart.split(","); - bytes.add(new BASE64Decoder().decodeBuffer(url[1])); - } - if (ServletUtils.isNotNull(tempEnvi_echart)) { - String[] url = tempEnvi_echart.split(","); - bytes.add(new BASE64Decoder().decodeBuffer(url[1])); - } - if (ServletUtils.isNotNull(humiEnvi_echart)) { - String[] url = humiEnvi_echart.split(","); - bytes.add(new BASE64Decoder().decodeBuffer(url[1])); - } - }catch (Exception e){ - e.printStackTrace(); - } - //褰撳墠鏃ユ湡 - String nowFormat = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); - String excelName = "FBX-"+nowFormat; - //HSSFWorkbook wb = new HSSFWorkbook(); - //HSSFSheet sheet = wb.createSheet("鏁版嵁鎬昏〃"); - XSSFWorkbook wb = new XSSFWorkbook(); - XSSFSheet sheet = wb.createSheet("鏁版嵁鎬昏〃"); - //鍥剧墖鍏冪礌 - //HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); - XSSFDrawing patriarch = sheet.createDrawingPatriarch(); - ////瀛椾綋鏍煎紡-鍔犵矖 - //HSSFCellStyle cellStyle = wb.createCellStyle(); - //HSSFFont font = wb.createFont(); - //font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); - //cellStyle.setFont(font); - - int rowNumSheet = 0; - FboDataHeadStart start = fboDataInf.fboDataStart; - FboDataHeadStop stop = fboDataInf.fboDataStop; - sheet.createRow(rowNumSheet); - sheet.getRow(rowNumSheet).createCell(0).setCellValue("鐢垫睜缁勫悕绉帮細"+start.battNameStr); - sheet.getRow(rowNumSheet).createCell(1).setCellValue("鐢垫睜鍝佺墝锛�"+start.battBrandStr); - rowNumSheet++; - sheet.createRow(rowNumSheet); - - sheet.getRow(rowNumSheet).createCell(0).setCellValue("瀹夎鏃ユ湡锛�"+start.batt_date_str); - sheet.getRow(rowNumSheet).createCell(1).setCellValue("鍗曚綋鏁伴噺锛�"+start.batt_mon_num); - sheet.getRow(rowNumSheet).createCell(2).setCellValue("鏍囩О瀹归噺锛�"+start.batt_std_cap+"AH"); - rowNumSheet++; - sheet.createRow(rowNumSheet); - sheet.getRow(rowNumSheet).createCell(0).setCellValue("娴嬭瘯寮�濮嬫椂闂达細"+formartDate(start.testStartTime,"yyyy-MM-dd HH:mm:ss")); - sheet.getRow(rowNumSheet).createCell(1).setCellValue("娴嬭瘯鏃堕暱锛�"+stop.TestTimeLong.hms()); - sheet.getRow(rowNumSheet).createCell(2).setCellValue("鍗曚綋鐢靛帇锛�"+start.batt_mon_vol+"V"); - rowNumSheet++; - sheet.createRow(rowNumSheet); - sheet.getRow(rowNumSheet).createCell(0).setCellValue("姝f瀬缁濈紭鐢甸樆锛�"+list.get(list.size()-1).PosInsRes+"k惟"); - sheet.getRow(rowNumSheet).createCell(1).setCellValue("璐熸瀬缁濈紭鐢甸樆锛�"+list.get(list.size()-1).NegInsRes+"k惟"); - sheet.getRow(rowNumSheet).createCell(2).setCellValue("鏍囩О鍐呴樆锛�"+start.batt_std_res+"m惟"); - if(start.DataType==0xFD){ - rowNumSheet++; - sheet.createRow(rowNumSheet); - sheet.getRow(rowNumSheet).createCell(0).setCellValue("棰勪及瀹為檯瀹归噺锛�"+list.get(list.size()-1).actualCap+"AH"); - } - rowNumSheet+=4; - //鎻掑叆鍥剧墖 - int picNum = 0; - String[] picName = getPicName(start.DataType); - if (picName.length==bytes.size()){ - for(int i=0;i<picName.length;i++){ - sheet.createRow(rowNumSheet-1); - sheet.getRow(rowNumSheet-1).createCell(0).setCellValue(picName[i]); - //rowNum++; - XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 512, 255,(short) 0, rowNumSheet, (short) 10, rowNumSheet+27); - anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE); - patriarch.createPicture(anchor,wb.addPicture(bytes.get(picNum),XSSFWorkbook.PICTURE_TYPE_PNG)).resize(1); - picNum ++; - rowNumSheet+=27; - } - } - - XSSFSheet sheet1 = wb.createSheet("鏁版嵁"); - //鏂板缓琛� - - //鎶ご - int rowNum = 0; - sheet1.createRow(rowNum).createCell(0).setCellValue("娴嬭瘯鏁版嵁"); - rowNum++; - - - - - //灞炴�ф爮 - String[] rowName = getRowName(start.DataType); - XSSFRow row = sheet1.createRow(rowNum); - for (int i=0;i<rowName.length;i++){ - row.createCell(i).setCellValue(rowName[i]); - } - for(int i=0;i<list.get(0).SingleVol.length;i++){ - row.createCell(rowName.length+i).setCellValue("#"+Integer.valueOf(i+1)); - } - rowNum++; - //鏁版嵁鏍� - for (int i = 0; i < list.size(); i++) { - sheet1.createRow(rowNum); //鍒涘缓琛� - FboData fbo=list.get(i); - sheet1.getRow(rowNum).createCell(0).setCellValue(fbo.m_TestTime.hms()); - sheet1.getRow(rowNum).createCell(1).setCellValue(fbo.SumVoltage); - sheet1.getRow(rowNum).createCell(2).setCellValue(fbo.SumCurrent); - sheet1.getRow(rowNum).createCell(3).setCellValue(fbo.Temp_Envi); - sheet1.getRow(rowNum).createCell(4).setCellValue(fbo.Humi_Envi); - if (start.DataType!=0xFB){ - sheet1.getRow(rowNum).createCell(5).setCellValue(fbo.testCap); - } - for (int k = 0;k<list.get(0).SingleVol.length;k++){ - sheet1.getRow(rowNum).createCell(rowName.length+k).setCellValue(fbo.SingleVol[k]); - } - rowNum++; - } - - rowNum++; - - try { - // 杞爜闃叉涔辩爜 - resp.addHeader("Content-Disposition", "attachment;filename=" - + new String(excelName.getBytes("UTF-8"), "ISO8859-1") - + ".xlsx"); - OutputStream out = resp.getOutputStream(); - wb.write(out); - out.close(); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - - - } - - public String[] getRowName(int dateType){ - if (dateType==0xFB){ - String[] rowName = {"娴嬭瘯鏃堕棿","鎬荤數鍘�(V)","鎬荤數娴�(A)","鐜娓╁害","鐜婀垮害"}; - return rowName; - }else{ - String[] rowName1 = {"娴嬭瘯鏃堕棿","鎬荤數鍘�(V)","鎬荤數娴�(A)","鐜娓╁害","鐜婀垮害","娴嬭瘯瀹归噺(AH)"}; - return rowName1; + String suffix=filePath.substring(filePath.lastIndexOf(".")+1).toLowerCase(Locale.ROOT); + switch (suffix){ + case "fbx":exportService.exportFbx(req,resp); + break; + case "bres":exportService.exportBres(req,resp); + break; + /*case "alm":exportService.exportAlm(req,resp); + break;*/ + case "mcp":exportService.exportMcph(req,resp); + break; + case "mch":exportService.exportMcph(req,resp); + break; + case "bcp":exportService.exportBcp(req,resp); + break; + case "chr":exportService.exportChr(req,resp); + break; } } - - public String[] getPicName(int dateType){ - if (dateType==0xFB){ - String[] picName1 = new String[]{ - "鐢垫睜鐢垫祦鎶樼嚎鍥�","缁勭鐢靛帇鎶樼嚎鍥�","鍗曚綋鐢靛帇鎶樼嚎鍥�","鐜娓╁害鎶樼嚎鍥�","鐜婀垮害鎶樼嚎鍥�" - }; - return picName1; - }else{ - String[] picName = new String[]{ - "鐢垫睜鐢垫祦鎶樼嚎鍥�","缁勭鐢靛帇鎶樼嚎鍥�","娴嬭瘯瀹归噺鎶樼嚎鍥�","鍗曚綋鐢靛帇鎶樼嚎鍥�","鐜娓╁害鎶樼嚎鍥�","鐜婀垮害鎶樼嚎鍥�" - }; - return picName; - } - } - - - /** - * 灏嗘棩鏈熸牸寮忚浆鎹㈡垚鎸囧畾鐨勫瓧绗︿覆鏍煎紡 - * @param date 鏃ユ湡 - * @param str 瀛楃涓茬殑鏍煎紡 - * @return - */ - public static String formartDate(Date date, String str){ - return new SimpleDateFormat(str).format(date); - } - } -- Gitblit v1.9.1