|
|
@@ -0,0 +1,217 @@
|
|
|
+package com.hotent.enterpriseDeclare.service;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.hotent.base.util.StringUtil;
|
|
|
+import com.hotent.enterpriseDeclare.manager.CostSurveyTemplateUploadDataManager;
|
|
|
+import com.hotent.enterpriseDeclare.model.CostSurveyTemplateUploadData;
|
|
|
+import com.hotent.surveyinfo.dao.CostSurveyFdTemplateItemsDao;
|
|
|
+import com.hotent.surveyinfo.dao.CostSurveyTemplateItemsDao;
|
|
|
+import com.hotent.surveyinfo.dao.CostVerifyTemplateItemsDao;
|
|
|
+import com.hotent.surveyinfo.manager.CostSurveyFdTemplateVersionManager;
|
|
|
+import com.hotent.surveyinfo.manager.CostSurveyTemplateVersionManager;
|
|
|
+import com.hotent.surveyinfo.model.*;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 单元格数据查询服务
|
|
|
+ * 用于获取指定任务、模板、年限、单元格的数据值
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class CellDataQueryService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CostSurveyTemplateUploadDataManager costSurveyTemplateUploadDataManager;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CostSurveyTemplateItemsDao costSurveyTemplateItemsDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CostSurveyFdTemplateItemsDao costSurveyFdTemplateItemsDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CostVerifyTemplateItemsDao costVerifyTemplateItemsDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CostSurveyTemplateVersionManager costSurveyTemplateVersionManager;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CostSurveyFdTemplateVersionManager costSurveyFdTemplateVersionManager;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取指定单元格在指定年限的值
|
|
|
+ * @param taskId 任务ID
|
|
|
+ * @param surveyTemplateId 模板ID
|
|
|
+ * @param cellCode 单元格代码(如 A1, Q2)
|
|
|
+ * @param period 年限(如 2024)
|
|
|
+ * @param type 类型:1-成本调查表 2-财务数据表 3-核定表
|
|
|
+ * @return 该单元格在该年限的值
|
|
|
+ */
|
|
|
+ public String getCellValueByPeriod(String taskId, String surveyTemplateId, String cellCode, String period, String type) {
|
|
|
+ // 1. 根据 cellCode 找到对应的 rowid
|
|
|
+ String rowid = getRowIdByCellCode(surveyTemplateId, cellCode, type);
|
|
|
+ if (StringUtil.isEmpty(rowid)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 查询上传数据
|
|
|
+ QueryWrapper<CostSurveyTemplateUploadData> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("task_id", taskId)
|
|
|
+ .eq("survey_template_id", surveyTemplateId)
|
|
|
+ .eq("rowid", rowid)
|
|
|
+ .eq("rkey", period)
|
|
|
+ .eq("type", type)
|
|
|
+ .eq("is_deleted", "0");
|
|
|
+
|
|
|
+ CostSurveyTemplateUploadData data = costSurveyTemplateUploadDataManager.getOne(wrapper);
|
|
|
+ return data != null ? data.getRvalue() : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取跨表公式的所有引用数据
|
|
|
+ * @param taskId 任务ID
|
|
|
+ * @param calculationTemplateId 计算模板ID(跨表引用的模板)
|
|
|
+ * @param calculationType 计算模板的类型
|
|
|
+ * @param period 年限
|
|
|
+ * @return cellCode_年限 -> 值 的映射
|
|
|
+ */
|
|
|
+ public java.util.Map<String, String> getCrossTableFormulaData(String taskId, String calculationTemplateId, String calculationType, String period) {
|
|
|
+ java.util.Map<String, String> result = new java.util.HashMap<>();
|
|
|
+
|
|
|
+ if (StringUtil.isEmpty(calculationTemplateId)) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询该模板下所有的上传数据
|
|
|
+ QueryWrapper<CostSurveyTemplateUploadData> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("task_id", taskId)
|
|
|
+ .eq("survey_template_id", calculationTemplateId)
|
|
|
+ .eq("rkey", period)
|
|
|
+ .eq("type", calculationType)
|
|
|
+ .eq("is_deleted", "0");
|
|
|
+
|
|
|
+ List<CostSurveyTemplateUploadData> dataList = costSurveyTemplateUploadDataManager.list(wrapper);
|
|
|
+
|
|
|
+ // 构建 cellCode_年限 -> 值 的映射
|
|
|
+ for (CostSurveyTemplateUploadData data : dataList) {
|
|
|
+ String rowid = data.getRowid();
|
|
|
+ String cellCode = getItemCellCodeByRowId(calculationTemplateId, rowid, calculationType);
|
|
|
+ if (StringUtil.isNotEmpty(cellCode)) {
|
|
|
+ String mapKey = cellCode + "_" + period;
|
|
|
+ result.put(mapKey, data.getRvalue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据 cellCode 获取对应的 rowid
|
|
|
+ */
|
|
|
+ private String getRowIdByCellCode(String surveyTemplateId, String cellCode, String type) {
|
|
|
+ try {
|
|
|
+ switch (type) {
|
|
|
+ case "1": {
|
|
|
+ // 成本调查表
|
|
|
+ CostSurveyTemplateVersion version = costSurveyTemplateVersionManager.selectCurrentVersion(surveyTemplateId);
|
|
|
+ if (version != null) {
|
|
|
+ List<CostSurveyTemplateItems> items = costSurveyTemplateItemsDao.selectBySurveyTemplateIdAndVersion(surveyTemplateId, version.getId());
|
|
|
+ if (items != null) {
|
|
|
+ return items.stream()
|
|
|
+ .filter(item -> cellCode.equals(item.getCellCode()))
|
|
|
+ .map(item -> item.getRowid())
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "2": {
|
|
|
+ // 财务数据表
|
|
|
+ CostSurveyFdTemplateVersion version = costSurveyFdTemplateVersionManager.selectCurrentVersion(surveyTemplateId);
|
|
|
+ if (version != null) {
|
|
|
+ List<CostSurveyFdTemplateItems> items = costSurveyFdTemplateItemsDao.selectBySurveyTemplateIdAndVersion(surveyTemplateId, version.getId());
|
|
|
+ if (items != null) {
|
|
|
+ return items.stream()
|
|
|
+ .filter(item -> cellCode.equals(item.getCellCode()))
|
|
|
+ .map(item -> item.getRowid())
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "3": {
|
|
|
+ // 核定表
|
|
|
+ List<CostVerifyTemplateItems> items = costVerifyTemplateItemsDao.selectByVerifyTemplateId(surveyTemplateId, null);
|
|
|
+ if (items != null) {
|
|
|
+ return items.stream()
|
|
|
+ .filter(item -> cellCode.equals(item.getCellCode()))
|
|
|
+ .map(item -> item.getRowid())
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据 rowid 获取对应的 cellCode
|
|
|
+ */
|
|
|
+ private String getItemCellCodeByRowId(String surveyTemplateId, String rowid, String type) {
|
|
|
+ try {
|
|
|
+ switch (type) {
|
|
|
+ case "1": {
|
|
|
+ CostSurveyTemplateVersion version = costSurveyTemplateVersionManager.selectCurrentVersion(surveyTemplateId);
|
|
|
+ if (version != null) {
|
|
|
+ List<CostSurveyTemplateItems> items = costSurveyTemplateItemsDao.selectBySurveyTemplateIdAndVersion(surveyTemplateId, version.getId());
|
|
|
+ if (items != null) {
|
|
|
+ return items.stream()
|
|
|
+ .filter(item -> rowid.equals(item.getRowid()))
|
|
|
+ .map(item -> item.getCellCode())
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "2": {
|
|
|
+ CostSurveyFdTemplateVersion version = costSurveyFdTemplateVersionManager.selectCurrentVersion(surveyTemplateId);
|
|
|
+ if (version != null) {
|
|
|
+ List<CostSurveyFdTemplateItems> items = costSurveyFdTemplateItemsDao.selectBySurveyTemplateIdAndVersion(surveyTemplateId, version.getId());
|
|
|
+ if (items != null) {
|
|
|
+ return items.stream()
|
|
|
+ .filter(item -> rowid.equals(item.getRowid()))
|
|
|
+ .map(item -> item.getCellCode())
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "3": {
|
|
|
+ List<CostVerifyTemplateItems> items = costVerifyTemplateItemsDao.selectByVerifyTemplateId(surveyTemplateId, null);
|
|
|
+ if (items != null) {
|
|
|
+ return items.stream()
|
|
|
+ .filter(item -> rowid.equals(item.getRowid()))
|
|
|
+ .map(item -> item.getCellCode())
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|