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:
@@ -58,7 +58,10 @@ public class WarehouseGoodsController {
|
||||
return this.service.searchByCode(request);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/goodsPrice")
|
||||
public Object goodsPrice(@RequestBody IdRequest request) {
|
||||
return this.service.goodsPrice(request);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.Ctx;
|
||||
import cn.lihongjie.coal.common.JpaUtils;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.warehouseGoods.dto.CreateWarehouseGoodsDto;
|
||||
import cn.lihongjie.coal.warehouseGoods.dto.UpdateWarehouseGoodsDto;
|
||||
@@ -18,6 +19,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
@@ -36,7 +38,10 @@ 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.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -66,9 +71,7 @@ public class WarehouseGoodsService
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
@Autowired
|
||||
WarehouseReceiptService warehouseReceiptService;
|
||||
|
||||
@Autowired WarehouseReceiptService warehouseReceiptService;
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
@@ -141,4 +144,35 @@ public class WarehouseGoodsService
|
||||
return mapper.toDto(all.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
public Object goodsPrice(IdRequest request) {
|
||||
|
||||
Object result =
|
||||
em.createNativeQuery(
|
||||
"""
|
||||
select min(d.price) as min_price,
|
||||
max(d.price) as max_price,
|
||||
avg(d.price) as avg_price,
|
||||
|
||||
min(d.price) filter ( where d.receipt_type = '0' ) as type_0_min_price,
|
||||
max(d.price) filter ( where d.receipt_type = '0' ) as type_0_max_price,
|
||||
avg(d.price) filter ( where d.receipt_type = '0' ) as type_0_avg_price,
|
||||
|
||||
min(d.price) filter ( where d.receipt_type = '1' ) as type_1_min_price,
|
||||
max(d.price) filter ( where d.receipt_type = '1' ) as type_1_max_price,
|
||||
avg(d.price) filter ( where d.receipt_type = '1' ) as type_1_avg_price
|
||||
from t_warehouse_receipt_detail d
|
||||
where id = :id
|
||||
|
||||
|
||||
|
||||
""",
|
||||
Tuple.class)
|
||||
.setParameter("id", request.getId())
|
||||
.getSingleResult();
|
||||
|
||||
List<Map> maps = JpaUtils.convertTuplesToRawMap(Collections.singletonList((Tuple) result));
|
||||
|
||||
return maps.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user