dobe_comic8/main/java/shkd/repc/recon/opplugin/IntroduceContractPlugin.java

58 lines
2.4 KiB
Java
Raw Normal View History

package shkd.repc.recon.opplugin;
import com.alibaba.fastjson.JSONObject;
import kd.bos.entity.api.ApiResult;
import kd.bos.entity.plugin.ImportLogger;
import kd.bos.form.plugin.impt.BatchImportPlugin;
import kd.bos.form.plugin.impt.ImportBillData;
import kd.bos.util.StringUtils;
import java.math.BigDecimal;
import java.util.Iterator;
import java.util.List;
/**
* 合同清单导入功能(校验)
*/
public class IntroduceContractPlugin extends BatchImportPlugin {
@Override
protected ApiResult save(List<ImportBillData> rowdatas, ImportLogger logger) {
Iterator<ImportBillData> iterator = rowdatas.iterator();
while (iterator.hasNext()){
ImportBillData importBillData = iterator.next();
JSONObject data = importBillData.getData();
String qeug_bcdecimalqty = (String) data.get("qeug_bcdecimalqty");//本次完工量
String qeug_decimalqty = (String) data.get("qeug_decimalqty");//工程量
String qeug_preofpro = (String) data.get("qeug_preofpro");//进度百分比
double bcdecimalqty = 0;
double decimalqty =0;
double preofpro =0;
if (qeug_decimalqty != null && qeug_preofpro!= null) {
//校验 工程量&进度百分比 数据格式是否正确
try {
decimalqty = Double.parseDouble(qeug_decimalqty);
preofpro = Double.parseDouble(qeug_preofpro);
} catch (NumberFormatException e) {
logger.log(importBillData.getStartIndex(),"工程量数据格式有误").fail();
iterator.remove();
}
// 本次完工量 = 工程量 * 进度百分比
BigDecimal bd1 = new BigDecimal(qeug_decimalqty);
BigDecimal bd2 = new BigDecimal(qeug_preofpro);
BigDecimal result = bd1.multiply(bd2);
result = result.setScale(2, BigDecimal.ROUND_HALF_UP);
data.put("qeug_bcdecimalqty",result);
if (StringUtils.isNotEmpty(qeug_preofpro)) {
preofpro = Double.parseDouble(qeug_preofpro);
}
if (preofpro>1){
logger.log(importBillData.getStartIndex(),"进度百分比不能大于1").fail();
iterator.remove();
}
}
}
return super.save(rowdatas, logger);
}
}