|
@@ -4,7 +4,10 @@ import cn.hutool.core.bean.BeanUtil;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.ruoyi.common.constant.StatusConstant;
|
|
import com.ruoyi.common.constant.StatusConstant;
|
|
|
|
+import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
|
+import com.sd.business.entity.apply.po.ApplyBuyBom;
|
|
import com.sd.business.entity.purchase.dto.PurchaseDto;
|
|
import com.sd.business.entity.purchase.dto.PurchaseDto;
|
|
import com.sd.business.entity.purchase.dto.PurchaseSelectDto;
|
|
import com.sd.business.entity.purchase.dto.PurchaseSelectDto;
|
|
import com.sd.business.entity.purchase.po.Purchase;
|
|
import com.sd.business.entity.purchase.po.Purchase;
|
|
@@ -13,6 +16,7 @@ import com.sd.business.entity.purchase.vo.PurchaseBomVo;
|
|
import com.sd.business.entity.purchase.vo.PurchaseVo;
|
|
import com.sd.business.entity.purchase.vo.PurchaseVo;
|
|
import com.sd.business.entity.supplier.po.Supplier;
|
|
import com.sd.business.entity.supplier.po.Supplier;
|
|
import com.sd.business.mapper.purchase.PurchaseMapper;
|
|
import com.sd.business.mapper.purchase.PurchaseMapper;
|
|
|
|
+import com.sd.business.service.apply.ApplyBuyBomService;
|
|
import com.sd.business.service.bom.BomSpecService;
|
|
import com.sd.business.service.bom.BomSpecService;
|
|
import com.sd.business.service.purchase.PurchaseBomService;
|
|
import com.sd.business.service.purchase.PurchaseBomService;
|
|
import com.sd.business.service.purchase.PurchaseService;
|
|
import com.sd.business.service.purchase.PurchaseService;
|
|
@@ -22,6 +26,7 @@ import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -45,6 +50,9 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
@Autowired
|
|
@Autowired
|
|
private BomSpecService bomSpecService;
|
|
private BomSpecService bomSpecService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ApplyBuyBomService applyBuyBomService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Page<PurchaseVo> getPage(PurchaseSelectDto dto) {
|
|
public Page<PurchaseVo> getPage(PurchaseSelectDto dto) {
|
|
IWrapper<Purchase> wrapper = getWrapper();
|
|
IWrapper<Purchase> wrapper = getWrapper();
|
|
@@ -105,6 +113,8 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Override
|
|
@Override
|
|
public void add(PurchaseDto purchaseDto) {
|
|
public void add(PurchaseDto purchaseDto) {
|
|
|
|
+
|
|
|
|
+ // 保存采购合同
|
|
purchaseDto.setCode(CodeEnum.PURCHASE_CODE.getCode());
|
|
purchaseDto.setCode(CodeEnum.PURCHASE_CODE.getCode());
|
|
purchaseDto.setReturnAmount(BigDecimal.ZERO);
|
|
purchaseDto.setReturnAmount(BigDecimal.ZERO);
|
|
purchaseDto.setClosedAccountAmount(BigDecimal.ZERO);
|
|
purchaseDto.setClosedAccountAmount(BigDecimal.ZERO);
|
|
@@ -112,22 +122,83 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
purchaseDto.setPaymentStatus(StatusConstant.NO);
|
|
purchaseDto.setPaymentStatus(StatusConstant.NO);
|
|
this.save(purchaseDto);
|
|
this.save(purchaseDto);
|
|
|
|
|
|
|
|
+ // 保存采购明细
|
|
|
|
+ Map<Long, ApplyBuyBom> applyBuyBomMap = applyBuyBomService.mapKEntity(
|
|
|
|
+ BaseIdPo::getId,
|
|
|
|
+ q -> q.eq(ApplyBuyBom::getApplyBuyId, purchaseDto.getApplyBuyId()));
|
|
List<PurchaseBom> purchaseBomList = purchaseDto.getPurchaseBomList();
|
|
List<PurchaseBom> purchaseBomList = purchaseDto.getPurchaseBomList();
|
|
purchaseBomList.forEach(item -> {
|
|
purchaseBomList.forEach(item -> {
|
|
|
|
+ ApplyBuyBom applyBuyBom = applyBuyBomMap.get(item.getApplyBuyBomId());
|
|
|
|
+ if (applyBuyBom == null) {
|
|
|
|
+ throw new ServiceException("存在未知申购明细id");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BigDecimal quantity = applyBuyBom.getQuantity();
|
|
|
|
+ BigDecimal purchaseQuantity = applyBuyBom.getPurchaseQuantity();
|
|
|
|
+ BigDecimal frozenQuantity = applyBuyBom.getFrozenQuantity();
|
|
|
|
+ BigDecimal itemPurchaseQuantity = item.getPurchaseQuantity();
|
|
|
|
+
|
|
|
|
+ if (quantity.compareTo(purchaseQuantity.add(frozenQuantity).add(itemPurchaseQuantity)) >= 0) {
|
|
|
|
+ applyBuyBom.setFrozenQuantity(frozenQuantity.add(itemPurchaseQuantity));
|
|
|
|
+ } else {
|
|
|
|
+ throw new ServiceException("采购数量超过申购数量");
|
|
|
|
+ }
|
|
|
|
+
|
|
item.setPurchaseId(purchaseDto.getId());
|
|
item.setPurchaseId(purchaseDto.getId());
|
|
item.setReturnQuantity(BigDecimal.ZERO);
|
|
item.setReturnQuantity(BigDecimal.ZERO);
|
|
item.setPaidAmount(BigDecimal.ZERO);
|
|
item.setPaidAmount(BigDecimal.ZERO);
|
|
});
|
|
});
|
|
purchaseBomService.saveBatch(purchaseBomList);
|
|
purchaseBomService.saveBatch(purchaseBomList);
|
|
|
|
+
|
|
|
|
+ // 更新申购明细
|
|
|
|
+ ArrayList<ApplyBuyBom> applyBuyBomList = new ArrayList<>(applyBuyBomMap.values());
|
|
|
|
+ applyBuyBomService.updateBatchById(applyBuyBomList);
|
|
}
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Override
|
|
@Override
|
|
public void edit(PurchaseDto purchaseDto) {
|
|
public void edit(PurchaseDto purchaseDto) {
|
|
|
|
+
|
|
|
|
+ // 保存采购合同
|
|
this.updateById(purchaseDto);
|
|
this.updateById(purchaseDto);
|
|
|
|
|
|
|
|
+ Map<Long, ApplyBuyBom> applyBuyBomMap = applyBuyBomService.mapKEntity(
|
|
|
|
+ BaseIdPo::getId,
|
|
|
|
+ q -> q.eq(ApplyBuyBom::getApplyBuyId, purchaseDto.getApplyBuyId()));
|
|
|
|
+
|
|
|
|
+ Map<Long, PurchaseBom> purchaseBomMap = purchaseBomService.mapKEntity(
|
|
|
|
+ BaseIdPo::getId,
|
|
|
|
+ q -> q.eq(PurchaseBom::getPurchaseId, purchaseDto.getId()));
|
|
|
|
+
|
|
List<PurchaseBom> purchaseBomList = purchaseDto.getPurchaseBomList();
|
|
List<PurchaseBom> purchaseBomList = purchaseDto.getPurchaseBomList();
|
|
- purchaseBomList.forEach(item -> item.setPurchaseId(purchaseDto.getId()));
|
|
|
|
|
|
+ purchaseBomList.forEach(item -> {
|
|
|
|
+ item.setPurchaseId(purchaseDto.getId());
|
|
|
|
+
|
|
|
|
+ ApplyBuyBom applyBuyBom = applyBuyBomMap.get(item.getApplyBuyBomId());
|
|
|
|
+ if (applyBuyBom == null) {
|
|
|
|
+ throw new ServiceException("存在未知申购明细id");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BigDecimal quantity = applyBuyBom.getQuantity();
|
|
|
|
+ BigDecimal purchaseQuantity = applyBuyBom.getPurchaseQuantity();
|
|
|
|
+ BigDecimal frozenQuantity = applyBuyBom.getFrozenQuantity();
|
|
|
|
+ BigDecimal itemPurchaseQuantity = item.getPurchaseQuantity();
|
|
|
|
+
|
|
|
|
+ if (item.getId() != null) {
|
|
|
|
+ PurchaseBom purchaseBom = purchaseBomMap.get(item.getId());
|
|
|
|
+ if (purchaseBom == null) {
|
|
|
|
+ throw new ServiceException("存在未知采购明细id");
|
|
|
|
+ }
|
|
|
|
+ frozenQuantity = frozenQuantity.subtract(purchaseBom.getPurchaseQuantity());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (quantity.compareTo(purchaseQuantity.add(frozenQuantity).add(itemPurchaseQuantity)) >= 0) {
|
|
|
|
+ applyBuyBom.setFrozenQuantity(frozenQuantity.add(itemPurchaseQuantity));
|
|
|
|
+ } else {
|
|
|
|
+ throw new ServiceException("采购数量超过申购数量");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ });
|
|
purchaseBomService.editLinked(purchaseBomList, PurchaseBom::getPurchaseId, purchaseDto.getId());
|
|
purchaseBomService.editLinked(purchaseBomList, PurchaseBom::getPurchaseId, purchaseDto.getId());
|
|
}
|
|
}
|
|
|
|
|
|
@@ -135,6 +206,21 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
@Override
|
|
@Override
|
|
public void delete(Long id) {
|
|
public void delete(Long id) {
|
|
this.removeById(id);
|
|
this.removeById(id);
|
|
|
|
+
|
|
|
|
+ Map<Long, PurchaseBom> purchaseBomMap = purchaseBomService.mapKEntity(
|
|
|
|
+ PurchaseBom::getApplyBuyBomId,
|
|
|
|
+ q -> q.eq(PurchaseBom::getPurchaseId, id));
|
|
|
|
+
|
|
|
|
+ List<ApplyBuyBom> applyBuyBomList = applyBuyBomService.list(q -> q.eq(ApplyBuyBom::getApplyBuyId, id));
|
|
|
|
+ applyBuyBomList.forEach(item -> {
|
|
|
|
+ PurchaseBom purchaseBom = purchaseBomMap.get(item.getId());
|
|
|
|
+ if (purchaseBom == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ item.setFrozenQuantity(item.getFrozenQuantity().subtract(purchaseBom.getPurchaseQuantity()));
|
|
|
|
+ });
|
|
|
|
+ applyBuyBomService.updateBatchById(applyBuyBomList);
|
|
|
|
+
|
|
purchaseBomService.remove(q -> q.eq(PurchaseBom::getPurchaseId, id));
|
|
purchaseBomService.remove(q -> q.eq(PurchaseBom::getPurchaseId, id));
|
|
}
|
|
}
|
|
|
|
|