|
@@ -0,0 +1,262 @@
|
|
|
|
+package com.fjhx.service.apply.impl;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
|
+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.base.Condition;
|
|
|
|
+import com.fjhx.entity.apply.ApplyPurchase;
|
|
|
|
+import com.fjhx.mapper.apply.ApplyPurchaseMapper;
|
|
|
|
+import com.fjhx.service.apply.ApplyPurchaseService;
|
|
|
|
+import com.fjhx.utils.BigDecimalUtil;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * 物料申购 服务实现类
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author ${author}
|
|
|
|
+ * @since 2022-09-14
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, ApplyPurchase> implements ApplyPurchaseService {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String getCode() {
|
|
|
|
+ return "PB-" + DateUtil.format(new Date(), "yyMMdd-HHmmss-SSS");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Map<Integer, Map<String, Object>> typeStatistics(Condition condition) {
|
|
|
|
+
|
|
|
|
+ Map<Integer, Map<String, Object>> result = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ Date beginTime = condition.getBeginTime();
|
|
|
|
+ Date endTime = condition.getEndTime();
|
|
|
|
+ String keyword = condition.getKeyword();
|
|
|
|
+
|
|
|
|
+ // 查询条件
|
|
|
|
+ QueryWrapper<Object> wrapper = Wrappers.query()
|
|
|
|
+ .between("ap.create_time", beginTime, endTime)
|
|
|
|
+ .and(ObjectUtil.isNotEmpty(keyword), q -> q.like("m.name", keyword).or().like("m.code", keyword))
|
|
|
|
+ .orderByDesc("apd.id");
|
|
|
|
+
|
|
|
|
+ List<Map<String, Object>> list = baseMapper.getTypeStatisticsList(wrapper);
|
|
|
|
+
|
|
|
|
+ Map<Integer, List<Map<String, Object>>> mapByType = list.stream()
|
|
|
|
+ .collect(Collectors.groupingBy(item -> Convert.toInt(item.get("type"))));
|
|
|
|
+
|
|
|
|
+ // 面料申购统计(0直喷 + 1热转 + 2打纸 + 4其他)
|
|
|
|
+ Map<String, Object> fabricMap = null;
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < 5; i++) {
|
|
|
|
+ Map<String, Object> typeStatistics = getTypeStatistics(i, mapByType.get(i));
|
|
|
|
+ result.put(i, typeStatistics);
|
|
|
|
+
|
|
|
|
+ if (i != 3) {
|
|
|
|
+ if (fabricMap == null) {
|
|
|
|
+ fabricMap = ObjectUtil.clone(typeStatistics);
|
|
|
|
+ fabricMap.put("technologyType", 5);
|
|
|
|
+ } else {
|
|
|
|
+ fabricMap.put("num", Convert.toInt(fabricMap.get("num")) + Convert.toInt(typeStatistics.get("num")));
|
|
|
|
+ fabricMap.put("purchaseQty", BigDecimalUtil.add(fabricMap.get("purchaseQty"), typeStatistics.get("purchaseQty")));
|
|
|
|
+ fabricMap.put("area", BigDecimalUtil.add(fabricMap.get("area"), typeStatistics.get("area")));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ result.put(5, fabricMap);
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<Map<String, Object>> flowStatistics(Condition condition) {
|
|
|
|
+ Date beginTime = condition.getBeginTime();
|
|
|
|
+ Date endTime = condition.getEndTime();
|
|
|
|
+ String keyword = condition.getKeyword();
|
|
|
|
+ Integer technologyType = condition.getInt("technologyType");
|
|
|
|
+
|
|
|
|
+ QueryWrapper<Object> wrapper = Wrappers.query()
|
|
|
|
+ .between("ap.create_time", beginTime, endTime)
|
|
|
|
+ .and(ObjectUtil.isNotEmpty(keyword), q -> q.like("m.Code", keyword).or().like("m.Name", keyword))
|
|
|
|
+ .func(ObjectUtil.isNotEmpty(technologyType), q -> {
|
|
|
|
+ if (technologyType.equals(5)) {
|
|
|
|
+ q.in("m.technology_type", 0, 1, 2, 4);
|
|
|
|
+ } else {
|
|
|
|
+ q.eq("m.technology_type", technologyType);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .groupBy("ap.flow_status");
|
|
|
|
+
|
|
|
|
+ List<Map<String, Object>> list = baseMapper.flowStatistics(wrapper);
|
|
|
|
+
|
|
|
|
+ Map<Integer, Long> collect = list.stream().collect(Collectors.toMap(
|
|
|
|
+ item -> (Integer) item.get("flowStatus"),
|
|
|
|
+ item -> (Long) item.get("count")
|
|
|
|
+ ));
|
|
|
|
+
|
|
|
|
+ Map<String, Object> approvedMap = new HashMap<>();
|
|
|
|
+ approvedMap.put("key", "审批中");
|
|
|
|
+ approvedMap.put("value", 1);
|
|
|
|
+ approvedMap.put("count", (collect.get(0) == null ? 0 : collect.get(0)) + (collect.get(1) == null ? 0 : collect.get(1)));
|
|
|
|
+
|
|
|
|
+ Map<String, Object> passedMap = new HashMap<>();
|
|
|
|
+ passedMap.put("key", "已通过");
|
|
|
|
+ passedMap.put("value", 2);
|
|
|
|
+ passedMap.put("count", collect.get(2) == null ? 0 : collect.get(2));
|
|
|
|
+
|
|
|
|
+ Map<String, Object> rejectedMap = new HashMap<>();
|
|
|
|
+ rejectedMap.put("key", "已驳回");
|
|
|
|
+ rejectedMap.put("value", 3);
|
|
|
|
+ rejectedMap.put("count", collect.get(3) == null ? 0 : collect.get(3));
|
|
|
|
+
|
|
|
|
+ Map<String, Object> wholeMap = new HashMap<>();
|
|
|
|
+ wholeMap.put("key", "全部");
|
|
|
|
+ wholeMap.put("count", (Long) approvedMap.get("count") + (Long) passedMap.get("count") + (Long) rejectedMap.get("count"));
|
|
|
|
+
|
|
|
|
+ return Arrays.asList(wholeMap, approvedMap, rejectedMap, passedMap);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Page<Map<String, Object>> getPage(Condition condition) {
|
|
|
|
+ String keyword = condition.getKeyword();
|
|
|
|
+ Date beginTime = condition.getBeginTime();
|
|
|
|
+ Date endTime = condition.getEndTime();
|
|
|
|
+ Integer technologyType = condition.getInt("technologyType");
|
|
|
|
+ Integer status = condition.getInt("status");
|
|
|
|
+
|
|
|
|
+ QueryWrapper<Object> wrapper = Wrappers.query()
|
|
|
|
+ .between("ap.create_time", beginTime, endTime)
|
|
|
|
+ .and(ObjectUtil.isNotEmpty(keyword), q -> q.like("m.Code", keyword).or().like("m.Name", keyword))
|
|
|
|
+ .func(ObjectUtil.isNotEmpty(technologyType), q -> {
|
|
|
|
+ if (technologyType.equals(5)) {
|
|
|
|
+ q.in("m.technology_type", 0, 1, 2, 4);
|
|
|
|
+ } else {
|
|
|
|
+ q.eq("m.technology_type", technologyType);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .func(ObjectUtil.isNotEmpty(status), q -> {
|
|
|
|
+ if (status.equals(1)) {
|
|
|
|
+ q.in("ap.flow_status", 0, 1);
|
|
|
|
+ } else {
|
|
|
|
+ q.eq("ap.flow_status", status);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .orderByAsc("pc.PurContractState")
|
|
|
|
+ .orderByDesc("ap.CreatedTime");
|
|
|
|
+
|
|
|
|
+// Page<Map<String, Object>> page = baseMapper.getPage(createPage(condition), wrapper);
|
|
|
|
+//
|
|
|
|
+// List<Map<String, Object>> records = page.getRecords();
|
|
|
|
+// if (records.size() == 0) {
|
|
|
|
+// return page;
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// // 获取物料编码集合
|
|
|
|
+// List<String> materialCodeList = records.stream()
|
|
|
|
+// .map(item -> item.get("materialCode").toString()).collect(Collectors.toList());
|
|
|
|
+//
|
|
|
|
+// // 查询库存,最长滞留时间和滞留超过30天数量
|
|
|
|
+// Date date = new Date();
|
|
|
|
+// DateTime dateTime = DateUtil.offsetDay(date, -30);
|
|
|
|
+// Map<String, Map<String, Object>> delayMap = baseMapper.selectDelay(
|
|
|
|
+// dateTime,
|
|
|
|
+// Wrappers.query().in("sd.MaterialCode", materialCodeList).groupBy("sd.MaterialCode")
|
|
|
|
+// );
|
|
|
|
+//
|
|
|
|
+// // 近30天消耗量
|
|
|
|
+// Map<String, Object> consumeMap = stockWaterService.listMaps(
|
|
|
|
+// Wrappers.<StockWater>query().select("sum(TotalQty) overUseQty", "MaterialCode materialCode")
|
|
|
|
+// .lambda()
|
|
|
|
+// .in(StockWater::getStockchangetype, 20, 23)
|
|
|
|
+// .gt(StockWater::getCreatedtime, dateTime)
|
|
|
|
+// .groupBy(StockWater::getMaterialcode)
|
|
|
|
+// ).stream().collect(Collectors.toMap(
|
|
|
|
+// item -> item.get("materialCode").toString(),
|
|
|
|
+// item -> item.get("overUseQty")
|
|
|
|
+// ));
|
|
|
|
+//
|
|
|
|
+// for (Map<String, Object> record : records) {
|
|
|
|
+// String materialCode = record.get("materialCode").toString();
|
|
|
|
+// Map<String, Object> map = delayMap.get(materialCode);
|
|
|
|
+//
|
|
|
|
+// if (map != null) {
|
|
|
|
+// record.putAll(map);
|
|
|
|
+// record.put("maxDelayTime", DateUtil.betweenDay(date, (Date) map.get("maxDelayTime"), true));
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// record.putIfAbsent("stockQty", 0);
|
|
|
|
+// record.putIfAbsent("maxDelayTime", 0);
|
|
|
|
+// record.putIfAbsent("delayQuantity", 0);
|
|
|
|
+//
|
|
|
|
+// Object overUseQty = consumeMap.get(materialCode);
|
|
|
|
+// record.put("overUseQty", overUseQty == null ? BigDecimal.ZERO : overUseQty);
|
|
|
|
+//
|
|
|
|
+// record.put("purchaseQty", BigDecimalUtil.keepDecimals(record.get("purchaseQty")));
|
|
|
|
+// record.put("onWayQuantity", BigDecimalUtil.keepDecimals(record.get("onWayQuantity")));
|
|
|
|
+//
|
|
|
|
+// int purContractState = Integer.parseInt(record.get("purContractState").toString());
|
|
|
|
+// switch (purContractState) {
|
|
|
|
+// case 0:
|
|
|
|
+// record.put("purContractState", "待确认");
|
|
|
|
+// break;
|
|
|
|
+// case 1:
|
|
|
|
+// record.put("purContractState", "审批中");
|
|
|
|
+// break;
|
|
|
|
+// case 2:
|
|
|
|
+// record.put("purContractState", "进行中");
|
|
|
|
+// break;
|
|
|
|
+// case 3:
|
|
|
|
+// record.put("purContractState", "已完成");
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据类型统计物料采购情况
|
|
|
|
+ */
|
|
|
|
+ private Map<String, Object> getTypeStatistics(int technologyType, List<Map<String, Object>> list) {
|
|
|
|
+
|
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ int num = 0;
|
|
|
|
+ BigDecimal purchaseQty = BigDecimal.ZERO;
|
|
|
|
+ BigDecimal area = BigDecimal.ZERO;
|
|
|
|
+
|
|
|
|
+ if (ObjectUtil.isNotEmpty(list)) {
|
|
|
|
+ for (Map<String, Object> item : list) {
|
|
|
|
+
|
|
|
|
+ BigDecimal quantity = Convert.toBigDecimal(item.get("quantity"));
|
|
|
|
+ BigDecimal width = Convert.toBigDecimal(item.get("width"));
|
|
|
|
+
|
|
|
|
+ num++;
|
|
|
|
+ purchaseQty = purchaseQty.add(BigDecimalUtil.keepDecimals(quantity, 1));
|
|
|
|
+ if (technologyType != 3) {
|
|
|
|
+ area = area.add(BigDecimalUtil.init(quantity).multiply(width).divide(100, 1).getValue());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 统计
|
|
|
|
+ map.put("technologyType", technologyType);
|
|
|
|
+ map.put("num", num);
|
|
|
|
+ map.put("purchaseQty", purchaseQty);
|
|
|
|
+ if (technologyType != 3) {
|
|
|
|
+ map.put("area", area);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|