@ -10,6 +10,7 @@ import com.biutag.supervision.mapper.SupDictContentMapper;
import com.biutag.supervision.pojo.entity.* ;
import com.biutag.supervision.pojo.entity.* ;
import com.biutag.supervision.util.ScoreRule ;
import com.biutag.supervision.util.ScoreRule ;
import lombok.RequiredArgsConstructor ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.scheduling.annotation.Async ;
import org.springframework.scheduling.annotation.Async ;
import org.springframework.stereotype.Service ;
import org.springframework.stereotype.Service ;
@ -23,6 +24,7 @@ import java.util.stream.Collectors;
* @author wxc
* @author wxc
* @date 2024 / 11 / 12
* @date 2024 / 11 / 12
* /
* /
@Slf4j
@RequiredArgsConstructor
@RequiredArgsConstructor
@Service
@Service
public class NegativeScoreService {
public class NegativeScoreService {
@ -50,6 +52,7 @@ public class NegativeScoreService {
flag . set ( true ) ;
flag . set ( true ) ;
System . out . println ( "calculateScore-------------------------------------------------" ) ;
System . out . println ( "calculateScore-------------------------------------------------" ) ;
List < NegativeBlame > negativeBlames = blameMapper . selectVerifyTrue ( ) ;
List < NegativeBlame > negativeBlames = blameMapper . selectVerifyTrue ( ) ;
log . info ( "总共问题条数:{}" , negativeBlames . size ( ) ) ;
if ( negativeBlames . isEmpty ( ) ) {
if ( negativeBlames . isEmpty ( ) ) {
flag . set ( false ) ;
flag . set ( false ) ;
return ;
return ;
@ -61,9 +64,10 @@ public class NegativeScoreService {
Set < String > negativeIds = negativeBlames . stream ( ) . map ( NegativeBlame : : getNegativeId ) . collect ( Collectors . toSet ( ) ) ;
Set < String > negativeIds = negativeBlames . stream ( ) . map ( NegativeBlame : : getNegativeId ) . collect ( Collectors . toSet ( ) ) ;
List < NegativeProblemRelation > problemsAll = problemRelationService . list ( negativeIds ) ;
List < NegativeProblemRelation > problemsAll = problemRelationService . list ( negativeIds ) ;
List < Negative > negatives = negativeService . listByIds ( negativeIds ) ;
List < Negative > negatives = negativeService . listByIds ( negativeIds ) ;
List < SupDepart > departs = departService . listByIds ( negatives . stream ( ) . map ( Negative : : getInvolveDepartId ) . collect ( Collectors . toSet ( ) ) ) ;
negativeBlames . forEach ( blame - > {
negativeBlames . forEach ( blame - > {
Negative negative = negatives . stream ( ) . filter ( item - > item . getId ( ) . equals ( blame . getNegativeId ( ) ) ) . findFirst ( ) . get ( ) ;
Negative negative = negatives . stream ( ) . filter ( item - > item . getId ( ) . equals ( blame . getNegativeId ( ) ) ) . findFirst ( ) . get ( ) ;
SupDepart depart = departService . getBy Id ( negative . getInvolveDepartId ( ) ) ;
SupDepart depart = departs . stream ( ) . filter ( item - > item . getId ( ) . equals ( negative . getInvolveDepartId ( ) ) ) . findFirst ( ) . get ( ) ;
NegativeScorePolice negativeScorePolice = new NegativeScorePolice ( )
NegativeScorePolice negativeScorePolice = new NegativeScorePolice ( )
. setNegativeId ( blame . getNegativeId ( ) )
. setNegativeId ( blame . getNegativeId ( ) )
. setIdCode ( blame . getBlameIdCode ( ) )
. setIdCode ( blame . getBlameIdCode ( ) )
@ -151,17 +155,17 @@ public class NegativeScoreService {
if ( sd = = 0 ) {
if ( sd = = 0 ) {
return 0 ;
return 0 ;
}
}
List < BusinessPolice > businessPolices = businessPolice Service . list ( beginTime , endTime , businessTypeCode ) ;
List < BusinessDepart > businessDeparts = businessDepart Service . list ( beginTime , endTime , businessTypeCode ) ;
// 总业务量
// 总业务量
int totalBusinessSize = businessPolice s . stream ( ) . mapToInt ( BusinessPolice : : getNumber ) . sum ( ) ;
int totalBusinessSize = businessDepart s . stream ( ) . mapToInt ( BusinessDepart : : getNumber ) . sum ( ) ;
// 平均问题发生率
// 平均问题发生率
double avgRate = totalBusinessSize = = 0 ? 0 : NumberUtil . div ( businessScorePolice . size ( ) , totalBusinessSize ) ;
double avgRate = totalBusinessSize = = 0 ? 0 : NumberUtil . div ( businessScorePolice . size ( ) , totalBusinessSize ) ;
// 个人问题数
// 个人问题数
long personSize = businessScorePolice . stream ( ) . filter ( item - > police . getIdCode ( ) . equals ( item . getIdCode ( ) ) ) . count ( ) ;
long personSize = businessScorePolice . stream ( ) . filter ( item - > police . getOrg Id ( ) . equals ( item . getIdCode ( ) ) ) . count ( ) ;
// 个人 业务量
// 单位 业务量
long personBusinessSize = businessPolice s. stream ( ) . filter ( item - > police . getName ( ) . equals ( item . getPoliceName ( ) ) & & police . getEmpNo ( ) . equals ( item . getEmpNo ( ) ) ) . count ( ) ;
long departBusinessSize = businessDepart s. stream ( ) . filter ( item - > police . getOrgId ( ) . equals ( item . getDepartId ( ) ) ) . count ( ) ;
// 个人问题发生率
// 个人问题发生率
double personRate = person BusinessSize = = 0 ? 0 : NumberUtil . div ( personSize , person BusinessSize) ;
double personRate = depart BusinessSize = = 0 ? 0 : NumberUtil . div ( personSize , depart BusinessSize) ;
return NumberUtil . div ( personRate - avgRate , sd ) ;
return NumberUtil . div ( personRate - avgRate , sd ) ;
}
}
@ -222,10 +226,12 @@ public class NegativeScoreService {
List < NegativeScorePolice > scorePolices = negativeScorePoliceService . list ( beginTime , endTime , depart . getStatisticsGroupId ( ) ) ;
List < NegativeScorePolice > scorePolices = negativeScorePoliceService . list ( beginTime , endTime , depart . getStatisticsGroupId ( ) ) ;
Double totalScore = scorePolices . stream ( ) . mapToDouble ( NegativeScorePolice : : getScore ) . sum ( ) ;
Double totalScore = scorePolices . stream ( ) . mapToDouble ( NegativeScorePolice : : getScore ) . sum ( ) ;
List < String > expressionArr = new ArrayList < > ( ) ;
List < String > expressionArr = new ArrayList < > ( ) ;
StringBuilder remarks = new StringBuilder ( ) ;
double policeScore = Arrays . stream ( BusinessTypeEnum . values ( ) ) . mapToDouble ( businessTypeEnum - > {
double policeScore = Arrays . stream ( BusinessTypeEnum . values ( ) ) . mapToDouble ( businessTypeEnum - > {
List < NegativeScorePolice > businessScorePolice = scorePolices . stream ( ) . filter ( item - > item . getBusinessTypeCode ( ) . equals ( businessTypeEnum . getValue ( ) ) ) . toList ( ) ;
List < NegativeScorePolice > businessScorePolice = scorePolices . stream ( ) . filter ( item - > item . getBusinessTypeCode ( ) . equals ( businessTypeEnum . getValue ( ) ) ) . toList ( ) ;
// 业务涉及人数
// 业务涉及人数
int policeSize = businessScorePolice . stream ( ) . map ( NegativeScorePolice : : getIdCode ) . collect ( Collectors . toSet ( ) ) . size ( ) ;
int policeSize = businessScorePolice . stream ( ) . map ( NegativeScorePolice : : getIdCode ) . collect ( Collectors . toSet ( ) ) . size ( ) ;
remarks . append ( String . format ( "业务设计人数 %s" , policeSize ) ) ;
// 业务问题数
// 业务问题数
int businessSize = businessScorePolice . size ( ) ;
int businessSize = businessScorePolice . size ( ) ;
//---------------------------------------------------------
//---------------------------------------------------------
@ -236,6 +242,7 @@ public class NegativeScoreService {
double [ ] diffNumbers = group . values ( ) . stream ( ) . mapToDouble ( val - > val . size ( ) - avgNumber ) . toArray ( ) ;
double [ ] diffNumbers = group . values ( ) . stream ( ) . mapToDouble ( val - > val . size ( ) - avgNumber ) . toArray ( ) ;
// 业务标准差
// 业务标准差
double sd = calculateSd ( diffNumbers , policeSize ) ;
double sd = calculateSd ( diffNumbers , policeSize ) ;
log . info ( "业务标准差为:{}" , sd ) ;
// 业务差异值
// 业务差异值
double diff ;
double diff ;
long personalSize = businessScorePolice . stream ( ) . filter ( item - > idCode . equals ( item . getIdCode ( ) ) ) . count ( ) ;
long personalSize = businessScorePolice . stream ( ) . filter ( item - > idCode . equals ( item . getIdCode ( ) ) ) . count ( ) ;
@ -244,17 +251,25 @@ public class NegativeScoreService {
} else {
} else {
diff = calculateDiff2 ( personalSize , avgNumber , sd ) ;
diff = calculateDiff2 ( personalSize , avgNumber , sd ) ;
}
}
log . info ( "业务差异值为:{}" , diff ) ;
// 业务风险指数
// 业务风险指数
double businessScore = calculateBusinessScore ( diff , personalSize ) ;
double businessScore = calculateBusinessScore ( diff , personalSize ) ;
log . info ( "业务风险指数:{}" , businessScore ) ;
// 业务权重
// 业务权重
Double score = businessScorePolice . stream ( ) . mapToDouble ( NegativeScorePolice : : getScore ) . sum ( ) ;
Double score = businessScorePolice . stream ( ) . mapToDouble ( NegativeScorePolice : : getScore ) . sum ( ) ;
double businessWeight = calculateBusinessWeight ( totalScore , score ) ;
double businessWeight = calculateBusinessWeight ( totalScore , score ) ;
expressionArr . add ( String . format ( "(%s * %s)" , businessScore , businessWeight ) ) ;
expressionArr . add ( String . format ( "(%s * %s)" , businessScore , businessWeight ) ) ;
remarks . append ( String . format ( "%s:" , businessTypeEnum . getLabel ( ) ) ) . append ( "\n" ) ;
remarks . append ( String . format ( "业务涉及人数 %s" , policeSize ) ) . append ( "\n" ) ;
remarks . append ( String . format ( "业务问题数 %s" , businessSize ) ) . append ( "\n" ) ;
remarks . append ( String . format ( "平均问题数 %s" , avgNumber ) ) . append ( "\n" ) ;
remarks . append ( String . format ( "业务标准差 %s" , sd ) ) . append ( "\n" ) ;
remarks . append ( String . format ( "业务差异值 %s" , diff ) ) . append ( "\n" ) ;
return NumberUtil . mul ( businessScore , businessWeight ) ;
return NumberUtil . mul ( businessScore , businessWeight ) ;
} ) . sum ( ) ;
} ) . sum ( ) ;
BigDecimal score = NumberUtil . roundHalfEven ( policeScore , 2 ) ;
BigDecimal score = NumberUtil . roundHalfEven ( policeScore , 2 ) ;
String expression = String . join ( " + " , expressionArr ) ;
String expression = String . join ( " + " , expressionArr ) ;
return List . of ( score , expression ) ;
return List . of ( score , expression , remarks ) ;
}
}
/ * *
/ * *
@ -270,6 +285,7 @@ public class NegativeScoreService {
List < NegativeScoreDepart > scoreDeparts = negativeScoreDepartService . list ( beginTime , endTime , depart . getStatisticsGroupId ( ) ) ;
List < NegativeScoreDepart > scoreDeparts = negativeScoreDepartService . list ( beginTime , endTime , depart . getStatisticsGroupId ( ) ) ;
Double totalScore = scoreDeparts . stream ( ) . mapToDouble ( NegativeScoreDepart : : getScore ) . sum ( ) ;
Double totalScore = scoreDeparts . stream ( ) . mapToDouble ( NegativeScoreDepart : : getScore ) . sum ( ) ;
List < String > expressionArr = new ArrayList < > ( ) ;
List < String > expressionArr = new ArrayList < > ( ) ;
StringBuilder remarks = new StringBuilder ( ) ;
double policeScore = Arrays . stream ( BusinessTypeEnum . values ( ) ) . mapToDouble ( businessTypeEnum - > {
double policeScore = Arrays . stream ( BusinessTypeEnum . values ( ) ) . mapToDouble ( businessTypeEnum - > {
List < NegativeScoreDepart > businessScoreDeparts = scoreDeparts . stream ( ) . filter ( item - > item . getBusinessTypeCode ( ) . equals ( businessTypeEnum . getValue ( ) ) ) . toList ( ) ;
List < NegativeScoreDepart > businessScoreDeparts = scoreDeparts . stream ( ) . filter ( item - > item . getBusinessTypeCode ( ) . equals ( businessTypeEnum . getValue ( ) ) ) . toList ( ) ;
// 业务涉及人数
// 业务涉及人数
@ -296,6 +312,12 @@ public class NegativeScoreService {
Double score = businessScoreDeparts . stream ( ) . mapToDouble ( NegativeScoreDepart : : getScore ) . sum ( ) ;
Double score = businessScoreDeparts . stream ( ) . mapToDouble ( NegativeScoreDepart : : getScore ) . sum ( ) ;
double businessWeight = calculateBusinessWeight ( totalScore , score ) ;
double businessWeight = calculateBusinessWeight ( totalScore , score ) ;
expressionArr . add ( String . format ( "(%s * %s)" , businessScore , businessWeight ) ) ;
expressionArr . add ( String . format ( "(%s * %s)" , businessScore , businessWeight ) ) ;
remarks . append ( String . format ( "%s:" , businessTypeEnum . getLabel ( ) ) ) . append ( "\n" ) ;
remarks . append ( String . format ( "业务涉及人数 %s" , departSize ) ) . append ( "\n" ) ;
remarks . append ( String . format ( "当前部门问题数 %s" , personalSize ) ) . append ( "\n" ) ;
remarks . append ( String . format ( "平均问题数 %s" , avgNumber ) ) . append ( "\n" ) ;
remarks . append ( String . format ( "业务标准差 %s" , sd ) ) . append ( "\n" ) ;
remarks . append ( String . format ( "业务差异值 %s" , diff ) ) . append ( "\n" ) ;
return NumberUtil . mul ( businessScore , businessWeight ) ;
return NumberUtil . mul ( businessScore , businessWeight ) ;
} ) . sum ( ) ;
} ) . sum ( ) ;
BigDecimal score = NumberUtil . roundHalfEven ( policeScore , 2 ) ;
BigDecimal score = NumberUtil . roundHalfEven ( policeScore , 2 ) ;