diff --git a/src/main/java/cn/lihongjie/coal/warehouseGoods/dto/CreateWarehouseGoodsDto.java b/src/main/java/cn/lihongjie/coal/warehouseGoods/dto/CreateWarehouseGoodsDto.java index 0f8c2735..13960911 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseGoods/dto/CreateWarehouseGoodsDto.java +++ b/src/main/java/cn/lihongjie/coal/warehouseGoods/dto/CreateWarehouseGoodsDto.java @@ -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; +} diff --git a/src/main/java/cn/lihongjie/coal/warehouseGoods/dto/UpdateWarehouseGoodsDto.java b/src/main/java/cn/lihongjie/coal/warehouseGoods/dto/UpdateWarehouseGoodsDto.java index 2d5603d7..b23a5fad 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseGoods/dto/UpdateWarehouseGoodsDto.java +++ b/src/main/java/cn/lihongjie/coal/warehouseGoods/dto/UpdateWarehouseGoodsDto.java @@ -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; +} diff --git a/src/main/java/cn/lihongjie/coal/warehouseGoods/dto/WarehouseGoodsDto.java b/src/main/java/cn/lihongjie/coal/warehouseGoods/dto/WarehouseGoodsDto.java index 57c48ebb..5b7400e5 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseGoods/dto/WarehouseGoodsDto.java +++ b/src/main/java/cn/lihongjie/coal/warehouseGoods/dto/WarehouseGoodsDto.java @@ -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; +} diff --git a/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/controller/WarehouseGoodsSummaryController.java b/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/controller/WarehouseGoodsSummaryController.java index 0cb832b9..d3fb0917 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/controller/WarehouseGoodsSummaryController.java +++ b/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/controller/WarehouseGoodsSummaryController.java @@ -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 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 list(@RequestBody CommonQuery request) { +// return this.service.list(request); +// } +//} diff --git a/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/service/WarehouseGoodsSummaryService.java b/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/service/WarehouseGoodsSummaryService.java index 65c0188a..f960d220 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/service/WarehouseGoodsSummaryService.java +++ b/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/service/WarehouseGoodsSummaryService.java @@ -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 { - @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 list(CommonQuery query) { - Page 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 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, 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 { +// @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 list(CommonQuery query) { +// Page 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 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, 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()); +// } +//} diff --git a/src/main/java/cn/lihongjie/coal/warehouseReceipt/dto/CreateWarehouseReceiptDto.java b/src/main/java/cn/lihongjie/coal/warehouseReceipt/dto/CreateWarehouseReceiptDto.java index 0437be2e..a6602f06 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseReceipt/dto/CreateWarehouseReceiptDto.java +++ b/src/main/java/cn/lihongjie/coal/warehouseReceipt/dto/CreateWarehouseReceiptDto.java @@ -46,4 +46,7 @@ public class CreateWarehouseReceiptDto extends OrgCommonDto { + @Comment("制单人") + private String creator; + } diff --git a/src/main/java/cn/lihongjie/coal/warehouseReceipt/dto/UpdateWarehouseReceiptDto.java b/src/main/java/cn/lihongjie/coal/warehouseReceipt/dto/UpdateWarehouseReceiptDto.java index 4452e296..2a9911c2 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseReceipt/dto/UpdateWarehouseReceiptDto.java +++ b/src/main/java/cn/lihongjie/coal/warehouseReceipt/dto/UpdateWarehouseReceiptDto.java @@ -43,4 +43,8 @@ public class UpdateWarehouseReceiptDto extends OrgCommonDto { @OneToMany private List detail; + + + @Comment("制单人") + private String creator; } diff --git a/src/main/java/cn/lihongjie/coal/warehouseReceipt/dto/WarehouseReceiptDto.java b/src/main/java/cn/lihongjie/coal/warehouseReceipt/dto/WarehouseReceiptDto.java index e4c11185..06e128bf 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseReceipt/dto/WarehouseReceiptDto.java +++ b/src/main/java/cn/lihongjie/coal/warehouseReceipt/dto/WarehouseReceiptDto.java @@ -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; + } diff --git a/src/main/java/cn/lihongjie/coal/warehouseReceipt/entity/WarehouseReceiptEntity.java b/src/main/java/cn/lihongjie/coal/warehouseReceipt/entity/WarehouseReceiptEntity.java index 4a1ee3f9..34d35071 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseReceipt/entity/WarehouseReceiptEntity.java +++ b/src/main/java/cn/lihongjie/coal/warehouseReceipt/entity/WarehouseReceiptEntity.java @@ -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 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; - - -} \ No newline at end of file + @Comment("制单人") + private String creator; +} diff --git a/src/main/java/cn/lihongjie/coal/warehouseReceipt/repository/WarehouseReceiptRepository.java b/src/main/java/cn/lihongjie/coal/warehouseReceipt/repository/WarehouseReceiptRepository.java index 590f4bfb..38ca5e57 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseReceipt/repository/WarehouseReceiptRepository.java +++ b/src/main/java/cn/lihongjie/coal/warehouseReceipt/repository/WarehouseReceiptRepository.java @@ -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 { - @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 findAllByWarehouseIdInAndShelveIdInAndGoodsIdIn(Set warehouseIds, Set shelveIds, Set goodsIds); + } diff --git a/src/main/java/cn/lihongjie/coal/warehouseReceipt/service/WarehouseReceiptService.java b/src/main/java/cn/lihongjie/coal/warehouseReceipt/service/WarehouseReceiptService.java index a538ae08..205d65a5 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseReceipt/service/WarehouseReceiptService.java +++ b/src/main/java/cn/lihongjie/coal/warehouseReceipt/service/WarehouseReceiptService.java @@ -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() { + @Override + public Predicate toPredicate(Root 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 allById = this.repository.findAllById(request.getIds()); this.repository.deleteAllById(request.getIds()); handleType3Delete(allById); - warehouseGoodsSummaryService.refresh(allById); +// warehouseGoodsSummaryService.refresh(allById); } private void handleType3Delete(List allById) { diff --git a/src/main/java/cn/lihongjie/coal/warehouseReceiptDetail/dto/CreateWarehouseReceiptDetailDto.java b/src/main/java/cn/lihongjie/coal/warehouseReceiptDetail/dto/CreateWarehouseReceiptDetailDto.java index 42cca9b7..b947ba19 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseReceiptDetail/dto/CreateWarehouseReceiptDetailDto.java +++ b/src/main/java/cn/lihongjie/coal/warehouseReceiptDetail/dto/CreateWarehouseReceiptDetailDto.java @@ -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; } diff --git a/src/main/java/cn/lihongjie/coal/warehouseReceiptDetail/dto/UpdateWarehouseReceiptDetailDto.java b/src/main/java/cn/lihongjie/coal/warehouseReceiptDetail/dto/UpdateWarehouseReceiptDetailDto.java index afc8537c..373279a9 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseReceiptDetail/dto/UpdateWarehouseReceiptDetailDto.java +++ b/src/main/java/cn/lihongjie/coal/warehouseReceiptDetail/dto/UpdateWarehouseReceiptDetailDto.java @@ -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; } diff --git a/src/main/java/cn/lihongjie/coal/warehouseReceiptDetail/dto/WarehouseReceiptDetailDto.java b/src/main/java/cn/lihongjie/coal/warehouseReceiptDetail/dto/WarehouseReceiptDetailDto.java index 83ede9b6..d48a7314 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseReceiptDetail/dto/WarehouseReceiptDetailDto.java +++ b/src/main/java/cn/lihongjie/coal/warehouseReceiptDetail/dto/WarehouseReceiptDetailDto.java @@ -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; } diff --git a/src/main/java/cn/lihongjie/coal/warehouseReceiptDetail/entity/WarehouseReceiptDetailEntity.java b/src/main/java/cn/lihongjie/coal/warehouseReceiptDetail/entity/WarehouseReceiptDetailEntity.java index c73ee296..bdf76bc6 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseReceiptDetail/entity/WarehouseReceiptDetailEntity.java +++ b/src/main/java/cn/lihongjie/coal/warehouseReceiptDetail/entity/WarehouseReceiptDetailEntity.java @@ -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; diff --git a/src/main/resources/config/dictionary.json b/src/main/resources/config/dictionary.json index 1759bcdf..f163fd3e 100644 --- a/src/main/resources/config/dictionary.json +++ b/src/main/resources/config/dictionary.json @@ -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": "调拨单" } ] },