From ae8eddc0362b72c6a0b5ed5b7e0a1c75ab3a184b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=B6=E4=B8=9C?= <1654135867@qq.com> Date: Sat, 29 Jun 2024 09:27:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/comp/controller/CompController.java | 70 ++++++++++++++++--- .../demo/comptype/mapper/CompTypeMapper.java | 6 ++ 2 files changed, 65 insertions(+), 11 deletions(-) diff --git a/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/comp/controller/CompController.java b/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/comp/controller/CompController.java index f9291ea7..3fc63e4d 100644 --- a/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/comp/controller/CompController.java +++ b/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/comp/controller/CompController.java @@ -195,24 +195,72 @@ public class CompController extends JeecgController { } /*--------------------------王家东添加开始============================*/ - //获取比赛类型 + //获取比赛类型comptyp就是类型的分数 Double comptypeweight = compTypeService.getById(comp.getCompTypeId()).getScore(); int comptyp = (int) Math.round(comptypeweight); - //得到排序排序加大一便将比赛类型数据减一,最大值是10 - int csort; - if (comp.getCompOrder() == 10 || comp.getCompOrder() > 10) { - csort = comptyp - 10; - } else { - csort = comptyp - comp.getCompOrder(); - } - - comp.setCompweight(csort); - + //开始获取 + /*comp.setCompweight(csort);*/ + List stringNumbers = compTypeService.getALL(); + // 将字符串数字转换为整数并进行排序 + List intNumbers = convertAndSort(stringNumbers); + //获取到的上下限 + int result = processInput(intNumbers, comptyp); + //开始获取个数 + 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); return Result.OK("添加成功!"); } + private static int findPosition(List 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 convertAndSort(List stringNumbers) { + List 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 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; // 或者可以抛出异常 + } + } /** * 编辑 diff --git a/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/comptype/mapper/CompTypeMapper.java b/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/comptype/mapper/CompTypeMapper.java index 13620c72..19e90e75 100644 --- a/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/comptype/mapper/CompTypeMapper.java +++ b/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/comptype/mapper/CompTypeMapper.java @@ -5,6 +5,7 @@ import java.util.List; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Select; import org.jeecg.modules.demo.comptype.entity.CompType; /** @@ -15,4 +16,9 @@ import org.jeecg.modules.demo.comptype.entity.CompType; */ public interface CompTypeMapper extends BaseMapper { + @Select("select score from comp_type") + List getgetAL(); + + @Select("SELECT COUNT(*) from comp where comp_type_id =#{compTypeId}") + int getgeshu(String compTypeId); }