|
@@ -0,0 +1,98 @@
|
|
|
+package cn.com.qmth.dp.examcloud.oe.modules.cut_exam_capture_data;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.json.JSONArray;
|
|
|
+import org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Scope;
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.jdbc.core.RowMapper;
|
|
|
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
|
|
+import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import cn.com.qmth.dp.examcloud.oe.multithread.Consumer;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Scope("prototype")
|
|
|
+public class CutExamCaptureDataConsumer extends Consumer<CutExamCaptureDataDto> {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void consume(Map<String, Object> param, CutExamCaptureDataDto dto) {
|
|
|
+ List<CutExamCaptureData> cs = getData(dto.getStart(), dto.getEnd());
|
|
|
+ if(CollectionUtils.isEmpty(cs)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, ExamCaptureCameraInfo> map = new LinkedHashMap<>();
|
|
|
+ for (CutExamCaptureData c : cs) {
|
|
|
+ try {
|
|
|
+ if (StringUtils.isNotBlank(c.getCameraInfos())) {
|
|
|
+ JSONArray jsonArray = new JSONArray(c.getCameraInfos());
|
|
|
+ for (int i = 0; i < jsonArray.length(); i++) {
|
|
|
+ JSONObject jsonObject = (JSONObject) jsonArray.get(i);
|
|
|
+ ExamCaptureCameraInfo ci = new ExamCaptureCameraInfo();
|
|
|
+ ci.setExamRecordDataId(c.getExamRecordDataId());
|
|
|
+ ci.setDetail(getVal(jsonObject, "detail"));
|
|
|
+ ci.setName(getVal(jsonObject, "name"));
|
|
|
+ ci.setPid(getVal(jsonObject, "pid"));
|
|
|
+ ci.setVid(getVal(jsonObject, "vid"));
|
|
|
+ if (jsonObject.isNull("pid") || StringUtils.isBlank(jsonObject.getString("pid"))) {
|
|
|
+ ci.setVirtualCamera(true);
|
|
|
+ } else {
|
|
|
+ ci.setVirtualCamera(false);
|
|
|
+ }
|
|
|
+ if (map.get(getKey(ci))==null) {
|
|
|
+ map.put(getKey(ci), ci);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (JSONException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!map.isEmpty()) {
|
|
|
+ List<ExamCaptureCameraInfo> list = new ArrayList<>();
|
|
|
+ for(ExamCaptureCameraInfo ci:map.values()) {
|
|
|
+ list.add(ci);
|
|
|
+ }
|
|
|
+ namedParameterJdbcTemplate.batchUpdate(
|
|
|
+ "INSERT INTO ec_oe_exam_capture_camera_info (exam_record_data_id, pid,vid,virtual_camera,name,detail,creation_time,update_time)"
|
|
|
+ + " VALUES (:examRecordDataId, :pid,:vid,:virtualCamera,:name,:detail,now(),now())",
|
|
|
+ SqlParameterSourceUtils.createBatch(list));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getVal(JSONObject jsonObject,String name) throws JSONException {
|
|
|
+ if (jsonObject.isNull(name) || StringUtils.isBlank(jsonObject.getString(name))) {
|
|
|
+ return "";
|
|
|
+ }else {
|
|
|
+ return jsonObject.getString(name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getKey(ExamCaptureCameraInfo ci) {
|
|
|
+ return ci.getExamRecordDataId()+"_"+ci.getPid()+"_"+ci.getVid()+"_"+ci.getName();
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<CutExamCaptureData> getData(long start, long end) {
|
|
|
+ String sql = "select t.exam_record_data_id examRecordDataId,t.camera_infos cameraInfos from ec_oe_exam_capture t where t.exam_record_data_id>"
|
|
|
+ + start + " and t.exam_record_data_id<=" + end + " order by t.exam_record_data_id ";
|
|
|
+ RowMapper<CutExamCaptureData> rowMapper = new BeanPropertyRowMapper<CutExamCaptureData>(
|
|
|
+ CutExamCaptureData.class);
|
|
|
+ List<CutExamCaptureData> ret = jdbcTemplate.query(sql, rowMapper);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+}
|