@ -8,8 +8,12 @@ import com.biutag.supervision.common.UserContextHolder;
import com.biutag.supervision.constants.enums.DistributionCycleEnum ;
import com.biutag.supervision.constants.enums.DistributionCycleEnum ;
import com.biutag.supervision.constants.enums.DistributionMethodEnum ;
import com.biutag.supervision.constants.enums.DistributionMethodEnum ;
import com.biutag.supervision.mapper.ModelMapper ;
import com.biutag.supervision.mapper.ModelMapper ;
import com.biutag.supervision.pojo.dto.ModelClueMappingData ;
import com.biutag.supervision.pojo.dto.ModelClueMappingItem ;
import com.biutag.supervision.pojo.dto.ModelDto ;
import com.biutag.supervision.pojo.dto.flow.VerifyData ;
import com.biutag.supervision.pojo.dto.flow.VerifyData ;
import com.biutag.supervision.pojo.entity.Model ;
import com.biutag.supervision.pojo.entity.Model ;
import com.biutag.supervision.pojo.entity.ModelGeneration ;
import com.biutag.supervision.pojo.entity.ModelProblemType ;
import com.biutag.supervision.pojo.entity.ModelProblemType ;
import com.biutag.supervision.pojo.model.UserAuth ;
import com.biutag.supervision.pojo.model.UserAuth ;
import com.biutag.supervision.util.ExpressionBuilder ;
import com.biutag.supervision.util.ExpressionBuilder ;
@ -19,6 +23,8 @@ import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime ;
import java.time.LocalDateTime ;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.stream.Collectors ;
@RequiredArgsConstructor
@RequiredArgsConstructor
@Service
@Service
@ -26,12 +32,14 @@ public class ModelService extends ServiceImpl<ModelMapper, Model> {
private final ModelProblemTypeService modelProblemTypeService ;
private final ModelProblemTypeService modelProblemTypeService ;
private final ModelGenerationService modelGenerationService ;
public List < Model > listByDistributionMethodOfNegative ( ) {
public List < Model > listByDistributionMethodOfNegative ( ) {
return list ( new LambdaQueryWrapper < Model > ( ) . eq ( Model : : getDistributionMethod , DistributionMethodEnum . NEGATIVE_DISTRIBUTE . getValue ( ) ) ) ;
return list ( new LambdaQueryWrapper < Model > ( ) . eq ( Model : : getDistributionMethod , DistributionMethodEnum . NEGATIVE_DISTRIBUTE . getValue ( ) ) ) ;
}
}
@Transactional ( rollbackFor = Exception . class )
@Transactional ( rollbackFor = Exception . class )
public boolean saveModel ( Model model , List < VerifyData . Problem > problems ) {
public boolean saveModel ( Model model , List < VerifyData . Problem > problems , ModelDto modelDto ) {
if ( StrUtil . isNotBlank ( model . getDistributionCycle ( ) ) & & DistributionMethodEnum . NEGATIVE_DISTRIBUTE . getValue ( ) . equals ( model . getDistributionMethod ( ) ) ) {
if ( StrUtil . isNotBlank ( model . getDistributionCycle ( ) ) & & DistributionMethodEnum . NEGATIVE_DISTRIBUTE . getValue ( ) . equals ( model . getDistributionMethod ( ) ) ) {
String expression = DistributionCycleEnum . day . name ( ) . equals ( model . getDistributionCycle ( ) ) ? ExpressionBuilder . build ( model . getDistributionCycleTime ( ) ) :
String expression = DistributionCycleEnum . day . name ( ) . equals ( model . getDistributionCycle ( ) ) ? ExpressionBuilder . build ( model . getDistributionCycleTime ( ) ) :
ExpressionBuilder . build ( model . getDistributionCycleTime ( ) , model . getDistributionCycleDayOfWeek ( ) ) ;
ExpressionBuilder . build ( model . getDistributionCycleTime ( ) , model . getDistributionCycleDayOfWeek ( ) ) ;
@ -44,6 +52,13 @@ public class ModelService extends ServiceImpl<ModelMapper, Model> {
model . setCreateDepartId ( user . getDepartId ( ) ) ;
model . setCreateDepartId ( user . getDepartId ( ) ) ;
model . setCreateDepartName ( user . getDepartName ( ) ) ;
model . setCreateDepartName ( user . getDepartName ( ) ) ;
boolean save = save ( model ) ;
boolean save = save ( model ) ;
if ( "2" . equals ( modelDto . getModelingMethod ( ) ) & & modelDto . getModelGeneration ( ) ! = null ) {
modelDto . getModelGeneration ( ) . setModelId ( model . getId ( ) ) ;
modelDto . getModelGeneration ( ) . setCreateTime ( LocalDateTime . now ( ) ) ;
modelDto . getModelGeneration ( ) . setUpdateTime ( LocalDateTime . now ( ) ) ;
modelDto . getModelGeneration ( ) . setThingDescGeneration ( modelDto . getThingDescGeneration ( ) ) ;
modelGenerationService . save ( modelDto . getModelGeneration ( ) ) ;
}
if ( ! problems . isEmpty ( ) ) {
if ( ! problems . isEmpty ( ) ) {
List < ModelProblemType > problemTypes = problems . stream ( ) . map ( item - > {
List < ModelProblemType > problemTypes = problems . stream ( ) . map ( item - > {
ModelProblemType modelProblemType = new ModelProblemType ( ) ;
ModelProblemType modelProblemType = new ModelProblemType ( ) ;
@ -57,7 +72,7 @@ public class ModelService extends ServiceImpl<ModelMapper, Model> {
}
}
@Transactional ( rollbackFor = Exception . class )
@Transactional ( rollbackFor = Exception . class )
public boolean updateModel ( Model model , List < VerifyData . Problem > problems ) {
public boolean updateModel ( Model model , List < VerifyData . Problem > problems , ModelDto modelDto ) {
if ( StrUtil . isNotBlank ( model . getDistributionCycle ( ) ) & & DistributionMethodEnum . NEGATIVE_DISTRIBUTE . getValue ( ) . equals ( model . getDistributionMethod ( ) ) ) {
if ( StrUtil . isNotBlank ( model . getDistributionCycle ( ) ) & & DistributionMethodEnum . NEGATIVE_DISTRIBUTE . getValue ( ) . equals ( model . getDistributionMethod ( ) ) ) {
String expression = DistributionCycleEnum . day . name ( ) . equals ( model . getDistributionCycle ( ) ) ? ExpressionBuilder . build ( model . getDistributionCycleTime ( ) ) :
String expression = DistributionCycleEnum . day . name ( ) . equals ( model . getDistributionCycle ( ) ) ? ExpressionBuilder . build ( model . getDistributionCycleTime ( ) ) :
ExpressionBuilder . build ( model . getDistributionCycleTime ( ) , model . getDistributionCycleDayOfWeek ( ) ) ;
ExpressionBuilder . build ( model . getDistributionCycleTime ( ) , model . getDistributionCycleDayOfWeek ( ) ) ;
@ -74,12 +89,37 @@ public class ModelService extends ServiceImpl<ModelMapper, Model> {
} ) . toList ( ) ;
} ) . toList ( ) ;
modelProblemTypeService . saveBatch ( problemTypes ) ;
modelProblemTypeService . saveBatch ( problemTypes ) ;
}
}
if ( "2" . equals ( modelDto . getModelingMethod ( ) ) & & modelDto . getModelGeneration ( ) ! = null ) {
ModelGeneration one = modelGenerationService . getOne ( new LambdaQueryWrapper < ModelGeneration > ( ) . eq ( ModelGeneration : : getModelId , model . getId ( ) ) ) ;
if ( one ! = null ) {
modelDto . getModelGeneration ( ) . setId ( one . getId ( ) ) ;
modelDto . getModelGeneration ( ) . setCreateTime ( one . getCreateTime ( ) ) ;
}
modelDto . getModelGeneration ( ) . setModelId ( model . getId ( ) ) ;
modelDto . getModelGeneration ( ) . setUpdateTime ( LocalDateTime . now ( ) ) ;
modelDto . getModelGeneration ( ) . setThingDescGeneration ( modelDto . getThingDescGeneration ( ) ) ;
modelGenerationService . saveOrUpdate ( modelDto . getModelGeneration ( ) ) ;
}
return updateById ( model ) ;
return updateById ( model ) ;
}
}
@Transactional ( rollbackFor = Exception . class )
public boolean remove ( Integer modelId ) {
public boolean remove ( Integer modelId ) {
modelGenerationService . remove ( new LambdaQueryWrapper < ModelGeneration > ( ) . eq ( ModelGeneration : : getModelId , modelId ) ) ;
return removeById ( modelId ) ;
return removeById ( modelId ) ;
}
}
public List < ModelClueMappingData > listClueMappingData ( ) {
List < ModelClueMappingItem > items = baseMapper . selectClueMappingData ( ) ;
Map < String , List < ModelClueMappingItem > > collect = items . stream ( ) . collect ( Collectors . groupingBy ( ModelClueMappingItem : : getTableName ) ) ;
List < ModelClueMappingData > list = collect . keySet ( ) . stream ( ) . sorted ( ) . map ( tableName - > {
ModelClueMappingData data = new ModelClueMappingData ( ) ;
data . setTableName ( tableName ) ;
data . setFields ( collect . get ( tableName ) ) ;
return data ;
} ) . toList ( ) ;
return list ;
}
}
}