红太阳POC
parent
c764c45c76
commit
c2f9a4dda6
@ -0,0 +1,12 @@
|
||||
package com.api.htypoc.web;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2024/09/08
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Path("/hty/poc")
|
||||
public class HtyController extends com.engine.hty.web.HtyController{
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
package com.engine.hty.web;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.engine.common.util.ParamUtil;
|
||||
import com.weaver.general.Util;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import weaver.conn.RecordSet;
|
||||
|
||||
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.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2024/09/08
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class HtyController {
|
||||
|
||||
@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 khzq = Util.null2String((String) map.get("khzq"));
|
||||
String xmkhry = Util.null2String((String) map.get("xmkhry"));
|
||||
String xmpfqz = Util.null2String((String) map.get("xmpfqz"));
|
||||
String gwzzpfqz = Util.null2String((String) map.get("gwzzpfqz"));
|
||||
String gwzzpf = Util.null2String((String) map.get("gwzzpf"));
|
||||
RecordSet rs = new RecordSet();
|
||||
List<Double> list = new ArrayList<>();
|
||||
// 考核周期。考核人员
|
||||
rs.executeQuery("select xmjldf from uf_xmkhpf where khzq = ? and xmkhry = ?", khzq, xmkhry);
|
||||
while (rs.next()) {
|
||||
list.add(Convert.toDouble(rs.getString("xmjldf"), 0D));
|
||||
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
Double total = 0D;
|
||||
for (Double i : list) {
|
||||
total += i;
|
||||
}
|
||||
BigDecimal totalDecimal = BigDecimal.valueOf(total);
|
||||
BigDecimal sizeDecimal = BigDecimal.valueOf(list.size());
|
||||
// 保留两位小数
|
||||
BigDecimal average = totalDecimal.divide(sizeDecimal, 2, RoundingMode.HALF_UP);
|
||||
returnMap.put("average", average);
|
||||
|
||||
//
|
||||
Double xmpfqzInt = Convert.toDouble(xmpfqz, 0D);
|
||||
if (xmpfqzInt == 0D) {
|
||||
returnMap.put("api_status", false);
|
||||
returnMap.put("msg", "项目评分权重转换失败");
|
||||
}
|
||||
Double gwzzpfqzInt = Convert.toDouble(gwzzpfqz, 0D);
|
||||
if (gwzzpfqzInt == 0D) {
|
||||
returnMap.put("api_status", false);
|
||||
returnMap.put("msg", "岗位职责评分权重转换失败");
|
||||
}
|
||||
Double gwzzpfInt = Convert.toDouble(gwzzpf, 0D);
|
||||
if (gwzzpfInt == 0D) {
|
||||
returnMap.put("api_status", false);
|
||||
returnMap.put("msg", "岗位职责评分转换失败");
|
||||
}
|
||||
BigDecimal xmpfqzBig = BigDecimal.valueOf(xmpfqzInt).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP);
|
||||
|
||||
BigDecimal gwzzpfqzBig = BigDecimal.valueOf(gwzzpfqzInt).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP);
|
||||
|
||||
BigDecimal result1 = average.multiply(xmpfqzBig).setScale(2, RoundingMode.HALF_UP);
|
||||
BigDecimal result2 = gwzzpfqzBig.multiply(BigDecimal.valueOf(gwzzpfInt)).setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
returnMap.put("result", result1.add(result2));
|
||||
}
|
||||
|
||||
|
||||
return returnMap;
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package weaver.formmode.hty.modeexpand.activity;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.workflow.webservices.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2024/09/06
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class FlowUtil {
|
||||
|
||||
public static String parseBlankToNull(String str) {
|
||||
return StringUtils.isBlank(str) ? null : str;
|
||||
}
|
||||
|
||||
public static List<Map<String, String>> getRecordMapList(RecordSet rs) {
|
||||
List<Map<String, String>> list = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
String[] columnNames = rs.getColumnName();
|
||||
Map<String, String> dataMap = new HashMap<>();
|
||||
for (String columnName : columnNames) {
|
||||
dataMap.put(columnName.toLowerCase(), parseBlankToNull(rs.getString(columnName)));
|
||||
}
|
||||
list.add(dataMap);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static WorkflowRequestTableField createWorkflowRequestTableField(String fieldName, String fieldValue) {
|
||||
WorkflowRequestTableField tableField = new WorkflowRequestTableField();
|
||||
tableField.setFieldName(fieldName);
|
||||
tableField.setFieldValue(fieldValue);
|
||||
tableField.setView(true);
|
||||
tableField.setEdit(true);
|
||||
return tableField;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建流程
|
||||
*
|
||||
* @param flowId
|
||||
* @param title
|
||||
* @param creatorId
|
||||
* @param isNextFlow
|
||||
* @param workflowMainTableInfo
|
||||
* @param workflowDetailTableInfoArray
|
||||
* @return
|
||||
*/
|
||||
public static String createWorkflow(String flowId, String title, String creatorId, String isNextFlow, WorkflowMainTableInfo workflowMainTableInfo, WorkflowDetailTableInfo[] workflowDetailTableInfoArray) {
|
||||
WorkflowBaseInfo workflowBaseInfo = new WorkflowBaseInfo();
|
||||
workflowBaseInfo.setWorkflowId(flowId);
|
||||
//工作流程请求信息
|
||||
WorkflowRequestInfo workflowRequestInfo = new WorkflowRequestInfo();
|
||||
//请求标题
|
||||
workflowRequestInfo.setRequestName(title);
|
||||
//请求重要级别
|
||||
workflowRequestInfo.setRequestLevel("1");
|
||||
//显示
|
||||
workflowRequestInfo.setCanView(true);
|
||||
//创建者id
|
||||
workflowRequestInfo.setCreatorId(creatorId);
|
||||
//工作流信息
|
||||
workflowRequestInfo.setWorkflowBaseInfo(workflowBaseInfo);
|
||||
//主表
|
||||
workflowRequestInfo.setWorkflowMainTableInfo(workflowMainTableInfo);
|
||||
workflowRequestInfo.setWorkflowDetailTableInfos(workflowDetailTableInfoArray);
|
||||
//是否提交下一节点
|
||||
workflowRequestInfo.setIsnextflow(isNextFlow);
|
||||
|
||||
WorkflowService workflow = new WorkflowServiceImpl();
|
||||
return workflow.doCreateWorkflowRequest(workflowRequestInfo, Convert.toInt(creatorId, 1));
|
||||
}
|
||||
}
|
@ -0,0 +1,215 @@
|
||||
package weaver.formmode.hty.modeexpand.performance;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew;
|
||||
import weaver.soa.workflow.request.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2024/09/07
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class RegistrationDistributionExpand extends AbstractModeExpandJavaCodeNew {
|
||||
@Override
|
||||
public Map<String, String> doModeExpand(Map<String, Object> param) {
|
||||
Map<String, String> resultMap = new HashMap<>(2);
|
||||
RecordSet rs = new RecordSet();
|
||||
try {
|
||||
int billId;
|
||||
int modeId;
|
||||
RequestInfo requestInfo = (RequestInfo) param.get("RequestInfo");
|
||||
if (requestInfo != null) {
|
||||
{
|
||||
|
||||
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 -> rs.writeLog(JSON.toJSONString(item)));
|
||||
|
||||
|
||||
DetailTable detailTable1 = detailTableInfo.getDetailTable(1);
|
||||
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(Convert.toInt(value, 0));
|
||||
}
|
||||
}
|
||||
resultList.add(result);
|
||||
}
|
||||
|
||||
// 所有人员排名
|
||||
LinkedHashSet<Integer> rankSet = calculateRankings(resultList);
|
||||
rs.writeLog("排名");
|
||||
resultList.forEach(item -> rs.writeLog(JSON.toJSONString(item)));
|
||||
|
||||
ArrayList<Integer> rankList = new ArrayList<>(rankSet);
|
||||
// 根据排名,按照分部比例划分
|
||||
int subStart = 0;
|
||||
double currentRange = 0.0;
|
||||
for (int i = 0; i < ruleList.size(); i++) {
|
||||
Rule rule = ruleList.get(i);
|
||||
double ruleRange = rule.getRuleRange() / 100;
|
||||
currentRange += ruleRange;
|
||||
rs.writeLog("ruleRange==" + ruleRange);
|
||||
rs.writeLog("currentRange==" + currentRange);
|
||||
//int subEnd = subStart!=0?(int) Math.floor(rankList.size() * ruleRange):(int) Math.ceil(rankList.size() * ruleRange);
|
||||
// 向下取
|
||||
int subEnd = (int) Math.floor(rankList.size() * currentRange);
|
||||
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;
|
||||
}
|
||||
|
||||
rs.writeLog("划分等级");
|
||||
|
||||
// 更新明细表
|
||||
String updateSql = "update uf_jxdjfb_dt2 set khdj = ? where id = ?";
|
||||
for (Result result : resultList) {
|
||||
rs.writeLog(JSON.toJSONString(result));
|
||||
rs.executeUpdate(updateSql, result.getLevel(), result.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
rs.writeLog(e);
|
||||
resultMap.put("errmsg", e.getMessage());
|
||||
resultMap.put("flag", "false");
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
public static LinkedHashSet<Integer> calculateRankings(List<Result> resultList) {
|
||||
LinkedHashSet<Integer> rankSet = new LinkedHashSet<>();
|
||||
|
||||
|
||||
resultList.sort((o1, o2) -> {
|
||||
return o2.getScore().compareTo(o1.getScore()); // 按值(分数)降序排序
|
||||
});
|
||||
|
||||
// 计算排名并输出
|
||||
int rank = 1;
|
||||
double prevScore = -1;
|
||||
for (Result result : resultList) {
|
||||
double score = result.getScore();
|
||||
if (score < prevScore) {
|
||||
rank++;
|
||||
}
|
||||
prevScore = score;
|
||||
result.setRank(rank);
|
||||
rankSet.add(rank);
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
Integer score;
|
||||
String level;
|
||||
Integer rank;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScore(Integer 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