Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
@@ -31,12 +31,6 @@ public class SampleAnalysisAuditController implements BusinessControllerMarker {
|
|||||||
@Resource
|
@Resource
|
||||||
private SampleAnalysisAuditService sampleAnalysisAuditService;
|
private SampleAnalysisAuditService sampleAnalysisAuditService;
|
||||||
|
|
||||||
@GetMapping("/crossAuditByTaskId")
|
|
||||||
public CommonResult<?> crossAuditByTaskId(Long businessAssayTaskId) {
|
|
||||||
JSONObject result = sampleAnalysisAuditService.crossAuditByTaskId(businessAssayTaskId);
|
|
||||||
return success(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 交叉审核
|
* 交叉审核
|
||||||
* @return
|
* @return
|
||||||
|
|||||||
@@ -59,14 +59,6 @@ public class SampleEntrustController implements BusinessControllerMarker {
|
|||||||
BusinessSampleEntrustRegistrationExtendRespVO sampleEntrustRegistration = sampleEntrustService.detail(id);
|
BusinessSampleEntrustRegistrationExtendRespVO sampleEntrustRegistration = sampleEntrustService.detail(id);
|
||||||
return success(sampleEntrustRegistration);
|
return success(sampleEntrustRegistration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/reportDetail")
|
|
||||||
@Operation(summary = "委托单详情数据")
|
|
||||||
public CommonResult<?> reportDetail(@RequestParam("id") Long id) {
|
|
||||||
JSONObject jsonObject = sampleEntrustService.reportDetail(id);
|
|
||||||
return success(jsonObject);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
@Operation(summary = "修改委托登记")
|
@Operation(summary = "修改委托登记")
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -90,13 +90,16 @@ public interface BusinessSampleEntrustDetailMapper extends BaseMapperX<BusinessS
|
|||||||
/**
|
/**
|
||||||
* 查询当前批次的第一条数据
|
* 查询当前批次的第一条数据
|
||||||
* @param businessBaseSampleId 任意一条的主样id
|
* @param businessBaseSampleId 任意一条的主样id
|
||||||
|
* @param baseSampleDictionaryBusinessKey 样品大类类型key
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
default BusinessSampleEntrustDetailDO selectCurrBatchFirstByBusinessBaseSampleId(Long businessBaseSampleId) {
|
default BusinessSampleEntrustDetailDO selectCurrBatchFirstByBusinessBaseSampleIdAndBaseSampleDictionaryBusinessKey(Long businessBaseSampleId, String baseSampleDictionaryBusinessKey) {
|
||||||
BusinessSampleEntrustDetailDO businessSampleEntrustDetailDO = selectByBusinessBaseSampleId(businessBaseSampleId);
|
BusinessSampleEntrustDetailDO businessSampleEntrustDetailDO = selectByBusinessBaseSampleId(businessBaseSampleId);
|
||||||
//查询当前委托的第一条
|
//查询当前委托的第一条
|
||||||
return selectOne(new LambdaQueryWrapperX<BusinessSampleEntrustDetailDO>()
|
return selectJoinOne(BusinessSampleEntrustDetailDO.class, new MPJLambdaWrapperX<BusinessSampleEntrustDetailDO>()
|
||||||
|
.leftJoin(BaseSampleDO.class, BaseSampleDO::getId, BusinessSampleEntrustDetailDO::getBaseSampleId)
|
||||||
.eq(BusinessSampleEntrustDetailDO::getBusinessSampleEntrustRegistrationId, businessSampleEntrustDetailDO.getBusinessSampleEntrustRegistrationId())
|
.eq(BusinessSampleEntrustDetailDO::getBusinessSampleEntrustRegistrationId, businessSampleEntrustDetailDO.getBusinessSampleEntrustRegistrationId())
|
||||||
|
.eq(BaseSampleDO::getDictionaryBusinessKey, baseSampleDictionaryBusinessKey)
|
||||||
.orderByAsc(BusinessSampleEntrustDetailDO::getSort)
|
.orderByAsc(BusinessSampleEntrustDetailDO::getSort)
|
||||||
.last(" limit 1 "));
|
.last(" limit 1 "));
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import java.util.*;
|
|||||||
|
|
||||||
import com.zt.plat.framework.common.pojo.PageResult;
|
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.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.controller.vo.*;
|
||||||
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSubParentSampleAssessmentDO;
|
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 com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
@@ -48,4 +50,12 @@ public interface BusinessSubParentSampleAssessmentMapper extends BaseMapperX<Bus
|
|||||||
.eq(BusinessSubParentSampleAssessmentDO::getConfigAssayMethodId, configAssayMethodId));
|
.eq(BusinessSubParentSampleAssessmentDO::getConfigAssayMethodId, configAssayMethodId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default List<BusinessSubParentSampleAssessmentDO> selectByBusinessSubParentSampleIdsAndAssayDepartmentId(List<Long> businessSubParentSampleIds,
|
||||||
|
Long assayDepartmentId) {
|
||||||
|
return selectJoinList(BusinessSubParentSampleAssessmentDO.class, new MPJLambdaWrapperX<BusinessSubParentSampleAssessmentDO>()
|
||||||
|
.leftJoin(ConfigAssayMethodDO.class, ConfigAssayMethodDO::getId, BusinessSubParentSampleAssessmentDO::getConfigAssayMethodId)
|
||||||
|
.in(BusinessSubParentSampleAssessmentDO::getBusinessSubParentSampleId, businessSubParentSampleIds)
|
||||||
|
.eq(ConfigAssayMethodDO::getAssayDepartmentId, assayDepartmentId));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -46,6 +46,12 @@ public interface BusinessSubSampleAnalysisGroupMapper extends BaseMapperX<Busine
|
|||||||
.in(BusinessSubSampleAnalysisGroupDO::getBusinessSubParentSampleId, businessSubParentSampleIds));
|
.in(BusinessSubSampleAnalysisGroupDO::getBusinessSubParentSampleId, businessSubParentSampleIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default List<BusinessSubSampleAnalysisGroupDO> selectByBusinessSubParentSampleIdsAndAssayDepartmentId(List<Long> businessSubParentSampleIds, Long assayDepartmentId) {
|
||||||
|
return selectList(new LambdaQueryWrapperX<BusinessSubSampleAnalysisGroupDO>()
|
||||||
|
.in(BusinessSubSampleAnalysisGroupDO::getBusinessSubParentSampleId, businessSubParentSampleIds)
|
||||||
|
.eq(BusinessSubSampleAnalysisGroupDO::getAssayDepartmentId, assayDepartmentId));
|
||||||
|
}
|
||||||
|
|
||||||
default List<BusinessSubSampleAnalysisGroupDO> selectByBusinessSubSampleId(Long businessSubSampleId) {
|
default List<BusinessSubSampleAnalysisGroupDO> selectByBusinessSubSampleId(Long businessSubSampleId) {
|
||||||
return selectList(new LambdaQueryWrapperX<BusinessSubSampleAnalysisGroupDO>()
|
return selectList(new LambdaQueryWrapperX<BusinessSubSampleAnalysisGroupDO>()
|
||||||
.eq(BusinessSubSampleAnalysisGroupDO::getBusinessSubSampleId, businessSubSampleId));
|
.eq(BusinessSubSampleAnalysisGroupDO::getBusinessSubSampleId, businessSubSampleId));
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.zt.plat.framework.common.exception.ServiceException;
|
import com.zt.plat.framework.common.exception.ServiceException;
|
||||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
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.ConfigSubSampleMethodConfInfo;
|
||||||
import com.zt.plat.module.qms.business.config.controller.vo.ConfigSubSampleMethodConfItem;
|
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.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.ConfigAssayMethodDO;
|
||||||
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigAssayMethodProjectCoefficientDO;
|
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.ConfigAssayMethodProjectRangeDO;
|
||||||
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigSubSampleMethodDO;
|
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.ConfigAssayMethodMapper;
|
||||||
import com.zt.plat.module.qms.business.config.dal.mapper.ConfigAssayMethodProjectCoefficientMapper;
|
import com.zt.plat.module.qms.business.config.dal.mapper.ConfigAssayMethodProjectCoefficientMapper;
|
||||||
import com.zt.plat.module.qms.business.config.dal.mapper.ConfigAssayMethodProjectRangeMapper;
|
import com.zt.plat.module.qms.business.config.dal.mapper.ConfigAssayMethodProjectRangeMapper;
|
||||||
@@ -142,6 +145,9 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService {
|
|||||||
@Resource
|
@Resource
|
||||||
private BusinessSampleEntrustDetailMapper businessSampleEntrustDetailMapper;
|
private BusinessSampleEntrustDetailMapper businessSampleEntrustDetailMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private BaseSampleMapper baseSampleMapper;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private BusinessSubParentSampleMapper businessSubParentSampleMapper;
|
private BusinessSubParentSampleMapper businessSubParentSampleMapper;
|
||||||
|
|
||||||
@@ -152,6 +158,7 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService {
|
|||||||
private DataCollectionService dataCollectionService;
|
private DataCollectionService dataCollectionService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public BusinessAssayTaskAnalysisSampleProjectRespVO batchSampleAnalysisByTaskId(Long businessAssayTaskId) {
|
public BusinessAssayTaskAnalysisSampleProjectRespVO batchSampleAnalysisByTaskId(Long businessAssayTaskId) {
|
||||||
BusinessAssayTaskAnalysisSampleProjectRespVO businessAssayTaskAnalysisSampleProjectRespVO = new BusinessAssayTaskAnalysisSampleProjectRespVO();
|
BusinessAssayTaskAnalysisSampleProjectRespVO businessAssayTaskAnalysisSampleProjectRespVO = new BusinessAssayTaskAnalysisSampleProjectRespVO();
|
||||||
BusinessAssayTaskDO businessAssayTaskDO = businessAssayTaskMapper.selectById(businessAssayTaskId);
|
BusinessAssayTaskDO businessAssayTaskDO = businessAssayTaskMapper.selectById(businessAssayTaskId);
|
||||||
@@ -177,17 +184,27 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService {
|
|||||||
List<BatchSampleAnalysisColumnRespVO> cloumns = new ArrayList<>();
|
List<BatchSampleAnalysisColumnRespVO> 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("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("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<BusinessAssayTaskDetailDO> businessAssayTaskDetailList = businessAssayTaskDetailMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskDetailDO>().eq(BusinessAssayTaskDetailDO::getBusinessAssayTaskId, businessAssayTaskId));
|
List<BusinessAssayTaskDetailDO> businessAssayTaskDetailList = businessAssayTaskDetailMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskDetailDO>().eq(BusinessAssayTaskDetailDO::getBusinessAssayTaskId, businessAssayTaskId));
|
||||||
|
|
||||||
List<BusinessAssayTaskDataDO> businessAssayTaskDataList = businessAssayTaskDataMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>().eq(BusinessAssayTaskDataDO::getBusinessAssayTaskId, businessAssayTaskId).eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId()));
|
List<BusinessAssayTaskDataDO> businessAssayTaskDataList = businessAssayTaskDataMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>().eq(BusinessAssayTaskDataDO::getBusinessAssayTaskId, businessAssayTaskId).eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId()));
|
||||||
List<Long> businessAssayTaskDataIdList = businessAssayTaskDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
|
List<Long> businessAssayTaskDataIdList = businessAssayTaskDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
|
||||||
//BusinessAssayTaskDataDO businessAssayTaskData = businessAssayTaskDataList.get(0);
|
|
||||||
|
|
||||||
|
//子样Id列表
|
||||||
|
List<Long> businessSubSampleIdList = businessAssayTaskDataList.stream().map(m -> m.getBusinessSubSampleId()).distinct().collect(Collectors.toList());
|
||||||
|
|
||||||
|
//子样列表
|
||||||
|
List<BusinessSubSampleDO> businessSubSampleDOList = businessSubSampleMapper.selectByIds(businessSubSampleIdList);
|
||||||
|
//子样配置id列表
|
||||||
|
List<Long> configSubSampleIdList = businessSubSampleDOList.stream().map(m -> m.getConfigSubSampleId()).distinct().collect(Collectors.toList());
|
||||||
|
|
||||||
|
//子样方法配置列表
|
||||||
|
List<ConfigSubSampleMethodDO> configSubSampleMethodDOList = configSubSampleMethodMapper.selectByConfigSubSampleIdsAndConfigAssayMethodId(configSubSampleIdList, businessAssayTaskDO.getConfigAssayMethodId());
|
||||||
|
|
||||||
|
|
||||||
BusinessAssayProjectDataReqVO projectDataSearch = new BusinessAssayProjectDataReqVO();
|
BusinessAssayProjectDataReqVO projectDataSearch = new BusinessAssayProjectDataReqVO();
|
||||||
// projectDataSearch.setBusinessAssayTaskDataId(businessAssayTaskData.getId());
|
|
||||||
projectDataSearch.setBusinessAssayTaskDataIdList(businessAssayTaskDataIdList);
|
projectDataSearch.setBusinessAssayTaskDataIdList(businessAssayTaskDataIdList);
|
||||||
List<BusinessAssayProjectAndParameterRespVO> projectAndParameterList = businessAssayProjectDataMapper.selectProjectAndParameterBy(projectDataSearch);
|
List<BusinessAssayProjectAndParameterRespVO> 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<BusinessAssayProjectAndParameterRespVO> 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);
|
businessAssayTaskAnalysisSampleProjectRespVO.setColumns(cloumns);
|
||||||
|
|
||||||
|
|
||||||
@@ -241,6 +240,91 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService {
|
|||||||
for (BusinessAssayTaskDataDO businessAssayTaskDataDO : businessAssayTaskDataList) {
|
for (BusinessAssayTaskDataDO businessAssayTaskDataDO : businessAssayTaskDataList) {
|
||||||
BusinessAssayTaskDetailDO businessAssayTaskDetailDO = businessAssayTaskDetailList.stream().filter(f -> f.getBusinessAssayTaskDataId().equals(businessAssayTaskDataDO.getId())).findFirst().orElse(null);
|
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<ConfigSubSampleMethodConfItem> 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<BusinessSubParentSampleDO> currBusinessSubParentSampleDOList = businessSubParentSampleMapper.selectByBusinessBaseSampleId(currBatchFirstBusinessSampleEntrustDetailDO.getBusinessBaseSampleId());
|
||||||
|
List<Long> currBusinessSubParentSampleIdList = currBusinessSubParentSampleDOList.stream().map(m -> m.getId()).collect(Collectors.toList());
|
||||||
|
List<BusinessSubParentSampleAssessmentProjectExtendRespVO> 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<Long> businessSubParentSampleIdList = Arrays.asList(businessAssayTaskDataDO.getBusinessSubParentSampleId());
|
||||||
|
List<BusinessSubParentSampleAssessmentProjectExtendRespVO> 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<Long> businessSubParentSampleIdList = Arrays.asList(businessAssayTaskDataDO.getBusinessSubParentSampleId());
|
||||||
|
List<BusinessSubParentSampleAssessmentProjectExtendRespVO> 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<String, Object> map = new HashedMap<>();
|
Map<String, Object> map = new HashedMap<>();
|
||||||
map.put("businessAssayTaskDataId", businessAssayTaskDataDO.getId());
|
map.put("businessAssayTaskDataId", businessAssayTaskDataDO.getId());
|
||||||
map.put("businessAssayTaskId", businessAssayTaskDataDO.getBusinessAssayTaskId());
|
map.put("businessAssayTaskId", businessAssayTaskDataDO.getBusinessAssayTaskId());
|
||||||
@@ -405,6 +489,7 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public BusinessAssayTaskAnalysisSampleAndQcProjectRespVO batchSampleAndQcAnalysisByTaskId(Long businessAssayTaskId) {
|
public BusinessAssayTaskAnalysisSampleAndQcProjectRespVO batchSampleAndQcAnalysisByTaskId(Long businessAssayTaskId) {
|
||||||
BusinessAssayTaskAnalysisSampleAndQcProjectRespVO businessAssayTaskAnalysisSampleAndQcProjectRespVO = new BusinessAssayTaskAnalysisSampleAndQcProjectRespVO();
|
BusinessAssayTaskAnalysisSampleAndQcProjectRespVO businessAssayTaskAnalysisSampleAndQcProjectRespVO = new BusinessAssayTaskAnalysisSampleAndQcProjectRespVO();
|
||||||
BusinessAssayTaskDO businessAssayTaskDO = businessAssayTaskMapper.selectById(businessAssayTaskId);
|
BusinessAssayTaskDO businessAssayTaskDO = businessAssayTaskMapper.selectById(businessAssayTaskId);
|
||||||
@@ -437,9 +522,6 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService {
|
|||||||
assayTaskAnalysisDataList.add(analysis);
|
assayTaskAnalysisDataList.add(analysis);
|
||||||
|
|
||||||
businessAssayTaskAnalysisSampleAndQcProjectRespVO.setAssayTaskAnalysisDataList(assayTaskAnalysisDataList);
|
businessAssayTaskAnalysisSampleAndQcProjectRespVO.setAssayTaskAnalysisDataList(assayTaskAnalysisDataList);
|
||||||
|
|
||||||
// List<ConfigQCSampleMethodExtendRespVO> configQCSampleMethodList = configQCSampleMethodMapper.selectByConfigAssayMethodId(businessAssayTaskDO.getConfigAssayMethodId());
|
|
||||||
// businessAssayTaskAnalysisSampleAndQcProjectRespVO.setConfigQCSampleMethodList(configQCSampleMethodList);
|
|
||||||
|
|
||||||
//查询区间范围
|
//查询区间范围
|
||||||
List<ConfigAssayMethodProjectRangeDO> configAssayMethodProjectRangeDOList = configAssayMethodProjectRangeMapper.selectList(new LambdaQueryWrapperX<ConfigAssayMethodProjectRangeDO>().eq(ConfigAssayMethodProjectRangeDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId()));
|
List<ConfigAssayMethodProjectRangeDO> configAssayMethodProjectRangeDOList = configAssayMethodProjectRangeMapper.selectList(new LambdaQueryWrapperX<ConfigAssayMethodProjectRangeDO>().eq(ConfigAssayMethodProjectRangeDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId()));
|
||||||
@@ -462,9 +544,7 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService {
|
|||||||
//处理列
|
//处理列
|
||||||
List<BatchSampleAnalysisColumnRespVO> cloumns = new ArrayList<>();
|
List<BatchSampleAnalysisColumnRespVO> 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("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("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<BusinessAssayTaskDetailDO> businessAssayTaskDetailList = businessAssayTaskDetailMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskDetailDO>().eq(BusinessAssayTaskDetailDO::getBusinessAssayTaskId, businessAssayTaskDO.getId()));
|
List<BusinessAssayTaskDetailDO> businessAssayTaskDetailList = businessAssayTaskDetailMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskDetailDO>().eq(BusinessAssayTaskDetailDO::getBusinessAssayTaskId, businessAssayTaskDO.getId()));
|
||||||
List<BusinessAssayTaskDataDO> businessAssayTaskDataList = businessAssayTaskDataMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>().eq(BusinessAssayTaskDataDO::getBusinessAssayTaskId, businessAssayTaskDO.getId()).eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId()));
|
List<BusinessAssayTaskDataDO> businessAssayTaskDataList = businessAssayTaskDataMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>().eq(BusinessAssayTaskDataDO::getBusinessAssayTaskId, businessAssayTaskDO.getId()).eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId()));
|
||||||
@@ -482,10 +562,8 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService {
|
|||||||
|
|
||||||
|
|
||||||
List<Long> businessAssayTaskDataIdList = businessAssayTaskDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
|
List<Long> businessAssayTaskDataIdList = businessAssayTaskDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
|
||||||
// BusinessAssayTaskDataDO businessAssayTaskData = businessAssayTaskDataList.get(0);
|
|
||||||
|
|
||||||
BusinessAssayProjectDataReqVO projectDataSearch = new BusinessAssayProjectDataReqVO();
|
BusinessAssayProjectDataReqVO projectDataSearch = new BusinessAssayProjectDataReqVO();
|
||||||
// projectDataSearch.setBusinessAssayTaskDataId(businessAssayTaskData.getId());
|
|
||||||
projectDataSearch.setBusinessAssayTaskDataIdList(businessAssayTaskDataIdList);
|
projectDataSearch.setBusinessAssayTaskDataIdList(businessAssayTaskDataIdList);
|
||||||
List<BusinessAssayProjectAndParameterRespVO> projectAndParameterList = businessAssayProjectDataMapper.selectProjectAndParameterBy(projectDataSearch);
|
List<BusinessAssayProjectAndParameterRespVO> projectAndParameterList = businessAssayProjectDataMapper.selectProjectAndParameterBy(projectDataSearch);
|
||||||
Map<Long, List<BusinessAssayProjectAndParameterRespVO>> projectAndParameterMap = projectAndParameterList.stream().sorted(Comparator.comparing(BusinessAssayProjectAndParameterRespVO::getParamNo)).collect(Collectors.groupingBy(BusinessAssayProjectAndParameterRespVO::getDicId,
|
Map<Long, List<BusinessAssayProjectAndParameterRespVO>> 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<BusinessAssayProjectAndParameterRespVO> 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);
|
businessAssayTaskAnalysisDataRespVO.setColumns(cloumns);
|
||||||
|
|
||||||
|
|
||||||
@@ -557,36 +618,65 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService {
|
|||||||
|
|
||||||
BusinessAssayParameterDataDO businessAssayParameterDataDO = businessAssayParameterDataMapper.selectByBusinessAssayTaskDataIdAndProjectSimpleNameAndParameterKey(businessAssayTaskDataDO.getId(), targetProject, targetParameter);
|
BusinessAssayParameterDataDO businessAssayParameterDataDO = businessAssayParameterDataMapper.selectByBusinessAssayTaskDataIdAndProjectSimpleNameAndParameterKey(businessAssayTaskDataDO.getId(), targetProject, targetParameter);
|
||||||
if (StringUtils.isBlank(businessAssayParameterDataDO.getValue())) {
|
if (StringUtils.isBlank(businessAssayParameterDataDO.getValue())) {
|
||||||
//1 查询来源品位
|
//1 查询委托明细
|
||||||
BusinessSampleEntrustDetailDO businessSampleEntrustDetailDO = businessSampleEntrustDetailMapper.selectByBusinessBaseSampleId(businessAssayTaskDataDO.getBusinessBaseSampleId());
|
BusinessSampleEntrustDetailDO businessSampleEntrustDetailDO = businessSampleEntrustDetailMapper.selectByBusinessBaseSampleId(businessAssayTaskDataDO.getBusinessBaseSampleId());
|
||||||
String forecastResult = businessSampleEntrustDetailDO.getForecastResult();//预报品位
|
//2 查询样品大类
|
||||||
if (StringUtils.isBlank(forecastResult)) {
|
BaseSampleDO baseSampleDO = baseSampleMapper.selectById(businessSampleEntrustDetailDO.getBaseSampleId());
|
||||||
//2 查询当前样品其他分析方法的结果 (废弃-20251202)
|
//3 判断样品大类类型
|
||||||
// List<Long> businessSubParentSampleIdList = Arrays.asList(businessAssayTaskDataDO.getBusinessSubParentSampleId());
|
if (QmsCommonConstant.ENTRUST_INSPECTION_ANALYSIS_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是商检分析样
|
||||||
// List<BusinessSubParentSampleAssessmentProjectExtendRespVO> businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(businessSubParentSampleIdList, configMethodId);
|
//查询当前批次的第一个商检分析样
|
||||||
// BusinessSubParentSampleAssessmentProjectExtendRespVO businessSubParentSampleAssessmentProject = businessSubParentSampleAssessmentProjectList.stream().filter(f -> f.getSimpleName().equals(sourceProject)).findFirst().orElse(null);
|
BusinessSampleEntrustDetailDO currBatchFirstBusinessSampleEntrustDetailDO = businessSampleEntrustDetailMapper.selectCurrBatchFirstByBusinessBaseSampleIdAndBaseSampleDictionaryBusinessKey(businessAssayTaskDataDO.getBusinessBaseSampleId(), QmsCommonConstant.ENTRUST_INSPECTION_ANALYSIS_SAMPLE);
|
||||||
// if (businessSubParentSampleAssessmentProject == null || StringUtils.isBlank(businessSubParentSampleAssessmentProject.getAssessmentValue())) {
|
List<BusinessSubParentSampleDO> currBusinessSubParentSampleDOList = businessSubParentSampleMapper.selectByBusinessBaseSampleId(currBatchFirstBusinessSampleEntrustDetailDO.getBusinessBaseSampleId());
|
||||||
|
List<Long> currBusinessSubParentSampleIdList = currBusinessSubParentSampleDOList.stream().map(m -> m.getId()).collect(Collectors.toList());
|
||||||
//3 查询当前批次委托的第一个样品对应的分析方法的结果
|
List<BusinessSubParentSampleAssessmentProjectExtendRespVO> businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(currBusinessSubParentSampleIdList, configMethodId);
|
||||||
BusinessSampleEntrustDetailDO currBatchFirstBusinessSampleEntrustDetailDO = businessSampleEntrustDetailMapper.selectCurrBatchFirstByBusinessBaseSampleId(businessAssayTaskDataDO.getBusinessBaseSampleId());
|
BusinessSubParentSampleAssessmentProjectExtendRespVO businessSubParentSampleAssessmentProject = businessSubParentSampleAssessmentProjectList.stream().filter(f -> f.getSimpleName().equals(sourceProject)).findFirst().orElse(null);
|
||||||
List<BusinessSubParentSampleDO> currBusinessSubParentSampleDOList = businessSubParentSampleMapper.selectByBusinessBaseSampleId(currBatchFirstBusinessSampleEntrustDetailDO.getBusinessBaseSampleId());
|
if (businessSubParentSampleAssessmentProject != null && StringUtils.isNotBlank(businessSubParentSampleAssessmentProject.getAssessmentValue())) {
|
||||||
List<Long> currBusinessSubParentSampleIdList = currBusinessSubParentSampleDOList.stream().map(m -> m.getId()).collect(Collectors.toList());
|
businessAssayParameterDataDO.setValue(businessSubParentSampleAssessmentProject.getAssessmentValue());
|
||||||
List<BusinessSubParentSampleAssessmentProjectExtendRespVO> businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(currBusinessSubParentSampleIdList, configMethodId);
|
}
|
||||||
|
} else if (QmsCommonConstant.ENTRUST_COMPREHENSIVE_INSPECTION_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是商检综合样
|
||||||
|
//查询当前样品的其他分析方法的结果
|
||||||
|
List<Long> businessSubParentSampleIdList = Arrays.asList(businessAssayTaskDataDO.getBusinessSubParentSampleId());
|
||||||
|
List<BusinessSubParentSampleAssessmentProjectExtendRespVO> 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<Long> businessSubParentSampleIdList = Arrays.asList(businessAssayTaskDataDO.getBusinessSubParentSampleId());
|
||||||
|
List<BusinessSubParentSampleAssessmentProjectExtendRespVO> businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(businessSubParentSampleIdList, configMethodId);
|
||||||
BusinessSubParentSampleAssessmentProjectExtendRespVO businessSubParentSampleAssessmentProject = businessSubParentSampleAssessmentProjectList.stream().filter(f -> f.getSimpleName().equals(sourceProject)).findFirst().orElse(null);
|
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());
|
businessAssayParameterDataDO.setValue(businessSubParentSampleAssessmentProject.getAssessmentValue());
|
||||||
}
|
}
|
||||||
// } else {
|
}
|
||||||
// businessAssayParameterDataDO.setValue(businessSubParentSampleAssessmentProject.getAssessmentValue());
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
JSONObject forecastResultJson = JSON.parseObject(forecastResult);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
businessAssayParameterDataMapper.updateById(businessAssayParameterDataDO);
|
businessAssayParameterDataMapper.updateById(businessAssayParameterDataDO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -432,8 +432,7 @@ public class SampleResultReportingServiceImpl implements SampleResultReportingSe
|
|||||||
|
|
||||||
//当前登录用户昵称
|
//当前登录用户昵称
|
||||||
String nickName = SecurityFrameworkUtils.getLoginUserNickname();
|
String nickName = SecurityFrameworkUtils.getLoginUserNickname();
|
||||||
|
|
||||||
|
|
||||||
List<BusinessSubSampleDO> updateBusinessSubSampleDOList = new ArrayList<>();
|
List<BusinessSubSampleDO> updateBusinessSubSampleDOList = new ArrayList<>();
|
||||||
List<BusinessSubSampleAnalysisGroupDO> updateBusinessSubSampleAnalysisGroupDOList = new ArrayList<>();
|
List<BusinessSubSampleAnalysisGroupDO> updateBusinessSubSampleAnalysisGroupDOList = new ArrayList<>();
|
||||||
|
|
||||||
@@ -444,8 +443,6 @@ public class SampleResultReportingServiceImpl implements SampleResultReportingSe
|
|||||||
|
|
||||||
List<BusinessSubParentSampleDO> businessSubParentSampleDOList = businessSubParentSampleMapper.selectByIds(reqVO.getBusinessSubParentSampleIds());
|
List<BusinessSubParentSampleDO> businessSubParentSampleDOList = businessSubParentSampleMapper.selectByIds(reqVO.getBusinessSubParentSampleIds());
|
||||||
|
|
||||||
// List<BusinessSubParentSampleAssessmentDO> businessSubParentSampleAssessmentDOList = businessSubParentSampleAssessmentMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(reqVO.getBusinessSubParentSampleIds(), reqVO.getConfigAssayMethodId());
|
|
||||||
|
|
||||||
//循环分样主样数据
|
//循环分样主样数据
|
||||||
for (BusinessSubParentSampleDO businessSubParentSampleDO : businessSubParentSampleDOList) {
|
for (BusinessSubParentSampleDO businessSubParentSampleDO : businessSubParentSampleDOList) {
|
||||||
|
|
||||||
@@ -538,8 +535,9 @@ public class SampleResultReportingServiceImpl implements SampleResultReportingSe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
//处理子样分析任务数据
|
//处理子样分析任务数据
|
||||||
List<BusinessAssayTaskDataDO> businessAssayTaskDataDOList = businessAssayTaskDataMapper.selectByBusinessSubParentSampleIds(reqVO.getBusinessSubParentSampleIds());
|
List<BusinessAssayTaskDataDO> businessAssayTaskDataDOList = businessAssayTaskDataMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(reqVO.getBusinessSubParentSampleIds(), reqVO.getConfigAssayMethodId());
|
||||||
List<Long> businessSubSampleIdList = businessAssayTaskDataDOList.stream().map(m -> m.getBusinessSubSampleId()).distinct().collect(Collectors.toList());
|
List<Long> businessSubSampleIdList = businessAssayTaskDataDOList.stream().map(m -> m.getBusinessSubSampleId()).distinct().collect(Collectors.toList());
|
||||||
List<BusinessSubSampleDO> businessSubSampleDOList = businessSubSampleMapper.selectByIds(businessSubSampleIdList);
|
List<BusinessSubSampleDO> businessSubSampleDOList = businessSubSampleMapper.selectByIds(businessSubSampleIdList);
|
||||||
List<BusinessSubSampleAnalysisGroupDO> businessSubSampleAnalysisGroupDOList = businessSubSampleAnalysisGroupMapper.selectByBusinessSubParentSampleIds(reqVO.getBusinessSubParentSampleIds());
|
List<BusinessSubSampleAnalysisGroupDO> businessSubSampleAnalysisGroupDOList = businessSubSampleAnalysisGroupMapper.selectByBusinessSubParentSampleIds(reqVO.getBusinessSubParentSampleIds());
|
||||||
@@ -566,6 +564,26 @@ public class SampleResultReportingServiceImpl implements SampleResultReportingSe
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
**/
|
||||||
|
//分析方法信息
|
||||||
|
ConfigAssayMethodDO configAssayMethodDO = configAssayMethodMapper.selectById(reqVO.getConfigAssayMethodId());
|
||||||
|
//查询当前分析部门下的分样判定信息
|
||||||
|
List<BusinessSubParentSampleAssessmentDO> businessSubParentSampleAssessmentDOList = businessSubParentSampleAssessmentMapper.selectByBusinessSubParentSampleIdsAndAssayDepartmentId(reqVO.getBusinessSubParentSampleIds(), configAssayMethodDO.getAssayDepartmentId());
|
||||||
|
//查询当前分析部门下的子样分析班组信息
|
||||||
|
List<BusinessSubSampleAnalysisGroupDO> 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) {
|
if (saveBusinessAssayReportDataDOList.size() > 0) {
|
||||||
businessAssayReportDataMapper.insertBatch(saveBusinessAssayReportDataDOList);
|
businessAssayReportDataMapper.insertBatch(saveBusinessAssayReportDataDOList);
|
||||||
|
|||||||
@@ -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.ConfigReportTemplatePageReqVO;
|
||||||
import com.zt.plat.module.qms.business.config.controller.vo.ConfigReportTemplateRespVO;
|
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.ConfigReportTemplateSaveReqVO;
|
||||||
import com.zt.plat.module.qms.business.config.controller.vo.GenReportBody;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
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 jakarta.annotation.Resource;
|
||||||
import org.springframework.validation.annotation.Validated;
|
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 com.zt.plat.framework.business.interceptor.BusinessControllerMarker;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import jakarta.validation.*;
|
import jakarta.validation.*;
|
||||||
import jakarta.servlet.http.*;
|
import jakarta.servlet.http.*;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.zt.plat.framework.common.pojo.PageParam;
|
import com.zt.plat.framework.common.pojo.PageParam;
|
||||||
import com.zt.plat.framework.common.pojo.PageResult;
|
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.pojo.CommonResult;
|
||||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
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 static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
import com.zt.plat.framework.excel.core.util.ExcelUtils;
|
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 com.zt.plat.framework.apilog.core.annotation.ApiAccessLog;
|
||||||
import static com.zt.plat.framework.apilog.core.enums.OperateTypeEnum.*;
|
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.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 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 = "管理后台 - 报表模版配置")
|
@Tag(name = "管理后台 - 报表模版配置")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/qms/config-report-template")
|
@RequestMapping("/qms/config-report-template")
|
||||||
@Validated
|
@Validated
|
||||||
@Slf4j
|
public class ConfigReportTemplateController implements BusinessControllerMarker {
|
||||||
public class ConfigReportTemplateController {
|
|
||||||
|
|
||||||
public static final String WR_PREFIX = "_WR_";
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private GridReport gridReport;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private SecurityProperties securityProperties;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ConfigReportTemplateService configReportTemplateService;
|
private ConfigReportTemplateService configReportTemplateService;
|
||||||
|
|
||||||
@GetMapping("/info")
|
|
||||||
@Operation(summary = "获取报表信息")
|
|
||||||
public CommonResult<?> info() {
|
|
||||||
Map<String, Object> 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")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "创建报表模版配置")
|
@Operation(summary = "创建报表模版配置")
|
||||||
@@ -179,460 +111,4 @@ public class ConfigReportTemplateController {
|
|||||||
BeanUtils.toBean(list, ConfigReportTemplateRespVO.class));
|
BeanUtils.toBean(list, ConfigReportTemplateRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
|
||||||
* 预览报表
|
|
||||||
* @param reportId
|
|
||||||
* @param reportKey
|
|
||||||
* @param dataUrl
|
|
||||||
* @param isCrypto
|
|
||||||
* @param type
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
@GetMapping("/preview")
|
|
||||||
@Operation(summary = "预览报表")
|
|
||||||
public ResponseEntity<org.springframework.core.io.Resource> 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<String, String> 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<String, String> 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<org.springframework.core.io.Resource> 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<String, String> 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<String, String> 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<String, Object> map = BeanUtil.beanToMap(dataR.getData());
|
|
||||||
for (Map.Entry<String,Object> 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<ResourceRegion> 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<String, String> 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<String, String> 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<ResourceRegion> download(File file) throws IOException {
|
|
||||||
String fileName = file.getName();
|
|
||||||
return download(file, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 下载
|
|
||||||
*
|
|
||||||
* @param file 文件
|
|
||||||
* @param fileName 生成的文件名
|
|
||||||
* @return {ResponseEntity}
|
|
||||||
* @throws IOException io异常
|
|
||||||
*/
|
|
||||||
protected ResponseEntity<ResourceRegion> 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<ResourceRegion> 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<org.springframework.core.io.Resource> 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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<String, Object> 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<org.springframework.core.io.Resource> 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<String, String> 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<String, String> 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<org.springframework.core.io.Resource> 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<String, String> 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<String, String> 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<String, Object> map = BeanUtil.beanToMap(dataR.getData());
|
||||||
|
for (Map.Entry<String,Object> 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<ResourceRegion> 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<String, String> 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<String, String> 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<ResourceRegion> download(File file) throws IOException {
|
||||||
|
String fileName = file.getName();
|
||||||
|
return download(file, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载
|
||||||
|
*
|
||||||
|
* @param file 文件
|
||||||
|
* @param fileName 生成的文件名
|
||||||
|
* @return {ResponseEntity}
|
||||||
|
* @throws IOException io异常
|
||||||
|
*/
|
||||||
|
protected ResponseEntity<ResourceRegion> 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<ResourceRegion> 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<org.springframework.core.io.Resource> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user