mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 23:57:12 +08:00
添加销售订单报表
This commit is contained in:
@@ -317,7 +317,7 @@ public class PurchaseOrderService
|
||||
|
||||
|
||||
select to_char(date_trunc('${timeDimension}', o.start_time), 'YYYY-MM-DD') as time,
|
||||
array_agg(id) as ids
|
||||
array_agg(o.id) as ids
|
||||
<#list reportFields as field>
|
||||
|
||||
|
||||
@@ -336,8 +336,8 @@ public class PurchaseOrderService
|
||||
<#if field.fieldName == 'total'>, ${field.function}(o.amount * o.price + o.other_fee) as ${underScore(field.fieldName)}_${field.function} </#if>
|
||||
|
||||
|
||||
<#if field.fieldName == 'receivedAmount'>, ${field.function}((select round(sum(sz)::numeric, 2) from t_weight_device_data where purchase_order_id = o.id )) as ${underScore(field.fieldName)}_${field.function} </#if>
|
||||
<#if field.fieldName == 'leftAmount'>, ${field.function}( coalesce(o.amount, 0) - coalesce( (select round(sum(sz)::numeric, 2) from t_weight_device_data where purchase_order_id = o.id ) , 0)) as ${underScore(field.fieldName)}_${field.function} </#if>
|
||||
<#if field.fieldName == 'receivedAmount'>, ${field.function}((select round(sum(sz)::::numeric, 2) from t_weight_device_data where purchase_order_id = o.id )) as ${underScore(field.fieldName)}_${field.function} </#if>
|
||||
<#if field.fieldName == 'leftAmount'>, ${field.function}( coalesce(o.amount, 0) - coalesce( (select round(sum(sz)::::numeric, 2) from t_weight_device_data where purchase_order_id = o.id ) , 0)) as ${underScore(field.fieldName)}_${field.function} </#if>
|
||||
<#if field.fieldName == 'totalCarCount'>, ${field.function}( (select count(1) from t_weight_device_data where purchase_order_id = o.id ) ) as ${underScore(field.fieldName)}_${field.function} </#if>
|
||||
|
||||
|
||||
|
||||
@@ -4,10 +4,7 @@ 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.saleOrder.dto.CreateSaleOrderDto;
|
||||
import cn.lihongjie.coal.saleOrder.dto.SaleOrderDto;
|
||||
import cn.lihongjie.coal.saleOrder.dto.UpdateSaleOrderDto;
|
||||
import cn.lihongjie.coal.saleOrder.dto.UpdateWeightDataDto;
|
||||
import cn.lihongjie.coal.saleOrder.dto.*;
|
||||
import cn.lihongjie.coal.saleOrder.service.SaleOrderService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -63,4 +60,10 @@ public class SaleOrderController {
|
||||
public Page<SaleOrderDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/report")
|
||||
public Object report(@RequestBody SaleOrderReportRequest request) {
|
||||
return this.service.report(request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package cn.lihongjie.coal.saleOrder.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
|
||||
@Data
|
||||
public class SaleOrderReportRequest extends CommonQuery {
|
||||
|
||||
@Comment(
|
||||
"""
|
||||
时间维度
|
||||
year
|
||||
month
|
||||
|
||||
""")
|
||||
private String timeDimension;
|
||||
|
||||
@Comment(
|
||||
"""
|
||||
统计字段
|
||||
|
||||
客户 supplierId
|
||||
产品 productId
|
||||
|
||||
|
||||
""")
|
||||
private List<String> reportFields;
|
||||
|
||||
/**
|
||||
*
|
||||
* 采购数量 amount
|
||||
* 已发货数量 receivedAmount
|
||||
* 未发货数量 leftAmount
|
||||
* 车数 totalCarCount
|
||||
* 单价 price
|
||||
* 总价 total
|
||||
* 其他费用 otherFee
|
||||
*
|
||||
*
|
||||
*/
|
||||
private List<FieldInfo> fieldInfos;
|
||||
|
||||
private LocalDate startTime;
|
||||
private LocalDate endTime;
|
||||
|
||||
/** 过滤条件 */
|
||||
private List<String> supplierIds;
|
||||
|
||||
private List<String> productIds;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Data
|
||||
public static class FieldInfo {
|
||||
private String fieldName;
|
||||
|
||||
@Comment("sum avg count max min")
|
||||
private String function;
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,12 @@ 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.FreeMakerUtils;
|
||||
import cn.lihongjie.coal.common.JpaUtils;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.organizationConfig.entity.OrganizationConfigEntity;
|
||||
import cn.lihongjie.coal.organizationConfig.service.OrganizationConfigService;
|
||||
import cn.lihongjie.coal.saleOrder.dto.CreateSaleOrderDto;
|
||||
import cn.lihongjie.coal.saleOrder.dto.SaleOrderDto;
|
||||
import cn.lihongjie.coal.saleOrder.dto.UpdateSaleOrderDto;
|
||||
import cn.lihongjie.coal.saleOrder.dto.UpdateWeightDataDto;
|
||||
import cn.lihongjie.coal.saleOrder.dto.*;
|
||||
import cn.lihongjie.coal.saleOrder.entity.SaleOrderEntity;
|
||||
import cn.lihongjie.coal.saleOrder.mapper.SaleOrderMapper;
|
||||
import cn.lihongjie.coal.saleOrder.repository.SaleOrderRepository;
|
||||
@@ -21,6 +19,8 @@ import cn.lihongjie.coal.weightDeviceData.entity.WeightDeviceDataEntity;
|
||||
import cn.lihongjie.coal.weightDeviceData.mapper.WeightDeviceDataMapper;
|
||||
import cn.lihongjie.coal.weightDeviceData.repository.WeightDeviceDataRepository;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.Tuple;
|
||||
@@ -33,6 +33,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -41,8 +42,11 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -287,4 +291,127 @@ public class SaleOrderService extends BaseService<SaleOrderEntity, SaleOrderRepo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PersistenceContext
|
||||
EntityManager em;
|
||||
|
||||
public Object report(SaleOrderReportRequest request) {
|
||||
|
||||
if (CollectionUtils.isEmpty(request.getFieldInfos())) {
|
||||
request.setFieldInfos(new ArrayList<>());
|
||||
}
|
||||
|
||||
String sql =
|
||||
FreeMakerUtils.render(
|
||||
"""
|
||||
|
||||
|
||||
select to_char(date_trunc('${timeDimension}', o.start_time), 'YYYY-MM-DD') as time,
|
||||
array_agg(o.id) as ids
|
||||
<#list reportFields as field>
|
||||
|
||||
|
||||
|
||||
|
||||
<#if field == 'supplierId'>,s.id as supplier_id, max(s.name) as supplier_name, max(s.code) as supplier_code </#if>
|
||||
<#if field == 'productId'>,p.id as product_id, max(p.name) as product_name, max(p.code) as product_code </#if>
|
||||
|
||||
|
||||
</#list>
|
||||
<#list fieldInfos as field>
|
||||
|
||||
<#if field.fieldName == 'price'>, ${field.function}(o.price) as ${underScore(field.fieldName)}_${field.function} </#if>
|
||||
<#if field.fieldName == 'otherFee'>, ${field.function}(o.other_fee) as ${underScore(field.fieldName)}_${field.function} </#if>
|
||||
<#if field.fieldName == 'amount'>, ${field.function}(o.amount) as ${underScore(field.fieldName)}_${field.function} </#if>
|
||||
<#if field.fieldName == 'total'>, ${field.function}(o.amount * o.price + o.other_fee) as ${underScore(field.fieldName)}_${field.function} </#if>
|
||||
|
||||
|
||||
<#if field.fieldName == 'receivedAmount'>, ${field.function}((select round(sum(sz)::::numeric, 2) from t_weight_device_data where purchase_order_id = o.id )) as ${underScore(field.fieldName)}_${field.function} </#if>
|
||||
<#if field.fieldName == 'leftAmount'>, ${field.function}( coalesce(o.amount, 0) - coalesce( (select round(sum(sz)::::numeric, 2) from t_weight_device_data where purchase_order_id = o.id ) , 0)) as ${underScore(field.fieldName)}_${field.function} </#if>
|
||||
<#if field.fieldName == 'totalCarCount'>, ${field.function}( (select count(1) from t_weight_device_data where purchase_order_id = o.id ) ) as ${underScore(field.fieldName)}_${field.function} </#if>
|
||||
|
||||
|
||||
</#list>
|
||||
|
||||
from
|
||||
t_sale_order o
|
||||
left join t_product p on o.product_info_id = p.id
|
||||
left join t_supplier s on o.supplier_id = s.id
|
||||
|
||||
|
||||
where 1=1
|
||||
|
||||
<#if startTime??> and o.start_time >= :startTime </#if>
|
||||
|
||||
<#if endTime??> and o.start_time <= :endTime </#if>
|
||||
|
||||
<#if supplierIds??> and s.id in :supplierIds </#if>
|
||||
|
||||
<#if productIds??> and p.id in :productIds </#if>
|
||||
|
||||
|
||||
|
||||
|
||||
group by 1, date_trunc('${timeDimension}', o.start_time)
|
||||
<#list reportFields as field>
|
||||
|
||||
|
||||
<#if field == 'supplierId'>,s.id </#if>
|
||||
<#if field == 'productId'>,p.id </#if>
|
||||
|
||||
|
||||
</#list>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
""",
|
||||
request);
|
||||
|
||||
var countSql = "select count(1) from (" + sql + ") as t";
|
||||
|
||||
var selectSql =
|
||||
"select * from ("
|
||||
+ sql
|
||||
+ ") as t limit "
|
||||
+ request.getPageSize()
|
||||
+ " offset "
|
||||
+ request.getPageNo() * request.getPageSize();
|
||||
|
||||
Integer count = JpaUtils.execNativeQuery(em, countSql, request, Integer.class).get(0);
|
||||
|
||||
List<Tuple> data = JpaUtils.execNativeQuery(em, selectSql, request, Tuple.class);
|
||||
|
||||
var resultList = JpaUtils.convertTuplesToMap(data);
|
||||
|
||||
var ans =
|
||||
resultList.stream()
|
||||
.map(
|
||||
x ->
|
||||
((Map) x)
|
||||
.entrySet().stream()
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
(Map.Entry e) ->
|
||||
CaseFormat
|
||||
.LOWER_UNDERSCORE
|
||||
.to(
|
||||
CaseFormat
|
||||
.LOWER_CAMEL,
|
||||
e.getKey()
|
||||
.toString()),
|
||||
e ->
|
||||
ObjectUtils
|
||||
.defaultIfNull(
|
||||
e
|
||||
.getValue(),
|
||||
""))))
|
||||
.toList();
|
||||
|
||||
return new PageImpl<>(ans, PageRequest.of(0, request.getPageSize()), count);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user