@@ -1,10 +1,14 @@
package com.njcn.supervision.service.survey.impl ;
import cn.hutool.core.collection.CollectionUtil ;
import cn.hutool.core.date.DatePattern ;
import cn.hutool.core.date.DateUtil ;
import cn.hutool.core.date.LocalDateTimeUtil ;
import cn.hutool.core.text.StrPool ;
import cn.hutool.core.util.StrUtil ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.core.toolkit.IdWorker ;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page ;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl ;
import com.njcn.bpm.api.BpmProcessFeignClient ;
@@ -15,12 +19,18 @@ import com.njcn.bpm.pojo.param.instance.BpmProcessInstanceCancelParam;
import com.njcn.common.pojo.enums.common.DataStateEnum ;
import com.njcn.device.pq.api.LineFeignClient ;
import com.njcn.device.pq.pojo.dto.PollutionSubstationDTO ;
import com.njcn.supervision.enums.FlowStatusEnum ;
import com.njcn.supervision.enums.LeafletTypeEnum ;
import com.njcn.supervision.enums.ProblemTypeEnum ;
import com.njcn.supervision.mapper.survey.SurveyTestMapper ;
import com.njcn.supervision.pojo.param.survey.SurveyTestParam ;
import com.njcn.supervision.pojo.po.survey.SupervisionGeneralSurveyPlanDetailPO ;
import com.njcn.supervision.pojo.po.survey.SupervisionGeneralSurveyPlanPO ;
import com.njcn.supervision.pojo.po.survey.SurveyPlan ;
import com.njcn.supervision.pojo.po.survey.SurveyTest ;
import com.njcn.supervision.pojo.vo.survey.SurveyPlanVO ;
import com.njcn.supervision.pojo.vo.survey.SurveyTestVO ;
import com.njcn.supervision.service.leaflet.IWarningLeafletService ;
import com.njcn.supervision.service.survey.ISurveyPlanService ;
import com.njcn.supervision.service.survey.ISurveyTestService ;
import com.njcn.supervision.utils.InstanceUtil ;
@@ -38,6 +48,7 @@ import java.util.HashMap;
import java.util.List ;
import java.util.Map ;
import java.util.Objects ;
import java.util.stream.Collectors ;
/**
* <p>
@@ -64,6 +75,8 @@ public class SurveyTestServiceImpl extends ServiceImpl<SurveyTestMapper, SurveyT
@Resource
private ISurveyPlanService surveyPlanService ;
@Resource
private IWarningLeafletService warningLeafletService ;
/**
* 预告警单的反馈单对应的流程定义 KEY
@@ -76,12 +89,22 @@ public class SurveyTestServiceImpl extends ServiceImpl<SurveyTestMapper, SurveyT
QueryWrapper < SurveyTestVO > surveyTestVOQueryWrapper = new QueryWrapper < > ( ) ;
if ( Objects . nonNull ( surveyTestQueryParam ) ) {
//添加上时间范围
surveyTestVOQueryWrapper . between ( " supervision_survey_test.C reate_T ime " ,
surveyTestVOQueryWrapper . between ( " supervision_survey_test.c reate_t ime " ,
DateUtil . beginOfDay ( DateUtil . parse ( surveyTestQueryParam . getSearchBeginTime ( ) ) ) ,
DateUtil . endOfDay ( DateUtil . parse ( surveyTestQueryParam . getSearchEndTime ( ) ) ) ) ;
//根据工程名称模糊搜索
if ( StrUtil . isNotBlank ( surveyTestQueryParam . getSearchValue ( ) ) ) {
surveyTestVO QueryWrapper. like ( " supervision_survey_test.plan_name " , surveyTestQueryParam . getSearchValue ( ) ) ;
Lambda QueryWrapper< SurveyPlan > surveyPlanLambdaQueryWrapper = new LambdaQueryWrapper < > ( ) ;
surveyPlanLambdaQueryWrapper . eq ( SurveyPlan : : getState , DataStateEnum . ENABLE . getCode ( ) )
. like ( SurveyPlan : : getPlanName , surveyTestQueryParam . getSearchValue ( ) ) ;
List < SurveyPlan > surveyPlans = surveyPlanService . getBaseMapper ( ) . selectList ( surveyPlanLambdaQueryWrapper ) ;
if ( CollectionUtil . isNotEmpty ( surveyPlans ) ) {
List < String > planIds = surveyPlans . stream ( ) . map ( SurveyPlan : : getId ) . collect ( Collectors . toList ( ) ) ;
surveyTestVOQueryWrapper . in ( " supervision_survey_test.plan_id " , planIds ) ;
}
} else {
//没有匹配的。直接返回
return new Page < > ( ) ;
}
}
//获取当前用户部门所有同事的id, 查看该部门下所有的数据
@@ -108,6 +131,55 @@ public class SurveyTestServiceImpl extends ServiceImpl<SurveyTestMapper, SurveyT
return surveyTestVOPage ;
}
@Override
public Page < SurveyTestVO > pageProblemSurvey ( SurveyTestParam . SurveyTestQueryParam surveyTestQueryParam ) {
QueryWrapper < SurveyTestVO > surveyTestVOQueryWrapper = new QueryWrapper < > ( ) ;
if ( Objects . nonNull ( surveyTestQueryParam ) ) {
//添加上时间范围
surveyTestVOQueryWrapper . between ( " supervision_survey_test.create_time " ,
DateUtil . beginOfDay ( DateUtil . parse ( surveyTestQueryParam . getSearchBeginTime ( ) ) ) ,
DateUtil . endOfDay ( DateUtil . parse ( surveyTestQueryParam . getSearchEndTime ( ) ) ) ) ;
//根据工程名称模糊搜索
if ( StrUtil . isNotBlank ( surveyTestQueryParam . getSearchValue ( ) ) ) {
LambdaQueryWrapper < SurveyPlan > surveyPlanLambdaQueryWrapper = new LambdaQueryWrapper < > ( ) ;
surveyPlanLambdaQueryWrapper . eq ( SurveyPlan : : getState , DataStateEnum . ENABLE . getCode ( ) )
. like ( SurveyPlan : : getPlanName , surveyTestQueryParam . getSearchValue ( ) ) ;
List < SurveyPlan > surveyPlans = surveyPlanService . getBaseMapper ( ) . selectList ( surveyPlanLambdaQueryWrapper ) ;
if ( CollectionUtil . isNotEmpty ( surveyPlans ) ) {
List < String > planIds = surveyPlans . stream ( ) . map ( SurveyPlan : : getId ) . collect ( Collectors . toList ( ) ) ;
surveyTestVOQueryWrapper . in ( " supervision_survey_test.plan_id " , planIds ) ;
} else {
//没有匹配的。直接返回
return new Page < > ( ) ;
}
}
}
//获取当前用户部门所有同事的id, 查看该部门下所有的数据
List < String > colleaguesIds = userFeignClient . getColleaguesIdByUserId ( RequestUtil . getUserIndex ( ) ) . getData ( ) ;
surveyTestVOQueryWrapper . in ( " supervision_survey_test.Create_By " , colleaguesIds )
. eq ( " supervision_survey_test.problem_flag " , 1 )
. eq ( " supervision_survey_test.status " , FlowStatusEnum . APPROVE . getCode ( ) )
. eq ( " supervision_survey_test.state " , DataStateEnum . ENABLE . getCode ( ) )
. orderByDesc ( " supervision_survey_test.Update_Time " ) ;
Page < SurveyTestVO > surveyTestVOPage = this . baseMapper . surveyTestPage ( new Page < > ( PageFactory . getPageNum ( surveyTestQueryParam ) , PageFactory . getPageSize ( surveyTestQueryParam ) ) , surveyTestVOQueryWrapper ) ;
List < SurveyTestVO > records = surveyTestVOPage . getRecords ( ) ;
if ( CollectionUtil . isNotEmpty ( records ) ) {
for ( SurveyTestVO record : records ) {
//回显部门名称
record . setDeptName ( deptFeignClient . getDeptById ( record . getDeptId ( ) ) . getData ( ) . getName ( ) ) ;
//回显变电站名称
if ( record . getCustomSubstationFlag ( ) = = 0 ) {
//关联台账内的变电站名称
String substation = record . getSubstation ( ) ;
record . setSubstationName ( lineFeignClient . getSubstationInfo ( substation ) . getData ( ) . getName ( ) ) ;
} else {
record . setSubstationName ( record . getSubstation ( ) ) ;
}
}
}
return surveyTestVOPage ;
}
@Override
@Transactional ( rollbackFor = Exception . class )
public String addSurveyTest ( SurveyTestParam surveyTestParam ) {
@@ -211,4 +283,46 @@ public class SurveyTestServiceImpl extends ServiceImpl<SurveyTestMapper, SurveyT
}
return surveyTestVO ;
}
@Override
@Transactional ( rollbackFor = Exception . class )
public void initiateWarningLeaflet ( String id ) {
SurveyTestVO surveyTestVO = this . getVOById ( id ) ;
/*
* 1、预告警单名称, 此处暂时用普测计划名称+变电站名称组成预告警单名
* 2、预告警编号暂时随机by yxb
* 3、问题类型: 1: 技术监督管理; 2: 在线监测超标问题; 3: 用户投诉; 4: 现场测试超标, 此处是现场测试超标
* 4、对应问题源id, 用于查询详细数据
* 5、单子类型: 1: 预警单; 2: 告警单
* 6、问题详细描述
* */
warningLeafletService . createLeaflet (
surveyTestVO . getPlanName ( ) . concat ( StrPool . UNDERLINE ) . concat ( surveyTestVO . getSubstationName ( ) ) ,
IdWorker . get32UUID ( ) ,
id ,
ProblemTypeEnum . SITE_TEST . getCode ( ) ,
LeafletTypeEnum . ALARM . getCode ( ) ,
assembleIssueDetail ( surveyTestVO )
) ;
//将当前的测试数据改为已告警
this . lambdaUpdate ( ) . eq ( SurveyTest : : getId , id ) . set ( SurveyTest : : getInitiateWarningFlag , 1 ) . update ( ) ;
}
/**
* 组装谐波普测的问题
* 格式: planCreateTime发起的planName普测计划, 由负责人leader测试后, 于planComplateTime完成, 其中subName在本次普测计划测试中存在电能质量问题, 详细请查看附件
*/
private String assembleIssueDetail ( SurveyTestVO surveyTestVO ) {
return " 变电站: " . concat ( surveyTestVO . getSubstationName ( ) )
. concat ( " 在 " )
. concat ( LocalDateTimeUtil . format ( surveyTestVO . getCreateTime ( ) , DatePattern . CHINESE_DATE_PATTERN ) )
. concat ( " 发起的 " )
. concat ( surveyTestVO . getPlanName ( ) )
. concat ( " 普测计划,由负责人 " )
. concat ( surveyTestVO . getCompleteBy ( ) )
. concat ( " 测试后,于 " )
. concat ( LocalDateTimeUtil . format ( surveyTestVO . getCompleteTime ( ) , DatePattern . CHINESE_DATE_PATTERN ) )
. concat ( " 完成变电站电能质量测试, " )
. concat ( " 在本次普测计划测试中存在电能质量问题,详细请查看问题附件 " ) ;
}
}