beetlsql3-dev
Mlxa0324
parent ee22f5f116
commit 74dc8208de

File diff suppressed because it is too large Load Diff

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<?PowerDesigner AppLocale="UTF16" ID="{BA33ABB7-B246-4DB0-85DE-396EDDB46458}" Label="" LastModificationDate="1673271673" Name="cjks" Objects="1373" Symbols="105" Target="MySQL 5.0" Type="{CDE44E21-9669-11D1-9914-006097355D9B}" signature="PDM_DATA_MODEL_XML" version="16.5.0.3982"?>
<?PowerDesigner AppLocale="UTF16" ID="{BA33ABB7-B246-4DB0-85DE-396EDDB46458}" Label="" LastModificationDate="1673279323" Name="cjks" Objects="1373" Symbols="105" Target="MySQL 5.0" Type="{CDE44E21-9669-11D1-9914-006097355D9B}" signature="PDM_DATA_MODEL_XML" version="16.5.0.3982"?>
<!-- do not edit this file -->
<Model xmlns:a="attribute" xmlns:c="collection" xmlns:o="object">
@ -8528,8 +8528,8 @@ COLLATE = utf8_general_ci</a:PhysicalOptions>
<a:Code>resources_info</a:Code>
<a:CreationDate>1563157584</a:CreationDate>
<a:Creator>Administrator</a:Creator>
<a:ModificationDate>1667577201</a:ModificationDate>
<a:Modifier>87966</a:Modifier>
<a:ModificationDate>1673279304</a:ModificationDate>
<a:Modifier>lx</a:Modifier>
<a:Comment>资源管理 - 资源管理</a:Comment>
<a:PhysicalOptions>auto_increment = 1
ENGINE = InnoDB
@ -8618,10 +8618,12 @@ COLLATE = utf8_general_ci</a:PhysicalOptions>
<a:Code>order_index</a:Code>
<a:CreationDate>1667549851</a:CreationDate>
<a:Creator>lx</a:Creator>
<a:ModificationDate>1667549860</a:ModificationDate>
<a:ModificationDate>1673279323</a:ModificationDate>
<a:Modifier>lx</a:Modifier>
<a:Comment>排序</a:Comment>
<a:DataType>bigint</a:DataType>
<a:Comment>排序(越小越靠前)</a:Comment>
<a:DataType>decimal(10,6)</a:DataType>
<a:Length>10</a:Length>
<a:Precision>6</a:Precision>
</o:Column>
<o:Column Id="o351">
<a:ObjectID>0A5D68B5-E63B-4C4F-9297-EC0AC34FFC14</a:ObjectID>
@ -19554,11 +19556,12 @@ COLLATE = utf8_general_ci</a:PhysicalOptions>
<a:Code>order_index</a:Code>
<a:CreationDate>1667577916</a:CreationDate>
<a:Creator>87966</a:Creator>
<a:ModificationDate>1671701065</a:ModificationDate>
<a:Modifier>87966</a:Modifier>
<a:ModificationDate>1673278643</a:ModificationDate>
<a:Modifier>lx</a:Modifier>
<a:Comment>资源排序</a:Comment>
<a:DataType>int(10)</a:DataType>
<a:DataType>decimal(10,6)</a:DataType>
<a:Length>10</a:Length>
<a:Precision>6</a:Precision>
</o:Column>
<o:Column Id="o1167">
<a:ObjectID>DF0255D5-A8C9-43E8-9D9E-0DDFA19DFE5E</a:ObjectID>

@ -492,6 +492,7 @@ alter table question_log_summary comment '学生-题目日志-分析汇总';
ALTER TABLE teacher_open_course_question_setting ADD COLUMN teacher_open_course_merge_course_info_id bigint(20) COMMENT '关联的章节ID仅章节练习有值';
ALTER TABLE teacher_open_course_merge_resources_info ADD COLUMN resources_info_status int(2) COMMENT '资源状态 0 删除 1上架 2下架';
ALTER TABLE teacher_open_course_merge_resources_info ADD COLUMN order_index decimal(10, 6) COMMENT '排序(越小越靠前)';
ALTER TABLE student ADD COLUMN student_gender int(2) COMMENT '性别 -1 未知 1男 2女';
ALTER TABLE teacher ADD COLUMN teacher_gender int(2) COMMENT '性别 -1 未知 1男 2女';

