|
@@ -5,10 +5,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.base.Condition;
|
|
|
import com.fjhx.entity.apply.ApplyPurchase;
|
|
|
import com.fjhx.entity.product.ProductInfo;
|
|
|
+import com.fjhx.entity.stock.Stock;
|
|
|
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.StockService;
|
|
|
import com.fjhx.uitl.code.CodeEnum;
|
|
|
import com.fjhx.utils.UserClientUtil;
|
|
|
import com.fjhx.utils.wrapperUtil.IWrapper;
|
|
@@ -19,6 +22,7 @@ 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.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -36,6 +40,12 @@ public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, A
|
|
|
@Autowired
|
|
|
private RedisLockClient redisLockClient;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private StockService stockService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductInfoService productInfoService;
|
|
|
+
|
|
|
private final String REDIS_LOCK_CACHE_KEY = "seq:lock:" + AuthUtil.getTenantId() + ":material:";
|
|
|
|
|
|
@Override
|
|
@@ -43,7 +53,16 @@ public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, A
|
|
|
|
|
|
IWrapper<ApplyPurchase> wrapper = IWrapper.getWrapper(condition);
|
|
|
|
|
|
- wrapper.eq("t1", ApplyPurchase::getReceiptWarehouseId, condition.get("warehouseId")).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::getCreateTime);
|
|
|
+ wrapper.eq("t1", ApplyPurchase::getReceiptWarehouseId, condition.get("warehouseId"))
|
|
|
+ .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())) {
|
|
@@ -67,7 +86,10 @@ public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, A
|
|
|
if (!checkCodeIsExist(null, code)) {
|
|
|
throw new ServiceException("后台自增编码存在重复,请重试或联系管理员!编码:" + code);
|
|
|
}
|
|
|
- list.forEach(item -> item.setCode(code));
|
|
|
+ list.forEach(item -> {
|
|
|
+ item.setCode(code);
|
|
|
+ item.setStatus(ApplyPurchaseStatusEnum.STATUS_10.getKey());
|
|
|
+ });
|
|
|
saveBatch(list);
|
|
|
return true;
|
|
|
})) {
|
|
@@ -97,16 +119,16 @@ public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, A
|
|
|
public Page<Map<String, Object>> applyInPage(Condition condition) {
|
|
|
IWrapper<Object> wrapper = IWrapper.getWrapper(condition);
|
|
|
wrapper.func(q -> {
|
|
|
- Integer status = condition.getStatus();
|
|
|
- if (status == null) {
|
|
|
- q.in("ap", ApplyPurchase::getStatus,
|
|
|
- ApplyPurchaseStatusEnum.STATUS_30.getKey(),
|
|
|
- ApplyPurchaseStatusEnum.STATUS_40.getKey(),
|
|
|
- ApplyPurchaseStatusEnum.STATUS_50.getKey());
|
|
|
- } else {
|
|
|
- q.eq("ap", ApplyPurchase::getStatus);
|
|
|
- }
|
|
|
- })
|
|
|
+ Integer status = condition.getStatus();
|
|
|
+ if (status == null) {
|
|
|
+ q.in("ap", ApplyPurchase::getStatus,
|
|
|
+ ApplyPurchaseStatusEnum.STATUS_30.getKey(),
|
|
|
+ ApplyPurchaseStatusEnum.STATUS_40.getKey(),
|
|
|
+ ApplyPurchaseStatusEnum.STATUS_50.getKey());
|
|
|
+ } else {
|
|
|
+ q.eq("ap", ApplyPurchase::getStatus);
|
|
|
+ }
|
|
|
+ })
|
|
|
.eq("ap", ApplyPurchase::getReceiptWarehouseId, condition.getLong("warehouseId"))
|
|
|
.like("ap", ApplyPurchase::getCode)
|
|
|
.like("pi", ProductInfo::getName, condition.getStr("productName"))
|
|
@@ -118,4 +140,25 @@ public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, A
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ApplyPurchase getById(Serializable id) {
|
|
|
+ ApplyPurchase purchase = super.getById(id);
|
|
|
+ if (Func.isNotEmpty(purchase)) {
|
|
|
+
|
|
|
+ ProductInfo info = productInfoService.getById(purchase.getGoodsId());
|
|
|
+ if (Func.isNotEmpty(info)) {
|
|
|
+ purchase.setGoodsCode(info.getCode());
|
|
|
+ purchase.setGoodsName(info.getName());
|
|
|
+ purchase.setGoodsType(info.getType());
|
|
|
+ purchase.setGoodsUnit(info.getUnit());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Stock stock = stockService.lambdaQuery().eq(Stock::getWarehouseId, purchase.getReceiptWarehouseId()).eq(Stock::getGoodsId, purchase.getGoodsId()).one();
|
|
|
+ if (Func.isNotEmpty(stock)) {
|
|
|
+ purchase.setStockQuantity(stock.getQuantity());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return purchase;
|
|
|
+ }
|
|
|
}
|