首页供水、水质接口优化

master
chenxiwang 2024-07-23 14:59:39 +08:00
parent 8199b3e63d
commit 4945410a8e
3 changed files with 81 additions and 18 deletions

View File

@ -1,6 +1,8 @@
package com.gunshi.project.xyt.controller; package com.gunshi.project.xyt.controller;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -8,7 +10,9 @@ import com.gunshi.core.result.R;
import com.gunshi.project.xyt.entity.vo.OsmoticWaterRVo; import com.gunshi.project.xyt.entity.vo.OsmoticWaterRVo;
import com.gunshi.project.xyt.listener.OsmoticWaterRImportListener; import com.gunshi.project.xyt.listener.OsmoticWaterRImportListener;
import com.gunshi.project.xyt.model.OsmoticWaterR; import com.gunshi.project.xyt.model.OsmoticWaterR;
import com.gunshi.project.xyt.model.OsmoticWaterRule;
import com.gunshi.project.xyt.service.OsmoticWaterRService; import com.gunshi.project.xyt.service.OsmoticWaterRService;
import com.gunshi.project.xyt.service.OsmoticWaterRuleService;
import com.gunshi.project.xyt.util.ConvertUtil; import com.gunshi.project.xyt.util.ConvertUtil;
import com.gunshi.project.xyt.util.DateUtil; import com.gunshi.project.xyt.util.DateUtil;
import com.gunshi.project.xyt.util.ExcelUtil; import com.gunshi.project.xyt.util.ExcelUtil;
@ -35,7 +39,10 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* : * :
@ -50,6 +57,9 @@ public class OsmoticWaterRController {
@Autowired @Autowired
private OsmoticWaterRService service; private OsmoticWaterRService service;
@Autowired
private OsmoticWaterRuleService osmoticWaterRuleService;
@Operation(summary = "新增") @Operation(summary = "新增")
@PostMapping("/insert") @PostMapping("/insert")
public R<OsmoticWaterR> insert(@Validated(Insert.class) @RequestBody OsmoticWaterR dto) { public R<OsmoticWaterR> insert(@Validated(Insert.class) @RequestBody OsmoticWaterR dto) {
@ -72,11 +82,41 @@ public class OsmoticWaterRController {
@Operation(summary = "获取最新一条数据") @Operation(summary = "获取最新一条数据")
@PostMapping("/getLastData") @PostMapping("/getLastData")
public R<OsmoticWaterR> getLastData() { public R<Map<String, Object>> getLastData() {
Map<String, Object> resMap = new HashMap<>();
QueryWrapper qw = new QueryWrapper<>(); QueryWrapper qw = new QueryWrapper<>();
qw.orderBy(true, false, "tm"); qw.orderBy(true, false, "tm").last(" limit 1");
OsmoticWaterR result = service.getOne(qw); OsmoticWaterR osmoticWaterR = service.getOne(qw);
return R.ok(result); 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);
} }
@Operation(summary = "列表") @Operation(summary = "列表")

View File

@ -1,22 +1,32 @@
package com.gunshi.project.xyt.controller; package com.gunshi.project.xyt.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import java.io.Serializable;
import com.gunshi.core.result.R; import java.util.Calendar;
import com.gunshi.project.xyt.model.StWaterRReal; import java.util.List;
import com.gunshi.project.xyt.service.StWaterRRealService;
import com.gunshi.project.xyt.validate.markers.Insert;
import com.gunshi.project.xyt.validate.markers.Query;
import com.gunshi.project.xyt.validate.markers.Update;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; 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.RestController;
import java.io.Serializable; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.gunshi.core.result.R;
import com.gunshi.project.xyt.model.ResMonthEcoFlow;
import com.gunshi.project.xyt.model.StWaterRReal;
import com.gunshi.project.xyt.service.ResMonthEcoFlowService;
import com.gunshi.project.xyt.service.StWaterRRealService;
import com.gunshi.project.xyt.validate.markers.Insert;
import com.gunshi.project.xyt.validate.markers.Update;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
/** /**
* : * :
* author: xusan * author: xusan
@ -30,12 +40,21 @@ public class StWaterRRealController {
@Autowired @Autowired
private StWaterRRealService service; private StWaterRRealService service;
@Autowired
private ResMonthEcoFlowService resMonthEcoFlowService;
@Operation(summary = "根据测站编码查询实时供水量") @Operation(summary = "根据测站编码查询实时供水量")
@PostMapping("/getByStcd/{stcd}") @PostMapping("/getByStcd/{stcd}")
public R<StWaterRReal> getById(@Schema(name = "stcd", description = "测站编码")@PathVariable("stcd") @NotNull String stcd) { public R<StWaterRReal> getById(@Schema(name = "stcd", description = "测站编码")@PathVariable("stcd") @NotNull String stcd) {
QueryWrapper<StWaterRReal> qw = new QueryWrapper<>(); QueryWrapper<StWaterRReal> qw = new QueryWrapper<>();
qw.eq("stcd", stcd).orderBy(true, false, "tm"); qw.eq("stcd", stcd).orderBy(true, false, "tm");
StWaterRReal result = service.getOne(qw); StWaterRReal result = service.getOne(qw);
// 获取当月核定流量
if (ObjectUtils.isNotEmpty(result)) {
ResMonthEcoFlow resMonthEcoFlow = resMonthEcoFlowService.getOne(
new QueryWrapper<ResMonthEcoFlow>().eq("month", Calendar.getInstance().get(Calendar.MONTH) + 1));
result.setResMonthEcoFlow(resMonthEcoFlow);
}
return R.ok(result); return R.ok(result);
} }

View File

@ -63,4 +63,8 @@ public class StWaterRReal implements Serializable {
// @Size(max = 0,message = "水量最大长度要小于 0") // @Size(max = 0,message = "水量最大长度要小于 0")
private String v; private String v;
// 月核定流量
@TableField(exist = false)
private ResMonthEcoFlow resMonthEcoFlow;
} }