mybatis單筆批量保存

来源:https://www.cnblogs.com/shenkebky/archive/2018/01/18/8310658.html
-Advertisement-
Play Games

在上一篇寫了介面調用解析返回的xml,並賦值到實體。這一篇主要介紹,如何保存實體數據。 一,xml樣例 二,表結構設計 1,批次號:各表之間用最外層批次號關聯。 2,主表:即把各層欄位全部存在一個表中。 三,實體設計 分為三層:CisReportRoot ,CisReportChild ,Repor ...


  在上一篇寫了介面調用解析返回的xml,並賦值到實體。這一篇主要介紹,如何保存實體數據。

一,xml樣例

<?xml version="1.0" encoding="GBK"?>
<!-- 1..1 -->
<cisReports batNo="查詢批次號" unitName="查詢單位名稱" subOrgan="分支機構名稱" queryUserID="查詢操作員登錄名" queryCount="查詢請求數量" receiveTime="查詢申請時間,格式YYYYMMDD HH24:mm:ss">
    <!-- 以下為每個查詢申請的查詢結果 1..n -->
    <cisReport reportID="報告編號" buildEndTime="報告生成結束時間,格式YYYY-MM-DD HH24:mm:ss" queryReasonID="查詢原因ID,詳見數據字典" subReportTypes="查詢的收費子報告ID,多個收費子報告ID用逗號分隔" treatResult="對應的收費子報告收費次數,與subReportTypes一一對應,為大於等於0的值的集合,用逗號分隔"   
    subReportTypesShortCaption="查詢的收費子報告中文名稱 " refID="引用ID,為查詢申請條件中的引用ID" hasSystemError="有否系統錯誤,true:有錯誤,false:無錯誤" 
    isFrozen="該客戶是否被凍結,true:被凍結,false:未被凍結">
        <!-- 1查詢條件信息 1..1 -->
        <queryConditions>
            <!-- 1..n -->
            <item>
                <name>查詢條件英文名稱</name>
                <caption>查詢條件中文名稱</caption>
                <value>查詢條件值</value>
            </item>
        </queryConditions>
        
        
        <!--2身份認證 1..1 -->
        <policeCheckInfo subReportType="10602" subReportTypeCost="96040" treatResult="子報告查詢狀態,1:查得,2:未查得,3:其他原因未查得" treatErrorCode ="treatResult=3時的錯誤代碼,詳見數據字典,treatResult!=3時,該屬性不存在" errorMessage="treatResult=3時的錯誤描述信息,treatResult!=3時,該屬性的值為空">
                <item>                    
                    <name>被查詢者姓名</name>
                    <documentNo>被查詢者證件號碼</documentNo>
                    <!--1,一致 2,不一致 treatResult為3時為空-->
                    <result>身份認證結果,1,一致 2,不一致</result>
                </item>
        </policeCheckInfo>
        
        <!-- 3個人手機號碼核查 1..1 -->
        <mobileCheckInfo subReportType="13612" subReportTypeCost="96040" treatResult="子報告查詢狀態,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3時的錯誤代碼,詳見數據字典,treatResult!=3時,該屬性不存在" errorMessage="treatResult=3時的錯誤描述信息,treatResult!=3時,該屬性的值為空">
                <!--treatresult為2、3時沒有以下節點-->
                <item>
                    <nameCheckResult>姓名核查結果,有:一致、基本一致、不一致、無法核查 </nameCheckResult>
                    <documentNoCheckResult>證件號碼核查結果,有:一致、不一致、無法核查 </documentNoCheckResult>
                    <phoneCheckResult>手機號碼核查結果:一致、無法核查 </phoneCheckResult>                    
                    <areaInfo>號碼歸屬地</areaInfo>
                    <operator>運營商 1:中國電信 2:中國移動 3:中國聯通 </operator>
                </item>
        </mobileCheckInfo>
        
            
        <!--4個人反欺詐風險綜述信息 1..1 -->
        <personAntiSpoofingDescInfo subReportType="14225" subReportTypeCost="96040" treatResult="子報告查詢狀態,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3時的錯誤代碼,詳見數據字典,treatsult!=3時,該屬性不存在" errorMessage="treatResult=3時的錯誤描述信息,treatResult!=3時,該屬性的值為空">
            <!--treatresult為2時沒有以下節點-->
            <!--
            個人反欺詐綜述信息。如以下例子,可能為空,可能存在其中0條或n條,根據具體結果返回。
            1、 反欺詐風險評分為100分,風險等級為高,建議拒絕。
            2、 電信手機號碼131****1542使用不足1個月。
            3、 命中羊毛黨名單。
            4、 命中欺詐風險名單。
            5、 命中高風險人員名單。
            6、 存在7筆逾期的信貸記錄。
            7、 存在40條個人風險概要信息。
            8、 在近兩年被機構查詢過23次個人信息。            
            -->            
            <personAntiSpoofingDesc>個人反欺詐綜述信息</personAntiSpoofingDesc>
        </personAntiSpoofingDescInfo>
        
        <!--5個人反欺詐風險評分信息 1..1 -->
        <personAntiSpoofingInfo subReportType="14224" subReportTypeCost="96040" treatResult="子報告查詢狀態,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3時的錯誤代碼,詳見數據字典,treatResult!=3時,該屬性不存在" errorMessage="treatResult=3時的錯誤描述信息,treatResult!=3時,該屬性的值為空">
            <!--treatresult為2、3時沒有以下節點-->
            
            <riskScore>風險評分</riskScore>
            <riskLevel>風險等級,取值:高,中度,低</riskLevel>
            <suggest>風險建議,取值:建議拒絕,建議覆核,建議通過</suggest>
            <hitTypes>命中類型:高風險名單、個人風險信息、信貸逾期名單、被機構查詢信息、手機號碼狀態異常、手機號碼低網齡、羊毛黨名單、欺詐風險名單等等,可能為1個或多個</hitTypes>
        </personAntiSpoofingInfo>
        
        <!-- 6手機號碼狀態信息 1..1 -->
        <mobileStatusInfo subReportType="13611" subReportTypeCost="96040" treatResult="子報告查詢狀態,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3時的錯誤代碼,詳見數據字典,treatResult!=3時,該屬性不存在" errorMessage="treatResult=3時的錯誤描述信息,treatResult!=3時,該屬性的值為空">
                <!--treatresult為2、3時沒有以下節點-->
                <item>
                    <operator>運營商 1:中國電信 2:中國移動 3:中國聯通 </operator>
                    <areaInfo>手機號碼歸屬地 </areaInfo>
                    <phoneStatus>手機狀態 1:正常在用 2: 停機 3:未啟用 4:已銷號 5-其他  6:預銷號</phoneStatus>
                    <timeLength>手機號碼在網時長,如:在網時長不足1個月,1-2個月,3-6個月,7-12個月 </timeLength>
                    <cancelTime>號碼註銷時間</cancelTime>
                </item>
        </mobileStatusInfo>
        
        <!--7是否命中羊毛黨名單 1..1-->
        <econnoisserurInfo subReportType="14228" subReportTypeCost="96040" treatResult="子報告查詢狀態,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3時的錯誤代碼,詳見數據字典,treatResult!=3時,該屬性不存在" errorMessage="treatResult=3時的錯誤描述信息,treatResult!=3時,該屬性的值為空">
            <!--treatresult為2、3時沒有以下節點-->
            <state>是否命中羊毛黨名單,取值:0/1,0表示未命中羊毛黨名單,1表示命中羊毛黨名單</state>
        </econnoisserurInfo>
        
        <!--8是否命中欺詐風險名單 1..1-->
        <fraudRiskInfo subReportType="14229" subReportTypeCost="96040" treatResult="子報告查詢狀態,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3時的錯誤代碼,詳見數據字典,treatResult!=3時,該屬性不存在" errorMessage="treatResult=3時的錯誤描述信息,treatResult!=3時,該屬性的值為空">
            <!--treatresult為2、3時沒有以下節點-->
            <state>是否命中欺詐風險名單,取值:0/1,0表示未命中欺詐風險名單,1表示命中欺詐風險名單</state>
        </fraudRiskInfo>
        
        <!--9是否命中高風險名單 1..1 -->
        <personRiskAssess subReportType="14226" subReportTypeCost="96040" treatResult="子報告查詢狀態,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3時的錯誤代碼,詳見數據字典,treatResult!=3時,該屬性不存在" errorMessage="treatResult=3時的錯誤描述信息,treatResult!=3時,該屬性的值為空">
                <!--treatresult為2、3時沒有以下節點-->
                <checkResult>是否命中高風險名單  1:是,2:否</checkResult>
        </personRiskAssess>
        
        <!-- 10網貸逾期信息 1..1 -->
        <microNearlyThreeYearsOverdueInfo subReportType="13204" subReportTypeCost="96040" treatResult="子報告查詢狀態,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3時的錯誤代碼,詳見數據字典,treatResult!=3時,該屬性不存在" errorMessage="treatResult=3時的錯誤描述信息,treatResult!=3時,該屬性的值為空">
              <!--treatresult為2、3時沒有以下節點-->
                            
              <!--逾期彙總信息 0..1-->
                <stat>
                    <overdueAmount>逾期本金,單位:以貸款基本信息的幣種為準</overdueAmount>
                    <overdueDays>逾期天數區間,取值區間:逾期1天(含)以上</overdueDays>
                    <overdueCount>逾期天數區間的總筆數</overdueCount>
                </stat>
                
                <!--0..1-->
                <items>
                    <!--逾期概要信息 1..5 多個記錄-->
                    <item>
                        <overdueAmount>逾期本金,單位:以貸款基本信息的幣種為準</overdueAmount>
                        <overdueDays>逾期天數區間,取值區間:逾期1-6天,逾期7-29天,逾期30-59天,逾期60-89天,逾期90天(含)以上</overdueDays>
                        <overdueCount>逾期天數區間的筆數</overdueCount>
                    </item>
                </items>
        </microNearlyThreeYearsOverdueInfo>

        <!--  11風險信息 1..1 -->
        <personRiskInfo subReportType="14227" subReportTypeCost="96040" treatResult="子報告查詢狀態,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3時的錯誤代碼,詳見數據字典,treatResult!=3時,該屬性不存在" errorMessage="treatResult=3時的錯誤描述信息,treatResult!=3時,該屬性的值為空">
            <!--treatresult為2、3時沒有以下節點-->
            
            <!-- 彙總信息  0..1-->
            <stat>
                <totleCount>概要彙總條數</totleCount>
                <alCount>司法案例信息條數</alCount>
                <zxCount>司法執行信息條數</zxCount>
                <sxCount>司法失信信息條數</sxCount>
                <swCount>稅務行政執法信息條數</swCount>
                <cqggCount>催欠公告信息條數</cqggCount>
                <wdyqCount>網貸逾期信息條數</wdyqCount>
            </stat>
            <!-- 彙總信息 end-->
            <!-- 概要信息  0..1-->
            <summary>
                <!--  司法案例信息概要信息 0..1 -->
                <als>
                    <!--  司法案例信息概要信息內容 1..n -->
                    <item>
                        <recordId>記錄編號</recordId>
                        <bt>標題</bt>
                        <ajlx>案件類型</ajlx>
                        <sjnf>審結年份,格式:YYYY</sjnf>
                        <dsrlx>當事人類型</dsrlx>
                    </item>
                </als>
                <!--  司法執行信息概要信息 0..1 -->
                <zxs>
                    <!--  司法執行信息概要信息內容 1..n -->
                    <item>
                        <recordId>記錄編號</recordId>
                        <bt>標題</bt>
                        <zxbd>執行標的,單位:以幣種為準</zxbd>
                        <larq>立案日期,格式YYYY-MM-DD</larq>
                    </item>
                </zxs>
                <!--  司法失信信息概要信息 0..1 -->
                <sxs>
                    <!--  司法失信信息概要信息內容 1..n -->
                    <item>
                        <recordId>記錄編號</recordId>
                        <bt>標題</bt>
                        <larq>立案日期,格式YYYY-MM-DD</larq>
                        <fbrq>發佈日期,格式YYYY-MM-DD</fbrq>
                    </item>
                </sxs>
                <!--  稅務行政執法信息概要信息 0..1 -->
                <sws>
                    <!--  稅務行政執法信息概要信息內容 1..n -->
                    <item>
                        <recordId>記錄編號</recordId>
                        <bt>標題</bt>
                        <ggrq>公告日期,格式YYYY-MM-DD</ggrq>
                    </item>
                </sws>
                <!--  >催欠公告信息概要信息 0..1 -->
                <cqs>
                    <!--  催欠公告信息概要信息內容 1..n -->
                    <item>
                        <recordId>記錄編號</recordId>
                        <bt>標題</bt>
                        <fbrq>發佈日期,格式YYYY-MM-DD</fbrq>
                    </item>
                </cqs>
                <!--  網貸逾期信息概要信息 0..1 -->
                <wdyqs>
                    <!--  網貸逾期信息概要信息內容 1..n -->
                    <item>
                        <recordId>記錄編號</recordId>
                        <bt>標題</bt>
                        <fbrq>發佈日期,格式YYYY-MM-DD</fbrq>
                    </item>
                </wdyqs>
            </summary>
        </personRiskInfo>        
        
        <!--12個人近兩年曆史查詢記錄 1..1 -->
        <historySimpleQueryInfo subReportType="19902" subReportTypeCost="96040" treatResult="子報告查詢狀態,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3時的錯誤代碼,詳見數據字典,treatResult!=3時,該屬性不存在" errorMessage="treatResult=3時的錯誤描述信息,treatResult!=3時,該屬性的值為空">
            <!--treatresult為2、3時沒有以下節點-->
            
            <!--0..1-->
            <items>
                <!-- 1..n -->
                <item>
                    <unitMember>單位類型名稱</unitMember>
                    <last1Month>近1個月查詢記錄數</last1Month>
                    <last3Month>近3個月查詢記錄數</last3Month>
                    <last6Month>近6個月查詢記錄數</last6Month>
                    <last12Month>近12個月查詢記錄數</last12Month>
                    <last18Month>近18月查詢記錄數</last18Month>
                    <last24Month>近24月查詢記錄數</last24Month>
                </item>
            </items>
            <!--0..1-->
            <count>
                <last1Month>近1個月各單位類型查詢記錄總數</last1Month>
                <last3Month>近3個月各單位類型查詢記錄總數</last3Month>
                <last6Month>近6個月各單位類型查詢記錄總數</last6Month>
                <last12Month>近12個月各單位類型查詢記錄總數</last12Month>
                <last18Month>近18月各單位類型查詢記錄總數</last18Month>
                <last24Month>近24月各單位類型查詢記錄總數</last24Month>            
            </count>
        </historySimpleQueryInfo>
    </cisReport>
