181 lines
7.3 KiB
Java
181 lines
7.3 KiB
Java
package com.gunshi.project.hsz.controller;
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import com.alibaba.excel.EasyExcel;
|
|
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
|
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
|
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.gunshi.core.result.R;
|
|
import com.gunshi.project.hsz.entity.so.GateHisPageSo;
|
|
import com.gunshi.project.hsz.entity.vo.GateStautsVo;
|
|
import com.gunshi.project.hsz.entity.vo.GateValveOplogVo;
|
|
import com.gunshi.project.hsz.model.GateValveKey;
|
|
import com.gunshi.project.hsz.model.GateValveOplog;
|
|
import com.gunshi.project.hsz.model.GateValveReal;
|
|
import com.gunshi.project.hsz.service.GateValveRealService;
|
|
import com.gunshi.project.hsz.validate.markers.Insert;
|
|
import com.gunshi.project.hsz.validate.markers.Update;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
import org.apache.poi.ss.usermodel.FillPatternType;
|
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.io.Serializable;
|
|
import java.math.BigDecimal;
|
|
import java.net.URLEncoder;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* 描述: 闸阀开关表
|
|
* author: xusan
|
|
* date: 2024-07-08 17:40:37
|
|
*/
|
|
@Tag(name = "闸阀开关表")
|
|
@RestController
|
|
@RequestMapping(value="/gateValveReal")
|
|
public class GateValveRealController {
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(GateValveRealController.class);
|
|
|
|
|
|
@Autowired
|
|
private GateValveRealService service;
|
|
|
|
@Operation(summary = "新增")
|
|
@PostMapping("/insert")
|
|
public R<GateValveReal> insert(@Validated(Insert.class) @RequestBody GateValveReal dto) {
|
|
boolean result = service.save(dto);
|
|
return R.ok(result ? dto : null);
|
|
}
|
|
|
|
@Operation(summary = "修改")
|
|
@PostMapping("/update")
|
|
public R<GateValveReal> update(@Validated(Update.class) @RequestBody GateValveReal dto) {
|
|
boolean result = service.updateById(dto);
|
|
return R.ok(result ? dto : null);
|
|
}
|
|
|
|
@Operation(summary = "删除")
|
|
@GetMapping("/del/{id}")
|
|
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
|
return R.ok(service.removeById(id));
|
|
}
|
|
|
|
@Operation(summary = "列表")
|
|
@PostMapping("/list")
|
|
public R<List<GateStautsVo>> list() {
|
|
return R.ok(service.gateStatusList());
|
|
}
|
|
|
|
@Operation(summary = "通过闸阀查询实时流量")
|
|
@GetMapping("/realQ")
|
|
public R<BigDecimal> realQ(@RequestParam("valveCode") @Parameter(description = "闸阀编码") String valveCode) {
|
|
return R.ok(service.realQ(valveCode));
|
|
}
|
|
|
|
@Operation(summary = "调节闸阀")
|
|
@PostMapping("/control")
|
|
public R<String> control(@RequestBody GateValveKey gateValveKey) {
|
|
return R.ok(service.control(gateValveKey));
|
|
}
|
|
|
|
@Operation(summary = "闸阀操作日志-分页")
|
|
@PostMapping("/log/page")
|
|
public R<Page<GateValveOplogVo>> logPage(@RequestBody GateHisPageSo so) {
|
|
return R.ok(service.logPage(so));
|
|
}
|
|
|
|
@Operation(summary = "闸阀操作日志-导出")
|
|
@PostMapping("/log/exp")
|
|
public void logexp(@RequestBody GateHisPageSo so, HttpServletResponse response) {
|
|
so.getPageSo().setPageSize(1000000);
|
|
Page<GateValveOplogVo> gateValveOplogVoPage = service.logPage(so);
|
|
|
|
try {
|
|
// 设置响应
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
response.setCharacterEncoding("utf-8");
|
|
String fileName = URLEncoder.encode("闸阀操作日志_" + System.currentTimeMillis(), "UTF-8")
|
|
.replaceAll("\\+", "%20");
|
|
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
|
|
|
// 自定义表头样式
|
|
WriteCellStyle headStyle = new WriteCellStyle();
|
|
headStyle.setFillForegroundColor(IndexedColors.SKY_BLUE.getIndex());
|
|
headStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
// 自定义内容样式
|
|
WriteCellStyle contentStyle = new WriteCellStyle();
|
|
contentStyle.setWrapped(true); // 自动换行
|
|
List<List<String>> headlist= Arrays.asList(
|
|
Arrays.asList("闸阀名称"),
|
|
Arrays.asList("操作人"),
|
|
Arrays.asList("操作时间"),
|
|
Arrays.asList("操作内容"),
|
|
Arrays.asList("设定开度"),
|
|
Arrays.asList("操作前开度")
|
|
);
|
|
// 构建导出器
|
|
EasyExcel.write(response.getOutputStream())
|
|
.head(headlist) // 自定义表头
|
|
.registerWriteHandler(new HorizontalCellStyleStrategy(headStyle, contentStyle))
|
|
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // 自动列宽
|
|
.sheet("闸阀操作日志")
|
|
.doWrite(gateValveOplogVoPage.getRecords());
|
|
}catch (Exception e){
|
|
log.error("导出异常", e);
|
|
}
|
|
}
|
|
|
|
@Operation(summary = "闸阀操作日志-分页")
|
|
@PostMapping("/log/loglist")
|
|
public R<List<GateValveOplogVo>> loglist(@RequestBody GateHisPageSo so) {
|
|
List<GateStautsVo> gateStautsVos = service.gateStatusList();
|
|
if(CollectionUtil.isEmpty(gateStautsVos)){
|
|
return R.ok(null);
|
|
}
|
|
List<GateValveOplogVo> collect = gateStautsVos.stream().map(e -> {
|
|
GateValveOplogVo vo = new GateValveOplogVo();
|
|
GateValveOplog loginfo = service.loginfo(e.getValveCode());
|
|
if(Objects.nonNull(loginfo)){
|
|
BeanUtils.copyProperties(loginfo, vo);
|
|
}
|
|
vo.setValveCode(e.getValveCode());
|
|
vo.setValveName(e.getValveName());
|
|
return vo;
|
|
}).collect(Collectors.toList());
|
|
return R.ok(collect);
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "闸阀操作日志-导出")
|
|
@PostMapping("/log/export")
|
|
public void logExport(@RequestBody GateHisPageSo so, HttpServletResponse response) {
|
|
service.logExport(so,response);
|
|
}
|
|
|
|
@Operation(summary = "预计可供水时间")
|
|
@GetMapping("/supply/time")
|
|
public R<Map<BigDecimal, String>> supplyTime(@RequestParam(value = "year",required = false) @Parameter(description = "年份") Integer year,@RequestParam(value = "month",required = false) @Parameter(description = "月份") Integer month) {
|
|
return R.ok(service.supplyTime(year,month));
|
|
}
|
|
|
|
@Operation(summary = "预测来水量")
|
|
@GetMapping("/predict/water")
|
|
public R<BigDecimal> predictWater(@RequestParam(value = "year") @Parameter(description = "年份") Integer year, @RequestParam(value = "month") @Parameter(description = "月份") Integer month) {
|
|
return R.ok(service.predictWater(year,month));
|
|
}
|
|
} |