|
@@ -1,12 +1,19 @@
|
|
|
package com.fjhx.stock.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.entity.stock.StockWater;
|
|
|
import com.fjhx.stock.mapper.StockWaterMapper;
|
|
|
import com.fjhx.stock.service.StockWaterService;
|
|
|
+import com.fjhx.utils.WrapperUtil;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.Map;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -21,8 +28,300 @@ public class StockWaterServiceImpl extends ServiceImpl<StockWaterMapper, StockWa
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Object> getPickingStatistics(Map<String, String> condition) {
|
|
|
-
|
|
|
- return null;
|
|
|
+
|
|
|
+ QueryWrapper<?> wrapper = WrapperUtil.init(condition)
|
|
|
+ .periodOfTime("sw.CreatedTime") // 时间段查询
|
|
|
+ .getWrapper();
|
|
|
+
|
|
|
+ wrapper.eq("sw.IsDelete", 0); // 未删除
|
|
|
+ wrapper.in("sw.StockChangeType", 15, 20, 23);
|
|
|
+
|
|
|
+ // 获取统计数据
|
|
|
+ List<Map<String, Object>> pickingStatistics = baseMapper.getPickingStatistics(wrapper);
|
|
|
+
|
|
|
+ HashMap<String, Object> result = new HashMap<>();
|
|
|
+
|
|
|
+ // 按物料属性分组
|
|
|
+ Map<String, List<Map<String, Object>>> groupByStatistics = pickingStatistics.stream().collect(
|
|
|
+ Collectors.groupingBy(item -> item.get("materialType").toString()));
|
|
|
+
|
|
|
+ // 统计面料
|
|
|
+ HashMap<String, Object> fabricStatistics = new HashMap<>();
|
|
|
+ fabricStatistics.put("total", 0);
|
|
|
+ fabricStatistics.put("length", BigDecimal.ZERO);
|
|
|
+ fabricStatistics.put("measureArea", BigDecimal.ZERO);
|
|
|
+ fabricStatistics.put("money", BigDecimal.ZERO);
|
|
|
+
|
|
|
+ // 面料属性属性
|
|
|
+ List<Map<String, Object>> fabricTree = new ArrayList<>();
|
|
|
+
|
|
|
+ // 构建前端所需参数
|
|
|
+ for (Map.Entry<String, List<Map<String, Object>>> entry : groupByStatistics.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ List<Map<String, Object>> value = entry.getValue();
|
|
|
+
|
|
|
+ // 墨水统计
|
|
|
+ if (key.equals("3")) {
|
|
|
+ // 墨水统计
|
|
|
+ HashMap<Object, Object> inkStatistics = new HashMap<>();
|
|
|
+ // 件数
|
|
|
+ inkStatistics.put("total", value.size());
|
|
|
+ // 公斤
|
|
|
+ inkStatistics.put("weight", value.stream().map(item -> (BigDecimal) item.get("changeNum"))
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ // 金额
|
|
|
+ inkStatistics.put("money", value.stream()
|
|
|
+ .map(item -> ((BigDecimal) item.get("changeNum")).multiply((BigDecimal) item.get("materialPrice")))
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ result.put("inkStatistics", inkStatistics);
|
|
|
+
|
|
|
+ // 墨水领料明细
|
|
|
+ List<HashMap<String, Object>> inkDetails = new ArrayList<>(value.stream().collect(Collectors.toMap(
|
|
|
+ item -> item.get("userId").toString(), // 根据用户id分组
|
|
|
+ item -> { // 统计单条数据
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("userId", item.get("userId"));
|
|
|
+ map.put("userName", item.get("userName"));
|
|
|
+ map.put("total", 1);
|
|
|
+ map.put("weight", item.get("changeNum"));
|
|
|
+ map.put("money", ((BigDecimal) item.get("changeNum"))
|
|
|
+ .multiply((BigDecimal) item.get("materialPrice")).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ return map;
|
|
|
+ },
|
|
|
+ (v1, v2) -> { // 当有多条用户记录时,统计数据
|
|
|
+ v1.put("total", ((Integer) v1.get("total")) + 1);
|
|
|
+ v1.put("weight", ((BigDecimal) v1.get("weight")).add((BigDecimal) v2.get("weight")));
|
|
|
+ v1.put("money", ((BigDecimal) v1.get("money")).add((BigDecimal) v2.get("money")));
|
|
|
+ return v1;
|
|
|
+ })).values());
|
|
|
+
|
|
|
+ result.put("inkDetails", inkDetails);
|
|
|
+
|
|
|
+ }
|
|
|
+ // 面料统计
|
|
|
+ else {
|
|
|
+ // 卷数
|
|
|
+ int size = value.size();
|
|
|
+ // 米数
|
|
|
+ BigDecimal length = value.stream().map(item -> (BigDecimal) item.get("changeNum")).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ // 面积
|
|
|
+ BigDecimal measureArea = value.stream().map(item -> ((BigDecimal) item.get("changeNum"))
|
|
|
+ .multiply(BigDecimal.valueOf((float) item.get("materialWidth")))
|
|
|
+ .divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP))
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ // 金额
|
|
|
+ BigDecimal money = value.stream().map(item -> ((BigDecimal) item.get("changeNum"))
|
|
|
+ .multiply(BigDecimal.valueOf((float) item.get("materialWidth")))
|
|
|
+ .multiply((BigDecimal) item.get("materialPrice"))
|
|
|
+ .divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP))
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ // 添加到面料统计
|
|
|
+ fabricStatistics.put("total", (Integer) fabricStatistics.get("total") + size);
|
|
|
+ fabricStatistics.put("length", ((BigDecimal) fabricStatistics.get("length")).add(length));
|
|
|
+ fabricStatistics.put("measureArea", ((BigDecimal) fabricStatistics.get("measureArea")).add(measureArea));
|
|
|
+ fabricStatistics.put("money", ((BigDecimal) fabricStatistics.get("money")).add(money));
|
|
|
+
|
|
|
+ // 构建树形
|
|
|
+ Map<String, Object> attribute = new HashMap<>();
|
|
|
+ attribute.put("materialType", key);
|
|
|
+ attribute.put("total", size);
|
|
|
+ attribute.put("length", length);
|
|
|
+ attribute.put("measureArea", measureArea);
|
|
|
+ attribute.put("money", money);
|
|
|
+ attribute.put("name",
|
|
|
+ key.equals("0") ? "直喷" : key.equals("1") ? "热转" : key.equals("2") ? "打纸" : "其他");
|
|
|
+
|
|
|
+
|
|
|
+ // 查询子集
|
|
|
+ List<HashMap<String, Object>> children = new ArrayList<>(value.stream().collect(Collectors.toMap(
|
|
|
+ item -> item.get("userId").toString(), // 根据用户id分组
|
|
|
+ item -> { // 统计单条数据
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("userId", item.get("userId"));
|
|
|
+ map.put("name", item.get("userName"));
|
|
|
+ map.put("total", 1); // 数量
|
|
|
+ map.put("length", item.get("changeNum")); // 米数
|
|
|
+
|
|
|
+ // 计算面积
|
|
|
+ BigDecimal measureAreaItem = ((BigDecimal) item.get("changeNum"))
|
|
|
+ .multiply(BigDecimal.valueOf((float) item.get("materialWidth")))
|
|
|
+ .divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ map.put("measureArea", measureAreaItem); // 面积
|
|
|
+ map.put("money", measureAreaItem.multiply((BigDecimal) item.get("materialPrice"))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP)); // 金额
|
|
|
+ return map;
|
|
|
+ },
|
|
|
+ (v1, v2) -> { // 当有多条用户记录时,统计数据
|
|
|
+ v1.put("total", ((Integer) v1.get("total")) + 1);
|
|
|
+ v1.put("length", ((BigDecimal) v1.get("length")).add((BigDecimal) v2.get("length")));
|
|
|
+ v1.put("measureArea", ((BigDecimal) v1.get("measureArea")).add((BigDecimal) v2.get("measureArea")));
|
|
|
+ v1.put("money", ((BigDecimal) v1.get("money")).add((BigDecimal) v2.get("money")));
|
|
|
+ return v1;
|
|
|
+ })).values());
|
|
|
+
|
|
|
+ attribute.put("children", children);
|
|
|
+
|
|
|
+ fabricTree.add(attribute);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 面料统计
|
|
|
+ result.put("fabricStatistics", fabricStatistics);
|
|
|
+
|
|
|
+ // 面料树形
|
|
|
+ result.put("fabricTree", fabricTree);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> contractPaymentStatistics(Map<String, String> condition) {
|
|
|
+ QueryWrapper<?> wrapper = WrapperUtil.init(condition).periodOfTime("pc.ApprovalTime").getWrapper();
|
|
|
+ wrapper.eq("pc.IsDelete", 0);
|
|
|
+ wrapper.in("s.AccountDate ", 45, 30, 15, 0);
|
|
|
+
|
|
|
+ List<Map<String, Object>> list = baseMapper.contractPaymentStatistics(wrapper);
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+
|
|
|
+ /*
|
|
|
+ 0 =》申购金额
|
|
|
+ 1 =》面料采购
|
|
|
+ 2 =》墨水采购
|
|
|
+ 3 =》其他
|
|
|
+ */
|
|
|
+ Map<String, BigDecimal> collect = list.stream().collect(Collectors.toMap(
|
|
|
+ item -> {
|
|
|
+ String materialType = item.get("materialType").toString();
|
|
|
+ switch (materialType) {
|
|
|
+ case "3":
|
|
|
+ return "2";
|
|
|
+ case "4":
|
|
|
+ return "3";
|
|
|
+ default:
|
|
|
+ return "1";
|
|
|
+ }
|
|
|
+ },
|
|
|
+ item -> ((BigDecimal) item.get("money")).setScale(2, RoundingMode.HALF_UP),
|
|
|
+ BigDecimal::add
|
|
|
+ ));
|
|
|
+ collect.putIfAbsent("1", BigDecimal.ZERO);
|
|
|
+ collect.putIfAbsent("2", BigDecimal.ZERO);
|
|
|
+ collect.putIfAbsent("3", BigDecimal.ZERO);
|
|
|
+ collect.put("0", collect.get("1").add(collect.get("2")).add(collect.get("3")));
|
|
|
+
|
|
|
+ /*
|
|
|
+ 4 =》45天账期
|
|
|
+ 5 =》30天账期
|
|
|
+ 6 =》15天账期
|
|
|
+ 7 =》预付款
|
|
|
+ */
|
|
|
+ Map<String, BigDecimal> collect2 = list.stream().collect(Collectors.toMap(
|
|
|
+ item -> {
|
|
|
+ Integer accountDate = (Integer) item.get("accountDate");
|
|
|
+ switch (accountDate) {
|
|
|
+ case 45:
|
|
|
+ return "4";
|
|
|
+ case 30:
|
|
|
+ return "5";
|
|
|
+ case 15:
|
|
|
+ return "6";
|
|
|
+ default:
|
|
|
+ return "7";
|
|
|
+ }
|
|
|
+ },
|
|
|
+ item -> ((BigDecimal) item.get("money")).setScale(2, RoundingMode.HALF_UP),
|
|
|
+ BigDecimal::add
|
|
|
+ ));
|
|
|
+ collect.putIfAbsent("4", BigDecimal.ZERO);
|
|
|
+ collect.putIfAbsent("5", BigDecimal.ZERO);
|
|
|
+ collect.putIfAbsent("6", BigDecimal.ZERO);
|
|
|
+ collect.putIfAbsent("7", BigDecimal.ZERO);
|
|
|
+
|
|
|
+ collect.putAll(collect2);
|
|
|
+
|
|
|
+ // 赋值全部金额查询信息
|
|
|
+ result.put("money", collect);
|
|
|
+
|
|
|
+
|
|
|
+ // 根据供应商id,统计出向每家公司付款的金额
|
|
|
+ Collection<Map<String, Object>> values = list.stream().collect(Collectors.toMap(
|
|
|
+ item -> item.get("supplierId").toString(),
|
|
|
+ item -> {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("supplierId", item.get("supplierId"));
|
|
|
+ map.put("supplierName", item.get("supplierName"));
|
|
|
+ map.put("money", ((BigDecimal) item.get("money")).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ return map;
|
|
|
+ },
|
|
|
+ (v1, v2) -> {
|
|
|
+ v1.put("money", ((BigDecimal) v1.get("money")).add((BigDecimal) v2.get("money")));
|
|
|
+ return v1;
|
|
|
+ }
|
|
|
+ )).values();
|
|
|
+
|
|
|
+ /*
|
|
|
+ 0 全部公司统计
|
|
|
+ 1 50万以上
|
|
|
+ 2 20~50万
|
|
|
+ 3 10~20万
|
|
|
+ 4 5~20万
|
|
|
+ 5 5万以下
|
|
|
+ */
|
|
|
+ Map<String, List<Map<String, Object>>> map = values.stream().collect(Collectors.groupingBy(item -> {
|
|
|
+ BigDecimal money = (BigDecimal) item.get("money");
|
|
|
+ if (money.compareTo(new BigDecimal("50000")) < 0) {
|
|
|
+ return "5";
|
|
|
+ }
|
|
|
+ if (money.compareTo(new BigDecimal("100000")) > 0) {
|
|
|
+ return "4";
|
|
|
+ }
|
|
|
+ if (money.compareTo(new BigDecimal("200000")) > 0) {
|
|
|
+ return "3";
|
|
|
+ }
|
|
|
+ if (money.compareTo(new BigDecimal("500000")) > 0) {
|
|
|
+ return "4";
|
|
|
+ }
|
|
|
+ return "5";
|
|
|
+ }));
|
|
|
+
|
|
|
+ map.put("0", new ArrayList<>(values));
|
|
|
+ map.putIfAbsent("1", new ArrayList<>());
|
|
|
+ map.putIfAbsent("2", new ArrayList<>());
|
|
|
+ map.putIfAbsent("3", new ArrayList<>());
|
|
|
+ map.putIfAbsent("4", new ArrayList<>());
|
|
|
+ map.putIfAbsent("5", new ArrayList<>());
|
|
|
+
|
|
|
+ result.put("statisticsSupplier", map);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<Map<String, Object>> subscriptionAmountPage(Map<String, String> condition) {
|
|
|
+
|
|
|
+ QueryWrapper<?> wrapper = WrapperUtil
|
|
|
+ .init(condition)
|
|
|
+ .periodOfTime("pc.ApprovalTime")
|
|
|
+ .in("pc.SupplierId", "supplierIdList")
|
|
|
+ .getWrapper();
|
|
|
+
|
|
|
+ wrapper.eq("pc.IsDelete", 0);
|
|
|
+
|
|
|
+ Page<Map<String, Object>> result = baseMapper.subscriptionAmountPage(createPage(condition), wrapper);
|
|
|
+ List<Map<String, Object>> records = result.getRecords();
|
|
|
+
|
|
|
+ records.forEach(item -> {
|
|
|
+ item.put("purchaseQty", ((BigDecimal) item.get("purchaseQty")).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ item.put("totalAmount", ((BigDecimal) item.get("totalAmount")).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ item.put("adjustAmount", item.get("adjustAmount") == null ? "-" : ((BigDecimal) item.get("adjustAmount")).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ item.put("approvalTime", DateUtil.format((Date) item.get("approvalTime"), "yyyy-MM-dd"));
|
|
|
+ });
|
|
|
+
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
}
|