|
@@ -1,14 +1,20 @@
|
|
|
package com.fjhx.purchase.service.purchase.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.alibaba.fastjson2.JSONWriter;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.common.utils.Assert;
|
|
|
+import com.fjhx.file.utils.ObsFileUtil;
|
|
|
import com.fjhx.purchase.entity.purchase.dto.PurchasePayRecordDto;
|
|
|
+import com.fjhx.purchase.entity.purchase.dto.PurchasePayRecordSelectDto;
|
|
|
import com.fjhx.purchase.entity.purchase.po.Purchase;
|
|
|
import com.fjhx.purchase.entity.purchase.po.PurchasePayRecord;
|
|
|
import com.fjhx.purchase.entity.purchase.po.PurchasePayRecordDetail;
|
|
|
+import com.fjhx.purchase.entity.purchase.vo.PurchasePayRecordDetailVo;
|
|
|
+import com.fjhx.purchase.entity.purchase.vo.PurchasePayRecordVo;
|
|
|
import com.fjhx.purchase.mapper.purchase.PurchasePayRecordMapper;
|
|
|
import com.fjhx.purchase.service.purchase.PurchasePayRecordDetailService;
|
|
|
import com.fjhx.purchase.service.purchase.PurchasePayRecordService;
|
|
@@ -16,7 +22,6 @@ import com.fjhx.purchase.service.purchase.PurchaseService;
|
|
|
import com.obs.services.internal.ServiceException;
|
|
|
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.List;
|
|
@@ -41,10 +46,11 @@ public class PurchasePayRecordServiceImpl extends ServiceImpl<PurchasePayRecordM
|
|
|
private PurchasePayRecordDetailService purchasePayRecordDetailService;
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
+ @DSTransactional
|
|
|
public void add(PurchasePayRecordDto purchasePayRecordDto) {
|
|
|
//保存付款记录
|
|
|
this.save(purchasePayRecordDto);
|
|
|
+ ObsFileUtil.saveFile(purchasePayRecordDto.getFileList(), purchasePayRecordDto.getId());
|
|
|
|
|
|
//创建付款记录
|
|
|
List<PurchasePayRecordDetail> purchasePayRecordList = purchasePayRecordDto.getPurchasePayRecordDetailList();
|
|
@@ -63,7 +69,7 @@ public class PurchasePayRecordServiceImpl extends ServiceImpl<PurchasePayRecordM
|
|
|
List<PurchasePayRecordDetail> oldPurchasePayRecords = PayRecordMap.get(payRecord.getPurchaseId());
|
|
|
//求和已付款
|
|
|
BigDecimal paidAmount = BigDecimal.ZERO;
|
|
|
- if(ObjectUtil.isNotEmpty(oldPurchasePayRecords)){
|
|
|
+ if (ObjectUtil.isNotEmpty(oldPurchasePayRecords)) {
|
|
|
paidAmount = oldPurchasePayRecords.stream().map(PurchasePayRecordDetail::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
}
|
|
|
BigDecimal add = paidAmount.add(payRecord.getAmount());
|
|
@@ -83,7 +89,7 @@ public class PurchasePayRecordServiceImpl extends ServiceImpl<PurchasePayRecordM
|
|
|
String victoriatouristJson = purchase.getVictoriatouristJson();
|
|
|
JSONObject json = ObjectUtil.isEmpty(victoriatouristJson) ? new JSONObject() : JSONObject.parseObject(victoriatouristJson);
|
|
|
json.put("paidAmount", add);
|
|
|
- purchase.setVictoriatouristJson(JSONObject.toJSONString(json,JSONWriter.Feature.WriteLongAsString));
|
|
|
+ purchase.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
|
|
|
|
|
|
purchaseService.updateById(purchase);
|
|
|
|
|
@@ -94,4 +100,31 @@ public class PurchasePayRecordServiceImpl extends ServiceImpl<PurchasePayRecordM
|
|
|
purchasePayRecordDetailService.saveBatch(purchasePayRecordList);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PurchasePayRecordVo detail(PurchasePayRecordSelectDto dto) {
|
|
|
+ Assert.notEmpty(dto.getId(), "采购付款记录id不能为空");
|
|
|
+ PurchasePayRecord purchasePayRecord = this.getById(dto.getId());
|
|
|
+ PurchasePayRecordVo result = BeanUtil.toBean(purchasePayRecord, PurchasePayRecordVo.class);
|
|
|
+ Assert.notEmpty(result,"查询不到采购付款信息");
|
|
|
+ //赋值付款记录明细
|
|
|
+ List<PurchasePayRecordDetail> list = purchasePayRecordDetailService.list(q -> q.eq(PurchasePayRecordDetail::getPurchasePayRecordId, result.getId()));
|
|
|
+ List<PurchasePayRecordDetailVo> purchasePayRecordDetailVos = BeanUtil.copyToList(list, PurchasePayRecordDetailVo.class);
|
|
|
+ for (PurchasePayRecordDetailVo purchasePayRecordDetailVo : purchasePayRecordDetailVos) {
|
|
|
+ Purchase purchase = purchaseService.getById(purchasePayRecordDetailVo.getPurchaseId());
|
|
|
+ String victoriatouristJsonStr = purchase.getVictoriatouristJson();
|
|
|
+ if (ObjectUtil.isNotEmpty(victoriatouristJsonStr)) {
|
|
|
+ JSONObject victoriatouristJson = JSONObject.parseObject(victoriatouristJsonStr);
|
|
|
+ purchasePayRecordDetailVo.setContractCode(victoriatouristJson.getString("contractCode"));
|
|
|
+ purchasePayRecordDetailVo.setIsAgreement(victoriatouristJson.getInteger("isAgreement"));
|
|
|
+ purchasePayRecordDetailVo.setPaymentMethod(victoriatouristJson.getString("paymentMethod"));
|
|
|
+ purchasePayRecordDetailVo.setPurchaseContent(purchase.getPurchaseContent());
|
|
|
+ purchasePayRecordDetailVo.setPurchaseAmount(purchase.getAmount());
|
|
|
+ purchasePayRecordDetailVo.setPaidAmount(victoriatouristJson.getBigDecimal("paidAmount"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ result.setPurchasePayRecordDetailList(purchasePayRecordDetailVos);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
}
|