|
|
@ -195,24 +195,72 @@ public class CompController extends JeecgController<Comp, ICompService> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------王家东添加开始============================*/ |
|
|
|
/*--------------------------王家东添加开始============================*/ |
|
|
|
//获取比赛类型
|
|
|
|
//获取比赛类型comptyp就是类型的分数
|
|
|
|
Double comptypeweight = compTypeService.getById(comp.getCompTypeId()).getScore(); |
|
|
|
Double comptypeweight = compTypeService.getById(comp.getCompTypeId()).getScore(); |
|
|
|
int comptyp = (int) Math.round(comptypeweight); |
|
|
|
int comptyp = (int) Math.round(comptypeweight); |
|
|
|
//得到排序排序加大一便将比赛类型数据减一,最大值是10
|
|
|
|
//开始获取
|
|
|
|
int csort; |
|
|
|
/*comp.setCompweight(csort);*/ |
|
|
|
if (comp.getCompOrder() == 10 || comp.getCompOrder() > 10) { |
|
|
|
List<String> stringNumbers = compTypeService.getALL(); |
|
|
|
csort = comptyp - 10; |
|
|
|
// 将字符串数字转换为整数并进行排序
|
|
|
|
} else { |
|
|
|
List<Integer> intNumbers = convertAndSort(stringNumbers); |
|
|
|
csort = comptyp - comp.getCompOrder(); |
|
|
|
//获取到的上下限
|
|
|
|
} |
|
|
|
int result = processInput(intNumbers, comptyp); |
|
|
|
|
|
|
|
//开始获取个数
|
|
|
|
comp.setCompweight(csort); |
|
|
|
int geshu = compTypeService.getgeshu(comp.getCompTypeId()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//开始计算中间值
|
|
|
|
|
|
|
|
int b = result / geshu; |
|
|
|
|
|
|
|
//开始获取逆向排名
|
|
|
|
|
|
|
|
int position = findPosition(intNumbers,comptyp); |
|
|
|
|
|
|
|
//计算全职
|
|
|
|
|
|
|
|
int wei = (intNumbers.size()-position +1) * b+comptyp; |
|
|
|
|
|
|
|
comp.setCompweight(wei); |
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------王家东添加开始============================*/ |
|
|
|
/*--------------------------王家东添加开始============================*/ |
|
|
|
compService.save(comp); |
|
|
|
compService.save(comp); |
|
|
|
return Result.OK("添加成功!"); |
|
|
|
return Result.OK("添加成功!"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static int findPosition(List<Integer> intList, int inputNumber) { |
|
|
|
|
|
|
|
// 使用二分查找或简单遍历找到输入数字的位置(索引从0开始)
|
|
|
|
|
|
|
|
int position = Collections.binarySearch(intList, inputNumber); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果binarySearch返回负数,说明输入的数字不在列表中,我们需要找到它应该插入的位置(取反然后减1)
|
|
|
|
|
|
|
|
if (position < 0) { |
|
|
|
|
|
|
|
position = -position - 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据位置计算并返回相应的位数
|
|
|
|
|
|
|
|
// 如果最大返回1,最小返回列表长度
|
|
|
|
|
|
|
|
return (position == 0) ? 1 : (intList.size() - position + 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static List<Integer> convertAndSort(List<String> stringNumbers) { |
|
|
|
|
|
|
|
List<Integer> intNumbers = new ArrayList<>(); |
|
|
|
|
|
|
|
for (String s : stringNumbers) { |
|
|
|
|
|
|
|
intNumbers.add(Integer.parseInt(String.valueOf((int)Double.parseDouble(s)))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Collections.sort(intNumbers, Collections.reverseOrder()); // 从大到小排序
|
|
|
|
|
|
|
|
return intNumbers; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static int processInput(List<Integer> intNumbers, int inputNumber) { |
|
|
|
|
|
|
|
// 查找输入的数字在列表中的位置
|
|
|
|
|
|
|
|
int index = intNumbers.indexOf(inputNumber); |
|
|
|
|
|
|
|
if (index != -1) { // 如果找到了
|
|
|
|
|
|
|
|
// 如果是最大的一个数字,用100减去这个数
|
|
|
|
|
|
|
|
if (index == 0) { |
|
|
|
|
|
|
|
return 100 - inputNumber; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// 如果不是最大的一个数字,用它前面的那个数字减去这个数
|
|
|
|
|
|
|
|
return intNumbers.get(index - 1) - inputNumber; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// 输入的数字不在列表中
|
|
|
|
|
|
|
|
System.out.println("输入的数字不在列表中。"); |
|
|
|
|
|
|
|
return -1; // 或者可以抛出异常
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 编辑 |
|
|
|
* 编辑 |
|
|
|