@@ -6,14 +6,19 @@ import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult ;
import cn.hutool.core.bean.BeanUtil ;
import cn.hutool.core.collection.CollUtil ;
import cn.hutool.core.io.FileUtil ;
import cn.hutool.core.util.CharsetUtil ;
import cn.hutool.core.util.ObjectUtil ;
import cn.hutool.core.util.StrUtil ;
import cn.hutool.core.util.ZipUtil ;
import cn.hutool.extra.spring.SpringUtil ;
import cn.hutool.json.JSONUtil ;
import com.baomidou.mybatisplus.core.conditions.Wrapper ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper ;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl ;
import com.njcn.common.pojo.enums.common.DataStateEnum ;
import com.njcn.common.pojo.enums.response.CommonResponseEnum ;
import com.njcn.common.pojo.exception.BusinessException ;
import com.njcn.common.pojo.poi.PullDown ;
import com.njcn.gather.device.mapper.PqDevMapper ;
@@ -29,7 +34,11 @@ import com.njcn.gather.device.pojo.vo.ProvinceDevExcel;
import com.njcn.gather.device.service.IPqDevService ;
import com.njcn.gather.device.service.IPqDevSubService ;
import com.njcn.gather.err.pojo.po.PqErrSys ;
import com.njcn.gather.err.pojo.po.PqErrSysDtls ;
import com.njcn.gather.err.service.IPqErrSysDtlsService ;
import com.njcn.gather.err.service.IPqErrSysService ;
import com.njcn.gather.monitor.pojo.po.PqMonitor ;
import com.njcn.gather.monitor.service.IPqMonitorService ;
import com.njcn.gather.plan.mapper.AdPlanMapper ;
import com.njcn.gather.plan.mapper.AdPlanStandardDevMapper ;
import com.njcn.gather.plan.pojo.enums.DataSourceEnum ;
@@ -37,15 +46,13 @@ import com.njcn.gather.plan.pojo.enums.PlanReportStateEnum;
import com.njcn.gather.plan.pojo.param.AdPlanParam ;
import com.njcn.gather.plan.pojo.po.AdPlan ;
import com.njcn.gather.plan.pojo.po.AdPlanStandardDev ;
import com.njcn.gather.plan.pojo.vo.AdPlanVO ;
import com.njcn.gather.plan.pojo.vo.CNPlanExcel ;
import com.njcn.gather.plan.pojo.vo.ContrastPlanExcel ;
import com.njcn.gather.plan.pojo.vo.ProvincePlanExcel ;
import com.njcn.gather.plan.pojo.vo.* ;
import com.njcn.gather.plan.service.IAdPlanService ;
import com.njcn.gather.plan.service.IAdPlanSourceService ;
import com.njcn.gather.plan.service.IAdPlanStandardDevService ;
import com.njcn.gather.pojo.enums.DetectionResponseEnum ;
import com.njcn.gather.report.pojo.po.PqReport ;
import com.njcn.gather.report.service.IPqReportService ;
import com.njcn.gather.script.pojo.po.PqScript ;
import com.njcn.gather.script.pojo.po.PqScriptDtls ;
import com.njcn.gather.script.service.IPqScriptDtlsService ;
@@ -84,6 +91,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream ;
import javax.servlet.http.HttpServletResponse ;
import java.io.File ;
import java.io.IOException ;
import java.net.URLEncoder ;
import java.util.* ;
@@ -116,6 +124,8 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
private final IAdPlanStandardDevService adPlanStandardDevService ;
private final AdPlanStandardDevMapper adPlanStandardDevMapper ;
private final IAdPlanStandardDevService adPlanContrastStandardDevService ;
private final IPqMonitorService pqMonitorService ;
private final IPqErrSysDtlsService pqErrSysDtlsService ;
@Override
public List < AdPlanVO > listAdPlan ( AdPlanParam . QueryParam queryParam ) {
@@ -160,7 +170,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
adPlanVO . setSourceName ( pqSourceList . stream ( ) . map ( PqSource : : getName ) . collect ( Collectors . toList ( ) ) ) ;
PqDevParam . QueryParam queryParam1 = new PqDevParam . QueryParam ( ) ;
queryParam1 . setPlanIdList ( Arrays . as List( adPlan . getId ( ) ) ) ;
queryParam1 . setPlanIdList ( Collections . singleton List( adPlan . getId ( ) ) ) ;
List < PqDevVO > pqDevVOList = pqDevMapper . selectByQueryParam ( queryParam1 ) ;
if ( CollUtil . isNotEmpty ( pqDevVOList ) ) {
@@ -261,7 +271,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
// 关联检测源
adPlanSourceService . addAdPlanSource ( planId , param . getSourceIds ( ) ) ;
}
tableGenService . deleteTable ( Arrays . as List( adPlan . getCode ( ) . toString ( ) ) ) ;
tableGenService . deleteTable ( Collections . singleton List( adPlan . getCode ( ) . toString ( ) ) ) ;
tableGenService . genTable ( adPlan . getCode ( ) . toString ( ) , PatternEnum . CONTRAST . getValue ( ) . equals ( dictData . getCode ( ) ) ) ;
return true ;
@@ -273,14 +283,42 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
param . setName ( param . getName ( ) . trim ( ) ) ;
AdPlan plan1 = this . getById ( param . getId ( ) ) ;
// 更新子计划
if ( StrUtil . isNotEmpty ( plan1 . getFatherPlanId ( ) ) ) {
String fatherPlanId = plan1 . getFatherPlanId ( ) ;
if ( StrUtil . isNotEmpty ( fatherPlanId ) & & ! StrUtil . equals ( fatherPlanId , " 0 " ) ) {
this . updateBindStandardDev ( param . getId ( ) , param . getStandardDevIds ( ) ) ;
PqDevParam . BindPlanParam bindPlanParam = new PqDevParam . BindPlanParam ( ) ;
bin dPlanParam . setPlanId ( param . getId ( ) ) ;
bindPlanParam . setDevIds ( param . getDevIds ( ) ) ;
bindPlanP aram. s etBindFlag ( 1 ) ;
th is. updateBindDev ( bindPlanParam ) ;
return true ;
List < AdPlan > list = new ArrayList < > ( ) ;
A dPlan fatherPlan = this . getBy Id ( fatherPlanId ) ;
// 原始绑定被检设备
List < PqDev > oldDevList = pqDevService . list ( new QueryWrapper < PqDev > ( ) . eq ( " Plan_Id " , p aram. g etId ( ) ) . eq ( " State " , DataStateEnum . ENABLE . getCode ( ) ) ) ;
List < String > oldDevIds = oldDevL ist . stream ( ) . map ( PqDev : : getId ) . collect ( Collectors . toList ( ) ) ;
List < String > newDevIds = param . getDevIds ( ) ;
if ( CollUtil . isNotEmpty ( newDevIds ) ) {
plan1 . setTestState ( pqDevService . bind ( param . getId ( ) , newDevIds ) ) ;
// 获取并集
List < String > unionDevIds = new ArrayList < > ( CollUtil . union ( oldDevIds , newDevIds ) ) ;
// 排除
newDevIds . forEach ( unionDevIds : : remove ) ;
List < PqDev > fatherNowDevList = pqDevService . list ( new QueryWrapper < PqDev > ( ) . eq ( " Plan_Id " , fatherPlanId ) . eq ( " State " , DataStateEnum . ENABLE . getCode ( ) ) ) ;
List < String > fatherNowDevIds = fatherNowDevList . stream ( ) . map ( PqDev : : getId ) . collect ( Collectors . toList ( ) ) ;
// 把排除绑定到主计划
fatherNowDevIds . addAll ( unionDevIds ) ;
fatherPlan . setTestState ( pqDevService . bind ( fatherPlanId , fatherNowDevIds ) ) ;
list . add ( fatherPlan ) ;
} else {
if ( CollUtil . isNotEmpty ( oldDevIds ) ) {
List < PqDev > fatherNowDevList = pqDevService . list ( new QueryWrapper < PqDev > ( ) . eq ( " Plan_Id " , fatherPlanId ) . eq ( " State " , DataStateEnum . ENABLE . getCode ( ) ) ) ;
List < String > fatherNowDevIds = fatherNowDevList . stream ( ) . map ( PqDev : : getId ) . collect ( Collectors . toList ( ) ) ;
fatherNowDevIds . addAll ( oldDevIds ) ;
// 把原始都绑定到主计划
fatherPlan . setTestState ( pqDevService . bind ( fatherPlanId , fatherNowDevIds ) ) ;
list . add ( fatherPlan ) ;
}
}
return this . updateBatchById ( list ) ;
}
this . checkRepeat ( param , true , CommonEnum . FATHER_ID . getValue ( ) ) ;
AdPlan plan2 = new AdPlan ( ) ;
@@ -360,7 +398,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
public boolean deleteAdPlan ( List < String > ids , String pattern ) {
for ( String id : ids ) {
PqDevParam . QueryParam queryParam = new PqDevParam . QueryParam ( ) ;
queryParam . setPlanIdList ( Arrays . as List( id ) ) ;
queryParam . setPlanIdList ( Collections . singleton List( id ) ) ;
if ( ObjectUtils . isNotEmpty ( pqDevService . listByPlanId ( queryParam ) ) ) {
throw new BusinessException ( DetectionResponseEnum . PLAN_HAS_DEVICE_BIND ) ;
}
@@ -558,7 +596,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
}
}
PqDevParam . QueryParam queryParam = new PqDevParam . QueryParam ( ) ;
queryParam . setPlanIdList ( Arrays . as List( planId ) ) ;
queryParam . setPlanIdList ( Collections . singleton List( planId ) ) ;
List < PqDevVO > pqDevVOList1 = pqDevMapper . selectByQueryParam ( queryParam ) ;
List < PqDev > collect = pqDevVOList1 . stream ( ) . filter ( x - > ! x . getCheckState ( ) . equals ( CheckStateEnum . UNCHECKED . getValue ( ) ) ) . collect ( Collectors . toList ( ) ) ;
if ( CollUtil . isEmpty ( collect ) ) {
@@ -605,7 +643,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
List < PqDevVO > allDevList = new ArrayList < > ( ) ;
for ( AdPlan plan : planList ) {
PqDevParam . QueryParam queryParam = new PqDevParam . QueryParam ( ) ;
queryParam . setPlanIdList ( Arrays . as List( plan . getId ( ) ) ) ;
queryParam . setPlanIdList ( Collections . singleton List( plan . getId ( ) ) ) ;
List < PqDevVO > pqDevVOList = pqDevMapper . selectByQueryParam ( queryParam ) ;
pqDevVOList = pqDevVOList . stream ( ) . filter ( x - > ! x . getCheckResult ( ) . equals ( CheckResultEnum . UNCHECKED . getValue ( ) ) ) . collect ( Collectors . toList ( ) ) ;
allDevList . addAll ( pqDevVOList ) ;
@@ -623,7 +661,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
} else {
AdPlan plan = planList . get ( 0 ) ;
PqDevParam . QueryParam queryParam = new PqDevParam . QueryParam ( ) ;
queryParam . setPlanIdList ( Arrays . as List( plan . getId ( ) ) ) ;
queryParam . setPlanIdList ( Collections . singleton List( plan . getId ( ) ) ) ;
List < PqDevVO > pqDevVOList = pqDevMapper . selectByQueryParam ( queryParam ) ;
pqDevVOList = pqDevVOList . stream ( ) . filter ( x - > ! x . getCheckResult ( ) . equals ( CheckResultEnum . UNCHECKED . getValue ( ) ) ) . collect ( Collectors . toList ( ) ) ;
@@ -671,7 +709,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
sheet . put ( " entity " , ContrastDevExcel . class ) ;
PqDevParam . QueryParam param = new PqDevParam . QueryParam ( ) ;
param . setPlanIdList ( Arrays . as List( plan . getId ( ) ) ) ;
param . setPlanIdList ( Collections . singleton List( plan . getId ( ) ) ) ;
List < PqDevVO > pqDevVOList = pqDevService . listByPlanId ( param ) ;
List < ContrastDevExcel > exportContrastDevData = pqDevService . getExportContrastDevData ( pqDevVOList ) ;
sheet . put ( " data " , exportContrastDevData ) ;
@@ -806,24 +844,6 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
return true ;
}
@Override
public void exportSubPlan ( String planId , HttpServletResponse response ) {
// 子计划数据
AdPlan subPlan = this . getById ( planId ) ;
//子计划绑定的标准设备
List < PqStandardDev > pqStandardDevs = adPlanStandardDevMapper . listByPlanId ( Collections . singletonList ( planId ) ) ;
// 子计划绑定的被检设备
PqDevParam . QueryParam queryParam = new PqDevParam . QueryParam ( ) ;
queryParam . setPlanIdList ( Collections . singletonList ( planId ) ) ;
List < PqDev > pqDevList = pqDevService . list ( new QueryWrapper < PqDev > ( ) . eq ( " Plan_Id " , planId ) ) ;
List < PqDevSub > pqDevSubList = new ArrayList < > ( ) ;
if ( CollUtil . isNotEmpty ( pqDevList ) ) {
pqDevSubList . addAll ( pqDevSubService . list ( new QueryWrapper < PqDevSub > ( ) . in ( " dev_Id " , pqDevList . stream ( ) . map ( PqDev : : getId ) . collect ( Collectors . toList ( ) ) ) ) ) ;
}
}
/**
* 省级平台导出检测计划数据
*
@@ -838,7 +858,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
planExcelList . get ( i ) . setSource ( pqSources . stream ( ) . map ( PqSource : : getName ) . collect ( Collectors . joining ( StrUtil . COMMA ) ) ) ;
PqDevParam . QueryParam queryParam1 = new PqDevParam . QueryParam ( ) ;
queryParam1 . setPlanIdList ( Arrays . as List( planList . get ( i ) . getId ( ) ) ) ;
queryParam1 . setPlanIdList ( Collections . singleton List( planList . get ( i ) . getId ( ) ) ) ;
List < PqDevVO > pqDevVOList = pqDevMapper . selectByQueryParam ( queryParam1 ) ;
pqDevService . visualizeProvinceDev ( pqDevVOList ) ;
List < ProvinceDevExcel > deviceExportData = BeanUtil . copyToList ( pqDevVOList , ProvinceDevExcel . class ) ;
@@ -861,7 +881,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
planExcelList . get ( i ) . setSource ( pqSources . stream ( ) . map ( PqSource : : getName ) . collect ( Collectors . joining ( StrUtil . COMMA ) ) ) ;
PqDevParam . QueryParam queryParam1 = new PqDevParam . QueryParam ( ) ;
queryParam1 . setPlanIdList ( Arrays . as List( planList . get ( i ) . getId ( ) ) ) ;
queryParam1 . setPlanIdList ( Collections . singleton List( planList . get ( i ) . getId ( ) ) ) ;
List < PqDevVO > pqDevs = pqDevMapper . selectByQueryParam ( queryParam1 ) ;
pqDevService . visualizeCNDev ( pqDevs ) ;
List < CNDevExcel > deviceExportData = BeanUtil . copyToList ( pqDevs , CNDevExcel . class ) ;
@@ -943,7 +963,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
List < CNDevExcel > cnDevExcelList = planExcel . getDevices ( ) ;
pqDevService . importCNDev ( cnDevExcelList , patternId , planId ) ;
tableGenService . deleteTable ( Arrays . as List( code . toString ( ) ) ) ;
tableGenService . deleteTable ( Collections . singleton List( code . toString ( ) ) ) ;
tableGenService . genTable ( code . toString ( ) , PatternEnum . CONTRAST . getValue ( ) . equals ( patternCode ) ) ;
}
// 逆向可视化
@@ -1001,7 +1021,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
Integer code = this . generateCode ( ) ;
adPlans . get ( i ) . setCode ( code ) ;
tableGenService . deleteTable ( Arrays . as List( code . toString ( ) ) ) ;
tableGenService . deleteTable ( Collections . singleton List( code . toString ( ) ) ) ;
tableGenService . genTable ( code . toString ( ) , PatternEnum . CONTRAST . getValue ( ) . equals ( patternCode ) ) ;
String source = planExcel . getSource ( ) ;
@@ -1484,4 +1504,137 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
}
return pullDowns ;
}
@Override
public void exportSubPlanDataZip ( String planId , HttpServletResponse response ) {
AdSubPlanMetaDataVO subPlanMetaData = new AdSubPlanMetaDataVO ( ) ;
// 获取所有字典数据
AdSubPlanMetaDataVO . Dict dict = new AdSubPlanMetaDataVO . Dict ( ) ;
List < DictType > dictTypeList = dictTypeService . list ( ) ;
List < DictData > dictDataList = dictDataService . list ( ) ;
List < DictTree > dictTreeList = dictTreeService . list ( ) ;
dict . setTypeList ( dictTypeList ) ;
dict . setDataList ( dictDataList ) ;
dict . setTreeList ( dictTreeList ) ;
subPlanMetaData . setDict ( dict ) ;
// 获取检测相关配置
SysTestConfig testConfig = sysTestConfigService . getOneConfig ( ) ;
subPlanMetaData . setTestConfig ( testConfig ) ;
// 获取误差体系数据
List < PqErrSys > errSysList = pqErrSysService . list ( ) ;
subPlanMetaData . setErrSysList ( errSysList ) ;
List < PqErrSysDtls > errSysDtlsList = pqErrSysDtlsService . list ( ) ;
subPlanMetaData . setErrSysDtlsList ( errSysDtlsList ) ;
// 获取检测计划基本数据
AdPlan subPlan = this . getById ( planId ) ;
subPlanMetaData . setPlan ( subPlan ) ;
// 获取检设备类型数据
List < DevType > devTypeList = devTypeService . list ( ) ;
subPlanMetaData . setDevTypeList ( devTypeList ) ;
// 获取检测计划绑定的被检设备数据
List < PqDev > devList = pqDevService . list ( new QueryWrapper < PqDev > ( ) . eq ( " Plan_Id " , planId ) ) ;
if ( CollUtil . isNotEmpty ( devList ) ) {
List < String > devIds = devList . stream ( ) . map ( PqDev : : getId ) . collect ( Collectors . toList ( ) ) ;
// 被检设备监测点
List < PqMonitor > pqMonitorList = pqMonitorService . lambdaQuery ( ) . in ( PqMonitor : : getDevId , devIds ) . list ( ) ;
Map < String , List < PqMonitor > > monitorListMap = pqMonitorList . stream ( ) . collect ( Collectors . groupingBy ( PqMonitor : : getDevId ) ) ;
devList . forEach ( dev - > {
dev . setMonitorList ( monitorListMap . getOrDefault ( dev . getId ( ) , new ArrayList < > ( ) ) ) ;
} ) ;
}
subPlanMetaData . setDevList ( devList ) ;
// 获取检测计划绑定的标准设备数据
List < PqStandardDev > standardDevList = adPlanStandardDevMapper . listByPlanId ( Collections . singletonList ( planId ) ) ;
subPlanMetaData . setStandardDevList ( standardDevList ) ;
// 获取检测计划关联的检测报告模板数据以及文件
PqReport reportTemplate = SpringUtil . getBean ( IPqReportService . class ) . getById ( subPlan . getReportTemplateId ( ) ) ;
subPlanMetaData . setReportTemplate ( reportTemplate ) ;
String basePath = reportTemplate . getBasePath ( ) ;
// 导出数据.zip文件
String jsonStr = JSONUtil . toJsonStr ( subPlanMetaData ) ;
try {
// 创建临时目录
File tempDir = FileUtil . mkdir ( FileUtil . getTmpDirPath ( ) + " export_ " + System . currentTimeMillis ( ) + " / " ) ;
// 创建 JSON 文件
String jsonFileName = subPlan . getName ( ) + " .json " ;
File jsonFile = FileUtil . file ( tempDir , jsonFileName ) ;
FileUtil . writeUtf8String ( jsonStr , jsonFile ) ;
// 创建 ZIP 文件
String zipFileName = URLEncoder . encode ( subPlan . getName ( ) + " .zip " , " UTF-8 " ) ;
File zipFile = FileUtil . file ( tempDir , zipFileName ) ;
// 先将json文件添加到zip中
ZipUtil . zip ( jsonFile . getAbsolutePath ( ) , zipFile . getAbsolutePath ( ) ) ;
// 如果basePath存在, 则将basePath中的文件添加到已有的zip文件中
if ( FileUtil . exist ( basePath ) ) {
File baseFile = new File ( basePath ) ;
if ( baseFile . isDirectory ( ) ) {
// 如果是目录, 将目录内容添加到zip中
File [ ] files = baseFile . listFiles ( ) ;
if ( files ! = null & & files . length > 0 ) {
// 创建一个临时目录用于存放所有需要压缩的文件
File tempZipDir = FileUtil . mkdir ( FileUtil . getTmpDirPath ( ) + " zip_temp_ " + System . currentTimeMillis ( ) + " / " ) ;
// 复制json文件到临时目录
FileUtil . copy ( jsonFile , tempZipDir , true ) ;
// 复制basePath目录下的所有文件到临时目录
for ( File file : files ) {
FileUtil . copy ( file , tempZipDir , true ) ;
}
// 重新创建zip文件, 包含所有文件
ZipUtil . zip ( tempZipDir . getAbsolutePath ( ) , zipFile . getAbsolutePath ( ) ) ;
// 删除临时目录
FileUtil . del ( tempZipDir ) ;
}
} else {
// 如果是单个文件,创建一个临时目录存放两个文件
File tempZipDir = FileUtil . mkdir ( FileUtil . getTmpDirPath ( ) + " zip_temp_ " + System . currentTimeMillis ( ) + " / " ) ;
// 复制json文件到临时目录
FileUtil . copy ( jsonFile , tempZipDir , true ) ;
// 复制baseFile到临时目录
FileUtil . copy ( baseFile , tempZipDir , true ) ;
// 重新创建zip文件, 包含所有文件
ZipUtil . zip ( tempZipDir . getAbsolutePath ( ) , zipFile . getAbsolutePath ( ) ) ;
// 删除临时目录
FileUtil . del ( tempZipDir ) ;
}
}
// 设置响应头
response . reset ( ) ;
response . setContentType ( " application/octet-stream;charset=UTF-8 " ) ;
response . setHeader ( " Content-Disposition " , " attachment; filename= \" " + zipFileName + " \" " ) ;
// 将 ZIP 文件写入响应
ServletOutputStream os = response . getOutputStream ( ) ;
FileUtil . writeToStream ( zipFile , os ) ;
os . flush ( ) ;
os . close ( ) ;
// 删除临时文件
FileUtil . del ( tempDir ) ;
} catch ( IOException e ) {
log . error ( " 导出子计划.zip文件失败: " , e ) ;
throw new BusinessException ( CommonResponseEnum . FAIL ) ;
}
}
}