diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/controller/admin/SampleAnalysisAuditController.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/controller/admin/SampleAnalysisAuditController.java index c89cbbf..ced06cc 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/controller/admin/SampleAnalysisAuditController.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/controller/admin/SampleAnalysisAuditController.java @@ -31,12 +31,6 @@ public class SampleAnalysisAuditController implements BusinessControllerMarker { @Resource private SampleAnalysisAuditService sampleAnalysisAuditService; - @GetMapping("/crossAuditByTaskId") - public CommonResult crossAuditByTaskId(Long businessAssayTaskId) { - JSONObject result = sampleAnalysisAuditService.crossAuditByTaskId(businessAssayTaskId); - return success(result); - } - /** * 交叉审核 * @return diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/controller/admin/SampleEntrustController.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/controller/admin/SampleEntrustController.java index 0fc1c56..5336a48 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/controller/admin/SampleEntrustController.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/controller/admin/SampleEntrustController.java @@ -59,14 +59,6 @@ public class SampleEntrustController implements BusinessControllerMarker { BusinessSampleEntrustRegistrationExtendRespVO sampleEntrustRegistration = sampleEntrustService.detail(id); return success(sampleEntrustRegistration); } - - @GetMapping("/reportDetail") - @Operation(summary = "委托单详情数据") - public CommonResult reportDetail(@RequestParam("id") Long id) { - JSONObject jsonObject = sampleEntrustService.reportDetail(id); - return success(jsonObject); - - } @PostMapping("/update") @Operation(summary = "修改委托登记") diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/controller/admin/SampleReportDataQueryController.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/controller/admin/SampleReportDataQueryController.java new file mode 100644 index 0000000..fe7db94 --- /dev/null +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/controller/admin/SampleReportDataQueryController.java @@ -0,0 +1,45 @@ +package com.zt.plat.module.qms.business.bus.controller.admin; + +import static com.zt.plat.framework.common.pojo.CommonResult.success; + +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 com.alibaba.fastjson2.JSONObject; +import com.zt.plat.framework.common.pojo.CommonResult; +import com.zt.plat.module.qms.business.bus.service.SampleAnalysisAuditService; +import com.zt.plat.module.qms.business.bus.service.SampleEntrustService; + +import io.swagger.v3.oas.annotations.Operation; +import jakarta.annotation.Resource; + +/** + * 报表数据查询接口,不继承BusinessControllerMarker + */ +@RestController +@RequestMapping("/qms/bus/sample/reporting-data-query") +public class SampleReportDataQueryController { + + @Resource + private SampleEntrustService sampleEntrustService; + + @Resource + private SampleAnalysisAuditService sampleAnalysisAuditService; + + @GetMapping("/entrust-report-detail") + @Operation(summary = "委托单详情数据") + public CommonResult reportDetail(@RequestParam("id") Long id) { + JSONObject jsonObject = sampleEntrustService.reportDetail(id); + return success(jsonObject); + + } + + @Operation(summary = "委托单详情数据") + @GetMapping("/crossAuditByTaskId") + public CommonResult crossAuditByTaskId(Long businessAssayTaskId) { + JSONObject result = sampleAnalysisAuditService.crossAuditByTaskId(businessAssayTaskId); + return success(result); + } +} diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/dal/mapper/BusinessSampleEntrustDetailMapper.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/dal/mapper/BusinessSampleEntrustDetailMapper.java index 2f40ea1..3c71cf7 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/dal/mapper/BusinessSampleEntrustDetailMapper.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/dal/mapper/BusinessSampleEntrustDetailMapper.java @@ -90,13 +90,16 @@ public interface BusinessSampleEntrustDetailMapper extends BaseMapperX() + return selectJoinOne(BusinessSampleEntrustDetailDO.class, new MPJLambdaWrapperX() + .leftJoin(BaseSampleDO.class, BaseSampleDO::getId, BusinessSampleEntrustDetailDO::getBaseSampleId) .eq(BusinessSampleEntrustDetailDO::getBusinessSampleEntrustRegistrationId, businessSampleEntrustDetailDO.getBusinessSampleEntrustRegistrationId()) + .eq(BaseSampleDO::getDictionaryBusinessKey, baseSampleDictionaryBusinessKey) .orderByAsc(BusinessSampleEntrustDetailDO::getSort) .last(" limit 1 ")); diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/dal/mapper/BusinessSubParentSampleAssessmentMapper.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/dal/mapper/BusinessSubParentSampleAssessmentMapper.java index 1116eda..506d086 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/dal/mapper/BusinessSubParentSampleAssessmentMapper.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/dal/mapper/BusinessSubParentSampleAssessmentMapper.java @@ -4,8 +4,10 @@ import java.util.*; import com.zt.plat.framework.common.pojo.PageResult; import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX; +import com.zt.plat.framework.mybatis.core.query.MPJLambdaWrapperX; import com.zt.plat.module.qms.business.bus.controller.vo.*; import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSubParentSampleAssessmentDO; +import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigAssayMethodDO; import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX; import org.apache.ibatis.annotations.Mapper; @@ -48,4 +50,12 @@ public interface BusinessSubParentSampleAssessmentMapper extends BaseMapperX selectByBusinessSubParentSampleIdsAndAssayDepartmentId(List businessSubParentSampleIds, + Long assayDepartmentId) { + return selectJoinList(BusinessSubParentSampleAssessmentDO.class, new MPJLambdaWrapperX() + .leftJoin(ConfigAssayMethodDO.class, ConfigAssayMethodDO::getId, BusinessSubParentSampleAssessmentDO::getConfigAssayMethodId) + .in(BusinessSubParentSampleAssessmentDO::getBusinessSubParentSampleId, businessSubParentSampleIds) + .eq(ConfigAssayMethodDO::getAssayDepartmentId, assayDepartmentId)); + } + } \ No newline at end of file diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/dal/mapper/BusinessSubSampleAnalysisGroupMapper.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/dal/mapper/BusinessSubSampleAnalysisGroupMapper.java index 2e4a679..c513296 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/dal/mapper/BusinessSubSampleAnalysisGroupMapper.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/dal/mapper/BusinessSubSampleAnalysisGroupMapper.java @@ -46,6 +46,12 @@ public interface BusinessSubSampleAnalysisGroupMapper extends BaseMapperX selectByBusinessSubParentSampleIdsAndAssayDepartmentId(List businessSubParentSampleIds, Long assayDepartmentId) { + return selectList(new LambdaQueryWrapperX() + .in(BusinessSubSampleAnalysisGroupDO::getBusinessSubParentSampleId, businessSubParentSampleIds) + .eq(BusinessSubSampleAnalysisGroupDO::getAssayDepartmentId, assayDepartmentId)); + } + default List selectByBusinessSubSampleId(Long businessSubSampleId) { return selectList(new LambdaQueryWrapperX() .eq(BusinessSubSampleAnalysisGroupDO::getBusinessSubSampleId, businessSubSampleId)); diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleAnalysisServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleAnalysisServiceImpl.java index a28b2f9..c886791 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleAnalysisServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleAnalysisServiceImpl.java @@ -18,6 +18,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.zt.plat.framework.common.exception.ServiceException; import com.zt.plat.framework.common.util.object.BeanUtils; @@ -71,10 +72,12 @@ import com.zt.plat.module.qms.business.config.controller.vo.ConfigQCSampleMethod import com.zt.plat.module.qms.business.config.controller.vo.ConfigSubSampleMethodConfInfo; import com.zt.plat.module.qms.business.config.controller.vo.ConfigSubSampleMethodConfItem; import com.zt.plat.module.qms.business.config.controller.vo.ConfigSubSampleMethodConfPoint; +import com.zt.plat.module.qms.business.config.dal.dataobject.BaseSampleDO; import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigAssayMethodDO; import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigAssayMethodProjectCoefficientDO; import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigAssayMethodProjectRangeDO; import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigSubSampleMethodDO; +import com.zt.plat.module.qms.business.config.dal.mapper.BaseSampleMapper; import com.zt.plat.module.qms.business.config.dal.mapper.ConfigAssayMethodMapper; import com.zt.plat.module.qms.business.config.dal.mapper.ConfigAssayMethodProjectCoefficientMapper; import com.zt.plat.module.qms.business.config.dal.mapper.ConfigAssayMethodProjectRangeMapper; @@ -142,6 +145,9 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService { @Resource private BusinessSampleEntrustDetailMapper businessSampleEntrustDetailMapper; + @Resource + private BaseSampleMapper baseSampleMapper; + @Resource private BusinessSubParentSampleMapper businessSubParentSampleMapper; @@ -152,6 +158,7 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService { private DataCollectionService dataCollectionService; @Override + @Transactional(rollbackFor = Exception.class) public BusinessAssayTaskAnalysisSampleProjectRespVO batchSampleAnalysisByTaskId(Long businessAssayTaskId) { BusinessAssayTaskAnalysisSampleProjectRespVO businessAssayTaskAnalysisSampleProjectRespVO = new BusinessAssayTaskAnalysisSampleProjectRespVO(); BusinessAssayTaskDO businessAssayTaskDO = businessAssayTaskMapper.selectById(businessAssayTaskId); @@ -177,17 +184,27 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService { List cloumns = new ArrayList<>(); cloumns.add(new BatchSampleAnalysisColumnRespVO("sampleCode", "sampleCode", "样品编号", "200px", "200px", "string", null, null, null, null, false, null, null, null, null, null, null)); cloumns.add(new BatchSampleAnalysisColumnRespVO("sampleName", "sampleName", "样品名称", "200px", "200px", "string", null, null, null, null, false, null, null, null, null, null, null)); - //cloumns.add(new BatchSampleAnalysisColumnRespVO("cupNumber", "cupNumber", "杯号", "200px", "200px", "string", null, null, null, null, true, null)); List businessAssayTaskDetailList = businessAssayTaskDetailMapper.selectList(new LambdaQueryWrapperX().eq(BusinessAssayTaskDetailDO::getBusinessAssayTaskId, businessAssayTaskId)); List businessAssayTaskDataList = businessAssayTaskDataMapper.selectList(new LambdaQueryWrapperX().eq(BusinessAssayTaskDataDO::getBusinessAssayTaskId, businessAssayTaskId).eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId())); List businessAssayTaskDataIdList = businessAssayTaskDataList.stream().map(m -> m.getId()).collect(Collectors.toList()); - //BusinessAssayTaskDataDO businessAssayTaskData = businessAssayTaskDataList.get(0); + + + //子样Id列表 + List businessSubSampleIdList = businessAssayTaskDataList.stream().map(m -> m.getBusinessSubSampleId()).distinct().collect(Collectors.toList()); + + //子样列表 + List businessSubSampleDOList = businessSubSampleMapper.selectByIds(businessSubSampleIdList); + //子样配置id列表 + List configSubSampleIdList = businessSubSampleDOList.stream().map(m -> m.getConfigSubSampleId()).distinct().collect(Collectors.toList()); + + //子样方法配置列表 + List configSubSampleMethodDOList = configSubSampleMethodMapper.selectByConfigSubSampleIdsAndConfigAssayMethodId(configSubSampleIdList, businessAssayTaskDO.getConfigAssayMethodId()); + BusinessAssayProjectDataReqVO projectDataSearch = new BusinessAssayProjectDataReqVO(); -// projectDataSearch.setBusinessAssayTaskDataId(businessAssayTaskData.getId()); projectDataSearch.setBusinessAssayTaskDataIdList(businessAssayTaskDataIdList); List projectAndParameterList = businessAssayProjectDataMapper.selectProjectAndParameterBy(projectDataSearch); @@ -215,24 +232,6 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService { } } -// for (BusinessAssayProjectAndParameterRespVO ep : projectAndParameterList) { -// String fieldIndex = "e" + ep.getDicId(); -// String title = ep.getShowName() + (StringUtils.isBlank(ep.getUnit()) ? "" : "(" + ep.getUnit() + ")"); -// boolean isEdit = StringUtils.isBlank(ep.getFormula()); -// cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title, "", "120px", ep.getDataType(), ep.getDecimalPosition(), null, ep.getFormula(), ep.getParamNo(), isEdit, ep.getUnit(), "project", ep.getFillingWay(), ep.getGroupDictionaryBusinessId(), ep.getGroupDictionaryBusinessKey(), ep.getGroupDictionaryBusinessName())); -// -// if (StringUtils.isNotEmpty(ep.getFormula())) { -// BusinessAssayParameterDataReqVO parameterDataSearch = new BusinessAssayParameterDataReqVO(); -// parameterDataSearch.setBusinessAssayProjectDataId(ep.getId()); -// List plist = businessAssayParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch); -// for (BusinessAssayProjectAndParameterRespVO p : plist) { -// fieldIndex = "p" + p.getDicId(); -// title = p.getShowName() + (StringUtils.isBlank(p.getUnit()) ? "" : "(" + p.getUnit() + ")"); -// isEdit = StringUtils.isBlank(p.getFormula()); -// cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title, "", "120px", p.getDataType(), p.getDecimalPosition(), null, p.getFormula(), p.getParamNo(), isEdit, p.getUnit(), "parameter", p.getFillingWay(), p.getGroupDictionaryBusinessId(), p.getGroupDictionaryBusinessKey(), p.getGroupDictionaryBusinessName())); -// } -// } -// } businessAssayTaskAnalysisSampleProjectRespVO.setColumns(cloumns); @@ -241,6 +240,91 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService { for (BusinessAssayTaskDataDO businessAssayTaskDataDO : businessAssayTaskDataList) { BusinessAssayTaskDetailDO businessAssayTaskDetailDO = businessAssayTaskDetailList.stream().filter(f -> f.getBusinessAssayTaskDataId().equals(businessAssayTaskDataDO.getId())).findFirst().orElse(null); + + BusinessSubSampleDO businessSubSampleDO = businessSubSampleDOList.stream().filter(f -> f.getId().equals(businessAssayTaskDataDO.getBusinessSubSampleId())).findFirst().orElse(null); + ConfigSubSampleMethodDO configSubSampleMethodDO = configSubSampleMethodDOList.stream().filter(f -> f.getConfigAssayMethodId().equals(businessAssayTaskDataDO.getConfigAssayMethodId()) && f.getConfigSubSampleId().equals(businessSubSampleDO.getConfigSubSampleId())).findFirst().orElse(null); + String configInfomation = configSubSampleMethodDO.getConfigInfomation(); + if (StringUtils.isNotBlank(configInfomation)) { + ConfigSubSampleMethodConfInfo configSubSampleMethodConfInfo = JSON.parseObject(configInfomation, ConfigSubSampleMethodConfInfo.class); + List getParamList = configSubSampleMethodConfInfo.getGetParam(); + for (ConfigSubSampleMethodConfItem configSubSampleMethodConfItem: getParamList) { + //Boolean required = configSubSampleMethodConfItem.getRequired();//是否必须 + ConfigSubSampleMethodConfPoint source = configSubSampleMethodConfItem.getSource();//来源 + Long configMethodId = source.getMethodId(); + String sourceProject = source.getProject(); + //String sourceParameter = source.getParameter(); + + + ConfigSubSampleMethodConfPoint target = configSubSampleMethodConfItem.getTarget();//目标 + String targetProject = target.getProject(); + String targetParameter = target.getParameter(); + + BusinessAssayParameterDataDO businessAssayParameterDataDO = businessAssayParameterDataMapper.selectByBusinessAssayTaskDataIdAndProjectSimpleNameAndParameterKey(businessAssayTaskDataDO.getId(), targetProject, targetParameter); + if (StringUtils.isBlank(businessAssayParameterDataDO.getValue())) { + //1 查询委托明细 + BusinessSampleEntrustDetailDO businessSampleEntrustDetailDO = businessSampleEntrustDetailMapper.selectByBusinessBaseSampleId(businessAssayTaskDataDO.getBusinessBaseSampleId()); + //2 查询样品大类 + BaseSampleDO baseSampleDO = baseSampleMapper.selectById(businessSampleEntrustDetailDO.getBaseSampleId()); + //3 判断样品大类类型 + if (QmsCommonConstant.ENTRUST_INSPECTION_ANALYSIS_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是商检分析样 + //查询当前批次的第一个商检分析样 + BusinessSampleEntrustDetailDO currBatchFirstBusinessSampleEntrustDetailDO = businessSampleEntrustDetailMapper.selectCurrBatchFirstByBusinessBaseSampleIdAndBaseSampleDictionaryBusinessKey(businessAssayTaskDataDO.getBusinessBaseSampleId(), QmsCommonConstant.ENTRUST_INSPECTION_ANALYSIS_SAMPLE); + List currBusinessSubParentSampleDOList = businessSubParentSampleMapper.selectByBusinessBaseSampleId(currBatchFirstBusinessSampleEntrustDetailDO.getBusinessBaseSampleId()); + List currBusinessSubParentSampleIdList = currBusinessSubParentSampleDOList.stream().map(m -> m.getId()).collect(Collectors.toList()); + List businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(currBusinessSubParentSampleIdList, configMethodId); + BusinessSubParentSampleAssessmentProjectExtendRespVO businessSubParentSampleAssessmentProject = businessSubParentSampleAssessmentProjectList.stream().filter(f -> f.getSimpleName().equals(sourceProject)).findFirst().orElse(null); + if (businessSubParentSampleAssessmentProject != null && StringUtils.isNotBlank(businessSubParentSampleAssessmentProject.getAssessmentValue())) { + businessAssayParameterDataDO.setValue(businessSubParentSampleAssessmentProject.getAssessmentValue()); + } + } else if (QmsCommonConstant.ENTRUST_COMPREHENSIVE_INSPECTION_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是商检综合样 + //查询当前样品的其他分析方法的结果 + List businessSubParentSampleIdList = Arrays.asList(businessAssayTaskDataDO.getBusinessSubParentSampleId()); + List businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(businessSubParentSampleIdList, configMethodId); + BusinessSubParentSampleAssessmentProjectExtendRespVO businessSubParentSampleAssessmentProject = businessSubParentSampleAssessmentProjectList.stream().filter(f -> f.getSimpleName().equals(sourceProject)).findFirst().orElse(null); + if (businessSubParentSampleAssessmentProject == null || StringUtils.isBlank(businessSubParentSampleAssessmentProject.getAssessmentValue())) { + businessAssayParameterDataDO.setValue(businessSubParentSampleAssessmentProject.getAssessmentValue()); + } + } else if (QmsCommonConstant.ENTRUST_COMMISSION_INSPECTION_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是委检样 + //查询来样品位 + Boolean isForecastS = false; + String forecastValue = null; + String forecastResult = businessSampleEntrustDetailDO.getForecastResult(); + if (StringUtils.isNotBlank(forecastResult)) { + JSONArray array = JSON.parseArray(forecastResult); + for (int i = 0; i < array.size(); i++) { + JSONObject item = array.getJSONObject(i); + if ("S".equals(item.getString("simpleName"))) { + isForecastS = true; + break; + } + } + for (int i = 0; i < array.size(); i++) { + JSONObject item = array.getJSONObject(i); + if (sourceProject.equals(item.getString("simpleName"))) { + forecastValue = item.getString("value"); + break; + } + } + } + if (isForecastS) {//来样品位存在S值, 则取预报的值 + businessAssayParameterDataDO.setValue(forecastValue); + } else { + //查询当前样品的其他方法的结果 + List businessSubParentSampleIdList = Arrays.asList(businessAssayTaskDataDO.getBusinessSubParentSampleId()); + List businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(businessSubParentSampleIdList, configMethodId); + BusinessSubParentSampleAssessmentProjectExtendRespVO businessSubParentSampleAssessmentProject = businessSubParentSampleAssessmentProjectList.stream().filter(f -> f.getSimpleName().equals(sourceProject)).findFirst().orElse(null); + if (businessSubParentSampleAssessmentProject == null || StringUtils.isBlank(businessSubParentSampleAssessmentProject.getAssessmentValue())) { + businessAssayParameterDataDO.setValue(businessSubParentSampleAssessmentProject.getAssessmentValue()); + } + } + + } + + businessAssayParameterDataMapper.updateById(businessAssayParameterDataDO); + } + } + } + Map map = new HashedMap<>(); map.put("businessAssayTaskDataId", businessAssayTaskDataDO.getId()); map.put("businessAssayTaskId", businessAssayTaskDataDO.getBusinessAssayTaskId()); @@ -405,6 +489,7 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService { } @Override + @Transactional(rollbackFor = Exception.class) public BusinessAssayTaskAnalysisSampleAndQcProjectRespVO batchSampleAndQcAnalysisByTaskId(Long businessAssayTaskId) { BusinessAssayTaskAnalysisSampleAndQcProjectRespVO businessAssayTaskAnalysisSampleAndQcProjectRespVO = new BusinessAssayTaskAnalysisSampleAndQcProjectRespVO(); BusinessAssayTaskDO businessAssayTaskDO = businessAssayTaskMapper.selectById(businessAssayTaskId); @@ -437,9 +522,6 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService { assayTaskAnalysisDataList.add(analysis); businessAssayTaskAnalysisSampleAndQcProjectRespVO.setAssayTaskAnalysisDataList(assayTaskAnalysisDataList); - -// List configQCSampleMethodList = configQCSampleMethodMapper.selectByConfigAssayMethodId(businessAssayTaskDO.getConfigAssayMethodId()); -// businessAssayTaskAnalysisSampleAndQcProjectRespVO.setConfigQCSampleMethodList(configQCSampleMethodList); //查询区间范围 List configAssayMethodProjectRangeDOList = configAssayMethodProjectRangeMapper.selectList(new LambdaQueryWrapperX().eq(ConfigAssayMethodProjectRangeDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId())); @@ -462,9 +544,7 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService { //处理列 List cloumns = new ArrayList<>(); cloumns.add(new BatchSampleAnalysisColumnRespVO("sampleCode", "sampleCode", "样品编号", "200px", "200px", "string", null, null, null, null, false, null, null, null, null, null, null)); - cloumns.add(new BatchSampleAnalysisColumnRespVO("sampleName", "sampleName", "样品名称", "200px", "200px", "string", null, null, null, null, false, null, null, null, null, null, null)); - //cloumns.add(new BatchSampleAnalysisColumnRespVO("cupNumber", "cupNumber", "杯号", "200px", "200px", "string", null, null, null, null, true, null)); - + cloumns.add(new BatchSampleAnalysisColumnRespVO("sampleName", "sampleName", "样品名称", "200px", "200px", "string", null, null, null, null, false, null, null, null, null, null, null)); List businessAssayTaskDetailList = businessAssayTaskDetailMapper.selectList(new LambdaQueryWrapperX().eq(BusinessAssayTaskDetailDO::getBusinessAssayTaskId, businessAssayTaskDO.getId())); List businessAssayTaskDataList = businessAssayTaskDataMapper.selectList(new LambdaQueryWrapperX().eq(BusinessAssayTaskDataDO::getBusinessAssayTaskId, businessAssayTaskDO.getId()).eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId())); @@ -482,10 +562,8 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService { List businessAssayTaskDataIdList = businessAssayTaskDataList.stream().map(m -> m.getId()).collect(Collectors.toList()); - // BusinessAssayTaskDataDO businessAssayTaskData = businessAssayTaskDataList.get(0); BusinessAssayProjectDataReqVO projectDataSearch = new BusinessAssayProjectDataReqVO(); -// projectDataSearch.setBusinessAssayTaskDataId(businessAssayTaskData.getId()); projectDataSearch.setBusinessAssayTaskDataIdList(businessAssayTaskDataIdList); List projectAndParameterList = businessAssayProjectDataMapper.selectProjectAndParameterBy(projectDataSearch); Map> projectAndParameterMap = projectAndParameterList.stream().sorted(Comparator.comparing(BusinessAssayProjectAndParameterRespVO::getParamNo)).collect(Collectors.groupingBy(BusinessAssayProjectAndParameterRespVO::getDicId, @@ -511,24 +589,7 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService { } } } -// for (BusinessAssayProjectAndParameterRespVO ep : projectAndParameterList) { -// String fieldIndex = "e" + ep.getDicId(); -// String title = ep.getShowName() + (StringUtils.isBlank(ep.getUnit()) ? "" : "(" + ep.getUnit() + ")"); -// boolean isEdit = StringUtils.isBlank(ep.getFormula()); -// cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title, "", "120px", ep.getDataType(), ep.getDecimalPosition(), null, ep.getFormula(), ep.getParamNo(), isEdit, ep.getUnit(), "project", ep.getFillingWay(), ep.getGroupDictionaryBusinessId(), ep.getGroupDictionaryBusinessKey(), ep.getGroupDictionaryBusinessName())); -// -// if (StringUtils.isNotEmpty(ep.getFormula())) { -// BusinessAssayParameterDataReqVO parameterDataSearch = new BusinessAssayParameterDataReqVO(); -// parameterDataSearch.setBusinessAssayProjectDataId(ep.getId()); -// List plist = businessAssayParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch); -// for (BusinessAssayProjectAndParameterRespVO p : plist) { -// fieldIndex = "p" + p.getDicId(); -// title = p.getShowName() + (StringUtils.isBlank(p.getUnit()) ? "" : "(" + p.getUnit() + ")"); -// isEdit = StringUtils.isBlank(p.getFormula()); -// cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title, "", "120px", p.getDataType(), p.getDecimalPosition(), null, p.getFormula(), p.getParamNo(), isEdit, p.getUnit(), "parameter", p.getFillingWay(), p.getGroupDictionaryBusinessId(), p.getGroupDictionaryBusinessKey(), p.getGroupDictionaryBusinessName())); -// } -// } -// } + businessAssayTaskAnalysisDataRespVO.setColumns(cloumns); @@ -557,36 +618,65 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService { BusinessAssayParameterDataDO businessAssayParameterDataDO = businessAssayParameterDataMapper.selectByBusinessAssayTaskDataIdAndProjectSimpleNameAndParameterKey(businessAssayTaskDataDO.getId(), targetProject, targetParameter); if (StringUtils.isBlank(businessAssayParameterDataDO.getValue())) { - //1 查询来源品位 + //1 查询委托明细 BusinessSampleEntrustDetailDO businessSampleEntrustDetailDO = businessSampleEntrustDetailMapper.selectByBusinessBaseSampleId(businessAssayTaskDataDO.getBusinessBaseSampleId()); - String forecastResult = businessSampleEntrustDetailDO.getForecastResult();//预报品位 - if (StringUtils.isBlank(forecastResult)) { - //2 查询当前样品其他分析方法的结果 (废弃-20251202) -// List businessSubParentSampleIdList = Arrays.asList(businessAssayTaskDataDO.getBusinessSubParentSampleId()); -// List businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(businessSubParentSampleIdList, configMethodId); -// BusinessSubParentSampleAssessmentProjectExtendRespVO businessSubParentSampleAssessmentProject = businessSubParentSampleAssessmentProjectList.stream().filter(f -> f.getSimpleName().equals(sourceProject)).findFirst().orElse(null); -// if (businessSubParentSampleAssessmentProject == null || StringUtils.isBlank(businessSubParentSampleAssessmentProject.getAssessmentValue())) { - - //3 查询当前批次委托的第一个样品对应的分析方法的结果 - BusinessSampleEntrustDetailDO currBatchFirstBusinessSampleEntrustDetailDO = businessSampleEntrustDetailMapper.selectCurrBatchFirstByBusinessBaseSampleId(businessAssayTaskDataDO.getBusinessBaseSampleId()); - List currBusinessSubParentSampleDOList = businessSubParentSampleMapper.selectByBusinessBaseSampleId(currBatchFirstBusinessSampleEntrustDetailDO.getBusinessBaseSampleId()); - List currBusinessSubParentSampleIdList = currBusinessSubParentSampleDOList.stream().map(m -> m.getId()).collect(Collectors.toList()); - List businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(currBusinessSubParentSampleIdList, configMethodId); + //2 查询样品大类 + BaseSampleDO baseSampleDO = baseSampleMapper.selectById(businessSampleEntrustDetailDO.getBaseSampleId()); + //3 判断样品大类类型 + if (QmsCommonConstant.ENTRUST_INSPECTION_ANALYSIS_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是商检分析样 + //查询当前批次的第一个商检分析样 + BusinessSampleEntrustDetailDO currBatchFirstBusinessSampleEntrustDetailDO = businessSampleEntrustDetailMapper.selectCurrBatchFirstByBusinessBaseSampleIdAndBaseSampleDictionaryBusinessKey(businessAssayTaskDataDO.getBusinessBaseSampleId(), QmsCommonConstant.ENTRUST_INSPECTION_ANALYSIS_SAMPLE); + List currBusinessSubParentSampleDOList = businessSubParentSampleMapper.selectByBusinessBaseSampleId(currBatchFirstBusinessSampleEntrustDetailDO.getBusinessBaseSampleId()); + List currBusinessSubParentSampleIdList = currBusinessSubParentSampleDOList.stream().map(m -> m.getId()).collect(Collectors.toList()); + List businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(currBusinessSubParentSampleIdList, configMethodId); + BusinessSubParentSampleAssessmentProjectExtendRespVO businessSubParentSampleAssessmentProject = businessSubParentSampleAssessmentProjectList.stream().filter(f -> f.getSimpleName().equals(sourceProject)).findFirst().orElse(null); + if (businessSubParentSampleAssessmentProject != null && StringUtils.isNotBlank(businessSubParentSampleAssessmentProject.getAssessmentValue())) { + businessAssayParameterDataDO.setValue(businessSubParentSampleAssessmentProject.getAssessmentValue()); + } + } else if (QmsCommonConstant.ENTRUST_COMPREHENSIVE_INSPECTION_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是商检综合样 + //查询当前样品的其他分析方法的结果 + List businessSubParentSampleIdList = Arrays.asList(businessAssayTaskDataDO.getBusinessSubParentSampleId()); + List businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(businessSubParentSampleIdList, configMethodId); + BusinessSubParentSampleAssessmentProjectExtendRespVO businessSubParentSampleAssessmentProject = businessSubParentSampleAssessmentProjectList.stream().filter(f -> f.getSimpleName().equals(sourceProject)).findFirst().orElse(null); + if (businessSubParentSampleAssessmentProject == null || StringUtils.isBlank(businessSubParentSampleAssessmentProject.getAssessmentValue())) { + businessAssayParameterDataDO.setValue(businessSubParentSampleAssessmentProject.getAssessmentValue()); + } + } else if (QmsCommonConstant.ENTRUST_COMMISSION_INSPECTION_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是委检样 + //查询来样品位 + Boolean isForecastS = false; + String forecastValue = null; + String forecastResult = businessSampleEntrustDetailDO.getForecastResult(); + if (StringUtils.isNotBlank(forecastResult)) { + JSONArray array = JSON.parseArray(forecastResult); + for (int i = 0; i < array.size(); i++) { + JSONObject item = array.getJSONObject(i); + if ("S".equals(item.getString("simpleName"))) { + isForecastS = true; + break; + } + } + for (int i = 0; i < array.size(); i++) { + JSONObject item = array.getJSONObject(i); + if (sourceProject.equals(item.getString("simpleName"))) { + forecastValue = item.getString("value"); + break; + } + } + } + if (isForecastS) {//来样品位存在S值, 则取预报的值 + businessAssayParameterDataDO.setValue(forecastValue); + } else { + //查询当前样品的其他方法的结果 + List businessSubParentSampleIdList = Arrays.asList(businessAssayTaskDataDO.getBusinessSubParentSampleId()); + List businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(businessSubParentSampleIdList, configMethodId); BusinessSubParentSampleAssessmentProjectExtendRespVO businessSubParentSampleAssessmentProject = businessSubParentSampleAssessmentProjectList.stream().filter(f -> f.getSimpleName().equals(sourceProject)).findFirst().orElse(null); - if (businessSubParentSampleAssessmentProject != null && StringUtils.isNotBlank(businessSubParentSampleAssessmentProject.getAssessmentValue())) { + if (businessSubParentSampleAssessmentProject == null || StringUtils.isBlank(businessSubParentSampleAssessmentProject.getAssessmentValue())) { businessAssayParameterDataDO.setValue(businessSubParentSampleAssessmentProject.getAssessmentValue()); } -// } else { -// businessAssayParameterDataDO.setValue(businessSubParentSampleAssessmentProject.getAssessmentValue()); -// } - - - } else { - JSONObject forecastResultJson = JSON.parseObject(forecastResult); - + } } - + businessAssayParameterDataMapper.updateById(businessAssayParameterDataDO); } } diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleResultReportingServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleResultReportingServiceImpl.java index 45a9013..5ce2a83 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleResultReportingServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleResultReportingServiceImpl.java @@ -432,8 +432,7 @@ public class SampleResultReportingServiceImpl implements SampleResultReportingSe //当前登录用户昵称 String nickName = SecurityFrameworkUtils.getLoginUserNickname(); - - + List updateBusinessSubSampleDOList = new ArrayList<>(); List updateBusinessSubSampleAnalysisGroupDOList = new ArrayList<>(); @@ -444,8 +443,6 @@ public class SampleResultReportingServiceImpl implements SampleResultReportingSe List businessSubParentSampleDOList = businessSubParentSampleMapper.selectByIds(reqVO.getBusinessSubParentSampleIds()); -// List businessSubParentSampleAssessmentDOList = businessSubParentSampleAssessmentMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(reqVO.getBusinessSubParentSampleIds(), reqVO.getConfigAssayMethodId()); - //循环分样主样数据 for (BusinessSubParentSampleDO businessSubParentSampleDO : businessSubParentSampleDOList) { @@ -538,8 +535,9 @@ public class SampleResultReportingServiceImpl implements SampleResultReportingSe } } + /** //处理子样分析任务数据 - List businessAssayTaskDataDOList = businessAssayTaskDataMapper.selectByBusinessSubParentSampleIds(reqVO.getBusinessSubParentSampleIds()); + List businessAssayTaskDataDOList = businessAssayTaskDataMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(reqVO.getBusinessSubParentSampleIds(), reqVO.getConfigAssayMethodId()); List businessSubSampleIdList = businessAssayTaskDataDOList.stream().map(m -> m.getBusinessSubSampleId()).distinct().collect(Collectors.toList()); List businessSubSampleDOList = businessSubSampleMapper.selectByIds(businessSubSampleIdList); List businessSubSampleAnalysisGroupDOList = businessSubSampleAnalysisGroupMapper.selectByBusinessSubParentSampleIds(reqVO.getBusinessSubParentSampleIds()); @@ -566,6 +564,26 @@ public class SampleResultReportingServiceImpl implements SampleResultReportingSe } + **/ + //分析方法信息 + ConfigAssayMethodDO configAssayMethodDO = configAssayMethodMapper.selectById(reqVO.getConfigAssayMethodId()); + //查询当前分析部门下的分样判定信息 + List businessSubParentSampleAssessmentDOList = businessSubParentSampleAssessmentMapper.selectByBusinessSubParentSampleIdsAndAssayDepartmentId(reqVO.getBusinessSubParentSampleIds(), configAssayMethodDO.getAssayDepartmentId()); + //查询当前分析部门下的子样分析班组信息 + List businessSubSampleAnalysisGroupDOList = businessSubSampleAnalysisGroupMapper.selectByBusinessSubParentSampleIdsAndAssayDepartmentId(reqVO.getBusinessSubParentSampleIds(), configAssayMethodDO.getAssayDepartmentId()); + for (BusinessSubSampleAnalysisGroupDO businessSubSampleAnalysisGroupDO : businessSubSampleAnalysisGroupDOList) {//循环分析班组信息 + //查询当前分样判定上报未上报的,并排除当前上报的方法,的数量 + long count = businessSubParentSampleAssessmentDOList.stream().filter(f -> f.getBusinessSubParentSampleId().equals(businessSubSampleAnalysisGroupDO.getBusinessSubParentSampleId()) && !f.getConfigAssayMethodId().equals(reqVO.getConfigAssayMethodId()) && f.getIsReported().equals(QmsCommonConstant.NO)).count(); + if (count > 0) {//如果还存在未上报的数据,则继续 + continue; + } + businessSubSampleAnalysisGroupDO.setSampleStatus("已完成");//当前班组分析已完成 + updateBusinessSubSampleAnalysisGroupDOList.add(businessSubSampleAnalysisGroupDO); + //查询子样 + BusinessSubSampleDO businessSubSampleDO = businessSubSampleMapper.selectById(businessSubSampleAnalysisGroupDO.getBusinessSubSampleId()); + updateBusinessSubSampleDOList.add(businessSubSampleDO); + } + if (saveBusinessAssayReportDataDOList.size() > 0) { businessAssayReportDataMapper.insertBatch(saveBusinessAssayReportDataDOList); diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/config/controller/admin/ConfigReportTemplateController.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/config/controller/admin/ConfigReportTemplateController.java index 4cd4efd..1a0369f 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/config/controller/admin/ConfigReportTemplateController.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/config/controller/admin/ConfigReportTemplateController.java @@ -3,109 +3,41 @@ package com.zt.plat.module.qms.business.config.controller.admin; import com.zt.plat.module.qms.business.config.controller.vo.ConfigReportTemplatePageReqVO; import com.zt.plat.module.qms.business.config.controller.vo.ConfigReportTemplateRespVO; import com.zt.plat.module.qms.business.config.controller.vo.ConfigReportTemplateSaveReqVO; -import com.zt.plat.module.qms.business.config.controller.vo.GenReportBody; import org.springframework.web.bind.annotation.*; -import org.springframework.web.util.UriUtils; - -import com.alibaba.fastjson.JSON; -import com.baomidou.mybatisplus.core.toolkit.StringPool; - import jakarta.annotation.Resource; import org.springframework.validation.annotation.Validated; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.text.StringEscapeUtils; -import org.springframework.core.io.ByteArrayResource; -import org.springframework.core.io.FileSystemResource; -import org.springframework.core.io.support.ResourceRegion; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; import com.zt.plat.framework.business.interceptor.BusinessControllerMarker; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; -import lombok.extern.slf4j.Slf4j; import jakarta.validation.*; import jakarta.servlet.http.*; -import java.io.File; import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Collection; -import java.util.HashMap; import java.util.List; -import java.util.Map; - import com.zt.plat.framework.common.pojo.PageParam; import com.zt.plat.framework.common.pojo.PageResult; -import com.zt.plat.framework.common.exception.ServiceException; import com.zt.plat.framework.common.pojo.CommonResult; import com.zt.plat.framework.common.util.object.BeanUtils; -import com.zt.plat.framework.common.util.servlet.ServletUtils; - import static com.zt.plat.framework.common.pojo.CommonResult.success; import com.zt.plat.framework.excel.core.util.ExcelUtils; -import com.zt.plat.framework.security.config.SecurityProperties; -import com.zt.plat.framework.security.core.LoginUser; -import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils; -import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.codec.Base64; -import cn.hutool.core.util.ArrayUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.http.HttpRequest; -import cn.hutool.http.HttpResponse; import com.zt.plat.framework.apilog.core.annotation.ApiAccessLog; import static com.zt.plat.framework.apilog.core.enums.OperateTypeEnum.*; import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigReportTemplateDO; -import com.zt.plat.module.qms.enums.ErrorCodeConstants; -import com.zt.plat.module.qms.framework.gridreport.GridReport; -import com.zt.plat.module.qms.framework.gridreport.PdfHelper; -import com.zt.plat.module.qms.framework.gridreport.exception.GridReportException; import com.zt.plat.module.qms.business.config.service.ConfigReportTemplateService; -import gridreport.jni.BinaryObject; -import gridreport.jni.ExportImageType; -import gridreport.jni.ExportType; -import gridreport.jni.Report; @Tag(name = "管理后台 - 报表模版配置") @RestController @RequestMapping("/qms/config-report-template") @Validated -@Slf4j -public class ConfigReportTemplateController { - - public static final String WR_PREFIX = "_WR_"; - - @Resource - private GridReport gridReport; - - @Resource - private SecurityProperties securityProperties; +public class ConfigReportTemplateController implements BusinessControllerMarker { @Resource private ConfigReportTemplateService configReportTemplateService; - @GetMapping("/info") - @Operation(summary = "获取报表信息") - public CommonResult info() { - Map data = new HashMap<>(); - try { - String moduleInfo = Report.getModuleInfo(); - String moduleVersion = Report.getModuleVersion(); - String modulePath = Report.getModulePath(); - data.put("moduleInfo", moduleInfo); - data.put("moduleVersion", moduleVersion); - data.put("modulePath", modulePath); - } catch (Exception e) { - } - return success(data); - } @PostMapping("/create") @Operation(summary = "创建报表模版配置") @@ -179,460 +111,4 @@ public class ConfigReportTemplateController { BeanUtils.toBean(list, ConfigReportTemplateRespVO.class)); } - /*** - * 预览报表 - * @param reportId - * @param reportKey - * @param dataUrl - * @param isCrypto - * @param type - * @return - * @throws Exception - */ - @GetMapping("/preview") - @Operation(summary = "预览报表") - public ResponseEntity preview(Long reportId, String reportKey, String dataUrl, Boolean isCrypto, String type) throws Exception { - HttpServletRequest request = ServletUtils.getRequest(); - ConfigReportTemplateDO gridppReportFile = null; - if (reportId != null) { - gridppReportFile = configReportTemplateService.getConfigReportTemplate(reportId); - } else if (StrUtil.isNotBlank(reportKey)) { - gridppReportFile = configReportTemplateService.getConfigReportTemplateByKey(reportKey); - } - if (ObjectUtil.isEmpty(gridppReportFile)) { - throw new ServiceException(ErrorCodeConstants.CONFIG_REPORT_TEMPLATE_NOT_EXISTS); - } - String reportData = StringEscapeUtils.unescapeHtml4(gridppReportFile.getData()); - - //报表参数 - Map reportParams = new HashMap<>(); - //获取当前用户姓名 - LoginUser user = SecurityFrameworkUtils.getLoginUser(); - String realName = ""; - if (user != null) { - realName = SecurityFrameworkUtils.getLoginUserNickname(); - } - reportParams.put("operName", realName); - - if (StrUtil.isNotBlank(dataUrl)) { - log.info("url:" + dataUrl); - dataUrl = StringEscapeUtils.unescapeHtml4(dataUrl); - log.info("url:" + dataUrl); - //处理url参数 - if(dataUrl.contains("?")) { - String urlParam = dataUrl.split("\\?")[1]; - String[] urlVks = urlParam.split("&"); - for (int i = 0; i < urlVks.length; i++) { - String vk = urlVks[i]; - if (StrUtil.isNotBlank(vk)) { - String[] vkSplit = vk.split("="); - if(vkSplit.length == 2){ - reportParams.put(vkSplit[0], vkSplit[1]); - } - } - } - } - - Map headers = new HashMap<>(); - String token = SecurityFrameworkUtils.obtainAuthorization(request, - securityProperties.getTokenHeader(), securityProperties.getTokenParameter()); - headers.put(securityProperties.getTokenHeader(), token); - HttpResponse res = HttpRequest.get(dataUrl) - .addHeaders(headers) - .setConnectionTimeout(60 * 1000) - .setReadTimeout(120 * 1000) - .execute(); - if (res.getStatus() != 200) { - log.error("报表数据,网络请求错误!", res.body()); - throw new GridReportException("报表数据,网络请求错误!"); - } - String body = res.body(); - CommonResult dataR = JSON.parseObject(body, CommonResult.class); - if (dataR != null && dataR.getCode() == 0) { - if (ArrayUtil.isArray(dataR.getData()) || dataR.getData() instanceof Collection) { - reportData = JSON.toJSONString(dataR); - } else { - reportData = JSON.toJSONString(dataR.getData()); - } - } else { - log.error("获取报表数据错误!", dataR.getMsg()); - log.error("报表数据:" + reportData); - throw new GridReportException("获取报表数据错误!"); - } - } - - - BinaryObject binaryObject = gridReport.genReport(gridppReportFile.getContent(), reportData, reportParams, ExportType.valueOf("OFD".equals(type.toUpperCase()) ? "PDF" : type.toUpperCase())); - MediaType mediaType = null; - byte[] docBytes = null; - //文件扩展名 - String fileExtName = type.toLowerCase(); - switch (type.toUpperCase()) { - case "PDF": - mediaType = MediaType.APPLICATION_PDF; - docBytes = PdfHelper.modifyDocInfo(binaryObject.getDataBuf()); - break; - case "OFD": - mediaType = MediaType.APPLICATION_OCTET_STREAM; - docBytes = PdfHelper.modifyDocInfo(binaryObject.getDataBuf()); - break; - case "RTF": - fileExtName = "doc"; - mediaType = MediaType.APPLICATION_OCTET_STREAM; - docBytes = binaryObject.getDataBuf(); - break; - default: - mediaType = MediaType.APPLICATION_OCTET_STREAM; - docBytes = binaryObject.getDataBuf(); - break; - } - - return browser(new ByteArrayResource(docBytes), gridppReportFile.getName() + "." + fileExtName, mediaType); - } - - @GetMapping("/previewDocs") - @Operation(summary = "报告预览报表") - public ResponseEntity previewDocs(Long reportId, String reportKey, String dataUrl, Boolean isCrypto, String type) throws Exception { - HttpServletRequest request = ServletUtils.getRequest(); - ConfigReportTemplateDO gridppReportFile = null; - if (reportId != null) { - gridppReportFile = configReportTemplateService.getConfigReportTemplate(reportId); - } else if (StrUtil.isNotBlank(reportKey)) { - gridppReportFile = configReportTemplateService.getConfigReportTemplateByKey(reportKey); - } - if (ObjectUtil.isEmpty(gridppReportFile)) { - throw new GridReportException("未找到报表模板!"); - } - String reportData = StringEscapeUtils.unescapeHtml4(gridppReportFile.getData()); - - //报表参数 - Map reportParams = new HashMap<>(); - //获取当前用户姓名 - LoginUser user = SecurityFrameworkUtils.getLoginUser(); - String realName = ""; - if (user != null) { - realName = SecurityFrameworkUtils.getLoginUserNickname(); - } - reportParams.put("operName", realName); - - if (StrUtil.isNotBlank(dataUrl)) { - log.info("url:" + dataUrl); - dataUrl = StringEscapeUtils.unescapeHtml4(dataUrl); - log.info("url:" + dataUrl); - - - Map headers = new HashMap<>(); - String token = SecurityFrameworkUtils.obtainAuthorization(request, - securityProperties.getTokenHeader(), securityProperties.getTokenParameter()); - headers.put(securityProperties.getTokenHeader(), token); - HttpResponse res = HttpRequest.get(dataUrl) - .addHeaders(headers) - .setConnectionTimeout(60 * 1000) - .setReadTimeout(120 * 1000) - .execute(); - if (res.getStatus() != 200) { - log.error("报表数据,网络请求错误!", res.body()); - throw new GridReportException("报表数据,网络请求错误!"); - } - String body = res.body(); - CommonResult dataR = JSON.parseObject(body, CommonResult.class); - if (dataR != null && dataR.getCode() == 0) { - if (ArrayUtil.isArray(dataR.getData()) || dataR.getData() instanceof Collection) { - reportData = JSON.toJSONString(dataR); - } else { - - Map map = BeanUtil.beanToMap(dataR.getData()); - for (Map.Entry obj : BeanUtil.beanToMap(map.get("reportParams")).entrySet()) { - reportParams.put(obj.getKey(), obj.getValue() == null ? "": obj.getValue().toString()); - } - reportData = JSON.toJSONString(dataR.getData()); - } - } else { - log.error("获取报表数据错误!", dataR.getMsg()); - log.error("报表数据:" + reportData); - throw new GridReportException("获取报表数据错误!"); - } - - } - - BinaryObject binaryObject = gridReport.genReport(gridppReportFile.getContent(), reportData, reportParams, ExportType.valueOf("OFD".equals(type.toUpperCase()) ? "PDF" : type.toUpperCase())); - MediaType mediaType = null; - byte[] docBytes = null; - //文件扩展名 - String fileExtName = type.toLowerCase(); - switch (type.toUpperCase()) { - case "PDF": - mediaType = MediaType.APPLICATION_PDF; - docBytes = PdfHelper.modifyDocInfo(binaryObject.getDataBuf()); - break; - case "OFD": - mediaType = MediaType.APPLICATION_OCTET_STREAM; - docBytes = PdfHelper.modifyDocInfo(binaryObject.getDataBuf()); - break; - case "RTF": - fileExtName = "doc"; - mediaType = MediaType.APPLICATION_OCTET_STREAM; - docBytes = binaryObject.getDataBuf(); - break; - case "IMG": - fileExtName = "png"; - mediaType = MediaType.IMAGE_PNG; - docBytes = binaryObject.getDataBuf(); - break; - default: - mediaType = MediaType.APPLICATION_OCTET_STREAM; - docBytes = binaryObject.getDataBuf(); - break; - } - - return browser(new ByteArrayResource(docBytes), gridppReportFile.getName() + "." + fileExtName, mediaType); - } - - @GetMapping("/export") - @Operation(summary = "导出报表") - public ResponseEntity export(Long reportId, String reportKey, String exportName, String dataUrl, Boolean isCrypto, String type) throws Exception { - HttpServletRequest request = ServletUtils.getRequest(); - ConfigReportTemplateDO gridppReportFile = null; - if (reportId != null) { - gridppReportFile = configReportTemplateService.getConfigReportTemplate(reportId); - } else if (StrUtil.isNotBlank(reportKey)) { - gridppReportFile = configReportTemplateService.getConfigReportTemplateByKey(reportKey); - } - if (ObjectUtil.isEmpty(gridppReportFile)) { - throw new GridReportException("未找到报表模板!"); - } - String reportData = StringEscapeUtils.unescapeHtml4(gridppReportFile.getData()); - - //报表参数 - Map reportParams = new HashMap<>(); - //获取当前用户姓名 - LoginUser user = SecurityFrameworkUtils.getLoginUser(); - String realName = ""; - if (user != null) { - realName = SecurityFrameworkUtils.getLoginUserNickname(); - } - reportParams.put("operName", realName); - - if (StrUtil.isNotBlank(dataUrl)) { - dataUrl = StringEscapeUtils.unescapeHtml4(dataUrl); - //处理url参数 - if (dataUrl.contains("?")) { - String urlParam = dataUrl.split("\\?")[1]; - String[] urlVks = urlParam.split("&"); - for (int i = 0; i < urlVks.length; i++) { - String vk = urlVks[i]; - if (StrUtil.isNotBlank(vk)) { - String[] vkSplit = vk.split("="); - if(vkSplit.length == 2){ - reportParams.put(vkSplit[0], vkSplit[1]); - } - } - } - } - Map headers = new HashMap<>(); - String token = SecurityFrameworkUtils.obtainAuthorization(request, - securityProperties.getTokenHeader(), securityProperties.getTokenParameter()); - headers.put(securityProperties.getTokenHeader(), token); - HttpResponse res = HttpRequest.get(dataUrl) - .addHeaders(headers) - .setConnectionTimeout(60 * 1000) - .setReadTimeout(120 * 1000) - .execute(); - if (res.getStatus() != 200) { - log.error("报表数据,网络请求错误!", res.body()); - throw new GridReportException("报表数据,网络请求错误!"); - } - String body = res.body(); - CommonResult dataR = JSON.parseObject(body, CommonResult.class); - if (dataR != null && dataR.getCode() == 0) { - if (ArrayUtil.isArray(dataR.getData()) || dataR.getData() instanceof Collection) { - reportData = JSON.toJSONString(dataR); - } else { - reportData = JSON.toJSONString(dataR.getData()); - } - } else { - log.error("获取报表数据错误!", dataR.getMsg()); - throw new GridReportException("获取报表数据错误!"); - } - } - - BinaryObject binaryObject = gridReport.genReport(gridppReportFile.getContent(), reportData, reportParams, ExportType.valueOf("OFD".equals(type.toUpperCase()) ? "PDF" : type.toUpperCase())); - byte[] docBytes = null; - //文件扩展名 - String fileExtName = type.toLowerCase(); - switch (type.toUpperCase()) { - case "PDF": - docBytes = PdfHelper.modifyDocInfo(binaryObject.getDataBuf()); - break; - case "OFD": - docBytes = PdfHelper.modifyDocInfo(binaryObject.getDataBuf()); - break; - case "RTF": - fileExtName = "doc"; - docBytes = binaryObject.getDataBuf(); - break; - case "IMG": - fileExtName = "png"; - docBytes = binaryObject.getDataBuf(); - break; - default: - docBytes = binaryObject.getDataBuf(); - break; - } - String fileName = gridppReportFile.getName(); - if (StrUtil.isNotBlank(exportName)) { - fileName = exportName; - } - return download(new ByteArrayResource(docBytes), fileName + "." + fileExtName); - } - - /** - * 生成Base64图片 - * @return - */ - @PostMapping("/gen-report-png-image-base64") - @Operation(summary = "生成Base64图片") - public CommonResult genReportPngImageBase64(@RequestBody GenReportBody body) { - ConfigReportTemplateDO gridppReportFile = null; - if (body.getReportId() != null) { - gridppReportFile = configReportTemplateService.getConfigReportTemplate(body.getReportId()); - } else if (StrUtil.isNotBlank(body.getReportKey())) { - gridppReportFile = configReportTemplateService.getConfigReportTemplateByKey(body.getReportKey()); - } - if (ObjectUtil.isEmpty(gridppReportFile)) { - throw new ServiceException(ErrorCodeConstants.CONFIG_REPORT_TEMPLATE_NOT_EXISTS); - } - - String imgBase64 = null; - try { - BinaryObject binaryObject = gridReport.genReport(gridppReportFile.getContent(), body.getReportDataJson(), body.getReportParams(), ExportType.IMG, ExportImageType.PNG, body.getImgDpi()); - imgBase64 = binaryObject.getAsBase64Text(); - } catch (Exception e) { - log.error("生成base64图片失败", e); - } - if (StringUtils.isBlank(imgBase64)) { - return CommonResult.error(1_032_100_000, "生成Base64图片失败"); - } - return success(imgBase64); - } - - /** - * 生成Base64图片 - * @return - */ - @PostMapping("/gen-report-png-image-base64-by-pdf") - @Operation(summary = "生成Base64图片") - public CommonResult genReportPngImageBase64ByPdf(@RequestBody GenReportBody body) { - ConfigReportTemplateDO gridppReportFile = null; - if (body.getReportId() != null) { - gridppReportFile = configReportTemplateService.getConfigReportTemplate(body.getReportId()); - } else if (StrUtil.isNotBlank(body.getReportKey())) { - gridppReportFile = configReportTemplateService.getConfigReportTemplateByKey(body.getReportKey()); - } - if (ObjectUtil.isEmpty(gridppReportFile)) { - throw new ServiceException(ErrorCodeConstants.CONFIG_REPORT_TEMPLATE_NOT_EXISTS); - } - - String imgBase64 = null; - try { - BinaryObject binaryObject = gridReport.genReport(gridppReportFile.getContent(), body.getReportDataJson(), body.getReportParams(), ExportType.PDF); - byte[] pngBytes = PdfHelper.pdfToPng(binaryObject.getDataBuf(), body.getImgDpi()); - //String encodeHexStr = HexUtil.encodeHexStr(pngBytes); - //System.out.println(encodeHexStr); - imgBase64 = Base64.encode(pngBytes); - } catch (Exception e) { - log.error("生成base64图片失败", e); - } - if (StringUtils.isBlank(imgBase64)) { - return CommonResult.error(1_032_100_000, "生成Base64图片失败"); - } - return success(imgBase64); - } - - /** - * 下载文件 - * - * @param file 文件 - * @return {ResponseEntity} - * @throws IOException io异常 - */ - protected ResponseEntity download(File file) throws IOException { - String fileName = file.getName(); - return download(file, fileName); - } - - /** - * 下载 - * - * @param file 文件 - * @param fileName 生成的文件名 - * @return {ResponseEntity} - * @throws IOException io异常 - */ - protected ResponseEntity download(File file, String fileName) throws IOException { - org.springframework.core.io.Resource resource = new FileSystemResource(file); - return download(resource, fileName); - } - - /** - * 下载 - * - * @param resource 资源 - * @param fileName 生成的文件名 - * @return {ResponseEntity} - * @throws IOException io异常 - */ - protected ResponseEntity download(org.springframework.core.io.Resource resource, String fileName) throws IOException { - HttpServletRequest request = ServletUtils.getRequest(); - String header = request.getHeader(HttpHeaders.USER_AGENT); - // 避免空指针 - header = header == null ? StringPool.EMPTY : header.toUpperCase(); - HttpStatus status= HttpStatus.OK; - // 断点续传 - long position = 0; - long count = resource.contentLength(); - String range = request.getHeader(HttpHeaders.RANGE); - if (null != range) { - status = HttpStatus.PARTIAL_CONTENT; - String[] rangeRange = range.replace("bytes=", StringPool.EMPTY).split(StringPool.DASH); - position = Long.parseLong(rangeRange[0]); - if (rangeRange.length > 1) { - long end = Long.parseLong(rangeRange[1]); - count = end - position + 1; - } - } - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); - String encodeFileName = UriUtils.encode(fileName, StandardCharsets.UTF_8); - // 兼容各种浏览器下载: - // https://blog.robotshell.org/2012/deal-with-http-header-encoding-for-file-download/ - String disposition = "attachment;" + - "filename=\"" + encodeFileName + "\";" + - "filename*=utf-8''" + encodeFileName; - headers.set(HttpHeaders.CONTENT_DISPOSITION, disposition); - return new ResponseEntity<>(new ResourceRegion(resource, position, count), headers, status); - } - - /** - * 浏览器打开 - * - * @param resource 资源 - * @param fileName 生成的文件名 - * @return {ResponseEntity} - * @throws IOException io异常 - */ - protected ResponseEntity browser(org.springframework.core.io.Resource resource, String fileName, MediaType mediaType) throws IOException { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(mediaType); - headers.setContentLength(resource.contentLength()); - String encodeFileName = UriUtils.encode(fileName, StandardCharsets.UTF_8); - // 兼容各种浏览器下载: - // https://blog.robotshell.org/2012/deal-with-http-header-encoding-for-file-download/ - String disposition = "inline;" + - "filename=\"" + encodeFileName + "\";" + - "filename*=utf-8''" + encodeFileName; - headers.set(HttpHeaders.CONTENT_DISPOSITION, disposition); - return new ResponseEntity<>(resource, headers, HttpStatus.OK); - } - } \ No newline at end of file diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/config/controller/admin/GridReportController.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/config/controller/admin/GridReportController.java new file mode 100644 index 0000000..9a564b0 --- /dev/null +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/config/controller/admin/GridReportController.java @@ -0,0 +1,556 @@ +package com.zt.plat.module.qms.business.config.controller.admin; + +import static com.zt.plat.framework.common.pojo.CommonResult.success; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.text.StringEscapeUtils; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.core.io.FileSystemResource; +import org.springframework.core.io.support.ResourceRegion; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.util.UriUtils; + +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.toolkit.StringPool; +import com.zt.plat.framework.common.exception.ServiceException; +import com.zt.plat.framework.common.pojo.CommonResult; +import com.zt.plat.framework.common.util.servlet.ServletUtils; +import com.zt.plat.framework.security.config.SecurityProperties; +import com.zt.plat.framework.security.core.LoginUser; +import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils; +import com.zt.plat.framework.web.core.util.WebFrameworkUtils; +import com.zt.plat.module.qms.business.config.controller.vo.GenReportBody; +import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigReportTemplateDO; +import com.zt.plat.module.qms.business.config.service.ConfigReportTemplateService; +import com.zt.plat.module.qms.enums.ErrorCodeConstants; +import com.zt.plat.module.qms.framework.gridreport.GridReport; +import com.zt.plat.module.qms.framework.gridreport.PdfHelper; +import com.zt.plat.module.qms.framework.gridreport.exception.GridReportException; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.codec.Base64; +import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import gridreport.jni.BinaryObject; +import gridreport.jni.ExportImageType; +import gridreport.jni.ExportType; +import gridreport.jni.Report; +import io.swagger.v3.oas.annotations.Operation; +import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletRequest; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RestController +@RequestMapping("/qms/config-report-template") +public class GridReportController { + + public static final String WR_PREFIX = "_WR_"; + + @Resource + private GridReport gridReport; + + @Resource + private SecurityProperties securityProperties; + + @Resource + private ConfigReportTemplateService configReportTemplateService; + + @GetMapping("/info") + @Operation(summary = "获取报表信息") + public CommonResult info() { + Map data = new HashMap<>(); + try { + String moduleInfo = Report.getModuleInfo(); + String moduleVersion = Report.getModuleVersion(); + String modulePath = Report.getModulePath(); + data.put("moduleInfo", moduleInfo); + data.put("moduleVersion", moduleVersion); + data.put("modulePath", modulePath); + } catch (Exception e) { + } + return success(data); + } + + /*** + * 预览报表 + * @param reportId + * @param reportKey + * @param dataUrl + * @param isCrypto + * @param type + * @return + * @throws Exception + */ + @GetMapping("/preview") + @Operation(summary = "预览报表") + public ResponseEntity preview(Long reportId, String reportKey, String dataUrl, Boolean isCrypto, String type) throws Exception { + HttpServletRequest request = ServletUtils.getRequest(); + ConfigReportTemplateDO gridppReportFile = null; + if (reportId != null) { + gridppReportFile = configReportTemplateService.getConfigReportTemplate(reportId); + } else if (StrUtil.isNotBlank(reportKey)) { + gridppReportFile = configReportTemplateService.getConfigReportTemplateByKey(reportKey); + } + if (ObjectUtil.isEmpty(gridppReportFile)) { + throw new ServiceException(ErrorCodeConstants.CONFIG_REPORT_TEMPLATE_NOT_EXISTS); + } + String reportData = StringEscapeUtils.unescapeHtml4(gridppReportFile.getData()); + + //报表参数 + Map reportParams = new HashMap<>(); + //获取当前用户姓名 + LoginUser user = SecurityFrameworkUtils.getLoginUser(); + String realName = ""; + if (user != null) { + realName = SecurityFrameworkUtils.getLoginUserNickname(); + } + reportParams.put("operName", realName); + + if (StrUtil.isNotBlank(dataUrl)) { + log.info("url:" + dataUrl); + dataUrl = StringEscapeUtils.unescapeHtml4(dataUrl); + log.info("url:" + dataUrl); + //处理url参数 + if(dataUrl.contains("?")) { + String urlParam = dataUrl.split("\\?")[1]; + String[] urlVks = urlParam.split("&"); + for (int i = 0; i < urlVks.length; i++) { + String vk = urlVks[i]; + if (StrUtil.isNotBlank(vk)) { + String[] vkSplit = vk.split("="); + if(vkSplit.length == 2){ + reportParams.put(vkSplit[0], vkSplit[1]); + } + } + } + } + + Map headers = new HashMap<>(); + String token = SecurityFrameworkUtils.obtainAuthorization(request, + securityProperties.getTokenHeader(), securityProperties.getTokenParameter()); + headers.put(securityProperties.getTokenHeader(), token); +// headers.put(WebFrameworkUtils.HEADER_VISIT_COMPANY_ID, user.getVisitCompanyId() + ""); +// headers.put(WebFrameworkUtils.HEADER_VISIT_DEPT_ID, user.getVisitDeptId() + ""); + + HttpResponse res = HttpRequest.get(dataUrl) + .addHeaders(headers) + .setConnectionTimeout(60 * 1000) + .setReadTimeout(120 * 1000) + .execute(); + if (res.getStatus() != 200) { + log.error("报表数据,网络请求错误!", res.body()); + throw new GridReportException("报表数据,网络请求错误!"); + } + String body = res.body(); + CommonResult dataR = JSON.parseObject(body, CommonResult.class); + if (dataR != null && dataR.getCode() == 0) { + if (ArrayUtil.isArray(dataR.getData()) || dataR.getData() instanceof Collection) { + reportData = JSON.toJSONString(dataR); + } else { + reportData = JSON.toJSONString(dataR.getData()); + } + } else { + log.error("获取报表数据错误!", dataR.getMsg()); + log.error("报表数据:" + reportData); + throw new GridReportException("获取报表数据错误!"); + } + } + + + BinaryObject binaryObject = gridReport.genReport(gridppReportFile.getContent(), reportData, reportParams, ExportType.valueOf("OFD".equals(type.toUpperCase()) ? "PDF" : type.toUpperCase())); + MediaType mediaType = null; + byte[] docBytes = null; + //文件扩展名 + String fileExtName = type.toLowerCase(); + switch (type.toUpperCase()) { + case "PDF": + mediaType = MediaType.APPLICATION_PDF; + docBytes = PdfHelper.modifyDocInfo(binaryObject.getDataBuf()); + break; + case "OFD": + mediaType = MediaType.APPLICATION_OCTET_STREAM; + docBytes = PdfHelper.modifyDocInfo(binaryObject.getDataBuf()); + break; + case "RTF": + fileExtName = "doc"; + mediaType = MediaType.APPLICATION_OCTET_STREAM; + docBytes = binaryObject.getDataBuf(); + break; + default: + mediaType = MediaType.APPLICATION_OCTET_STREAM; + docBytes = binaryObject.getDataBuf(); + break; + } + + return browser(new ByteArrayResource(docBytes), gridppReportFile.getName() + "." + fileExtName, mediaType); + } + + @GetMapping("/previewDocs") + @Operation(summary = "报告预览报表") + public ResponseEntity previewDocs(Long reportId, String reportKey, String dataUrl, Boolean isCrypto, String type) throws Exception { + HttpServletRequest request = ServletUtils.getRequest(); + ConfigReportTemplateDO gridppReportFile = null; + if (reportId != null) { + gridppReportFile = configReportTemplateService.getConfigReportTemplate(reportId); + } else if (StrUtil.isNotBlank(reportKey)) { + gridppReportFile = configReportTemplateService.getConfigReportTemplateByKey(reportKey); + } + if (ObjectUtil.isEmpty(gridppReportFile)) { + throw new GridReportException("未找到报表模板!"); + } + String reportData = StringEscapeUtils.unescapeHtml4(gridppReportFile.getData()); + + //报表参数 + Map reportParams = new HashMap<>(); + //获取当前用户姓名 + LoginUser user = SecurityFrameworkUtils.getLoginUser(); + String realName = ""; + if (user != null) { + realName = SecurityFrameworkUtils.getLoginUserNickname(); + } + reportParams.put("operName", realName); + + if (StrUtil.isNotBlank(dataUrl)) { + log.info("url:" + dataUrl); + dataUrl = StringEscapeUtils.unescapeHtml4(dataUrl); + log.info("url:" + dataUrl); + + + Map headers = new HashMap<>(); + String token = SecurityFrameworkUtils.obtainAuthorization(request, + securityProperties.getTokenHeader(), securityProperties.getTokenParameter()); + headers.put(securityProperties.getTokenHeader(), token); +// headers.put(WebFrameworkUtils.HEADER_VISIT_COMPANY_ID, user.getVisitCompanyId() + ""); +// headers.put(WebFrameworkUtils.HEADER_VISIT_DEPT_ID, user.getVisitDeptId() + ""); + HttpResponse res = HttpRequest.get(dataUrl) + .addHeaders(headers) + .setConnectionTimeout(60 * 1000) + .setReadTimeout(120 * 1000) + .execute(); + if (res.getStatus() != 200) { + log.error("报表数据,网络请求错误!", res.body()); + throw new GridReportException("报表数据,网络请求错误!"); + } + String body = res.body(); + CommonResult dataR = JSON.parseObject(body, CommonResult.class); + if (dataR != null && dataR.getCode() == 0) { + if (ArrayUtil.isArray(dataR.getData()) || dataR.getData() instanceof Collection) { + reportData = JSON.toJSONString(dataR); + } else { + + Map map = BeanUtil.beanToMap(dataR.getData()); + for (Map.Entry obj : BeanUtil.beanToMap(map.get("reportParams")).entrySet()) { + reportParams.put(obj.getKey(), obj.getValue() == null ? "": obj.getValue().toString()); + } + reportData = JSON.toJSONString(dataR.getData()); + } + } else { + log.error("获取报表数据错误!", dataR.getMsg()); + log.error("报表数据:" + reportData); + throw new GridReportException("获取报表数据错误!"); + } + + } + + BinaryObject binaryObject = gridReport.genReport(gridppReportFile.getContent(), reportData, reportParams, ExportType.valueOf("OFD".equals(type.toUpperCase()) ? "PDF" : type.toUpperCase())); + MediaType mediaType = null; + byte[] docBytes = null; + //文件扩展名 + String fileExtName = type.toLowerCase(); + switch (type.toUpperCase()) { + case "PDF": + mediaType = MediaType.APPLICATION_PDF; + docBytes = PdfHelper.modifyDocInfo(binaryObject.getDataBuf()); + break; + case "OFD": + mediaType = MediaType.APPLICATION_OCTET_STREAM; + docBytes = PdfHelper.modifyDocInfo(binaryObject.getDataBuf()); + break; + case "RTF": + fileExtName = "doc"; + mediaType = MediaType.APPLICATION_OCTET_STREAM; + docBytes = binaryObject.getDataBuf(); + break; + case "IMG": + fileExtName = "png"; + mediaType = MediaType.IMAGE_PNG; + docBytes = binaryObject.getDataBuf(); + break; + default: + mediaType = MediaType.APPLICATION_OCTET_STREAM; + docBytes = binaryObject.getDataBuf(); + break; + } + + return browser(new ByteArrayResource(docBytes), gridppReportFile.getName() + "." + fileExtName, mediaType); + } + + @GetMapping("/export") + @Operation(summary = "导出报表") + public ResponseEntity export(Long reportId, String reportKey, String exportName, String dataUrl, Boolean isCrypto, String type) throws Exception { + HttpServletRequest request = ServletUtils.getRequest(); + ConfigReportTemplateDO gridppReportFile = null; + if (reportId != null) { + gridppReportFile = configReportTemplateService.getConfigReportTemplate(reportId); + } else if (StrUtil.isNotBlank(reportKey)) { + gridppReportFile = configReportTemplateService.getConfigReportTemplateByKey(reportKey); + } + if (ObjectUtil.isEmpty(gridppReportFile)) { + throw new GridReportException("未找到报表模板!"); + } + String reportData = StringEscapeUtils.unescapeHtml4(gridppReportFile.getData()); + + //报表参数 + Map reportParams = new HashMap<>(); + //获取当前用户姓名 + LoginUser user = SecurityFrameworkUtils.getLoginUser(); + String realName = ""; + if (user != null) { + realName = SecurityFrameworkUtils.getLoginUserNickname(); + } + reportParams.put("operName", realName); + + if (StrUtil.isNotBlank(dataUrl)) { + dataUrl = StringEscapeUtils.unescapeHtml4(dataUrl); + //处理url参数 + if (dataUrl.contains("?")) { + String urlParam = dataUrl.split("\\?")[1]; + String[] urlVks = urlParam.split("&"); + for (int i = 0; i < urlVks.length; i++) { + String vk = urlVks[i]; + if (StrUtil.isNotBlank(vk)) { + String[] vkSplit = vk.split("="); + if(vkSplit.length == 2){ + reportParams.put(vkSplit[0], vkSplit[1]); + } + } + } + } + Map headers = new HashMap<>(); + String token = SecurityFrameworkUtils.obtainAuthorization(request, + securityProperties.getTokenHeader(), securityProperties.getTokenParameter()); + headers.put(securityProperties.getTokenHeader(), token); +// headers.put(WebFrameworkUtils.HEADER_VISIT_COMPANY_ID, user.getVisitCompanyId() + ""); +// headers.put(WebFrameworkUtils.HEADER_VISIT_DEPT_ID, user.getVisitDeptId() + ""); + HttpResponse res = HttpRequest.get(dataUrl) + .addHeaders(headers) + .setConnectionTimeout(60 * 1000) + .setReadTimeout(120 * 1000) + .execute(); + if (res.getStatus() != 200) { + log.error("报表数据,网络请求错误!", res.body()); + throw new GridReportException("报表数据,网络请求错误!"); + } + String body = res.body(); + CommonResult dataR = JSON.parseObject(body, CommonResult.class); + if (dataR != null && dataR.getCode() == 0) { + if (ArrayUtil.isArray(dataR.getData()) || dataR.getData() instanceof Collection) { + reportData = JSON.toJSONString(dataR); + } else { + reportData = JSON.toJSONString(dataR.getData()); + } + } else { + log.error("获取报表数据错误!", dataR.getMsg()); + throw new GridReportException("获取报表数据错误!"); + } + } + + BinaryObject binaryObject = gridReport.genReport(gridppReportFile.getContent(), reportData, reportParams, ExportType.valueOf("OFD".equals(type.toUpperCase()) ? "PDF" : type.toUpperCase())); + byte[] docBytes = null; + //文件扩展名 + String fileExtName = type.toLowerCase(); + switch (type.toUpperCase()) { + case "PDF": + docBytes = PdfHelper.modifyDocInfo(binaryObject.getDataBuf()); + break; + case "OFD": + docBytes = PdfHelper.modifyDocInfo(binaryObject.getDataBuf()); + break; + case "RTF": + fileExtName = "doc"; + docBytes = binaryObject.getDataBuf(); + break; + case "IMG": + fileExtName = "png"; + docBytes = binaryObject.getDataBuf(); + break; + default: + docBytes = binaryObject.getDataBuf(); + break; + } + String fileName = gridppReportFile.getName(); + if (StrUtil.isNotBlank(exportName)) { + fileName = exportName; + } + return download(new ByteArrayResource(docBytes), fileName + "." + fileExtName); + } + + /** + * 生成Base64图片 + * @return + */ + @PostMapping("/gen-report-png-image-base64") + @Operation(summary = "生成Base64图片") + public CommonResult genReportPngImageBase64(@RequestBody GenReportBody body) { + ConfigReportTemplateDO gridppReportFile = null; + if (body.getReportId() != null) { + gridppReportFile = configReportTemplateService.getConfigReportTemplate(body.getReportId()); + } else if (StrUtil.isNotBlank(body.getReportKey())) { + gridppReportFile = configReportTemplateService.getConfigReportTemplateByKey(body.getReportKey()); + } + if (ObjectUtil.isEmpty(gridppReportFile)) { + throw new ServiceException(ErrorCodeConstants.CONFIG_REPORT_TEMPLATE_NOT_EXISTS); + } + + String imgBase64 = null; + try { + BinaryObject binaryObject = gridReport.genReport(gridppReportFile.getContent(), body.getReportDataJson(), body.getReportParams(), ExportType.IMG, ExportImageType.PNG, body.getImgDpi()); + imgBase64 = binaryObject.getAsBase64Text(); + } catch (Exception e) { + log.error("生成base64图片失败", e); + } + if (StringUtils.isBlank(imgBase64)) { + return CommonResult.error(1_032_100_000, "生成Base64图片失败"); + } + return success(imgBase64); + } + + /** + * 生成Base64图片 + * @return + */ + @PostMapping("/gen-report-png-image-base64-by-pdf") + @Operation(summary = "生成Base64图片") + public CommonResult genReportPngImageBase64ByPdf(@RequestBody GenReportBody body) { + ConfigReportTemplateDO gridppReportFile = null; + if (body.getReportId() != null) { + gridppReportFile = configReportTemplateService.getConfigReportTemplate(body.getReportId()); + } else if (StrUtil.isNotBlank(body.getReportKey())) { + gridppReportFile = configReportTemplateService.getConfigReportTemplateByKey(body.getReportKey()); + } + if (ObjectUtil.isEmpty(gridppReportFile)) { + throw new ServiceException(ErrorCodeConstants.CONFIG_REPORT_TEMPLATE_NOT_EXISTS); + } + + String imgBase64 = null; + try { + BinaryObject binaryObject = gridReport.genReport(gridppReportFile.getContent(), body.getReportDataJson(), body.getReportParams(), ExportType.PDF); + byte[] pngBytes = PdfHelper.pdfToPng(binaryObject.getDataBuf(), body.getImgDpi()); + //String encodeHexStr = HexUtil.encodeHexStr(pngBytes); + //System.out.println(encodeHexStr); + imgBase64 = Base64.encode(pngBytes); + } catch (Exception e) { + log.error("生成base64图片失败", e); + } + if (StringUtils.isBlank(imgBase64)) { + return CommonResult.error(1_032_100_000, "生成Base64图片失败"); + } + return success(imgBase64); + } + + /** + * 下载文件 + * + * @param file 文件 + * @return {ResponseEntity} + * @throws IOException io异常 + */ + protected ResponseEntity download(File file) throws IOException { + String fileName = file.getName(); + return download(file, fileName); + } + + /** + * 下载 + * + * @param file 文件 + * @param fileName 生成的文件名 + * @return {ResponseEntity} + * @throws IOException io异常 + */ + protected ResponseEntity download(File file, String fileName) throws IOException { + org.springframework.core.io.Resource resource = new FileSystemResource(file); + return download(resource, fileName); + } + + /** + * 下载 + * + * @param resource 资源 + * @param fileName 生成的文件名 + * @return {ResponseEntity} + * @throws IOException io异常 + */ + protected ResponseEntity download(org.springframework.core.io.Resource resource, String fileName) throws IOException { + HttpServletRequest request = ServletUtils.getRequest(); + String header = request.getHeader(HttpHeaders.USER_AGENT); + // 避免空指针 + header = header == null ? StringPool.EMPTY : header.toUpperCase(); + HttpStatus status= HttpStatus.OK; + // 断点续传 + long position = 0; + long count = resource.contentLength(); + String range = request.getHeader(HttpHeaders.RANGE); + if (null != range) { + status = HttpStatus.PARTIAL_CONTENT; + String[] rangeRange = range.replace("bytes=", StringPool.EMPTY).split(StringPool.DASH); + position = Long.parseLong(rangeRange[0]); + if (rangeRange.length > 1) { + long end = Long.parseLong(rangeRange[1]); + count = end - position + 1; + } + } + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); + String encodeFileName = UriUtils.encode(fileName, StandardCharsets.UTF_8); + // 兼容各种浏览器下载: + // https://blog.robotshell.org/2012/deal-with-http-header-encoding-for-file-download/ + String disposition = "attachment;" + + "filename=\"" + encodeFileName + "\";" + + "filename*=utf-8''" + encodeFileName; + headers.set(HttpHeaders.CONTENT_DISPOSITION, disposition); + return new ResponseEntity<>(new ResourceRegion(resource, position, count), headers, status); + } + + /** + * 浏览器打开 + * + * @param resource 资源 + * @param fileName 生成的文件名 + * @return {ResponseEntity} + * @throws IOException io异常 + */ + protected ResponseEntity browser(org.springframework.core.io.Resource resource, String fileName, MediaType mediaType) throws IOException { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(mediaType); + headers.setContentLength(resource.contentLength()); + String encodeFileName = UriUtils.encode(fileName, StandardCharsets.UTF_8); + // 兼容各种浏览器下载: + // https://blog.robotshell.org/2012/deal-with-http-header-encoding-for-file-download/ + String disposition = "inline;" + + "filename=\"" + encodeFileName + "\";" + + "filename*=utf-8''" + encodeFileName; + headers.set(HttpHeaders.CONTENT_DISPOSITION, disposition); + return new ResponseEntity<>(resource, headers, HttpStatus.OK); + } + +}