</cisReports>

二,表結構設計

1,批次號:各表之間用最外層批次號關聯。

2,主表:即把各層欄位全部存在一個表中。

三,實體設計

分為三層:CisReportRoot ,CisReportChild ,ReportElement

public class CisReportRoot extends BasePojo implements Serializable {
    private String docId;
    private String batNo;//查詢批次號
    @JSONField(serialize = false)
    private String xmlId;
    private CisReportChild cisReportChild;
/**
 * 2017/7/21.
 * 報告節點屬性以及子節點
 */
public class CisReportChild extends BasePojo {
    /**
     * 報告生成結束時間
     **/
    private String buildEndTime;
    /**
     * 是否有系統錯誤 true表示有 false表示沒有
     **/
    private String hasSystemError;
    /**
     * 該客戶是否被凍結
     **/
    private String isFrozen;

    private ReportElement reportElement;
public class ReportElement extends BasePojo {
    private String phone;
    private PoliceCheckInfo policeCheckInfo;//身份認證
    private MobileCheckInfo mobileCheckInfo;//個人手機號碼核查
    private PersonAntiSpoofingDescInfo personAntiSpoofingDescInfo;//個人反欺詐風險綜述信息
    private PersonAntiSpoofingInfo personAntiSpoofingInfo;//個人反欺詐風險評分信息
    private MobileStatusInfo mobileStatusInfo;//手機號碼狀態信息
    private EconnoisserurInfo econnoisserurInfo;//是否命中羊毛黨名單
    private FraudRiskInfo fraudRiskInfo;//是否命中欺詐風險名單
    private PersonRiskAssess personRiskAssess;//是否命中高風險名單
    private MicroNearlyThreeYearsOverdueInfo microNearlyThreeYearsOverdueInfo;//網貸逾期信息
    private PersonRiskInfo personRiskInfo;//風險信息
    private HistorySimpleQueryInfo historySimpleQueryInfo;//個人近兩年曆史查詢記錄

 

四,代碼

<1>單筆,批量無需主鍵

無論單筆還是批量都可以把數據存在map中,sql中通過map的鍵獲取數據。

如:

    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:

