@@ -2,10 +2,16 @@ package com.njcn.supervision.service.user.impl;
import cn.hutool.core.collection.CollectionUtil ;
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.extension.plugins.pagination.Page ;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl ;
import com.njcn.bpm.api.BpmProcessFeignClient ;
import com.njcn.bpm.pojo.dto.BpmProcessInstanceCreateReqDTO ;
import com.njcn.common.pojo.enums.common.DataStateEnum ;
import com.njcn.common.pojo.exception.BusinessException ;
import com.njcn.supervision.enums.FlowStatusEnum ;
import com.njcn.supervision.enums.UserNatureEnum ;
import com.njcn.supervision.mapper.user.UserReportPOMapper ;
import com.njcn.supervision.pojo.param.user.UserReportParam ;
import com.njcn.supervision.pojo.po.user.UserReportPO ;
@@ -24,14 +30,12 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeanWrapper ;
import org.springframework.beans.BeanWrapperImpl ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import java.util.HashSet ;
import java.util.Li st ;
import java.util.Objects ;
import java.util.Set ;
import java.util.* ;
import java.util.stream.Collectors ;
/**
*
* Description:
* Date: 2024/4/25 10:07【需求编号】
*
@@ -42,59 +46,91 @@ import java.util.Set;
@RequiredArgsConstructor
public class UserReportPOServiceImpl extends ServiceImpl < UserReportPOMapper , UserReportPO > implements UserReportPOService {
/**
* 用户信息建档对应的流程定义 KEY
*/
public static final String PROCESS_KEY = " build_user_info " ;
private final UserReportProjectPOService userReportProjectPOService ;
private final UserReportSubstationPOService userReportSubstationPOService ;
private final UserReportSensitivePOService userReportSensitivePOService ;
private final BpmProcessFeignClient bpmProcessFeignClient ;
@Override
public boolean addUserReport ( UserReportParam userReportParam ) {
@Transactional ( rollbackFor = Exception . class )
public String addUserReport ( UserReportParam userReportParam ) {
//判断工程名称是否有重复的
checkProjectName ( userReportParam , false ) ;
UserReportPO userReportPO = new UserReportPO ( ) ;
BeanUtils . copyProperties ( userReportParam , userReportPO ) ;
userReportPO . setState ( 1 ) ;
boolean save = this . save ( userReportPO ) ;
String id = userReportPO . getId ( ) ;
if ( Objects . equals ( userReportPO . getUserType ( ) , " 1 " ) | |
Objects . equals ( userReportPO . getUserTyp e ( ) , " 2 " ) ) {
BeanUtils . copyProperties ( userReportParam , userReportPO ) ;
userReportPO . setState ( DataStateEnum . ENABLE . getCode ( ) ) ;
this . save ( userReportPO ) ;
if (
CollectionUtil . newArrayList (
UserNatureEnum . BUILD_POWER_GRID . getCod e ( ) ,
UserNatureEnum . EXTEND_POWER_GRID . getCode ( )
) . contains ( userReportPO . getUserType ( ) ) ) {
//电网工程类用户额外数据
UserReportProjectPO userReportProjectPO = userReportParam . getUserReportProjectPO ( ) ;
userReportProjectPO . setId ( id ) ;
userReportProjectPO . setState ( 1 ) ;
userReportProjectPO . setId ( userReportPO . getId ( ) ) ;
userReportProjectPO . setState ( DataStateEnum . ENABLE . getCode ( ) ) ;
userReportProjectPOService . saveOrUpdate ( userReportProjectPO ) ;
} else if (Objects . equals ( userReportPO . getUserType ( ) , " 3 " ) | |
Objects . equals ( userReportPO . getUserType ( ) , " 4 " ) ) {
} else if (
CollectionUtil . newArrayList (
UserNatureEnum . BUILD_NON_LINEAR_LOAD . getCode ( ) ,
UserNatureEnum . EXTEND_NON_LINEAR_LOAD . getCode ( ) ,
UserNatureEnum . BUILD_NEW_ENERGY_POWER_STATION . getCode ( ) ,
UserNatureEnum . EXTEND_NEW_ENERGY_POWER_STATION . getCode ( )
) . contains ( userReportPO . getUserType ( ) ) ) {
//非线性负荷用户 & 新能源发电站用户
UserReportSubstationPO userReportSubstationPO = userReportParam . getUserReportSubstationPO ( ) ;
userReportSubstationPO . setId ( id ) ;
userReportSubstationPO . setState ( 1 ) ;
userReportSubstationPO . setId ( userReportPO . getId ( ) ) ;
userReportSubstationPO . setState ( DataStateEnum . ENABLE . getCode ( ) ) ;
userReportSubstationPOService . saveOrUpdate ( userReportSubstationPO ) ;
} else if ( Objects . equals ( userReportPO . getUserType ( ) , " 5 " ) ) {
} else if ( UserNatureEnum . SENSITIVE_USER . getCode ( ) . equals ( userReportPO . getUserType ( ) ) ) {
// 敏感及重要用户
UserReportSensitivePO userReportSensitivePO = userReportParam . getUserReportSensitivePO ( ) ;
userReportSensitivePO . setId ( id ) ;
userReportSensitivePO . setState ( 1 ) ;
userReportSensitivePO . setId ( userReportPO . getId ( ) ) ;
userReportSensitivePO . setState ( DataStateEnum . ENABLE . getCode ( ) ) ;
userReportSensitivePOService . saveOrUpdate ( userReportSensitivePO ) ;
}
// 发起 BPM 流程
Map < String , Object > processInstanceVariables = new HashMap < > ( ) ;
BpmProcessInstanceCreateReqDTO bpmProcessInstanceCreateReqDTO = new BpmProcessInstanceCreateReqDTO ( ) ;
bpmProcessInstanceCreateReqDTO . setProcessDefinitionKey ( PROCESS_KEY ) ;
bpmProcessInstanceCreateReqDTO . setBusinessKey ( userReportPO . getId ( ) ) ;
bpmProcessInstanceCreateReqDTO . setStartUserSelectAssignees ( userReportParam . getStartUserSelectAssignees ( ) ) ;
bpmProcessInstanceCreateReqDTO . setVariables ( processInstanceVariables ) ;
String processInstanceId = bpmProcessFeignClient . createProcessInstance ( userReportPO . getCreateBy ( ) , bpmProcessInstanceCreateReqDTO ) . getData ( ) ;
// 将工作流的编号,更新到流程单中
userReportPO . setProcessInstanceId ( processInstanceId ) ;
this . baseMapper . updateById ( userReportPO ) ;
return save ;
return userReportPO . getId ( ) ;
}
@Override
public boolean auditUserReport ( UserReportParam . UserReportUpdate userReportUpdate ) {
String id = userReportUpdate . getId ( ) ;
UserReportPO byId = this . getById ( id ) ;
BeanUtils . copyProperties ( userReportUpdate , byId ) ;
BeanUtils . copyProperties ( userReportUpdate , byId ) ;
this . updateById ( byId ) ;
if ( Objects . equals ( userReportUpdate . getUserType ( ) , " 1 " ) | |
Objects . equals ( userReportUpdate . getUserType ( ) , " 2 " ) ) {
if ( Objects . equals ( userReportUpdate . getUserType ( ) , " 1 " ) | |
Objects . equals ( userReportUpdate . getUserType ( ) , " 2 " ) ) {
UserReportProjectPO userReportProjectPO = userReportProjectPOService . getById ( id ) ;
BeanUtils . copyProperties ( userReportUpdate . getUserReportProjectPO ( ) , userReportProjectPO , getNullPropertyNames ( userReportUpdate . getUserReportProjectPO ( ) ) ) ;
BeanUtils . copyProperties ( userReportUpdate . getUserReportProjectPO ( ) , userReportProjectPO , getNullPropertyNames ( userReportUpdate . getUserReportProjectPO ( ) ) ) ;
userReportProjectPOService . updateById ( userReportProjectPO ) ;
} else if ( Objects . equals ( userReportUpdate . getUserType ( ) , " 3 " ) | |
Objects . equals ( userReportUpdate . getUserType ( ) , " 4 " ) ) {
UserReportSubstationPO userReportSubstationPO = userReportSubstationPOService . getById ( id ) ;
BeanUtils . copyProperties ( userReportUpdate . getUserReportSubstationPO ( ) , userReportSubstationPO , getNullPropertyNames ( userReportUpdate . getUserReportSubstationPO ( ) ) ) ;
} else if ( Objects . equals ( userReportUpdate . getUserType ( ) , " 3 " ) | |
Objects . equals ( userReportUpdate . getUserType ( ) , " 4 " ) ) {
UserReportSubstationPO userReportSubstationPO = userReportSubstationPOService . getById ( id ) ;
BeanUtils . copyProperties ( userReportUpdate . getUserReportSubstationPO ( ) , userReportSubstationPO , getNullPropertyNames ( userReportUpdate . getUserReportSubstationPO ( ) ) ) ;
userReportSubstationPOService . updateById ( userReportSubstationPO ) ;
} else if ( Objects . equals ( userReportUpdate . getUserType ( ) , " 5 " ) ) {
UserReportSensitivePO userReportSensitivePO = userReportSensitivePOService . getById ( id ) ;
BeanUtils . copyProperties ( userReportUpdate . getUserReportSensitivePO ( ) , userReportSensitivePO , getNullPropertyNames ( userReportUpdate . getUserReportSensitivePO ( ) ) ) ;
} else if ( Objects . equals ( userReportUpdate . getUserType ( ) , " 5 " ) ) {
UserReportSensitivePO userReportSensitivePO = userReportSensitivePOService . getById ( id ) ;
BeanUtils . copyProperties ( userReportUpdate . getUserReportSensitivePO ( ) , userReportSensitivePO , getNullPropertyNames ( userReportUpdate . getUserReportSensitivePO ( ) ) ) ;
userReportSensitivePOService . updateById ( userReportSensitivePO ) ;
}
@@ -111,10 +147,10 @@ public class UserReportPOServiceImpl extends ServiceImpl<UserReportPOMapper, Use
QueryWrapper < UserReportVO > userReportVOQueryWrapper = new QueryWrapper < > ( ) ;
userReportVOQueryWrapper . in ( " supervision_user_report.create_by " , CollectionUtil . newArrayList ( userIndex ) )
. eq ( " supervision_user_report.state " , DataStateEnum . ENABLE . getCode ( ) ) ;
if ( Objects . nonNull ( userReportQueryParam ) ) {
if ( StrUtil . isNotBlank ( userReportQueryParam . getCity ( ) ) ) {
if ( Objects . nonNull ( userReportQueryParam ) ) {
if ( StrUtil . isNotBlank ( userReportQueryParam . getCity ( ) ) ) {
//查询所有区域下的数据
userReportVOQueryWrapper . in ( " supervision_user_report.city " , userReportQueryParam . getCity ( ) ) ;
userReportVOQueryWrapper . in ( " supervision_user_report.city " , userReportQueryParam . getCity ( ) ) ;
}
}
userReportVOQueryWrapper . orderByDesc ( " supervision_user_report.create_time " ) ;
@@ -123,10 +159,10 @@ public class UserReportPOServiceImpl extends ServiceImpl<UserReportPOMapper, Use
@Override
public Boolean removeUserReport ( List < String > ids ) {
this . lambdaUpdate ( ) . set ( UserReportPO : : getState , 0 ) . in ( UserReportPO : : getId , ids ) . update ( ) ;
userReportProjectPOService . lambdaUpdate ( ) . set ( UserReportProjectPO : : getState , 0 ) . in ( UserReportProjectPO : : getId , ids ) . update ( ) ;
userReportSubstationPOService . lambdaUpdate ( ) . set ( UserReportSubstationPO : : getState , 0 ) . in ( UserReportSubstationPO : : getId , ids ) . update ( ) ;
userReportSensitivePOService . lambdaUpdate ( ) . set ( UserReportSensitivePO : : getState , 0 ) . in ( UserReportSensitivePO : : getId , ids ) . update ( ) ;
this . lambdaUpdate ( ) . set ( UserReportPO : : getState , 0 ) . in ( UserReportPO : : getId , ids ) . update ( ) ;
userReportProjectPOService . lambdaUpdate ( ) . set ( UserReportProjectPO : : getState , 0 ) . in ( UserReportProjectPO : : getId , ids ) . update ( ) ;
userReportSubstationPOService . lambdaUpdate ( ) . set ( UserReportSubstationPO : : getState , 0 ) . in ( UserReportSubstationPO : : getId , ids ) . update ( ) ;
userReportSensitivePOService . lambdaUpdate ( ) . set ( UserReportSensitivePO : : getState , 0 ) . in ( UserReportSensitivePO : : getId , ids ) . update ( ) ;
return true ;
}
@@ -134,23 +170,55 @@ public class UserReportPOServiceImpl extends ServiceImpl<UserReportPOMapper, Use
/**
* 获取所有字段为null的属性名
*
* @param source
* @return
*/
public String [ ] getNullPropertyNames ( Object source ) {
public String [ ] getNullPropertyNames ( Object source ) {
final BeanWrapper src = new BeanWrapperImpl ( source ) ;
java . beans . PropertyDescriptor [ ] pds = src . getPropertyDescriptors ( ) ;
java . beans . PropertyDescriptor [ ] pds = src . getPropertyDescriptors ( ) ;
Set < String > emptyNames = new HashSet < String > ( ) ;
Set < String > emptyNames = new HashSet < > ( ) ;
for ( java . beans . PropertyDescriptor pd : pds ) {
Object srcValue = src . getPropertyValue ( pd . getName ( ) ) ;
if ( srcValue = = null ) {
emptyNames . add ( pd . getName ( ) ) ;
Object srcValue = src . getPropertyValue ( pd . getName ( ) ) ;
if ( srcValue = = null ) {
emptyNames . add ( pd . getName ( ) ) ;
}
}
String [ ] result = new String [ emptyNames . size ( ) ] ;
return emptyNames . toArray ( result ) ;
String [ ] result = new String [ emptyNames . size ( ) ] ;
return emptyNames . toArray ( result ) ;
}
/**
* 判断工程名称是否重复, 如果重复则提示用户XXX已经创建该工程
*
* @param userReportParam 用户申请数据
* @param isExcludeSelf 是否排除自己,一般新增不排除,更新时需要排除自己
*/
private void checkProjectName ( UserReportParam userReportParam , boolean isExcludeSelf ) {
LambdaQueryWrapper < UserReportPO > userReportPOLambdaQueryWrapper = new LambdaQueryWrapper < > ( ) ;
userReportPOLambdaQueryWrapper
. eq ( UserReportPO : : getProjectName , userReportParam . getProjectName ( ) )
. eq ( UserReportPO : : getState , DataStateEnum . ENABLE . getCode ( ) ) ;
//更新的时候,需排除当前记录
if ( isExcludeSelf ) {
if ( userReportParam instanceof UserReportParam . UserReportUpdate ) {
userReportPOLambdaQueryWrapper . ne ( UserReportPO : : getId , ( ( UserReportParam . UserReportUpdate ) userReportParam ) . getId ( ) ) ;
}
}
List < UserReportPO > userReportPOList = this . baseMapper . selectList ( userReportPOLambdaQueryWrapper ) ;
if ( CollectionUtil . isNotEmpty ( userReportPOList ) ) {
//过滤已取消的申请
userReportPOList = userReportPOList . stream ( )
. filter ( userReportPO - > ! userReportPO . getStatus ( ) . equals ( FlowStatusEnum . CANCEL . getCode ( ) ) )
. collect ( Collectors . toList ( ) ) ;
//如果还存在,则说明有人申请过了
if ( CollectionUtil . isNotEmpty ( userReportPOList ) ) {
throw new BusinessException ( userReportParam . getProjectName ( ) . concat ( " ,该工程已被 " ) . concat ( userReportPOList . get ( 0 ) . getReporter ( ) ) . concat ( " 申请 " ) ) ;
}
}
}
}