mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
完善
This commit is contained in:
@@ -685,6 +685,19 @@ public class CommonQuery {
|
||||
private Integer pageSize = Integer.MAX_VALUE;
|
||||
private List<Order> orders;
|
||||
|
||||
private Map<String, String> extras;
|
||||
|
||||
|
||||
public String get(String key, String def){
|
||||
|
||||
if (extras == null){
|
||||
return def;
|
||||
}
|
||||
|
||||
return extras.getOrDefault(key, def);
|
||||
|
||||
}
|
||||
|
||||
public static Path parseKey(Root root, String key) {
|
||||
Iterable<String> parts = Splitter.on(".").trimResults().omitEmptyStrings().split(key);
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public class PurchaseOrderDto extends OrgCommonDto {
|
||||
@Comment("订单开始时间")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
private List<String> weightDataList;
|
||||
// private List<String> weightDataList;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.lihongjie.coal.coalInfo.entity.CoalInfoEntity;
|
||||
import cn.lihongjie.coal.weightDeviceData.entity.WeightDeviceDataEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
|
||||
@@ -30,7 +31,7 @@ public class PurchaseOrderEntity extends OrgCommonEntity {
|
||||
|
||||
|
||||
|
||||
@OneToMany
|
||||
@OneToMany(mappedBy = "purchaseOrder", fetch = FetchType.LAZY)
|
||||
private List<WeightDeviceDataEntity> weightDataList;
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.Ctx;
|
||||
import cn.lihongjie.coal.common.JpaUtils;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.organizationConfig.entity.OrganizationConfigEntity;
|
||||
import cn.lihongjie.coal.organizationConfig.service.OrganizationConfigService;
|
||||
import cn.lihongjie.coal.purchaseOrder.dto.CreatePurchaseOrderDto;
|
||||
@@ -40,9 +41,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -69,6 +69,7 @@ public class PurchaseOrderService
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
@Autowired OrganizationConfigService organizationConfigService;
|
||||
@Autowired private CommonMapper commonMapper;
|
||||
|
||||
@@ -118,47 +119,72 @@ public class PurchaseOrderService
|
||||
PurchaseOrderEntity entity = this.repository.get(request.getId());
|
||||
|
||||
switch (request.getOptType()) {
|
||||
case "0" -> {
|
||||
if (CollectionUtils.isNotEmpty(entity.getWeightDataList())) {
|
||||
case "1" -> {
|
||||
if (CollectionUtils.isNotEmpty(request.getWeightDataList())) {
|
||||
|
||||
Collection<String> toAdd =
|
||||
CollectionUtils.removeAll(
|
||||
request.getWeightDataList(),
|
||||
entity.getWeightDataList().stream()
|
||||
.map(x -> x.getId())
|
||||
.collect(Collectors.toSet()));
|
||||
List<WeightDeviceDataEntity> allById =
|
||||
weightDeviceDataRepository.findAllById(request.getWeightDataList());
|
||||
|
||||
entity.getWeightDataList()
|
||||
.addAll(
|
||||
toAdd.stream()
|
||||
.map(
|
||||
x ->
|
||||
entityManager.getReference(
|
||||
WeightDeviceDataEntity.class,
|
||||
x))
|
||||
.collect(Collectors.toList()));
|
||||
for (WeightDeviceDataEntity data : allById) {
|
||||
|
||||
} else {
|
||||
if (data.getSaleOrder() != null) {
|
||||
throw new BizException("过磅数据" + data.getFlowNumber() + "已经关联销售单");
|
||||
}
|
||||
|
||||
request.setOptType("2");
|
||||
if (data.getPurchaseOrder() !=null){
|
||||
throw new BizException("过磅数据" + data.getFlowNumber() + "已经关联采购单");
|
||||
}
|
||||
data.setPurchaseOrder(entity);
|
||||
}
|
||||
|
||||
updateWeightData(request);
|
||||
weightDeviceDataRepository.saveAll(allById);
|
||||
}
|
||||
}
|
||||
case "1" -> {
|
||||
entity.setWeightDataList(
|
||||
request.getWeightDataList().stream()
|
||||
.map(
|
||||
x ->
|
||||
entityManager.getReference(
|
||||
WeightDeviceDataEntity.class, x))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
case "2" -> {
|
||||
entity.setWeightDataList(
|
||||
entity.getWeightDataList().stream()
|
||||
.filter(x -> !request.getWeightDataList().contains(x.getId()))
|
||||
.collect(Collectors.toList()));
|
||||
entity.getWeightDataList().stream().forEach(x -> x.setPurchaseOrder(null));
|
||||
|
||||
weightDeviceDataRepository.saveAllAndFlush(entity.getWeightDataList());
|
||||
|
||||
List<WeightDeviceDataEntity> allById =
|
||||
weightDeviceDataRepository.findAllById(request.getWeightDataList());
|
||||
|
||||
for (WeightDeviceDataEntity data : allById) {
|
||||
|
||||
if (data.getSaleOrder() != null) {
|
||||
throw new BizException("过磅数据" + data.getFlowNumber() + "已经关联销售单");
|
||||
}
|
||||
|
||||
if (data.getPurchaseOrder() !=null){
|
||||
throw new BizException("过磅数据" + data.getFlowNumber() + "已经关联采购单");
|
||||
}
|
||||
data.setPurchaseOrder(entity);
|
||||
}
|
||||
|
||||
weightDeviceDataRepository.saveAll(allById);
|
||||
}
|
||||
case "3" -> {
|
||||
List<WeightDeviceDataEntity> allById =
|
||||
weightDeviceDataRepository.findAllById(request.getWeightDataList());
|
||||
|
||||
for (WeightDeviceDataEntity data : allById) {
|
||||
|
||||
|
||||
if (data.getSaleOrder() !=null){
|
||||
throw new BizException("过磅数据" + data.getFlowNumber() + "已经关联销售单");
|
||||
}
|
||||
|
||||
if (data.getPurchaseOrder() == null) {
|
||||
throw new BizException("过磅数据" + data.getFlowNumber() + "没有关联采购单");
|
||||
}
|
||||
|
||||
if (!Objects.equals(data.getPurchaseOrder().getId(), entity.getId())) {
|
||||
throw new BizException("过磅数据" + data.getFlowNumber() + "关联采购单不匹配");
|
||||
}
|
||||
|
||||
data.setPurchaseOrder(null);
|
||||
}
|
||||
|
||||
weightDeviceDataRepository.saveAll(allById);
|
||||
}
|
||||
}
|
||||
this.repository.save(entity);
|
||||
|
||||
@@ -79,5 +79,5 @@ public class SaleOrderDto extends OrgCommonDto {
|
||||
@Comment("订单开始时间")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
private List<String> weightDataList;
|
||||
// private List<String> weightDataList;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class SaleOrderEntity extends OrgCommonEntity {
|
||||
|
||||
|
||||
|
||||
@OneToMany
|
||||
@OneToMany(mappedBy = "saleOrder")
|
||||
private List<WeightDeviceDataEntity> weightDataList;
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.Ctx;
|
||||
import cn.lihongjie.coal.common.JpaUtils;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.organizationConfig.entity.OrganizationConfigEntity;
|
||||
import cn.lihongjie.coal.organizationConfig.service.OrganizationConfigService;
|
||||
import cn.lihongjie.coal.saleOrder.dto.CreateSaleOrderDto;
|
||||
@@ -40,15 +41,13 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class SaleOrderService
|
||||
extends BaseService<SaleOrderEntity, SaleOrderRepository> {
|
||||
public class SaleOrderService extends BaseService<SaleOrderEntity, SaleOrderRepository> {
|
||||
@Autowired SequenceService sequenceService;
|
||||
@Autowired WeightDeviceDataRepository weightDeviceDataRepository;
|
||||
@Autowired WeightDeviceDataMapper weightDeviceDataMapper;
|
||||
@@ -115,47 +114,77 @@ public class SaleOrderService
|
||||
SaleOrderEntity entity = this.repository.get(request.getId());
|
||||
|
||||
switch (request.getOptType()) {
|
||||
case "0" -> {
|
||||
if (CollectionUtils.isNotEmpty(entity.getWeightDataList())) {
|
||||
case "1" -> {
|
||||
if (CollectionUtils.isNotEmpty(request.getWeightDataList())) {
|
||||
|
||||
Collection<String> toAdd =
|
||||
CollectionUtils.removeAll(
|
||||
request.getWeightDataList(),
|
||||
entity.getWeightDataList().stream()
|
||||
.map(x -> x.getId())
|
||||
.collect(Collectors.toSet()));
|
||||
List<WeightDeviceDataEntity> allById =
|
||||
weightDeviceDataRepository.findAllById(request.getWeightDataList());
|
||||
|
||||
entity.getWeightDataList()
|
||||
.addAll(
|
||||
toAdd.stream()
|
||||
.map(
|
||||
x ->
|
||||
entityManager.getReference(
|
||||
WeightDeviceDataEntity.class,
|
||||
x))
|
||||
.collect(Collectors.toList()));
|
||||
for (WeightDeviceDataEntity data : allById) {
|
||||
|
||||
} else {
|
||||
if (data.getSaleOrder() != null) {
|
||||
throw new BizException("过磅数据" + data.getFlowNumber() + "已经关联销售单");
|
||||
}
|
||||
|
||||
request.setOptType("2");
|
||||
if (data.getPurchaseOrder() !=null){
|
||||
throw new BizException("过磅数据" + data.getFlowNumber() + "已经关联采购单");
|
||||
}
|
||||
|
||||
updateWeightData(request);
|
||||
|
||||
|
||||
data.setSaleOrder(entity);
|
||||
}
|
||||
|
||||
weightDeviceDataRepository.saveAll(allById);
|
||||
}
|
||||
}
|
||||
case "1" -> {
|
||||
entity.setWeightDataList(
|
||||
request.getWeightDataList().stream()
|
||||
.map(
|
||||
x ->
|
||||
entityManager.getReference(
|
||||
WeightDeviceDataEntity.class, x))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
case "2" -> {
|
||||
entity.setWeightDataList(
|
||||
entity.getWeightDataList().stream()
|
||||
.filter(x -> !request.getWeightDataList().contains(x.getId()))
|
||||
.collect(Collectors.toList()));
|
||||
entity.getWeightDataList().stream().forEach(x -> x.setSaleOrder(null));
|
||||
|
||||
weightDeviceDataRepository.saveAllAndFlush(entity.getWeightDataList());
|
||||
|
||||
List<WeightDeviceDataEntity> allById =
|
||||
weightDeviceDataRepository.findAllById(request.getWeightDataList());
|
||||
|
||||
for (WeightDeviceDataEntity data : allById) {
|
||||
|
||||
if (data.getSaleOrder() != null) {
|
||||
throw new BizException("过磅数据" + data.getFlowNumber() + "已经关联销售单");
|
||||
}
|
||||
|
||||
if (data.getPurchaseOrder() !=null){
|
||||
throw new BizException("过磅数据" + data.getFlowNumber() + "已经关联采购单");
|
||||
}
|
||||
data.setSaleOrder(entity);
|
||||
}
|
||||
|
||||
weightDeviceDataRepository.saveAll(allById);
|
||||
}
|
||||
case "3" -> {
|
||||
List<WeightDeviceDataEntity> allById =
|
||||
weightDeviceDataRepository.findAllById(request.getWeightDataList());
|
||||
|
||||
for (WeightDeviceDataEntity data : allById) {
|
||||
|
||||
|
||||
if (data.getPurchaseOrder() !=null){
|
||||
throw new BizException("过磅数据" + data.getFlowNumber() + "已经关联采购单");
|
||||
}
|
||||
|
||||
if (data.getSaleOrder() == null) {
|
||||
throw new BizException("过磅数据" + data.getFlowNumber() + "没有关联销售单");
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!Objects.equals(data.getSaleOrder().getId(), entity.getId())) {
|
||||
throw new BizException("过磅数据" + data.getFlowNumber() + "关联采购单不匹配");
|
||||
}
|
||||
|
||||
data.setSaleOrder(null);
|
||||
}
|
||||
|
||||
weightDeviceDataRepository.saveAll(allById);
|
||||
}
|
||||
}
|
||||
this.repository.save(entity);
|
||||
|
||||
@@ -2,6 +2,8 @@ package cn.lihongjie.coal.weightDeviceData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.pojoProcessor.DictTranslate;
|
||||
import cn.lihongjie.coal.purchaseOrder.dto.PurchaseOrderDto;
|
||||
import cn.lihongjie.coal.saleOrder.dto.SaleOrderDto;
|
||||
import cn.lihongjie.coal.weightDevice.dto.WeightDeviceDto;
|
||||
|
||||
import jakarta.persistence.FetchType;
|
||||
@@ -19,6 +21,11 @@ public class WeightDeviceDataDto extends OrgCommonDto {
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
private WeightDeviceDto device;
|
||||
|
||||
|
||||
private PurchaseOrderDto purchaseOrder;
|
||||
|
||||
private SaleOrderDto saleOrder;
|
||||
|
||||
@Comment("序号")
|
||||
private Integer sequenceNumber;
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package cn.lihongjie.coal.weightDeviceData.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
import cn.lihongjie.coal.purchaseOrder.entity.PurchaseOrderEntity;
|
||||
import cn.lihongjie.coal.saleOrder.entity.SaleOrderEntity;
|
||||
import cn.lihongjie.coal.weightDevice.entity.WeightDeviceEntity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
@@ -196,6 +198,15 @@ public class WeightDeviceDataEntity extends OrgCommonEntity {
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
private WeightDeviceEntity device;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
private PurchaseOrderEntity purchaseOrder;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
private SaleOrderEntity saleOrder;
|
||||
|
||||
|
||||
|
||||
|
||||
@Comment("序号")
|
||||
private Integer sequenceNumber;
|
||||
|
||||
@@ -278,12 +289,11 @@ public class WeightDeviceDataEntity extends OrgCommonEntity {
|
||||
private String updateUser;
|
||||
|
||||
@Comment("数据更新时间")
|
||||
|
||||
private LocalDateTime dataUpdateTime;
|
||||
|
||||
@Comment("备注")
|
||||
private String remark;
|
||||
|
||||
|
||||
@Comment("打印次数")
|
||||
private Integer printCount;
|
||||
|
||||
@@ -459,10 +469,8 @@ public class WeightDeviceDataEntity extends OrgCommonEntity {
|
||||
@ColumnDefault("'0'")
|
||||
private String archiveStatus = "0";
|
||||
|
||||
|
||||
private LocalDateTime minTime;
|
||||
|
||||
|
||||
private Boolean invalid = false;
|
||||
|
||||
private Boolean finished = true;
|
||||
@@ -487,8 +495,10 @@ public class WeightDeviceDataEntity extends OrgCommonEntity {
|
||||
.min(LocalDateTime::compareTo)
|
||||
.orElse(null);
|
||||
|
||||
|
||||
this.finished = this.pzTime!=null && this.mzTime!=null && this.ecgbTime!=null && this.ycgbTIme!=null;
|
||||
|
||||
this.finished =
|
||||
this.pzTime != null
|
||||
&& this.mzTime != null
|
||||
&& this.ecgbTime != null
|
||||
&& this.ycgbTIme != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,10 +27,7 @@ import com.google.common.base.CaseFormat;
|
||||
import io.vavr.collection.Stream;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import jakarta.persistence.criteria.*;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -327,23 +324,28 @@ where 更新时间>='%s' and 更新时间<='%s'
|
||||
}
|
||||
|
||||
public Page<WeightDeviceDataDto> list(CommonQuery query) {
|
||||
|
||||
|
||||
Specification specification = query.specification(conversionService);
|
||||
|
||||
|
||||
|
||||
|
||||
Page<WeightDeviceDataEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService)
|
||||
.and(
|
||||
new Specification() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root root,
|
||||
CriteriaQuery query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
specification.and(
|
||||
new Specification() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root root,
|
||||
CriteriaQuery query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
|
||||
return criteriaBuilder.or(
|
||||
criteriaBuilder.isNull(root.get("invalid")),
|
||||
criteriaBuilder.isFalse(
|
||||
root.get("invalid")));
|
||||
}
|
||||
}),
|
||||
return criteriaBuilder.or(
|
||||
criteriaBuilder.isNull(root.get("invalid")),
|
||||
criteriaBuilder.isFalse(root.get("invalid")));
|
||||
}
|
||||
}),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
|
||||
Reference in New Issue
Block a user