   <!--個人風險記錄 -->
   //單筆 <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> <!--逾期詳細記錄 -->
   //批量 <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)保存數據 saveCisReport(cisReportRoot); return cisReportRoot; }

(1)保存數據

    @Transactional(rollbackFor = Exception.class)
    @Override
    public CisReportRoot saveCisReport(CisReportRoot cisReportRoot) throws Exception {
        try {
            ReportElement reportElement = cisReportRoot.getCisReportChild().getReportElement();
            PersonRiskInfo personRiskInfo = reportElement.getPersonRiskInfo();
            //(2)主表,保存xml所有節點信息(不包含個人風險信息),保存單筆數據
            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)保存批量數據
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)保存主表

<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}
        )

查詢主表(多個條件拼接)

<!-- 查詢徵信主表 -->
    <select id="queryCisReportRoot" parameterType="PyQueryBean" resultMap="cisReportRootMap">
        SELECT * FROM (
        SELECT
        BATNO,to_char(BUILDENDTIME,'yyyy-MM-dd hh24:mi:ss') as 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
        FROM
        TABLE_CISREPORT
        <trim prefix="where" prefixOverrides="AND | OR ">
            <if test="name != null and name != '' ">
                AND PCI_NAME = #{name,jdbcType=VARCHAR}
            </if>
            <if test="documentNo != null and documentNo != '' ">
                AND PCI_DOCUMENTNO=#{documentNo,jdbcType=VARCHAR}
            </if>
            <if test="phone != null and phone!= '' ">
                AND PHONE = #{phone}
            </if>
            <if test="docId != null and docId != '' ">
                AND BATNO = #{docId,jdbcType=VARCHAR}
            </if>
            <![CDATA[AND BUILDENDTIME >= add_months(sysdate,-1)]]>
        </trim>
        ORDER BY BUILDENDTIME DESC )
        WHERE  <![CDATA[ ROWNUM <= 1 ]]>
    </select>

 

(3)保存批量數據(不自動生成主鍵)

<!--個人近兩年曆史查詢記錄 -->
    <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>單筆,批量需要插入主鍵
單筆含主鍵

