|
@@ -0,0 +1,98 @@
|
|
|
+package com.persagy.dmp.report.jms.executor;
|
|
|
+
|
|
|
+import com.persagy.dmp.report.entity.QReportRwdObject;
|
|
|
+import com.persagy.dmp.report.entity.ReportRwdObject;
|
|
|
+import com.persagy.dmp.report.enumeration.DateType;
|
|
|
+import com.persagy.dmp.report.jms.MessageExecutor;
|
|
|
+import com.persagy.dmp.report.repository.ReportObjectRepository;
|
|
|
+import com.persagy.dmp.report.service.ReportUtils;
|
|
|
+import com.querydsl.core.types.dsl.BooleanExpression;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.MapUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: Fengyanjie
|
|
|
+ * @date: 2020-10-23
|
|
|
+ * @verison: 1.0
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class InstanceObjectCreateExecutor implements MessageExecutor {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ReportObjectRepository reportObjectRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ReportUtils reportUtils;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void execute(Map<String, Object> message) {
|
|
|
+ String projectId = MapUtils.getString(message, "projectId");
|
|
|
+ String objType = MapUtils.getString(message, "str1");
|
|
|
+ String classCode = MapUtils.getString(message, "str2");
|
|
|
+ String sendTime = MapUtils.getString(message, "sendTime");
|
|
|
+
|
|
|
+ String year = sendTime.substring(0, 4);
|
|
|
+ String month = sendTime.substring(0, 6);
|
|
|
+ String day = sendTime.substring(0, 8);
|
|
|
+ String hour = sendTime.substring(0, 10);
|
|
|
+
|
|
|
+ QReportRwdObject qt = QReportRwdObject.reportRwdObject;
|
|
|
+ BooleanExpression ex = qt.projectId.eq(projectId).and(qt.objType.eq(objType)).and(qt.classCode.eq(classCode)).and(qt.createTime.like(year + "%"));
|
|
|
+ Iterable<ReportRwdObject> all = reportObjectRepository.findAll(ex);
|
|
|
+ List<ReportRwdObject> data = new ArrayList<>();
|
|
|
+ all.forEach(data::add);
|
|
|
+ if (0 == data.size()) {
|
|
|
+ ReportRwdObject yearEntity = new ReportRwdObject();
|
|
|
+ yearEntity.setProjectId(projectId);
|
|
|
+ yearEntity.setObjType(objType);
|
|
|
+ yearEntity.setClassCode(classCode);
|
|
|
+ yearEntity.setYear(year);
|
|
|
+ yearEntity.setCreateTime(year);
|
|
|
+ yearEntity.setDateType(DateType.YEAR);
|
|
|
+ data.add(yearEntity);
|
|
|
+ ReportRwdObject monthEntity = new ReportRwdObject(yearEntity);
|
|
|
+ monthEntity.setMonth(month.substring(month.length() - 2));
|
|
|
+ monthEntity.setCreateTime(month);
|
|
|
+ monthEntity.setDateType(DateType.MONTH);
|
|
|
+ data.add(monthEntity);
|
|
|
+ ReportRwdObject dayEntity = new ReportRwdObject(monthEntity);
|
|
|
+ dayEntity.setDay(day.substring(day.length() - 2));
|
|
|
+ dayEntity.setCreateTime(day);
|
|
|
+ dayEntity.setDateType(DateType.DAY);
|
|
|
+ data.add(dayEntity);
|
|
|
+ ReportRwdObject hourEntity = new ReportRwdObject(dayEntity);
|
|
|
+ hourEntity.setHour(hour.substring(hour.length() - 2));
|
|
|
+ hourEntity.setCreateTime(hour);
|
|
|
+ hourEntity.setDateType(DateType.HOUR);
|
|
|
+ data.add(hourEntity);
|
|
|
+ reportObjectRepository.saveAll(data);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (ReportRwdObject datum : data) {
|
|
|
+ if (year.equals(datum.getCreateTime())) {
|
|
|
+ Long rwdObjectNum = datum.getRwdObjectNum();
|
|
|
+ datum.setRwdObjectNum((rwdObjectNum += 1));
|
|
|
+ }
|
|
|
+ if (month.equals(datum.getCreateTime())) {
|
|
|
+ Long rwdObjectNum = datum.getRwdObjectNum();
|
|
|
+ datum.setRwdObjectNum((rwdObjectNum += 1));
|
|
|
+ }
|
|
|
+ if (day.equals(datum.getCreateTime())) {
|
|
|
+ Long rwdObjectNum = datum.getRwdObjectNum();
|
|
|
+ datum.setRwdObjectNum((rwdObjectNum += 1));
|
|
|
+ }
|
|
|
+ if (hour.equals(datum.getCreateTime())) {
|
|
|
+ Long rwdObjectNum = datum.getRwdObjectNum();
|
|
|
+ datum.setRwdObjectNum((rwdObjectNum += 1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ reportObjectRepository.saveAll(data);
|
|
|
+ }
|
|
|
+}
|