|
@@ -3,14 +3,17 @@ package com.fjhx.service.apply.impl;
|
|
|
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.StockJournalTypeConstant;
|
|
|
import com.fjhx.entity.apply.ApplyPurchase;
|
|
|
import com.fjhx.entity.product.ProductInfo;
|
|
|
import com.fjhx.entity.stock.Stock;
|
|
|
+import com.fjhx.entity.stock.StockJournal;
|
|
|
import com.fjhx.enums.apply.ApplyPurchaseStatusEnum;
|
|
|
import com.fjhx.mapper.apply.ApplyPurchaseMapper;
|
|
|
import com.fjhx.params.apply.ApplyPurchaseVo;
|
|
|
import com.fjhx.service.apply.ApplyPurchaseService;
|
|
|
import com.fjhx.service.product.ProductInfoService;
|
|
|
+import com.fjhx.service.stock.StockJournalService;
|
|
|
import com.fjhx.service.stock.StockService;
|
|
|
import com.fjhx.uitl.code.CodeEnum;
|
|
|
import com.fjhx.utils.UserClientUtil;
|
|
@@ -18,13 +21,19 @@ import com.fjhx.utils.wrapperUtil.IWrapper;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.core.redis.lock.RedisLockClient;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.utils.DateUtil;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -46,7 +55,10 @@ public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, A
|
|
|
@Autowired
|
|
|
private ProductInfoService productInfoService;
|
|
|
|
|
|
- private final String REDIS_LOCK_CACHE_KEY = "seq:lock:" + AuthUtil.getTenantId() + ":material:";
|
|
|
+ @Autowired
|
|
|
+ private StockJournalService stockJournalService;
|
|
|
+
|
|
|
+ private final String REDIS_LOCK_CACHE_KEY = "seq:lock:" + AuthUtil.getTenantId() + ":apply_purchase:";
|
|
|
|
|
|
@Override
|
|
|
public Page<ApplyPurchase> getPage(Map<String, Object> condition) {
|
|
@@ -161,4 +173,64 @@ public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, A
|
|
|
}
|
|
|
return purchase;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 待采购列表
|
|
|
+ *
|
|
|
+ * @param condition 查询条件
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Page<ApplyPurchase> stayPurchasePage(Map<String, Object> condition) {
|
|
|
+ IWrapper<ApplyPurchase> wrapper = IWrapper.getWrapper(condition);
|
|
|
+
|
|
|
+ wrapper.lt("t1", ApplyPurchase::getStatus, ApplyPurchaseStatusEnum.STATUS_20.getKey())
|
|
|
+ .eq("t1", ApplyPurchase::getStatus)
|
|
|
+ .apply(Func.isNotEmpty(condition.get("code")), "instr(t1.`code`, '" + condition.get("code") + "') > 0")
|
|
|
+ .apply(Func.isNotEmpty(condition.get("goodsCode")), "instr(t2.`code`, '" + condition.get("goodsCode") + "') > 0")
|
|
|
+ .apply(Func.isNotEmpty(condition.get("goodsName")), "instr(t2.`name`, '" + condition.get("goodsName") + "') > 0")
|
|
|
+ .eq("t1", ApplyPurchase::getCreateUser, condition.get("applyUserId"))
|
|
|
+ .ge("t1", ApplyPurchase::getCreateTime, condition.get("startTime"))
|
|
|
+ .le("t1", ApplyPurchase::getCreateTime, condition.get("endTime"))
|
|
|
+ .and(Func.isNotEmpty(condition.get("keyword")), o -> o.apply("instr(t1.`code`, '" + condition.get("keyword") + "') > 0").or().apply("instr(t2.`code`, '" + condition.get("keyword") + "') > 0").or().apply("instr(t2.`name`, '" + condition.get("keyword") + "') > 0"))
|
|
|
+ .orderByDesc("t1", ApplyPurchase::getId);
|
|
|
+
|
|
|
+ Page<ApplyPurchase> page = baseMapper.getPage(createPage(condition), wrapper);
|
|
|
+ if (Func.isNotEmpty(page.getRecords())) {
|
|
|
+ //物品ID集合
|
|
|
+ List<Long> goodsIds = page.getRecords().stream().map(ApplyPurchase::getGoodsId).distinct().collect(Collectors.toList());
|
|
|
+ //结束时间
|
|
|
+ Date endTime = new Date();
|
|
|
+ //开始时间:往前推移30天
|
|
|
+ Date startTime = DateUtil.plusDays(endTime, -30l);
|
|
|
+ //物品出库信息map
|
|
|
+ Map<Long, BigDecimal> outStockMap = new HashMap<>();
|
|
|
+ //查询出库信息
|
|
|
+ List<StockJournal> stockJournals = stockJournalService.query()
|
|
|
+ .select("goods_id, SUM(change_quantity) change_quantity")
|
|
|
+ .eq("`type`", StockJournalTypeConstant.OUT)
|
|
|
+ .in("goods_id", goodsIds)
|
|
|
+ .apply("DATE_FORMAT(create_time, '%Y-%m-%d') >= '" + new SimpleDateFormat("yyyy-MM-dd").format(startTime) + "'")
|
|
|
+ .apply("DATE_FORMAT(create_time, '%Y-%m-%d') <= '" + new SimpleDateFormat("yyyy-MM-dd").format(endTime) + "'")
|
|
|
+ .groupBy("goods_id")
|
|
|
+ .list();
|
|
|
+ if (Func.isNotEmpty(stockJournals)) {
|
|
|
+ outStockMap = stockJournals.stream().collect(Collectors.toMap(StockJournal::getGoodsId, StockJournal::getChangeQuantity, (key1, key2) -> key2));
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户信息map
|
|
|
+ Map<Long, String> userNameMap = UserClientUtil.getUserNameMap(page.getRecords(), ApplyPurchase::getCreateUser);
|
|
|
+
|
|
|
+ for (ApplyPurchase record : page.getRecords()) {
|
|
|
+ if (Func.isNotEmpty(userNameMap) && Func.isNotEmpty(userNameMap.get(record.getCreateUser()))) {
|
|
|
+ record.setCreateName(userNameMap.get(record.getCreateUser()));
|
|
|
+ }
|
|
|
+ if (Func.isNotEmpty(outStockMap) && Func.isNotEmpty(outStockMap.get(record.getGoodsId()))) {
|
|
|
+ record.setOutStockQuantity(outStockMap.get(record.getGoodsId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return page;
|
|
|
+ }
|
|
|
}
|