2025-07-17 15:26:39 +08:00
|
|
|
|
package com.gunshi.project.hsz.controller;
|
2024-07-08 17:47:02 +08:00
|
|
|
|
|
2024-08-07 15:59:50 +08:00
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
2024-07-10 14:04:43 +08:00
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
2024-07-23 14:59:39 +08:00
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
2024-07-10 14:04:43 +08:00
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
2024-07-08 17:47:02 +08:00
|
|
|
|
import com.gunshi.core.result.R;
|
2025-07-17 15:26:39 +08:00
|
|
|
|
import com.gunshi.project.hsz.entity.vo.OsmoticWaterRVo;
|
|
|
|
|
|
import com.gunshi.project.hsz.listener.OsmoticWaterRImportListener;
|
|
|
|
|
|
import com.gunshi.project.hsz.model.OsmoticWaterR;
|
|
|
|
|
|
import com.gunshi.project.hsz.model.OsmoticWaterRule;
|
|
|
|
|
|
import com.gunshi.project.hsz.service.OsmoticWaterRService;
|
|
|
|
|
|
import com.gunshi.project.hsz.service.OsmoticWaterRuleService;
|
|
|
|
|
|
import com.gunshi.project.hsz.util.ConvertUtil;
|
|
|
|
|
|
import com.gunshi.project.hsz.util.DateUtil;
|
|
|
|
|
|
import com.gunshi.project.hsz.util.ExcelUtil;
|
|
|
|
|
|
import com.gunshi.project.hsz.util.ResultJson;
|
|
|
|
|
|
import com.gunshi.project.hsz.util.excel.ExcelResult;
|
2025-11-04 16:14:38 +08:00
|
|
|
|
import com.gunshi.project.hsz.common.validate.markers.Insert;
|
|
|
|
|
|
import com.gunshi.project.hsz.common.validate.markers.Update;
|
2024-07-08 17:47:02 +08:00
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
2024-07-10 14:04:43 +08:00
|
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
2024-07-08 17:47:02 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2024-07-10 14:04:43 +08:00
|
|
|
|
import org.springframework.http.MediaType;
|
2024-07-08 17:47:02 +08:00
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
2024-07-10 14:04:43 +08:00
|
|
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestPart;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
2024-07-08 17:47:02 +08:00
|
|
|
|
|
2024-08-21 09:34:06 +08:00
|
|
|
|
import java.io.File;
|
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
|
import java.io.IOException;
|
2024-08-21 10:22:47 +08:00
|
|
|
|
import java.io.InputStream;
|
2024-08-21 09:34:06 +08:00
|
|
|
|
import java.io.OutputStream;
|
2024-07-08 17:47:02 +08:00
|
|
|
|
import java.io.Serializable;
|
2024-08-21 09:34:06 +08:00
|
|
|
|
import java.net.URLEncoder;
|
2024-07-10 14:04:43 +08:00
|
|
|
|
import java.util.ArrayList;
|
2024-07-23 14:59:39 +08:00
|
|
|
|
import java.util.HashMap;
|
2024-07-08 17:47:02 +08:00
|
|
|
|
import java.util.List;
|
2024-07-23 14:59:39 +08:00
|
|
|
|
import java.util.Map;
|
2024-07-10 14:04:43 +08:00
|
|
|
|
|
2024-07-08 17:47:02 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 描述: 水质采样记录表
|
|
|
|
|
|
* author: xusan
|
|
|
|
|
|
* date: 2024-07-08 17:40:37
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Tag(name = "水质采样记录表")
|
|
|
|
|
|
@RestController
|
|
|
|
|
|
@RequestMapping(value="/osmoticWaterR")
|
|
|
|
|
|
public class OsmoticWaterRController {
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private OsmoticWaterRService service;
|
|
|
|
|
|
|
2024-07-23 14:59:39 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private OsmoticWaterRuleService osmoticWaterRuleService;
|
|
|
|
|
|
|
2024-07-08 17:47:02 +08:00
|
|
|
|
@Operation(summary = "新增")
|
|
|
|
|
|
@PostMapping("/insert")
|
|
|
|
|
|
public R<OsmoticWaterR> insert(@Validated(Insert.class) @RequestBody OsmoticWaterR dto) {
|
|
|
|
|
|
boolean result = service.save(dto);
|
|
|
|
|
|
return R.ok(result ? dto : null);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "修改")
|
|
|
|
|
|
@PostMapping("/update")
|
|
|
|
|
|
public R<OsmoticWaterR> update(@Validated(Update.class) @RequestBody OsmoticWaterR 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));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-10 14:27:43 +08:00
|
|
|
|
@Operation(summary = "获取最新一条数据")
|
|
|
|
|
|
@PostMapping("/getLastData")
|
2024-07-23 14:59:39 +08:00
|
|
|
|
public R<Map<String, Object>> getLastData() {
|
|
|
|
|
|
Map<String, Object> resMap = new HashMap<>();
|
2024-07-10 14:27:43 +08:00
|
|
|
|
QueryWrapper qw = new QueryWrapper<>();
|
2024-07-23 14:59:39 +08:00
|
|
|
|
qw.orderBy(true, false, "tm").last(" limit 1");
|
|
|
|
|
|
OsmoticWaterR osmoticWaterR = service.getOne(qw);
|
|
|
|
|
|
if(ObjectUtils.isNotEmpty(osmoticWaterR)){
|
|
|
|
|
|
resMap = JSON.parseObject(JSON.toJSONString(osmoticWaterR), Map.class);
|
|
|
|
|
|
// 获取标准值
|
|
|
|
|
|
List<OsmoticWaterRule> list = osmoticWaterRuleService.list();
|
|
|
|
|
|
if(CollectionUtils.isNotEmpty(list)){
|
|
|
|
|
|
for (OsmoticWaterRule rule : list){
|
|
|
|
|
|
String code = rule.getCode();
|
|
|
|
|
|
String codeStandard = code + "Standard";
|
|
|
|
|
|
if(resMap.containsKey(code)){
|
|
|
|
|
|
if("~".equals(rule.getCondition())){
|
|
|
|
|
|
resMap.put(codeStandard, "(" + rule.getOne() + rule.getCondition() + rule.getTwo() + ")");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
String codeLevel = resMap.get(code + "Level").toString();
|
|
|
|
|
|
if(codeLevel.contains("Ⅰ")){
|
|
|
|
|
|
resMap.put(codeStandard, "(" + rule.getCondition() + rule.getOne() + ")");
|
|
|
|
|
|
} else if (codeLevel.contains("Ⅱ")){
|
|
|
|
|
|
resMap.put(codeStandard, "(" + rule.getCondition() + rule.getTwo() + ")");
|
|
|
|
|
|
} else if (codeLevel.contains("Ⅲ")){
|
|
|
|
|
|
resMap.put(codeStandard, "(" + rule.getCondition() + rule.getThree() + ")");
|
|
|
|
|
|
} else if (codeLevel.contains("Ⅳ")){
|
|
|
|
|
|
resMap.put(codeStandard, "(" + rule.getCondition() + rule.getFour() + ")");
|
|
|
|
|
|
} else if (codeLevel.contains("Ⅴ")){
|
|
|
|
|
|
resMap.put(codeStandard, "(" + rule.getCondition() + rule.getFive() + ")");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return R.ok(resMap);
|
2024-07-10 14:27:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-08 17:47:02 +08:00
|
|
|
|
@Operation(summary = "列表")
|
|
|
|
|
|
@PostMapping("/list")
|
2024-07-10 14:04:43 +08:00
|
|
|
|
public R<List<OsmoticWaterR>> list(@RequestBody @Validated OsmoticWaterR osmoticWaterR) {
|
2024-07-10 17:03:50 +08:00
|
|
|
|
QueryWrapper<OsmoticWaterR> wrapper = new QueryWrapper<OsmoticWaterR>()
|
|
|
|
|
|
.ge(ObjectUtils.isNotNull(osmoticWaterR.getStartTime()), "tm", osmoticWaterR.getStartTime())
|
|
|
|
|
|
.le(ObjectUtils.isNotNull(osmoticWaterR.getEndTime()), "tm", osmoticWaterR.getEndTime());
|
2024-08-14 10:04:27 +08:00
|
|
|
|
if(StringUtils.isNotBlank(osmoticWaterR.getOrderField())){
|
|
|
|
|
|
wrapper.orderBy(true, ObjectUtils.isEmpty(osmoticWaterR.getIsAsc()) ? false : osmoticWaterR.getIsAsc(), osmoticWaterR.getOrderField());
|
2024-07-10 17:03:50 +08:00
|
|
|
|
}
|
2024-07-10 14:04:43 +08:00
|
|
|
|
return R.ok(service.list(wrapper));
|
2024-07-08 17:47:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "分页")
|
|
|
|
|
|
@PostMapping("/page")
|
2024-07-10 14:04:43 +08:00
|
|
|
|
public R<Page<OsmoticWaterR>> page(@RequestBody @Validated OsmoticWaterR osmoticWaterR) {
|
2024-07-10 17:03:50 +08:00
|
|
|
|
QueryWrapper<OsmoticWaterR> wrapper = new QueryWrapper<>();
|
|
|
|
|
|
wrapper.ge(ObjectUtils.isNotNull(osmoticWaterR.getStartTime()), "tm", osmoticWaterR.getStartTime())
|
|
|
|
|
|
.le(ObjectUtils.isNotNull(osmoticWaterR.getEndTime()), "tm", osmoticWaterR.getEndTime());
|
2024-08-14 10:04:27 +08:00
|
|
|
|
if(StringUtils.isNotBlank(osmoticWaterR.getOrderField())){
|
|
|
|
|
|
wrapper.orderBy(true, ObjectUtils.isEmpty(osmoticWaterR.getIsAsc()) ? false : osmoticWaterR.getIsAsc(), osmoticWaterR.getOrderField());
|
2024-07-10 17:03:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
return R.ok(service.page(osmoticWaterR.getPageSo().toPage(), wrapper));
|
2024-07-10 14:04:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取导入模板
|
|
|
|
|
|
*/
|
2024-07-10 17:03:50 +08:00
|
|
|
|
@Operation(summary = "获取导入模板")
|
2024-07-10 14:04:43 +08:00
|
|
|
|
@PostMapping("/importTemplate")
|
|
|
|
|
|
public void importTemplate(HttpServletResponse response) {
|
|
|
|
|
|
ExcelUtil.exportExcel(new ArrayList<>(), "水质整编表", OsmoticWaterRVo.class, response, "水质整编表");
|
2024-07-08 17:47:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-10 14:04:43 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 导入数据
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param file 导入文件
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Operation(summary = "导入数据")
|
|
|
|
|
|
@PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
|
|
|
public ResultJson<String> importData(@RequestPart("file") MultipartFile file) throws Exception {
|
|
|
|
|
|
ExcelResult<OsmoticWaterRVo> result = ExcelUtil.importExcel(file.getInputStream(), OsmoticWaterRVo.class, new OsmoticWaterRImportListener());
|
|
|
|
|
|
return ResultJson.ok(result.getAnalysis());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "导出")
|
|
|
|
|
|
@PostMapping("/exportOsmoticWaterRDataExcel")
|
|
|
|
|
|
@CrossOrigin
|
|
|
|
|
|
public void exportOsmoticWaterRDataExcel(@RequestBody @Validated OsmoticWaterR osmoticWaterR, HttpServletResponse response) {
|
2024-07-10 17:03:50 +08:00
|
|
|
|
String filename = "水质整编表";
|
|
|
|
|
|
if (ObjectUtils.isNotEmpty(osmoticWaterR.getStartTime())) {
|
|
|
|
|
|
filename.concat("_").concat(DateUtil.convertDateToString(osmoticWaterR.getStartTime()));
|
|
|
|
|
|
}
|
|
|
|
|
|
if (ObjectUtils.isNotEmpty(osmoticWaterR.getStartTime())) {
|
|
|
|
|
|
filename.concat("_").concat(DateUtil.convertDateToString(osmoticWaterR.getEndTime()));
|
|
|
|
|
|
}
|
2024-07-10 14:04:43 +08:00
|
|
|
|
List<OsmoticWaterRVo> vos = ConvertUtil.entityToVoList(this.list(osmoticWaterR).getData(), OsmoticWaterRVo.class);
|
|
|
|
|
|
ExcelUtil.exportExcel(vos, filename, OsmoticWaterRVo.class, response, "水质整编表");
|
|
|
|
|
|
}
|
2024-08-21 09:34:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "文件下载")
|
|
|
|
|
|
@PostMapping("/downloadFile")
|
|
|
|
|
|
@CrossOrigin
|
|
|
|
|
|
public void downloadFile(HttpServletResponse response) throws IOException {
|
2024-08-21 10:22:47 +08:00
|
|
|
|
String filePath = "doc/2002年6月1日_GB3838-2002地表水环境质量标准.pdf";
|
|
|
|
|
|
File file = new File(filePath);
|
2024-08-21 09:34:06 +08:00
|
|
|
|
if (!file.exists()) {
|
2024-08-21 10:22:47 +08:00
|
|
|
|
new FileNotFoundException("文件不存在!");
|
2024-08-21 09:34:06 +08:00
|
|
|
|
}
|
2024-08-21 13:06:59 +08:00
|
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
|
|
|
response.setContentType("application/octet-stream; charset=UTF-8");
|
|
|
|
|
|
response.setHeader("content-disposition", "attachment;filename*=utf-8'zh_cn'" + URLEncoder.encode("GB3838-2002地表水环境质量标准.pdf", "UTF-8"));
|
2024-08-21 10:22:47 +08:00
|
|
|
|
InputStream inputStream = null;
|
2024-08-21 09:34:06 +08:00
|
|
|
|
OutputStream outputStream = null;
|
|
|
|
|
|
try {
|
2024-08-21 10:22:47 +08:00
|
|
|
|
inputStream = this.getClass().getClassLoader().getResourceAsStream(filePath);
|
2024-08-21 09:34:06 +08:00
|
|
|
|
outputStream = response.getOutputStream();
|
|
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
|
|
int len = 0;
|
|
|
|
|
|
while ((len = inputStream.read(buffer)) != -1) {
|
|
|
|
|
|
outputStream.write(buffer, 0, len);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
inputStream.close();
|
|
|
|
|
|
outputStream.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-07-10 14:04:43 +08:00
|
|
|
|
}
|