You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
weaver-develop/src/com/engine/forstarsecond/service/impl/ExamineRankingServiceImpl.java

182 lines
7.0 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.engine.forstarsecond.service.impl;
import com.engine.core.impl.Service;
import com.engine.forstarsecond.entity.ExamineRanking;
import com.engine.forstarsecond.entity.FamilyWorkUnit;
import com.engine.forstarsecond.service.ExamineRankingService;
import lombok.SneakyThrows;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetDataSource;
import weaver.general.Util;
import weaver.hrm.resource.ResourceComInfo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @Author liang.cheng
* @Date 2025/4/27 10:04
* @Description: TODO
* @Version 1.0
*/
public class ExamineRankingServiceImpl extends Service implements ExamineRankingService {
@Override
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"));
String yglb = Util.null2String(params.get("yglb"));
List<ExamineRanking> examineRankings;
if ("1".equals(type)) {
examineRankings = calculateWorkers(khqj,yglb);
}else {
examineRankings = calculateWorkersByYear(khnd,yglb);
}
return examineRankings.size();
}
@Override
public List<ExamineRanking> calculateWorkers(String khqj,String yglb) {
RecordSet rs = new RecordSet();
List<ExamineRanking> examineRankings = new ArrayList<>();
rs.executeQuery("select id,ydzhdf,ssks,bmmc from uf_hr_ydjxkhpj_data where khqj = ? and yglb = ?",khqj,yglb);
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,String yglb) {
RecordSet rs = new RecordSet();
List<ExamineRanking> examineRankings = new ArrayList<>();
rs.executeQuery("select id,ndzhdf,ssks,bmmc from uf_hr_jxkhndpjb where khnd = ? and yglb = ?",year,yglb);
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;
}
@SneakyThrows
@Override
public Map<String,Object> resourceImage(String billid) {
RecordSet rs = new RecordSet();
Map<String,Object> result = new HashMap<>();
rs.executeQuery("select ryid from uf_hr_employee where id = ?",billid);
rs.next();
String ryid = Util.null2String(rs.getString("ryid"));
result.put("id",ryid);
result.put("url",new ResourceComInfo().getMessagerUrls(ryid));
return result;
}
@Override
public List<String> workUnits() {
RecordSetDataSource rst = new weaver.conn.RecordSetDataSource();
List<String> unitList = new ArrayList<>();
rst.executeQueryWithDatasource("select VndName from V_OA_BPVnd","psxt");
while (rst.next()) {
unitList.add(Util.null2String(rst.getString("VndName").trim()));
}
return unitList;
}
@Override
public Map<String,List<String>> familyWorkUnit(Map<String, Object> params) {
RecordSet rs = new RecordSet();
String type = Util.null2String(params.get("type"));
//1 正式员工台账
String tableName = "1".equals(type) ? "uf_jcl_rzgl_dt3" : "uf_jcl_wbrzgl_dt3";
List<FamilyWorkUnit> familyWorkUnits = new ArrayList<>();
rs.executeQuery("select mainid,gzdw from "+tableName);
while (rs.next()) {
familyWorkUnits.add(FamilyWorkUnit.builder()
.id(Util.null2String(rs.getString("mainid")))
.unit(Util.null2String(rs.getString("gzdw")))
.build());
}
return familyWorkUnits.stream()
.collect(Collectors.groupingBy(
FamilyWorkUnit::getId,
Collectors.mapping(
FamilyWorkUnit::getUnit,
Collectors.toList()
)
));
}
/**
* 通用排名计算方法
* @param dataList
* @param groupKeyGetter
* @param rankFieldSetter
*/
private void calculateRank(
List<ExamineRanking> dataList,
Function<ExamineRanking, Integer> groupKeyGetter,
BiConsumer<ExamineRanking, String> rankFieldSetter
) {
// 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);
}
});
}
}