|
@@ -1,18 +1,24 @@
|
|
|
package com.fjhx.service.stock.impl;
|
|
|
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+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.base.Condition;
|
|
|
import com.fjhx.constants.StatusConstant;
|
|
|
import com.fjhx.entity.stock.Stock;
|
|
|
import com.fjhx.entity.water.WaterTag;
|
|
|
import com.fjhx.enums.InTypeEnum;
|
|
|
+import com.fjhx.enums.MaterialTypeEnum;
|
|
|
import com.fjhx.mapper.stock.StockMapper;
|
|
|
import com.fjhx.service.stock.StockService;
|
|
|
import com.fjhx.utils.BigDecimalUtil;
|
|
|
+import com.fjhx.utils.WrapperUtil;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@@ -85,4 +91,138 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> statistics() {
|
|
|
+
|
|
|
+ HashMap<String, Object> result = new HashMap<>();
|
|
|
+
|
|
|
+
|
|
|
+ List<Map<String, Object>> list = baseMapper.statistics();
|
|
|
+
|
|
|
+ Map<Integer, Map<String, Object>> typeCollect = list.stream().collect(Collectors.toMap(
|
|
|
+ item -> Convert.toInt(item.get("technologyType")),
|
|
|
+ item -> {
|
|
|
+ Map<String, Object> map = putInfo(item);
|
|
|
+ map.put("type", MaterialTypeEnum.getName(Convert.toInt(item.get("technologyType"))));
|
|
|
+ return map;
|
|
|
+ },
|
|
|
+ this::addStatistics
|
|
|
+ ));
|
|
|
+
|
|
|
+ Map<String, Map<String, Object>> purposeCollect = list.stream()
|
|
|
+ .filter(item -> !MaterialTypeEnum.INK.getType().equals(Convert.toInt(item.get("technologyType"))))
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ item -> Convert.toStr(item.get("purpose")),
|
|
|
+ item -> {
|
|
|
+ Map<String, Object> map = putInfo(item);
|
|
|
+ map.put("materialPurpose", item.get("purpose"));
|
|
|
+ return map;
|
|
|
+ },
|
|
|
+ this::addStatistics
|
|
|
+ ));
|
|
|
+
|
|
|
+ result.put("ink", typeCollect.get(MaterialTypeEnum.INK.getType()));
|
|
|
+ result.put("typeStatistics", Arrays.asList(
|
|
|
+ typeCollect.get(MaterialTypeEnum.JET_PRINT.getType()),
|
|
|
+ typeCollect.get(MaterialTypeEnum.TRANSFER.getType()),
|
|
|
+ typeCollect.get(MaterialTypeEnum.TYPING.getType()),
|
|
|
+ typeCollect.get(MaterialTypeEnum.OTHER.getType())
|
|
|
+ ));
|
|
|
+
|
|
|
+ Map<String, Object> fabric = addStatistics(
|
|
|
+ typeCollect.get(MaterialTypeEnum.JET_PRINT.getType()),
|
|
|
+ typeCollect.get(MaterialTypeEnum.TRANSFER.getType()),
|
|
|
+ typeCollect.get(MaterialTypeEnum.TYPING.getType()),
|
|
|
+ typeCollect.get(MaterialTypeEnum.OTHER.getType())
|
|
|
+ );
|
|
|
+ fabric.remove("type");
|
|
|
+ result.put("fabric", fabric);
|
|
|
+ result.put("purposeStatistics", new ArrayList<>(purposeCollect.values()));
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<Map<String, Object>> getPage(Condition condition) {
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 赋值统计信息
|
|
|
+ */
|
|
|
+ private Map<String, Object> putInfo(Map<String, Object> map) {
|
|
|
+
|
|
|
+ HashMap<String, Object> itemMap = new HashMap<>();
|
|
|
+
|
|
|
+
|
|
|
+ Integer number = Convert.toInt(map.get("number"));
|
|
|
+
|
|
|
+ BigDecimal quantity = Convert.toBigDecimal(map.get("quantity"));
|
|
|
+
|
|
|
+ BigDecimal area = BigDecimalUtil.init(quantity).multiply(map.get("width")).divide(100, 2).getValue();
|
|
|
+
|
|
|
+ BigDecimal money = BigDecimalUtil.multiply(quantity, map.get("price"), 2);
|
|
|
+
|
|
|
+ itemMap.put("number", number);
|
|
|
+ itemMap.put("quantity", quantity);
|
|
|
+ itemMap.put("area", area);
|
|
|
+ itemMap.put("money", money);
|
|
|
+
|
|
|
+ return itemMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ @SafeVarargs
|
|
|
+ private final Map<String, Object> addStatistics(Map<String, Object>... item) {
|
|
|
+ Map<String, Object> v1 = new HashMap<>(item[0]);
|
|
|
+
|
|
|
+ for (int i = 1; i < item.length; i++) {
|
|
|
+ Map<String, Object> v2 = item[i];
|
|
|
+
|
|
|
+ v1.put("number", Convert.toInt(v1.get("number")) + Convert.toInt(v2.get("number")));
|
|
|
+ v1.put("quantity", BigDecimalUtil.add(v1.get("quantity"), v2.get("quantity")));
|
|
|
+ v1.put("area", BigDecimalUtil.add(v1.get("area"), v2.get("area")));
|
|
|
+ v1.put("money", BigDecimalUtil.add(v1.get("money"), v2.get("money")));
|
|
|
+ }
|
|
|
+
|
|
|
+ return v1;
|
|
|
+ }
|
|
|
+
|
|
|
+ private QueryWrapper<?> createRemainingTodayWrapper(Condition condition) {
|
|
|
+ QueryWrapper<?> wrapper = WrapperUtil.init(condition)
|
|
|
+ .keyword("m.Code", "m.Name")
|
|
|
+ .eq("m.CategoryCode", "categoryCode")
|
|
|
+ .eq("m.Purpose", "purpose")
|
|
|
+ .getWrapper();
|
|
|
+
|
|
|
+
|
|
|
+ wrapper.and(q -> q.likeRight("m.code", "01.").or().likeRight("m.code", "03.008."));
|
|
|
+
|
|
|
+ Integer inventoryResults = condition.getInt("inventoryResults");
|
|
|
+ wrapper.eq(inventoryResults == 0,
|
|
|
+ "IF( a.CheckTagCount = a.TagQuantity AND a.CheckTagCount = a.HandTagCount, 1, 0)", inventoryResults);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Integer technologyType = condition.getInt("technologyType");
|
|
|
+ if (ObjectUtil.isNotEmpty(technologyType)) {
|
|
|
+ if (technologyType == 5) {
|
|
|
+ wrapper.in("m.TechnologyType", 0, 1, 2, 4);
|
|
|
+ } else {
|
|
|
+ wrapper.eq("m.TechnologyType", technologyType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ wrapper.groupBy("m.id");
|
|
|
+ wrapper.orderByAsc("m.Name");
|
|
|
+ return wrapper;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|