@ -27226,7 +27226,7 @@ CREATE TABLE `resources_info` (
`resources_info_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '资源名称',
`resources_info_type` int(11) NULL DEFAULT NULL COMMENT '资源类型 数据字典resources_info_type',
`resources_info_content` varchar(4000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '资源内容',
`order_index` bigint(20) NULL DEFAULT 1 COMMENT '排序',
`order_index` decimal(10,6) NULL DEFAULT 1 COMMENT '排序 (越小越靠前)',
`org_id` bigint(20) NULL DEFAULT NULL COMMENT '组织机构ID',
`user_id` bigint(20) NULL DEFAULT NULL COMMENT '后台用户ID',
PRIMARY KEY (`resources_info_id`) USING BTREE

@ -9,6 +9,7 @@ import org.beetl.sql.annotation.entity.AutoID;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
/*
* -
@ -46,7 +47,7 @@ public class ResourcesInfo extends BaseEntity {
// 资源排序
private String orderIndex;
private BigDecimal orderIndex;
//组织机构ID
@ -159,11 +160,11 @@ public class ResourcesInfo extends BaseEntity {
this.resourcesInfoFiles = resourcesInfoFiles;
}
public String getOrderIndex() {
public BigDecimal getOrderIndex() {
return orderIndex;
}
public void setOrderIndex(String orderIndex) {
public void setOrderIndex(BigDecimal orderIndex) {
this.orderIndex = orderIndex;
}

@ -8,6 +8,7 @@ import com.ibeetl.jlw.enums.GlobalUpStatusEnum;
import org.beetl.sql.annotation.entity.AssignID;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
/*
* -
@ -55,7 +56,7 @@ public class TeacherOpenCourseMergeResourcesInfo extends BaseEntity{
// 资源排序
private Integer orderIndex;
private BigDecimal orderIndex;
//组织机构ID
@ -176,11 +177,11 @@ public class TeacherOpenCourseMergeResourcesInfo extends BaseEntity{
this.resourcesInfoFiles = resourcesInfoFiles;
}
public Integer getOrderIndex() {
public BigDecimal getOrderIndex() {
return orderIndex;
}
public void setOrderIndex(Integer orderIndex) {
public void setOrderIndex(BigDecimal orderIndex) {
this.orderIndex = orderIndex;
}

@ -2,31 +2,44 @@ package com.ibeetl.jlw.service;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.jlw.aliPay.utils.StringUtils;
import com.ibeetl.admin.core.service.CoreBaseService;
import com.ibeetl.jlw.dao.CourseInfoDao;
import com.ibeetl.jlw.dao.ResourcesInfoDao;
import com.ibeetl.jlw.entity.CourseInfo;
import com.ibeetl.jlw.entity.ResourcesInfo;
import com.ibeetl.jlw.enums.MoveEnum;
import com.ibeetl.jlw.web.query.ResourcesInfoQuery;
import lombok.extern.slf4j.Slf4j;
import org.beetl.sql.core.SqlId;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
import static cn.jlw.util.ConvertM3U8.booleanMap;
import static java.lang.Math.min;
import static java.math.BigDecimal.ROUND_HALF_UP;
/**
* ResourcesInfo Service
*/
@Service
@Slf4j
@Transactional
public class ResourcesInfoService extends CoreBaseService<ResourcesInfo>{
@ -291,4 +304,191 @@ public class ResourcesInfoService extends CoreBaseService<ResourcesInfo>{
insertBatch(insertList);
}
}
/**
*
* 00
* @param id
* @param moveType
*/
public void move(@NotNull(message = "ID不能为空") Long id, @NotNull(message = "移动类型不能为空!") MoveEnum moveType) {
List<ResourcesInfo> links = resourcesInfoDao.createLambdaQuery().andIn(ResourcesInfo::getResourcesInfoId, Arrays.asList(id))
.select();
Assert.notEmpty(links, "未查询到要移动的元素!");
ResourcesInfo mergeCourseInfo = links.get(0);
// 定义排序值
Double calcedOrder = null;
switch (moveType) {
case MOVE_TOP: {
List<ResourcesInfo> result = resourcesInfoDao.createLambdaQuery()
.andEq(ResourcesInfo::getResourcesInfoId, mergeCourseInfo.getResourcesInfoId())
.asc(ResourcesInfo::getOrderIndex)
.limit(1, 1)
.select(ResourcesInfo::getOrderIndex);
if (CollectionUtil.isNotEmpty(result)) {
ResourcesInfo minOrderClientLink = result.get(0);
// 最小的排序值
BigDecimal minLinkOrder = minOrderClientLink.getOrderIndex();
// 置顶就现有的最小值减1。但是需要确保结果小于0
calcedOrder = NumberUtil.sub(min(minLinkOrder.floatValue(), 0), 1);
}
} break;
case MOVE_LEFT: {
List<ResourcesInfo> result = resourcesInfoDao.createLambdaQuery()
.andEq(ResourcesInfo::getResourcesInfoId, mergeCourseInfo.getResourcesInfoId())
.andLess(ResourcesInfo::getOrderIndex, mergeCourseInfo.getOrderIndex())
.desc(ResourcesInfo::getOrderIndex)
.limit(1, 2)
.select(ResourcesInfo::getOrderIndex);
if (CollectionUtil.isNotEmpty(result)) {
// 找到应该安插的位置
BigDecimal LinkOrder0 = result.get(0).getOrderIndex();
BigDecimal LinkOrder1 = LinkOrder0.subtract(BigDecimal.ONE);
if (result.size() == 2) {
LinkOrder1 = result.get(1).getOrderIndex();
}
BigDecimal min = NumberUtil.min(LinkOrder0, LinkOrder1);
BigDecimal max = NumberUtil.max(LinkOrder0, LinkOrder1);
// 左移位后的值
calcedOrder = RandomUtil.randomDouble(min.doubleValue(), max.doubleValue(), 6, RoundingMode.HALF_UP);
}
} break;
case MOVE_RIGHT: {
List<ResourcesInfo> result = resourcesInfoDao.createLambdaQuery()
.andGreat(ResourcesInfo::getOrderIndex, mergeCourseInfo.getOrderIndex())
.andEq(ResourcesInfo::getResourcesInfoId, mergeCourseInfo.getResourcesInfoId())
.asc(ResourcesInfo::getOrderIndex)
.limit(1, 2)
.select(ResourcesInfo::getOrderIndex);
if (CollectionUtil.isNotEmpty(result)) {
// 找到应该安插的位置
BigDecimal LinkOrder0 = result.get(0).getOrderIndex();
BigDecimal LinkOrder1 = LinkOrder0.add(BigDecimal.ONE);
if (result.size() == 2) {
LinkOrder1 = result.get(1).getOrderIndex();
}
BigDecimal min = NumberUtil.min(LinkOrder0, LinkOrder1);
BigDecimal max = NumberUtil.max(LinkOrder0, LinkOrder1);
// 右移位后的值
calcedOrder = RandomUtil.randomDouble(min.doubleValue(), max.doubleValue(), 6, RoundingMode.HALF_UP);
}
} break;
default:
log.error("不支持的移动类型!");
break;
}
if (calcedOrder == null) {
// 改变排序记录值
ResourcesInfo updatePO = new ResourcesInfo();
updatePO.setResourcesInfoId(mergeCourseInfo.getResourcesInfoId());
updatePO.setOrderIndex(BigDecimal.valueOf(calcedOrder));
updateTemplate(updatePO);
}
}
/**
* : <br>
*
* ID
* ID
* ID
*
* @param id ID
* @param leftId ID ID
* @param rightId ID ID
*
* ==>
* ==>
*
*
*
* @Author: 87966
* @Date: 2023/1/9 16:44
*/
public void drag(@NotNull(message = "要移动的元素 ID不能为空") final Long id, final Long leftId, final Long rightId) {
// 查询出来所有元素
List<ResourcesInfo> allElement = resourcesInfoDao.createLambdaQuery().andIn(ResourcesInfo::getResourcesInfoId, Arrays.asList(id, leftId, rightId))
.select();
// 自身ID是否存在
boolean hasSelf = allElement.stream().anyMatch(item -> item.getCourseInfoId().equals(id));
// 是否有左元素
boolean hasLeft = allElement.stream().anyMatch(item -> item.getCourseInfoId().equals(leftId));
// 是否有元素
boolean hasRight = allElement.stream().anyMatch(item -> item.getCourseInfoId().equals(rightId));
// 断言
Assert.isTrue(hasSelf, "未查询到要移动的元素!");
Assert.isFalse(!hasLeft && !hasRight, "左右元素ID不能同时为空");
// 自身元素
ResourcesInfo selfElement = allElement.stream()
.filter(item -> item.getCourseInfoId().equals(id)).findFirst().get();
// 左侧元素
ResourcesInfo leftElement = allElement.stream()
.filter(item -> item.getCourseInfoId().equals(leftId)).findFirst().orElse(null);
// 右侧元素
ResourcesInfo rightElement = allElement.stream()
.filter(item -> item.getCourseInfoId().equals(rightId)).findFirst().orElse(null);
// 定义排序值
BigDecimal clacedOrder = null;
// 左移动,无法确定右侧边界,适用于置顶
if (hasLeft && !hasRight) {
BigDecimal leftOrder = defaultIfNull(leftElement.getOrderIndex(), BigDecimal.ZERO);
// 数据库里存小数点后六位的排序值
// 随机取值 0.0001 到 0.0005之间
BigDecimal randomNum = RandomUtil.randomBigDecimal(new BigDecimal("0.0001"), new BigDecimal("0.0005")).setScale(6, ROUND_HALF_UP);
// 计算后的排序值
clacedOrder = leftOrder.subtract(randomNum);
}
// 右移动,无法确定左侧边界,适用于置底
else if (!hasLeft && hasRight) {
BigDecimal rightOrder = defaultIfNull(rightElement.getOrderIndex(), BigDecimal.ZERO);
// 数据库里存小数点后六位的排序值
// 随机取值 0.0001 到 0.0005之间
BigDecimal randomNum = RandomUtil.randomBigDecimal(new BigDecimal("0.0001"), new BigDecimal("0.0005")).setScale(6, ROUND_HALF_UP);
// 计算后的排序值
clacedOrder = rightOrder.add(randomNum);
}
// 可以确定左右两侧边界,移动的比较精准
else if (hasLeft && hasRight) {
BigDecimal leftOrder = defaultIfNull(leftElement.getOrderIndex(), BigDecimal.ZERO);
BigDecimal rightOrder = defaultIfNull(rightElement.getOrderIndex(), BigDecimal.ONE);
// 随机取值
BigDecimal randomNum = RandomUtil.randomBigDecimal(leftOrder, rightOrder).setScale(6, ROUND_HALF_UP);
// 计算后的排序值
clacedOrder = rightOrder.add(randomNum);
}
// 最后更新排序值
if (clacedOrder != null) {
ResourcesInfo updatePO = new ResourcesInfo();
updatePO.setResourcesInfoId(selfElement.getResourcesInfoId());
updatePO.setOrderIndex(clacedOrder);
updateTemplate(updatePO);
}
}
}

@ -17,7 +17,6 @@ import com.ibeetl.jlw.entity.*;
import com.ibeetl.jlw.entity.dto.QuestionSettingDTO;
import com.ibeetl.jlw.entity.vo.ImportQuestionByWordTemplateResultVO;
import com.ibeetl.jlw.entity.vo.QuestionTypeCountVO;
import com.ibeetl.jlw.enums.AddTypeEnum;
import com.ibeetl.jlw.enums.ResourcesQuestionTypeEnum;
import com.ibeetl.jlw.service.strategy.StrategyContext;
import com.ibeetl.jlw.validator.QuestionValidator;
@ -62,12 +61,13 @@ import java.util.regex.Pattern;
import static cn.hutool.core.util.ArrayUtil.join;
import static com.ibeetl.jlw.entity.ResourcesQuestionOptionEntity.shuffleOrderOptions;
import static com.ibeetl.jlw.enums.AddTypeEnum.ADMIN_ADD;
import static com.ibeetl.jlw.enums.AddTypeEnum.FACULTY_ADD;
import static com.ibeetl.jlw.service.strategy.StrategyContext.QuestionParagraphTypeEnum.OTHER;
import static com.ibeetl.jlw.service.strategy.StrategyContext.QuestionTypeConcatEnum.DECIDE;
import static com.ibeetl.jlw.service.strategy.StrategyContext.QuestionTypeConcatEnum.MULTIPLE;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.joining;
import static org.apache.poi.util.LocaleID.SE;
/**
@ -468,7 +468,7 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
pojo.setQuestionAnswer(questionAnswer);
}
pojo.setQuestionAnalysis(questionAnalysis);
pojo.setAddType(AddTypeEnum.ADMIN_ADD);
pojo.setAddType(ADMIN_ADD);
insert(pojo);
@ -816,10 +816,7 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
/** 上传文件的临时路径 */
String importPath = fileEntity.getAbsoluteUrl();
/** 新建文件夹绝对路径 */
String absoluteDirPath = String.format("%s%s%s%s%s%s", GetFile.p , SE , "filesystem" , SE , "temp" , SE );
/** 新建文件的绝对路径 */
String absolutePath = absoluteDirPath + fileEntity.getTempName();
//各种流
String absoluteDirPath = String.format("%s\\%s\\%s\\", GetFile.p, "filesystem", "temp");
try {
@Cleanup FileInputStream fileInputStream = new FileInputStream(importPath);
xDocument.set(new XWPFDocument(fileInputStream));
@ -894,6 +891,7 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
resourcesQuestion.setQuestionStatus(1);
resourcesQuestion.setUserId(coreUser.getId());
resourcesQuestion.setOrgId(coreUser.getOrgId());
resourcesQuestion.setAddType(coreUser.isAdmin() ? ADMIN_ADD : FACULTY_ADD);
if (StringUtils.isNotBlank(questionStem.get())) {
resourcesQuestion.setQuestionStem(questionStem.get().replace("<", "&lt;").replace(">", "&gt;"));

@ -2,9 +2,13 @@ package com.ibeetl.jlw.service;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.jlw.util.ToolUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
@ -18,6 +22,7 @@ import com.ibeetl.jlw.entity.CourseInfo;
import com.ibeetl.jlw.entity.FileEntity;
import com.ibeetl.jlw.entity.ResourcesInfo;
import com.ibeetl.jlw.entity.TeacherOpenCourseMergeResourcesInfo;
import com.ibeetl.jlw.enums.MoveEnum;
import com.ibeetl.jlw.web.query.ResourcesInfoQuery;
import com.ibeetl.jlw.web.query.TeacherOpenCourseMergeResourcesInfoQuery;
import lombok.extern.slf4j.Slf4j;
@ -38,9 +43,14 @@ import javax.annotation.Nullable;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
import static com.ibeetl.admin.core.util.ExcelUtil.getCellFormatValue;
import static java.lang.Math.min;
import static java.math.BigDecimal.ROUND_HALF_UP;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toSet;
import static org.apache.commons.lang3.StringUtils.join;
@ -447,4 +457,195 @@ public class TeacherOpenCourseMergeResourcesInfoService extends CoreBaseService<
}
}
}
/**
*
* 00
* @param id
* @param moveType
*/
public void move(@NotNull(message = "ID不能为空") Long id, @NotNull(message = "移动类型不能为空!") MoveEnum moveType) {
List<TeacherOpenCourseMergeResourcesInfo> links = teacherOpenCourseMergeResourcesInfoDao.getByIds(id.toString());
Assert.notEmpty(links, "未查询到要移动的元素!");
TeacherOpenCourseMergeResourcesInfo mergeCourseInfo = links.get(0);
// 定义排序值
Double calcedOrder = null;
switch (moveType) {
case MOVE_TOP: {
List<TeacherOpenCourseMergeResourcesInfo> result = teacherOpenCourseMergeResourcesInfoDao.createLambdaQuery()
.andEq(TeacherOpenCourseMergeResourcesInfo::getResourcesInfoStatus, 1)
.andEq(TeacherOpenCourseMergeResourcesInfo::getTeacherOpenCourseMergeCourseInfoId, mergeCourseInfo.getTeacherOpenCourseMergeCourseInfoId())
.asc(TeacherOpenCourseMergeResourcesInfo::getOrderIndex)
.limit(1, 1)
.select(TeacherOpenCourseMergeResourcesInfo::getOrderIndex);
if (CollectionUtil.isNotEmpty(result)) {
TeacherOpenCourseMergeResourcesInfo minOrderClientLink = result.get(0);
// 最小的排序值
BigDecimal minLinkOrder = minOrderClientLink.getOrderIndex();
// 置顶就现有的最小值减1。但是需要确保结果小于0
calcedOrder = NumberUtil.sub(min(minLinkOrder.floatValue(), 0), 1);
}
} break;
case MOVE_LEFT: {
List<TeacherOpenCourseMergeResourcesInfo> result = teacherOpenCourseMergeResourcesInfoDao.createLambdaQuery()
.andEq(TeacherOpenCourseMergeResourcesInfo::getResourcesInfoStatus, 1)
.andNotEq(TeacherOpenCourseMergeResourcesInfo::getTeacherOpenCourseMergeResourcesInfoId, mergeCourseInfo.getTeacherOpenCourseMergeResourcesInfoId())
.andEq(TeacherOpenCourseMergeResourcesInfo::getTeacherOpenCourseMergeCourseInfoId, mergeCourseInfo.getTeacherOpenCourseMergeCourseInfoId())
.andLess(TeacherOpenCourseMergeResourcesInfo::getOrderIndex, mergeCourseInfo.getOrderIndex())
.andEq(TeacherOpenCourseMergeResourcesInfo::getResourcesInfoStatus, 1)
.desc(TeacherOpenCourseMergeResourcesInfo::getOrderIndex)
.limit(1, 2)
.select(TeacherOpenCourseMergeResourcesInfo::getOrderIndex);
if (CollectionUtil.isNotEmpty(result)) {
// 找到应该安插的位置
BigDecimal LinkOrder0 = result.get(0).getOrderIndex();
BigDecimal LinkOrder1 = LinkOrder0.subtract(BigDecimal.ONE);
if (result.size() == 2) {
LinkOrder1 = result.get(1).getOrderIndex();
}
BigDecimal min = NumberUtil.min(LinkOrder0, LinkOrder1);
BigDecimal max = NumberUtil.max(LinkOrder0, LinkOrder1);
// 左移位后的值
calcedOrder = RandomUtil.randomDouble(min.doubleValue(), max.doubleValue(), 6, RoundingMode.HALF_UP);
}
} break;
case MOVE_RIGHT: {
List<TeacherOpenCourseMergeResourcesInfo> result = teacherOpenCourseMergeResourcesInfoDao.createLambdaQuery()
.andGreat(TeacherOpenCourseMergeResourcesInfo::getOrderIndex, mergeCourseInfo.getOrderIndex())
.andEq(TeacherOpenCourseMergeResourcesInfo::getResourcesInfoStatus, 1)
.andNotEq(TeacherOpenCourseMergeResourcesInfo::getTeacherOpenCourseMergeResourcesInfoId, mergeCourseInfo.getTeacherOpenCourseMergeResourcesInfoId())
.andEq(TeacherOpenCourseMergeResourcesInfo::getTeacherOpenCourseMergeCourseInfoId, mergeCourseInfo.getTeacherOpenCourseMergeCourseInfoId())
.asc(TeacherOpenCourseMergeResourcesInfo::getOrderIndex)
.limit(1, 2)
.select(TeacherOpenCourseMergeResourcesInfo::getOrderIndex);
if (CollectionUtil.isNotEmpty(result)) {
// 找到应该安插的位置
BigDecimal LinkOrder0 = result.get(0).getOrderIndex();
BigDecimal LinkOrder1 = LinkOrder0.add(BigDecimal.ONE);
if (result.size() == 2) {
LinkOrder1 = result.get(1).getOrderIndex();
}
BigDecimal min = NumberUtil.min(LinkOrder0, LinkOrder1);
BigDecimal max = NumberUtil.max(LinkOrder0, LinkOrder1);
// 右移位后的值
calcedOrder = RandomUtil.randomDouble(min.doubleValue(), max.doubleValue(), 6, RoundingMode.HALF_UP);
}
} break;
default:
log.error("不支持的移动类型!");
break;
}
if (calcedOrder == null) {
// 改变排序记录值
TeacherOpenCourseMergeResourcesInfo updatePO = new TeacherOpenCourseMergeResourcesInfo();
updatePO.setTeacherOpenCourseMergeCourseInfoId(mergeCourseInfo.getTeacherOpenCourseMergeCourseInfoId());
updatePO.setOrderIndex(BigDecimal.valueOf(calcedOrder));
updateTemplate(updatePO);
}
}
/**
* : <br>
*
* ID
* ID
* ID
*
* @param id ID
* @param leftId ID ID
* @param rightId ID ID
*
* ==>
* ==>
*
*
*
* @Author: 87966
* @Date: 2023/1/9 16:44
*/
public void drag(@NotNull(message = "要移动的元素 ID不能为空") final Long id, final Long leftId, final Long rightId) {
// 查询出来所有元素
List<TeacherOpenCourseMergeResourcesInfo> allElement = teacherOpenCourseMergeResourcesInfoDao.getByIds(ArrayUtil.join(new Long[]{ id, leftId, rightId }, ","));
// 自身ID是否存在
boolean hasSelf = allElement.stream().anyMatch(item -> item.getTeacherOpenCourseMergeCourseInfoId().equals(id));
// 是否有左元素
boolean hasLeft = allElement.stream().anyMatch(item -> item.getTeacherOpenCourseMergeCourseInfoId().equals(leftId));
// 是否有元素
boolean hasRight = allElement.stream().anyMatch(item -> item.getTeacherOpenCourseMergeCourseInfoId().equals(rightId));
// 断言
Assert.isTrue(hasSelf, "未查询到要移动的元素!");
Assert.isFalse(!hasLeft && !hasRight, "左右元素ID不能同时为空");
// 自身元素
TeacherOpenCourseMergeResourcesInfo selfElement = allElement.stream()
.filter(item -> item.getTeacherOpenCourseMergeResourcesInfoId().equals(id)).findFirst().get();
// 左侧元素
TeacherOpenCourseMergeResourcesInfo leftElement = allElement.stream()
.filter(item -> item.getTeacherOpenCourseMergeResourcesInfoId().equals(leftId)).findFirst().orElse(null);
// 右侧元素
TeacherOpenCourseMergeResourcesInfo rightElement = allElement.stream()
.filter(item -> item.getTeacherOpenCourseMergeResourcesInfoId().equals(rightId)).findFirst().orElse(null);
// 定义排序值
BigDecimal clacedOrder = null;
// 左移动,无法确定右侧边界,适用于置顶
if (hasLeft && !hasRight) {
BigDecimal leftOrder = defaultIfNull(leftElement.getOrderIndex(), BigDecimal.ZERO);
// 数据库里存小数点后六位的排序值
// 随机取值 0.0001 到 0.0005之间
BigDecimal randomNum = RandomUtil.randomBigDecimal(new BigDecimal("0.0001"), new BigDecimal("0.0005")).setScale(6, ROUND_HALF_UP);
// 计算后的排序值
clacedOrder = leftOrder.subtract(randomNum);
}
// 右移动,无法确定左侧边界,适用于置底
else if (!hasLeft && hasRight) {
BigDecimal rightOrder = defaultIfNull(rightElement.getOrderIndex(), BigDecimal.ZERO);
// 数据库里存小数点后六位的排序值
// 随机取值 0.0001 到 0.0005之间
BigDecimal randomNum = RandomUtil.randomBigDecimal(new BigDecimal("0.0001"), new BigDecimal("0.0005")).setScale(6, ROUND_HALF_UP);
// 计算后的排序值
clacedOrder = rightOrder.add(randomNum);
}
// 可以确定左右两侧边界,移动的比较精准
else if (hasLeft && hasRight) {
BigDecimal leftOrder = defaultIfNull(leftElement.getOrderIndex(), BigDecimal.ZERO);
BigDecimal rightOrder = defaultIfNull(rightElement.getOrderIndex(), BigDecimal.ONE);
// 随机取值
BigDecimal randomNum = RandomUtil.randomBigDecimal(leftOrder, rightOrder).setScale(6, ROUND_HALF_UP);
// 计算后的排序值
clacedOrder = rightOrder.add(randomNum);
}
// 最后更新排序值
if (clacedOrder != null) {
TeacherOpenCourseMergeResourcesInfo updatePO = new TeacherOpenCourseMergeResourcesInfo();
updatePO.setTeacherOpenCourseMergeResourcesInfoId(selfElement.getTeacherOpenCourseMergeResourcesInfoId());
updatePO.setOrderIndex(clacedOrder);
updateTemplate(updatePO);
}
}
}

@ -11,6 +11,7 @@ import com.ibeetl.admin.core.file.FileService;
import com.ibeetl.admin.core.web.JsonResult;
import com.ibeetl.jlw.entity.CourseInfo;
import com.ibeetl.jlw.entity.ResourcesInfo;
import com.ibeetl.jlw.enums.MoveEnum;
import com.ibeetl.jlw.service.CourseInfoService;
import com.ibeetl.jlw.service.ResourcesInfoService;
import com.ibeetl.jlw.web.query.ResourcesInfoQuery;
@ -302,6 +303,47 @@ public class ResourcesInfoController{
return JsonResult.success();
}
/**
* : <br>
*
*
* @param id ID
* @param moveType
* @return {@link JsonResult}
* @Author: 87966
* @Date: 2023/1/9 16:17
*/
@PostMapping(MODEL + "/move.json")
@ResponseBody
public JsonResult move(Long id, MoveEnum moveType) {
resourcesInfoService.move(id, moveType);
return JsonResult.success();
}
/**
* : <br>
*
*
*
*
*
* ==>
* ==>
*
*
*
* @param id ID
* @param leftId ID ID
* @param rightId ID ID
* @return {@link JsonResult}
* @Author: 87966
* @Date: 2023/1/9 16:44
*/
@PostMapping(MODEL + "/drag.json")
@ResponseBody
public JsonResult drag(Long id, Long leftId, Long rightId) {
resourcesInfoService.drag(id, leftId, rightId);
return JsonResult.success();
}
}

@ -16,6 +16,7 @@ import com.ibeetl.admin.core.web.JsonResult;
import com.ibeetl.jlw.entity.FileEntity;
import com.ibeetl.jlw.entity.TeacherOpenCourseMergeResourcesInfo;
import com.ibeetl.jlw.enums.GlobalUpStatusEnum;
import com.ibeetl.jlw.enums.MoveEnum;
import com.ibeetl.jlw.service.TeacherOpenCourseMergeResourcesInfoService;
import com.ibeetl.jlw.web.query.TeacherOpenCourseMergeResourcesInfoQuery;
import org.apache.commons.lang3.StringUtils;
@ -535,4 +536,47 @@ public class TeacherOpenCourseMergeResourcesInfoController{
teacherOpenCourseMergeResourcesInfoService.copyFromResourcesInfo(CollectionUtil.newHashSet(resourcesInfoIds), teacherOpenCourseId, null);
return JsonResult.success();
}
/**
* : <br>
*
*
* @param id ID
* @param moveType
* @return {@link JsonResult}
* @Author: 87966
* @Date: 2023/1/9 16:17
*/
@PostMapping(MODEL + "/move.json")
@ResponseBody
public JsonResult move(Long id, MoveEnum moveType) {
teacherOpenCourseMergeResourcesInfoService.move(id, moveType);
return JsonResult.success();
}
/**
* : <br>
*
*
*
*
*
* ==>
* ==>
*
*
*
* @param id ID
* @param leftId ID ID
* @param rightId ID ID
* @return {@link JsonResult}
* @Author: 87966
* @Date: 2023/1/9 16:44
*/
@PostMapping(MODEL + "/drag.json")
@ResponseBody
public JsonResult drag(Long id, Long leftId, Long rightId) {
teacherOpenCourseMergeResourcesInfoService.drag(id, leftId, rightId);
return JsonResult.success();
}
}

@ -5,6 +5,8 @@ import com.ibeetl.admin.core.web.query.PageParam;
import com.ibeetl.jlw.entity.ResourcesInfo;
import com.ibeetl.jlw.enums.AddTypeEnum;
import java.math.BigDecimal;
import static com.ibeetl.admin.core.annotation.Query.TYPE_DICT;
import static com.ibeetl.admin.core.util.enums.CoreDictType.RESOURCES_INFO_TYPE;
@ -26,7 +28,7 @@ public class ResourcesInfoQuery extends PageParam {
@Query(name = "资源文件", display = false)
private String resourcesInfoFiles;
@Query(name = "资源排序", display = false)
private String orderIndex;
private BigDecimal orderIndex;
@Query(name = "组织机构ID", display = false)
private Long orgId;
@Query(name = "后台用户ID", display = false)
@ -128,11 +130,11 @@ public class ResourcesInfoQuery extends PageParam {
this.resourcesInfoFiles = resourcesInfoFiles;
}
public String getOrderIndex() {
public BigDecimal getOrderIndex() {
return orderIndex;
}
public void setOrderIndex(String orderIndex) {
public void setOrderIndex(BigDecimal orderIndex) {
this.orderIndex = orderIndex;
}

@ -8,6 +8,7 @@ import com.ibeetl.jlw.entity.TeacherOpenCourseMergeResourcesInfo;
import com.ibeetl.jlw.enums.GlobalUpStatusEnum;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
@ -31,7 +32,7 @@ public class TeacherOpenCourseMergeResourcesInfoQuery extends PageParam implemen
@Query(name = "资源文件", display = false)
private String resourcesInfoFiles;
@Query(name = "资源排序", display = false)
private Integer orderIndex;
private BigDecimal orderIndex;
// 资源状态 0删除 1上架 2下架
private GlobalUpStatusEnum resourcesInfoStatus;
@Query(name = "组织机构ID", display = false)
@ -169,11 +170,11 @@ public class TeacherOpenCourseMergeResourcesInfoQuery extends PageParam implemen
this.resourcesInfoFiles = resourcesInfoFiles;
}
public Integer getOrderIndex() {
public BigDecimal getOrderIndex() {
return orderIndex;
}
public void setOrderIndex(Integer orderIndex) {
public void setOrderIndex(BigDecimal orderIndex) {
this.orderIndex = orderIndex;
}

Loading…
Cancel
Save