ORCL 使用MyBatis批量添加
Service代码
/**
* 同步历史会议数据
* 作者: 吴 波
* 时间: 2020-03-11 15:36
* 笔名: 那年秋天的茄子^^
*/
private void syncMeetHistorys(Date startTime, Date endTime) {
Result<JSONArray> history = HistroryApi.getHistory(startTime, endTime);
JSONArray historyData = history.getData();
List<MeetHistory> meetHistoryList = new ArrayList<>(historyData.size());
historyData.stream().forEach(jsonobejct -> {
JSONObject mettHistoryJsonObject = (JSONObject) jsonobejct;
MeetHistory meetHistory = JSONObject.toJavaObject(mettHistoryJsonObject, MeetHistory.class);
meetHistoryList.add(meetHistory);
});
if (meetHistoryList.size() != 0) {
this.meetHistoryMapper.insertMeetHistoryList(meetHistoryList);
}
Result<JSONArray> historyInfo = HistroryApi.getHistoryInfo(startTime, endTime);
JSONArray historyInfoData = historyInfo.getData();
List<MeetHistoryInfo> meetHistoryInfoList = new ArrayList<>(historyInfoData.size());
historyInfoData.stream().forEach(jsonobejct -> {
JSONObject mettHistoryInfoJsonObject = (JSONObject) jsonobejct;
MeetHistoryInfo meetHistoryInfo = JSONObject.toJavaObject(mettHistoryInfoJsonObject, MeetHistoryInfo.class);
log.info("数据为\n{}", meetHistoryInfo);
meetHistoryInfoList.add(meetHistoryInfo);
});
if (meetHistoryInfoList.size() != 0) {
this.meetHistoryInfoMapper.insertMeetHistoryList(meetHistoryInfoList);
}
}
Mapper 代码
package com.itechhero.app.module.edu.meet.history.mapper;
import com.itechhero.app.module.edu.BaseMapper;
import com.itechhero.app.module.edu.meet.history.model.MeetHistoryInfo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface MeetHistoryInfoMapper extends BaseMapper<MeetHistoryInfo> {
/**
* 批量添加数据
* 作者: 吴 波
* 时间: 2020-03-12 9:44
* 笔名: 那年秋天的茄子^^
*/
void insertMeetHistoryList(@Param("meetHistoryInfos") List<MeetHistoryInfo> meetHistoryInfos);
}
Mapper.xml文件
<insert id="insertMeetHistoryList" parameterType="java.util.List" useGeneratedKeys="false">
INSERT INTO YJ_MEET_HISTORY_INFO(ID, PARTICIPANT_ID, PARTICIPANT_DEVICE_TYPE, JOIN_TIME_BEGIN,
JOIN_TIME_END, DURATION, MEETING_NUMBER, MEETING_NAME, DISPLAY_NAME, MEETING_ID)
SELECT SYS_GUID(),s.* FROM
<foreach collection="meetHistoryInfos" open="(" separator="UNION ALL" close=") s" item="item">
SELECT
#{item.participantId},
#{item.participantDeviceType},
#{item.joinTimeBegin},
#{item.joinTimeEnd},
#{item.duration},
<if test="item.meetingNumber==null">
null,
</if>
<if test="item.meetingNumber!=null">
#{item.meetingNumber},
</if>
<if test="item.meetingNumber==null">
null,
</if>
<if test="item.meetingNumber!=null">
#{item.meetingName},
</if>
#{item.displayName},
#{item.meetingId}
FROM DUAL
</foreach>
</insert>