|
@@ -7,6 +7,7 @@ import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -16,6 +17,7 @@ import com.fjhx.common.entity.documentary.bo.DocumentaryData;
|
|
|
import com.fjhx.common.enums.CodingRuleEnum;
|
|
|
import com.fjhx.common.service.coding.CodingRuleService;
|
|
|
import com.fjhx.common.service.documentary.GetDocumentaryBusinessTemplate;
|
|
|
+import com.fjhx.common.utils.Assert;
|
|
|
import com.fjhx.customer.service.customer.CustomerService;
|
|
|
import com.fjhx.item.entity.product.vo.ProductInfoVo;
|
|
|
import com.fjhx.item.service.product.ProductInfoService;
|
|
@@ -23,11 +25,13 @@ import com.fjhx.purchase.entity.invoice.vo.InvoiceDetailsVo;
|
|
|
import com.fjhx.purchase.entity.pay.vo.PayDetailVo;
|
|
|
import com.fjhx.purchase.entity.purchase.bo.PurchaseDocumentaryBo;
|
|
|
import com.fjhx.purchase.entity.purchase.dto.PurchaseDto;
|
|
|
+import com.fjhx.purchase.entity.purchase.dto.PurchasePayRecordDto;
|
|
|
import com.fjhx.purchase.entity.purchase.dto.PurchaseSelectDto;
|
|
|
import com.fjhx.purchase.entity.purchase.enums.PurchaseStatusEnum;
|
|
|
import com.fjhx.purchase.entity.purchase.po.Purchase;
|
|
|
import com.fjhx.purchase.entity.purchase.po.PurchaseDetail;
|
|
|
import com.fjhx.purchase.entity.purchase.po.PurchasePayRecord;
|
|
|
+import com.fjhx.purchase.entity.purchase.po.PurchasePayRecordDetail;
|
|
|
import com.fjhx.purchase.entity.purchase.vo.PurchaseDocumentaryVo;
|
|
|
import com.fjhx.purchase.entity.purchase.vo.PurchaseVo;
|
|
|
import com.fjhx.purchase.entity.subscribe.po.Subscribe;
|
|
@@ -38,7 +42,7 @@ import com.fjhx.purchase.service.arrival.ArrivalService;
|
|
|
import com.fjhx.purchase.service.invoice.InvoiceDetailsService;
|
|
|
import com.fjhx.purchase.service.pay.PayDetailService;
|
|
|
import com.fjhx.purchase.service.purchase.PurchaseDetailService;
|
|
|
-import com.fjhx.purchase.service.purchase.PurchasePayRecordService;
|
|
|
+import com.fjhx.purchase.service.purchase.PurchasePayRecordDetailService;
|
|
|
import com.fjhx.purchase.service.purchase.PurchaseService;
|
|
|
import com.fjhx.purchase.service.subscribe.SubscribeDetailService;
|
|
|
import com.fjhx.purchase.service.subscribe.SubscribeService;
|
|
@@ -54,6 +58,7 @@ import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import org.apache.commons.collections4.MapUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
@@ -110,7 +115,7 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
|
|
|
@Autowired
|
|
|
private CodingRuleService codingRuleService;
|
|
|
@Autowired
|
|
|
- private PurchasePayRecordService purchasePayRecordService;
|
|
|
+ private PurchasePayRecordDetailService purchasePayRecordDetailService;
|
|
|
|
|
|
/**
|
|
|
* 列表
|
|
@@ -198,6 +203,10 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
|
|
|
|
|
|
Page<PurchaseVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
List<PurchaseVo> list = page.getRecords();
|
|
|
+ if (ObjectUtils.isEmpty(list)) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
|
List<Long> supplyIds = list.stream().map(PurchaseVo::getSupplyId).collect(Collectors.toList());
|
|
|
List<SupplierInfo> supplierInfoList = supplierInfoService.list(Wrappers.<SupplierInfo>query().lambda().in(SupplierInfo::getId, supplyIds));
|
|
@@ -257,6 +266,20 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
|
|
|
// }
|
|
|
// }
|
|
|
}
|
|
|
+ //赋值已付款金额
|
|
|
+ List<Long> purchaseIds = list.stream().map(PurchaseVo::getId).collect(Collectors.toList());
|
|
|
+ Map<Long, List<PurchasePayRecordDetail>> PayRecordMap = purchasePayRecordDetailService.mapKGroup(PurchasePayRecordDetail::getPurchaseId,
|
|
|
+ q -> q.in(PurchasePayRecordDetail::getPurchaseId, purchaseIds));
|
|
|
+ for (PurchaseVo purchaseVo : list) {
|
|
|
+ List<PurchasePayRecordDetail> purchasePayRecords = PayRecordMap.get(purchaseVo.getId());
|
|
|
+ if (ObjectUtils.isEmpty(purchasePayRecords)) {
|
|
|
+ purchaseVo.setPaidAmount(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ //求和已付款
|
|
|
+ BigDecimal paidAmount = purchasePayRecords.stream().map(PurchasePayRecordDetail::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ purchaseVo.setPaidAmount(paidAmount);
|
|
|
+ }
|
|
|
+
|
|
|
return page;
|
|
|
}
|
|
|
|
|
@@ -441,7 +464,8 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Page<? extends DocumentaryData> getDocumentaryPage(JSONObject selectData, BaseSelectDto dto, List<Long> excludeBusinessId) {
|
|
|
+ public Page<? extends DocumentaryData> getDocumentaryPage(JSONObject selectData, BaseSelectDto
|
|
|
+ dto, List<Long> excludeBusinessId) {
|
|
|
PurchaseDocumentaryBo bo = selectData.toJavaObject(PurchaseDocumentaryBo.class);
|
|
|
|
|
|
IWrapper<Purchase> wrapper = IWrapper.getWrapper();
|
|
@@ -471,18 +495,54 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
|
|
|
* 维多利亚 采购付款
|
|
|
*/
|
|
|
@Override
|
|
|
- public void payByWdly(PurchaseDto purchaseDto) {
|
|
|
- Purchase purchase = getById(purchaseDto.getId());
|
|
|
- String victoriatouristJson = purchase.getVictoriatouristJson();
|
|
|
- JSONObject json = ObjectUtil.isEmpty(victoriatouristJson) ? new JSONObject() : JSONObject.parseObject(victoriatouristJson);
|
|
|
- BigDecimal paidAmount = ObjectUtil.isEmpty(json.getBigDecimal("paidAmount")) ? BigDecimal.ZERO : json.getBigDecimal("paidAmount");
|
|
|
- //计算已付款金额
|
|
|
- BigDecimal add = paidAmount.add(purchaseDto.getPaidAmount());
|
|
|
- json.put("paidAmount", add);
|
|
|
- purchase.setVictoriatouristJson(json.toJSONString());
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void payByWdly(PurchasePayRecordDto purchaseDto) {
|
|
|
//创建付款记录
|
|
|
+ long payId = IdWorker.getId();
|
|
|
+ List<PurchasePayRecordDetail> purchasePayRecordList = purchaseDto.getPurchasePayRecordList();
|
|
|
+ Assert.notEmpty(purchasePayRecordList, "付款列表为空");
|
|
|
+ List<Long> purchaseIds = purchasePayRecordList.stream().map(PurchasePayRecordDetail::getPurchaseId).collect(Collectors.toList());
|
|
|
+ ;
|
|
|
+
|
|
|
+ Map<Long, Purchase> purchaseMap = this.mapKEntity(Purchase::getId, q -> q.in(Purchase::getId, purchaseIds));
|
|
|
+ Map<Long, List<PurchasePayRecordDetail>> PayRecordMap = purchasePayRecordDetailService.mapKGroup(PurchasePayRecordDetail::getPurchaseId,
|
|
|
+ q -> q.in(PurchasePayRecordDetail::getPurchaseId, purchaseIds));
|
|
|
+
|
|
|
PurchasePayRecord purchasePayRecord = new PurchasePayRecord();
|
|
|
- purchasePayRecord.setPurchaseId(purchase.getId());
|
|
|
- purchasePayRecord.setAmount(purchaseDto.getPaidAmount());
|
|
|
+
|
|
|
+
|
|
|
+ for (PurchasePayRecordDetail payRecord : purchasePayRecordList) {
|
|
|
+ //检查付款金额+已付款金额是否大于采购金额
|
|
|
+ Purchase purchase = purchaseMap.get(payRecord.getPurchaseId());
|
|
|
+ List<PurchasePayRecordDetail> oldPurchasePayRecords = PayRecordMap.get(payRecord.getPurchaseId());
|
|
|
+
|
|
|
+ //求和已付款
|
|
|
+ BigDecimal paidAmount = oldPurchasePayRecords.stream().map(PurchasePayRecordDetail::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal add = paidAmount.add(payRecord.getAmount());
|
|
|
+
|
|
|
+ if (purchase.getAmount().compareTo(add) < 0) {
|
|
|
+ throw new ServiceException("付款金额不能大于采购金额");
|
|
|
+ }
|
|
|
+ if (purchase.getAmount().compareTo(add) > 0) {
|
|
|
+ //部分付款
|
|
|
+ purchase.setPayStatus(10);
|
|
|
+ } else {
|
|
|
+ //完全付款
|
|
|
+ purchase.setPayStatus(20);
|
|
|
+ }
|
|
|
+
|
|
|
+ //赋值已付款金额
|
|
|
+ String victoriatouristJson = purchase.getVictoriatouristJson();
|
|
|
+ JSONObject json = ObjectUtil.isEmpty(victoriatouristJson) ? new JSONObject() : JSONObject.parseObject(victoriatouristJson);
|
|
|
+ json.put("paidAmount", add);
|
|
|
+ purchase.setVictoriatouristJson(json.toJSONString());
|
|
|
+
|
|
|
+ this.updateById(purchase);
|
|
|
+
|
|
|
+ //获取付款记录并赋值付款时间
|
|
|
+ payRecord.setPayDate(purchaseDto.getPayDate());
|
|
|
+ payRecord.setPurchasePayRecordId(payId);
|
|
|
+ }
|
|
|
+ purchasePayRecordDetailService.saveBatch(purchasePayRecordList);
|
|
|
}
|
|
|
}
|