@ -1,9 +1,17 @@
package com.engine.forstarsecond.service.impl ;
package com.engine.forstarsecond.service.impl ;
import com.engine.core.impl.Service ;
import com.engine.core.impl.Service ;
import com.engine.forstarsecond.entity.ExamineRanking ;
import com.engine.forstarsecond.service.ExamineRankingService ;
import com.engine.forstarsecond.service.ExamineRankingService ;
import weaver.conn.RecordSet ;
import weaver.general.Util ;
import java.util.ArrayList ;
import java.util.List ;
import java.util.Map ;
import java.util.Map ;
import java.util.function.BiConsumer ;
import java.util.function.Function ;
import java.util.stream.Collectors ;
/ * *
/ * *
* @Author liang . cheng
* @Author liang . cheng
@ -14,9 +22,105 @@ import java.util.Map;
public class ExamineRankingServiceImpl extends Service implements ExamineRankingService {
public class ExamineRankingServiceImpl extends Service implements ExamineRankingService {
@Override
@Override
public Map < String , Object > examineRanking ( Map < String , Object > params ) {
public int examineRanking ( Map < String , Object > params ) {
String type = Util . null2String ( params . get ( "type" ) ) ;
String khqj = Util . null2String ( params . get ( "khqj" ) ) ;
String khnd = Util . null2String ( params . get ( "khnd" ) ) ;
return null ;
List < ExamineRanking > examineRankings ;
if ( "1" . equals ( type ) ) {
examineRankings = calculateWorkers ( khqj ) ;
} else {
examineRankings = calculateWorkersByYear ( khnd ) ;
}
return examineRankings . size ( ) ;
}
@Override
public List < ExamineRanking > calculateWorkers ( String khqj ) {
RecordSet rs = new RecordSet ( ) ;
List < ExamineRanking > examineRankings = new ArrayList < > ( ) ;
rs . executeQuery ( "select id,ydzhdf,ssks,bmmc from uf_hr_ydjxkhpj_data where khqj = ?" , khqj ) ;
while ( rs . next ( ) ) {
examineRankings . add ( ExamineRanking . builder ( )
. id ( Util . getIntValue ( rs . getString ( "id" ) ) )
. df ( Util . getDoubleValue ( rs . getString ( "ydzhdf" ) ) )
. ssks ( Util . getIntValue ( rs . getString ( "ssks" ) ) )
. bmmc ( Util . getIntValue ( rs . getString ( "bmmc" ) ) )
. build ( ) ) ;
}
// 分别处理 ssks → kspm 和 bmmc → bmpm 的排名
calculateRank ( examineRankings , ExamineRanking : : getSsks , ExamineRanking : : setKspm ) ;
calculateRank ( examineRankings , ExamineRanking : : getBmmc , ExamineRanking : : setBmpm ) ;
examineRankings . forEach ( examine - > rs . executeUpdate ( "update uf_hr_ydjxkhpj_data set bmpm = ?,kspm = ? where id = ?" , examine . getBmpm ( ) , examine . getKspm ( ) , examine . getId ( ) ) ) ;
return examineRankings ;
}
@Override
public List < ExamineRanking > calculateWorkersByYear ( String year ) {
RecordSet rs = new RecordSet ( ) ;
List < ExamineRanking > examineRankings = new ArrayList < > ( ) ;
rs . executeQuery ( "select id,ndzhdf,ssks,bmmc from uf_hr_jxkhndpjb where khnd = ?" , year ) ;
while ( rs . next ( ) ) {
examineRankings . add ( ExamineRanking . builder ( )
. id ( Util . getIntValue ( rs . getString ( "id" ) ) )
. df ( Util . getDoubleValue ( rs . getString ( "ndzhdf" ) ) )
. ssks ( Util . getIntValue ( rs . getString ( "ssks" ) ) )
. bmmc ( Util . getIntValue ( rs . getString ( "bmmc" ) ) )
. build ( ) ) ;
}
// 分别处理 ssks → kspm 和 bmmc → bmpm 的排名
calculateRank ( examineRankings , ExamineRanking : : getSsks , ExamineRanking : : setKspm ) ;
calculateRank ( examineRankings , ExamineRanking : : getBmmc , ExamineRanking : : setBmpm ) ;
examineRankings . forEach ( examine - > rs . executeUpdate ( "update uf_hr_jxkhndpjb set bmpm = ?,kspm = ? where id = ?" , examine . getBmpm ( ) , examine . getKspm ( ) , examine . getId ( ) ) ) ;
return examineRankings ;
}
/ * *
* 通 用 排 名 计 算 方 法
* @param dataList
* @param groupKeyGetter
* @param rankFieldSetter
* /
private void calculateRank (
List < ExamineRanking > dataList ,
Function < ExamineRanking , Integer > groupKeyGetter , // 分组字段的 Getter
BiConsumer < ExamineRanking , String > rankFieldSetter // 排名结果的 Setter( 直接使用 BiConsumer)
) {
// 1. 按分组字段(如 ssks 或 bmmc) 分组
Map < Integer , List < ExamineRanking > > groupedData = dataList . stream ( )
. collect ( Collectors . groupingBy ( groupKeyGetter ) ) ;
// 2. 处理每个分组
groupedData . forEach ( ( groupKey , groupList ) - > {
// 按 ydzhdf 降序排序
groupList . sort ( ( a , b ) - > Double . compare ( b . getDf ( ) , a . getDf ( ) ) ) ;
int groupSize = groupList . size ( ) ;
if ( groupSize = = 0 ) {
return ;
}
// 动态计算排名
double previousScore = groupList . get ( 0 ) . getDf ( ) ;
int currentRank = 1 ;
rankFieldSetter . accept ( groupList . get ( 0 ) , currentRank + "/" + groupSize ) ;
for ( int i = 1 ; i < groupSize ; i + + ) {
ExamineRanking current = groupList . get ( i ) ;
if ( Math . abs ( current . getDf ( ) - previousScore ) > 1e-6 ) {
currentRank = i + 1 ;
previousScore = current . getDf ( ) ;
}
rankFieldSetter . accept ( current , currentRank + "/" + groupSize ) ;
}
} ) ;
}
}
}
}