czh-20260430-修复任务管理相关bug
This commit is contained in:
+1
-1
@@ -270,7 +270,7 @@ public class TaskListController {
|
||||
@PostMapping(value = "/addToFavorites")
|
||||
public Result<String> addToFavorites(@RequestBody Map<String, String> params) {
|
||||
try {
|
||||
taskListService.addToFavorites(params.get("taskListId"));
|
||||
taskListService.addToFavorites(params.get("taskListId"), params.get("pid"));
|
||||
return Result.OK("添加成功!");
|
||||
} catch (RuntimeException e) {
|
||||
return Result.error(e.getMessage());
|
||||
|
||||
+12
@@ -152,6 +152,18 @@ public class TaskListDetial implements Serializable {
|
||||
@Excel(name = "其他事项说明", width = 15)
|
||||
@Schema(description = "其他事项说明")
|
||||
private java.lang.String remark;
|
||||
/**是否默认分组*/
|
||||
@Excel(name = "是否默认分组", width = 15, dicCode = "is_default")
|
||||
@Schema(description = "是否默认分组(1=是,0=否)")
|
||||
private java.lang.Integer isDefault;
|
||||
/**来源清单名称*/
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "来源清单名称")
|
||||
private java.lang.String listName;
|
||||
/**当前用户对清单的权限*/
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "当前用户对该清单的权限(1=所有者,2=可编辑,3=只读)")
|
||||
private java.lang.String myPermission;
|
||||
/**删除标识*/
|
||||
@Excel(name = "删除标识", width = 15)
|
||||
@Schema(description = "删除标识")
|
||||
|
||||
+2
-2
@@ -55,9 +55,9 @@ public interface TaskListDetialMapper extends BaseMapper<TaskListDetial> {
|
||||
|
||||
Integer countChildrenByPid(@Param("pid") String pid);
|
||||
|
||||
List<TaskListDetial> selectByAssigneeId(@Param("assigneeId") String assigneeId);
|
||||
List<TaskListDetial> selectByAssigneeId(@Param("assigneeId") String assigneeId, @Param("userId") String userId);
|
||||
|
||||
List<TaskListDetial> selectByFollowersId(@Param("followersId") String followersId);
|
||||
List<TaskListDetial> selectByFollowersId(@Param("followersId") String followersId, @Param("userId") String userId);
|
||||
|
||||
void appendAssigner(@Param("taskId") String taskId, @Param("userId") String userId, @Param("userName") String userName);
|
||||
}
|
||||
|
||||
+2
@@ -44,4 +44,6 @@ public interface TaskListFavoriteMapper extends BaseMapper<TaskListFavorite> {
|
||||
Integer countChildrenByPid(@Param("userId") String userId, @Param("pid") String pid);
|
||||
|
||||
void updatePidAndSort(@Param("id") String id, @Param("pid") String pid, @Param("sortOrder") Integer sortOrder);
|
||||
|
||||
void updateSortOrder(@Param("id") String id, @Param("sortOrder") Integer sortOrder);
|
||||
}
|
||||
|
||||
+18
-6
@@ -158,15 +158,27 @@
|
||||
</select>
|
||||
|
||||
<select id="selectByAssigneeId" resultType="org.jeecg.modules.demo.tasklist.entity.TaskListDetial">
|
||||
SELECT * FROM task_list_detial
|
||||
WHERE type = '1' AND del_flag = '0'
|
||||
AND assignee_id LIKE CONCAT('%', #{assigneeId}, '%')
|
||||
SELECT d.*,
|
||||
t.tasklist_name AS listName,
|
||||
p.permission AS myPermission
|
||||
FROM task_list_detial d
|
||||
LEFT JOIN task_list t ON d.main_id = t.id AND t.del_flag = '0'
|
||||
LEFT JOIN task_list_permission p ON d.main_id = p.main_id
|
||||
AND p.user_id = #{userId} AND p.del_flag = '0'
|
||||
WHERE d.type = '1' AND d.del_flag = '0'
|
||||
AND d.assignee_id LIKE CONCAT('%', #{assigneeId}, '%')
|
||||
</select>
|
||||
|
||||
<select id="selectByFollowersId" resultType="org.jeecg.modules.demo.tasklist.entity.TaskListDetial">
|
||||
SELECT * FROM task_list_detial
|
||||
WHERE type = '1' AND del_flag = '0'
|
||||
AND followers_id LIKE CONCAT('%', #{followersId}, '%')
|
||||
SELECT d.*,
|
||||
t.tasklist_name AS listName,
|
||||
p.permission AS myPermission
|
||||
FROM task_list_detial d
|
||||
LEFT JOIN task_list t ON d.main_id = t.id AND t.del_flag = '0'
|
||||
LEFT JOIN task_list_permission p ON d.main_id = p.main_id
|
||||
AND p.user_id = #{userId} AND p.del_flag = '0'
|
||||
WHERE d.type = '1' AND d.del_flag = '0'
|
||||
AND d.followers_id LIKE CONCAT('%', #{followersId}, '%')
|
||||
</select>
|
||||
|
||||
<update id="appendAssigner">
|
||||
|
||||
+3
@@ -75,4 +75,7 @@
|
||||
SET pid = #{pid}, sort_order = #{sortOrder}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
<update id="updateSortOrder">
|
||||
UPDATE task_list_favorite SET sort_order = #{sortOrder} WHERE id = #{id}
|
||||
</update>
|
||||
</mapper>
|
||||
|
||||
+7
@@ -26,6 +26,13 @@ public interface ITaskListDetialService extends IService<TaskListDetial> {
|
||||
|
||||
void moveTaskGroup(String taskGroupId, Integer targetSortOrder);
|
||||
|
||||
/**
|
||||
* 纯排序重算:将任务/分组移到同级第 targetPosition 个位置
|
||||
* 不包含权限校验和副作用处理,由调用方负责
|
||||
*/
|
||||
void reorderTaskItem(String movedId, String mainId, String pid,
|
||||
Integer targetPosition, String newPid, boolean isGroup);
|
||||
|
||||
void followTask(String taskId);
|
||||
|
||||
void unfollowTask(String taskId);
|
||||
|
||||
+7
@@ -35,4 +35,11 @@ public interface ITaskListFavoriteService extends IService<TaskListFavorite> {
|
||||
Integer countChildren(String userId, String pid);
|
||||
|
||||
void updatePidAndSort(String favoriteId, String pid, Integer sortOrder);
|
||||
|
||||
/**
|
||||
* 纯排序重算:将指定记录移到同级第 targetPosition 个位置
|
||||
* 不包含权限校验和副作用处理,由调用方负责
|
||||
*/
|
||||
void reorderItem(String movedId, String userId, String pid, String type,
|
||||
Integer targetPosition, String newPid);
|
||||
}
|
||||
|
||||
+1
-1
@@ -92,7 +92,7 @@ public interface ITaskListService extends IService<TaskList> {
|
||||
|
||||
String getMyPermission(String taskListId);
|
||||
|
||||
void addToFavorites(String taskListId);
|
||||
void addToFavorites(String taskListId, String pid);
|
||||
|
||||
List<TaskListDetial> myResponsibleTasks();
|
||||
|
||||
|
||||
+87
-39
@@ -71,8 +71,6 @@ public class TaskListDetialServiceImpl extends ServiceImpl<TaskListDetialMapper,
|
||||
entity.setSubTaskCount(0);
|
||||
entity.setCompletedSubTaskCount(0);
|
||||
entity.setHasChild("0");
|
||||
entity.setCreateBy(userId);
|
||||
entity.setCreateTime(new Date());
|
||||
entity.setDelFlag("0");
|
||||
entity.setSysOrgCode(loginUser.getOrgCode());
|
||||
|
||||
@@ -130,6 +128,8 @@ public class TaskListDetialServiceImpl extends ServiceImpl<TaskListDetialMapper,
|
||||
if (oConvertUtils.isEmpty(assigneeId) || !assigneeId.contains(userId)) {
|
||||
throw new RuntimeException("可阅读者只能编辑自己负责的任务");
|
||||
}
|
||||
task.setAssigneeId(existing.getAssigneeId());
|
||||
task.setAssigneeName(existing.getAssigneeName());
|
||||
}
|
||||
|
||||
if (task.getAssigneeId() != null) {
|
||||
@@ -158,10 +158,6 @@ public class TaskListDetialServiceImpl extends ServiceImpl<TaskListDetialMapper,
|
||||
task.setFollowersName("");
|
||||
}
|
||||
}
|
||||
|
||||
task.setUpdateBy(userId);
|
||||
task.setUpdateTime(new Date());
|
||||
|
||||
boolean clearStartTime = task.getStartTime() == null && existing.getStartTime() != null;
|
||||
boolean clearEndTime = task.getEndTime() == null && existing.getEndTime() != null;
|
||||
|
||||
@@ -197,7 +193,7 @@ public class TaskListDetialServiceImpl extends ServiceImpl<TaskListDetialMapper,
|
||||
throw new RuntimeException("可阅读者无法删除任务");
|
||||
}
|
||||
|
||||
if ("0".equals(existing.getType()) && "默认分组".equals(existing.getTaskName())) {
|
||||
if ("0".equals(existing.getType()) && existing.getIsDefault() != null && existing.getIsDefault() == 1) {
|
||||
throw new RuntimeException("默认分组不能删除");
|
||||
}
|
||||
|
||||
@@ -275,7 +271,7 @@ public class TaskListDetialServiceImpl extends ServiceImpl<TaskListDetialMapper,
|
||||
int newStatus = oldStatus == 0 ? 1 : 0;
|
||||
java.util.Date completeTime = oldStatus == 0 ? new java.util.Date() : null;
|
||||
|
||||
taskListDetialMapper.toggleTaskStatus(taskId, userId, newStatus, completeTime);
|
||||
taskListDetialMapper.toggleTaskStatus(taskId, loginUser.getUsername(), newStatus, completeTime);
|
||||
|
||||
if (oConvertUtils.isNotEmpty(existing.getPid())) {
|
||||
TaskListDetial parent = taskListDetialMapper.selectById(existing.getPid());
|
||||
@@ -309,41 +305,35 @@ public class TaskListDetialServiceImpl extends ServiceImpl<TaskListDetialMapper,
|
||||
}
|
||||
|
||||
String oldPid = normalizePid(task.getPid());
|
||||
Integer oldSort = task.getSortOrder();
|
||||
String newPid = normalizePid(req.getTargetPid());
|
||||
|
||||
Integer maxSort = taskListDetialMapper.getMaxSortOrder(task.getMainId(), newPid);
|
||||
Integer targetSort;
|
||||
if (req.getTargetSortOrder() != null) {
|
||||
targetSort = req.getTargetSortOrder();
|
||||
} else {
|
||||
targetSort = maxSort + 1;
|
||||
}
|
||||
if (targetSort < 1) targetSort = 1;
|
||||
if (targetSort > maxSort + 1) targetSort = maxSort + 1;
|
||||
boolean pidChanged = (oldPid == null && newPid != null) || (oldPid != null && !oldPid.equals(newPid));
|
||||
|
||||
taskListDetialMapper.shiftSortOrderDown(task.getMainId(), oldPid, oldSort);
|
||||
|
||||
taskListDetialMapper.shiftSortOrderUp(task.getMainId(), newPid, targetSort);
|
||||
|
||||
taskListDetialMapper.updatePidAndSort(req.getTaskId(), newPid, targetSort);
|
||||
// 调用纯排序方法
|
||||
reorderTaskItem(req.getTaskId(), task.getMainId(), oldPid, req.getTargetSortOrder(), newPid, false);
|
||||
|
||||
// 仅在 pid 变更时更新父子计数
|
||||
if (pidChanged) {
|
||||
// 清除旧父任务的副作用
|
||||
if (oConvertUtils.isNotEmpty(oldPid)) {
|
||||
TaskListDetial oldParent = taskListDetialMapper.selectById(oldPid);
|
||||
if (oldParent != null && "1".equals(oldParent.getType())) {
|
||||
taskListDetialMapper.decrementSubTaskCount(oldPid);
|
||||
Integer childCount = taskListDetialMapper.countChildrenByPid(oldPid);
|
||||
if (childCount == null || childCount == 0) {
|
||||
taskListDetialMapper.updateHasChild(oldPid, "0");
|
||||
}
|
||||
taskListDetialMapper.decrementSubTaskCount(oldPid);
|
||||
}
|
||||
}
|
||||
|
||||
// 设置新父任务的副作用
|
||||
if (oConvertUtils.isNotEmpty(newPid)) {
|
||||
TaskListDetial newParent = taskListDetialMapper.selectById(newPid);
|
||||
if (newParent != null && "1".equals(newParent.getType())) {
|
||||
taskListDetialMapper.incrementSubTaskCount(newPid);
|
||||
}
|
||||
taskListDetialMapper.updateHasChild(newPid, "1");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,17 +354,60 @@ public class TaskListDetialServiceImpl extends ServiceImpl<TaskListDetialMapper,
|
||||
throw new RuntimeException("无权限移动此分组");
|
||||
}
|
||||
|
||||
Integer oldSort = group.getSortOrder();
|
||||
Integer maxSort = taskListDetialMapper.getMaxSortOrderForGroup(mainId);
|
||||
Integer targetSort = targetSortOrder != null ? targetSortOrder : 1;
|
||||
if (targetSort < 1) targetSort = 1;
|
||||
if (targetSort > maxSort) targetSort = maxSort;
|
||||
reorderTaskItem(taskGroupId, mainId, null, targetSortOrder, null, true);
|
||||
}
|
||||
|
||||
taskListDetialMapper.shiftSortOrderDownForGroup(mainId, oldSort);
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void reorderTaskItem(String movedId, String mainId, String pid,
|
||||
Integer targetPosition, String newPid, boolean isGroup) {
|
||||
TaskListDetial moved = taskListDetialMapper.selectById(movedId);
|
||||
if (moved == null) {
|
||||
throw new RuntimeException("记录不存在");
|
||||
}
|
||||
|
||||
taskListDetialMapper.shiftSortOrderUpForGroup(mainId, targetSort);
|
||||
// 当 newPid 有值时使用 newPid(跨组移动),否则使用 pid(同组内移动)
|
||||
// 关键:newPid="" 表示拖到根级别,此时应设为 null
|
||||
String effectiveNewPid;
|
||||
if (newPid != null) {
|
||||
effectiveNewPid = newPid.isEmpty() ? null : newPid;
|
||||
} else {
|
||||
effectiveNewPid = pid;
|
||||
}
|
||||
|
||||
taskListDetialMapper.updateSortOrder(taskGroupId, targetSort);
|
||||
LambdaQueryWrapper<TaskListDetial> query = new LambdaQueryWrapper<>();
|
||||
query.eq(TaskListDetial::getMainId, mainId);
|
||||
query.eq(TaskListDetial::getDelFlag, "0");
|
||||
if (isGroup) {
|
||||
query.eq(TaskListDetial::getType, "0");
|
||||
query.and(w -> w.isNull(TaskListDetial::getPid).or().eq(TaskListDetial::getPid, ""));
|
||||
} else {
|
||||
if (effectiveNewPid != null) {
|
||||
query.eq(TaskListDetial::getPid, effectiveNewPid);
|
||||
} else {
|
||||
query.isNull(TaskListDetial::getPid);
|
||||
}
|
||||
}
|
||||
query.ne(TaskListDetial::getId, movedId);
|
||||
query.orderByAsc(TaskListDetial::getSortOrder);
|
||||
List<TaskListDetial> siblings = taskListDetialMapper.selectList(query);
|
||||
|
||||
int pos = targetPosition != null ? targetPosition : siblings.size() + 1;
|
||||
pos = Math.max(1, Math.min(pos, siblings.size() + 1));
|
||||
|
||||
int sort = 1;
|
||||
for (int i = 0; i < siblings.size(); i++) {
|
||||
if (sort == pos) {
|
||||
sort++;
|
||||
}
|
||||
TaskListDetial sibling = siblings.get(i);
|
||||
if (!sibling.getSortOrder().equals(sort)) {
|
||||
taskListDetialMapper.updateSortOrder(sibling.getId(), sort);
|
||||
}
|
||||
sort++;
|
||||
}
|
||||
|
||||
taskListDetialMapper.updatePidAndSort(movedId, effectiveNewPid, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -415,11 +448,10 @@ public class TaskListDetialServiceImpl extends ServiceImpl<TaskListDetialMapper,
|
||||
group.setType("0");
|
||||
group.setPid(null);
|
||||
group.setSortOrder(0);
|
||||
group.setIsDefault(1);
|
||||
group.setHasChild("0");
|
||||
group.setSubTaskCount(0);
|
||||
group.setCompletedSubTaskCount(0);
|
||||
group.setCreateBy(loginUser.getId());
|
||||
group.setCreateTime(new Date());
|
||||
group.setDelFlag("0");
|
||||
taskListDetialMapper.insert(group);
|
||||
}
|
||||
@@ -429,9 +461,25 @@ public class TaskListDetialServiceImpl extends ServiceImpl<TaskListDetialMapper,
|
||||
LambdaQueryWrapper<TaskListDetial> query = new LambdaQueryWrapper<>();
|
||||
query.eq(TaskListDetial::getMainId, mainId);
|
||||
query.eq(TaskListDetial::getType, "0");
|
||||
query.eq(TaskListDetial::getTaskName, "默认分组");
|
||||
query.eq(TaskListDetial::getIsDefault, 1);
|
||||
query.last("LIMIT 1");
|
||||
return taskListDetialMapper.selectOne(query);
|
||||
TaskListDetial result = taskListDetialMapper.selectOne(query);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
query = new LambdaQueryWrapper<>();
|
||||
query.eq(TaskListDetial::getMainId, mainId);
|
||||
query.eq(TaskListDetial::getType, "0");
|
||||
query.isNull(TaskListDetial::getIsDefault);
|
||||
query.orderByAsc(TaskListDetial::getSortOrder);
|
||||
query.last("LIMIT 1");
|
||||
result = taskListDetialMapper.selectOne(query);
|
||||
if (result != null) {
|
||||
result.setIsDefault(1);
|
||||
taskListDetialMapper.updateById(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String getPermission(String mainId, String userId) {
|
||||
@@ -452,9 +500,9 @@ public class TaskListDetialServiceImpl extends ServiceImpl<TaskListDetialMapper,
|
||||
}
|
||||
for (TaskListDetial task : list) {
|
||||
if (oConvertUtils.isNotEmpty(task.getCreateBy())) {
|
||||
LoginUser createUser = sysBaseAPI.getUserById(task.getCreateBy());
|
||||
if (createUser != null) {
|
||||
task.setCreateByName(createUser.getRealname());
|
||||
List<com.alibaba.fastjson.JSONObject> users = sysBaseAPI.queryUsersByUsernames(task.getCreateBy());
|
||||
if (users != null && !users.isEmpty()) {
|
||||
task.setCreateByName(users.get(0).getString("realname"));
|
||||
}
|
||||
}
|
||||
if (oConvertUtils.isNotEmpty(task.getAssigneeId()) && oConvertUtils.isEmpty(task.getAssigneeName())) {
|
||||
|
||||
+53
@@ -7,6 +7,8 @@ import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @Description: 任务清单收藏表
|
||||
@@ -66,4 +68,55 @@ public class TaskListFavoriteServiceImpl extends ServiceImpl<TaskListFavoriteMap
|
||||
public void updatePidAndSort(String favoriteId, String pid, Integer sortOrder) {
|
||||
taskListFavoriteMapper.updatePidAndSort(favoriteId, pid, sortOrder);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void reorderItem(String movedId, String userId, String pid, String type,
|
||||
Integer targetPosition, String newPid) {
|
||||
TaskListFavorite moved = taskListFavoriteMapper.selectById(movedId);
|
||||
if (moved == null) {
|
||||
throw new RuntimeException("记录不存在");
|
||||
}
|
||||
|
||||
// 当 newPid 有值时使用 newPid(跨组移动),否则使用 pid(同组内移动)
|
||||
// 关键:newPid="" 表示拖到根级别(无分组),此时应设为 null
|
||||
String effectiveNewPid;
|
||||
if (newPid != null) {
|
||||
effectiveNewPid = newPid.isEmpty() ? null : newPid;
|
||||
} else {
|
||||
effectiveNewPid = pid;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<TaskListFavorite> query = new LambdaQueryWrapper<>();
|
||||
query.eq(TaskListFavorite::getUserId, userId);
|
||||
query.eq(TaskListFavorite::getDelFlag, "0");
|
||||
if (type != null) {
|
||||
query.eq(TaskListFavorite::getType, type);
|
||||
}
|
||||
if (effectiveNewPid != null) {
|
||||
query.eq(TaskListFavorite::getPid, effectiveNewPid);
|
||||
} else {
|
||||
query.isNull(TaskListFavorite::getPid);
|
||||
}
|
||||
query.ne(TaskListFavorite::getId, movedId);
|
||||
query.orderByAsc(TaskListFavorite::getSortOrder);
|
||||
List<TaskListFavorite> siblings = taskListFavoriteMapper.selectList(query);
|
||||
|
||||
int pos = targetPosition != null ? targetPosition : siblings.size() + 1;
|
||||
pos = Math.max(1, Math.min(pos, siblings.size() + 1));
|
||||
|
||||
int sort = 1;
|
||||
for (int i = 0; i < siblings.size(); i++) {
|
||||
if (sort == pos) {
|
||||
sort++;
|
||||
}
|
||||
TaskListFavorite sibling = siblings.get(i);
|
||||
if (!sibling.getSortOrder().equals(sort)) {
|
||||
taskListFavoriteMapper.updateSortOrder(sibling.getId(), sort);
|
||||
}
|
||||
sort++;
|
||||
}
|
||||
|
||||
taskListFavoriteMapper.updatePidAndSort(movedId, effectiveNewPid, pos);
|
||||
}
|
||||
}
|
||||
|
||||
+63
-74
@@ -24,6 +24,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import java.io.Serializable;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
@@ -146,15 +148,6 @@ public class TaskListServiceImpl extends ServiceImpl<TaskListMapper, TaskList> i
|
||||
}
|
||||
}
|
||||
|
||||
Integer targetSort;
|
||||
if (req.getSortOrder() != null) {
|
||||
taskListFavoriteService.shiftSortOrderUp(userId, req.getPid(), req.getSortOrder());
|
||||
targetSort = req.getSortOrder();
|
||||
} else {
|
||||
String pidForSort = oConvertUtils.isNotEmpty(req.getPid()) ? req.getPid() : null;
|
||||
targetSort = taskListFavoriteService.getMaxSortOrderByType(userId, pidForSort, "1") + 1;
|
||||
}
|
||||
|
||||
TaskList taskList = new TaskList();
|
||||
taskList.setTasklistName(req.getTasklistName());
|
||||
taskListMapper.insert(taskList);
|
||||
@@ -165,24 +158,13 @@ public class TaskListServiceImpl extends ServiceImpl<TaskListMapper, TaskList> i
|
||||
defaultGroup.setType("0");
|
||||
defaultGroup.setPid(null);
|
||||
defaultGroup.setSortOrder(0);
|
||||
defaultGroup.setIsDefault(1);
|
||||
defaultGroup.setHasChild("0");
|
||||
defaultGroup.setSubTaskCount(0);
|
||||
defaultGroup.setCompletedSubTaskCount(0);
|
||||
defaultGroup.setCreateBy(userId);
|
||||
defaultGroup.setCreateTime(new java.util.Date());
|
||||
defaultGroup.setDelFlag("0");
|
||||
taskListDetialMapper.insert(defaultGroup);
|
||||
|
||||
TaskListFavorite favorite = new TaskListFavorite();
|
||||
favorite.setMainId(taskList.getId());
|
||||
favorite.setUserId(userId);
|
||||
favorite.setType("1");
|
||||
favorite.setPid(req.getPid());
|
||||
favorite.setHasChild("0");
|
||||
favorite.setSortOrder(targetSort);
|
||||
favorite.setTasklistName(req.getTasklistName());
|
||||
taskListFavoriteMapper.insert(favorite);
|
||||
|
||||
TaskListPermission permission = new TaskListPermission();
|
||||
permission.setMainId(taskList.getId());
|
||||
permission.setUserId(userId);
|
||||
@@ -236,40 +218,27 @@ public class TaskListServiceImpl extends ServiceImpl<TaskListMapper, TaskList> i
|
||||
}
|
||||
|
||||
String oldPid = normalizePid(favorite.getPid());
|
||||
Integer oldSort = favorite.getSortOrder();
|
||||
|
||||
String newPid = null;
|
||||
if (req.getTargetGroupId() != null) {
|
||||
if (oConvertUtils.isNotEmpty(req.getTargetGroupId())) {
|
||||
TaskListFavorite targetGroup = taskListFavoriteMapper.selectById(req.getTargetGroupId());
|
||||
if (targetGroup == null || !"0".equals(targetGroup.getType()) || !userId.equals(targetGroup.getUserId())) {
|
||||
throw new RuntimeException("目标分组不存在或无权限");
|
||||
}
|
||||
newPid = normalizePid(req.getTargetGroupId());
|
||||
}
|
||||
|
||||
Integer maxSort = taskListFavoriteService.getMaxSortOrder(userId, newPid);
|
||||
Integer targetSort;
|
||||
if (req.getSortOrder() != null) {
|
||||
targetSort = req.getSortOrder();
|
||||
} else {
|
||||
targetSort = maxSort + 1;
|
||||
newPid = "";
|
||||
}
|
||||
if (targetSort < 1) {
|
||||
targetSort = 1;
|
||||
}
|
||||
if (targetSort > maxSort + 1) {
|
||||
targetSort = maxSort + 1;
|
||||
}
|
||||
|
||||
taskListFavoriteService.shiftSortOrderDown(userId, oldPid, oldSort);
|
||||
// 调用纯排序方法
|
||||
taskListFavoriteService.reorderItem(req.getFavoriteId(), userId, oldPid, "1", req.getSortOrder(), newPid);
|
||||
|
||||
taskListFavoriteService.shiftSortOrderUp(userId, newPid, targetSort);
|
||||
|
||||
taskListFavoriteService.updatePidAndSort(req.getFavoriteId(), newPid, targetSort);
|
||||
|
||||
if (oConvertUtils.isNotEmpty(oldPid)) {
|
||||
// 维护旧父节点 hasChild
|
||||
if (oConvertUtils.isNotEmpty(oldPid) && !oldPid.equals(newPid)) {
|
||||
Integer remainCount = taskListFavoriteService.countChildren(userId, oldPid);
|
||||
if (remainCount == 0) {
|
||||
if (remainCount == null || remainCount == 0) {
|
||||
TaskListFavorite oldParent = new TaskListFavorite();
|
||||
oldParent.setId(oldPid);
|
||||
oldParent.setHasChild("0");
|
||||
@@ -277,6 +246,7 @@ public class TaskListServiceImpl extends ServiceImpl<TaskListMapper, TaskList> i
|
||||
}
|
||||
}
|
||||
|
||||
// 维护新父节点 hasChild
|
||||
if (oConvertUtils.isNotEmpty(newPid)) {
|
||||
TaskListFavorite newParent = new TaskListFavorite();
|
||||
newParent.setId(newPid);
|
||||
@@ -289,10 +259,11 @@ public class TaskListServiceImpl extends ServiceImpl<TaskListMapper, TaskList> i
|
||||
public List<TaskListFavorite> getMyFavorites() {
|
||||
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
String userId = loginUser.getId();
|
||||
LambdaQueryWrapper<TaskListFavorite> query = new LambdaQueryWrapper<>();
|
||||
query.eq(TaskListFavorite::getUserId, userId);
|
||||
query.orderByAsc(TaskListFavorite::getType);
|
||||
query.orderByAsc(TaskListFavorite::getSortOrder);
|
||||
QueryWrapper<TaskListFavorite> query = new QueryWrapper<>();
|
||||
query.eq("user_id", userId);
|
||||
query.eq("del_flag", "0");
|
||||
query.orderByAsc("type");
|
||||
query.orderByAsc("sort_order");
|
||||
List<TaskListFavorite> list = taskListFavoriteMapper.selectList(query);
|
||||
for (TaskListFavorite fav : list) {
|
||||
if ("1".equals(fav.getType()) && fav.getMainId() != null && fav.getTasklistName() == null) {
|
||||
@@ -368,8 +339,7 @@ public class TaskListServiceImpl extends ServiceImpl<TaskListMapper, TaskList> i
|
||||
throw new RuntimeException("无权限操作此记录");
|
||||
}
|
||||
|
||||
fav.setDelFlag("1");
|
||||
taskListFavoriteMapper.updateById(fav);
|
||||
taskListFavoriteMapper.deleteById(favoriteId);
|
||||
|
||||
if (fav.getPid() != null) {
|
||||
Integer remainCount = taskListFavoriteService.countChildren(userId, fav.getPid());
|
||||
@@ -393,16 +363,14 @@ public class TaskListServiceImpl extends ServiceImpl<TaskListMapper, TaskList> i
|
||||
throw new RuntimeException("分组不存在或无权限");
|
||||
}
|
||||
|
||||
groupFav.setDelFlag("1");
|
||||
taskListFavoriteMapper.updateById(groupFav);
|
||||
taskListFavoriteMapper.deleteById(groupId);
|
||||
|
||||
LambdaQueryWrapper<TaskListFavorite> childQuery = new LambdaQueryWrapper<>();
|
||||
childQuery.eq(TaskListFavorite::getPid, groupId);
|
||||
childQuery.eq(TaskListFavorite::getUserId, userId);
|
||||
List<TaskListFavorite> children = taskListFavoriteMapper.selectList(childQuery);
|
||||
for (TaskListFavorite child : children) {
|
||||
child.setDelFlag("1");
|
||||
taskListFavoriteMapper.updateById(child);
|
||||
taskListFavoriteMapper.deleteById(child.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,22 +400,7 @@ public class TaskListServiceImpl extends ServiceImpl<TaskListMapper, TaskList> i
|
||||
throw new RuntimeException("分组不存在或无权限");
|
||||
}
|
||||
|
||||
Integer oldSort = group.getSortOrder();
|
||||
Integer targetSort = (sortOrder != null) ? sortOrder : 0;
|
||||
if (targetSort < 1) {
|
||||
targetSort = 1;
|
||||
}
|
||||
|
||||
Integer maxSort = taskListFavoriteService.getMaxSortOrderByType(userId, null, "0");
|
||||
if (targetSort > maxSort) {
|
||||
targetSort = maxSort;
|
||||
}
|
||||
|
||||
taskListFavoriteService.shiftSortOrderDownByType(userId, "0", oldSort);
|
||||
|
||||
taskListFavoriteService.shiftSortOrderUpByType(userId, "0", targetSort);
|
||||
|
||||
taskListFavoriteService.updatePidAndSort(groupId, null, targetSort);
|
||||
taskListFavoriteService.reorderItem(groupId, userId, null, "0", sortOrder, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -713,7 +666,7 @@ public class TaskListServiceImpl extends ServiceImpl<TaskListMapper, TaskList> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToFavorites(String taskListId) {
|
||||
public void addToFavorites(String taskListId, String pid) {
|
||||
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
String userId = loginUser.getId();
|
||||
|
||||
@@ -721,38 +674,74 @@ public class TaskListServiceImpl extends ServiceImpl<TaskListMapper, TaskList> i
|
||||
existCheck.eq(TaskListFavorite::getMainId, taskListId);
|
||||
existCheck.eq(TaskListFavorite::getUserId, userId);
|
||||
existCheck.eq(TaskListFavorite::getType, "1");
|
||||
Long existCount = taskListFavoriteMapper.selectCount(existCheck);
|
||||
if (existCount > 0) {
|
||||
existCheck.eq(TaskListFavorite::getDelFlag, "0");
|
||||
TaskListFavorite existFav = taskListFavoriteMapper.selectOne(existCheck);
|
||||
if (existFav != null) {
|
||||
throw new RuntimeException("该清单已在收藏中");
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<TaskListFavorite> reactivateCheck = new LambdaQueryWrapper<>();
|
||||
reactivateCheck.eq(TaskListFavorite::getMainId, taskListId);
|
||||
reactivateCheck.eq(TaskListFavorite::getUserId, userId);
|
||||
reactivateCheck.eq(TaskListFavorite::getType, "1");
|
||||
reactivateCheck.eq(TaskListFavorite::getDelFlag, "1");
|
||||
TaskListFavorite softDeletedFav = taskListFavoriteMapper.selectOne(reactivateCheck);
|
||||
if (softDeletedFav != null) {
|
||||
UpdateWrapper<TaskListFavorite> uw = new UpdateWrapper<>();
|
||||
uw.eq("id", softDeletedFav.getId());
|
||||
uw.set("del_flag", "0");
|
||||
taskListFavoriteMapper.update(null, uw);
|
||||
if (softDeletedFav.getPid() != null) {
|
||||
TaskListFavorite parentUpdate = new TaskListFavorite();
|
||||
parentUpdate.setId(softDeletedFav.getPid());
|
||||
parentUpdate.setHasChild("1");
|
||||
taskListFavoriteMapper.updateById(parentUpdate);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
TaskList taskList = taskListMapper.selectById(taskListId);
|
||||
if (taskList == null) {
|
||||
throw new RuntimeException("清单不存在");
|
||||
}
|
||||
|
||||
Integer maxSort = taskListFavoriteService.getMaxSortOrderByType(userId, null, "1");
|
||||
String normalizedPid = oConvertUtils.isNotEmpty(pid) ? pid : null;
|
||||
if (normalizedPid != null) {
|
||||
TaskListFavorite groupFav = taskListFavoriteMapper.selectById(normalizedPid);
|
||||
if (groupFav == null || !"0".equals(groupFav.getType()) || !userId.equals(groupFav.getUserId())) {
|
||||
throw new RuntimeException("目标分组不存在或无权限");
|
||||
}
|
||||
}
|
||||
|
||||
Integer maxSort = taskListFavoriteService.getMaxSortOrderByType(userId, normalizedPid, "1");
|
||||
TaskListFavorite favorite = new TaskListFavorite();
|
||||
favorite.setMainId(taskListId);
|
||||
favorite.setUserId(userId);
|
||||
favorite.setType("1");
|
||||
favorite.setPid(null);
|
||||
favorite.setPid(normalizedPid);
|
||||
favorite.setHasChild("0");
|
||||
favorite.setSortOrder(maxSort + 1);
|
||||
favorite.setTasklistName(taskList.getTasklistName());
|
||||
taskListFavoriteMapper.insert(favorite);
|
||||
|
||||
if (normalizedPid != null) {
|
||||
TaskListFavorite parentFav = new TaskListFavorite();
|
||||
parentFav.setId(normalizedPid);
|
||||
parentFav.setHasChild("1");
|
||||
taskListFavoriteMapper.updateById(parentFav);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaskListDetial> myResponsibleTasks() {
|
||||
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
return taskListDetialMapper.selectByAssigneeId(loginUser.getId());
|
||||
return taskListDetialMapper.selectByAssigneeId(loginUser.getId(), loginUser.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaskListDetial> myFollowedTasks() {
|
||||
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
return taskListDetialMapper.selectByFollowersId(loginUser.getId());
|
||||
return taskListDetialMapper.selectByFollowersId(loginUser.getId(), loginUser.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user