Files
梁骏愉 2306c8b7cf 1
2025-03-15 15:03:34 +08:00

116 lines
4.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#引入clr运行库
import clr
#添加对cloud插件开发的常用组件引用
clr.AddReference('System')
clr.AddReference('System.Data')
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('Kingdee.BOS.App')
clr.AddReference('Kingdee.BOS.App.Core')
clr.AddReference('Kingdee.BOS.Contracts')
clr.AddReference('Kingdee.BOS.DataEntity')
clr.AddReference('Kingdee.BOS.ServiceHelper')
clr.AddReference('Kingdee.BOS.WebApi.FormService')
#dairycloud基础库中的常用实体对象分命名空间导入不会递归导入
from Kingdee.BOS.Core import *
from Kingdee.BOS.Util import *
from Kingdee.BOS.Core.Bill import *
from Kingdee.BOS.Core.List import *
from Kingdee.BOS.Core.Bill.PlugIn import *
from Kingdee.BOS.Orm.DataEntity import *
from Kingdee.BOS.Core.DynamicForm.PlugIn import *
from Kingdee.BOS.Core.DynamicForm.PlugIn.Args import *
from Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel import *
from Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs import *
from System import *
from System.Data import *
from Kingdee.BOS.App.Data import *
from Kingdee.BOS.App import *
from Kingdee.BOS.Orm import *
from Kingdee.BOS.Contracts import *
from System.Collections.Generic import List
from Kingdee.BOS.ServiceHelper import *
from Kingdee.BOS.App.Core import *
from Kingdee.BOS.WebApi.FormService import *
def OnPreparePropertys(e):
e.FieldKeys.Add("FVersions");
e.FieldKeys.Add("FBillNo");
e.FieldKeys.Add("FForecastYear");
def EndOperationTransaction(e):
# raise Exception("A")
if this.FormOperation.OperationId == 1:
DoClosePLN_FORECAST(e);
def DoClosePLN_FORECAST(e):
for entity in e.DataEntitys:
billNo = entity["BillNo"]
billId = entity["Id"]
sqlL = """/*dialect*/
;WITH #年度预测单 AS (
SELECT t1.FBILLNO,t1.FISCLOSE,t0.FFORECASTYEAR,t0.FBILLNO 'thisBillNo'
,ROW_NUMBER() OVER (ORDER BY t1.FBILLNO DESC) RN
,CASE WHEN t1.FBILLNO = t0.FBILLNO THEN 1 ELSE 0 END A
FROM T_PLN_FORECAST2YEAR t0
INNER JOIN T_PLN_FORECAST2YEAR t1 on t0.FFORECASTYEAR = t1.FFORECASTYEAR
WHERE t0.FBILLNO = '{0}'
--AND t1.FISCLOSE != 'B'
)
SELECT t0.FBILLNO,t0.FID,t0.FCONVERTBILLNO,t0e.FENTRYID,t0e.FCLOSESTATUS,t0.FBILLTYPEID
FROM ( SELECT TOP 1 t2.*
FROM #年度预测单 t2
INNER JOIN #年度预测单 t1 on t1.A = 1
WHERE t2.RN > t1.RN
ORDER BY t2.RN
) tt
INNER JOIN T_PLN_FORECAST t0 on t0.FCONVERTBILLNO = tt.FBILLNO
INNER JOIN T_PLN_FORECASTENTRY t0e on t0e.FID = t0.FID
WHERE 1 = 1
AND t0.FBILLTYPEID = '67707a90214919' --年度
AND (t0e.FCLOSESTATUS = 'A' OR t0e.FCLOSESTATUS = '')
""".format(billNo)
# raise Exception(sqlL);
dataList = DBServiceHelper.ExecuteDynamicObject(this.Context, sqlL)
if dataList.Count == 0:
return;
# 请求参数
id = dataList[0]["FID"]
pkEntryIds = List[str]()
para = {"CreateOrgId":this.Context.UserId,"Numbers":[],"Ids":"","PkEntryIds":[],"UseOrgId":this.Context.CurrentOrganizationInfo.ID,"NetworkCtrl":"","IgnoreInterationFlag":""}
for item in dataList:
# pkEntryIds.Add(str(item["FENTRYID"]))
para["PkEntryIds"].Add({"Id":str(item["FID"]),"EntryIds":str(item["FENTRYID"])})
# raise Exception(JsonUtil.Serialize(para))
# 业务对象标识
formId = "PLN_FORECAST"
# 操作接口编码
operateNumber = "BillClose"
resultJson = WebApiServiceCall.Execute(this.Context, formId, operateNumber, JsonUtil.Serialize(para));
# raise Exception(JsonUtil.Serialize(resultJson))
if resultJson !=None :
IsSuccess = resultJson["Result"]["ResponseStatus"]["IsSuccess"]
if IsSuccess==False:
raise Exception(JsonUtil.Serialize(resultJson))
updSql = """/*dialect*/
WITH #上版本 AS (
SELECT TOP 1 t1.*
FROM T_PLN_FORECAST2YEAR t0
INNER JOIN T_PLN_FORECAST2YEAR t1 on t0.FFORECASTYEAR = t1.FFORECASTYEAR
WHERE t0.FBILLNO = '{0}'
AND t1.FBILLNO != '{0}'
ORDER By t1.FBILLNO DESC
)
UPDATE T_PLN_FORECAST2YEAR SET FIsClose = 'B'
FROM T_PLN_FORECAST2YEAR t0
INNER JOIN #上版本 t1 on t1.FID = t0.FID
WHERE t1.FIsClose != 'B'
""".format(billNo)
res = DBServiceHelper.Execute(this.Context, updSql)
return;