|
@@ -1,28 +1,35 @@
|
|
package com.jjt.ws.controller;
|
|
package com.jjt.ws.controller;
|
|
|
|
|
|
-import java.util.List;
|
|
|
|
-import javax.annotation.Resource;
|
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
|
-
|
|
|
|
-import io.swagger.annotations.Api;
|
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
|
-import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import com.jjt.common.annotation.Log;
|
|
import com.jjt.common.annotation.Log;
|
|
import com.jjt.common.core.controller.BaseController;
|
|
import com.jjt.common.core.controller.BaseController;
|
|
import com.jjt.common.core.domain.AjaxResult;
|
|
import com.jjt.common.core.domain.AjaxResult;
|
|
|
|
+import com.jjt.common.core.page.TableDataInfo;
|
|
import com.jjt.common.enums.BusinessType;
|
|
import com.jjt.common.enums.BusinessType;
|
|
|
|
+import com.jjt.common.utils.DateUtils;
|
|
|
|
+import com.jjt.elec.domain.ElecPrice;
|
|
import com.jjt.ws.domain.TwinWorkshopCalc;
|
|
import com.jjt.ws.domain.TwinWorkshopCalc;
|
|
import com.jjt.ws.service.ITwinWorkshopCalcService;
|
|
import com.jjt.ws.service.ITwinWorkshopCalcService;
|
|
-import com.jjt.common.utils.poi.ExcelUtil;
|
|
|
|
-import com.jjt.common.core.page.TableDataInfo;
|
|
|
|
|
|
+import com.jjt.ws.vo.MonthCalcVO;
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.io.OutputStream;
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 能源统计Controller
|
|
* 能源统计Controller
|
|
@@ -30,10 +37,10 @@ import com.jjt.common.core.page.TableDataInfo;
|
|
* @author wukai
|
|
* @author wukai
|
|
* @date 2025-01-17
|
|
* @date 2025-01-17
|
|
*/
|
|
*/
|
|
-@Api(tags="能源统计")
|
|
|
|
|
|
+@Api(tags = "能源统计")
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/ws/calc")
|
|
@RequestMapping("/ws/calc")
|
|
-public class TwinWorkshopCalcController extends BaseController{
|
|
|
|
|
|
+public class TwinWorkshopCalcController extends BaseController {
|
|
@Resource
|
|
@Resource
|
|
private ITwinWorkshopCalcService twinWorkshopCalcService;
|
|
private ITwinWorkshopCalcService twinWorkshopCalcService;
|
|
|
|
|
|
@@ -43,25 +50,109 @@ public class TwinWorkshopCalcController extends BaseController{
|
|
@ApiOperation("查询能源统计列表")
|
|
@ApiOperation("查询能源统计列表")
|
|
@PreAuthorize("@ss.hasPermi('ws:calc:list')")
|
|
@PreAuthorize("@ss.hasPermi('ws:calc:list')")
|
|
@GetMapping("/list")
|
|
@GetMapping("/list")
|
|
- public TableDataInfo list(TwinWorkshopCalc twinWorkshopCalc)
|
|
|
|
- {
|
|
|
|
|
|
+ public TableDataInfo list(TwinWorkshopCalc twinWorkshopCalc) {
|
|
startPage();
|
|
startPage();
|
|
List<TwinWorkshopCalc> list = twinWorkshopCalcService.selectTwinWorkshopCalcList(twinWorkshopCalc);
|
|
List<TwinWorkshopCalc> list = twinWorkshopCalcService.selectTwinWorkshopCalcList(twinWorkshopCalc);
|
|
return getDataTable(list);
|
|
return getDataTable(list);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 导出能源统计列表
|
|
|
|
|
|
+ * 查询能源统计列表
|
|
*/
|
|
*/
|
|
|
|
+ @ApiOperation("查询能源统计月报")
|
|
|
|
+ @GetMapping("/calc/rz")
|
|
|
|
+ public TableDataInfo calcRz(TwinWorkshopCalc twinWorkshopCalc) {
|
|
|
|
+ List<MonthCalcVO> list = twinWorkshopCalcService.calcYr(twinWorkshopCalc);
|
|
|
|
+ return getDataTable(list);
|
|
|
|
+ }
|
|
|
|
+
|
|
@ApiOperation("导出能源统计列表")
|
|
@ApiOperation("导出能源统计列表")
|
|
- @PreAuthorize("@ss.hasPermi('ws:calc:export')")
|
|
|
|
- @Log(title = "能源统计", businessType = BusinessType.EXPORT)
|
|
|
|
- @PostMapping("/export")
|
|
|
|
- public void export(HttpServletResponse response, TwinWorkshopCalc twinWorkshopCalc)
|
|
|
|
- {
|
|
|
|
- List<TwinWorkshopCalc> list = twinWorkshopCalcService.selectTwinWorkshopCalcList(twinWorkshopCalc);
|
|
|
|
- ExcelUtil<TwinWorkshopCalc> util = new ExcelUtil<TwinWorkshopCalc>(TwinWorkshopCalc.class);
|
|
|
|
- util.exportExcel(response, list, "能源统计数据");
|
|
|
|
|
|
+ @RequestMapping("/export/rz")
|
|
|
|
+ public void exportRz(TwinWorkshopCalc twinWorkshopCalc, HttpServletResponse response) {
|
|
|
|
+ List<MonthCalcVO> list = twinWorkshopCalcService.calcYr(twinWorkshopCalc);
|
|
|
|
+ try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("tpl/yr-energy-month.xlsx"); Workbook wb = new XSSFWorkbook(inputStream); OutputStream outputStream = new BufferedOutputStream(response.getOutputStream())) {
|
|
|
|
+ Sheet sheet = wb.getSheetAt(0);
|
|
|
|
+ AtomicInteger colNum = new AtomicInteger(2);
|
|
|
|
+ int rowNum = 31;
|
|
|
|
+ AtomicReference<ElecPrice> elecPrice = new AtomicReference<>(new ElecPrice());
|
|
|
|
+ list.forEach(vo -> {
|
|
|
|
+ elecPrice.set(vo.getElecPrice());
|
|
|
|
+ Cell[] cells = new Cell[rowNum];
|
|
|
|
+ for (int i = 0; i < rowNum; i++) {
|
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
|
+ cells[i] = row.getCell(colNum.get());
|
|
|
|
+ }
|
|
|
|
+ cells[0].setCellValue(DateUtils.parseDateToStrCN(vo.getDate()));
|
|
|
|
+ cells[1].setCellValue(vo.getD().getQz().getUse().doubleValue());
|
|
|
|
+ cells[2].setCellValue(vo.getD().getQz().getFUse().doubleValue());
|
|
|
|
+ cells[3].setCellValue(vo.getD().getQz().getGUse().doubleValue());
|
|
|
|
+ cells[4].setCellValue(vo.getD().getQz().getPUse().doubleValue());
|
|
|
|
+ if (vo.getD().getQz().getJfUse() != null) {
|
|
|
|
+ cells[5].setCellValue(vo.getD().getQz().getJfUse().doubleValue());
|
|
|
|
+ }
|
|
|
|
+ cells[6].setCellValue(vo.getD().getQz().getPrice().doubleValue());
|
|
|
|
+
|
|
|
|
+ cells[7].setCellValue(vo.getD().getHz().getUse().doubleValue());
|
|
|
|
+ cells[8].setCellValue(vo.getD().getHz().getFUse().doubleValue());
|
|
|
|
+ cells[9].setCellValue(vo.getD().getHz().getGUse().doubleValue());
|
|
|
|
+ cells[10].setCellValue(vo.getD().getHz().getPUse().doubleValue());
|
|
|
|
+ if (vo.getD().getHz().getJfUse() != null) {
|
|
|
|
+ cells[11].setCellValue(vo.getD().getHz().getJfUse().doubleValue());
|
|
|
|
+ }
|
|
|
|
+ cells[12].setCellValue(vo.getD().getHz().getPrice().doubleValue());
|
|
|
|
+
|
|
|
|
+ cells[13].setCellValue(vo.getD().getYr().getUse().doubleValue());
|
|
|
|
+ cells[14].setCellValue(vo.getD().getYr().getFUse().doubleValue());
|
|
|
|
+ cells[15].setCellValue(vo.getD().getYr().getGUse().doubleValue());
|
|
|
|
+ cells[16].setCellValue(vo.getD().getYr().getPUse().doubleValue());
|
|
|
|
+ if (vo.getD().getYr().getJfUse() != null) {
|
|
|
|
+ cells[17].setCellValue(vo.getD().getYr().getJfUse().doubleValue());
|
|
|
|
+ }
|
|
|
|
+ cells[18].setCellValue(vo.getD().getYr().getPrice().doubleValue());
|
|
|
|
+ cells[19].setCellValue(vo.getD().getPrice().doubleValue());
|
|
|
|
+
|
|
|
|
+ cells[20].setCellValue(vo.getS().getUse().doubleValue());
|
|
|
|
+ cells[21].setCellValue(vo.getS().getPrice().doubleValue());
|
|
|
|
+
|
|
|
|
+ cells[22].setCellValue(vo.getQ().getLowUse().doubleValue());
|
|
|
|
+ cells[23].setCellValue(vo.getQ().getLowPrice().doubleValue());
|
|
|
|
+ cells[24].setCellValue(vo.getQ().getMidUse().doubleValue());
|
|
|
|
+ cells[25].setCellValue(vo.getQ().getMidPrice().doubleValue());
|
|
|
|
+
|
|
|
|
+ cells[26].setCellValue(vo.getPrice().doubleValue());
|
|
|
|
+ cells[27].setCellValue("");
|
|
|
|
+ cells[28].setCellValue("");
|
|
|
|
+ cells[29].setCellValue("");
|
|
|
|
+ cells[30].setCellValue("");
|
|
|
|
+ colNum.getAndIncrement();
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ Cell[] cells = new Cell[rowNum];
|
|
|
|
+ for (int i = 0; i < rowNum; i++) {
|
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
|
+ cells[i] = row.getCell(1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ cells[2].setCellValue("峰电(kwh/"+elecPrice.get().getPricePeak()+")");
|
|
|
|
+ cells[3].setCellValue("谷电(kwh/"+elecPrice.get().getPriceValley()+")");
|
|
|
|
+ cells[4].setCellValue("平电(kwh/"+elecPrice.get().getPriceFlat()+")");
|
|
|
|
+ cells[5].setCellValue("尖峰(kwh/"+elecPrice.get().getPriceSuperPeak()+")");
|
|
|
|
+
|
|
|
|
+ wb.removeSheetAt(1);
|
|
|
|
+ // 清空response
|
|
|
|
+ response.reset();
|
|
|
|
+ // 设置response的Header
|
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
|
+ //Content-Disposition的作用:告知浏览器以何种方式显示响应返回的文件,用浏览器打开还是以附件的形式下载到本地保存
|
|
|
|
+ //attachment表示以附件方式下载 inline表示在线打开 "Content-Disposition: inline; filename=文件名.mp3"
|
|
|
|
+ // filename表示文件的默认名称,因为网络传输只支持URL编码的相关支付,因此需要将文件名URL编码后进行传输,前端收到后需要反编码才能获取到真正的名称
|
|
|
|
+ response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("染整线统计" + DateUtils.dateTimeNow() + ".xlsx", "UTF-8"));
|
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
|
+ wb.write(outputStream);
|
|
|
|
+ outputStream.flush();
|
|
|
|
+ } catch (IOException ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -70,8 +161,7 @@ public class TwinWorkshopCalcController extends BaseController{
|
|
@ApiOperation("获取能源统计详细信息")
|
|
@ApiOperation("获取能源统计详细信息")
|
|
@PreAuthorize("@ss.hasPermi('ws:calc:query')")
|
|
@PreAuthorize("@ss.hasPermi('ws:calc:query')")
|
|
@GetMapping(value = "/{calcId}")
|
|
@GetMapping(value = "/{calcId}")
|
|
- public AjaxResult getInfo(@PathVariable("calcId") Long calcId)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult getInfo(@PathVariable("calcId") Long calcId) {
|
|
return success(twinWorkshopCalcService.selectTwinWorkshopCalcByCalcId(calcId));
|
|
return success(twinWorkshopCalcService.selectTwinWorkshopCalcByCalcId(calcId));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -82,8 +172,7 @@ public class TwinWorkshopCalcController extends BaseController{
|
|
@PreAuthorize("@ss.hasPermi('ws:calc:add')")
|
|
@PreAuthorize("@ss.hasPermi('ws:calc:add')")
|
|
@Log(title = "能源统计", businessType = BusinessType.INSERT)
|
|
@Log(title = "能源统计", businessType = BusinessType.INSERT)
|
|
@PostMapping
|
|
@PostMapping
|
|
- public AjaxResult add(@RequestBody TwinWorkshopCalc twinWorkshopCalc)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult add(@RequestBody TwinWorkshopCalc twinWorkshopCalc) {
|
|
return toAjax(twinWorkshopCalcService.insertTwinWorkshopCalc(twinWorkshopCalc));
|
|
return toAjax(twinWorkshopCalcService.insertTwinWorkshopCalc(twinWorkshopCalc));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -94,8 +183,7 @@ public class TwinWorkshopCalcController extends BaseController{
|
|
@PreAuthorize("@ss.hasPermi('ws:calc:edit')")
|
|
@PreAuthorize("@ss.hasPermi('ws:calc:edit')")
|
|
@Log(title = "能源统计", businessType = BusinessType.UPDATE)
|
|
@Log(title = "能源统计", businessType = BusinessType.UPDATE)
|
|
@PutMapping
|
|
@PutMapping
|
|
- public AjaxResult edit(@RequestBody TwinWorkshopCalc twinWorkshopCalc)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult edit(@RequestBody TwinWorkshopCalc twinWorkshopCalc) {
|
|
return toAjax(twinWorkshopCalcService.updateTwinWorkshopCalc(twinWorkshopCalc));
|
|
return toAjax(twinWorkshopCalcService.updateTwinWorkshopCalc(twinWorkshopCalc));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -105,9 +193,8 @@ public class TwinWorkshopCalcController extends BaseController{
|
|
@ApiOperation("删除能源统计")
|
|
@ApiOperation("删除能源统计")
|
|
@PreAuthorize("@ss.hasPermi('ws:calc:remove')")
|
|
@PreAuthorize("@ss.hasPermi('ws:calc:remove')")
|
|
@Log(title = "能源统计", businessType = BusinessType.DELETE)
|
|
@Log(title = "能源统计", businessType = BusinessType.DELETE)
|
|
- @DeleteMapping("/{calcIds}")
|
|
|
|
- public AjaxResult remove(@PathVariable Long[] calcIds)
|
|
|
|
- {
|
|
|
|
|
|
+ @DeleteMapping("/{calcIds}")
|
|
|
|
+ public AjaxResult remove(@PathVariable Long[] calcIds) {
|
|
return toAjax(twinWorkshopCalcService.deleteTwinWorkshopCalcByCalcIds(calcIds));
|
|
return toAjax(twinWorkshopCalcService.deleteTwinWorkshopCalcByCalcIds(calcIds));
|
|
}
|
|
}
|
|
}
|
|
}
|