This commit is contained in:
2024-11-04 21:16:58 +08:00
parent 665d770316
commit c0a6951d4e
16 changed files with 592 additions and 332 deletions

View File

@@ -2,7 +2,62 @@ package cn.lihongjie.coal.warehouseGoods.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import jakarta.persistence.ManyToOne;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class CreateWarehouseGoodsDto extends OrgCommonDto {}
public class CreateWarehouseGoodsDto extends OrgCommonDto {
@ManyToOne
private String category;
@ManyToOne
private String brand;
@ManyToOne
private String unit;
@ManyToOne
private String defaultWarehouse;
@ManyToOne
private String defaultShelve;
@Comment("条码")
private String barCode;
@Comment("规格")
private String spec;
@Comment("重量 kg")
private Double weight;
@Comment("体积 m3")
private Double volume;
@Comment("尺寸")
private String size;
@Comment("进货价")
private Double price1;
@Comment("市场价")
private Double price2;
@Comment("仓库核算价")
private Double price3;
@Comment("批发价")
private Double price4;
private Double price5;
}

View File

@@ -2,7 +2,60 @@ package cn.lihongjie.coal.warehouseGoods.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import jakarta.persistence.ManyToOne;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class UpdateWarehouseGoodsDto extends OrgCommonDto {}
public class UpdateWarehouseGoodsDto extends OrgCommonDto {
@ManyToOne
private String category;
@ManyToOne
private String brand;
@ManyToOne
private String unit;
@ManyToOne
private String defaultWarehouse;
@ManyToOne
private String defaultShelve;
@Comment("条码")
private String barCode;
@Comment("规格")
private String spec;
@Comment("重量 kg")
private Double weight;
@Comment("体积 m3")
private Double volume;
@Comment("尺寸")
private String size;
@Comment("进货价")
private Double price1;
@Comment("市场价")
private Double price2;
@Comment("仓库核算价")
private Double price3;
@Comment("批发价")
private Double price4;
private Double price5;
}

View File

@@ -1,8 +1,62 @@
package cn.lihongjie.coal.warehouseGoods.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import cn.lihongjie.coal.base.dto.SimpleDto;
import jakarta.persistence.ManyToOne;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class WarehouseGoodsDto extends OrgCommonDto {}
public class WarehouseGoodsDto extends OrgCommonDto {
@ManyToOne
private SimpleDto category;
@ManyToOne
private SimpleDto brand;
@ManyToOne
private SimpleDto unit;
@ManyToOne
private SimpleDto defaultWarehouse;
@ManyToOne
private SimpleDto defaultShelve;
@Comment("条码")
private String barCode;
@Comment("规格")
private String spec;
@Comment("重量 kg")
private Double weight;
@Comment("体积 m3")
private Double volume;
@Comment("尺寸")
private String size;
@Comment("进货价")
private Double price1;
@Comment("市场价")
private Double price2;
@Comment("仓库核算价")
private Double price3;
@Comment("批发价")
private Double price4;
private Double price5;
}

View File

