這一篇主要介紹,如何保存實(shí)體數(shù)據(jù)。具體內(nèi)容如下所示;
一,xml樣例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
<?xml version= "1.0" encoding= "GBK" ?> <!-- 1 .. 1 --> <cisReports batNo= "查詢批次號(hào)" unitName= "查詢單位名稱" subOrgan= "分支機(jī)構(gòu)名稱" queryUserID= "查詢操作員登錄名" queryCount= "查詢請(qǐng)求數(shù)量" receiveTime= "查詢申請(qǐng)時(shí)間,格式Y(jié)YYYMMDD HH24:mm:ss" > <!-- 以下為每個(gè)查詢申請(qǐng)的查詢結(jié)果 1 ..n --> <cisReport reportID= "報(bào)告編號(hào)" buildEndTime= "報(bào)告生成結(jié)束時(shí)間,格式Y(jié)YYY-MM-DD HH24:mm:ss" queryReasonID= "查詢?cè)騃D,詳見(jiàn)數(shù)據(jù)字典" subReportTypes= "查詢的收費(fèi)子報(bào)告ID,多個(gè)收費(fèi)子報(bào)告ID用逗號(hào)分隔" treatResult= "對(duì)應(yīng)的收費(fèi)子報(bào)告收費(fèi)次數(shù),與subReportTypes一一對(duì)應(yīng),為大于等于0的值的集合,用逗號(hào)分隔" subReportTypesShortCaption= "查詢的收費(fèi)子報(bào)告中文名稱 " refID= "引用ID,為查詢申請(qǐng)條件中的引用ID" hasSystemError= "有否系統(tǒng)錯(cuò)誤,true:有錯(cuò)誤,false:無(wú)錯(cuò)誤" isFrozen= "該客戶是否被凍結(jié),true:被凍結(jié),false:未被凍結(jié)" > <!-- 1 查詢條件信息 1 .. 1 --> <queryConditions> <!-- 1 ..n --> <item> <name>查詢條件英文名稱</name> <caption>查詢條件中文名稱</caption> <value>查詢條件值</value> </item> </queryConditions> <!-- 2 身份認(rèn)證 1 .. 1 --> <policeCheckInfo subReportType= "10602" subReportTypeCost= "96040" treatResult= "子報(bào)告查詢狀態(tài),1:查得,2:未查得,3:其他原因未查得" treatErrorCode = "treatResult=3時(shí)的錯(cuò)誤代碼,詳見(jiàn)數(shù)據(jù)字典,treatResult!=3時(shí),該屬性不存在" errorMessage= "treatResult=3時(shí)的錯(cuò)誤描述信息,treatResult!=3時(shí),該屬性的值為空" > <item> <name>被查詢者姓名</name> <documentNo>被查詢者證件號(hào)碼</documentNo> <!-- 1 ,一致 2 ,不一致 treatResult為 3 時(shí)為空--> <result>身份認(rèn)證結(jié)果, 1 ,一致 2 ,不一致</result> </item> </policeCheckInfo> <!-- 3 個(gè)人手機(jī)號(hào)碼核查 1 .. 1 --> <mobileCheckInfo subReportType= "13612" subReportTypeCost= "96040" treatResult= "子報(bào)告查詢狀態(tài),1:查得,2:未查得,3:其他原因未查得" treatErrorCode= "treatResult=3時(shí)的錯(cuò)誤代碼,詳見(jiàn)數(shù)據(jù)字典,treatResult!=3時(shí),該屬性不存在" errorMessage= "treatResult=3時(shí)的錯(cuò)誤描述信息,treatResult!=3時(shí),該屬性的值為空" > <!--treatresult為 2 、 3 時(shí)沒(méi)有以下節(jié)點(diǎn)--> <item> <nameCheckResult>姓名核查結(jié)果,有:一致、基本一致、不一致、無(wú)法核查 </nameCheckResult> <documentNoCheckResult>證件號(hào)碼核查結(jié)果,有:一致、不一致、無(wú)法核查 </documentNoCheckResult> <phoneCheckResult>手機(jī)號(hào)碼核查結(jié)果:一致、無(wú)法核查 </phoneCheckResult> <areaInfo>號(hào)碼歸屬地</areaInfo> <operator>運(yùn)營(yíng)商 1 :中國(guó)電信 2 :中國(guó)移動(dòng) 3 :中國(guó)聯(lián)通 </operator> </item> </mobileCheckInfo> <!-- 4 個(gè)人反欺詐風(fēng)險(xiǎn)綜述信息 1 .. 1 --> <personAntiSpoofingDescInfo subReportType= "14225" subReportTypeCost= "96040" treatResult= "子報(bào)告查詢狀態(tài),1:查得,2:未查得,3:其他原因未查得" treatErrorCode= "treatResult=3時(shí)的錯(cuò)誤代碼,詳見(jiàn)數(shù)據(jù)字典,treatsult!=3時(shí),該屬性不存在" errorMessage= "treatResult=3時(shí)的錯(cuò)誤描述信息,treatResult!=3時(shí),該屬性的值為空" > <!--treatresult為 2 時(shí)沒(méi)有以下節(jié)點(diǎn)--> <!-- 個(gè)人反欺詐綜述信息。如以下例子,可能為空,可能存在其中 0 條或n條,根據(jù)具體結(jié)果返回。 1 、 反欺詐風(fēng)險(xiǎn)評(píng)分為 100 分,風(fēng)險(xiǎn)等級(jí)為高,建議拒絕。 2 、 電信手機(jī)號(hào)碼 131 **** 1542 使用不足 1 個(gè)月。 3 、 命中羊毛黨名單。 4 、 命中欺詐風(fēng)險(xiǎn)名單。 5 、 命中高風(fēng)險(xiǎn)人員名單。 6 、 存在 7 筆逾期的信貸記錄。 7 、 存在 40 條個(gè)人風(fēng)險(xiǎn)概要信息。 8 、 在近兩年被機(jī)構(gòu)查詢過(guò) 23 次個(gè)人信息。 --> <personAntiSpoofingDesc>個(gè)人反欺詐綜述信息</personAntiSpoofingDesc> </personAntiSpoofingDescInfo> <!-- 5 個(gè)人反欺詐風(fēng)險(xiǎn)評(píng)分信息 1 .. 1 --> <personAntiSpoofingInfo subReportType= "14224" subReportTypeCost= "96040" treatResult= "子報(bào)告查詢狀態(tài),1:查得,2:未查得,3:其他原因未查得" treatErrorCode= "treatResult=3時(shí)的錯(cuò)誤代碼,詳見(jiàn)數(shù)據(jù)字典,treatResult!=3時(shí),該屬性不存在" errorMessage= "treatResult=3時(shí)的錯(cuò)誤描述信息,treatResult!=3時(shí),該屬性的值為空" > <!--treatresult為 2 、 3 時(shí)沒(méi)有以下節(jié)點(diǎn)--> <riskScore>風(fēng)險(xiǎn)評(píng)分</riskScore> <riskLevel>風(fēng)險(xiǎn)等級(jí),取值:高,中度,低</riskLevel> <suggest>風(fēng)險(xiǎn)建議,取值:建議拒絕,建議復(fù)核,建議通過(guò)</suggest> <hitTypes>命中類型:高風(fēng)險(xiǎn)名單、個(gè)人風(fēng)險(xiǎn)信息、信貸逾期名單、被機(jī)構(gòu)查詢信息、手機(jī)號(hào)碼狀態(tài)異常、手機(jī)號(hào)碼低網(wǎng)齡、羊毛黨名單、欺詐風(fēng)險(xiǎn)名單等等,可能為 1 個(gè)或多個(gè)</hitTypes> </personAntiSpoofingInfo> <!-- 6 手機(jī)號(hào)碼狀態(tài)信息 1 .. 1 --> <mobileStatusInfo subReportType= "13611" subReportTypeCost= "96040" treatResult= "子報(bào)告查詢狀態(tài),1:查得,2:未查得,3:其他原因未查得" treatErrorCode= "treatResult=3時(shí)的錯(cuò)誤代碼,詳見(jiàn)數(shù)據(jù)字典,treatResult!=3時(shí),該屬性不存在" errorMessage= "treatResult=3時(shí)的錯(cuò)誤描述信息,treatResult!=3時(shí),該屬性的值為空" > <!--treatresult為 2 、 3 時(shí)沒(méi)有以下節(jié)點(diǎn)--> <item> <operator>運(yùn)營(yíng)商 1 :中國(guó)電信 2 :中國(guó)移動(dòng) 3 :中國(guó)聯(lián)通 </operator> <areaInfo>手機(jī)號(hào)碼歸屬地 </areaInfo> <phoneStatus>手機(jī)狀態(tài) 1 :正常在用 2 : 停機(jī) 3 :未啟用 4 :已銷號(hào) 5 -其他 6 :預(yù)銷號(hào)</phoneStatus> <timeLength>手機(jī)號(hào)碼在網(wǎng)時(shí)長(zhǎng),如:在網(wǎng)時(shí)長(zhǎng)不足 1 個(gè)月, 1 - 2 個(gè)月, 3 - 6 個(gè)月, 7 - 12 個(gè)月 </timeLength> <cancelTime>號(hào)碼注銷時(shí)間</cancelTime> </item> </mobileStatusInfo> <!-- 7 是否命中羊毛黨名單 1 .. 1 --> <econnoisserurInfo subReportType= "14228" subReportTypeCost= "96040" treatResult= "子報(bào)告查詢狀態(tài),1:查得,2:未查得,3:其他原因未查得" treatErrorCode= "treatResult=3時(shí)的錯(cuò)誤代碼,詳見(jiàn)數(shù)據(jù)字典,treatResult!=3時(shí),該屬性不存在" errorMessage= "treatResult=3時(shí)的錯(cuò)誤描述信息,treatResult!=3時(shí),該屬性的值為空" > <!--treatresult為 2 、 3 時(shí)沒(méi)有以下節(jié)點(diǎn)--> <state>是否命中羊毛黨名單,取值: 0 / 1 , 0 表示未命中羊毛黨名單, 1 表示命中羊毛黨名單</state> </econnoisserurInfo> <!-- 8 是否命中欺詐風(fēng)險(xiǎn)名單 1 .. 1 --> <fraudRiskInfo subReportType= "14229" subReportTypeCost= "96040" treatResult= "子報(bào)告查詢狀態(tài),1:查得,2:未查得,3:其他原因未查得" treatErrorCode= "treatResult=3時(shí)的錯(cuò)誤代碼,詳見(jiàn)數(shù)據(jù)字典,treatResult!=3時(shí),該屬性不存在" errorMessage= "treatResult=3時(shí)的錯(cuò)誤描述信息,treatResult!=3時(shí),該屬性的值為空" > <!--treatresult為 2 、 3 時(shí)沒(méi)有以下節(jié)點(diǎn)--> <state>是否命中欺詐風(fēng)險(xiǎn)名單,取值: 0 / 1 , 0 表示未命中欺詐風(fēng)險(xiǎn)名單, 1 表示命中欺詐風(fēng)險(xiǎn)名單</state> </fraudRiskInfo> <!-- 9 是否命中高風(fēng)險(xiǎn)名單 1 .. 1 --> <personRiskAssess subReportType= "14226" subReportTypeCost= "96040" treatResult= "子報(bào)告查詢狀態(tài),1:查得,2:未查得,3:其他原因未查得" treatErrorCode= "treatResult=3時(shí)的錯(cuò)誤代碼,詳見(jiàn)數(shù)據(jù)字典,treatResult!=3時(shí),該屬性不存在" errorMessage= "treatResult=3時(shí)的錯(cuò)誤描述信息,treatResult!=3時(shí),該屬性的值為空" > <!--treatresult為 2 、 3 時(shí)沒(méi)有以下節(jié)點(diǎn)--> <checkResult>是否命中高風(fēng)險(xiǎn)名單 1 :是, 2 :否</checkResult> </personRiskAssess> <!-- 10 網(wǎng)貸逾期信息 1 .. 1 --> <microNearlyThreeYearsOverdueInfo subReportType= "13204" subReportTypeCost= "96040" treatResult= "子報(bào)告查詢狀態(tài),1:查得,2:未查得,3:其他原因未查得" treatErrorCode= "treatResult=3時(shí)的錯(cuò)誤代碼,詳見(jiàn)數(shù)據(jù)字典,treatResult!=3時(shí),該屬性不存在" errorMessage= "treatResult=3時(shí)的錯(cuò)誤描述信息,treatResult!=3時(shí),該屬性的值為空" > <!--treatresult為 2 、 3 時(shí)沒(méi)有以下節(jié)點(diǎn)--> <!--逾期匯總信息 0 .. 1 --> <stat> <overdueAmount>逾期本金,單位:以貸款基本信息的幣種為準(zhǔn)</overdueAmount> <overdueDays>逾期天數(shù)區(qū)間,取值區(qū)間:逾期 1 天(含)以上</overdueDays> <overdueCount>逾期天數(shù)區(qū)間的總筆數(shù)</overdueCount> </stat> <!-- 0 .. 1 --> <items> <!--逾期概要信息 1 .. 5 多個(gè)記錄--> <item> <overdueAmount>逾期本金,單位:以貸款基本信息的幣種為準(zhǔn)</overdueAmount> <overdueDays>逾期天數(shù)區(qū)間,取值區(qū)間:逾期 1 - 6 天,逾期 7 - 29 天,逾期 30 - 59 天,逾期 60 - 89 天,逾期 90 天(含)以上</overdueDays> <overdueCount>逾期天數(shù)區(qū)間的筆數(shù)</overdueCount> </item> </items> </microNearlyThreeYearsOverdueInfo> <!-- 11 風(fēng)險(xiǎn)信息 1 .. 1 --> <personRiskInfo subReportType= "14227" subReportTypeCost= "96040" treatResult= "子報(bào)告查詢狀態(tài),1:查得,2:未查得,3:其他原因未查得" treatErrorCode= "treatResult=3時(shí)的錯(cuò)誤代碼,詳見(jiàn)數(shù)據(jù)字典,treatResult!=3時(shí),該屬性不存在" errorMessage= "treatResult=3時(shí)的錯(cuò)誤描述信息,treatResult!=3時(shí),該屬性的值為空" > <!--treatresult為 2 、 3 時(shí)沒(méi)有以下節(jié)點(diǎn)--> <!-- 匯總信息 0 .. 1 --> <stat> <totleCount>概要匯總條數(shù)</totleCount> <alCount>司法案例信息條數(shù)</alCount> <zxCount>司法執(zhí)行信息條數(shù)</zxCount> <sxCount>司法失信信息條數(shù)</sxCount> <swCount>稅務(wù)行政執(zhí)法信息條數(shù)</swCount> <cqggCount>催欠公告信息條數(shù)</cqggCount> <wdyqCount>網(wǎng)貸逾期信息條數(shù)</wdyqCount> </stat> <!-- 匯總信息 end--> <!-- 概要信息 0 .. 1 --> <summary> <!-- 司法案例信息概要信息 0 .. 1 --> <als> <!-- 司法案例信息概要信息內(nèi)容 1 ..n --> <item> <recordId>記錄編號(hào)</recordId> <bt>標(biāo)題</bt> <ajlx>案件類型</ajlx> <sjnf>審結(jié)年份,格式:YYYY</sjnf> <dsrlx>當(dāng)事人類型</dsrlx> </item> </als> <!-- 司法執(zhí)行信息概要信息 0 .. 1 --> <zxs> <!-- 司法執(zhí)行信息概要信息內(nèi)容 1 ..n --> <item> <recordId>記錄編號(hào)</recordId> <bt>標(biāo)題</bt> <zxbd>執(zhí)行標(biāo)的,單位:以幣種為準(zhǔn)</zxbd> <larq>立案日期,格式Y(jié)YYY-MM-DD</larq> </item> </zxs> <!-- 司法失信信息概要信息 0 .. 1 --> <sxs> <!-- 司法失信信息概要信息內(nèi)容 1 ..n --> <item> <recordId>記錄編號(hào)</recordId> <bt>標(biāo)題</bt> <larq>立案日期,格式Y(jié)YYY-MM-DD</larq> <fbrq>發(fā)布日期,格式Y(jié)YYY-MM-DD</fbrq> </item> </sxs> <!-- 稅務(wù)行政執(zhí)法信息概要信息 0 .. 1 --> <sws> <!-- 稅務(wù)行政執(zhí)法信息概要信息內(nèi)容 1 ..n --> <item> <recordId>記錄編號(hào)</recordId> <bt>標(biāo)題</bt> <ggrq>公告日期,格式Y(jié)YYY-MM-DD</ggrq> </item> </sws> <!-- >催欠公告信息概要信息 0 .. 1 --> <cqs> <!-- 催欠公告信息概要信息內(nèi)容 1 ..n --> <item> <recordId>記錄編號(hào)</recordId> <bt>標(biāo)題</bt> <fbrq>發(fā)布日期,格式Y(jié)YYY-MM-DD</fbrq> </item> </cqs> <!-- 網(wǎng)貸逾期信息概要信息 0 .. 1 --> <wdyqs> <!-- 網(wǎng)貸逾期信息概要信息內(nèi)容 1 ..n --> <item> <recordId>記錄編號(hào)</recordId> <bt>標(biāo)題</bt> <fbrq>發(fā)布日期,格式Y(jié)YYY-MM-DD</fbrq> </item> </wdyqs> </summary> </personRiskInfo> <!-- 12 個(gè)人近兩年歷史查詢記錄 1 .. 1 --> <historySimpleQueryInfo subReportType= "19902" subReportTypeCost= "96040" treatResult= "子報(bào)告查詢狀態(tài),1:查得,2:未查得,3:其他原因未查得" treatErrorCode= "treatResult=3時(shí)的錯(cuò)誤代碼,詳見(jiàn)數(shù)據(jù)字典,treatResult!=3時(shí),該屬性不存在" errorMessage= "treatResult=3時(shí)的錯(cuò)誤描述信息,treatResult!=3時(shí),該屬性的值為空" > <!--treatresult為 2 、 3 時(shí)沒(méi)有以下節(jié)點(diǎn)--> <!-- 0 .. 1 --> <items> <!-- 1 ..n --> <item> <unitMember>單位類型名稱</unitMember> <last1Month>近 1 個(gè)月查詢記錄數(shù)</last1Month> <last3Month>近 3 個(gè)月查詢記錄數(shù)</last3Month> <last6Month>近 6 個(gè)月查詢記錄數(shù)</last6Month> <last12Month>近 12 個(gè)月查詢記錄數(shù)</last12Month> <last18Month>近 18 月查詢記錄數(shù)</last18Month> <last24Month>近 24 月查詢記錄數(shù)</last24Month> </item> </items> <!-- 0 .. 1 --> <count> <last1Month>近 1 個(gè)月各單位類型查詢記錄總數(shù)</last1Month> <last3Month>近 3 個(gè)月各單位類型查詢記錄總數(shù)</last3Month> <last6Month>近 6 個(gè)月各單位類型查詢記錄總數(shù)</last6Month> <last12Month>近 12 個(gè)月各單位類型查詢記錄總數(shù)</last12Month> <last18Month>近 18 月各單位類型查詢記錄總數(shù)</last18Month> <last24Month>近 24 月各單位類型查詢記錄總數(shù)</last24Month> </count> </historySimpleQueryInfo> </cisReport> </cisReports> |
二,表結(jié)構(gòu)設(shè)計(jì)
1,批次號(hào):各表之間用最外層批次號(hào)關(guān)聯(lián)。
2,主表:即把各層字段全部存在一個(gè)表中。
三,實(shí)體設(shè)計(jì)
分為三層:CisReportRoot ,CisReportChild ,ReportElement
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
public class CisReportRoot extends BasePojo implements Serializable { private String docId; private String batNo; //查詢批次號(hào) @JSONField (serialize = false ) private String xmlId; private CisReportChild cisReportChild; /** * 2017/7/21. * 報(bào)告節(jié)點(diǎn)屬性以及子節(jié)點(diǎn) */ public class CisReportChild extends BasePojo { /** * 報(bào)告生成結(jié)束時(shí)間 **/ private String buildEndTime; /** * 是否有系統(tǒng)錯(cuò)誤 true表示有 false表示沒(méi)有 **/ private String hasSystemError; /** * 該客戶是否被凍結(jié) **/ private String isFrozen; private ReportElement reportElement; public class ReportElement extends BasePojo { private String phone; private PoliceCheckInfo policeCheckInfo; //身份認(rèn)證 private MobileCheckInfo mobileCheckInfo; //個(gè)人手機(jī)號(hào)碼核查 private PersonAntiSpoofingDescInfo personAntiSpoofingDescInfo; //個(gè)人反欺詐風(fēng)險(xiǎn)綜述信息 private PersonAntiSpoofingInfo personAntiSpoofingInfo; //個(gè)人反欺詐風(fēng)險(xiǎn)評(píng)分信息 private MobileStatusInfo mobileStatusInfo; //手機(jī)號(hào)碼狀態(tài)信息 private EconnoisserurInfo econnoisserurInfo; //是否命中羊毛黨名單 private FraudRiskInfo fraudRiskInfo; //是否命中欺詐風(fēng)險(xiǎn)名單 private PersonRiskAssess personRiskAssess; //是否命中高風(fēng)險(xiǎn)名單 private MicroNearlyThreeYearsOverdueInfo microNearlyThreeYearsOverdueInfo; //網(wǎng)貸逾期信息 private PersonRiskInfo personRiskInfo; //風(fēng)險(xiǎn)信息 private HistorySimpleQueryInfo historySimpleQueryInfo; //個(gè)人近兩年歷史查詢記錄 |
四,代碼
<1>單筆,批量無(wú)需主鍵
無(wú)論單筆還是批量都可以把數(shù)據(jù)存在map中,sql中通過(guò)map的鍵獲取數(shù)據(jù)。
如:
1
2
3
4
5
6
7
8
9
10
11
|
private void savePersonRiskInfo(String batNo, PersonRiskInfo personRiskInfo) throws Exception { Map<String, Object> map = new HashMap<>(); map.put( "batNo" , batNo); //單筆 map.put( "item" , personRiskInfo); pyMapper.savePersonRiskInfo(map); if (!ListUtil.isEmpty(personRiskInfo.getAlList())) { //批量 map.put( "list" , personRiskInfo.getAlList()); pyMapper.saveAlInfoList(map); } |
sql:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
<!--個(gè)人風(fēng)險(xiǎn)記錄 --> //單筆 <insert id= "savePersonRiskInfo" parameterType= "java.util.Map" > INSERT INTO TABLE_PERSON_RISK_INFO(BATNO,TOTLECOUNT,ALCOUNT,ZXCOUNT,SXCOUNT,SWCOUNT,CQGGCOUNT,WDYQCOUNT) VALUES (#{batNo,jdbcType=VARCHAR}, #{item.totleCount,jdbcType=NUMERIC}, #{item.alCount,jdbcType=NUMERIC},#{item.zxCount,jdbcType=NUMERIC},#{item.sxCount,jdbcType=NUMERIC}, #{item.swCount,jdbcType=NUMERIC},#{item.cqggCount,jdbcType=NUMERIC},#{item.wdyqCount,jdbcType=NUMERIC}) </insert> <!--逾期詳細(xì)記錄 --> //批量 <insert id= "saveMicroNearlyThreeYearsOverdueInfoList" parameterType= "java.util.Map" > INSERT INTO TABLE_MNTYOI (BATNO,OVERDUEAMOUNT,OVERDUEDAYS,OVERDUECOUNT) <foreach collection= "list" item= "item" separator= "union all" > ( SELECT #{batNo,jdbcType=VARCHAR}, #{item.overdueAmount,jdbcType=VARCHAR}, #{item.overdueDays,jdbcType=VARCHAR}, #{item.overdueCount,jdbcType=NUMERIC} FROM DUAL ) </foreach> </insert> private CisReportRoot invokePy(PyQueryBean pyQueryBean) throws Exception { pyQueryBean.setQueryFromPy(QUERY_FROM_PY); //call py service CisReportRoot cisReportRoot = queryCisReportFromPyServer(pyQueryBean); cisReportRoot.getCisReportChild().getReportElement().setPhone(pyQueryBean.getPhone()); //cacheService.save(cisReportRoot); //(1)保存數(shù)據(jù) saveCisReport(cisReportRoot); return cisReportRoot; } |
(1)保存數(shù)據(jù)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
@Transactional (rollbackFor = Exception. class ) @Override public CisReportRoot saveCisReport(CisReportRoot cisReportRoot) throws Exception { try { ReportElement reportElement = cisReportRoot.getCisReportChild().getReportElement(); PersonRiskInfo personRiskInfo = reportElement.getPersonRiskInfo(); //(2)主表,保存xml所有節(jié)點(diǎn)信息(不包含個(gè)人風(fēng)險(xiǎn)信息),保存單筆數(shù)據(jù) pyMapper.saveCisReport(cisReportRoot); if (SUCCESS.equals(cisReportRoot.getCisReportChild().getReportElement().getPersonRiskInfo().getTreatResult())) { savePersonRiskInfo(cisReportRoot.getBatNo(), personRiskInfo); } if (cisReportRoot.getCisReportChild().getReportElement().getHistorySimpleQueryInfo().getTreatResult().equals(SUCCESS)) { Map<String, Object> map = new HashMap<>(); //(3)保存批量數(shù)據(jù) map.put( "batNo" , cisReportRoot.getBatNo()); if (!ListUtil.isEmpty(cisReportRoot.getCisReportChild().getReportElement().getHistorySimpleQueryInfo().getItemList())) { map.put( "list" , cisReportRoot.getCisReportChild().getReportElement().getHistorySimpleQueryInfo().getItemList()); pyMapper.saveHistorySimpleQueryInfoList(map); } if (!ListUtil.isEmpty(cisReportRoot.getCisReportChild().getReportElement().getMicroNearlyThreeYearsOverdueInfo().getList())) { map.put( "list" , cisReportRoot.getCisReportChild().getReportElement().getMicroNearlyThreeYearsOverdueInfo().getList()); pyMapper.saveMicroNearlyThreeYearsOverdueInfoList(map); } } return cisReportRoot; } catch (Exception e) { logger.error( "saveCisReport@PyserviceImpl_Exception" , e); throw e; } } |
(2)保存主表
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
<insert id= "saveCisReport" parameterType= "java.util.Map" > INSERT INTO TABLE_CISREPORT (BATNO,BUILDENDTIME,ISFROZEN, MCI_NAMECHECKRESULT,MCI_AREAINFO,MCI_DOCUMENTNOCHECKRESULT,MCI_OPERATOR,MCI_PHONECHECKRESULT, PCI_DOCUMENTNO,PCI_NAME,PCI_RESULT, PASDI_DESC, PASI_HITTYPES,PASI_RISKLEVEL,PASI_RISKSCORE,PASI_RISKSUGGEST, MS_AREAINFO,MS_CAnCELTIME,MS_OPERATOR,MS_PHONESTATUS,MS_TIMELENGTH, ECONNOISSERUR, FRAUDRISK, PRA_CHECKRESULT, MNTYOI_OVERDUEAMOUNT,MNTYOI_OVERDUECOUNT,MNTYOI_OVERDUEDAYS, HS_LAST1MONTH,HS_LAST3MONTH,HS_LAST6MONTH,HS_LAST12MONTH,HS_LAST18MONTH,HS_LAST24MONTH, PHONE,XMLID) VALUES (#{batNo,jdbcType=VARCHAR}, to_date(#{cisReportChild.buildEndTime}, 'yyyy-MM-dd hh24:mi:ss' ), #{cisReportChild.isFrozen,jdbcType=VARCHAR}, #{cisReportChild.reportElement.mobileCheckInfo.nameCheckResult,jdbcType=VARCHAR}, #{cisReportChild.reportElement.mobileCheckInfo.areaInfo,jdbcType=VARCHAR}, #{cisReportChild.reportElement.mobileCheckInfo.documentNoCheckResult,jdbcType=VARCHAR}, #{cisReportChild.reportElement.mobileCheckInfo.operator,jdbcType=NUMERIC}, #{cisReportChild.reportElement.mobileCheckInfo.phoneCheckResult,jdbcType=VARCHAR}, #{cisReportChild.reportElement.policeCheckInfo.documentNo,jdbcType=VARCHAR}, #{cisReportChild.reportElement.policeCheckInfo.name,jdbcType=VARCHAR}, #{cisReportChild.reportElement.policeCheckInfo.result,jdbcType=NUMERIC}, #{cisReportChild.reportElement.personAntiSpoofingDescInfo.personAntiSpoofingDesc,jdbcType=VARCHAR}, #{cisReportChild.reportElement.personAntiSpoofingInfo.hitTypes,jdbcType=VARCHAR}, #{cisReportChild.reportElement.personAntiSpoofingInfo.riskLevel,jdbcType=VARCHAR}, #{cisReportChild.reportElement.personAntiSpoofingInfo.riskScore,jdbcType=VARCHAR}, #{cisReportChild.reportElement.personAntiSpoofingInfo.suggest,jdbcType=VARCHAR}, #{cisReportChild.reportElement.mobileStatusInfo.areaInfo,jdbcType=VARCHAR}, #{cisReportChild.reportElement.mobileStatusInfo.cancelTime,jdbcType=VARCHAR}, #{cisReportChild.reportElement.mobileStatusInfo.operator,jdbcType=NUMERIC}, #{cisReportChild.reportElement.mobileStatusInfo.phoneStatus,jdbcType=NUMERIC}, #{cisReportChild.reportElement.mobileStatusInfo.timeLength,jdbcType=VARCHAR}, #{cisReportChild.reportElement.econnoisserurInfo.state,jdbcType=NUMERIC}, #{cisReportChild.reportElement.fraudRiskInfo.state,jdbcType=NUMERIC}, #{cisReportChild.reportElement.personRiskAssess.checkResult,jdbcType=NUMERIC}, #{cisReportChild.reportElement.microNearlyThreeYearsOverdueInfo.overdueAmount,jdbcType=VARCHAR}, #{cisReportChild.reportElement.microNearlyThreeYearsOverdueInfo.overdueCount,jdbcType=NUMERIC}, #{cisReportChild.reportElement.microNearlyThreeYearsOverdueInfo.overdueDays,jdbcType=VARCHAR}, #{cisReportChild.reportElement.historySimpleQueryInfo.totalCount.last1Month,jdbcType=NUMERIC}, #{cisReportChild.reportElement.historySimpleQueryInfo.totalCount.last3Month,jdbcType=NUMERIC}, #{cisReportChild.reportElement.historySimpleQueryInfo.totalCount.last6Month,jdbcType=NUMERIC}, #{cisReportChild.reportElement.historySimpleQueryInfo.totalCount.last12Month,jdbcType=NUMERIC}, #{cisReportChild.reportElement.historySimpleQueryInfo.totalCount.last18Month,jdbcType=NUMERIC}, #{cisReportChild.reportElement.historySimpleQueryInfo.totalCount.last24Month,jdbcType=NUMERIC}, #{cisReportChild.reportElement.phone,jdbcType=VARCHAR}, #{xmlId,jdbcType=VARCHAR} ) |
(3)保存批量數(shù)據(jù)(不自動(dòng)生成主鍵)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<!--個(gè)人近兩年歷史查詢記錄 --> <insert id= "saveHistorySimpleQueryInfoList" parameterType= "java.util.Map" > INSERT INTO TABLE_HISTORY_SIMPLE_QUERY (BATNO,UNIT_MEMBER,LAST1MONTH,LAST3MONTH,LAST6MONTH,LAST12MONTH,LAST18MONTH,LAST24MONTH) <foreach collection= "list" item= "item" separator= "union all" > ( SELECT #{batNo,jdbcType=VARCHAR}, #{item.unitMember,jdbcType=VARCHAR}, #{item.last1Month,jdbcType=NUMERIC},#{item.last3Month,jdbcType=NUMERIC}, #{item.last6Month,jdbcType=NUMERIC},#{item.last12Month,jdbcType=NUMERIC}, #{item.last18Month,jdbcType=NUMERIC},#{item.last24Month,jdbcType=NUMERIC} FROM DUAL ) </foreach> </insert> |
<2>單筆,批量需要插入主鍵
單筆含主鍵
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
DataServiceDetailResult dataServiceDetailResult = tdService.getDataServiceDetailResult(tdReportRoot); int n = tdDataServiceMapper.insertDataServiceDetailResult(dataServiceDetailResult); <!--信息核驗(yàn)接口--> <!--DATASERVICE--> <insert id= "insertDataServiceDetailResult" parameterType= "DataServiceDetailResult" > <selectKey keyProperty= "id" resultType= "BigDecimal" order= "BEFORE" > select SEQ_ICS_TD_DATASERVICE.nextval as id from dual </selectKey> insert into ICS_TD_DATASERVICE (ID, RECORDID, REASON_DESC, REASON_CODE, SUCCESS) values (#{id,jdbcType=DECIMAL}, #{recordId,jdbcType=DECIMAL}, #{reasonDesc,jdbcType=VARCHAR}, #{reasonCode,jdbcType=VARCHAR}, #{success,jdbcType=DECIMAL}) </insert> |
批量保存包含主鍵
1
2
3
4
5
|
if (!ListUtil.isEmpty(interfacesList)) { map.put( "recordId" , id); map.put( "list" , interfacesList); tdDataServiceMapper.addBatchInterfaces(map); } |
sql:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
<!--批量保存interfaces--> <insert id= "addBatchInterfaces" parameterType= "java.util.List" > <!-- 注釋為mysql插入方式,可以插入但是導(dǎo)致數(shù)據(jù)回滾不了 下面為oracle插入方式:注意parameterType:java.util.List或java.util.Map都可以 BEGIN <foreach collection= "list" item= "item" index= "index" separator= "" > INSERT INTO ICS_TD_INTERFACES(ID, RECORDID, TYPE) VALUES ( BLOANCRDTDATA.SEQ_ICS_TD_INTERFACES.nextval, #{recordId,jdbcType=DECIMAL}, #{item.type,jdbcType=VARCHAR} ); </foreach> COMMIT; END;--> insert into ICS_TD_INTERFACES (ID,RECORDID, TYPE) SELECT SEQ_ICS_TD_INTERFACES.nextval ID, A.* FROM( <foreach collection= "list" item= "item" index= "index" separator= "union all" > SELECT #{recordId,jdbcType=DECIMAL}, #{item.type,jdbcType=VARCHAR} FROM DUAL </foreach> ) A </insert> |
總結(jié)
以上所述是小編給大家介紹的mybatis單筆批量保存實(shí)體數(shù)據(jù)的方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)服務(wù)器之家網(wǎng)站的支持!
原文鏈接:https://www.cnblogs.com/shenkebky/archive/2018/01/18/8310658.html