多平台统一管理软件接口,如何实现多平台统一管理软件接口
717
2023-02-26
mybatis单笔批量保存实体数据的方法
这一篇主要介绍,如何保存实体数据。具体内容如下所示;
一,xml样例
subReportTypesShortCaption="查询的收费子报告中文名称 " refID="引用ID,为查询申请条件中的引用ID" hasSystemError="有否系统错误,true:有错误,false:无错误"
isFrozen="该客户是否被冻结,true:被冻结,false:未被冻结">
查询条件中文名称
subReportTypesShortCaption="查询的收费子报告中文名称 " refID="引用ID,为查询申请条件中的引用ID" hasSystemError="有否系统错误,true:有错误,false:无错误"
isFrozen="该客户是否被冻结,true:被冻结,false:未被冻结">
二,表结构设计
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
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 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 INTO TABLE_MNTYOI (BATNO,OVERDUEAMOUNT,OVERDUEDAYS,OVERDUECOUNT)
(
SELECT #{batNo,jdbcType=VARCHAR},
#{item.overdueAmount,jdbcType=VARCHAR},
#{item.overdueDays,jdbcType=VARCHAR},
#{item.overdueCount,jdbcType=NUMERIC}
FROM DUAL
)
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)) {
http:// Map
//(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 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)保存批量数据(不自动生成主键)
INSERT INTO
TABLE_HISTORY_SIMPLE_QUERY
(BATNO,UNIT_MEMBER,LAST1MONTH,LAST3MONTH,LAST6MONTH,LAST12MONTH,LAST18MONTH,LAST24MONTH)
(
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
)
<2>单笔,批量需要插入主键
单笔含主键
DataServiceDetailResult dataServiceDetailResult = tdService.getDataServiceDetailResult(tdReportRoot);
int n = tdDataServiceMapper.insertDataServiceDetailResult(dataServiceDetailResult);
select SEQ_ICS_TD_DATASERVICE.nextval as id from dual
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})
批量保存包含主键
if (!ListUtil.isEmpty(interfacesList)) {
map.put("recordId", id);
map.put("list", interfacesList);
tdDataServiceMapper.addBatchInterfaces(map);
}
sql:
insert into ICS_TD_INTERFACES (ID,RECORDID, TYPE)
SELECT SEQ_ICS_TD_INTERFACES.nextval ID, A.*
FROM(
SELECT
#{recordId,jdbcType=DECIMAL},
#{item.type,jdbcType=VARCHAR}
FROM DUAL
) A
总结
以上sRMUnZ所述是给大家介绍的mybatis单笔批量保存实体数据的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,会及时回复大家的。在此也非常感谢大家对我们网站的支持!
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~