|
|
@@ -0,0 +1,124 @@
|
|
|
+package org.springblade.salesPart.corps.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.core.mp.support.Condition;
|
|
|
+import org.springblade.core.mp.support.Query;
|
|
|
+import org.springblade.core.secure.utils.SecureUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.salesPart.corps.service.ICorpsDescService;
|
|
|
+import org.springblade.salesPart.entity.PjCorpsDesc;
|
|
|
+import org.springblade.salesPart.entity.PjOrder;
|
|
|
+import org.springblade.salesPart.order.service.IOrderService;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author :jixinyuan
|
|
|
+ * @date : 2023/6/30
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@AllArgsConstructor
|
|
|
+@RequestMapping("/statisticsCorp")
|
|
|
+public class CorpsStatisticsController {
|
|
|
+
|
|
|
+ private final ICorpsDescService corpsDescService;
|
|
|
+
|
|
|
+ private final IOrderService orderService;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 自定义分页 客户详情
|
|
|
+ */
|
|
|
+ @GetMapping("/page")
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
+ @ApiOperation(value = "分页", notes = "传入corpsDesc")
|
|
|
+ public R<IPage<PjCorpsDesc>> page(PjCorpsDesc corpsDescDto, Query query) {
|
|
|
+ corpsDescDto.setIsDeleted(0);//默认查有效的
|
|
|
+ corpsDescDto.setEnableOrNot(0);//默认查有效的
|
|
|
+ corpsDescDto.setTenantId(SecureUtil.getTenantId());
|
|
|
+ IPage<PjCorpsDesc> pages = corpsDescService.selectPartsCorpsDescPage(Condition.getPage(query), corpsDescDto);
|
|
|
+ for (PjCorpsDesc corpsDescDto1 : pages.getRecords()) {
|
|
|
+ LambdaQueryWrapper<PjOrder> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(PjOrder::getCustomerId, corpsDescDto1.getId());
|
|
|
+ if (corpsDescDto1.getCorpType().equals("KH")) {
|
|
|
+ lambdaQueryWrapper.eq(PjOrder::getBsType, "XS");
|
|
|
+ } else {
|
|
|
+ lambdaQueryWrapper.eq(PjOrder::getBsType, "CG");
|
|
|
+ }
|
|
|
+ List<PjOrder> orderList = orderService.list(lambdaQueryWrapper);
|
|
|
+ if (ObjectUtils.isNotNull(orderList)) {
|
|
|
+ BigDecimal totalAmount = orderList.stream().map(PjOrder::getTotalMoney).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ //已付
|
|
|
+ corpsDescDto1.setPaidAmount(orderList.stream().map(PjOrder::getPaymentAmountTl).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //未付
|
|
|
+ corpsDescDto1.setUnpaidAmount(totalAmount.subtract(corpsDescDto1.getPaidAmount()));
|
|
|
+ corpsDescDto1.setTotalAmount(totalAmount);
|
|
|
+ } else {
|
|
|
+ //已付
|
|
|
+ corpsDescDto1.setPaidAmount(new BigDecimal("0.00"));
|
|
|
+ //未付
|
|
|
+ corpsDescDto1.setUnpaidAmount(new BigDecimal("0.00"));
|
|
|
+ corpsDescDto1.setTotalAmount(new BigDecimal("0.00"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.data(pages);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 自定义分页 客户详情(统计)
|
|
|
+ */
|
|
|
+ @GetMapping("/pageStatistics")
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
+ @ApiOperation(value = "分页", notes = "传入corpsDesc")
|
|
|
+ public R<Map<String, Object>> pageStatistics(PjCorpsDesc corpsDescDto) {
|
|
|
+ corpsDescDto.setIsDeleted(0);//默认查有效的
|
|
|
+ corpsDescDto.setEnableOrNot(0);//默认查有效的
|
|
|
+ corpsDescDto.setTenantId(SecureUtil.getTenantId());
|
|
|
+ List<PjCorpsDesc> corpsDescDtoList = corpsDescService.selectPartsCorpsStatistics(corpsDescDto);
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ //未付
|
|
|
+ BigDecimal paidAmount = new BigDecimal("0.00");
|
|
|
+ //已付
|
|
|
+ BigDecimal unpaidAmount = new BigDecimal("0.00");
|
|
|
+ //总金额
|
|
|
+ BigDecimal totalAmount = new BigDecimal("0.00");
|
|
|
+ for (PjCorpsDesc corpsDescDto1 : corpsDescDtoList) {
|
|
|
+ LambdaQueryWrapper<PjOrder> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(PjOrder::getCustomerId, corpsDescDto1.getId());
|
|
|
+ if (corpsDescDto1.getCorpType().equals("KH")) {
|
|
|
+ lambdaQueryWrapper.eq(PjOrder::getBsType, "XS");
|
|
|
+ } else {
|
|
|
+ lambdaQueryWrapper.eq(PjOrder::getBsType, "CG");
|
|
|
+ }
|
|
|
+ List<PjOrder> orderList = orderService.list(lambdaQueryWrapper);
|
|
|
+ if (ObjectUtils.isNotNull(orderList)) {
|
|
|
+ BigDecimal sumAmount = orderList.stream().map(PjOrder::getTotalMoney).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ totalAmount = totalAmount.add(orderList.stream().map(PjOrder::getTotalMoney).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //已付
|
|
|
+ unpaidAmount = unpaidAmount.add(orderList.stream().map(PjOrder::getPaymentAmountTl).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //未付
|
|
|
+ paidAmount = paidAmount.add(sumAmount.subtract(unpaidAmount));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //已付
|
|
|
+ map.put("unpaidAmount", unpaidAmount);
|
|
|
+ //未付
|
|
|
+ map.put("paidAmount", paidAmount);
|
|
|
+ //总金额
|
|
|
+ map.put("totalAmount", totalAmount);
|
|
|
+ return R.data(map);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|