mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
feat: 库存查询接口
This commit is contained in:
@@ -86,26 +86,6 @@ public class WarehouseGoodsEntity extends OrgCommonEntity {
|
||||
@ManyToOne
|
||||
private WarehouseSupplierEntity defaultSupplier;
|
||||
|
||||
// @Comment("是否启用属性")
|
||||
// private Boolean enableAttribute;
|
||||
//
|
||||
//
|
||||
// @Comment("属性配置")
|
||||
// @Type(JsonType.class)
|
||||
// @Column(columnDefinition = "jsonb")
|
||||
// private List<GoodsAttrConfig> attributes;
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// // 不同的规格
|
||||
// @OneToMany(mappedBy = "parent")
|
||||
// private List<WarehouseGoodsEntity> children;
|
||||
//
|
||||
// @ManyToOne
|
||||
// private WarehouseGoodsEntity parent;
|
||||
|
||||
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public class WarehouseGoodsService
|
||||
.setParameter("warehouseId", request.getWarehouseId())
|
||||
.setParameter("goodsIds", request.getGoodsId())
|
||||
.getSingleResult();
|
||||
if (request == null){
|
||||
if (result == null){
|
||||
return 0;
|
||||
}
|
||||
return result.intValue();
|
||||
|
||||
@@ -0,0 +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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.warehouseGoodsSummary.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateWarehouseGoodsSummaryDto extends OrgCommonDto {}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.warehouseGoodsSummary.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UpdateWarehouseGoodsSummaryDto extends OrgCommonDto {}
|
||||
@@ -0,0 +1,79 @@
|
||||
package cn.lihongjie.coal.warehouseGoodsSummary.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.warehouse.dto.WarehouseDto;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class WarehouseGoodsSummaryDto extends OrgCommonDto {
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private WarehouseDto category;
|
||||
|
||||
@ManyToOne
|
||||
private WarehouseDto brand;
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private WarehouseDto unit;
|
||||
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private WarehouseDto warehouse;
|
||||
|
||||
|
||||
|
||||
private Integer detailCount;
|
||||
|
||||
private Double type0Number;
|
||||
private Double type1Number;
|
||||
|
||||
private Double type0Amount;
|
||||
|
||||
private Double type1Amount;
|
||||
|
||||
|
||||
@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;
|
||||
|
||||
|
||||
|
||||
@Comment("是否启用保质期")
|
||||
|
||||
private Boolean enableShelfLife;
|
||||
|
||||
|
||||
@Comment("保质期 天")
|
||||
private Integer shelfLife;
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package cn.lihongjie.coal.warehouseGoodsSummary.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
import cn.lihongjie.coal.warehouse.entity.WarehouseEntity;
|
||||
import cn.lihongjie.coal.warehouseGoodsBrand.entity.WarehouseGoodsBrandEntity;
|
||||
import cn.lihongjie.coal.warehouseGoodsCategory.entity.WarehouseGoodsCategoryEntity;
|
||||
import cn.lihongjie.coal.warehouseGoodsUnit.entity.WarehouseGoodsUnitEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Subselect;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Subselect(
|
||||
"""
|
||||
|
||||
select
|
||||
distinct on (g.id)
|
||||
g.id,
|
||||
g.create_time,
|
||||
g.create_user_id,
|
||||
g.file_ids,
|
||||
g.update_time,
|
||||
g.update_user_id,
|
||||
g.code,
|
||||
g.name,
|
||||
g.remarks,
|
||||
g.sort_key,
|
||||
g.status,
|
||||
g.organization_id,
|
||||
g.bar_code,
|
||||
g.price1,
|
||||
g.price2,
|
||||
g.price3,
|
||||
g.price4,
|
||||
g.price5,
|
||||
g.size,
|
||||
g.spec,
|
||||
g.volume,
|
||||
g.weight,
|
||||
g.brand_id,
|
||||
g.category_id,
|
||||
g.unit_id,
|
||||
g.enable_shelf_life,
|
||||
g.shelf_life,
|
||||
d.warehouse_id as warehouse_id,
|
||||
count(d.id) over (partition by g.id) as detail_count,
|
||||
round((sum(d.number) filter ( where d.receipt_type = '0' ) over (partition by g.id, d.warehouse_id))::numeric,
|
||||
2) as type0_number,
|
||||
round((sum(d.number) filter ( where d.receipt_type = '1' ) over (partition by g.id, d.warehouse_id))::numeric,
|
||||
2) as type1_number,
|
||||
|
||||
round((sum(d.amount) filter ( where d.receipt_type = '0' ) over (partition by g.id, d.warehouse_id))::numeric,
|
||||
2) as type0_amount,
|
||||
round((sum(d.amount) filter ( where d.receipt_type = '1' ) over (partition by g.id, d.warehouse_id))::numeric,
|
||||
2) as type1_amount
|
||||
|
||||
from t_warehouse_goods g
|
||||
inner join t_warehouse_receipt_detail d on d.goods_id = g.id and d.organization_id = g.organization_id
|
||||
inner join t_warehouse_receipt r on r.id = d.receipt_id and r.organization_id = g.organization_id
|
||||
|
||||
|
||||
""")
|
||||
public class WarehouseGoodsSummaryEntity extends OrgCommonEntity {
|
||||
|
||||
@ManyToOne
|
||||
private WarehouseGoodsCategoryEntity category;
|
||||
|
||||
@ManyToOne
|
||||
private WarehouseGoodsBrandEntity brand;
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private WarehouseGoodsUnitEntity unit;
|
||||
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private WarehouseEntity warehouse;
|
||||
|
||||
|
||||
|
||||
private Integer detailCount;
|
||||
|
||||
private Double type0Number;
|
||||
private Double type1Number;
|
||||
|
||||
private Double type0Amount;
|
||||
|
||||
private Double type1Amount;
|
||||
|
||||
|
||||
@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;
|
||||
|
||||
|
||||
|
||||
@Comment("是否启用保质期")
|
||||
|
||||
private Boolean enableShelfLife;
|
||||
|
||||
|
||||
@Comment("保质期 天")
|
||||
private Integer shelfLife;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.lihongjie.coal.warehouseGoodsSummary.mapper;
|
||||
|
||||
import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
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 org.mapstruct.Mapper;
|
||||
import org.mapstruct.control.DeepClone;
|
||||
|
||||
@Mapper(
|
||||
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class, CommonEntityMapper.class},
|
||||
mappingControl = DeepClone.class)
|
||||
public interface WarehouseGoodsSummaryMapper
|
||||
extends BaseMapper<
|
||||
WarehouseGoodsSummaryEntity,
|
||||
WarehouseGoodsSummaryDto,
|
||||
CreateWarehouseGoodsSummaryDto,
|
||||
UpdateWarehouseGoodsSummaryDto> {}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.lihongjie.coal.warehouseGoodsSummary.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.warehouseGoodsSummary.entity.WarehouseGoodsSummaryEntity;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface WarehouseGoodsSummaryRepository
|
||||
extends BaseRepository<WarehouseGoodsSummaryEntity> {
|
||||
@Query("select false")
|
||||
boolean isLinked(List<String> ids);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
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.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
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 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;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class WarehouseGoodsSummaryService
|
||||
extends BaseService<WarehouseGoodsSummaryEntity, WarehouseGoodsSummaryRepository> {
|
||||
@Autowired private WarehouseGoodsSummaryRepository repository;
|
||||
|
||||
@Autowired private WarehouseGoodsSummaryMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
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) {
|
||||
boolean linked = this.repository.isLinked(request.getIds());
|
||||
|
||||
if (linked) {
|
||||
throw new BizException("数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import cn.lihongjie.coal.warehouseGoodsSummary.controller.WarehouseGoodsSummaryController
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(WarehouseGoodsSummaryController.class)
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(new CommonQuery())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user