产值确认,定标修改,附件名字,待办OA,合同清单导入功能(校验)

This commit is contained in:
weiyunlong 2024-11-09 10:35:26 +08:00
parent d0dd9b3890
commit 4211d5a7ef
8 changed files with 747 additions and 68 deletions

View File

@ -0,0 +1,48 @@
package shkd.repc.rebm.formplugin;
import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.resource.ResManager;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.operate.FormOperate;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.lang.Lang;
import kd.scm.bid.business.helper.BidFileHelper;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 定标
* qeug_rebm_decision_ext
*/
public class CalibrationsFormPlugin extends AbstractFormPlugin {
@Override
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
super.beforeDoOperation(args);
// 获取当前时间
Date now = new Date();
// 定义时间格式
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 将当前时间按照指定格式转换为字符串
String currentTimeString = sdf.format(now);
Lang lang = RequestContext.get().getLang();
FormOperate operate = (FormOperate)args.getSource();
operate.getOption().setVariableValue("form", "edit");
String operateKey = operate.getOperateKey();
Object bidDecisionId = this.getModel().getDataEntity().getPkValue();
DynamicObject bidDecision;
if ("alldownfiles".equals(operateKey)) {
DynamicObject dataEntity = this.getModel().getDataEntity(true);
String serviceAppId = this.getView().getFormShowParameter().getServiceAppId();
bidDecision = dataEntity.getDynamicObject("bidproject");
String billno = bidDecision.getString("billno");
String fileName = String.format(ResManager.loadKDString("%s定标附件"+"_"+currentTimeString, "BidDecisionEditUI_54", "scm-bid-formplugin", new Object[0]), billno);
String docType = bidDecision.getString("doctype");
this.getView().download(BidFileHelper.downAllFile(fileName, dataEntity.getPkValue(), serviceAppId + "_decision", serviceAppId, docType));
}
}
}

View File

@ -191,12 +191,11 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
}
}
//删除单据体数据
qeug_invoiceentryinfos.clear();
SaveServiceHelper.save(new DynamicObject[]{this.getModel().getDataEntity(true)});
SaveServiceHelper.save(new DynamicObject[]{this.getModel().getDataEntity()});
// 删除完成之后刷新界面
getView().invokeOperation("refresh");
this.getView().invokeOperation("refresh");
return result;
}
@Override

View File

