mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
环保管理相关接口
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package cn.lihongjie.coal.emDevice.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.OrgScope;
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.emDevice.dto.CreateEmDeviceDto;
|
||||
import cn.lihongjie.coal.emDevice.dto.EmDeviceDto;
|
||||
import cn.lihongjie.coal.emDevice.dto.UpdateEmDeviceDto;
|
||||
import cn.lihongjie.coal.emDevice.service.EmDeviceService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
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;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/emDevice")
|
||||
@SysLog(module = "环保设备管理")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class EmDeviceController {
|
||||
@Autowired private EmDeviceService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public EmDeviceDto create(@RequestBody CreateEmDeviceDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public EmDeviceDto update(@RequestBody UpdateEmDeviceDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public EmDeviceDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<EmDeviceDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
|
||||
@PostMapping("/archive")
|
||||
public Object archive(@RequestBody IdRequest request) {
|
||||
this.service.archive(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/unarchive")
|
||||
public Object unarchive(@RequestBody IdRequest request) {
|
||||
this.service.unarchive(request);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package cn.lihongjie.coal.emDevice.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.emDevice.entity.EmDeviceEntity;
|
||||
import cn.lihongjie.coal.errorMsg.ErrorMsgCode;
|
||||
import cn.lihongjie.coal.validator.OrgUniq;
|
||||
import cn.lihongjie.coal.validator.RequireCode;
|
||||
import cn.lihongjie.coal.validator.RequireName;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
@RequireName
|
||||
@RequireCode
|
||||
|
||||
@OrgUniq(fields = {"code"}, message = ErrorMsgCode.UNIQ_CODE, entityClass = EmDeviceEntity.class)
|
||||
@OrgUniq(fields = {"name"}, message = ErrorMsgCode.UNIQ_NAME, entityClass = EmDeviceEntity.class)
|
||||
public class CreateEmDeviceDto extends OrgCommonDto {
|
||||
|
||||
String supplier;
|
||||
|
||||
@ManyToOne
|
||||
String thirdAccount;
|
||||
|
||||
@Comment("设备类型")
|
||||
private String deviceType;
|
||||
|
||||
private String location;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.lihongjie.coal.emDevice.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.dto.EmDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.thirdAccount.dto.ThirdAccountDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class EmDeviceDto extends OrgCommonDto {
|
||||
|
||||
|
||||
EmDeviceSupplierDto supplier;
|
||||
|
||||
ThirdAccountDto thirdAccount;
|
||||
|
||||
@Comment("设备类型")
|
||||
private String deviceType;
|
||||
|
||||
private String location;
|
||||
private String archiveStatus;
|
||||
|
||||
private String archiveStatusName;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package cn.lihongjie.coal.emDevice.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.emDevice.entity.EmDeviceEntity;
|
||||
import cn.lihongjie.coal.errorMsg.ErrorMsgCode;
|
||||
import cn.lihongjie.coal.validator.OrgUniq;
|
||||
import cn.lihongjie.coal.validator.RequireCode;
|
||||
import cn.lihongjie.coal.validator.RequireName;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
@RequireName
|
||||
@RequireCode
|
||||
|
||||
@OrgUniq(fields = {"code"}, message = ErrorMsgCode.UNIQ_CODE, entityClass = EmDeviceEntity.class)
|
||||
@OrgUniq(fields = {"name"}, message = ErrorMsgCode.UNIQ_NAME, entityClass = EmDeviceEntity.class)
|
||||
public class UpdateEmDeviceDto extends OrgCommonDto {
|
||||
|
||||
String supplier;
|
||||
|
||||
@ManyToOne
|
||||
String thirdAccount;
|
||||
|
||||
@Comment("设备类型")
|
||||
private String deviceType;
|
||||
|
||||
private String location;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package cn.lihongjie.coal.emDevice.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.entity.EmDeviceSupplierEntity;
|
||||
import cn.lihongjie.coal.thirdAccount.entity.ThirdAccountEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Formula;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class EmDeviceEntity extends OrgCommonEntity {
|
||||
|
||||
@ManyToOne EmDeviceSupplierEntity supplier;
|
||||
|
||||
@ManyToOne ThirdAccountEntity thirdAccount;
|
||||
|
||||
@Comment("设备类型")
|
||||
private String deviceType;
|
||||
|
||||
@Formula(
|
||||
"(select i.name\n"
|
||||
+ "from t_dictionary d,\n"
|
||||
+ " t_dictionary_item i\n"
|
||||
+ "where d.id = i.dictionary_id\n"
|
||||
+ " and d.code = 'em.device.type'\n"
|
||||
+ " and i.code = device_type)")
|
||||
private String deviceTypeName;
|
||||
|
||||
private String location;
|
||||
|
||||
@Comment("归档状态")
|
||||
@ColumnDefault("'0'")
|
||||
private String archiveStatus = "0";
|
||||
|
||||
@Formula(
|
||||
"(select i.name\n"
|
||||
+ "from t_dictionary d,\n"
|
||||
+ " t_dictionary_item i\n"
|
||||
+ "where d.id = i.dictionary_id\n"
|
||||
+ " and d.code = 'archiveStatus'\n"
|
||||
+ " and i.code = archive_status)")
|
||||
private String archiveStatusName;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.lihongjie.coal.emDevice.mapper;
|
||||
|
||||
import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.emDevice.dto.CreateEmDeviceDto;
|
||||
import cn.lihongjie.coal.emDevice.dto.EmDeviceDto;
|
||||
import cn.lihongjie.coal.emDevice.dto.UpdateEmDeviceDto;
|
||||
import cn.lihongjie.coal.emDevice.entity.EmDeviceEntity;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.control.DeepClone;
|
||||
|
||||
@Mapper(
|
||||
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class, CommonEntityMapper.class},
|
||||
mappingControl = DeepClone.class)
|
||||
public interface EmDeviceMapper
|
||||
extends BaseMapper<EmDeviceEntity, EmDeviceDto, CreateEmDeviceDto, UpdateEmDeviceDto> {}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.lihongjie.coal.emDevice.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.emDevice.entity.EmDeviceEntity;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface EmDeviceRepository extends BaseRepository<EmDeviceEntity> {}
|
||||
@@ -0,0 +1,120 @@
|
||||
package cn.lihongjie.coal.emDevice.service;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.ArchiveUtils;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.emDevice.dto.CreateEmDeviceDto;
|
||||
import cn.lihongjie.coal.emDevice.dto.EmDeviceDto;
|
||||
import cn.lihongjie.coal.emDevice.dto.UpdateEmDeviceDto;
|
||||
import cn.lihongjie.coal.emDevice.entity.EmDeviceEntity;
|
||||
import cn.lihongjie.coal.emDevice.mapper.EmDeviceMapper;
|
||||
import cn.lihongjie.coal.emDevice.repository.EmDeviceRepository;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class EmDeviceService extends BaseService<EmDeviceEntity, EmDeviceRepository> {
|
||||
@Autowired private EmDeviceRepository repository;
|
||||
|
||||
@Autowired private EmDeviceMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
public EmDeviceDto create(CreateEmDeviceDto request) {
|
||||
EmDeviceEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public EmDeviceDto update(UpdateEmDeviceDto request) {
|
||||
EmDeviceEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
EmDeviceEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
EmDeviceEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
public EmDeviceDto getById(String id) {
|
||||
EmDeviceEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<EmDeviceDto> list(CommonQuery query) {
|
||||
Page<EmDeviceEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
EmDeviceEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
EmDeviceEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package cn.lihongjie.coal.emDeviceData.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.OrgScope;
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.emDeviceData.dto.CreateEmDeviceDataDto;
|
||||
import cn.lihongjie.coal.emDeviceData.dto.EmDeviceDataDto;
|
||||
import cn.lihongjie.coal.emDeviceData.dto.UpdateEmDeviceDataDto;
|
||||
import cn.lihongjie.coal.emDeviceData.service.EmDeviceDataService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
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;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/emDeviceData")
|
||||
@SysLog(module = "环保设备数据")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class EmDeviceDataController {
|
||||
@Autowired private EmDeviceDataService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public EmDeviceDataDto create(@RequestBody CreateEmDeviceDataDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public EmDeviceDataDto update(@RequestBody UpdateEmDeviceDataDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public EmDeviceDataDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<EmDeviceDataDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package cn.lihongjie.coal.emDeviceData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class CreateEmDeviceDataDto extends OrgCommonDto {
|
||||
|
||||
private String deviceId;
|
||||
|
||||
private LocalDateTime time;
|
||||
|
||||
@Comment("Pm2.5")
|
||||
private Double pm25;
|
||||
|
||||
@Comment("Pm10")
|
||||
private Double pm10;
|
||||
|
||||
@Comment("噪声")
|
||||
private Double noise;
|
||||
|
||||
@Comment("温度")
|
||||
private Double tem;
|
||||
|
||||
@Comment("湿度")
|
||||
private Double hum;
|
||||
|
||||
@Comment("风力")
|
||||
private Double wp;
|
||||
|
||||
@Comment("风速")
|
||||
private Double ws;
|
||||
|
||||
@Comment("八风向")
|
||||
private Double wd8;
|
||||
|
||||
@Comment("风向")
|
||||
private Double wd360;
|
||||
|
||||
@Comment("悬浮微粒")
|
||||
private Double tsp;
|
||||
|
||||
@Comment("大气压")
|
||||
private Double atm;
|
||||
|
||||
@Comment("光照")
|
||||
private Double lux;
|
||||
|
||||
@Comment("一氧化碳")
|
||||
private Double co;
|
||||
|
||||
@Comment("二氧化硫")
|
||||
private Double so2;
|
||||
|
||||
@Comment("二氧化氮")
|
||||
private Double no2;
|
||||
|
||||
@Comment("臭氧")
|
||||
private Double o3;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package cn.lihongjie.coal.emDeviceData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class EmDeviceDataDto extends OrgCommonDto {
|
||||
|
||||
private String deviceId;
|
||||
|
||||
private LocalDateTime time;
|
||||
|
||||
@Comment("Pm2.5")
|
||||
private Double pm25;
|
||||
|
||||
@Comment("Pm10")
|
||||
private Double pm10;
|
||||
|
||||
@Comment("噪声")
|
||||
private Double noise;
|
||||
|
||||
@Comment("温度")
|
||||
private Double tem;
|
||||
|
||||
@Comment("湿度")
|
||||
private Double hum;
|
||||
|
||||
@Comment("风力")
|
||||
private Double wp;
|
||||
|
||||
@Comment("风速")
|
||||
private Double ws;
|
||||
|
||||
@Comment("八风向")
|
||||
private Double wd8;
|
||||
|
||||
@Comment("风向")
|
||||
private Double wd360;
|
||||
|
||||
@Comment("悬浮微粒")
|
||||
private Double tsp;
|
||||
|
||||
@Comment("大气压")
|
||||
private Double atm;
|
||||
|
||||
@Comment("光照")
|
||||
private Double lux;
|
||||
|
||||
@Comment("一氧化碳")
|
||||
private Double co;
|
||||
|
||||
@Comment("二氧化硫")
|
||||
private Double so2;
|
||||
|
||||
@Comment("二氧化氮")
|
||||
private Double no2;
|
||||
|
||||
@Comment("臭氧")
|
||||
private Double o3;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package cn.lihongjie.coal.emDeviceData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class UpdateEmDeviceDataDto extends OrgCommonDto {
|
||||
private String deviceId;
|
||||
|
||||
private LocalDateTime time;
|
||||
|
||||
@Comment("Pm2.5")
|
||||
private Double pm25;
|
||||
|
||||
@Comment("Pm10")
|
||||
private Double pm10;
|
||||
|
||||
@Comment("噪声")
|
||||
private Double noise;
|
||||
|
||||
@Comment("温度")
|
||||
private Double tem;
|
||||
|
||||
@Comment("湿度")
|
||||
private Double hum;
|
||||
|
||||
@Comment("风力")
|
||||
private Double wp;
|
||||
|
||||
@Comment("风速")
|
||||
private Double ws;
|
||||
|
||||
@Comment("八风向")
|
||||
private Double wd8;
|
||||
|
||||
@Comment("风向")
|
||||
private Double wd360;
|
||||
|
||||
@Comment("悬浮微粒")
|
||||
private Double tsp;
|
||||
|
||||
@Comment("大气压")
|
||||
private Double atm;
|
||||
|
||||
@Comment("光照")
|
||||
private Double lux;
|
||||
|
||||
@Comment("一氧化碳")
|
||||
private Double co;
|
||||
|
||||
@Comment("二氧化硫")
|
||||
private Double so2;
|
||||
|
||||
@Comment("二氧化氮")
|
||||
private Double no2;
|
||||
|
||||
@Comment("臭氧")
|
||||
private Double o3;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package cn.lihongjie.coal.emDeviceData.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* pm25 float Pm2.5 pm10 float Pm10 noise float 噪声 tem float 温度 hum float 湿度 wp float 风力 ws float 风速
|
||||
* wd8 float 八风向 wd360 float 风向 tsp float 悬浮微粒 atm float 大气压 lux float 光照 co float 一氧化碳 so2 float
|
||||
* 二氧化硫 no2 float 二氧化氮 o3 float 臭氧
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
public class EmDeviceDataEntity extends OrgCommonEntity {
|
||||
|
||||
private String deviceId;
|
||||
|
||||
private LocalDateTime time;
|
||||
|
||||
@Comment("Pm2.5")
|
||||
private Double pm25;
|
||||
|
||||
@Comment("Pm10")
|
||||
private Double pm10;
|
||||
|
||||
@Comment("噪声")
|
||||
private Double noise;
|
||||
|
||||
@Comment("温度")
|
||||
private Double tem;
|
||||
|
||||
@Comment("湿度")
|
||||
private Double hum;
|
||||
|
||||
@Comment("风力")
|
||||
private Double wp;
|
||||
|
||||
@Comment("风速")
|
||||
private Double ws;
|
||||
|
||||
@Comment("八风向")
|
||||
private Double wd8;
|
||||
|
||||
@Comment("风向")
|
||||
private Double wd360;
|
||||
|
||||
@Comment("悬浮微粒")
|
||||
private Double tsp;
|
||||
|
||||
@Comment("大气压")
|
||||
private Double atm;
|
||||
|
||||
@Comment("光照")
|
||||
private Double lux;
|
||||
|
||||
@Comment("一氧化碳")
|
||||
private Double co;
|
||||
|
||||
@Comment("二氧化硫")
|
||||
private Double so2;
|
||||
|
||||
@Comment("二氧化氮")
|
||||
private Double no2;
|
||||
|
||||
@Comment("臭氧")
|
||||
private Double o3;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.lihongjie.coal.emDeviceData.mapper;
|
||||
|
||||
import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.emDeviceData.dto.CreateEmDeviceDataDto;
|
||||
import cn.lihongjie.coal.emDeviceData.dto.EmDeviceDataDto;
|
||||
import cn.lihongjie.coal.emDeviceData.dto.UpdateEmDeviceDataDto;
|
||||
import cn.lihongjie.coal.emDeviceData.entity.EmDeviceDataEntity;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.control.DeepClone;
|
||||
|
||||
@Mapper(
|
||||
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class, CommonEntityMapper.class},
|
||||
mappingControl = DeepClone.class)
|
||||
public interface EmDeviceDataMapper
|
||||
extends BaseMapper<
|
||||
EmDeviceDataEntity,
|
||||
EmDeviceDataDto,
|
||||
CreateEmDeviceDataDto,
|
||||
UpdateEmDeviceDataDto> {}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.lihongjie.coal.emDeviceData.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.emDeviceData.entity.EmDeviceDataEntity;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface EmDeviceDataRepository extends BaseRepository<EmDeviceDataEntity> {}
|
||||
@@ -0,0 +1,73 @@
|
||||
package cn.lihongjie.coal.emDeviceData.service;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.emDeviceData.dto.CreateEmDeviceDataDto;
|
||||
import cn.lihongjie.coal.emDeviceData.dto.EmDeviceDataDto;
|
||||
import cn.lihongjie.coal.emDeviceData.dto.UpdateEmDeviceDataDto;
|
||||
import cn.lihongjie.coal.emDeviceData.entity.EmDeviceDataEntity;
|
||||
import cn.lihongjie.coal.emDeviceData.mapper.EmDeviceDataMapper;
|
||||
import cn.lihongjie.coal.emDeviceData.repository.EmDeviceDataRepository;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class EmDeviceDataService extends BaseService<EmDeviceDataEntity, EmDeviceDataRepository> {
|
||||
@Autowired private EmDeviceDataRepository repository;
|
||||
|
||||
@Autowired private EmDeviceDataMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
public EmDeviceDataDto create(CreateEmDeviceDataDto request) {
|
||||
EmDeviceDataEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public EmDeviceDataDto update(UpdateEmDeviceDataDto request) {
|
||||
EmDeviceDataEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
public EmDeviceDataDto getById(String id) {
|
||||
EmDeviceDataEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<EmDeviceDataDto> list(CommonQuery query) {
|
||||
Page<EmDeviceDataEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package cn.lihongjie.coal.emDeviceSupplier.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.OrgScope;
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.dto.CreateEmDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.dto.EmDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.dto.UpdateEmDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.service.EmDeviceSupplierService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
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;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/emDeviceSupplier")
|
||||
@SysLog(module = "环保设备供应商")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class EmDeviceSupplierController {
|
||||
@Autowired private EmDeviceSupplierService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public EmDeviceSupplierDto create(@RequestBody CreateEmDeviceSupplierDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public EmDeviceSupplierDto update(@RequestBody UpdateEmDeviceSupplierDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public EmDeviceSupplierDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<EmDeviceSupplierDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
|
||||
@PostMapping("/archive")
|
||||
public Object archive(@RequestBody IdRequest request) {
|
||||
this.service.archive(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/unarchive")
|
||||
public Object unarchive(@RequestBody IdRequest request) {
|
||||
this.service.unarchive(request);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.emDeviceSupplier.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateEmDeviceSupplierDto extends OrgCommonDto {}
|
||||
@@ -0,0 +1,12 @@
|
||||
package cn.lihongjie.coal.emDeviceSupplier.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class EmDeviceSupplierDto extends OrgCommonDto {
|
||||
private String archiveStatus;
|
||||
|
||||
private String archiveStatusName;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.emDeviceSupplier.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UpdateEmDeviceSupplierDto extends OrgCommonDto {}
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.lihongjie.coal.emDeviceSupplier.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Formula;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class EmDeviceSupplierEntity extends OrgCommonEntity {
|
||||
@Comment("归档状态")
|
||||
@ColumnDefault("'0'")
|
||||
private String archiveStatus = "0";
|
||||
|
||||
@Formula(
|
||||
"(select i.name\n"
|
||||
+ "from t_dictionary d,\n"
|
||||
+ " t_dictionary_item i\n"
|
||||
+ "where d.id = i.dictionary_id\n"
|
||||
+ " and d.code = 'archiveStatus'\n"
|
||||
+ " and i.code = archive_status)")
|
||||
private String archiveStatusName;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.lihongjie.coal.emDeviceSupplier.mapper;
|
||||
|
||||
import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.dto.CreateEmDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.dto.EmDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.dto.UpdateEmDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.entity.EmDeviceSupplierEntity;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.control.DeepClone;
|
||||
|
||||
@Mapper(
|
||||
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class, CommonEntityMapper.class},
|
||||
mappingControl = DeepClone.class)
|
||||
public interface EmDeviceSupplierMapper
|
||||
extends BaseMapper<
|
||||
EmDeviceSupplierEntity,
|
||||
EmDeviceSupplierDto,
|
||||
CreateEmDeviceSupplierDto,
|
||||
UpdateEmDeviceSupplierDto> {}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.lihongjie.coal.emDeviceSupplier.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.entity.EmDeviceSupplierEntity;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface EmDeviceSupplierRepository extends BaseRepository<EmDeviceSupplierEntity> {}
|
||||
@@ -0,0 +1,121 @@
|
||||
package cn.lihongjie.coal.emDeviceSupplier.service;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.ArchiveUtils;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.dto.CreateEmDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.dto.EmDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.dto.UpdateEmDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.entity.EmDeviceSupplierEntity;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.mapper.EmDeviceSupplierMapper;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.repository.EmDeviceSupplierRepository;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class EmDeviceSupplierService
|
||||
extends BaseService<EmDeviceSupplierEntity, EmDeviceSupplierRepository> {
|
||||
@Autowired private EmDeviceSupplierRepository repository;
|
||||
|
||||
@Autowired private EmDeviceSupplierMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
public EmDeviceSupplierDto create(CreateEmDeviceSupplierDto request) {
|
||||
EmDeviceSupplierEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public EmDeviceSupplierDto update(UpdateEmDeviceSupplierDto request) {
|
||||
EmDeviceSupplierEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
EmDeviceSupplierEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
EmDeviceSupplierEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
public EmDeviceSupplierDto getById(String id) {
|
||||
EmDeviceSupplierEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<EmDeviceSupplierDto> list(CommonQuery query) {
|
||||
Page<EmDeviceSupplierEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
EmDeviceSupplierEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
EmDeviceSupplierEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
}
|
||||
}
|
||||
@@ -2529,6 +2529,18 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"code": "em.device.type",
|
||||
"name": "环保设备类型",
|
||||
"item": [
|
||||
{
|
||||
"code": "1",
|
||||
"name": "扬尘检测设备"
|
||||
}
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"code": "thirdAccount.type",
|
||||
"name": "第三方账号类型",
|
||||
|
||||
17
src/main/resources/scripts/dict/enum/emDeviceDataDict.groovy
Normal file
17
src/main/resources/scripts/dict/enum/emDeviceDataDict.groovy
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import cn.lihongjie.coal.emDeviceData.controller.EmDeviceDataController
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(EmDeviceDataController.class)
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(new CommonQuery())
|
||||
|
||||
|
||||
17
src/main/resources/scripts/dict/enum/emDeviceDict.groovy
Normal file
17
src/main/resources/scripts/dict/enum/emDeviceDict.groovy
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import cn.lihongjie.coal.emDevice.controller.EmDeviceController
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(EmDeviceController.class)
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(new CommonQuery())
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import cn.lihongjie.coal.emDeviceSupplier.controller.EmDeviceSupplierController
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(EmDeviceSupplierController.class)
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(new CommonQuery())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user