@@ -1,54 +1,54 @@
package cn.lihongjie.coal.warehouseGoodsSummary.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.warehouseGoodsSummary.dto.CreateWarehouseGoodsSummaryDto;
import cn.lihongjie.coal.warehouseGoodsSummary.dto.UpdateWarehouseGoodsSummaryDto;
import cn.lihongjie.coal.warehouseGoodsSummary.dto.WarehouseGoodsSummaryDto;
import cn.lihongjie.coal.warehouseGoodsSummary.service.WarehouseGoodsSummaryService;
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("/warehouseGoodsSummary")
@SysLog(module = "仓库商品统计")
@Slf4j
@OrgScope
public class WarehouseGoodsSummaryController {
@Autowired private WarehouseGoodsSummaryService service;
@PostMapping("/create")
public WarehouseGoodsSummaryDto create(@RequestBody CreateWarehouseGoodsSummaryDto request) {
return this.service.create(request);
}
@PostMapping("/update")
public WarehouseGoodsSummaryDto update(@RequestBody UpdateWarehouseGoodsSummaryDto request) {
return this.service.update(request);
}
@PostMapping("/delete")
public Object delete(@RequestBody IdRequest request) {
this.service.delete(request);
return true;
}
@PostMapping("/getById")
public WarehouseGoodsSummaryDto getById(@RequestBody IdRequest request) {
return this.service.getById(request.getId());
}
@PostMapping("/list")
public Page<WarehouseGoodsSummaryDto> list(@RequestBody CommonQuery request) {
return this.service.list(request);
}
}
//package cn.lihongjie.coal.warehouseGoodsSummary.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.warehouseGoodsSummary.dto.CreateWarehouseGoodsSummaryDto;
//import cn.lihongjie.coal.warehouseGoodsSummary.dto.UpdateWarehouseGoodsSummaryDto;
//import cn.lihongjie.coal.warehouseGoodsSummary.dto.WarehouseGoodsSummaryDto;
//import cn.lihongjie.coal.warehouseGoodsSummary.service.WarehouseGoodsSummaryService;
//
//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("/warehouseGoodsSummary")
//@SysLog(module = "仓库商品统计")
//@Slf4j
//@OrgScope
//public class WarehouseGoodsSummaryController {
// @Autowired private WarehouseGoodsSummaryService service;
//
// @PostMapping("/create")
// public WarehouseGoodsSummaryDto create(@RequestBody CreateWarehouseGoodsSummaryDto request) {
// return this.service.create(request);
// }
//
// @PostMapping("/update")
// public WarehouseGoodsSummaryDto update(@RequestBody UpdateWarehouseGoodsSummaryDto request) {
// return this.service.update(request);
// }
//
// @PostMapping("/delete")
// public Object delete(@RequestBody IdRequest request) {
// this.service.delete(request);
// return true;
// }
//
// @PostMapping("/getById")
// public WarehouseGoodsSummaryDto getById(@RequestBody IdRequest request) {
// return this.service.getById(request.getId());
// }
//
// @PostMapping("/list")
// public Page<WarehouseGoodsSummaryDto> list(@RequestBody CommonQuery request) {
// return this.service.list(request);
// }
//}

View File

