Purchase order BP timed task plug-in development
Recently, our company has to integrate the purchase order approval and OA, that is, move the approval process of u9 to OA. When the salesperson clicks the standard purchase submit button, the information of the purchase order is triggered to the OA process, and the review is done in the OA. After the OA review is completed, the review result is written back to U9.
To achieve this function, you need to use BE plug-in and BP plug-in.
The BE plug-in is responsible for writing the purchase order information into the intermediate table when the salesman submits the review, and then triggers the OA process.
(Please see this article: BE Plug-in Development for U9 Secondary Development )
The BP plug-in is responsible for regularly querying the intermediate table and writing the audit results back to the u9 system.
Here I explain the development process of the BP plug-in.
Generate project code
1. Open the ubfdev tool to create a new solution
Open the ubfdev tool, click File-New Solution, check the operation item, enter the name of the solution, and click the OK button.
2. Modify the project name
Modify the project name and delete the automatically generated .ubfbp file.
Click the Properties button to modify the name:
After modification:
3. Create new business components
Right-click the project – create new, select the business operation component, fill in the component name, and click the OK button.
Select the model view and double-click the item to open the operation page.
Drag the action button onto the form:
Click the operation entity, click the property button, and modify the name:
Modify the transaction type to required:
4. Construct code
Right-click the project and click Construct
You can see the path of the generated code in the message list
Write code
Open the generated project, right click on the reference, and add a reference:
Note: BP needs to import *PMISV.Agent.dll, to import the agent.
Write code:
namespace UpdatePurchaseOrderAuditStatus
{
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using UFIDA.U9.CBO.Pub.Controller;
using UFIDA.U9.PM.PO;
using UFSoft.UBF.AopFrame;
using UFSoft.UBF.Util.Context;
using UFSoft.UBF.Util.DataAccess;
using UFIDA.U9.Base.DTOs;
using UFIDA.U9.PM.DTOs;
/// <summary>
/// UpdateStatus partial
/// </summary>
public partial class UpdateStatus
{
internal BaseStrategy Select()
{
return new UpdateStatusImpementStrategy();
}
}
#region implement strategy
/// <summary>
/// Impement Implement
///
/// </summary>
internal partial class UpdateStatusImpementStrategy : BaseStrategy
{
public UpdateStatusImpementStrategy() {
}
public override object Do(object obj)
{
UpdateStatus bpObj = (UpdateStatus)obj;
//get business operation context is as follows
//IContext context = ContextManager.Context
//auto generating code end,underside is user custom code
//and if you Implement replace this Exception Code...
//throw new NotImplementedException();
DataSet ds = new DataSet();
DataParamList paras = new DataParamList();
StringBuilder sql = new StringBuilder();
//查找OA审核通过并未同步的数据,OA审核不通过的不处理
sql.Append("select * from PurchaseOrder_Middle where audit_status = 1 and state = 0");
DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), sql.ToString(), paras, out ds);
if (ds != null)
{
if (ds.Tables.Count > 0)
{
// 生成审核状态BP对象
UFIDA.U9.ISV.PO.Proxy.ApprovePOISVProxy approveProxy = new UFIDA.U9.ISV.PO.Proxy.ApprovePOISVProxy();
foreach (DataRow dataRow in ds.Tables[0].Rows)
{
try
{
string auditPerson = Convert.ToString(dataRow["audit_person"]);
if (auditPerson != null)
{
//设置审核人
setApprovedBy(auditPerson);
}
List<IDCodeNameDTOData> dtoDatas = new List<IDCodeNameDTOData>();
IDCodeNameDTOData dtoData = new IDCodeNameDTOData();
dtoData.ID = Convert.ToInt64(dataRow["PRID"]);
dtoDatas.Add(dtoData);
//审核通过
approveProxy.ActionType = 8; // 审核:8
approveProxy.POList = dtoDatas;
approveProxy.TargetOrgCode = UFIDA.U9.Base.Context.LoginOrg.Code;
approveProxy.Do();
//修改中间表状态
sql.Clear();
sql.Append("update PurchaseOrder_Middle set state = 1,memo = '审核状态同步成功',update_by = 'sys',update_time = GETDATE() where id = " + dataRow["id"]);
DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), sql.ToString(), paras, out ds);
}
catch (Exception ex)
{
//记录异常信息
sql.Clear();
sql.Append("update PurchaseOrder_Middle set state = -1, memo = '" + ex.Message + "',update_by = 'sys',update_time = GETDATE() where id = " + dataRow["id"]);
DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), sql.ToString(), paras, out ds);
//throw ex; //throw 异常会导致sql回滚
}
}
}
}
return null;
}
//设置审核人
private void setApprovedBy(String UserCode)
{
PlatformContext context = PlatformContext.Current;
if (!((context == null) || string.IsNullOrEmpty(context.OrgCode)))
{
ContextDTO tdto = new ContextDTO();
//传入审核人工号
tdto.UserCode = UserCode;
tdto.EntCode = context.EnterpriseID;
tdto.CultureName = context.Culture;
tdto.OrgCode = context.OrgCode;
tdto.WriteToContext();
}
}
}
#endregion
}
After compiling, execute the AutoBuild.bat batch program, which will automatically copy the dll file of the corresponding project to the u9 system directory.
If the copy fails, please refer to the content of AutoBuild.bat to copy manually.
Also remember to run the sql statement in the UBFV60\U9.VOB.Product.Other\Unconfiged\MetadataScript directory.
I forgot to run the sql here causing the service not found on the service permissions page, wasting a lot of time. . .
publish components
Right-click the solution, click Publish Service Components, and publish the components:
After the release is complete, a .sg file will be generated in the solution directory.
The environment.xml file needs to be configured before configuring components.
1. Configure the environment.xml file
Open the environment.xml file in the \UBFV60\U9.VOB.Product.UBF\UBFStudio\Runtime directory, and configure the database connection information.
2. Configuration components
Open the BuildupDesigner.exe file in the \UBFV60\U9.VOB.Product.UBF\UBFStudio directory
Select Supply Chain – Purchasing Management, and click the Add Component button.
load component
Select the .sg file:
Select the component to be loaded, and then click OK.
Then select Tools – Publish.
3. Add service permissions
Open the u9 service permission page, select the procurement management module, select the BP service we added, usually on the last page, and then select Allow in the execution drop-down box.
4. Insert UBF_JOB_NoParaRunableBPSVList table data
The latest patch of U9 6.0 optimizes the function of selecting asynchronous programs in request management. You need to insert BP-related data into the prefab table UBF_JOB_NoParaRunableBPSVList before you can select BP (the full name of BP is required for prefabrication).
The preset script is as follows: (each BP scheduled for execution needs to be preset)
INSERT INTO UBF_JOB_NoParaRunableBPSVList VALUES( NewID(), 'UpdatePurchaseOrderAuditStatus.UpdateStatus', 'Modify purchase order audit status')
Note: The FullName field of the UBF_JOB_NoParaRunableBPSVList table is: 'UpdatePurchaseOrderAuditStatus.UpdateStatus', which must be copied in the service authority page, so don't make a mistake.
5. Add request management
Open the request management page, fill in the code and request name, then select the scheduling scheme, select the application and asynchronous program, and click Save.
After saving, click Operation – Submit Request, and if you have the submitter and submission time, it will be successful.
6. Debugging program
Note that if you want to debug BP, the additional process you choose is ApplicationService.exe instead of w3wp.exe:
make patch
For patch production, please refer to this article: U9 Secondary Development Patch Production
1. Copy the bdxml file
Copy the .bdxml file under the ubfdev solution path to the AssemblyInfo folder:
2. Copy bp related compilation files
We compile bp-related files from
Project Path\BpImplement\bin\Debug
Project Path\BpAgent\bin\Debug
Copy to the Files folder:
If you don't know which files to copy, you can refer to the content in the AutoBuild.bat file.
3. Copy the .bulk file
Then, copy the .bulk file from the UBFV60\U9.VOB.Product.Other\Unconfiged\MetadataScript path to the Metadata folder:
After the patch is done, it can be released.
at last
This is the whole process of developing the BP timing task plug-in. The steps are relatively cumbersome, and there are relatively few u9 second-opening materials on the Internet. Just make a record for future reference.