118 lines
4.3 KiB
Java
118 lines
4.3 KiB
Java
package com.gunshi.project.hsz.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.gunshi.core.result.R;
|
|
import com.gunshi.project.hsz.entity.so.OsmoticDevicePage;
|
|
import com.gunshi.project.hsz.entity.vo.HomeOsmoticPressDeviceVo;
|
|
import com.gunshi.project.hsz.model.OsmoticPressDevice;
|
|
import com.gunshi.project.hsz.service.FileAssociationsService;
|
|
import com.gunshi.project.hsz.service.OsmoticPressDeviceService;
|
|
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.media.Schema;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
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.util.Date;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
|
|
/**
|
|
* 描述: 渗压设备表
|
|
* author: xusan
|
|
* date: 2024-07-08 17:40:37
|
|
*/
|
|
@Tag(name = "渗压设备表")
|
|
@RestController
|
|
@RequestMapping(value="/osmoticPressDevice")
|
|
public class OsmoticPressDeviceController extends AbstractCommonFileController{
|
|
|
|
@Autowired
|
|
private OsmoticPressDeviceService service;
|
|
|
|
@Autowired
|
|
private FileAssociationsService fileService;
|
|
|
|
@Operation(summary = "新增")
|
|
@PostMapping("/insert")
|
|
public R<OsmoticPressDevice> insert(@Validated(Insert.class) @RequestBody OsmoticPressDevice dto) {
|
|
if (Objects.nonNull(service.getById(dto.getStationCode()))) {
|
|
throw new IllegalArgumentException("当前编号已存在");
|
|
}
|
|
dto.setCreateTime(new Date());
|
|
boolean result = service.save(dto);
|
|
if (result){
|
|
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getStationCode());
|
|
}
|
|
return R.ok(result ? dto : null);
|
|
}
|
|
|
|
@Operation(summary = "修改")
|
|
@PostMapping("/update")
|
|
public R<OsmoticPressDevice> update(@Validated(Update.class) @RequestBody OsmoticPressDevice dto) {
|
|
if (Objects.isNull(service.getById(dto.getStationCode()))) {
|
|
throw new IllegalArgumentException("当前数据不存在");
|
|
}
|
|
dto.setCreateTime(null);
|
|
boolean result = service.updateById(dto);
|
|
if (result){
|
|
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getStationCode());
|
|
}
|
|
return R.ok(result ? dto : null);
|
|
}
|
|
|
|
@Operation(summary = "删除")
|
|
@GetMapping("/del/{id}")
|
|
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
|
if (Objects.isNull(service.getById(id))) {
|
|
throw new IllegalArgumentException("当前数据不存在");
|
|
}
|
|
return R.ok(service.removeById(id));
|
|
}
|
|
|
|
@Operation(summary = "列表")
|
|
@PostMapping("/list")
|
|
public R<List<OsmoticPressDevice>> list() {
|
|
return R.ok(service.lambdaQuery().list());
|
|
}
|
|
|
|
@Operation(summary = "分页")
|
|
@PostMapping("/page")
|
|
public R<Page<OsmoticPressDevice>> page(@RequestBody @Validated OsmoticDevicePage page) {
|
|
LambdaQueryWrapper<OsmoticPressDevice> query = Wrappers.lambdaQuery();
|
|
|
|
if (ObjectUtils.isNotNull(page.getStationCode())) {
|
|
query.like(OsmoticPressDevice::getStationCode, page.getStationCode());
|
|
}
|
|
if (ObjectUtils.isNotNull(page.getDeviceCode())) {
|
|
query.like(OsmoticPressDevice::getDeviceName, page.getDeviceCode());
|
|
}
|
|
|
|
query.orderByDesc(OsmoticPressDevice::getCreateTime);
|
|
|
|
Page<OsmoticPressDevice> data = service.page(page.getPageSo().toPage(), query);
|
|
data.getRecords().forEach(o -> o.setFiles(
|
|
fileService.getFiles(getGroupId(),o.getStationCode())
|
|
));
|
|
return R.ok(data);
|
|
}
|
|
|
|
|
|
@Operation(summary = "详情和监测数据查询")
|
|
@PostMapping("/getDetailsAndMonitoringDataList")
|
|
public R<List<HomeOsmoticPressDeviceVo>> getDetailsAndMonitoringDataList() {
|
|
return R.ok(service.getDetailsAndMonitoringDataList());
|
|
}
|
|
|
|
@Override
|
|
public String getGroupId() {
|
|
return "OsmoticPressDevice";
|
|
}
|
|
} |