代码提交

提交人:陈绍鑫
时间:2024/11/06
内容:成本测算解析附件数据插件以及实体类,潜在供应商资质预审操作前校验
This commit is contained in:
陈绍鑫 2024-11-06 17:39:26 +08:00
parent d6556b8120
commit fc277af345
4 changed files with 275 additions and 8 deletions

View File

@ -193,7 +193,6 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadList
Map<String, BigDecimal> amounttotalMap = new HashMap<>(); Map<String, BigDecimal> amounttotalMap = new HashMap<>();
for (Sheet sheet : workbook) { for (Sheet sheet : workbook) {
int rowNum = 0; int rowNum = 0;
int a=0;
// 获取总行数 // 获取总行数
int rowCountsheet = sheet.getPhysicalNumberOfRows();//总行数 int rowCountsheet = sheet.getPhysicalNumberOfRows();//总行数
for (Row cells : sheet) { for (Row cells : sheet) {

View File

@ -0,0 +1,73 @@
package shkd.repc.recos.domain;
/*
* 成本测算附件信息对象
* */
public class Calculation {
//科目长编码
String entry_longnumber;
//科目名称
String entry_accountname;
//单位
String entry_workloadunit;
//调整系数
Double entry_adjustcoefficient;
//合价含税
Double entry_amount;
public Calculation(String entry_longnumber, String entry_accountname, String entry_workloadunit, Double entry_adjustcoefficient, Double entry_amount) {
this.entry_longnumber = entry_longnumber;
this.entry_accountname = entry_accountname;
this.entry_workloadunit = entry_workloadunit;
this.entry_adjustcoefficient = entry_adjustcoefficient;
this.entry_amount = entry_amount;
}
public String getEntry_longnumber() {
return entry_longnumber;
}
public void setEntry_longnumber(String entry_longnumber) {
this.entry_longnumber = entry_longnumber;
}
public String getEntry_accountname() {
return entry_accountname;
}
public void setEntry_accountname(String entry_accountname) {
this.entry_accountname = entry_accountname;
}
public String getEntry_workloadunit() {
return entry_workloadunit;
}
public void setEntry_workloadunit(String entry_workloadunit) {
this.entry_workloadunit = entry_workloadunit;
}
public Double getEntry_adjustcoefficient() {
return entry_adjustcoefficient;
}
public void setEntry_adjustcoefficient(Double entry_adjustcoefficient) {
this.entry_adjustcoefficient = entry_adjustcoefficient;
}
public Double getEntry_amount() {
return entry_amount;
}
public void setEntry_amount(Double entry_amount) {
this.entry_amount = entry_amount;
}
public Calculation() {
}
}

View File

@ -0,0 +1,142 @@
package shkd.repc.recos.formplugin;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.form.control.AttachmentPanel;
import kd.bos.form.control.events.UploadListener;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.operate.FormOperate;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.AttachmentDto;
import kd.bos.servicehelper.AttachmentServiceHelper;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import org.apache.poi.ss.usermodel.*;
import shkd.repc.recos.domain.Calculation;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.EventObject;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
public class RecosMeasurecosFormPlugin extends AbstractFormPlugin implements UploadListener {
private static boolean attPk = true;
@Override
public void registerListener(EventObject e) {
super.registerListener(e);
//注册附件监听
AttachmentPanel attachmentPanel = getControl("attachmentpanelap");
attachmentPanel.addUploadListener(this);
}
@Override
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
super.beforeDoOperation(args);
FormOperate source = (FormOperate) args.getSource();
String operateKey = source.getOperateKey();
switch (operateKey){
case "qeug_test":
Long id = (Long) this.getModel().getValue("id");//获取单据id
//遍历附件前校验
AttachmentPanel att = this.getView().getControl("attachmentpanelap");
if (att.getAttachmentData().size()==0){
this.getView().showMessage("请上传附件");
return;
}
Object attPkId = att.getAttachmentData().get(0).get("attPkId");
if (null == attPkId) {
attPk = false;
this.getView().invokeOperation("save");//调用保存
}
AttachmentPanel attachmentpanelap = this.getView().getControl("attachmentpanelap");
List<Map<String, Object>> attachments = attachmentpanelap.getAttachmentData();
for (Map<String, Object> attachment : attachments) {
AttachmentDto attachmentDto = AttachmentServiceHelper.getAttachmentInfoByAttPk(attachment.get("attPkId"));
String fileUrl = attachmentDto.getResourcePath();//真实路径
try {
FileInputStream in = new FileInputStream(fileUrl);
Workbook workbook = WorkbookFactory.create(in);
for (Sheet sheet : workbook) {
List<Calculation> arrayList = new ArrayList<>();//修改的集合
String sheetName = sheet.getSheetName();//获取excl标签名称
int rowNum = 0;
int rowCountsheet = sheet.getPhysicalNumberOfRows();//总行数
for (Row cells : sheet) {
String billno = cells.getCell(0).toString();
//第一列属于数字
Pattern pattern = Pattern.compile("^-?\\d+(\\.\\d+)?$");
boolean matches = pattern.matcher(billno).matches();
if (matches) {
rowNum = cells.getRowNum();//记录序号出现的下标
break;
}
}
for (int j = rowNum; j <= rowCountsheet - 2; j++){//序号行至最后一行总计前一行
Row row = sheet.getRow(j);
Calculation calculation = new Calculation(
row.getCell(5).toString(),//科目编码
row.getCell(6).toString(),//科目名称
row.getCell(9).getStringCellValue(),//单位
//Double.parseDouble(row.getCell(12).getStringCellValue().replace("%", ""))/100.0,
Double.parseDouble(row.getCell(12).toString()),// 调整系数
row.getCell(17).getNumericCellValue()//合价含税
);
arrayList.add(calculation);
}
String res = updateRecosMeasurecos(arrayList, sheetName);
if (!"success".equals(res)){
this.getView().showSuccessNotification("功能失败");
return;
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
@Override
public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
super.afterDoOperation(afterDoOperationEventArgs);
String operateKey = afterDoOperationEventArgs.getOperateKey();
if ("save".equals(operateKey)&&afterDoOperationEventArgs.getOperationResult().isSuccess()){
if (!attPk){//附件功能调用的保存取消提示
afterDoOperationEventArgs.getOperationResult().setShowMessage(false);
attPk = true;
}
}
}
/*
* 根据入参信息修改成本测算方法
* */
public String updateRecosMeasurecos(List<Calculation> arrayList,String sheetName) {
try {
//处理
System.out.println(arrayList);
System.out.println(sheetName);
// QFilter filter = new QFilter("measurecostid", QCP.equals, (Long) this.getModel().getValue("id"));
// DynamicObject[] DynamicObjects = BusinessDataServiceHelper.load("recos_measureci", "id,status,cientry", filter.toArray());
// Long fid = (Long) DynamicObjects[0].get("id");
// DynamicObject loadSingle = BusinessDataServiceHelper.loadSingle(fid,"recos_measureci");
// DynamicObjectCollection cientry = loadSingle.getDynamicObjectCollection("cientry");
// cientry.get(4).set("entry_amount",666);
// Object[] save = SaveServiceHelper.save(new DynamicObject[]{loadSingle});
// System.out.println(save);
return "success";
} catch (Exception e) {
return e.getMessage();
//throw new RuntimeException(e);
}
}
}

View File

@ -2,12 +2,16 @@ package shkd.repc.resm.formplugin;
import kd.bos.bill.BillShowParameter; import kd.bos.bill.BillShowParameter;
import kd.bos.bill.OperationStatus; import kd.bos.bill.OperationStatus;
import kd.bos.dataentity.OperateOption;
import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.resource.ResManager; import kd.bos.dataentity.resource.ResManager;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.entity.EntityMetadataCache; import kd.bos.entity.EntityMetadataCache;
import kd.bos.entity.datamodel.ListSelectedRowCollection; import kd.bos.entity.datamodel.ListSelectedRowCollection;
import kd.bos.entity.operate.result.OperationResult;
import kd.bos.form.ShowType; import kd.bos.form.ShowType;
import kd.bos.form.control.events.BeforeItemClickEvent;
import kd.bos.form.events.AfterDoOperationEventArgs; import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.events.BeforeDoOperationEventArgs; import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.operate.FormOperate; import kd.bos.form.operate.FormOperate;
@ -15,8 +19,11 @@ import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.orm.query.QFilter; import kd.bos.orm.query.QFilter;
import kd.bos.orm.util.CollectionUtils; import kd.bos.orm.util.CollectionUtils;
import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.OperationServiceHelper;
import kd.repc.common.enums.PersontypeEnum;
import kd.repc.common.enums.resm.RegSupplierStatusEnum; import kd.repc.common.enums.resm.RegSupplierStatusEnum;
import kd.repc.common.util.PermissionUtils; import kd.repc.common.util.PermissionUtils;
import kd.repc.common.util.resm.SupplierAptUtils;
import kd.repc.common.util.resm.SupplierStrategyUtil; import kd.repc.common.util.resm.SupplierStrategyUtil;
//import kd.repc.common.util.resm.SupplierStrategyUtil; //import kd.repc.common.util.resm.SupplierStrategyUtil;
//import kd.repc.common.util.MultiLangEnumBridge; //import kd.repc.common.util.MultiLangEnumBridge;
@ -27,6 +34,45 @@ import java.util.stream.Collectors;
public class TycQzSupplierFormPlugin extends AbstractFormPlugin { public class TycQzSupplierFormPlugin extends AbstractFormPlugin {
private static final String KEY_BUT_MENU = "tbmain";
@Override
public void registerListener(EventObject e) {
super.registerListener(e);
this.addItemClickListeners(KEY_BUT_MENU);
}
public void beforeItemClick(BeforeItemClickEvent evt) {
if (evt.getItemKey().equals("qeug_preaudit")) {
DynamicObject regSupplier = BusinessDataServiceHelper.loadSingle(this.getModel().getDataEntity().getPkValue(), "resm_regsupplier");
String socode = regSupplier.getString("societycreditcode");
String personType = regSupplier.getString("persontype");
if (!PersontypeEnum.PERSONAL.getVal().equals(personType) && StringUtils.isEmpty(socode)) {
this.getView().showMessage(ResManager.loadKDString("社会统一信用代码不能为空。", "ImportRegSupplierList_2", "repc-resm-formplugin", new Object[0]));
evt.setCancel(true);
return;
}
OperationResult result = OperationServiceHelper.executeOperate("save", "resm_regsupplier", new DynamicObject[]{regSupplier}, OperateOption.create());
if (!result.isSuccess()) {
evt.setCancel(true);
StringJoiner joiner = new StringJoiner("\n");
result.getAllErrorOrValidateInfo().forEach((info) -> {
joiner.add(info.getMessage());
});
this.getView().showMessage(joiner.toString());
return;
}
boolean isSuccess = SupplierAptUtils.checkAptitudeFile(this.getView(), regSupplier);
if (!isSuccess) {
evt.setCancel(true);
return;
}
}
}
@Override @Override
public void beforeDoOperation(BeforeDoOperationEventArgs args) { public void beforeDoOperation(BeforeDoOperationEventArgs args) {
super.beforeDoOperation(args); super.beforeDoOperation(args);
@ -40,12 +86,14 @@ public class TycQzSupplierFormPlugin extends AbstractFormPlugin {
} }
} }
protected boolean checkIsCanDo(BeforeDoOperationEventArgs args) { protected boolean checkIsCanDo(BeforeDoOperationEventArgs args) {
if (!SupplierStrategyUtil.isPreTrial()) { if (!SupplierStrategyUtil.isPreTrial()) {
return true; return true;
} else { } else {
ListSelectedRowCollection listSelectedData = args.getListSelectedData(); DynamicObject dataEntity = this.getModel().getDataEntity(true);
QFilter qFilter = new QFilter("id", "in", listSelectedData.getPrimaryKeyValues()); QFilter qFilter = new QFilter("id", "in", dataEntity.getPkValue());
DynamicObject[] regSupplierArr = BusinessDataServiceHelper.load("resm_regsupplier", "status", qFilter.toArray()); DynamicObject[] regSupplierArr = BusinessDataServiceHelper.load("resm_regsupplier", "status", qFilter.toArray());
boolean isExist = Arrays.stream(regSupplierArr).anyMatch((item) -> { boolean isExist = Arrays.stream(regSupplierArr).anyMatch((item) -> {
return item.getString("status").equals(RegSupplierStatusEnum.SAVE.getValue()); return item.getString("status").equals(RegSupplierStatusEnum.SAVE.getValue());
@ -96,16 +144,22 @@ public class TycQzSupplierFormPlugin extends AbstractFormPlugin {
this.getView().showErrorNotification(ResManager.loadKDString("很抱歉!您没有[潜在供应商]的操作[资质预审]的功能权限,请联系管理员。", "RegSupplierList_21", "repc-resm-formplugin", new Object[0])); this.getView().showErrorNotification(ResManager.loadKDString("很抱歉!您没有[潜在供应商]的操作[资质预审]的功能权限,请联系管理员。", "RegSupplierList_21", "repc-resm-formplugin", new Object[0]));
args.setCancel(true); args.setCancel(true);
} else { } else {
DynamicObjectCollection dynamicObjects=new DynamicObjectCollection();
dynamicObjects.add(this.getModel().getDataEntity(true));
ListSelectedRowCollection listSelectedData = args.getListSelectedData(); ListSelectedRowCollection listSelectedData = args.getListSelectedData();
Set<Object> selectRowSet = (Set)listSelectedData.stream().map((item) -> { // Set<Object> selectRowSet = (Set)listSelectedData.stream().map((item) -> {
return item.getPrimaryKeyValue(); // return item.getPrimaryKeyValue();
// }).collect(Collectors.toSet());
Set<Object> selectRowSet = (Set)dynamicObjects.stream().map((item) -> {
return item.getPkValue();
}).collect(Collectors.toSet()); }).collect(Collectors.toSet());
List<String> groupId = new ArrayList(); List<String> groupId = new ArrayList();
if (selectRowSet.size() > 1) { if (selectRowSet.size() > 1) {
this.getView().showErrorNotification(ResManager.loadKDString("不允许对多条记录进行操作。", "RegSupplierList_18", "repc-resm-formplugin", new Object[0])); this.getView().showErrorNotification(ResManager.loadKDString("不允许对多条记录进行操作。", "RegSupplierList_18", "repc-resm-formplugin", new Object[0]));
args.setCancel(true); args.setCancel(true);
} else { } else {
DynamicObject[] regSuppliers = BusinessDataServiceHelper.load(listSelectedData.getPrimaryKeyValues(), EntityMetadataCache.getDataEntityType("resm_regsupplier")); //DynamicObject[] regSuppliers = BusinessDataServiceHelper.load(listSelectedData.getPrimaryKeyValues(), EntityMetadataCache.getDataEntityType("resm_regsupplier"));
DynamicObject[] regSuppliers = BusinessDataServiceHelper.load(new Object[]{dynamicObjects.get(0).getPkValue()}, EntityMetadataCache.getDataEntityType("resm_regsupplier"));
StringBuilder preQulicaStatus = new StringBuilder(); StringBuilder preQulicaStatus = new StringBuilder();
DynamicObject[] var8 = regSuppliers; DynamicObject[] var8 = regSuppliers;
int var9 = regSuppliers.length; int var9 = regSuppliers.length;
@ -200,8 +254,7 @@ public class TycQzSupplierFormPlugin extends AbstractFormPlugin {
} }
} }
// DynamicObject serviceOrg = regSuppliers[0].getDynamicObject("serviceorg"); DynamicObject serviceOrg = regSuppliers[0].getDynamicObject("serviceorg");
DynamicObject serviceOrg = this.getModel().getDataEntity().getDynamicObject("serviceorg");
BillShowParameter billShowParameter = new BillShowParameter(); BillShowParameter billShowParameter = new BillShowParameter();
billShowParameter.setFormId("resm_prequalification"); billShowParameter.setFormId("resm_prequalification");
// billShowParameter.setCustomParam("regSupplierId", listSelectedData.getPrimaryKeyValues()[0]); // billShowParameter.setCustomParam("regSupplierId", listSelectedData.getPrimaryKeyValues()[0]);