添加设备冗余字段

This commit is contained in:
2024-05-22 22:36:21 +08:00
parent e5e197739c
commit 8c965a4838
5 changed files with 83 additions and 58 deletions

View File

@@ -47,6 +47,11 @@ public class DeviceController {
return this.service.getById(request.getId());
}
@PostMapping("/workOrderCount")
public Object workOrderCount(@RequestBody IdRequest request) {
return this.service.workOrderCount(request.getId());
}
@PostMapping("/list")
public Page<DeviceDto> list(@RequestBody CommonQuery request) {
return this.service.list(request);

View File

@@ -3,6 +3,8 @@ package cn.lihongjie.coal.device.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import cn.lihongjie.coal.device.entity.DevicePartVo;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.persistence.ManyToOne;
import lombok.Data;
@@ -39,23 +41,23 @@ public class CreateDeviceDto extends OrgCommonDto {
private List<DevicePartVo> parts;
private Double dReserve1;
private Double dReserve2;
private Double dReserve3;
private Double dReserve4;
private Double dReserve5;
@JsonProperty("dReserve1") private Double dReserve1;
@JsonProperty("dReserve2") private Double dReserve2;
@JsonProperty("dReserve3") private Double dReserve3;
@JsonProperty("dReserve4") private Double dReserve4;
@JsonProperty("dReserve5") private Double dReserve5;
private String sReserve1;
private String sReserve2;
private String sReserve3;
private String sReserve4;
private String sReserve5;
@JsonProperty("sReserve1") private String sReserve1;
@JsonProperty("sReserve2") private String sReserve2;
@JsonProperty("sReserve3") private String sReserve3;
@JsonProperty("sReserve4") private String sReserve4;
@JsonProperty("sReserve5") private String sReserve5;
private LocalDateTime dtReserve1;
private LocalDateTime dtReserve2;
private LocalDateTime dtReserve3;
private LocalDateTime dtReserve4;
private LocalDateTime dtReserve5;
@JsonProperty("dtReserve1") private LocalDateTime dtReserve1;
@JsonProperty("dtReserve2") private LocalDateTime dtReserve2;
@JsonProperty("dtReserve3") private LocalDateTime dtReserve3;
@JsonProperty("dtReserve4") private LocalDateTime dtReserve4;
@JsonProperty("dtReserve5") private LocalDateTime dtReserve5;

View File

@@ -6,6 +6,8 @@ import cn.lihongjie.coal.common.DictCode;
import cn.lihongjie.coal.device.entity.DevicePartVo;
import cn.lihongjie.coal.pojoProcessor.DictTranslate;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.persistence.ManyToOne;
import lombok.Data;
@@ -59,21 +61,21 @@ public class DeviceDto extends OrgCommonDto {
private String archiveStatusName;
private Double dReserve1;
private Double dReserve2;
private Double dReserve3;
private Double dReserve4;
private Double dReserve5;
@JsonProperty("dReserve1") private Double dReserve1;
@JsonProperty("dReserve2") private Double dReserve2;
@JsonProperty("dReserve3") private Double dReserve3;
@JsonProperty("dReserve4") private Double dReserve4;
@JsonProperty("dReserve5") private Double dReserve5;
private String sReserve1;
private String sReserve2;
private String sReserve3;
private String sReserve4;
private String sReserve5;
@JsonProperty("sReserve1") private String sReserve1;
@JsonProperty("sReserve2") private String sReserve2;
@JsonProperty("sReserve3") private String sReserve3;
@JsonProperty("sReserve4") private String sReserve4;
@JsonProperty("sReserve5") private String sReserve5;
private LocalDateTime dtReserve1;
private LocalDateTime dtReserve2;
private LocalDateTime dtReserve3;
private LocalDateTime dtReserve4;
private LocalDateTime dtReserve5;
@JsonProperty("dtReserve1") private LocalDateTime dtReserve1;
@JsonProperty("dtReserve2") private LocalDateTime dtReserve2;
@JsonProperty("dtReserve3") private LocalDateTime dtReserve3;
@JsonProperty("dtReserve4") private LocalDateTime dtReserve4;
@JsonProperty("dtReserve5") private LocalDateTime dtReserve5;
}

View File

@@ -3,6 +3,8 @@ package cn.lihongjie.coal.device.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import cn.lihongjie.coal.device.entity.DevicePartVo;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.persistence.ManyToOne;
import lombok.Data;
@@ -37,21 +39,21 @@ public class UpdateDeviceDto extends OrgCommonDto {
private List<DevicePartVo> parts;
private Double dReserve1;
private Double dReserve2;
private Double dReserve3;
private Double dReserve4;
private Double dReserve5;
@JsonProperty("dReserve1") private Double dReserve1;
@JsonProperty("dReserve2") private Double dReserve2;
@JsonProperty("dReserve3") private Double dReserve3;
@JsonProperty("dReserve4") private Double dReserve4;
@JsonProperty("dReserve5") private Double dReserve5;
private String sReserve1;
private String sReserve2;
private String sReserve3;
private String sReserve4;
private String sReserve5;
@JsonProperty("sReserve1") private String sReserve1;
@JsonProperty("sReserve2") private String sReserve2;
@JsonProperty("sReserve3") private String sReserve3;
@JsonProperty("sReserve4") private String sReserve4;
@JsonProperty("sReserve5") private String sReserve5;
private LocalDateTime dtReserve1;
private LocalDateTime dtReserve2;
private LocalDateTime dtReserve3;
private LocalDateTime dtReserve4;
private LocalDateTime dtReserve5;
@JsonProperty("dtReserve1") private LocalDateTime dtReserve1;
@JsonProperty("dtReserve2") private LocalDateTime dtReserve2;
@JsonProperty("dtReserve3") private LocalDateTime dtReserve3;
@JsonProperty("dtReserve4") private LocalDateTime dtReserve4;
@JsonProperty("dtReserve5") private LocalDateTime dtReserve5;
}

View File

@@ -12,6 +12,8 @@ import cn.lihongjie.coal.device.mapper.DeviceMapper;
import cn.lihongjie.coal.device.repository.DeviceRepository;
import cn.lihongjie.coal.exception.BizException;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.JoinType;
@@ -44,9 +46,11 @@ public class DeviceService extends BaseService<DeviceEntity, DeviceRepository> {
return getById(entity.getId());
}
@PersistenceContext EntityManager em;
public DeviceDto update(UpdateDeviceDto request) {
DeviceEntity entity = this.repository.get(request.getId());
if (this.repository.containArchived(request.getId())){
if (this.repository.containArchived(request.getId())) {
throw new BizException("部分数据已归档,无法编辑或删除");
}
this.mapper.updateEntity(entity, request);
@@ -56,18 +60,6 @@ public class DeviceService extends BaseService<DeviceEntity, DeviceRepository> {
return getById(entity.getId());
}
public void delete(IdRequest request) {
if (this.repository.containArchived(request)){
throw new BizException("部分数据已归档,无法编辑或删除");
}
if (this.repository.isLinked(request.getIds())) {
throw new BizException("部分数据已被关联,无法删除");
}
this.repository.deleteAllById(request.getIds());
}
public DeviceDto getById(String id) {
DeviceEntity entity = repository.get(id);
@@ -115,4 +107,26 @@ public class DeviceService extends BaseService<DeviceEntity, DeviceRepository> {
public void unarchive(IdRequest dto) {
this.repository.unArchive(dto);
}
public void delete(IdRequest request) {
if (this.repository.containArchived(request)) {
throw new BizException("部分数据已归档,无法编辑或删除");
}
if (this.repository.isLinked(request.getIds())) {
throw new BizException("部分数据已被关联,无法删除");
}
this.repository.deleteAllById(request.getIds());
}
public Object workOrderCount(String id) {
return em.createQuery(
"select type as type, count(1) as cnt from DeviceWorkOrderEntity where device.id = :id group by type", DeviceWorkOrderSummary.class)
.setParameter("id", id)
.getResultList();
}
record DeviceWorkOrderSummary(String type, Long cnt) {}
}