@ -1,15 +1,17 @@
package shkd.repc.recon.formplugin;
import com.google.common.collect.Lists;
import kd.bos.bill.OperationStatus;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.form.IFormView;
import kd.bos.form.ShowFormHelper;
import kd.bos.form.ShowType;
import kd.bos.form.StyleCss;
import kd.bos.form.*;
import kd.bos.form.container.Tab;
import kd.bos.form.control.events.TabSelectEvent;
import kd.bos.form.control.events.TabSelectListener;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.events.PreOpenFormEventArgs;
import kd.bos.form.operate.FormOperate;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.list.ListFilterParameter;
@ -17,15 +19,23 @@ import kd.bos.list.ListShowParameter;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.scm.pds.common.util.OpenFormUtils;
import org.apache.cxf.Bus;
import java.math.BigDecimal;
import java.util.EventObject;
import java.util.List;
import java.util.Map;
/**
* 产值确认表单插件
* qeug_recon_workloadcf_ext
*/
public class WorkloadcfmbillFormPlugin extends AbstractFormPlugin {
public class WorkloadcfmbillFormPlugin extends AbstractFormPlugin implements TabSelectListener {
@Override
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
@ -42,7 +52,7 @@ public class WorkloadcfmbillFormPlugin extends AbstractFormPlugin {
this.getView().showTipNotification("新增行无法查看明细");
return;
}
DynamicObject cqcontract = (DynamicObject) this.getModel().getValue("qeug_contractbill");
DynamicObject cqcontract = (DynamicObject) this.getModel().getValue("contractbill");
long id = 0;
if (null != cqcontract) {
id = cqcontract.getLong("id");
@ -62,26 +72,32 @@ public class WorkloadcfmbillFormPlugin extends AbstractFormPlugin {
*/
private void getListShowParamer(IFormView formView, IDataModel model,String contentId) {
ListShowParameter parameter = ShowFormHelper.createShowListForm("qeug_contractsummarylist", true);
parameter.getOpenStyle().setShowType(ShowType.Modal);//Floating MainNewTabPage NewBrowserPage InContainer
parameter.setBillFormId("qeug_contractsummarylist");
parameter.setHasRight(true);
StyleCss styleCss = new StyleCss();
styleCss.setWidth("1500");
styleCss.setHeight("800");
parameter.getOpenStyle().setInlineStyleCss(styleCss);
// ListShowParameter parameter = ShowFormHelper.createShowListForm("qeug_contractsummarylist", true);
// parameter.getOpenStyle().setShowType(ShowType.MainNewTabPage);//Floating MainNewTabPage NewBrowserPage NewTabPage
// parameter.setBillFormId("qeug_contractsummarylist");
// parameter.setHasRight(true);
// StyleCss styleCss = new StyleCss();
// styleCss.setWidth("1500");
// styleCss.setHeight("800");
// parameter.getOpenStyle().setInlineStyleCss(styleCss);
DynamicObjectCollection dynColl = formView.getModel().getEntryEntity("qeug_invoiceentryinfo");
int index = model.getEntryCurrentRowIndex("qeug_invoiceentryinfo");
DynamicObject dynamicObject = dynColl.get(index);
String qeug_summarycontent = dynamicObject.getString("qeug_summarycontent");//汇总内容(sheetName)
// Object pkValue = formView.getModel().getDataEntity().getPkValue();//合同ID
//// Object pkValue = formView.getModel().getDataEntity().getPkValue();//合同ID
//
QFilter q1 = new QFilter("qeug_sheetname", QCP.equals, qeug_summarycontent);
QFilter q2 = new QFilter("qeug_contractid",QCP.equals, contentId);
List<QFilter> listQF = Lists.newArrayList();
listQF.add(q1.and(q2));
parameter.setListFilterParameter(new ListFilterParameter(listQF, null));
this.getView().showForm(parameter);
// List<QFilter> listQF = Lists.newArrayList();
// listQF.add(q1.and(q2));
// parameter.setListFilterParameter(new ListFilterParameter(listQF, null));
// parameter.setCustomParam("qeug_sheetname",qeug_summarycontent);
// parameter.setCustomParam("qeug_contractid",contentId);
// parameter.setStatus(OperationStatus.ADDNEW);
// this.getView().showForm(parameter);
// OpenFormUtils.openListPage();
OpenFormUtils.openListPage(this.getView(), "qeug_contractsummarylist", ShowType.MainNewTabPage, (Map) null, q1.and(q2), (CloseCallBack) null);
}
@Override
@ -92,7 +108,7 @@ public class WorkloadcfmbillFormPlugin extends AbstractFormPlugin {
//选合同时,将清单明细同步到产值确认
//合同
case "qeug_contractbill":
case "contractbill":
// String contractname = (String)this.getModel().getDataEntity(true).get("contractname");//suppliercontact supplier cqcontract
//产值确认--清单明细
DynamicObjectCollection invoiceentryinfos = this.getModel().getDataEntity(true).getDynamicObjectCollection("qeug_invoiceentryinfo");
@ -113,19 +129,95 @@ public class WorkloadcfmbillFormPlugin extends AbstractFormPlugin {
DynamicObject qeug_invoiceentryinfo = qeug_invoiceentryinfos.get(i);
DynamicObject add = invoiceentryinfos.addNew();
add.set("seq", i);
this.getModel().setValue("qeug_summarycontent", qeug_invoiceentryinfo.get("qeug_summarycontent"), i);//汇总内容
this.getModel().setValue("qeug_amount", qeug_invoiceentryinfo.get("qeug_amount"), i);//金额()
this.getModel().setValue("qeug_isnew", qeug_invoiceentryinfo.get("qeug_isnew"), i);//是否新增行
this.getModel().setValue("qeug_remarks", qeug_invoiceentryinfo.get("qeug_remarks"), i);//备注
this.getModel().setValue("qeug_currencylist", qeug_invoiceentryinfo.get("qeug_currencylist"), i);//清单币别
add.set("qeug_summarycontent", qeug_invoiceentryinfo.get("qeug_summarycontent"));
add.set("qeug_amount", qeug_invoiceentryinfo.get("qeug_amount"));
add.set("qeug_isnew", qeug_invoiceentryinfo.get("qeug_isnew"));
add.set("qeug_remarks", qeug_invoiceentryinfo.get("qeug_remarks"));
add.set("qeug_currencylist", qeug_invoiceentryinfo.get("qeug_currencylist"));
// this.getModel().setValue("qeug_summarycontent", qeug_invoiceentryinfo.get("qeug_summarycontent"), i);//汇总内容
// this.getModel().setValue("qeug_amount", qeug_invoiceentryinfo.get("qeug_amount"), i);//金额()
// this.getModel().setValue("qeug_isnew", qeug_invoiceentryinfo.get("qeug_isnew"), i);//是否新增行
// this.getModel().setValue("qeug_remarks", qeug_invoiceentryinfo.get("qeug_remarks"), i);//备注
// this.getModel().setValue("qeug_currencylist", qeug_invoiceentryinfo.get("qeug_currencylist"), i);//清单币别
}
//携带工程经理
this.getModel().getDataEntity(true).set("qeug_engmanager",recon_contractbill.get("qeug_engmanager"));
}
this.getView().updateView("qeug_invoiceentryinfo");
this.getView().updateView("qeug_engmanager");
SaveServiceHelper.save(new DynamicObject[]{this.getModel().getDataEntity(true)});
break;
default:
break;
}
}
@Override
public void preOpenForm(PreOpenFormEventArgs e) {
// super.preOpenForm(e);
//// String formId = e.getFormId();
// switch ("formId") {
// //产值确认--清单明细
// case "qeug_invoiceentryinfo":
// //清单明细--合同
// DynamicObjectCollection dynColl = this.getModel().getEntryEntity("qeug_invoiceentryinfo");
// int index = this.getModel().getEntryCurrentRowIndex("qeug_invoiceentryinfo");
// DynamicObject dynamicObject = dynColl.get(index);
// String qeug_summarycontent = dynamicObject.getString("qeug_summarycontent");//汇总内容(sheetName)
// QFilter q1 = new QFilter("qeug_sheetname", QCP.equals, qeug_summarycontent);
// DynamicObject cqcontract = (DynamicObject) this.getModel().getValue("qeug_contractbill");
// long id = 0;
// if (null != cqcontract) {
// id = cqcontract.getLong("id");
// }
// QFilter q2 = new QFilter("id", QCP.equals, id);
// DynamicObject recon_contractbill = BusinessDataServiceHelper.loadSingle("recon_contractbill", new QFilter[]{q1, q2});
// if (null != recon_contractbill) {
// //携带合同
// this.getModel().setValue("qeug_contractbill", recon_contractbill);
// }
// break;
// default:
// break;
// }
}
public void registerListener (EventObject e){
// 页签添加监听事件*
Tab tab = this.getView().getControl("tabap");
tab.addTabSelectListener(this);
}
@Override
public void tabSelected(TabSelectEvent tabSelectEvent) {
// 页签切换时触发
String tabKey = tabSelectEvent.getTabKey();
if ("tabbillinfo".equals(tabKey)) {
//获取产值确认当前合同对应的所有清单明细
DynamicObject cqcontract = (DynamicObject) this.getModel().getValue("contractbill");
long id = 0;
if (null != cqcontract) {
id = cqcontract.getLong("id");
}
QFilter q1 = new QFilter("qeug_contractid",QCP.equals, String.valueOf(id));
DynamicObject[] recon_contractbills = BusinessDataServiceHelper.load("qeug_contractsummarylist",
"id,qeug_bcdecimalqty,qeug_unitprice", new QFilter[]{q1});
if (recon_contractbills.length > 0) {
BigDecimal bigDecimal = BigDecimal.ZERO;
for (DynamicObject recon_contractbill : recon_contractbills) {
BigDecimal qeugBcdecimalqty = recon_contractbill.getBigDecimal("qeug_bcdecimalqty");//本次完工量
BigDecimal qeugUnitprice = recon_contractbill.getBigDecimal("qeug_unitprice");//综合单价
BigDecimal qeugAmount = qeugBcdecimalqty.multiply(qeugUnitprice).setScale(2, BigDecimal.ROUND_HALF_UP);//四舍五入金额
bigDecimal = bigDecimal.add(qeugAmount);
}
this.getModel().setValue("amount", bigDecimal);//合同总金额
this.getView().updateView("amount");//
// this.getModel().setValue("notaxamount", bigDecimal);//合同总金额
// this.getView().updateView("notaxamount");//
}
}
}
}

View File

@ -1,15 +1,31 @@
package shkd.repc.recon.listplugin;
import com.google.common.collect.Lists;
import com.grapecity.documents.excel.Q;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.ListSelectedRow;
import kd.bos.entity.datamodel.ListSelectedRowCollection;
import kd.bos.entity.filter.FilterParameter;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.events.ExportFileEvent;
import kd.bos.form.events.FlexBeforeClosedEvent;
import kd.bos.form.events.SetFilterEvent;
import kd.bos.list.BillList;
import kd.bos.list.events.BillClosedCallBackEvent;
import kd.bos.list.plugin.AbstractListPlugin;
import kd.bos.list.plugin.IListPlugin;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.bos.servicehelper.user.UserServiceHelper;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* 合同明细清单列表插件
@ -17,31 +33,69 @@ import java.io.FileOutputStream;
*/
public class ContractSummaryListPlugin extends AbstractListPlugin implements IListPlugin {
@Override
public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
super.afterDoOperation(afterDoOperationEventArgs);
// String operateKey = afterDoOperationEventArgs.getOperateKey();
// if ("importdata".equals(operateKey)) {
//
// this.getView().invokeOperation("refresh");
//
//
// }else if("refresh".equals(operateKey)){
// // 获取单据列表
// BillList billList = this.getControl(AbstractListPlugin.BILLLISTID);
// //获取过滤参数
// FilterParameter generalFilterParameter = billList.generalFilterParameter();
// //获取过滤条件
// List<QFilter> qFilters = generalFilterParameter.getQFilters();
// QFilter[] array = qFilters.toArray(new QFilter[0]);
// DynamicObject[] load = BusinessDataServiceHelper.load("qeug_contractsummarylist",
// "id,qeug_decimalqty,qeug_preofpro,qeug_bcdecimalqty", array);
// for (DynamicObject add : load) {
// BigDecimal qeugDecimalqty = add.getBigDecimal("qeug_decimalqty");//工程量
// BigDecimal qeug_preofpro = add.getBigDecimal("qeug_preofpro");//完成百分比
// BigDecimal bcdecimalqty = qeugDecimalqty.multiply(qeug_preofpro).setScale(2, BigDecimal.ROUND_HALF_UP);
// add.set("qeug_bcdecimalqty", bcdecimalqty);//本次完工量
// }
// SaveServiceHelper.save(load);
// }
}
@Override
public void billClosedCallBack(BillClosedCallBackEvent e) {
super.billClosedCallBack(e);
}
@Override
public void setFilter(SetFilterEvent e) {
super.setFilter(e);
Map<String, Object> customParams = this.getView().getFormShowParameter().getCustomParams();
if (customParams.isEmpty()) {
return;
}
String qeug_sheetname = (String) customParams.get("qeug_sheetname");
String qeug_contractid = (String) customParams.get("qeug_contractid");
// List<QFilter> qFilters = e.getQFilters();
// qFilters.clear();
// QFilter q1 = new QFilter("qeug_sheetname", QCP.equals, qeug_sheetname);
// QFilter q2 = new QFilter("qeug_contractid",QCP.equals, qeug_contractid);
// List<QFilter> listQF = Lists.newArrayList();
// listQF.add(q1.and(q2));
// qFilters.addAll(listQF);
}
/** 导出文件后事件可以用来修改导出的文件内容比如修改excel数据、格式、加密等 */
public void afterExportFile(ExportFileEvent e) {
File file = e.getFile();
// if (file != null) {
// try (FileInputStream fis = new FileInputStream(file);) {
// Workbook wb = new XSSFWorkbook(fis);
// Sheet sheet = wb.getSheetAt(0);
// // 修改背景颜色示例写死自行修改
// for (int i = 0; i < 3; i++) {
// CellStyle cs = wb.createCellStyle();
// cs.setFillForegroundColor(IndexedColors.RED.getIndex());
// cs.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// cs.setLocked(true);
// sheet.getRow(i).getCell(1).setCellStyle(cs);
// }
// // 保存
// FileOutputStream out = new FileOutputStream(file);
// wb.write(out);
// wb.close();
// out.close();
// } catch (Throwable ex) {
// ex.printStackTrace();
// }
// }
}
@Override
public String getPluginName() {
return null;

View File

@ -5,10 +5,15 @@ 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) {
@ -18,19 +23,34 @@ public class IntroduceContractPlugin extends BatchImportPlugin {
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;
try {
bcdecimalqty = Double.parseDouble(qeug_bcdecimalqty);
decimalqty = Double.parseDouble(qeug_decimalqty);
} catch (NumberFormatException e) {
logger.log(importBillData.getStartIndex(),"工程量数据格式有误").fail();
iterator.remove();
}
if (bcdecimalqty>decimalqty){
logger.log(importBillData.getStartIndex(),"本次完工量不能大于工程量").fail();
iterator.remove();
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);
}

View File

@ -7,6 +7,7 @@ import kd.bos.form.control.AttachmentPanel;
import kd.bos.form.control.Button;
import kd.bos.form.control.EntryGrid;
import kd.bos.form.control.events.UploadListener;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.events.HyperLinkClickEvent;
import kd.bos.form.events.HyperLinkClickListener;
import kd.bos.form.field.BasedataEdit;
@ -16,6 +17,7 @@ import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import org.jetbrains.annotations.NotNull;
import java.math.BigDecimal;
@ -132,4 +134,63 @@ public class RepeOrderFormPlugin extends AbstractFormPlugin {
return ordercount;
}
// @Override
// public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
// super.afterDoOperation(afterDoOperationEventArgs);
// //采购订单,选择合同,填写明细审核后反写到对应合同
// String operateKey = afterDoOperationEventArgs.getOperateKey();
// if ("audit".equals(operateKey)){
// DynamicObject dataEntity = this.getModel().getDataEntity();
//
// String number = "";
// String name = "";
// //获取合同()
// DynamicObject cqcontract = (DynamicObject) this.getModel().getValue("cqcontract");
// if (null == cqcontract) {
// return;
// }
// number = cqcontract.getString("number");
// name = cqcontract.getString("name");
// QFilter q1 = new QFilter("billno", QCP.equals, number);
// QFilter q2 = new QFilter("billname", QCP.equals, name);
// DynamicObject recon_contractbill = BusinessDataServiceHelper.loadSingle("recon_contractbill", new QFilter[]{q1,q2});
// if (null != recon_contractbill) {
// DynamicObjectCollection qeugOrderformentry = recon_contractbill.getDynamicObjectCollection("qeug_orderformentry");
// qeugOrderformentry.clear();
//
// cqcontract.getDynamicObjectCollection("");
// DynamicObjectCollection orderformentrys = dataEntity.getDynamicObjectCollection("orderformentry");
// for (int i = 0; i < orderformentrys.size(); i++) {
// DynamicObject add = qeugOrderformentry.addNew();
// DynamicObject orderformentry = orderformentrys.get(i);
// add.set("seq",i);
// add.set("qeug_material", orderformentry.get("material"));//物料编码
// add.set("qeug_brand", orderformentry.get("brand"));//品牌
// add.set("qeug_model", orderformentry.get("model"));//型号
// add.set("qeug_contractnum", orderformentry.get("contractnum"));//合同数量
// add.set("qeug_ordercount", orderformentry.get("ordercount"));//本次订货数量
// add.set("qeug_entryenterdate", orderformentry.get("entryenterdate"));//要求进场日期
// add.set("qeug_unitprice", orderformentry.get("unitprice"));//材料单价
// add.set("qeug_originalprice", orderformentry.get("originalprice"));//原始单价
// add.set("qeug_transportprice", orderformentry.get("transportprice"));//运费单价
// add.set("qeug_installprice", orderformentry.get("installprice"));//安装单价
// add.set("qeug_totalprice", orderformentry.get("totalprice"));//综合单价
// add.set("qeug_totaloriginalprice", orderformentry.get("totaloriginalprice"));//综合原始单价
// add.set("qeug_taxprice", orderformentry.get("taxprice"));//含税单价
// add.set("qeug_taxrate", orderformentry.get("taxrate"));//税率
// add.set("qeug_taxamount", orderformentry.get("taxamount"));//税额
// add.set("qeug_notaxtotalprice", orderformentry.get("notaxtotalprice"));//不含税总价
// add.set("qeug_taxtotalprice", orderformentry.get("taxtotalprice"));//含税总价
// add.set("qeug_totaldeliverycount", orderformentry.get("totaldeliverycount"));//累计发货数量
// add.set("qeug_totalreceivecount", orderformentry.get("totalreceivecount"));//累计收货数量
// add.set("qeug_totalrefundcount", orderformentry.get("totalrefundcount"));//累计退货数量
// add.set("qeug_total_accept_count", orderformentry.get("total_accept_count"));//累计验收数量
// add.set("qeug_goodsinfo", orderformentry.get("goodsinfo"));//商品信息
// add.set("qeug_description", orderformentry.get("description"));//备注
//
// }
// SaveServiceHelper.save(new DynamicObject[]{recon_contractbill});
// }
// }
// }
}

View File

@ -0,0 +1,198 @@
package shkd.todotask;
import com.alibaba.fastjson.JSONObject;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.util.StringUtils;
import kd.bos.workflow.engine.impl.persistence.entity.operationlog.OperationLogEntity;
import kd.bos.workflow.engine.msg.AbstractMessageServiceHandler;
import kd.bos.workflow.engine.msg.ctx.MessageContext;
import kd.bos.workflow.engine.msg.info.ToDoInfo;
import kd.bos.workflow.service.WorkflowService;
import kd.bos.workflow.service.impl.ServiceFactory;
import shkd.utils.OAUtils;
import java.text.SimpleDateFormat;
import java.util.*;
import static shkd.utils.OAUtils.*;
public class todoZyTaskServiceHandler extends AbstractMessageServiceHandler {
private static final Log logger = LogFactory.getLog(todoZyTaskServiceHandler.class);
/**
* 通过人员id获取人员信息
* @param userIds 人员id集合
* @param approvers 人员信息集合
*/
private List<DynamicObject> getApprovers(List<Long> userIds,List<DynamicObject> approvers){
for (Long userId : userIds) {
DynamicObject user = BusinessDataServiceHelper.loadSingle(userId, "bos_user");
approvers.add(user);
}
return approvers;
}
@Override
public void createToDo(MessageContext messageContext, ToDoInfo toDoInfo) {
System.out.println("createToDo");
//获取流程实例ID
Long processInstanceId = messageContext.getProcessInstanceId();
//获取任务步骤
Long executionId = messageContext.getExecutionId(); // 节点ID
//获取当前任务ID
Long taskId = messageContext.getTaskId();
//获取单据编码
String billNo = messageContext.getBillNo();
//获取审批人集合
List<DynamicObject> approvers = new ArrayList<>();
List<Long> userIds = toDoInfo.getUserIds(); // 审批人ID集合
List<DynamicObject> approversLists = getApprovers(userIds, approvers);
//获取任务标题
Map<String, Object> params = toDoInfo.getParams();
String subjectJson = (String) params.get("subject");
JSONObject subjectObj = JSONObject.parseObject(subjectJson);
String title = subjectObj.getString("zh_CN");
// 节点名称
String executionName = "";
DynamicObject execution = BusinessDataServiceHelper.loadSingle(executionId, "wf_execution");
if(execution != null){
executionName = execution.getString("activityname");// 节点名称
}
//获取Url
String url = toDoInfo.getUrl(); // 链接
//获取任务创建人
Long startUserId = messageContext.getStartUserId(); // 审批实例发起人id
DynamicObject startUser = BusinessDataServiceHelper.loadSingle(startUserId, "bos_user");
String startNumber = "";
String startName = "";
if (null != startUser) {
startNumber = startUser.getString("number");
startName = startUser.getString("name");
if (!userIds.contains(startUserId)) {
approversLists.add(startUser);//添加发起人到审批人集合_便于后续接口调用(用户绑定接口)
}
}
//待办创建时间格式yyyy-MM-dd HH:mm:ss
Date createDate = messageContext.getCreateDate();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String createDateStr = sdf.format(createDate);
//获取token
String oaToken = OAUtils.getOaToken(billNo);
if (StringUtils.isNotEmpty(oaToken)) {
//todo OA人员绑定接口
thirdpartyUser(approversLists, oaToken,billNo);
HashMap<String, Object> thirdPartyMap = new HashMap<>();
thirdPartyMap.put("oaToken",oaToken);
thirdPartyMap.put("approversLists",approversLists);
thirdPartyMap.put("taskId",taskId);
thirdPartyMap.put("title",title);
thirdPartyMap.put("startName",startName);
thirdPartyMap.put("createDateStr",createDateStr);
thirdPartyMap.put("url",url);
thirdPartyMap.put("billNo",billNo);
//推送OA待办新增接口
thirdParty(thirdPartyMap);
}
System.out.println("createToDo");
}
@Override
public void dealToDo(MessageContext messageContext, ToDoInfo toDoInfo) {
//select * from t_wf_operationlog where fbillno = '测试:待办推送致远(1106-1915)'
//todo 待办推送第三方,节点审批通过或者驳回到某节点时都会进入(dealToDo)方法,代码如何判断该节点是驳回还是审批通过
//获取当前任务ID
Long taskId = messageContext.getTaskId();
// List<OperationLogEntity> operationLogByTaskId = ServiceFactory.getService(WorkflowService.class).getTaskService().getOperationLogByTaskId(taskId);
String decisionType = ServiceFactory.getService(WorkflowService.class).getTaskService().getOperationLogByTaskId(taskId).get(0).getDecisionType();
String subState = "";
//驳回
if("reject".equals(decisionType)){
subState = "3";
}
//审批通过
else if ("approve".equals(decisionType)) {
subState = "0";
}
//获取流程实例ID
Long processInstanceId = messageContext.getProcessInstanceId();
//获取任务步骤
Long executionId = messageContext.getExecutionId(); // 节点ID
//获取单据编码
String billNo = messageContext.getBillNo();
//获取token
String oaToken = OAUtils.getOaToken(billNo);
if (StringUtils.isNotEmpty(oaToken)) {
HashMap<String, Object> updateStateMap = new HashMap<>();
updateStateMap.put("oaToken",oaToken);
updateStateMap.put("taskId",taskId);
updateStateMap.put("state","1");
updateStateMap.put("subState",subState);
updateStateMap.put("billNo",billNo);
//推送OA待办变更接口
updatePendingState(updateStateMap);
}
System.out.println("createToDo");
System.out.println("createToDo");
}
@Override
public void deleteToDo(MessageContext messageContext, ToDoInfo toDoInfo) {
//获取流程实例ID
Long processInstanceId = messageContext.getProcessInstanceId();
//获取任务步骤
Long executionId = messageContext.getExecutionId(); // 节点ID
//获取当前任务ID
Long taskId = messageContext.getTaskId();
String decisionType = ServiceFactory.getService(WorkflowService.class).getTaskService().getOperationLogByTaskId(taskId).get(0).getDecisionType();
String subState = "";
//单据撤销
if("reject".equals(decisionType)){
subState = "2";
}
//终止流程
else if ("approve".equals(decisionType)) {
subState = "3";
}
//获取单据编码
String billNo = messageContext.getBillNo();
//获取token
String oaToken = OAUtils.getOaToken(billNo);
if (StringUtils.isNotEmpty(oaToken)) {
HashMap<String, Object> updateStateMap = new HashMap<>();
updateStateMap.put("oaToken",oaToken);
updateStateMap.put("taskId",taskId);
updateStateMap.put("state","1");
updateStateMap.put("subState",subState);
updateStateMap.put("billNo",billNo);
//推送OA待办变更接口
updatePendingState(updateStateMap);
}
System.out.println("createToDo");
System.out.println("createToDo");
}
}

View File

@ -1,12 +1,17 @@
package shkd.utils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.util.HttpClientUtils;
import kd.bos.util.StringUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author weiyunlong
@ -16,17 +21,24 @@ import java.util.Date;
public class OAUtils {
private static final Log logger = LogFactory.getLog(OAUtils.class);
private static final String oaUrl = System.getProperty("oaurl");//(测试环境外网地址)
// private static final String oaUrl = "http://172.31.254.240:9090";//本地(内网地址)
//致远服务前获取token接口
public static String getOaToken(){
public static String getOaToken(String billNo){
//String url = System.getProperty("efms.infcompany.url.ip");
//logger.info("url");
//致远服务前获取token接口
String userName = "ICSTest";
String password = "8f72e360-268e-41ba-9886-af9a802e4de3";
String linkUrl = "http://172.31.254.240:9090/seeyon/rest/token";
// String userName = "ICSTest";
// String password = "8f72e360-268e-41ba-9886-af9a802e4de3";
String userName = "JDtest";
String password = "235c78d7-03a6-4b32-8632-7b75a002276b";
// String oaUrl = System.getProperty("oaurl");
// String oaUrl = "http://172.31.254.240:9090";
String linkUrl = oaUrl +"/seeyon/rest/token";
//接口请求体
JSONObject linkBody = new JSONObject();
linkBody.put("userName", userName);
@ -41,14 +53,209 @@ public class OAUtils {
JSONObject jsonObject = JSONObject.parseObject(linkPostjson);
token = jsonObject.getString("id");
DobeDWUtils.saveLog(billNo,
"致远",linkBody.toJSONString(), linkPostjson,
true,"调用致远服务前获取token接口");
}
return token;
} catch (Exception e) {
logger.info(String.format("获取OaToken接口异常%s", e.getMessage()));
DobeDWUtils.saveLog(billNo,
"致远",linkBody.toJSONString(), e.getMessage(),
false,"调用致远服务前获取token接口");
throw new RuntimeException(e);
}
}
/**
* OA接口绑定用户
* 代办接口之前需要先(用户的绑定 你通过定时任务 增量推就行或者你们系统有人员进来推一次这个人绑定成功了 就不需要再绑定除非人员工号有变动)
* 先调OA接口绑定用户(相当于校验金蝶用户的number在OA系统是否存在不存则推送失败)
* @param approversLists 金蝶系统的审批人集合
* @param oaToken 致远OA获取的token
* @return
*/
public static String thirdpartyUser(List<DynamicObject> approversLists, String oaToken,String billNo){
// String oaUrl = System.getProperty("oaurl");
String thirdUrl = oaUrl + "/seeyon/rest/thirdpartyUserMapper/binding";
Map<String, String> customerHeader = new HashMap<>();
customerHeader.put("Content-Type", "application/json");
customerHeader.put("token", oaToken);
//组装请求体
JSONObject thirdBody = new JSONObject();
JSONArray thirdList = new JSONArray();
//接口不支持接收人字段为多人,但接口支持批量 so 多人审批,遍历审批人集合,调用OA调待办接口
for (DynamicObject approver : approversLists) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("registerCode", "3004");//系统注册编码:3004
// jsonObject.put("thirdUserId",approver.getString("number"));//三方系统人员编码通过人员编码匹配需要和OA保持一致
jsonObject.put("thirdUserId","jdtest");//todo 三方系统人员编码通过人员编码匹配需要和OA保持一致
// jsonObject.put("thirdLoginName", approver.getString("name"));//三方系统人员登录名
jsonObject.put("thirdLoginName", "金蝶测试");//todo 三方系统人员登录名
// jsonObject.put("thirdName", approver.getString("name"));//三方系统人员姓名
jsonObject.put("thirdName", "金蝶测试");//todo 三方系统人员姓名
// jsonObject.put("thirdCode", approver.getString("number"));//三方系统人员编码
jsonObject.put("thirdCode","jdtest");//todo 三方系统人员编码
thirdList.add(jsonObject);
}
thirdBody.put("userlist", thirdList);
String thirdPostjson = null;
try {
// 发送POST请求并获取响应
thirdPostjson = HttpClientUtils.postjson(thirdUrl, customerHeader, thirdBody.toJSONString());
JSONObject jsonObject = JSONObject.parseObject(thirdPostjson);
// 检查JSON对象是否为空
if (jsonObject != null && !jsonObject.isEmpty()) {
Boolean result = jsonObject.getBoolean("success");
String logMessage = result ? "OA接口绑定用户成功" : "OA接口绑定用户失败";
logger.info(logMessage);
// 记录日志
DobeDWUtils.saveLog(billNo, "致远", thirdBody.toJSONString(), thirdPostjson, result, "调用致远用户绑定接口");
// 若绑定用户失败抛出异常
if (!result) {
throw new RuntimeException("OA接口绑定用户失败" + thirdPostjson);
}
}
} catch (Exception e) {
// 记录异常信息
String errorMessage = String.format("接口异常:%s", e.getMessage());
logger.info(errorMessage);
DobeDWUtils.saveLog(billNo, "致远", thirdBody.toJSONString(), e.getMessage(), false, "调用致远用户绑定接口");
throw new RuntimeException(e);
}
return thirdPostjson;
}
/**
* 金蝶系统推送OA待办新增
* @param thirdPartyMap 流程参数
*/
public static void thirdParty(HashMap<String, Object> thirdPartyMap){
// String oaUrl = System.getProperty("oaurl");
String pendingsUrl = oaUrl + "/seeyon/rest/thirdpartyPending/receive/pendings";
Map<String, String> customerHeader = new HashMap<>();
customerHeader.put("Content-Type", "application/json");
customerHeader.put("token", String.valueOf(thirdPartyMap.get("oaToken")));
//组装请求体
JSONObject pendingsBody = new JSONObject();
JSONArray pendingList = new JSONArray();
//接口不支持接收人字段为多人,但接口支持批量 so 多人审批,遍历审批人集合,调用OA调待办接口
List<DynamicObject> approversLists = (List<DynamicObject>)thirdPartyMap.get("approversLists");
for (DynamicObject approver :approversLists ) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("taskId", String.valueOf(thirdPartyMap.get("taskId")));//第三方待办主键保证唯一
jsonObject.put("registerCode", "3004");//系统注册编码
jsonObject.put("title", String.valueOf(thirdPartyMap.get("title")) );//待办标题
// jsonObject.put("thirdSenderId", startNumber);//第三方待办发起人主键
jsonObject.put("thirdSenderId", "jdtest");//todo 第三方待办发起人主键
// jsonObject.put("senderName", String.valueOf(thirdPartyMap.get("startName")) );//第三方待办发起人姓名
jsonObject.put("senderName", "金蝶测试" );//todo 第三方待办发起人姓名
// jsonObject.put("thirdReceiverId", approver.getString("number"));//第三方待办接收人主键保证唯一
jsonObject.put("thirdReceiverId", "jdtest");//todo 第三方待办接收人主键保证唯一
jsonObject.put("creationDate", String.valueOf(thirdPartyMap.get("createDateStr")));//待办创建时间格式yyyy-MM-dd HH:mm:ss
jsonObject.put("state", "0");//状态0:未办理1:已办理
jsonObject.put("url", String.valueOf(thirdPartyMap.get("url")));//PC端穿透链接
jsonObject.put("h5url", "test");//移动端穿透链接
pendingList.add(jsonObject);
}
pendingsBody.put("pendingList", pendingList);
String pendingPostjson = null;
try {
// 发送POST请求并获取响应
pendingPostjson = HttpClientUtils.postjson(pendingsUrl, customerHeader, pendingsBody.toJSONString());
JSONObject jsonObject = JSONObject.parseObject(pendingPostjson);
// 检查JSON对象是否为空
if (jsonObject != null && !jsonObject.isEmpty()) {
Boolean result = jsonObject.getBoolean("success");
String logMessage = result ? "金蝶系统推送OA待办新增成功" : "金蝶系统推送OA待办新增失败";
// 记录日志
logger.info(logMessage);
DobeDWUtils.saveLog(String.valueOf(thirdPartyMap.get("billNo")),
"致远", pendingsBody.toJSONString(), pendingPostjson,
result, "调用推送OA待办新增接口");
}
logger.info("接口返回结果:\n{}", pendingPostjson);
} catch (Exception e) {
// 记录异常信息
String errorMessage = String.format("接口异常:%s", e.getMessage());
logger.info(errorMessage);
DobeDWUtils.saveLog(String.valueOf(thirdPartyMap.get("billNo")),
"致远", pendingsBody.toJSONString(), e.getMessage(),
false, "调用推送OA待办新增接口");
throw new RuntimeException(e);
}
}
/**
* OA待办变更
* @param updateStateMap 流程参数
*/
public static void updatePendingState (HashMap<String, Object> updateStateMap){
// String oaUrl = System.getProperty("oaurl");
String pendingsUrl = oaUrl + "/seeyon/rest/thirdpartyPending/updatePendingState";
Map<String, String> customerHeader = new HashMap<>();
customerHeader.put("Content-Type", "application/json");
customerHeader.put("token", String.valueOf(updateStateMap.get("oaToken")));
//组装请求体
JSONObject pendingsBody = new JSONObject();
pendingsBody.put("registerCode","3004");
pendingsBody.put("taskId",String.valueOf(updateStateMap.get("taskId")));
pendingsBody.put("state",String.valueOf(updateStateMap.get("state")));
pendingsBody.put("subState",String.valueOf(updateStateMap.get("subState")));
String pendingPostjson = null;
try {
// 发送POST请求并获取响应
pendingPostjson = HttpClientUtils.postjson(pendingsUrl, customerHeader, pendingsBody.toJSONString());
JSONObject jsonObject = JSONObject.parseObject(pendingPostjson);
// 检查JSON对象是否为空
if (jsonObject != null && !jsonObject.isEmpty()) {
Boolean result = jsonObject.getBoolean("success");
String logMessage = result ? "金蝶系统推送OA待办变更成功" : "金蝶系统推送OA待办变更失败";
// 记录日志
logger.info(logMessage);
DobeDWUtils.saveLog(String.valueOf(updateStateMap.get("billNo")),
"致远", pendingsBody.toJSONString(), pendingPostjson,
result, "调用推送OA待办变更接口");
}
logger.info("接口返回结果:\n{}", pendingPostjson);
} catch (Exception e) {
// 记录异常信息
String errorMessage = String.format("接口异常:%s", e.getMessage());
logger.info(errorMessage);
DobeDWUtils.saveLog(String.valueOf(updateStateMap.get("billNo")),
"致远", pendingsBody.toJSONString(), e.getMessage(),
false, "调用推送OA待办变更接口");
throw new RuntimeException(e);
}
}
/**
* model值转Long
*/