@@ -1,147 +1,147 @@
package cn.lihongjie.coal.warehouseGoodsSummary.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.warehouseGoodsSummary.dto.CreateWarehouseGoodsSummaryDto;
import cn.lihongjie.coal.warehouseGoodsSummary.dto.UpdateWarehouseGoodsSummaryDto;
import cn.lihongjie.coal.warehouseGoodsSummary.dto.WarehouseGoodsSummaryDto;
import cn.lihongjie.coal.warehouseGoodsSummary.entity.WarehouseGoodsSummaryEntity;
import cn.lihongjie.coal.warehouseGoodsSummary.mapper.WarehouseGoodsSummaryMapper;
import cn.lihongjie.coal.warehouseGoodsSummary.repository.WarehouseGoodsSummaryRepository;
import cn.lihongjie.coal.warehouseReceipt.entity.WarehouseReceiptEntity;
import cn.lihongjie.coal.warehouseReceipt.repository.WarehouseReceiptRepository;
import cn.lihongjie.coal.warehouseReceiptDetail.repository.WarehouseReceiptDetailRepository;
import io.vavr.Tuple;
import io.vavr.Tuple2;
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;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
@Slf4j
@Transactional
public class WarehouseGoodsSummaryService
extends BaseService<WarehouseGoodsSummaryEntity, WarehouseGoodsSummaryRepository> {
@Autowired private WarehouseGoodsSummaryRepository repository;
@Autowired private WarehouseGoodsSummaryMapper mapper;
@Autowired private ConversionService conversionService;
@Autowired private WarehouseReceiptDetailRepository warehouseReceiptDetailRepository;
@Autowired private WarehouseReceiptRepository warehouseReceiptRepository;
public WarehouseGoodsSummaryDto create(CreateWarehouseGoodsSummaryDto request) {
WarehouseGoodsSummaryEntity entity = mapper.toEntity(request);
this.repository.save(entity);
return getById(entity.getId());
}
public WarehouseGoodsSummaryDto update(UpdateWarehouseGoodsSummaryDto request) {
WarehouseGoodsSummaryEntity 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 WarehouseGoodsSummaryDto getById(String id) {
WarehouseGoodsSummaryEntity entity = repository.get(id);
return mapper.toDto(entity);
}
public Page<WarehouseGoodsSummaryDto> list(CommonQuery query) {
Page<WarehouseGoodsSummaryEntity> page =
repository.findAll(
query.specification(conversionService),
PageRequest.of(
query.getPageNo(),
query.getPageSize(),
Sort.by(query.getOrders())));
return page.map(this.mapper::toDto);
}
public void refresh(List<WarehouseReceiptEntity> receipt) {
var warehouseIds =
receipt.stream().map(r -> r.getWarehouse().getId()).collect(Collectors.toSet());
var shelveIds =
receipt.stream()
.flatMap(r -> r.getDetail().stream().map(x -> x.getShelve().getId()))
.collect(Collectors.toSet());
var goodsIds =
receipt.stream()
.flatMap(r -> r.getDetail().stream().map(x -> x.getGoods().getId()))
.collect(Collectors.toSet());
var all =
warehouseReceiptRepository.findAllByWarehouseIdInAndShelveIdInAndGoodsIdIn(
warehouseIds, shelveIds, goodsIds);
Map<Tuple2<String, String>, WarehouseGoodsSummaryEntity> cache = new HashMap<>();
for (WarehouseReceiptEntity receiptEntity : all) {
for (var detail : receiptEntity.getDetail()) {
WarehouseGoodsSummaryEntity defaultEntity = new WarehouseGoodsSummaryEntity();
defaultEntity.setWarehouse(receiptEntity.getWarehouse());
defaultEntity.setGoods(detail.getGoods());
defaultEntity.setShelve(detail.getShelve());
defaultEntity.setNumber(0.0);
defaultEntity.setAmount(0.0);
WarehouseGoodsSummaryEntity summary =
cache.getOrDefault(
Tuple.of(detail.getShelve().getId(), detail.getGoods().getId()),
defaultEntity);
switch (receiptEntity.getReceiptType()) {
case "0":
summary.setNumber(summary.getNumber() + detail.getNumber());
summary.setPrice(detail.getPrice());
break;
case "1":
summary.setNumber(summary.getNumber() - detail.getNumber());
summary.setPrice(detail.getPrice());
break;
case "2":
// 调库单不处理, 由调库单的出库和入库单处理
break;
default:
throw new RuntimeException(
"unknown receipt type " + receiptEntity.getReceiptType());
}
}
}
repository.deleteAll(
repository.findAllByWarehouseIdInAndShelveIdInAndGoodsIdIn(
warehouseIds, shelveIds, goodsIds));
repository.saveAll(cache.values());
}
}
//package cn.lihongjie.coal.warehouseGoodsSummary.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.warehouseGoodsSummary.dto.CreateWarehouseGoodsSummaryDto;
//import cn.lihongjie.coal.warehouseGoodsSummary.dto.UpdateWarehouseGoodsSummaryDto;
//import cn.lihongjie.coal.warehouseGoodsSummary.dto.WarehouseGoodsSummaryDto;
//import cn.lihongjie.coal.warehouseGoodsSummary.entity.WarehouseGoodsSummaryEntity;
//import cn.lihongjie.coal.warehouseGoodsSummary.mapper.WarehouseGoodsSummaryMapper;
//import cn.lihongjie.coal.warehouseGoodsSummary.repository.WarehouseGoodsSummaryRepository;
//import cn.lihongjie.coal.warehouseReceipt.entity.WarehouseReceiptEntity;
//import cn.lihongjie.coal.warehouseReceipt.repository.WarehouseReceiptRepository;
//import cn.lihongjie.coal.warehouseReceiptDetail.repository.WarehouseReceiptDetailRepository;
//
//import io.vavr.Tuple;
//import io.vavr.Tuple2;
//
//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;
//
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.stream.Collectors;
//
//@Service
//@Slf4j
//@Transactional
//public class WarehouseGoodsSummaryService
// extends BaseService<WarehouseGoodsSummaryEntity, WarehouseGoodsSummaryRepository> {
// @Autowired private WarehouseGoodsSummaryRepository repository;
//
// @Autowired private WarehouseGoodsSummaryMapper mapper;
//
// @Autowired private ConversionService conversionService;
// @Autowired private WarehouseReceiptDetailRepository warehouseReceiptDetailRepository;
// @Autowired private WarehouseReceiptRepository warehouseReceiptRepository;
//
// public WarehouseGoodsSummaryDto create(CreateWarehouseGoodsSummaryDto request) {
// WarehouseGoodsSummaryEntity entity = mapper.toEntity(request);
//
// this.repository.save(entity);
// return getById(entity.getId());
// }
//
// public WarehouseGoodsSummaryDto update(UpdateWarehouseGoodsSummaryDto request) {
// WarehouseGoodsSummaryEntity 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 WarehouseGoodsSummaryDto getById(String id) {
// WarehouseGoodsSummaryEntity entity = repository.get(id);
//
// return mapper.toDto(entity);
// }
//
// public Page<WarehouseGoodsSummaryDto> list(CommonQuery query) {
// Page<WarehouseGoodsSummaryEntity> page =
// repository.findAll(
// query.specification(conversionService),
// PageRequest.of(
// query.getPageNo(),
// query.getPageSize(),
// Sort.by(query.getOrders())));
//
// return page.map(this.mapper::toDto);
// }
//
// public void refresh(List<WarehouseReceiptEntity> receipt) {
//
// var warehouseIds =
// receipt.stream().map(r -> r.getWarehouse().getId()).collect(Collectors.toSet());
//
// var shelveIds =
// receipt.stream()
// .flatMap(r -> r.getDetail().stream().map(x -> x.getShelve().getId()))
// .collect(Collectors.toSet());
// var goodsIds =
// receipt.stream()
// .flatMap(r -> r.getDetail().stream().map(x -> x.getGoods().getId()))
// .collect(Collectors.toSet());
//
// var all =
// warehouseReceiptRepository.findAllByWarehouseIdInAndShelveIdInAndGoodsIdIn(
// warehouseIds, shelveIds, goodsIds);
//
// Map<Tuple2<String, String>, WarehouseGoodsSummaryEntity> cache = new HashMap<>();
//
// for (WarehouseReceiptEntity receiptEntity : all) {
//
// for (var detail : receiptEntity.getDetail()) {
//
// WarehouseGoodsSummaryEntity defaultEntity = new WarehouseGoodsSummaryEntity();
//
// defaultEntity.setWarehouse(receiptEntity.getWarehouse());
// defaultEntity.setGoods(detail.getGoods());
// defaultEntity.setShelve(detail.getShelve());
// defaultEntity.setNumber(0.0);
// defaultEntity.setAmount(0.0);
// WarehouseGoodsSummaryEntity summary =
// cache.getOrDefault(
// Tuple.of(detail.getShelve().getId(), detail.getGoods().getId()),
// defaultEntity);
//
// switch (receiptEntity.getReceiptType()) {
// case "0":
// summary.setNumber(summary.getNumber() + detail.getNumber());
// summary.setPrice(detail.getPrice());
// break;
// case "1":
// summary.setNumber(summary.getNumber() - detail.getNumber());
// summary.setPrice(detail.getPrice());
// break;
//
// case "2":
// // 调库单不处理, 由调库单的出库和入库单处理
// break;
// default:
// throw new RuntimeException(
// "unknown receipt type " + receiptEntity.getReceiptType());
// }
// }
// }
//
// repository.deleteAll(
// repository.findAllByWarehouseIdInAndShelveIdInAndGoodsIdIn(
// warehouseIds, shelveIds, goodsIds));
//
// repository.saveAll(cache.values());
// }
//}

View File

@@ -46,4 +46,7 @@ public class CreateWarehouseReceiptDto extends OrgCommonDto {
@Comment("制单人")
private String creator;
}

View File

@@ -43,4 +43,8 @@ public class UpdateWarehouseReceiptDto extends OrgCommonDto {
@OneToMany
private List<CreateWarehouseReceiptDetailDto> detail;
@Comment("制单人")
private String creator;
}

View File

@@ -62,4 +62,7 @@ public class WarehouseReceiptDto extends OrgCommonDto {
@Formula("(select sum(d.number) from t_warehouse_receipt_detail d where d.receipt_id = id)")
private Double number;
@Comment("制单人")
private String creator;
}

View File

@@ -1,40 +1,37 @@
package cn.lihongjie.coal.warehouseReceipt.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import cn.lihongjie.coal.warehouse.entity.WarehouseEntity;
import cn.lihongjie.coal.warehouseReceiptDetail.entity.WarehouseReceiptDetailEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.*;
import lombok.Data;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
import java.time.LocalDateTime;
import java.util.List;
@Data
@Entity
@jakarta.persistence.Table(indexes = @jakarta.persistence.Index(name ="idx_warehouse_receipt_org_id", columnList = "organization_id"))
@jakarta.persistence.Table(
indexes =
@jakarta.persistence.Index(
name = "idx_warehouse_receipt_org_id",
columnList = "organization_id"))
public class WarehouseReceiptEntity extends OrgCommonEntity {
@Comment("单据类型")
private String receiptType;
@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 = 'warehouse.receiptType'\n"
+ " and i.code = receipt_type)")
private String receiptTypeName;
// @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 = 'warehouse.receiptType'\n"
// + " and i.code = receipt_type)")
// private String receiptTypeName;
@Comment("单据编号")
private String receiptNo;
@@ -45,41 +42,31 @@ public class WarehouseReceiptEntity extends OrgCommonEntity {
@Comment("是由说明")
private String reasonDesc;
@ManyToOne private WarehouseEntity warehouse;
// 调入仓库
@ManyToOne private WarehouseEntity warehouse2;
// @ManyToOne private WarehouseEntity warehouse;
//
//
// // 调入仓库
// @ManyToOne private WarehouseEntity warehouse2;
@Comment("单据日期")
private LocalDateTime receiptDate;
@OneToMany(mappedBy = "receipt", cascade = CascadeType.REMOVE)
private List<WarehouseReceiptDetailEntity> detail;
@Formula("(select sum(d.number * d.price) from t_warehouse_receipt_detail d where d.receipt_id = id)")
private Double amount;
@Formula("(select sum(d.number) from t_warehouse_receipt_detail d where d.receipt_id = id)")
private Double number;
// 调货单产生的入库单
@ManyToOne(cascade = CascadeType.REMOVE)
private WarehouseReceiptEntity receipt0;
// 调货单产生的出库单
@ManyToOne(cascade = CascadeType.REMOVE)
private WarehouseReceiptEntity receipt1;
@Comment("制单人")
private String creator;
}

View File

@@ -3,16 +3,11 @@ package cn.lihongjie.coal.warehouseReceipt.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.warehouseReceipt.entity.WarehouseReceiptEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Set;
@Repository
public interface WarehouseReceiptRepository extends BaseRepository<WarehouseReceiptEntity> {
@Query("select w from WarehouseReceiptEntity w join w.detail d where w.warehouse.id in ?1 and d.shelve.id in ?2 and d.goods.id in ?3 order by w.receiptDate asc ")
List<WarehouseReceiptEntity> findAllByWarehouseIdInAndShelveIdInAndGoodsIdIn(Set<String> warehouseIds, Set<String> shelveIds, Set<String> goodsIds);
}

View File

@@ -3,7 +3,6 @@ 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.warehouseGoodsSummary.service.WarehouseGoodsSummaryService;
import cn.lihongjie.coal.warehouseReceipt.dto.CreateWarehouseReceiptDto;
import cn.lihongjie.coal.warehouseReceipt.dto.UpdateWarehouseReceiptDto;
import cn.lihongjie.coal.warehouseReceipt.dto.WarehouseReceiptDto;
@@ -11,17 +10,28 @@ import cn.lihongjie.coal.warehouseReceipt.entity.WarehouseReceiptEntity;
import cn.lihongjie.coal.warehouseReceipt.mapper.WarehouseReceiptMapper;
import cn.lihongjie.coal.warehouseReceipt.repository.WarehouseReceiptRepository;
import cn.lihongjie.coal.warehouseReceiptDetail.entity.WarehouseReceiptDetailEntity;
import cn.lihongjie.coal.warehouseReceiptDetail.repository.WarehouseReceiptDetailRepository;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
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.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
@@ -36,19 +46,64 @@ public class WarehouseReceiptService
@Autowired private ConversionService conversionService;
@Autowired WarehouseGoodsSummaryService warehouseGoodsSummaryService;
@Autowired
WarehouseReceiptDetailRepository warehouseReceiptDetailRepository;
public WarehouseReceiptDto create(CreateWarehouseReceiptDto request) {
WarehouseReceiptEntity entity = mapper.toEntity(request);
processDetail(entity);
this.repository.save(entity);
handleType3Create(entity);
this.repository.save(entity);
warehouseGoodsSummaryService.refresh(List.of(entity));
return getById(entity.getId());
}
private void processDetail(WarehouseReceiptEntity entity) {
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());
warehouseReceiptDetailEntity.setNumber(
BigDecimal.valueOf(ObjectUtils.defaultIfNull(
warehouseReceiptDetailEntity.getNumber(), 0.0))
.setScale(2, RoundingMode.HALF_UP)
.doubleValue());
warehouseReceiptDetailEntity.setAmount(
warehouseReceiptDetailEntity.getPrice()
* (warehouseReceiptDetailEntity.getNumber()));
warehouseReceiptDetailEntity.setAmount(
BigDecimal.valueOf(ObjectUtils.defaultIfNull(
warehouseReceiptDetailEntity.getAmount(), 0.0))
.setScale(2, RoundingMode.HALF_UP)
.doubleValue());
}
entity.setAmount(
entity.getDetail().stream()
.map(WarehouseReceiptDetailEntity::getAmount)
.reduce(0.0, Double::sum));
entity.setNumber(
entity.getDetail().stream()
.map(WarehouseReceiptDetailEntity::getNumber)
.reduce(0.0, Double::sum));
warehouseReceiptDetailRepository.saveAll(entity.getDetail());
}
}
private void handleType3Create(WarehouseReceiptEntity entity) {
// 生成入库单
@@ -61,7 +116,7 @@ public class WarehouseReceiptService
type0.setReasonDesc("调货产生的入库单");
type0.setWarehouse(entity.getWarehouse2());
// type0.setWarehouse(entity.getWarehouse2());
type0.setReceiptDate(entity.getReceiptDate());
@@ -92,7 +147,7 @@ public class WarehouseReceiptService
type1.setReasonDesc("调货产生的出库单");
type1.setWarehouse(entity.getWarehouse());
// type1.setWarehouse(entity.getWarehouse());
type1.setReceiptDate(entity.getReceiptDate());
@@ -120,29 +175,50 @@ public class WarehouseReceiptService
}
public WarehouseReceiptDto update(UpdateWarehouseReceiptDto request) {
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);
handleType3Update(entity);
this.repository.save(entity);
warehouseGoodsSummaryService.refresh(List.of(entity));
return getById(entity.getId());
}
private void handleType3Update(WarehouseReceiptEntity entity) {
repository.delete(entity.getReceipt0());
repository.delete(entity.getReceipt1());
handleType3Create(entity);
}
// private void handleType3Update(WarehouseReceiptEntity entity) {
// repository.delete(entity.getReceipt0());
// repository.delete(entity.getReceipt1());
// handleType3Create(entity);
//
// }
public void delete(IdRequest request) {
List<WarehouseReceiptEntity> allById = this.repository.findAllById(request.getIds());
this.repository.deleteAllById(request.getIds());
handleType3Delete(allById);
warehouseGoodsSummaryService.refresh(allById);
// warehouseGoodsSummaryService.refresh(allById);
}
private void handleType3Delete(List<WarehouseReceiptEntity> allById) {

View File

@@ -2,8 +2,6 @@ package cn.lihongjie.coal.warehouseReceiptDetail.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import jakarta.persistence.ManyToOne;
import lombok.Data;
import org.hibernate.annotations.Comment;
@@ -11,13 +9,18 @@ import org.hibernate.annotations.Comment;
@Data
public class CreateWarehouseReceiptDetailDto extends OrgCommonDto {
@ManyToOne
private String goods;
@ManyToOne
private String warehouse;
private String shelve;
@ManyToOne
private String warehouse1;
private String shelve1;
private String receipt;
@Comment("数量")
@@ -27,5 +30,7 @@ public class CreateWarehouseReceiptDetailDto extends OrgCommonDto {
@Comment("单价")
private Double price;
@Comment("总价")
private Double amount;
}

View File

@@ -2,8 +2,6 @@ package cn.lihongjie.coal.warehouseReceiptDetail.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import jakarta.persistence.ManyToOne;
import lombok.Data;
import org.hibernate.annotations.Comment;
@@ -11,13 +9,20 @@ import org.hibernate.annotations.Comment;
@Data
public class UpdateWarehouseReceiptDetailDto extends OrgCommonDto {
@ManyToOne
private String goods;
@ManyToOne
private String warehouse;
private String shelve;
@ManyToOne
private String warehouse1;
private String shelve1;
private String receipt;
@Comment("数量")
@@ -26,4 +31,7 @@ public class UpdateWarehouseReceiptDetailDto extends OrgCommonDto {
@Comment("单价")
private Double price;
@Comment("总价")
private Double amount;
}

View File

@@ -1,6 +1,7 @@
package cn.lihongjie.coal.warehouseReceiptDetail.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import cn.lihongjie.coal.warehouse.dto.WarehouseDto;
import cn.lihongjie.coal.warehouseGoods.dto.WarehouseGoodsDto;
import cn.lihongjie.coal.warehouseReceipt.dto.WarehouseReceiptDto;
import cn.lihongjie.coal.warehouseShelve.dto.WarehouseShelveDto;
@@ -10,7 +11,6 @@ import jakarta.persistence.ManyToOne;
import lombok.Data;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
@Data
public class WarehouseReceiptDetailDto extends OrgCommonDto {
@@ -18,9 +18,20 @@ public class WarehouseReceiptDetailDto extends OrgCommonDto {
@ManyToOne
private WarehouseGoodsDto goods;
private WarehouseDto warehouse;
@ManyToOne
private WarehouseShelveDto shelve;
private WarehouseDto warehouse1;
@ManyToOne
private WarehouseShelveDto shelve1;
@ManyToOne
private WarehouseReceiptDto receipt;
@@ -32,6 +43,5 @@ public class WarehouseReceiptDetailDto extends OrgCommonDto {
private Double price;
@Formula("(number * price)")
private Double amount;
}

View File

@@ -1,6 +1,7 @@
package cn.lihongjie.coal.warehouseReceiptDetail.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import cn.lihongjie.coal.warehouse.entity.WarehouseEntity;
import cn.lihongjie.coal.warehouseGoods.entity.WarehouseGoodsEntity;
import cn.lihongjie.coal.warehouseReceipt.entity.WarehouseReceiptEntity;
import cn.lihongjie.coal.warehouseShelve.entity.WarehouseShelveEntity;
@@ -11,7 +12,6 @@ import jakarta.persistence.ManyToOne;
import lombok.Data;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
@Data
@Entity
@@ -24,10 +24,18 @@ public class WarehouseReceiptDetailEntity extends OrgCommonEntity {
@ManyToOne
private WarehouseGoodsEntity goods;
@ManyToOne
private WarehouseEntity warehouse;
@ManyToOne
private WarehouseShelveEntity shelve;
// 调入仓库
@ManyToOne
private WarehouseEntity warehouse2;
// 调入货架
@ManyToOne
private WarehouseShelveEntity shelve2;
@@ -43,7 +51,7 @@ public class WarehouseReceiptDetailEntity extends OrgCommonEntity {
private Double price;
@Formula("(number * price)")
@Comment("总价")
private Double amount;

View File

@@ -1697,60 +1697,58 @@
"code": "emp.politicalStatus",
"name": "政治面貌",
"item": [
{
"code": "0",
"name": "中共党员"
},
{
"code": "1",
"name": "中共预备党员"
},
{
"code": "2",
"name": "共青团员"
},
{
"code": "3",
"name": "民革党员"
},
{
"code": "4",
"name": "民盟盟员"
},
{
"code": "5",
"name": "民建会员"
},
{
"code": "6",
"name": "民进会员"
},
{
"code": "7",
"name": "农工党党员"
},
{
"code": "8",
"name": "致公党党员"
},
{
"code": "9",
"name": "九三学社社员"
},
{
"code": "10",
"name": "台盟盟员"
},
{
"code": "11",
"name": "无党派人士"
},
{
"code": "12",
"name": "群众"
}
{
"code": "0",
"name": "中共党员"
},
{
"code": "1",
"name": "中共预备党员"
},
{
"code": "2",
"name": "共青团员"
},
{
"code": "3",
"name": "民革党员"
},
{
"code": "4",
"name": "民盟盟员"
},
{
"code": "5",
"name": "民建会员"
},
{
"code": "6",
"name": "民进会员"
},
{
"code": "7",
"name": "农工党党员"
},
{
"code": "8",
"name": "致公党党员"
},
{
"code": "9",
"name": "九三学社社员"
},
{
"code": "10",
"name": "台盟盟员"
},
{
"code": "11",
"name": "无党派人士"
},
{
"code": "12",
"name": "群众"
}
]
},
{
@@ -1769,7 +1767,6 @@
"code": "3",
"name": "归档"
},
{
"code": "4",
"name": "完成"
@@ -1992,7 +1989,6 @@
}
]
},
{
"code": "ipList.addressType",
"name": "ip地址类型",
@@ -2007,7 +2003,6 @@
}
]
},
{
"code": "loginUserHis.loginType",
"name": "登录类型",
@@ -2209,6 +2204,10 @@
{
"code": "2",
"name": "盘库单"
},
{
"code": "3",
"name": "调拨单"
}
]
},