绩效POC
parent
2cd96be4e7
commit
140e728865
@ -1,12 +0,0 @@
|
|||||||
package com.api.jclpoc.web;
|
|
||||||
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author:dxfeng
|
|
||||||
* @createTime: 2024/04/17
|
|
||||||
* @version: 1.0
|
|
||||||
*/
|
|
||||||
@Path("/jcl/poc/entry")
|
|
||||||
public class PocEntryController extends com.engine.jclpoc.web.PocEntryController{
|
|
||||||
}
|
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.api.jclpoc.web;
|
||||||
|
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:dxfeng
|
||||||
|
* @createTime: 2024/05/08
|
||||||
|
* @version: 1.0
|
||||||
|
*/
|
||||||
|
@Path("/jcl/poc/pocperformance")
|
||||||
|
public class PocPerformanceController extends com.engine.jclpoc.web.PocPerformanceController{
|
||||||
|
}
|
@ -1,53 +0,0 @@
|
|||||||
package com.engine.jclpoc.web;
|
|
||||||
|
|
||||||
import cn.hutool.core.convert.Convert;
|
|
||||||
import com.engine.common.util.ParamUtil;
|
|
||||||
import weaver.conn.RecordSet;
|
|
||||||
import weaver.general.Util;
|
|
||||||
import weaver.hrm.HrmUserVarify;
|
|
||||||
import weaver.hrm.User;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.core.Context;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author:dxfeng
|
|
||||||
* @createTime: 2024/04/17
|
|
||||||
* @version: 1.0
|
|
||||||
*/
|
|
||||||
public class PocEntryController {
|
|
||||||
@GET
|
|
||||||
@Path("/getStaffInfo")
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
public Map<String, Object> getStaffInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
|
||||||
Map<String, Object> map = ParamUtil.request2Map(request);
|
|
||||||
Map<String, Object> returnMap = new HashMap<>();
|
|
||||||
returnMap.put("api_status",false);
|
|
||||||
String bm = Util.null2String(map.get("bm"));
|
|
||||||
RecordSet rs = new RecordSet();
|
|
||||||
int staff_num = 0;
|
|
||||||
int permanent_num = 0;
|
|
||||||
int freeze_num = 0;
|
|
||||||
rs.executeQuery("select staff_num,permanent_num,freeze_num from jcl_org_staff a inner join jcl_org_staffplan b on a.plan_id = b.id and b.forbidden_tag = 0 and b.delete_type = 0 where ec_department = ? and a.job_id is null and a.delete_type = 0", bm);
|
|
||||||
if (rs.next()) {
|
|
||||||
staff_num = Convert.toInt(rs.getString("staff_num"), 0);
|
|
||||||
permanent_num = Convert.toInt(rs.getString("permanent_num"), 0);
|
|
||||||
freeze_num = Convert.toInt(rs.getString("freeze_num"), 0);
|
|
||||||
returnMap.put("staff_num", staff_num);
|
|
||||||
returnMap.put("permanent_num", permanent_num);
|
|
||||||
returnMap.put("freeze_num", freeze_num);
|
|
||||||
returnMap.put("num", staff_num - permanent_num - freeze_num);
|
|
||||||
returnMap.put("api_status",true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnMap;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,56 @@
|
|||||||
|
package com.engine.jclpoc.web;
|
||||||
|
|
||||||
|
import com.engine.common.util.ParamUtil;
|
||||||
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.general.Util;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:dxfeng
|
||||||
|
* @createTime: 2024/05/08
|
||||||
|
* @version: 1.0
|
||||||
|
*/
|
||||||
|
public class PocPerformanceController {
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/getTotalScore")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Map<String, Object> getTotalScore(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||||
|
Map<String, Object> map = ParamUtil.request2Map(request);
|
||||||
|
Map<String, Object> returnMap = new HashMap<>();
|
||||||
|
returnMap.put("api_status", true);
|
||||||
|
String hdId = Util.null2String(map.get("hdId"));
|
||||||
|
String bpr = Util.null2String(map.get("bpr"));
|
||||||
|
RecordSet rs = new RecordSet();
|
||||||
|
// 查询明细表已完成评价且得分不为空的数据
|
||||||
|
rs.executeQuery("select * from uf_360pjhd_dt2 where mainid = ? and bpr = ? and sfpjwc = 1 and df is not null", hdId, bpr);
|
||||||
|
int count = 0;
|
||||||
|
double sum = 0;
|
||||||
|
if (rs.next()) {
|
||||||
|
count++;
|
||||||
|
sum += rs.getDouble("df");
|
||||||
|
}
|
||||||
|
if (count > 0 && sum > 0) {
|
||||||
|
// 计算并保留两位小数
|
||||||
|
BigDecimal dividend = new BigDecimal(sum);
|
||||||
|
BigDecimal divisor = new BigDecimal(count);
|
||||||
|
BigDecimal result = dividend.divide(divisor, 2, RoundingMode.HALF_UP);
|
||||||
|
returnMap.put("totalScore", result);
|
||||||
|
} else {
|
||||||
|
returnMap.put("totalScore", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnMap;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,98 @@
|
|||||||
|
package weaver.formmode.poc.modeexpand.evaluate;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew;
|
||||||
|
import weaver.general.Util;
|
||||||
|
import weaver.hrm.resource.ResourceComInfo;
|
||||||
|
import weaver.soa.workflow.request.MainTableInfo;
|
||||||
|
import weaver.soa.workflow.request.Property;
|
||||||
|
import weaver.soa.workflow.request.RequestInfo;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评价人员定义 添加评价人员
|
||||||
|
*
|
||||||
|
* @author:dxfeng
|
||||||
|
* @createTime: 2024/05/07
|
||||||
|
* @version: 1.0
|
||||||
|
*/
|
||||||
|
public class AddEvaluationMemberExpand extends AbstractModeExpandJavaCodeNew {
|
||||||
|
@Override
|
||||||
|
public Map<String, String> doModeExpand(Map<String, Object> param) {
|
||||||
|
Map<String, String> result = new HashMap<>(2);
|
||||||
|
RecordSet rs = new RecordSet();
|
||||||
|
try {
|
||||||
|
int billId;
|
||||||
|
int modeId;
|
||||||
|
RequestInfo requestInfo = (RequestInfo) param.get("RequestInfo");
|
||||||
|
if (requestInfo != null) {
|
||||||
|
billId = Util.getIntValue(requestInfo.getRequestid());
|
||||||
|
modeId = Util.getIntValue(requestInfo.getWorkflowid());
|
||||||
|
if (billId > 0 && modeId > 0) {
|
||||||
|
Map<String, String> mainDataMap = new HashMap<>(3);
|
||||||
|
MainTableInfo mainTableInfo = requestInfo.getMainTableInfo();
|
||||||
|
Property[] properties = mainTableInfo.getProperty();
|
||||||
|
for (Property property : properties) {
|
||||||
|
mainDataMap.put(property.getName(), property.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
String bpr = mainDataMap.get("bpr");
|
||||||
|
if (StringUtils.isNotBlank(bpr)) {
|
||||||
|
ResourceComInfo resourceComInfo = new ResourceComInfo();
|
||||||
|
String[] bprSplit = bpr.split(",");
|
||||||
|
for (String s : bprSplit) {
|
||||||
|
String departmentId = resourceComInfo.getDepartmentID(s);
|
||||||
|
// 查询同部门下的所有评价人
|
||||||
|
rs.executeQuery("select id from hrmresource where departmentid = ? and id != ?", departmentId, s);
|
||||||
|
while (rs.next()) {
|
||||||
|
Map<String, Object> insertMap = new HashMap<>(4);
|
||||||
|
// 主表ID
|
||||||
|
insertMap.put("mainid", billId);
|
||||||
|
// 评价人
|
||||||
|
insertMap.put("pjr", rs.getString("id"));
|
||||||
|
// 被评人
|
||||||
|
insertMap.put("bpr", s);
|
||||||
|
// 未评价
|
||||||
|
insertMap.put("sfpjwc", "0");
|
||||||
|
// 插入数据
|
||||||
|
insertData(insertMap, "uf_360pjhd_dt2");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
rs.writeLog(e);
|
||||||
|
result.put("errmsg", "添加评价人员拓展异常");
|
||||||
|
result.put("flag", "false");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void insertData(Map<String, Object> dataMap, String tableName) {
|
||||||
|
List<String> fieldList = new ArrayList<>();
|
||||||
|
List<Object> dataList = new ArrayList<>();
|
||||||
|
List<String> paramList = new ArrayList<>();
|
||||||
|
|
||||||
|
dataMap.forEach((key, value) -> {
|
||||||
|
if (null != value) {
|
||||||
|
fieldList.add(key);
|
||||||
|
dataList.add(value);
|
||||||
|
paramList.add("?");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
String insertSql = " insert into " + tableName + "(" + StringUtils.join(fieldList, ",") + ") values (" + StringUtils.join(paramList, ",") + ")";
|
||||||
|
RecordSet rs = new RecordSet();
|
||||||
|
rs.executeUpdate(insertSql, dataList);
|
||||||
|
if (StringUtils.isNotBlank(rs.getExceptionMsg())) {
|
||||||
|
throw new RuntimeException(rs.getExceptionMsg());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,88 +0,0 @@
|
|||||||
package weaver.interfaces.jcl.poc.action;
|
|
||||||
|
|
||||||
import com.engine.common.util.ServiceUtil;
|
|
||||||
import com.engine.hrm.service.impl.OrganizationServiceImpl;
|
|
||||||
import weaver.conn.RecordSet;
|
|
||||||
import weaver.general.BaseBean;
|
|
||||||
import weaver.general.Util;
|
|
||||||
import weaver.hrm.User;
|
|
||||||
import weaver.interfaces.workflow.action.Action;
|
|
||||||
import weaver.soa.workflow.request.MainTableInfo;
|
|
||||||
import weaver.soa.workflow.request.Property;
|
|
||||||
import weaver.soa.workflow.request.RequestInfo;
|
|
||||||
import weaver.workflow.request.RequestManager;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 组织调整流程,归档Action
|
|
||||||
*
|
|
||||||
* @author:dxfeng
|
|
||||||
* @createTime: 2024/04/17
|
|
||||||
* @version: 1.0
|
|
||||||
*/
|
|
||||||
public class AdjustDepartmentNameAction implements Action {
|
|
||||||
@Override
|
|
||||||
public String execute(RequestInfo requestInfo) {
|
|
||||||
try {
|
|
||||||
RequestManager requestManager = requestInfo.getRequestManager();
|
|
||||||
User user = requestManager.getUser();
|
|
||||||
MainTableInfo mainTableInfo = requestInfo.getMainTableInfo();
|
|
||||||
Property[] propertyArray = mainTableInfo.getProperty();
|
|
||||||
Map<String, String> mainMap = new HashMap<>(16);
|
|
||||||
|
|
||||||
for (Property property : propertyArray) {
|
|
||||||
mainMap.put(property.getName(), property.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
String departmentId = mainMap.get("yzz");
|
|
||||||
String newDepartmentName = mainMap.get("gm");
|
|
||||||
RecordSet rs = new RecordSet();
|
|
||||||
// 更新部门全称、简称
|
|
||||||
rs.executeUpdate("update hrmdepartment set departmentmark = ?,departmentname = ? where id = ?", newDepartmentName, newDepartmentName, departmentId);
|
|
||||||
Map<String, Object> map = new HashMap<>();
|
|
||||||
// 构建原来的部门数据集合
|
|
||||||
buildEcDepartmentData(map, departmentId);
|
|
||||||
map.put("departmentmark", newDepartmentName);
|
|
||||||
map.put("departmentname", newDepartmentName);
|
|
||||||
Map<String, Object> resultMap = ServiceUtil.getService(OrganizationServiceImpl.class, user).editDepartment(map, user);
|
|
||||||
if ("-1".equals(Util.null2String(resultMap.get("status")))) {
|
|
||||||
requestInfo.getRequestManager().setMessagecontent(Util.null2String(resultMap.get("message")));
|
|
||||||
return FAILURE_AND_CONTINUE;
|
|
||||||
}
|
|
||||||
return SUCCESS;
|
|
||||||
} catch (Exception e) {
|
|
||||||
new BaseBean().writeLog(e);
|
|
||||||
requestInfo.getRequestManager().setMessagecontent("操作失败,请联系系统管理处理");
|
|
||||||
return FAILURE_AND_CONTINUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建原部门信息集合
|
|
||||||
*
|
|
||||||
* @param map
|
|
||||||
* @param ecDepartment
|
|
||||||
*/
|
|
||||||
private void buildEcDepartmentData(Map<String, Object> map, String ecDepartment) {
|
|
||||||
map.put("id", ecDepartment);
|
|
||||||
RecordSet rs = new RecordSet();
|
|
||||||
// 先查拓展表
|
|
||||||
rs.execute("select * from hrmdepartmentdefined where deptid = '" + ecDepartment + "'");
|
|
||||||
int colcount = rs.getColCounts();
|
|
||||||
if (rs.next()) {
|
|
||||||
for (int i = 1; i <= colcount; i++) {
|
|
||||||
map.put(rs.getColumnName(i).toLowerCase(), Util.null2String(rs.getString(i)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 再查主表
|
|
||||||
rs.execute("select * from hrmdepartment where id = '" + ecDepartment + "'");
|
|
||||||
colcount = rs.getColCounts();
|
|
||||||
if (rs.next()) {
|
|
||||||
for (int i = 1; i <= colcount; i++) {
|
|
||||||
map.put(rs.getColumnName(i).toLowerCase(), Util.null2String(rs.getString(i)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,78 +0,0 @@
|
|||||||
package weaver.interfaces.jcl.poc.action;
|
|
||||||
|
|
||||||
import com.engine.common.util.ServiceUtil;
|
|
||||||
import com.engine.organization.entity.staff.param.StaffOutParam;
|
|
||||||
import com.engine.organization.enums.StaffChangeEnum;
|
|
||||||
import com.engine.organization.exception.OrganizationRunTimeException;
|
|
||||||
import com.engine.organization.service.impl.StaffOutServiceImpl;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.poi.util.StringUtil;
|
|
||||||
import weaver.conn.RecordSet;
|
|
||||||
import weaver.general.BaseBean;
|
|
||||||
import weaver.hrm.User;
|
|
||||||
import weaver.interfaces.workflow.action.Action;
|
|
||||||
import weaver.soa.workflow.request.MainTableInfo;
|
|
||||||
import weaver.soa.workflow.request.Property;
|
|
||||||
import weaver.soa.workflow.request.RequestInfo;
|
|
||||||
import weaver.workflow.request.RequestManager;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author:dxfeng
|
|
||||||
* @createTime: 2024/04/17
|
|
||||||
* @version: 1.0
|
|
||||||
*/
|
|
||||||
public class AdjustDepartmentStaffAction implements Action {
|
|
||||||
@Override
|
|
||||||
public String execute(RequestInfo requestInfo) {
|
|
||||||
try {
|
|
||||||
RequestManager requestManager = requestInfo.getRequestManager();
|
|
||||||
User user = requestManager.getUser();
|
|
||||||
MainTableInfo mainTableInfo = requestInfo.getMainTableInfo();
|
|
||||||
Property[] propertyArray = mainTableInfo.getProperty();
|
|
||||||
Map<String, String> mainMap = new HashMap<>(16);
|
|
||||||
|
|
||||||
for (Property property : propertyArray) {
|
|
||||||
mainMap.put(property.getName(), property.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
String departmentId = mainMap.get("bm");
|
|
||||||
String dz = mainMap.get("dz");
|
|
||||||
|
|
||||||
// 查询对应的该部门对应的编制方案
|
|
||||||
String planId = "";
|
|
||||||
String companyId = "";
|
|
||||||
RecordSet rs = new RecordSet();
|
|
||||||
rs.executeQuery("select a.plan_id , a.ec_company from jcl_org_staff a inner join jcl_org_staffplan b on a.plan_id = b.id and b.forbidden_tag = 0 and b.delete_type = 0 where a.ec_department = ? and a.job_id is null and a.delete_type = 0", departmentId);
|
|
||||||
if (rs.next()) {
|
|
||||||
planId = rs.getString("plan_id");
|
|
||||||
companyId = rs.getString("ec_company");
|
|
||||||
}
|
|
||||||
if (StringUtils.isBlank(planId)) {
|
|
||||||
requestInfo.getRequestManager().setMessagecontent("未获取到编制信息,请先在编制信息列表维护该部门编制");
|
|
||||||
return FAILURE_AND_CONTINUE;
|
|
||||||
}
|
|
||||||
int dzNum = Integer.parseInt(dz);
|
|
||||||
StaffOutServiceImpl staffOutService = ServiceUtil.getService(StaffOutServiceImpl.class, user);
|
|
||||||
StaffOutParam staffOutParam = new StaffOutParam();
|
|
||||||
staffOutParam.setType(dzNum > 0 ? StaffChangeEnum.ADD : StaffChangeEnum.REDUCE);
|
|
||||||
staffOutParam.setPlanId(Integer.parseInt(planId));
|
|
||||||
staffOutParam.setCompany(Integer.parseInt(companyId));
|
|
||||||
staffOutParam.setDepartment(Integer.parseInt(departmentId));
|
|
||||||
staffOutParam.setChangeMode(1);
|
|
||||||
staffOutParam.setNum(Math.abs(dzNum));
|
|
||||||
Integer integer = staffOutService.changeStaff(staffOutParam);
|
|
||||||
return SUCCESS;
|
|
||||||
|
|
||||||
} catch (OrganizationRunTimeException e) {
|
|
||||||
requestInfo.getRequestManager().setMessagecontent(e.getMessage());
|
|
||||||
return FAILURE_AND_CONTINUE;
|
|
||||||
} catch (Exception e) {
|
|
||||||
new BaseBean().writeLog(e);
|
|
||||||
requestInfo.getRequestManager().setMessagecontent("操作失败,请联系系统管理处理");
|
|
||||||
return FAILURE_AND_CONTINUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,233 @@
|
|||||||
|
package weaver.interfaces.poc.action;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.general.BaseBean;
|
||||||
|
import weaver.interfaces.workflow.action.Action;
|
||||||
|
import weaver.soa.workflow.request.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:dxfeng
|
||||||
|
* @createTime: 2024/05/08
|
||||||
|
* @version: 1.0
|
||||||
|
*/
|
||||||
|
public class PerformanceDistributionAction implements Action {
|
||||||
|
@Override
|
||||||
|
public String execute(RequestInfo requestInfo) {
|
||||||
|
BaseBean baseBean = new BaseBean();
|
||||||
|
try {
|
||||||
|
MainTableInfo mainTableInfo = requestInfo.getMainTableInfo();
|
||||||
|
|
||||||
|
DetailTableInfo detailTableInfo = requestInfo.getDetailTableInfo();
|
||||||
|
DetailTable detailTable0 = detailTableInfo.getDetailTable(0);
|
||||||
|
|
||||||
|
List<Rule> ruleList = new ArrayList<>();
|
||||||
|
Row[] rows0 = detailTable0.getRow();
|
||||||
|
for (Row row : rows0) {
|
||||||
|
Rule rule = new Rule();
|
||||||
|
Cell[] cells = row.getCell();
|
||||||
|
for (Cell cell : cells) {
|
||||||
|
String name = cell.getName();
|
||||||
|
String value = cell.getValue();
|
||||||
|
if ("jxdj".equals(name)) {
|
||||||
|
rule.setRuleName(value);
|
||||||
|
} else if ("fbbl".equals(name)) {
|
||||||
|
rule.setRuleRange(Double.parseDouble(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
ruleList.add(rule);
|
||||||
|
}
|
||||||
|
|
||||||
|
ruleList.forEach(item -> baseBean.writeLog(JSON.toJSONString(item)));
|
||||||
|
|
||||||
|
|
||||||
|
DetailTable detailTable1 = detailTableInfo.getDetailTable(1);
|
||||||
|
String tableDBName = detailTable1.getTableDBName();
|
||||||
|
Row[] rows1 = detailTable1.getRow();
|
||||||
|
List<Result> resultList = new ArrayList<>();
|
||||||
|
for (Row row : rows1) {
|
||||||
|
Cell[] cells = row.getCell();
|
||||||
|
Result result = new Result();
|
||||||
|
result.setId(row.getId());
|
||||||
|
for (Cell cell : cells) {
|
||||||
|
String name = cell.getName();
|
||||||
|
String value = cell.getValue();
|
||||||
|
if ("khzzdf".equals(name)) {
|
||||||
|
result.setScore(StringUtils.isBlank(value) ? "0" : value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resultList.add(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 所有人员排名
|
||||||
|
LinkedHashSet<Integer> rankSet = calculateRankings(resultList);
|
||||||
|
baseBean.writeLog("排名");
|
||||||
|
resultList.forEach(item -> baseBean.writeLog(JSON.toJSONString(item)));
|
||||||
|
|
||||||
|
ArrayList<Integer> rankList = new ArrayList<>(rankSet);
|
||||||
|
// 根据排名,按照分部比例划分
|
||||||
|
int subStart = 0;
|
||||||
|
for (int i = 0; i < ruleList.size(); i++) {
|
||||||
|
Rule rule = ruleList.get(i);
|
||||||
|
double ruleRange = rule.getRuleRange();
|
||||||
|
//int subEnd = subStart!=0?(int) Math.floor(rankList.size() * ruleRange):(int) Math.ceil(rankList.size() * ruleRange);
|
||||||
|
// 向下取
|
||||||
|
int subEnd = (int) Math.floor(rankList.size() * ruleRange);
|
||||||
|
if (i == 0 && subEnd < 1) {
|
||||||
|
subEnd = 1;
|
||||||
|
}
|
||||||
|
if (i == ruleList.size() && subEnd < ruleList.size()) {
|
||||||
|
subEnd = rankList.size();
|
||||||
|
}
|
||||||
|
List<Integer> rangeList = rankList.subList(subStart, subEnd);
|
||||||
|
for (Integer integer : rangeList) {
|
||||||
|
for (Result result : resultList) {
|
||||||
|
if (result.getRank().equals(integer)) {
|
||||||
|
result.setLevel(rule.getRuleName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subStart = subEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
baseBean.writeLog("划分等级");
|
||||||
|
|
||||||
|
// 更新明细表
|
||||||
|
RecordSet rs = new RecordSet();
|
||||||
|
String updateSql = "update " + tableDBName + " set khdj = ? where id = ?";
|
||||||
|
for (Result result : resultList) {
|
||||||
|
baseBean.writeLog(JSON.toJSONString(result));
|
||||||
|
rs.executeUpdate(updateSql, result.getLevel(), result.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return SUCCESS;
|
||||||
|
} catch (Exception e) {
|
||||||
|
baseBean.writeLog(e);
|
||||||
|
return FAILURE_AND_CONTINUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LinkedHashSet<Integer> calculateRankings(List<Result> resultList) {
|
||||||
|
LinkedHashSet<Integer> rankSet = new LinkedHashSet<>();
|
||||||
|
|
||||||
|
|
||||||
|
Collections.sort(resultList, (o1, o2) -> {
|
||||||
|
return o2.getScore().compareTo(o1.getScore()); // 按值(分数)降序排序
|
||||||
|
});
|
||||||
|
|
||||||
|
// 计算排名并输出
|
||||||
|
int rank = 1;
|
||||||
|
double prevScore = -1;
|
||||||
|
for (Result result : resultList) {
|
||||||
|
double score = Double.parseDouble(result.getScore());
|
||||||
|
if (score < prevScore) {
|
||||||
|
rank++;
|
||||||
|
}
|
||||||
|
prevScore = score;
|
||||||
|
result.setRank(rank);
|
||||||
|
rankSet.add(rank);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return rankSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
//public static LinkedHashSet<Integer> calculateRankings(List<Result> resultList) {
|
||||||
|
// LinkedHashSet<Integer> rankSet = new LinkedHashSet<>();
|
||||||
|
// int rank = 1;
|
||||||
|
// double prevScore = Integer.MAX_VALUE;
|
||||||
|
// double sameScoreCount = 0;
|
||||||
|
//
|
||||||
|
// for (Result result : resultList) {
|
||||||
|
// double score = Double.parseDouble(result.getScore());
|
||||||
|
// if (score < prevScore) {
|
||||||
|
// rank += sameScoreCount;
|
||||||
|
// sameScoreCount = 1;
|
||||||
|
// } else {
|
||||||
|
// sameScoreCount++;
|
||||||
|
// }
|
||||||
|
// result.setRank(rank);
|
||||||
|
// rankSet.add(rank);
|
||||||
|
// prevScore = score;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return rankSet;
|
||||||
|
//}
|
||||||
|
|
||||||
|
static class Rule {
|
||||||
|
String ruleName;
|
||||||
|
double ruleRange;
|
||||||
|
|
||||||
|
public Rule() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rule(String ruleName, double ruleRange) {
|
||||||
|
this.ruleName = ruleName;
|
||||||
|
this.ruleRange = ruleRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRuleName() {
|
||||||
|
return ruleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRuleName(String ruleName) {
|
||||||
|
this.ruleName = ruleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getRuleRange() {
|
||||||
|
return ruleRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRuleRange(double ruleRange) {
|
||||||
|
this.ruleRange = ruleRange;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class Result {
|
||||||
|
String id;
|
||||||
|
String score;
|
||||||
|
String level;
|
||||||
|
Integer rank;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getScore() {
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScore(String score) {
|
||||||
|
this.score = score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLevel() {
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLevel(String level) {
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getRank() {
|
||||||
|
return rank;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRank(Integer rank) {
|
||||||
|
this.rank = rank;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue