mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
feat: 完善
This commit is contained in:
@@ -20,6 +20,7 @@ import jakarta.persistence.metamodel.EntityType;
|
||||
import lombok.*;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
@@ -243,6 +244,8 @@ public class CommonQuery {
|
||||
private Integer pageSize = Integer.MAX_VALUE;
|
||||
private List<Order> orders;
|
||||
|
||||
private Boolean distinct;
|
||||
|
||||
private Map<String, String> extras;
|
||||
|
||||
private static Predicate getPredicate(
|
||||
@@ -350,7 +353,8 @@ public class CommonQuery {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) {
|
||||
query.distinct(true);
|
||||
|
||||
query.distinct(BooleanUtils.isTrue(distinct));
|
||||
|
||||
if (CollectionUtils.isNotEmpty(items)) {
|
||||
|
||||
|
||||
@@ -50,5 +50,12 @@ public class WarehouseGoodsSummaryController {
|
||||
@PostMapping("/list")
|
||||
public Page<WarehouseGoodsSummaryDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/summary")
|
||||
public WarehouseGoodsSummaryDto getSummary(@RequestBody CommonQuery request) {
|
||||
return this.service.getSummary(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,10 @@ import cn.lihongjie.coal.warehouseGoodsSummary.entity.WarehouseGoodsSummaryEntit
|
||||
import cn.lihongjie.coal.warehouseGoodsSummary.mapper.WarehouseGoodsSummaryMapper;
|
||||
import cn.lihongjie.coal.warehouseGoodsSummary.repository.WarehouseGoodsSummaryRepository;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.criteria.*;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -19,9 +23,13 @@ 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.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
@@ -77,5 +85,42 @@ public class WarehouseGoodsSummaryService
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
@PersistenceContext EntityManager em;
|
||||
|
||||
public WarehouseGoodsSummaryDto getSummary(CommonQuery query) {
|
||||
|
||||
CriteriaBuilder builder = em.getCriteriaBuilder();
|
||||
CriteriaQuery<WarehouseGoodsSummaryEntity> criteriaQuery = builder.createQuery(WarehouseGoodsSummaryEntity.class);
|
||||
|
||||
Root<WarehouseGoodsSummaryEntity> root = criteriaQuery.from(WarehouseGoodsSummaryEntity.class);
|
||||
|
||||
criteriaQuery = criteriaQuery.multiselect(
|
||||
Arrays.asList(
|
||||
builder.sumAsDouble(root.get("type0Number")).alias("type0Number"),
|
||||
builder.sumAsDouble(root.get("type1Number")).alias("type1Number"),
|
||||
builder.sumAsDouble(root.get("type0Amount")).alias("type0Amount"),
|
||||
builder.sumAsDouble(root.get("type1Amount")).alias("type1Amount")));
|
||||
|
||||
Specification specification = query.specification(conversionService);
|
||||
|
||||
|
||||
|
||||
|
||||
Predicate predicate = specification.toPredicate(root, criteriaQuery, builder);
|
||||
|
||||
criteriaQuery = criteriaQuery.where(predicate);
|
||||
|
||||
|
||||
List<WarehouseGoodsSummaryEntity> resultList = em.createQuery(criteriaQuery).getResultList();
|
||||
|
||||
|
||||
return mapper.toDto(resultList.get(0));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.common.DictCode;
|
||||
import cn.lihongjie.coal.pojoProcessor.DictTranslate;
|
||||
import cn.lihongjie.coal.warehouse.dto.WarehouseDto;
|
||||
import cn.lihongjie.coal.warehouseReceiptDetail.dto.WarehouseReceiptDetailDto;
|
||||
import cn.lihongjie.coal.warehouseReceiptDetail.dto.WarehouseReceiptDetailSimpleDto;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
@@ -49,7 +49,7 @@ public class WarehouseReceiptDto extends OrgCommonDto {
|
||||
|
||||
|
||||
@OneToMany
|
||||
private List<WarehouseReceiptDetailDto> detail;
|
||||
private List<WarehouseReceiptDetailSimpleDto> detail;
|
||||
|
||||
|
||||
@Formula("(select sum(d.number * d.price) from t_warehouse_receipt_detail d where d.receipt_id = id)")
|
||||
@@ -73,4 +73,6 @@ public class WarehouseReceiptDto extends OrgCommonDto {
|
||||
@DictTranslate(dictKey = DictCode.ARCHIVESTATUS)
|
||||
private String archiveStatusName;
|
||||
|
||||
|
||||
private String parent;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package cn.lihongjie.coal.warehouseReceipt.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.common.DictCode;
|
||||
import cn.lihongjie.coal.pojoProcessor.DictTranslate;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class WarehouseReceiptSimpleDto extends OrgCommonDto {
|
||||
|
||||
|
||||
@Comment("单据类型")
|
||||
private String receiptType;
|
||||
|
||||
@DictTranslate(dictKey = DictCode.WAREHOUSE_RECEIPTTYPE)
|
||||
private String receiptTypeName;
|
||||
|
||||
@Comment("单据编号")
|
||||
private String receiptNo;
|
||||
|
||||
@Comment("事由")
|
||||
private String reason;
|
||||
|
||||
@Comment("是由说明")
|
||||
private String reasonDesc;
|
||||
|
||||
|
||||
|
||||
@Comment("单据日期")
|
||||
private LocalDateTime receiptDate;
|
||||
|
||||
|
||||
|
||||
|
||||
private Double amount;
|
||||
|
||||
|
||||
private Double number;
|
||||
|
||||
@Comment("制单人")
|
||||
private String creator;
|
||||
|
||||
|
||||
private String location;
|
||||
@Comment("归档状态")
|
||||
@ColumnDefault("'0'")
|
||||
private String archiveStatus = "0";
|
||||
|
||||
|
||||
|
||||
@DictTranslate(dictKey = DictCode.ARCHIVESTATUS)
|
||||
private String archiveStatusName;
|
||||
|
||||
|
||||
|
||||
private String parent;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import cn.lihongjie.coal.warehouseReceiptDetail.entity.WarehouseReceiptDetailEnt
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
@@ -13,13 +14,15 @@ import org.hibernate.annotations.Comment;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Data()
|
||||
@Entity
|
||||
@jakarta.persistence.Table(
|
||||
indexes =
|
||||
@jakarta.persistence.Index(
|
||||
name = "idx_warehouse_receipt_org_id",
|
||||
columnList = "organization_id"))
|
||||
|
||||
@EqualsAndHashCode(exclude = {"detail", "parent"})
|
||||
public class WarehouseReceiptEntity extends OrgCommonEntity {
|
||||
|
||||
@Comment("单据类型")
|
||||
@@ -68,6 +71,12 @@ public class WarehouseReceiptEntity extends OrgCommonEntity {
|
||||
@ManyToOne(cascade = CascadeType.REMOVE)
|
||||
private WarehouseReceiptEntity receipt1;
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private WarehouseReceiptEntity parent;
|
||||
|
||||
|
||||
|
||||
@Comment("制单人")
|
||||
private String creator;
|
||||
|
||||
@@ -77,4 +86,6 @@ public class WarehouseReceiptEntity extends OrgCommonEntity {
|
||||
@Comment("归档状态")
|
||||
@ColumnDefault("'0'")
|
||||
private String archiveStatus = "0";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,11 @@ package cn.lihongjie.coal.warehouseReceipt.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.Ctx;
|
||||
import cn.lihongjie.coal.common.NumberUtils;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.orderNoRule.service.OrderNoRuleService;
|
||||
import cn.lihongjie.coal.orderNoRule.service.RuleCodeConstant;
|
||||
import cn.lihongjie.coal.warehouseGoods.dto.GoodsCountRequest;
|
||||
import cn.lihongjie.coal.warehouseGoods.dto.WarehouseGoodsDto;
|
||||
import cn.lihongjie.coal.warehouseGoods.service.WarehouseGoodsService;
|
||||
@@ -38,6 +42,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@@ -51,36 +56,174 @@ public class WarehouseReceiptService
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
|
||||
@Autowired
|
||||
WarehouseReceiptDetailRepository warehouseReceiptDetailRepository;
|
||||
@Autowired
|
||||
private WarehouseGoodsService warehouseGoodsService;
|
||||
|
||||
@Autowired WarehouseReceiptDetailRepository warehouseReceiptDetailRepository;
|
||||
@Autowired OrderNoRuleService orderNoRuleService;
|
||||
@Autowired private WarehouseGoodsService warehouseGoodsService;
|
||||
|
||||
public WarehouseReceiptDto create(CreateWarehouseReceiptDto request) {
|
||||
WarehouseReceiptEntity entity = mapper.toEntity(request);
|
||||
|
||||
|
||||
processDetail(entity);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
if (request.getReceiptType().equals("2")) {
|
||||
|
||||
createType2Receipt(entity);
|
||||
}
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理盘库单
|
||||
*
|
||||
* @param entity
|
||||
*/
|
||||
private void createType2Receipt(WarehouseReceiptEntity entity) {
|
||||
|
||||
WarehouseReceiptEntity receipt0 = new WarehouseReceiptEntity();
|
||||
receipt0.setReceiptType("0");
|
||||
receipt0.setReason(entity.getReason());
|
||||
receipt0.setReasonDesc(entity.getReasonDesc());
|
||||
receipt0.setReceiptDate(entity.getReceiptDate());
|
||||
receipt0.setDetail(new ArrayList<>());
|
||||
receipt0.setAmount(0.0);
|
||||
receipt0.setNumber(0.0);
|
||||
receipt0.setReceipt0(null);
|
||||
receipt0.setReceipt1(null);
|
||||
receipt0.setLocation(entity.getLocation());
|
||||
receipt0.setArchiveStatus(entity.getArchiveStatus());
|
||||
receipt0.setOrganizationId(entity.getOrganizationId());
|
||||
receipt0.setName(entity.getName());
|
||||
receipt0.setCode(entity.getCode());
|
||||
receipt0.setRemarks(entity.getReceiptNo() + "盘库单生成的入库单");
|
||||
receipt0.setSortKey(entity.getSortKey());
|
||||
receipt0.setStatus(entity.getStatus());
|
||||
receipt0.setFileIds(entity.getFileIds());
|
||||
receipt0.setCreator(entity.getCreator());
|
||||
|
||||
receipt0.setParent(entity);
|
||||
|
||||
WarehouseReceiptEntity receipt1 = new WarehouseReceiptEntity();
|
||||
receipt1.setCreator(entity.getCreator());
|
||||
receipt1.setReceiptType("1");
|
||||
receipt1.setReason(entity.getReason());
|
||||
receipt1.setReasonDesc(entity.getReasonDesc());
|
||||
receipt1.setReceiptDate(entity.getReceiptDate());
|
||||
receipt1.setDetail(new ArrayList<>());
|
||||
receipt1.setAmount(0.0);
|
||||
receipt1.setNumber(0.0);
|
||||
receipt1.setReceipt0(null);
|
||||
receipt1.setReceipt1(null);
|
||||
receipt1.setLocation(entity.getLocation());
|
||||
receipt1.setArchiveStatus(entity.getArchiveStatus());
|
||||
receipt1.setOrganizationId(entity.getOrganizationId());
|
||||
receipt1.setName(entity.getName());
|
||||
receipt1.setCode(entity.getCode());
|
||||
receipt1.setRemarks(entity.getReceiptNo() + "盘库单生成的出库单");
|
||||
receipt1.setSortKey(entity.getSortKey());
|
||||
receipt1.setStatus(entity.getStatus());
|
||||
receipt1.setFileIds(entity.getFileIds());
|
||||
receipt1.setParent(entity);
|
||||
|
||||
for (WarehouseReceiptDetailEntity detail : entity.getDetail()) {
|
||||
|
||||
if (ObjectUtils.notEqual(detail.getStock(), detail.getNumber())) {
|
||||
|
||||
if (detail.getStock() < detail.getNumber()) {
|
||||
WarehouseReceiptDetailEntity detail0 = new WarehouseReceiptDetailEntity();
|
||||
detail0.setWarehouse(detail.getWarehouse());
|
||||
detail0.setGoods(detail.getGoods());
|
||||
detail0.setNumber(detail.getNumber() - detail.getStock());
|
||||
detail0.setPrice(detail.getPrice());
|
||||
detail0.setAmount(NumberUtils.round2(detail0.getNumber() * detail0.getPrice()));
|
||||
detail0.setShelve(detail.getShelve());
|
||||
detail0.setReceipt(receipt0);
|
||||
detail0.setStock(detail.getStock());
|
||||
detail0.setReceiptType("0");
|
||||
receipt0.getDetail().add(detail0);
|
||||
} else {
|
||||
WarehouseReceiptDetailEntity detail1 = new WarehouseReceiptDetailEntity();
|
||||
detail1.setWarehouse(detail.getWarehouse());
|
||||
detail1.setGoods(detail.getGoods());
|
||||
detail1.setNumber(detail.getStock() - detail.getNumber());
|
||||
detail1.setPrice(detail.getPrice());
|
||||
detail1.setAmount(NumberUtils.round2(detail1.getNumber() * detail1.getPrice()));
|
||||
detail1.setShelve(detail.getShelve());
|
||||
detail1.setReceipt(receipt1);
|
||||
detail1.setStock(detail.getStock());
|
||||
detail1.setReceiptType("1");
|
||||
receipt1.getDetail().add(detail1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!receipt0.getDetail().isEmpty()) {
|
||||
|
||||
receipt0.setNumber(
|
||||
NumberUtils.round2(
|
||||
receipt0.getDetail().stream()
|
||||
.map(WarehouseReceiptDetailEntity::getNumber)
|
||||
.reduce(0.0, Double::sum)));
|
||||
|
||||
receipt0.setAmount(
|
||||
NumberUtils.round2(
|
||||
receipt0.getDetail().stream()
|
||||
.map(WarehouseReceiptDetailEntity::getAmount)
|
||||
.reduce(0.0, Double::sum)));
|
||||
|
||||
receipt0.setReceiptNo(
|
||||
orderNoRuleService.genOrderNo(
|
||||
RuleCodeConstant.KF_RKD, Ctx.currentUser().getOrganizationId()));
|
||||
|
||||
entity.setReceipt0(receipt0);
|
||||
this.warehouseReceiptDetailRepository.saveAll(receipt0.getDetail());
|
||||
this.save(receipt0);
|
||||
}
|
||||
|
||||
if (!receipt1.getDetail().isEmpty()) {
|
||||
|
||||
receipt1.setNumber(
|
||||
NumberUtils.round2(
|
||||
receipt1.getDetail().stream()
|
||||
.map(WarehouseReceiptDetailEntity::getNumber)
|
||||
.reduce(0.0, Double::sum)));
|
||||
|
||||
receipt1.setAmount(
|
||||
NumberUtils.round2(
|
||||
receipt1.getDetail().stream()
|
||||
.map(WarehouseReceiptDetailEntity::getAmount)
|
||||
.reduce(0.0, Double::sum)));
|
||||
|
||||
receipt1.setReceiptNo(
|
||||
orderNoRuleService.genOrderNo(
|
||||
RuleCodeConstant.KF_CKD, Ctx.currentUser().getOrganizationId()));
|
||||
|
||||
entity.setReceipt1(receipt1);
|
||||
this.save(receipt1);
|
||||
this.warehouseReceiptDetailRepository.saveAll(receipt1.getDetail());
|
||||
}
|
||||
|
||||
this.save(entity);
|
||||
}
|
||||
|
||||
private void processDetail(WarehouseReceiptEntity entity) {
|
||||
if (entity.getDetail() != null){
|
||||
if (entity.getDetail() != null) {
|
||||
|
||||
for (WarehouseReceiptDetailEntity warehouseReceiptDetailEntity : entity.getDetail()) {
|
||||
warehouseReceiptDetailEntity.setReceipt(entity);
|
||||
warehouseReceiptDetailEntity.setPrice(
|
||||
BigDecimal.valueOf(ObjectUtils.defaultIfNull(
|
||||
warehouseReceiptDetailEntity.getPrice(), 0.0)).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
||||
BigDecimal.valueOf(
|
||||
ObjectUtils.defaultIfNull(
|
||||
warehouseReceiptDetailEntity.getPrice(), 0.0))
|
||||
.setScale(2, RoundingMode.HALF_UP)
|
||||
.doubleValue());
|
||||
|
||||
warehouseReceiptDetailEntity.setNumber(
|
||||
BigDecimal.valueOf(ObjectUtils.defaultIfNull(
|
||||
warehouseReceiptDetailEntity.getNumber(), 0.0))
|
||||
BigDecimal.valueOf(
|
||||
ObjectUtils.defaultIfNull(
|
||||
warehouseReceiptDetailEntity.getNumber(), 0.0))
|
||||
.setScale(2, RoundingMode.HALF_UP)
|
||||
.doubleValue());
|
||||
|
||||
@@ -89,39 +232,36 @@ public class WarehouseReceiptService
|
||||
* (warehouseReceiptDetailEntity.getNumber()));
|
||||
|
||||
warehouseReceiptDetailEntity.setAmount(
|
||||
BigDecimal.valueOf(ObjectUtils.defaultIfNull(
|
||||
warehouseReceiptDetailEntity.getAmount(), 0.0))
|
||||
BigDecimal.valueOf(
|
||||
ObjectUtils.defaultIfNull(
|
||||
warehouseReceiptDetailEntity.getAmount(), 0.0))
|
||||
.setScale(2, RoundingMode.HALF_UP)
|
||||
.doubleValue());
|
||||
|
||||
warehouseReceiptDetailEntity.setReceiptType(entity.getReceiptType());
|
||||
|
||||
|
||||
GoodsCountRequest request = new GoodsCountRequest();
|
||||
request.setGoodsId(warehouseReceiptDetailEntity.getGoods().getId());
|
||||
request.setWarehouseId(warehouseReceiptDetailEntity.getWarehouse().getId());
|
||||
|
||||
Integer goodsCount = warehouseGoodsService.goodsCount(request);
|
||||
|
||||
WarehouseGoodsDto goods = warehouseGoodsService.getById(warehouseReceiptDetailEntity.getGoods().getId());
|
||||
if (ObjectUtils.notEqual(goodsCount, warehouseReceiptDetailEntity.getStock().intValue())){
|
||||
WarehouseGoodsDto goods =
|
||||
warehouseGoodsService.getById(
|
||||
warehouseReceiptDetailEntity.getGoods().getId());
|
||||
if (ObjectUtils.notEqual(
|
||||
goodsCount, warehouseReceiptDetailEntity.getStock().intValue())) {
|
||||
|
||||
throw new BizException("商品 " +
|
||||
goods.getName() +
|
||||
" 库存数量发生变化, 请重新操作");
|
||||
throw new BizException("商品 " + goods.getName() + " 库存数量发生变化, 请重新操作");
|
||||
}
|
||||
|
||||
if (StringUtils.equals(entity.getReceiptType(), "1")){
|
||||
if (goodsCount < warehouseReceiptDetailEntity.getNumber()){
|
||||
throw new BizException("商品 " +
|
||||
goods.getName() +
|
||||
" 库存数量不足");
|
||||
if (StringUtils.equals(entity.getReceiptType(), "1")) {
|
||||
if (goodsCount < warehouseReceiptDetailEntity.getNumber()) {
|
||||
throw new BizException("商品 " + goods.getName() + " 库存数量不足");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
entity.setAmount(
|
||||
entity.getDetail().stream()
|
||||
.map(WarehouseReceiptDetailEntity::getAmount)
|
||||
@@ -132,7 +272,6 @@ public class WarehouseReceiptService
|
||||
.map(WarehouseReceiptDetailEntity::getNumber)
|
||||
.reduce(0.0, Double::sum));
|
||||
|
||||
|
||||
warehouseReceiptDetailRepository.saveAll(entity.getDetail());
|
||||
}
|
||||
}
|
||||
@@ -148,8 +287,7 @@ public class WarehouseReceiptService
|
||||
|
||||
type0.setReasonDesc("调货产生的入库单");
|
||||
|
||||
|
||||
// type0.setWarehouse(entity.getWarehouse2());
|
||||
// type0.setWarehouse(entity.getWarehouse2());
|
||||
|
||||
type0.setReceiptDate(entity.getReceiptDate());
|
||||
|
||||
@@ -170,7 +308,6 @@ public class WarehouseReceiptService
|
||||
|
||||
// 生成出库单
|
||||
|
||||
|
||||
WarehouseReceiptEntity type1 = new WarehouseReceiptEntity();
|
||||
|
||||
type1.setReceiptType("1");
|
||||
@@ -179,8 +316,7 @@ public class WarehouseReceiptService
|
||||
|
||||
type1.setReasonDesc("调货产生的出库单");
|
||||
|
||||
|
||||
// type1.setWarehouse(entity.getWarehouse());
|
||||
// type1.setWarehouse(entity.getWarehouse());
|
||||
|
||||
type1.setReceiptDate(entity.getReceiptDate());
|
||||
|
||||
@@ -201,66 +337,124 @@ public class WarehouseReceiptService
|
||||
|
||||
entity.setReceipt0(type0);
|
||||
entity.setReceipt1(type1);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public WarehouseReceiptDto update(UpdateWarehouseReceiptDto request) {
|
||||
|
||||
long count =
|
||||
this.repository.count(
|
||||
new Specification<WarehouseReceiptEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root<WarehouseReceiptEntity> root,
|
||||
CriteriaQuery<?> query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
// 如果id 为 receipt0 或者 receipt1 则
|
||||
|
||||
this.warehouseReceiptDetailRepository.delete(new Specification<WarehouseReceiptDetailEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(Root<WarehouseReceiptDetailEntity> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
|
||||
return criteriaBuilder.or(
|
||||
criteriaBuilder.equal(
|
||||
root.get("receipt0").get("id"), request.getId()),
|
||||
criteriaBuilder.equal(
|
||||
root.get("receipt1").get("id"), request.getId()));
|
||||
}
|
||||
});
|
||||
|
||||
return criteriaBuilder.equal(root.get("receipt").get("id"), request.getId());
|
||||
}
|
||||
});
|
||||
if (count != 0) {
|
||||
throw new BizException("数据由调货单、盘库单生成,无法编辑或删除");
|
||||
}
|
||||
|
||||
this.warehouseReceiptDetailRepository.delete(
|
||||
new Specification<WarehouseReceiptDetailEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root<WarehouseReceiptDetailEntity> root,
|
||||
CriteriaQuery<?> query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
|
||||
return criteriaBuilder.equal(
|
||||
root.get("receipt").get("id"), request.getId());
|
||||
}
|
||||
});
|
||||
|
||||
if (CollectionUtils.isNotEmpty(request.getDetail())) {
|
||||
request.getDetail().forEach(x -> x.setId(null));
|
||||
}
|
||||
|
||||
|
||||
|
||||
WarehouseReceiptEntity entity = this.repository.get(request.getId());
|
||||
|
||||
|
||||
processDetail(entity);
|
||||
|
||||
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
if (request.getReceiptType().equals("2")) {
|
||||
|
||||
updateType2Receipt(entity);
|
||||
}
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
// private void handleType3Update(WarehouseReceiptEntity entity) {
|
||||
// repository.delete(entity.getReceipt0());
|
||||
// repository.delete(entity.getReceipt1());
|
||||
// handleType3Create(entity);
|
||||
//
|
||||
// }
|
||||
private void updateType2Receipt(WarehouseReceiptEntity entity) {}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
if (this.repository.containArchived(request)){
|
||||
// private void handleType3Update(WarehouseReceiptEntity entity) {
|
||||
// repository.delete(entity.getReceipt0());
|
||||
// repository.delete(entity.getReceipt1());
|
||||
// handleType3Create(entity);
|
||||
//
|
||||
// }
|
||||
|
||||
public void delete(IdRequest dto) {
|
||||
|
||||
List<WarehouseReceiptEntity> all = this.repository.findAll(
|
||||
new Specification<WarehouseReceiptEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root<WarehouseReceiptEntity> root,
|
||||
CriteriaQuery<?> query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
|
||||
return criteriaBuilder.or(
|
||||
root.get("id").in(dto.getIds()),
|
||||
root.get("parent").get("id").in(dto.getIds()));
|
||||
}
|
||||
});
|
||||
|
||||
List<WarehouseReceiptEntity> ch = this.repository.findAll(
|
||||
new Specification<WarehouseReceiptEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root<WarehouseReceiptEntity> root,
|
||||
CriteriaQuery<?> query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
|
||||
return criteriaBuilder.or(
|
||||
root.get("id").in(dto.getIds()),
|
||||
root.get("parent").get("id").isNotNull());
|
||||
}
|
||||
});
|
||||
|
||||
List<String> list = ch.stream().map(x -> x.getParent().getId()).toList();
|
||||
|
||||
Collection<String> notSelected = CollectionUtils.removeAll(list, dto.getIds());
|
||||
|
||||
if (!notSelected.isEmpty()) {
|
||||
throw new BizException("部分数据由调货单、盘库单生成,无法编辑或删除");
|
||||
}
|
||||
|
||||
dto.setIds(all.stream().map(WarehouseReceiptEntity::getId).toList());
|
||||
|
||||
if (this.repository.containArchived(dto)) {
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
List<WarehouseReceiptEntity> allById = this.repository.findAllById(request.getIds());
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
List<WarehouseReceiptEntity> allById = this.repository.findAllById(dto.getIds());
|
||||
this.repository.deleteAllById(dto.getIds());
|
||||
handleType3Delete(allById);
|
||||
// warehouseGoodsSummaryService.refresh(allById);
|
||||
// warehouseGoodsSummaryService.refresh(allById);
|
||||
}
|
||||
|
||||
private void handleType3Delete(List<WarehouseReceiptEntity> allById) {
|
||||
|
||||
|
||||
}
|
||||
private void handleType3Delete(List<WarehouseReceiptEntity> allById) {}
|
||||
|
||||
public WarehouseReceiptDto getById(String id) {
|
||||
WarehouseReceiptEntity entity = repository.get(id);
|
||||
@@ -281,11 +475,43 @@ public class WarehouseReceiptService
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
|
||||
List<WarehouseReceiptEntity> all = this.repository.findAll(
|
||||
new Specification<WarehouseReceiptEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root<WarehouseReceiptEntity> root,
|
||||
CriteriaQuery<?> query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
|
||||
return criteriaBuilder.or(
|
||||
root.get("id").in(dto.getIds()),
|
||||
root.get("parent").get("id").in(dto.getIds()));
|
||||
}
|
||||
});
|
||||
|
||||
dto.setIds(all.stream().map(WarehouseReceiptEntity::getId).toList());
|
||||
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
List<WarehouseReceiptEntity> all = this.repository.findAll(
|
||||
new Specification<WarehouseReceiptEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root<WarehouseReceiptEntity> root,
|
||||
CriteriaQuery<?> query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
|
||||
return criteriaBuilder.or(
|
||||
root.get("id").in(dto.getIds()),
|
||||
root.get("parent").get("id").in(dto.getIds()));
|
||||
}
|
||||
});
|
||||
|
||||
dto.setIds(all.stream().map(WarehouseReceiptEntity::getId).toList());
|
||||
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ public class UpdateWarehouseReceiptDetailDto extends OrgCommonDto {
|
||||
@Comment("数量")
|
||||
private Double number;
|
||||
|
||||
private Double stock;
|
||||
|
||||
|
||||
@Comment("单价")
|
||||
private Double price;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package cn.lihongjie.coal.warehouseReceiptDetail.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.base.dto.SimpleDto;
|
||||
import cn.lihongjie.coal.common.DictCode;
|
||||
import cn.lihongjie.coal.pojoProcessor.DictTranslate;
|
||||
import cn.lihongjie.coal.warehouse.dto.WarehouseDto;
|
||||
import cn.lihongjie.coal.warehouseGoods.dto.WarehouseGoodsDto;
|
||||
import cn.lihongjie.coal.warehouseReceipt.dto.WarehouseReceiptSimpleDto;
|
||||
import cn.lihongjie.coal.warehouseShelve.dto.WarehouseShelveDto;
|
||||
import cn.lihongjie.coal.warehouseSupplier.dto.WarehouseSupplierDto;
|
||||
|
||||
@@ -36,7 +38,13 @@ public class WarehouseReceiptDetailDto extends OrgCommonDto {
|
||||
private WarehouseSupplierDto supplier;
|
||||
|
||||
@ManyToOne
|
||||
private SimpleDto receipt;
|
||||
private WarehouseReceiptSimpleDto receipt;
|
||||
|
||||
|
||||
@DictTranslate(dictKey = DictCode.WAREHOUSE_RECEIPTTYPE)
|
||||
private String receiptTypeName;
|
||||
|
||||
private String receiptType;
|
||||
|
||||
@Comment("数量")
|
||||
private Double number;
|
||||
@@ -57,4 +65,8 @@ public class WarehouseReceiptDetailDto extends OrgCommonDto {
|
||||
|
||||
@Comment("过期日期")
|
||||
private LocalDateTime expirationDate;
|
||||
|
||||
|
||||
@Comment("现有库存")
|
||||
private Double stock;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package cn.lihongjie.coal.warehouseReceiptDetail.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.common.DictCode;
|
||||
import cn.lihongjie.coal.pojoProcessor.DictTranslate;
|
||||
import cn.lihongjie.coal.warehouse.dto.WarehouseDto;
|
||||
import cn.lihongjie.coal.warehouseGoods.dto.WarehouseGoodsDto;
|
||||
import cn.lihongjie.coal.warehouseShelve.dto.WarehouseShelveDto;
|
||||
import cn.lihongjie.coal.warehouseSupplier.dto.WarehouseSupplierDto;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class WarehouseReceiptDetailSimpleDto extends OrgCommonDto {
|
||||
|
||||
@ManyToOne
|
||||
private WarehouseGoodsDto goods;
|
||||
|
||||
private WarehouseDto warehouse;
|
||||
|
||||
@ManyToOne
|
||||
private WarehouseShelveDto shelve;
|
||||
|
||||
|
||||
|
||||
private WarehouseDto warehouse1;
|
||||
|
||||
@ManyToOne
|
||||
private WarehouseShelveDto shelve1;
|
||||
|
||||
private WarehouseSupplierDto supplier;
|
||||
|
||||
private Double stock;
|
||||
|
||||
@DictTranslate(dictKey = DictCode.WAREHOUSE_RECEIPTTYPE)
|
||||
private String receiptTypeName;
|
||||
|
||||
private String receiptType;
|
||||
|
||||
@Comment("数量")
|
||||
private Double number;
|
||||
|
||||
|
||||
@Comment("单价")
|
||||
private Double price;
|
||||
|
||||
|
||||
private Double amount;
|
||||
|
||||
@Comment("保质期 天")
|
||||
private Integer shelfLife;
|
||||
|
||||
|
||||
@Comment("生产日期")
|
||||
private LocalDateTime productionDate;
|
||||
|
||||
@Comment("过期日期")
|
||||
private LocalDateTime expirationDate;
|
||||
}
|
||||
Reference in New Issue
Block a user