|
@@ -0,0 +1,129 @@
|
|
|
+package com.persagy.apm.energy.report.monthly.outline.service.builder.common.impl;
|
|
|
+
|
|
|
+import com.persagy.apm.energy.report.monthly.config.type.constant.enums.BelongTypeEnum;
|
|
|
+import com.persagy.apm.energy.report.monthly.config.type.constant.enums.BuildingTypeEnum;
|
|
|
+import com.persagy.apm.energy.report.monthly.config.type.model.ReportType;
|
|
|
+import com.persagy.apm.energy.report.monthly.config.type.service.IReportTypeService;
|
|
|
+import com.persagy.apm.energy.report.monthly.detail.business.service.IReportBusinessDetailService;
|
|
|
+import com.persagy.apm.energy.report.monthly.outline.constants.enums.ReportStateEnum;
|
|
|
+import com.persagy.apm.energy.report.monthly.outline.model.ReportOutline;
|
|
|
+import com.persagy.apm.energy.report.monthly.outline.service.IReportOutlineService;
|
|
|
+import com.persagy.apm.energy.report.monthly.outline.service.builder.business.IBusinessReportBuilder;
|
|
|
+import com.persagy.apm.energy.report.monthly.outline.service.builder.hotel.IHotelAreaReportBuilder;
|
|
|
+import com.persagy.apm.energy.report.monthly.outline.service.builder.hotel.IHotelProjectReportBuilder;
|
|
|
+import com.persagy.apm.energy.report.monthly.outline.service.builder.common.IReportGenerator;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 商业项目报告建造者
|
|
|
+ *
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/5/12 2:53 下午
|
|
|
+ **/
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class ReportGenerator implements IReportGenerator {
|
|
|
+ @Autowired
|
|
|
+ private IReportTypeService reportTypeService;
|
|
|
+ @Autowired
|
|
|
+ private IReportOutlineService reportOutlineService;
|
|
|
+ @Autowired
|
|
|
+ private IHotelAreaReportBuilder hotelAreaReportBuilder;
|
|
|
+ @Autowired
|
|
|
+ private IHotelProjectReportBuilder hotelProjectReportBuilder;
|
|
|
+ @Resource(name = "businessProjectReportBuilder")
|
|
|
+ private IBusinessReportBuilder businessProjectReportBuilder;
|
|
|
+ @Resource(name = "businessAreaReportBuilder")
|
|
|
+ private IBusinessReportBuilder businessAreaReportBuilder;
|
|
|
+ @Autowired
|
|
|
+ private IReportBusinessDetailService businessDetailService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void generateReport(ReportOutline reportOutline) {
|
|
|
+ // 删除之前关联的报告详情
|
|
|
+ deletePreviousReportDetail(reportOutline.getDetailId());
|
|
|
+ // 生成新的报告详情
|
|
|
+ boolean generateSuccess = generateReportDetail(reportOutline);
|
|
|
+
|
|
|
+ // 更新报告概要的状态
|
|
|
+ if (generateSuccess) {
|
|
|
+ // 更新报告生成状态为已生成
|
|
|
+ updateReportOutlineInfoWhenSuccess(reportOutline);
|
|
|
+ } else {
|
|
|
+ // 生成失败,回滚上述生成报告操作,更新报告状态为生成失败
|
|
|
+ updateReportOutlineInfoWhenFailure(reportOutline);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean generateReportDetail(ReportOutline reportOutline) {
|
|
|
+ String reportTypeId = reportOutline.getReportTypeId();
|
|
|
+ ReportType reportType = reportTypeService.queryReportTypeDetail(reportTypeId);
|
|
|
+ // 根据业态判断生成那种报告
|
|
|
+ if (BuildingTypeEnum.BUSINESS.getType().equals(reportType.getBuildingType())) {
|
|
|
+ return generateBusinessReportDetail(reportOutline, reportType);
|
|
|
+ } else if (BuildingTypeEnum.HOTEL.getType().equals(reportType.getBuildingType())) {
|
|
|
+ return generateHotelReportDetail(reportOutline, reportType);
|
|
|
+ } else {
|
|
|
+ throw new IllegalArgumentException("目前不支持此类报告的生成,业态:" + reportType.getBuildingType());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成酒店报告详情
|
|
|
+ *
|
|
|
+ * @param reportOutline 报告概要
|
|
|
+ * @param reportType 报告类型
|
|
|
+ * @return 是否生成成功
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/6/8 7:28 下午
|
|
|
+ */
|
|
|
+ private boolean generateHotelReportDetail(ReportOutline reportOutline, ReportType reportType) {
|
|
|
+ if (BelongTypeEnum.PROJECT.getType().equals(reportType.getBelongType())) {
|
|
|
+ return hotelAreaReportBuilder.generateNewReportDetail(reportOutline);
|
|
|
+ } else {
|
|
|
+ return hotelProjectReportBuilder.generateNewReportDetail(reportOutline);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成商业报告详情
|
|
|
+ *
|
|
|
+ * @param reportOutline 报告概要
|
|
|
+ * @param reportType 报告类型
|
|
|
+ * @return 是否生成成功
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/6/8 7:28 下午
|
|
|
+ */
|
|
|
+ private Boolean generateBusinessReportDetail(ReportOutline reportOutline, ReportType reportType) {
|
|
|
+ IBusinessReportBuilder businessReportBuilder;
|
|
|
+ // 如果后续类型增多,可以修改为switch,case或者用map存储映射
|
|
|
+ if (BelongTypeEnum.PROJECT.getType().equals(reportType.getBelongType())) {
|
|
|
+ businessReportBuilder = businessProjectReportBuilder;
|
|
|
+ } else {
|
|
|
+ businessReportBuilder = businessAreaReportBuilder;
|
|
|
+ }
|
|
|
+ return businessReportBuilder.generateNewReportDetail(reportOutline);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateReportOutlineInfoWhenSuccess(ReportOutline reportOutline) {
|
|
|
+ reportOutline.setStatus(ReportStateEnum.GENERATED.getType());
|
|
|
+ reportOutlineService.updateReportOutline(reportOutline);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateReportOutlineInfoWhenFailure(ReportOutline reportOutline) {
|
|
|
+ reportOutline.setStatus(ReportStateEnum.BUILD_FAILED.getType());
|
|
|
+ reportOutlineService.updateReportOutline(reportOutline);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deletePreviousReportDetail(String detailId) {
|
|
|
+ businessDetailService.deleteReportBusinessDetail(detailId);
|
|
|
+ }
|
|
|
+}
|