|
@@ -29,7 +29,6 @@ import com.fjhx.common.entity.documentary.bo.DocumentaryData;
|
|
|
import com.fjhx.common.enums.FlowStatusEnum1;
|
|
|
import com.fjhx.common.service.contract.ContractTemplateService;
|
|
|
import com.fjhx.common.service.corporation.CorporationService;
|
|
|
-import com.fjhx.common.service.currency.CurrencyRateService;
|
|
|
import com.fjhx.common.service.documentary.GetDocumentaryBusinessTemplate;
|
|
|
import com.fjhx.common.utils.Assert;
|
|
|
import com.fjhx.customer.entity.customer.dto.CustomerDto;
|
|
@@ -40,6 +39,7 @@ import com.fjhx.file.entity.FileInfoVo;
|
|
|
import com.fjhx.file.service.FileInfoService;
|
|
|
import com.fjhx.file.utils.ObsFileUtil;
|
|
|
import com.fjhx.flow.service.flow.FlowExampleService;
|
|
|
+import com.fjhx.item.entity.product.bo.ProductAnalysisBo;
|
|
|
import com.fjhx.item.entity.product.dto.ProductInfoSelectDto;
|
|
|
import com.fjhx.item.entity.product.po.ProductInfo;
|
|
|
import com.fjhx.item.service.product.ProductInfoService;
|
|
@@ -102,6 +102,7 @@ import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@@ -154,9 +155,6 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
|
|
|
private PurchaseDetailService purchaseDetailService;
|
|
|
|
|
|
@Autowired
|
|
|
- private CurrencyRateService currencyRateService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
private ClaimContractService claimContractService;
|
|
|
|
|
|
@Autowired
|
|
@@ -2263,4 +2261,97 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 产品分析
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Page<ProductAnalysisBo> productAnalysis(ContractSelectDto dto) {
|
|
|
+ IWrapper<ProductInfo> wrapper = IWrapper.getWrapper();
|
|
|
+ Page<ProductAnalysisBo> productAnalysisPage = productInfoService.getProductAnalysisPage(dto.getPage(), wrapper);
|
|
|
+ List<ProductAnalysisBo> records = productAnalysisPage.getRecords();
|
|
|
+ if (ObjectUtil.isEmpty(records)) {
|
|
|
+ return productAnalysisPage;
|
|
|
+ }
|
|
|
+ List<Long> productIds = records.stream().map(ProductAnalysisBo::getProductId).collect(Collectors.toList());
|
|
|
+ List<ProductAnalysisBo> contractProductInfo = baseMapper.getContractProductInfo(IWrapper.getWrapper()
|
|
|
+ .in("cp.product_id", productIds)
|
|
|
+ .groupBy("cp.product_id")
|
|
|
+ .ge("c.create_time", dto.getBeginTime())
|
|
|
+ .le("c.create_time", dto.getEndTime())
|
|
|
+ );
|
|
|
+ Map<Long, ProductAnalysisBo> contractProductInfoMap = contractProductInfo.stream()
|
|
|
+ .collect(Collectors.toMap(ProductAnalysisBo::getProductId, Function.identity()));
|
|
|
+
|
|
|
+ List<ProductAnalysisBo> purchaseProductInfo = baseMapper.getPurchaseProductInfo(IWrapper.getWrapper()
|
|
|
+ .in("epp.product_id", productIds)
|
|
|
+ .groupBy("epp.product_id")
|
|
|
+ .ge("ep.create_time", dto.getBeginTime())
|
|
|
+ .le("ep.create_time", dto.getEndTime())
|
|
|
+ );
|
|
|
+ Map<Long, ProductAnalysisBo> purchaseProductInfoMap = purchaseProductInfo.stream()
|
|
|
+ .collect(Collectors.toMap(ProductAnalysisBo::getProductId, Function.identity()));
|
|
|
+
|
|
|
+ for (ProductAnalysisBo record : records) {
|
|
|
+
|
|
|
+ //合同统计
|
|
|
+ BigDecimal orderCount = BigDecimal.ZERO;
|
|
|
+ BigDecimal saleQuantity = BigDecimal.ZERO;
|
|
|
+ BigDecimal saleAmount = BigDecimal.ZERO;
|
|
|
+ BigDecimal saleAveragePrice = BigDecimal.ZERO;
|
|
|
+ BigDecimal saleMinPrice = BigDecimal.ZERO;
|
|
|
+ BigDecimal saleMaxPrice = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ ProductAnalysisBo contractProduct = contractProductInfoMap.get(record.getProductId());
|
|
|
+ if (ObjectUtil.isNotEmpty(contractProduct)) {
|
|
|
+ orderCount = contractProduct.getOrderCount();
|
|
|
+ saleQuantity = contractProduct.getSaleQuantity();
|
|
|
+ saleAmount = contractProduct.getSaleAmount();
|
|
|
+ //计算平均单价
|
|
|
+ if (contractProduct.getSaleQuantity().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ saleAveragePrice = contractProduct.getSaleAmount()
|
|
|
+ .divide(contractProduct.getSaleQuantity(), 4, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+ saleMinPrice = contractProduct.getSaleMinPrice();
|
|
|
+ saleMaxPrice = contractProduct.getSaleMaxPrice();
|
|
|
+ }
|
|
|
+
|
|
|
+ record.setOrderCount(orderCount.setScale(4, RoundingMode.HALF_UP));
|
|
|
+ record.setSaleQuantity(saleQuantity.setScale(4, RoundingMode.HALF_UP));
|
|
|
+ record.setSaleAmount(saleAmount.setScale(4, RoundingMode.HALF_UP));
|
|
|
+ record.setSaleAveragePrice(saleAveragePrice.setScale(4, RoundingMode.HALF_UP));
|
|
|
+ record.setSaleMinPrice(saleMinPrice.setScale(4, RoundingMode.HALF_UP));
|
|
|
+ record.setSaleMaxPrice(saleMaxPrice.setScale(4, RoundingMode.HALF_UP));
|
|
|
+
|
|
|
+ //采购统计
|
|
|
+ BigDecimal purchasesQuantity = BigDecimal.ZERO;
|
|
|
+ BigDecimal purchasesAmount = BigDecimal.ZERO;
|
|
|
+ BigDecimal purchasesAveragePrice = BigDecimal.ZERO;
|
|
|
+ BigDecimal purchasesMinPrice = BigDecimal.ZERO;
|
|
|
+ BigDecimal purchasesMaxPrice = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ ProductAnalysisBo purchaseProduct = purchaseProductInfoMap.get(record.getProductId());
|
|
|
+ if (ObjectUtil.isNotEmpty(purchaseProduct)) {
|
|
|
+ purchasesQuantity = purchaseProduct.getPurchasesQuantity();
|
|
|
+ purchasesAmount = purchaseProduct.getPurchasesAmount();
|
|
|
+ //计算平均单价
|
|
|
+ if (purchaseProduct.getPurchasesQuantity().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ purchasesAveragePrice = purchaseProduct.getPurchasesAmount()
|
|
|
+ .divide(purchaseProduct.getPurchasesQuantity(), 4, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+ purchasesMinPrice = purchaseProduct.getPurchasesMinPrice();
|
|
|
+ purchasesMaxPrice = purchaseProduct.getPurchasesMaxPrice();
|
|
|
+ }
|
|
|
+
|
|
|
+ record.setPurchasesQuantity(purchasesQuantity.setScale(4, RoundingMode.HALF_UP));
|
|
|
+ record.setPurchasesAmount(purchasesAmount.setScale(4, RoundingMode.HALF_UP));
|
|
|
+ record.setPurchasesAveragePrice(purchasesAveragePrice.setScale(4, RoundingMode.HALF_UP));
|
|
|
+ record.setPurchasesMinPrice(purchasesMinPrice.setScale(4, RoundingMode.HALF_UP));
|
|
|
+ record.setPurchasesMaxPrice(purchasesMaxPrice.setScale(4, RoundingMode.HALF_UP));
|
|
|
+
|
|
|
+ //计算总利润
|
|
|
+ record.setGrossProfit(record.getSaleAmount().subtract(record.getPurchasesAmount()));
|
|
|
+ }
|
|
|
+ return productAnalysisPage;
|
|
|
+ }
|
|
|
+
|
|
|
}
|