|
@@ -1,24 +1,18 @@
|
|
|
package org.springblade.manager.formula.impl;
|
|
|
|
|
|
-import com.alibaba.fastjson.annotation.JSONField;
|
|
|
import com.mixsmart.utils.FormulaUtils;
|
|
|
import com.mixsmart.utils.StringUtils;
|
|
|
-import io.swagger.models.auth.In;
|
|
|
import lombok.Data;
|
|
|
import lombok.EqualsAndHashCode;
|
|
|
+import org.springblade.common.utils.BaseUtils;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
-import org.springblade.core.tool.utils.ReflectUtil;
|
|
|
import org.springblade.core.tool.utils.StringPool;
|
|
|
import org.springblade.manager.dto.ElementData;
|
|
|
import org.springblade.manager.dto.FormData;
|
|
|
import org.springblade.manager.formula.FormulaExecutor;
|
|
|
-import org.springblade.manager.formula.NodeTable;
|
|
|
-import org.springblade.manager.vo.BaseInfo;
|
|
|
-import org.springblade.manager.vo.InterimPaymentCertificate;
|
|
|
-import org.springblade.manager.vo.Material;
|
|
|
-import org.springblade.manager.vo.MeterType;
|
|
|
+import org.springblade.manager.vo.*;
|
|
|
|
|
|
-import java.lang.reflect.Field;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -32,7 +26,10 @@ import java.util.stream.IntStream;
|
|
|
@EqualsAndHashCode(callSuper = true)
|
|
|
@Data
|
|
|
public class ExecutorSpecial extends FormulaExecutor {
|
|
|
- private Function<Long, List<Material>> materialListFc;
|
|
|
+ private Function<Long, List<Material>> materialFormFc;
|
|
|
+ private Function<Long, MeterPeriodInfo> interimMeterPeriodFc;
|
|
|
+ private Function<Long, List<Payment>> paymentListFc;
|
|
|
+ private Function<Long, List<InventoryForm>> inventoryFormFc;
|
|
|
public ExecutorSpecial(TableElementConverter tec) {
|
|
|
super(tec);
|
|
|
}
|
|
@@ -145,7 +142,7 @@ public class ExecutorSpecial extends FormulaExecutor {
|
|
|
/*加载合同材料、材料清单*/
|
|
|
/* b.material_name name,b.unit,b.price,a.meter_amount amount,a.material_source source
|
|
|
,material_conform materialConform,a.storage_place storagePlace,a.storage_status storageStatus,a.storage_conform storageConform,a.remark*/
|
|
|
- List<Material> materials = materialListFc.apply(tec.getPeriodId());
|
|
|
+ List<Material> materials = materialFormFc.apply(tec.getPeriodId());
|
|
|
if(Func.isNotEmpty(materials)){
|
|
|
BaseInfo baseInfo= (BaseInfo) tec.getConstantMap().get(BaseInfo.TBN);
|
|
|
int n=1;
|
|
@@ -190,6 +187,7 @@ public class ExecutorSpecial extends FormulaExecutor {
|
|
|
|
|
|
@Data
|
|
|
public class InterimPayCert implements Special{
|
|
|
+ private List<InventoryForm> chapters = new ArrayList<>();
|
|
|
|
|
|
@Override
|
|
|
public boolean ready() {
|
|
@@ -197,27 +195,100 @@ public class ExecutorSpecial extends FormulaExecutor {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+ private Function<List<InventoryForm>, Map<String, BigDecimal[]>> contractMoneySum = data -> data.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ form -> getPrefix(form.getFormNumber()),
|
|
|
+ Collectors.reducing(
|
|
|
+ new BigDecimal[]{BigDecimal.ZERO, BigDecimal.ZERO},
|
|
|
+ form -> new BigDecimal[]{
|
|
|
+ form.getContractMoney() != null ? new BigDecimal(form.getContractMoney()) : BigDecimal.ZERO,
|
|
|
+ form.getChangeMoney() != null ? new BigDecimal(form.getChangeMoney()) : BigDecimal.ZERO
|
|
|
+ },
|
|
|
+ (total1, total2) -> new BigDecimal[]{total1[0].add(total2[0]), total1[1].add(total2[1])}
|
|
|
+ )
|
|
|
+ ));
|
|
|
+
|
|
|
+ private Function<List<Payment>, Map<String, BigDecimal>> moneySum= data-> data.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ payment -> getPrefix(payment.getNumber()),
|
|
|
+ LinkedHashMap::new,
|
|
|
+ Collectors.reducing(BigDecimal.ZERO, Payment::getMoneyAsBigDecimal, BigDecimal::add)
|
|
|
+ ));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public String getPrefix(String fn){
|
|
|
+ for(InventoryForm itf:this.chapters){
|
|
|
+ String prefix=itf.getChapter();
|
|
|
+ if(fn.startsWith(prefix)){
|
|
|
+ return prefix;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return fn;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void parse() {
|
|
|
LinkedHashMap<String,FormData> fdm = FormulaUtils.toFormDataMap(new InterimPaymentCertificate());
|
|
|
- Map<String,Function<InterimPaymentCertificate,Object>> functionMap = FormulaUtils.functionMapBuilder(InterimPaymentCertificate.class);
|
|
|
tec.getFormDataMap().putAll(fdm);
|
|
|
+
|
|
|
+ Map<String,Function<List<InterimPaymentCertificate>,List<Object>>> functionMap =FormulaUtils.fieldDataFcMap(InterimPaymentCertificate.class);
|
|
|
+
|
|
|
List<InterimPaymentCertificate> dataList = new ArrayList<>();
|
|
|
/*数据获取start*/
|
|
|
- dataList.add(new InterimPaymentCertificate()) ;//测试,按照业务写,实际会复杂许多
|
|
|
- //TODO
|
|
|
- /*数据获取end*/
|
|
|
- fdm.values().forEach(fd->{
|
|
|
- List<Object> raw = dataList.stream().map(functionMap.get(fd.getCode())).filter(Func::isNotEmpty).collect(Collectors.toList());
|
|
|
- if(raw.size()>0){
|
|
|
- List<ElementData> eds = fd.getValues();
|
|
|
- for(Object value:raw){
|
|
|
- eds.add(new ElementData(value));
|
|
|
- }
|
|
|
+ /*支付数据*/
|
|
|
+ List<Payment> paymentList=paymentListFc.apply(tec.getContractId());
|
|
|
+ /*计量期*/
|
|
|
+ MeterPeriodInfo periodInfo=interimMeterPeriodFc.apply(tec.getPeriodId());
|
|
|
+ /*合同计量清单*/
|
|
|
+ List<InventoryForm> inventoryForms = inventoryFormFc.apply(tec.getContractId());
|
|
|
+ InventoryForm root = null;
|
|
|
+ for(InventoryForm itf:inventoryForms){
|
|
|
+ if(itf.getParentId()==0){
|
|
|
+ root = itf;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(InventoryForm itf:inventoryForms){
|
|
|
+ assert root != null;
|
|
|
+ if(itf.getParentId().equals(root.getParentId())){
|
|
|
+ chapters.add(itf);
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
+
|
|
|
+ if(Func.isNotEmpty(paymentList)){
|
|
|
+ /*之前的计量期数据*/
|
|
|
+ List<Payment>previous = paymentList.stream().filter(e->e.getSort()<periodInfo.getSort()).collect(Collectors.toList());
|
|
|
+ /*当前计量期数据*/
|
|
|
+ List<Payment>current = paymentList.stream().filter(e-> e.getSort().equals(periodInfo.getSort())).collect(Collectors.toList());
|
|
|
+ /*往期每章节的实际花费*/
|
|
|
+ Map<String,BigDecimal> previousMoney= this.moneySum.apply(previous);
|
|
|
+ /*当前计量期每章节的实际花费*/
|
|
|
+ Map<String,BigDecimal> currentMoney= this.moneySum.apply(current);
|
|
|
+ /*合同金额*/
|
|
|
+ Map<String,BigDecimal[]> contractMoney = this.contractMoneySum.apply(inventoryForms);
|
|
|
+ for(Map.Entry<String,BigDecimal[]> cm:contractMoney.entrySet()){
|
|
|
+ InterimPaymentCertificate ipc = new InterimPaymentCertificate();
|
|
|
+ BigDecimal[] bmMoney =cm.getValue();
|
|
|
+ ipc.setContractAmount(bmMoney[0].toString());
|
|
|
+ ipc.setRevisedAmount(bmMoney[1].toString());
|
|
|
+ ipc.setPreviousPeriodEndPay(previousMoney.getOrDefault(cm.getKey(),BigDecimal.ZERO).toString());
|
|
|
+ ipc.setCurrentPeriodPay(currentMoney.getOrDefault(cm.getKey(),BigDecimal.ZERO).toString());
|
|
|
+ /*由已知求未知*/
|
|
|
+ ipc.calculate();
|
|
|
+ dataList.add(ipc);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /*数据获取end*/
|
|
|
+ /*本期实际支付合计计算*/
|
|
|
+ functionMap.put(InterimPaymentCertificate.TBN+ StringPool.COLON+"key_9",(List<InterimPaymentCertificate> list)-> Collections.singletonList(list.stream().map(InterimPaymentCertificate::getCurrentPeriodPay).mapToDouble(Double::parseDouble).sum()));
|
|
|
+ /*内容输出*/
|
|
|
+ FormulaUtils.put2FormData(fdm,functionMap,dataList);
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|