diff --git a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/controller/ParamsReportDetailEOController.java b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/controller/ParamsReportDetailEOController.java index 8906be54b..ce59f6900 100644 --- a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/controller/ParamsReportDetailEOController.java +++ b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/controller/ParamsReportDetailEOController.java @@ -22,10 +22,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -197,4 +194,23 @@ public class ParamsReportDetailEOController extends JeroController save(@RequestBody ParamsReportDetailVO paramsReportDetailVO) { + boolean isSuccess = paramsReportConfigEOService.save(paramsReportDetailVO.getConfigDataList(), paramsReportDetailVO.getParamsManifestId()); + if (isSuccess) { + return Result.OK("暂存成功!"); + } else { + return Result.error("暂存失败!"); + } + } + } diff --git a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/IParamsReportConfigDataEOService.java b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/IParamsReportConfigDataEOService.java index 16dce9473..dc3818c1d 100644 --- a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/IParamsReportConfigDataEOService.java +++ b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/IParamsReportConfigDataEOService.java @@ -23,4 +23,11 @@ public interface IParamsReportConfigDataEOService extends IService queryByConfigIdListAndCollectManifestId(List paramsConfigIdList, String paramsCollectManifestId); + + /** + * 查询清单的所有配置数据 + * @param configIdList + * @return + */ + List queryListByConfigIdList(List configIdList); } diff --git a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/IParamsReportConfigEOService.java b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/IParamsReportConfigEOService.java index 4c0d18c9c..649b427d0 100644 --- a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/IParamsReportConfigEOService.java +++ b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/IParamsReportConfigEOService.java @@ -3,6 +3,7 @@ package com.jero.modules.cert.report.service; import com.jero.modules.cert.report.entity.ParamsReportConfigEO; import com.baomidou.mybatisplus.extension.service.IService; import java.util.List; +import java.util.Map; /** * @Description: 上报库参数配置 @@ -12,5 +13,19 @@ import java.util.List; */ public interface IParamsReportConfigEOService extends IService { + /** + * 列表查询 + * @param paramsManifestId + * @return + */ List queryList(String paramsManifestId); + + /** + * 保存 + * @param configDataList + * @param paramsManifestId + * @return + */ + boolean save(List> configDataList, String paramsManifestId); + } diff --git a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportConfigDataEOServiceImpl.java b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportConfigDataEOServiceImpl.java index ac69c6438..cce1ae4ed 100644 --- a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportConfigDataEOServiceImpl.java +++ b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportConfigDataEOServiceImpl.java @@ -1,5 +1,6 @@ package com.jero.modules.cert.report.service.impl; +import cn.hutool.core.collection.CollectionUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.jero.modules.cert.report.entity.ParamsReportConfigDataEO; @@ -38,4 +39,20 @@ public class ParamsReportConfigDataEOServiceImpl extends ServiceImpl queryByConfigIdListAndCollectManifestId(List paramsConfigIdList, String paramsCollectManifestId) { return baseMapper.selectByConfigIdListAndCollectManifestId(paramsConfigIdList, paramsCollectManifestId); } + + /** + * 查询清单的所有配置数据 + * @param configIdList + * @return + */ + @Override + public List queryListByConfigIdList(List configIdList) { + if (CollectionUtil.isNotEmpty(configIdList)) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.in(ParamsReportConfigDataEO::getParamsConfigId, configIdList); + return list(queryWrapper); + } + return null; + } + } diff --git a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportConfigEOServiceImpl.java b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportConfigEOServiceImpl.java index 23af1d970..edb2fe3d2 100644 --- a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportConfigEOServiceImpl.java +++ b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportConfigEOServiceImpl.java @@ -1,13 +1,28 @@ package com.jero.modules.cert.report.service.impl; +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.jero.modules.cert.collect.entity.ParamsConfigDataEO; +import com.jero.modules.cert.collect.entity.ParamsConfigEO; +import com.jero.modules.cert.collect.enums.ConfigDataTypeEnum; +import com.jero.modules.cert.report.entity.ParamsReportConfigDataEO; import com.jero.modules.cert.report.entity.ParamsReportConfigEO; import com.jero.modules.cert.report.mapper.ParamsReportConfigEOMapper; +import com.jero.modules.cert.report.service.IParamsReportConfigDataEOService; import com.jero.modules.cert.report.service.IParamsReportConfigEOService; +import com.jero.modules.oss.entity.OSSFile; +import com.jero.modules.oss.service.IOSSFileService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; /** * @Description: 上报库参数配置 @@ -18,6 +33,15 @@ import java.util.List; @Service public class ParamsReportConfigEOServiceImpl extends ServiceImpl implements IParamsReportConfigEOService { + @Autowired + private IOSSFileService ossFileService; + + @Autowired + private IParamsReportConfigEOService paramsReportConfigEOService; + + @Autowired + private IParamsReportConfigDataEOService paramsReportConfigDataEOService; + /** * 列表查询 * @@ -31,4 +55,102 @@ public class ParamsReportConfigEOServiceImpl extends ServiceImpl list = list(queryWrapper); return list; } + + @Override + public boolean save(List> configDataList, String paramsManifestId) { + List newConfigDataEOList = new ArrayList<>(); + List paramsReportConfigEOList = paramsReportConfigEOService.queryList(paramsManifestId); // 查询配置列 + List paramsReportConfigIdList = paramsReportConfigEOList.stream().map(ParamsConfigEO::getId).collect(Collectors.toList()); + List paramsReportConfigDataEOList = paramsReportConfigDataEOService.queryListByConfigIdList(paramsReportConfigIdList); // 查询所有配置数据 + + // 处理数据 + for (Map map : configDataList) { + String paramsCollectManifestId = (String) map.get("id"); + + // 添加配置数据 + for (Map.Entry entry : map.entrySet()) { + ParamsReportConfigDataEO paramsReportConfigDataEO = new ParamsReportConfigDataEO(); + if ("id".equals(entry.getKey())) { + continue; + } + + // 取值 + String paramsReportConfigEOId = entry.getKey(); + Map paramsReportConfigDataMap = (Map) entry.getValue(); + // 无法转ParamsConfigDataVO(遍历会出现该异常 : LinkedHashMap cannot be cast to ParamsConfigDataVO) + List> configDataVOList = (List>) paramsReportConfigDataMap.get("list"); + + // 判断是新增还是修改 + ParamsConfigDataEO oldConfigDataEO = getConfigDataEOByConfigIdAndCollectManifestId(paramsReportConfigEOId, paramsCollectManifestId, paramsReportConfigDataEOList); + if (ObjectUtil.isNotEmpty(oldConfigDataEO)) { + paramsReportConfigDataEO.setId(oldConfigDataEO.getId()); + + } + paramsReportConfigDataEO.setParamsCollectManifestId(paramsCollectManifestId); + paramsReportConfigDataEO.setParamsConfigId(paramsReportConfigEOId); + if (CollectionUtil.isNotEmpty(configDataVOList)) { + for (Map paramsConfigDataVO : configDataVOList) { + String type = (String) paramsConfigDataVO.get("type"); + String dataValue = (String) paramsConfigDataVO.get("dataValue"); + + if (type.equals(ConfigDataTypeEnum.TEXT.getValue())) { + paramsReportConfigDataEO.setTextData(dataValue); + + } else if (type.equals(ConfigDataTypeEnum.PULL.getValue()) + || type.equals(ConfigDataTypeEnum.PULL_MORE.getValue())) { + paramsReportConfigDataEO.setPullData(dataValue); + + } else if (type.equals(ConfigDataTypeEnum.FILE.getValue())) { + if (StringUtils.isNotEmpty(dataValue) && dataValue.contains(",")) { // 新加多个文件 + // 处理文件connectId + String[] fileIdList = dataValue.split(","); + String connectId = UUID.randomUUID().toString().replace("-", ""); + List updateFileList = new ArrayList<>(); + for (int i = 0; i < fileIdList.length; i++) { + OSSFile ossFile = new OSSFile(); + ossFile.setId(fileIdList[i]); + ossFile.setConnectId(connectId); + updateFileList.add(ossFile); + } + ossFileService.updateBatchById(updateFileList); + dataValue = connectId; + } else if (StringUtils.isNotEmpty(dataValue) && !dataValue.contains(",")) { + List ossFiles = ossFileService.getFileInfosByConnectId(dataValue); + if(CollectionUtil.isEmpty(ossFiles)){ // 新加了一个文件 + String connectId = UUID.randomUUID().toString().replace("-", ""); + //修改文件表关联信息connect_id + List oSSFileList = new ArrayList<>(); + for (String fileId : dataValue.split(",")) { + OSSFile ossFile = new OSSFile(); + ossFile.setId(fileId); + ossFile.setConnectId(connectId); + oSSFileList.add(ossFile); + } + ossFileService.updateFileInfo(oSSFileList); + dataValue = connectId; + } + } + paramsReportConfigDataEO.setFileConnectId(dataValue); + + } + } + } + newConfigDataEOList.add(paramsReportConfigDataEO); + } + } + + // 批量更新 + return paramsReportConfigDataEOService.saveOrUpdateBatch(newConfigDataEOList); + } + + private ParamsReportConfigDataEO getConfigDataEOByConfigIdAndCollectManifestId(String configId, String collectManifestId, List paramsReportConfigDataEOList) { + List configDataEOList = paramsReportConfigDataEOList.stream() + .filter(e-> configId.equals(e.getParamsConfigId()) && collectManifestId.equals(e.getParamsCollectManifestId())) + .collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(configDataEOList)) { + return configDataEOList.get(0); + } + return null; + } + } diff --git a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/vo/ParamsReportDetailVO.java b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/vo/ParamsReportDetailVO.java index 1ab8e7c79..d93101f2b 100644 --- a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/vo/ParamsReportDetailVO.java +++ b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/vo/ParamsReportDetailVO.java @@ -3,6 +3,9 @@ package com.jero.modules.cert.report.vo; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.util.List; +import java.util.Map; + @Data public class ParamsReportDetailVO { @@ -37,6 +40,9 @@ public class ParamsReportDetailVO { @ApiModelProperty(value = "对应参数模板发布版本") private Integer paramsTemplatePublishVersion; + @ApiModelProperty(value = "保存专用") + private List> configDataList; // 保存专用 + // 导出通用 private String cut; private String exportName;