        DataServiceDetailResult dataServiceDetailResult = tdService.getDataServiceDetailResult(tdReportRoot);
        int n = tdDataServiceMapper.insertDataServiceDetailResult(dataServiceDetailResult);
  <!--信息核驗介面-->
    <!--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>

批量保存包含主鍵

 if (!ListUtil.isEmpty(interfacesList)) {
            map.put("recordId", id);
            map.put("list", interfacesList);
            tdDataServiceMapper.addBatchInterfaces(map);
        }

sql:

 <!--批量保存interfaces-->
    <insert id="addBatchInterfaces" parameterType="java.util.List">
        <!--
        註釋為mysql插入方式,可以插入但是導致數據回滾不了
        下麵為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>

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 網站加速方面 1. Nginx 配置 gzip 壓縮 開啟nginx gzip壓縮後,網頁、css、js等靜態資源的大小會大大的減少,從而可以節約大量的帶寬,提高傳輸效率,給用戶快的體驗。雖然會消耗cpu資源,但是為了給用戶更好的體驗是值得的。 將以上配置放到nginx.conf的http{ ... ...
  • @Controller @RequestMapping("/task/topic") public class TopicQuartzController { protected Logger logger = LoggerFactory.getLogger(TopicQuartzControlle... ...
  • 字元串格式化 Python的字元串格式化有兩種方式:百分號方式、format方式 百分號的方式相對來說比較老,而format方式則是比較先進的方式,企圖替換古老的方式,目前兩者並存。 1、百分號方式 常用格式化: 2、Format方式 表達格式: 常用格式化: ...
  • 強大的windbg定位記憶體泄露,兩句命令搞定! ...
  • 蜂鳴器。左邊的是有源蜂鳴器,右邊的無源。從外觀上看,無源蜂鳴器略矮(約1mm)。有源蜂鳴器觸發就會發聲,發聲頻率固定。無源蜂鳴器要用方波驅動,方波頻率即為其發聲頻率: 沒有像樣的規格書,頻率範圍未知。網店商品描述中提到一句2k-5k,that's all。一些關於聲音頻率的數據: 人耳的敏感範圍約為 ...
  • 在一臺機器上連接另一臺機器的MySQL伺服器時,出現了下麵的錯誤: 這是對方機器沒有關閉防火牆造成的,關閉對方機器防火牆以後就正常了。 ...
  • 目錄 1.序 2.題庫 3. Oracle 資料庫 資料庫本質是用電腦存儲數據的一種系統。它是位於 用戶 和系統 之間的一種管理軟體。 1.序 1.1 登錄SQLPLUS 1.2 創建一個自己的用戶(比如 vip/vip) 1.3 切換到用戶 1.4 使用 1.5 激活內置的測試賬號,這裡面有幾張 ...
  • 索引的類型 B-Tree索引 B-Tree 索引 通常意味著所有的值都是按順序存儲的,並且每一個葉子頁到根的距離相同。 B-Tree 索引 能夠加快訪問數據的速度,存儲引擎不再需要進行全表掃描來獲取需要的數據,取而代之的是從索引的根節點開始搜索。 B-Tree 索引 適用於全鍵值、鍵值範圍或鍵首碼查 ...
一周排行
    -Advertisement-
    Play Games
  • 概述:本文代碼示例演示瞭如何在WPF中使用LiveCharts庫創建動態條形圖。通過創建數據模型、ViewModel和在XAML中使用`CartesianChart`控制項,你可以輕鬆實現圖表的數據綁定和動態更新。我將通過清晰的步驟指南包括詳細的中文註釋,幫助你快速理解並應用這一功能。 先上效果: 在 ...
  • openGauss(GaussDB ) openGauss是一款全面友好開放,攜手伙伴共同打造的企業級開源關係型資料庫。openGauss採用木蘭寬鬆許可證v2發行,提供面向多核架構的極致性能、全鏈路的業務、數據安全、基於AI的調優和高效運維的能力。openGauss深度融合華為在資料庫領域多年的研 ...
  • openGauss(GaussDB ) openGauss是一款全面友好開放,攜手伙伴共同打造的企業級開源關係型資料庫。openGauss採用木蘭寬鬆許可證v2發行,提供面向多核架構的極致性能、全鏈路的業務、數據安全、基於AI的調優和高效運維的能力。openGauss深度融合華為在資料庫領域多年的研 ...
  • 概述:本示例演示了在WPF應用程式中實現多語言支持的詳細步驟。通過資源字典和數據綁定,以及使用語言管理器類,應用程式能夠在運行時動態切換語言。這種方法使得多語言支持更加靈活,便於維護,同時提供清晰的代碼結構。 在WPF中實現多語言的一種常見方法是使用資源字典和數據綁定。以下是一個詳細的步驟和示例源代 ...
  • 描述(做一個簡單的記錄): 事件(event)的本質是一個委托;(聲明一個事件: public event TestDelegate eventTest;) 委托(delegate)可以理解為一個符合某種簽名的方法類型;比如:TestDelegate委托的返回數據類型為string,參數為 int和 ...
  • 1、AOT適合場景 Aot適合工具類型的項目使用,優點禁止反編 ,第一次啟動快,業務型項目或者反射多的項目不適合用AOT AOT更新記錄: 實實在在經過實踐的AOT ORM 5.1.4.117 +支持AOT 5.1.4.123 +支持CodeFirst和非同步方法 5.1.4.129-preview1 ...
  • 總說周知,UWP 是運行在沙盒裡面的,所有許可權都有嚴格限制,和沙盒外交互也需要特殊的通道,所以從根本杜絕了 UWP 毒瘤的存在。但是實際上 UWP 只是一個應用模型,本身是沒有什麼許可權管理的,許可權管理全靠 App Container 沙盒控制,如果我們脫離了這個沙盒,UWP 就會放飛自我了。那麼有沒... ...
  • 目錄條款17:讓介面容易被正確使用,不易被誤用(Make interfaces easy to use correctly and hard to use incorrectly)限制類型和值規定能做和不能做的事提供行為一致的介面條款19:設計class猶如設計type(Treat class de ...
  • title: 從零開始:Django項目的創建與配置指南 date: 2024/5/2 18:29:33 updated: 2024/5/2 18:29:33 categories: 後端開發 tags: Django WebDev Python ORM Security Deployment Op ...
  • 1、BOM對象 BOM:Broswer object model,即瀏覽器提供我們開發者在javascript用於操作瀏覽器的對象。 1.1、window對象 視窗方法 // BOM Browser object model 瀏覽器對象模型 // js中最大的一個對象.整個瀏覽器視窗出現的所有東西都 ...