# 後端
:::info
## ComplexReport表尾
:::
```
protected override void EndBuilder(JArray[] toaData)
{
this.ComplexReport.FinishOR();
this.ReturnTOTA.TotaBody = new TxnReportResultViewModel<ReportResultViewModel>
{
ReportData = new ReportResultViewModel
{
ConversationId = this.ConversationID,
Unid = this.FirstUnid
}
};
}
```
:::info
####當報表無TOTA
:::
```
var toadata = new ColumnViewModel[] { };
```
:::info
####當報表無LocalData
:::
```
var localData = new ColumnViewModel[] { };
```
:::info
####只有系統及輸入資料
:::

```
protected override void Builder(TitaViewModel titaModel, JArray[] toaData)
{
//純印輸入資料
var toadata = new ColumnViewModel[] { };
var reportId = "H27307R1";
var reportInfo = new ReportInfoViewModel();
var localData = new ColumnViewModel[] { };
ReportResultViewModel r = this.GenerateSimpleReport(toadata, localData, reportInfo, reportId);
this.ReturnTOTA.TotaBody = new TxnReportResultViewModel<ReportResultViewModel>
{
ReportData = new ReportResultViewModel
{
ConversationId = r.ConversationId,
Unid = r.Unid
}
};
}
```
:::info
####轉數字
:::
```
int PAYAMT = Convert.ToInt32(temp.PAYAMT);
```
:::info
####this.ReqData,要用前端包進來的東西用的,未經ViewModel處理
:::

:::info
localData using toaData
:::
string HIGHRISK = toadata[0][0]["HIGHRISK"].ToString();

:::info
依次印多個報表
:::

:::info
資料傳回前端用
:::
H37501
:::info
toaData裡有4個不同Msgid的資料用成一個
:::

:::info
在多個toaData裡抓一個key value
傳回前端
:::

```
var target = toaData.Where(x=> x[0].ToObject<JObject>().Value<string>("vMsgID") == msgId3);
JObject jobj2 = target.ToArray()[0][0].ToObject<JObject>();
object txnData = new { DEBT3 = jobj2["DEBT3"] };
```
:::info

:::
:::info
產報表也顯示畫面時,第二次傳回值會壞掉
要重新轉型一次
:::
```
var _titaBody2 = JsonConvert.DeserializeObject(titaModel.TitaBody.ToString()); // 解第二次回傳資料格式不同
titaModel.TitaBody = _titaBody2; // 替換TitaBody
```
:::info
顯示畫面又印報表,要加按鈕
:::
```
var reportInfoVModel = new ReportInfoViewModel()
{
NextPageMode = NextPageModeEnum.Auto,
AvailableButtons = AvailableButtonsEnum.R
};
this.ComplexReport = this.CreateComplexReportService(reportID, reportInfoVModel, "", "");
```
:::info
SimpleReport have tota and localData
:::
```
public class TxnLogic : SimpleReportBase
{
public TxnLogic(ILogHelper logHelper, IConfigHelper configHelper, PlatFormEnum platFormEnum, IMapper mapper) : base(logHelper, configHelper, platFormEnum, mapper)
{
}
protected override bool IsWait => true;
protected override void Builder(TitaViewModel titaModel, JArray[] toaData)
{
foreach (var jArray in toaData)
{
//取 toa 資料
JObject jObj = jArray[0].ToObject<JObject>();
var msgId = jObj.Value<string>("vMsgID");
if (msgId == "H37443O1")
{
var todata = ColumnViewModelUtil.FromJson(jObj, msgId);
string reportId = "H37443R1";
//取 data 資料
var localData = GetLocalData(titaModel, toaData);
var reportInfo = new ReportInfoViewModel();
ReportResultViewModel r = this.GenerateSimpleReport(todata, localData.ToArray(), reportInfo, reportId);
this.ReturnTOTA.TotaBody = new TxnReportResultViewModel<ReportResultViewModel>
{
ReportData = new ReportResultViewModel
{
ConversationId = r.ConversationId,
Unid = r.Unid
}
};
}
}
}
private List<ColumnViewModel> GetLocalData(TitaViewModel tita, JArray[] toaData)
{
var NBANKAMT = tita.TitaBody["NBANKAMT"];
List<ColumnViewModel> loVar = new List<ColumnViewModel>();
loVar.Add(new ColumnViewModel
{
Type = "P_NBANKAMT",
Value = NBANKAMT
});
return loVar;
}
}
```
:::info
SimpleReport have no tota and localData
:::
```
public class TxnLogic : SimpleReportBase
{
public TxnLogic(ILogHelper logHelper, IConfigHelper configHelper, PlatFormEnum platFormEnum, IMapper mapper) : base(logHelper, configHelper, platFormEnum, mapper)
{
}
protected override bool IsWait => true;
protected override void Builder(TitaViewModel titaModel, JArray[] toaData)
{
var toadata = new ColumnViewModel[] { };
string reportId = "H37443R1";
var reportInfo = new ReportInfoViewModel();
var localData = GetLocalData(titaModel, toaData);
ReportResultViewModel r = this.GenerateSimpleReport(toadata, localData.ToArray(), reportInfo, reportId);
this.ReturnTOTA.TotaBody = new TxnReportResultViewModel<ReportResultViewModel>
{
ReportData = new ReportResultViewModel
{
ConversationId = r.ConversationId,
Unid = r.Unid
}
};
}
private List<ColumnViewModel> GetLocalData(TitaViewModel tita, JArray[] toaData)
{
var NBANKAMT = tita.TitaBody["NBANKAMT"];
List<ColumnViewModel> loVar = new List<ColumnViewModel>();
loVar.Add(new ColumnViewModel
{
Type = "P_NBANKAMT",
Value = NBANKAMT
});
return loVar;
}
}
```
:::info
顯示加列印報表
:::
```
//Startup
namespace PSTHL.H77705
{
public class Startup
{
public Startup()
{
}
/// <summary>
/// 程式進入點
/// </summary>
/// <param name="reqData"></param>
/// <returns>TotaBody內會有一個Unid,前端需再透過API匯出報表</returns>
public async Task<TotaViewModel> RunBiz(TitaViewModel reqData)
{
try
{
#region 建立固定項目(log, config, db connection等等)
var titaHeader = reqData.TitaHeader;
var container = IocUtil.CreateContainer()
.AddPlatForm(PlatFormEnum.Saving)
.AddTxnLocalConfigHelper(titaHeader)
.SetDapperHelper(PlatFormEnum.Saving)
.RegisterTxnLogic(typeof(Startup));
#endregion 建立固定項目(log, config, db connection等等)
// 執行交易主邏輯
string caseName = reqData.TitaHeader.CaseName;
string buttonType = reqData.TitaBody["ButtonType"];
ITxnLogic txnLogic;
//H77705R1 H77705O1
switch (buttonType)
{
case "R":
txnLogic = container.ResolveTxnLogic("H77705R1");
break;
default:
txnLogic = container.ResolveTxnLogic("H77705O1");
break;
}
TotaViewModel result = await txnLogic.Run(reqData);
return result;
}
catch (System.Exception ex)
{
throw ex;
}
}
}
}
//
```