|
@@ -3,6 +3,7 @@ package com.fjhx.stock.service.impl;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.entity.stock.StockWater;
|
|
@@ -352,4 +353,151 @@ public class StockWaterServiceImpl extends ServiceImpl<StockWaterMapper, StockWa
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> remainingToday(Map<String, String> condition) {
|
|
|
+
|
|
|
+ List<Map<String, Object>> list = baseMapper.remainingToday();
|
|
|
+
|
|
|
+ Map<String, Map<String, Object>> Statistics = list.stream()
|
|
|
+// .filter(item -> !item.get("materialType").toString().equals("4")) // 过滤出其他不统计
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ item -> item.get("materialType").toString().equals("3") ? "ink" : "fabric",
|
|
|
+ this::remainingTodayGetMap,
|
|
|
+ this::remainingTodayMerge
|
|
|
+ ));
|
|
|
+
|
|
|
+ HashMap<String, Object> absentInk = new HashMap<>();
|
|
|
+ absentInk.put("count", 0);
|
|
|
+ absentInk.put("sum", BigDecimal.ZERO);
|
|
|
+ absentInk.put("measureArea", BigDecimal.ZERO);
|
|
|
+ absentInk.put("money", BigDecimal.ZERO);
|
|
|
+ Statistics.putIfAbsent("ink", absentInk);
|
|
|
+
|
|
|
+ HashMap<String, Object> absentFabric = new HashMap<>();
|
|
|
+ absentInk.put("count", 0);
|
|
|
+ absentInk.put("sum", BigDecimal.ZERO);
|
|
|
+ absentInk.put("money", BigDecimal.ZERO);
|
|
|
+ Statistics.putIfAbsent("fabric", absentFabric);
|
|
|
+
|
|
|
+ HashMap<String, Object> result = new HashMap<>(Statistics);
|
|
|
+
|
|
|
+ Map<String, Map<String, Object>> typeStatistics = list.stream()
|
|
|
+ .filter(item -> !item.get("materialType").toString().equals("3")) // 过滤出墨水不统计
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ item -> item.get("materialType").toString(),
|
|
|
+ this::remainingTodayGetMap,
|
|
|
+ this::remainingTodayMerge
|
|
|
+ ));
|
|
|
+
|
|
|
+ result.put("typeStatistics", typeStatistics);
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Map<String, Object>> purposeStatistics = list.stream()
|
|
|
+ .filter(item -> !item.get("materialType").toString().equals("3")) // 过滤出墨水不统计
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ item -> item.get("materialPurpose").toString(),
|
|
|
+ item -> {
|
|
|
+ Map<String, Object> map = remainingTodayGetMap(item);
|
|
|
+ map.put("materialPurpose", item.get("materialPurpose"));
|
|
|
+ return map;
|
|
|
+ },
|
|
|
+ this::remainingTodayMerge
|
|
|
+ ));
|
|
|
+
|
|
|
+ result.put("purposeStatistics", new ArrayList<>(purposeStatistics.values()));
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<Map<String, Object>> remainingTodayPage(Map<String, String> condition) {
|
|
|
+ QueryWrapper<?> wrapper = WrapperUtil.init(condition)
|
|
|
+ .keyword("m.Code", "m.Name") // 关键字查询
|
|
|
+ .eq("m.CategoryCode", "categoryCode") // 物料分类
|
|
|
+ .eq("IF( a.CheckTagCount = a.TagQuantity AND a.CheckTagCount = a.HandTagCount, 1, 0)", "inventoryResults")
|
|
|
+ .getWrapper();
|
|
|
+
|
|
|
+ // 物料分组
|
|
|
+ wrapper.groupBy("m.id");
|
|
|
+ // 在库
|
|
|
+ wrapper.eq("sd.IsDelete", 0);
|
|
|
+
|
|
|
+ // 仓库id
|
|
|
+ String houseId = condition.get("houseId");
|
|
|
+ if (ObjectUtil.isNotEmpty(houseId)) {
|
|
|
+ List<String> materialCodeList = baseMapper.selectMaterialIdByHouseId(houseId);
|
|
|
+ wrapper.in("m.code", materialCodeList);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 工艺类型
|
|
|
+ String technologyType = condition.get("technologyType");
|
|
|
+ if (ObjectUtil.isNotEmpty(technologyType)) {
|
|
|
+ if (technologyType.equals("4")) {
|
|
|
+ wrapper.in("m.TechnologyType", 0, 1, 2);
|
|
|
+ } else {
|
|
|
+ wrapper.eq("m.TechnologyType", technologyType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 用途
|
|
|
+ String purpose = condition.get("purpose");
|
|
|
+ if (ObjectUtil.isNotEmpty(purpose)) {
|
|
|
+ if (purpose.equals("其他")) {
|
|
|
+ wrapper.ne("m.TechnologyType", 3);
|
|
|
+ wrapper.eq("ifNull(m.Purpose,'其他')", purpose);
|
|
|
+ } else {
|
|
|
+ wrapper.eq("m.Purpose", purpose);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询基本信息
|
|
|
+ Page<Map<String, Object>> page = baseMapper.remainingTodayPage(createPage(condition), wrapper);
|
|
|
+
|
|
|
+ List<Map<String, Object>> records = page.getRecords();
|
|
|
+ if (records.size() == 0) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> materialIdList = records.stream().map(item -> item.get("materialId").toString()).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 查库存所在信息
|
|
|
+ List<Map<String, Object>> materialHouseList = baseMapper.selectMaterialHouse(
|
|
|
+ Wrappers.query().in("m.id", materialIdList).eq("sd.IsDelete", 0).groupBy("m.id,sh.id"));
|
|
|
+
|
|
|
+ // 按物料id分组
|
|
|
+ Map<String, List<Map<String, Object>>> materialIdGroup =
|
|
|
+ materialHouseList.stream().collect(Collectors.groupingBy(item -> item.get("materialId").toString()));
|
|
|
+
|
|
|
+ records.forEach(item -> {
|
|
|
+ String materialId = item.get("materialId").toString();
|
|
|
+ // 赋值物料所在库存信息
|
|
|
+ item.put("houseInfo", materialIdGroup.get(materialId));
|
|
|
+ });
|
|
|
+
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> remainingTodayGetMap(Map<String, Object> item) {
|
|
|
+ BigDecimal quantity = (BigDecimal) item.get("quantity");
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("count", 1);
|
|
|
+ map.put("sum", quantity.setScale(2, RoundingMode.HALF_UP));
|
|
|
+ if (!item.get("materialType").toString().equals("3")) {
|
|
|
+ map.put("measureArea", quantity.multiply(BigDecimal.valueOf((float) item.get("materialWidth"))).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ map.put("money", quantity.multiply((BigDecimal) item.get("price")).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> remainingTodayMerge(Map<String, Object> v1, Map<String, Object> v2) {
|
|
|
+ v1.put("count", (Integer) v1.get("count") + 1);
|
|
|
+ v1.put("sum", ((BigDecimal) v1.get("sum")).add((BigDecimal) v2.get("sum")));
|
|
|
+ Object measureArea = v1.get("measureArea");
|
|
|
+ if (measureArea != null) {
|
|
|
+ v1.put("measureArea", ((BigDecimal) measureArea).add((BigDecimal) v2.get("measureArea")));
|
|
|
+ }
|
|
|
+ v1.put("money", ((BigDecimal) v1.get("money")).add((BigDecimal) v2.get("money")));
|
|
|
+ return v1;
|
|
|
+ }
|
|
|
+
|
|
|
}
|