功能:1.指定设计师发送钉钉个人通知 2.部门负责人可查看部门内所有任务
This commit is contained in:
parent
88e1af8f44
commit
54438a9910
@ -5,6 +5,7 @@ import com.designhub.common.Result;
|
||||
import com.designhub.entity.TaskItem;
|
||||
import com.designhub.service.TaskItemService;
|
||||
import com.designhub.mapper.UserMapper;
|
||||
import com.designhub.mapper.DepartmentMapper;
|
||||
import com.designhub.util.JwtUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@ -26,6 +27,7 @@ public class TaskItemController {
|
||||
|
||||
private final TaskItemService taskItemService;
|
||||
private final UserMapper userMapper;
|
||||
private final DepartmentMapper departmentMapper;
|
||||
private final JwtUtil jwtUtil;
|
||||
|
||||
/**
|
||||
@ -45,6 +47,9 @@ public class TaskItemController {
|
||||
|
||||
/**
|
||||
* 获取进行中的子任务列表
|
||||
* - 管理员:看到所有进行中的子任务
|
||||
* - 部门负责人:看到本部门所有成员的子任务
|
||||
* - 普通设计师:只看自己的子任务
|
||||
*/
|
||||
@Operation(summary = "获取进行中的子任务列表")
|
||||
@GetMapping("/in-progress")
|
||||
@ -56,17 +61,41 @@ public class TaskItemController {
|
||||
String actualToken = token.replace("Bearer ", "");
|
||||
Long userId = jwtUtil.getUserIdFromToken(actualToken);
|
||||
|
||||
// 检查是否是管理员
|
||||
com.designhub.entity.User user = userMapper.selectById(userId);
|
||||
boolean isAdmin = user != null && Integer.valueOf(1).equals(user.getIsAdmin());
|
||||
|
||||
// 管理员可以看到所有进行中的子任务
|
||||
IPage<TaskItem> items = taskItemService.getInProgressItems(page, pageSize, isAdmin ? null : userId);
|
||||
// 检查用户是否是部门负责人
|
||||
boolean isDeptLeader = false;
|
||||
Long userDeptId = null;
|
||||
if (user != null && user.getDeptId() != null) {
|
||||
userDeptId = user.getDeptId();
|
||||
// 查询该部门,检查当前用户是否是负责人
|
||||
com.designhub.entity.Department dept = departmentMapper.selectById(userDeptId);
|
||||
if (dept != null && userId.equals(dept.getLeaderId())) {
|
||||
isDeptLeader = true;
|
||||
}
|
||||
}
|
||||
|
||||
IPage<TaskItem> items;
|
||||
if (isAdmin) {
|
||||
// 管理员:看到所有进行中的子任务
|
||||
items = taskItemService.getInProgressItems(page, pageSize, null, null);
|
||||
} else if (isDeptLeader) {
|
||||
// 部门负责人:看到本部门所有成员的子任务
|
||||
items = taskItemService.getInProgressItems(page, pageSize, null, userDeptId);
|
||||
} else {
|
||||
// 普通设计师:只看自己的子任务
|
||||
items = taskItemService.getInProgressItems(page, pageSize, userId, null);
|
||||
}
|
||||
|
||||
return Result.success(items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已完成的子任务列表
|
||||
* - 管理员:看到所有已完成的子任务
|
||||
* - 部门负责人:看到本部门所有成员的子任务
|
||||
* - 普通设计师:只看自己的子任务
|
||||
*/
|
||||
@Operation(summary = "获取已完成的子任务列表")
|
||||
@GetMapping("/completed")
|
||||
@ -78,12 +107,32 @@ public class TaskItemController {
|
||||
String actualToken = token.replace("Bearer ", "");
|
||||
Long userId = jwtUtil.getUserIdFromToken(actualToken);
|
||||
|
||||
// 检查是否是管理员
|
||||
com.designhub.entity.User user = userMapper.selectById(userId);
|
||||
boolean isAdmin = user != null && Integer.valueOf(1).equals(user.getIsAdmin());
|
||||
|
||||
// 管理员可以看到所有已完成的子任务
|
||||
IPage<TaskItem> items = taskItemService.getCompletedItems(page, pageSize, isAdmin ? null : userId);
|
||||
// 检查用户是否是部门负责人
|
||||
boolean isDeptLeader = false;
|
||||
Long userDeptId = null;
|
||||
if (user != null && user.getDeptId() != null) {
|
||||
userDeptId = user.getDeptId();
|
||||
com.designhub.entity.Department dept = departmentMapper.selectById(userDeptId);
|
||||
if (dept != null && userId.equals(dept.getLeaderId())) {
|
||||
isDeptLeader = true;
|
||||
}
|
||||
}
|
||||
|
||||
IPage<TaskItem> items;
|
||||
if (isAdmin) {
|
||||
// 管理员:看到所有已完成的子任务
|
||||
items = taskItemService.getCompletedItems(page, pageSize, null, null);
|
||||
} else if (isDeptLeader) {
|
||||
// 部门负责人:看到本部门所有成员的子任务
|
||||
items = taskItemService.getCompletedItems(page, pageSize, null, userDeptId);
|
||||
} else {
|
||||
// 普通设计师:只看自己的子任务
|
||||
items = taskItemService.getCompletedItems(page, pageSize, userId, null);
|
||||
}
|
||||
|
||||
return Result.success(items);
|
||||
}
|
||||
|
||||
|
||||
@ -59,7 +59,9 @@ public interface TaskItemMapper extends BaseMapper<TaskItem> {
|
||||
@Param("keyword") String keyword);
|
||||
|
||||
/**
|
||||
* 查询进行中的子任务列表(按接单人,null表示查询所有-管理员)
|
||||
* 查询进行中的子任务列表
|
||||
* @param receiverId 接单人ID,null表示不按接单人过滤
|
||||
* @param deptId 部门ID,用于部门负责人查看本部门所有任务
|
||||
*/
|
||||
@Select("<script>" +
|
||||
"SELECT ti.*, " +
|
||||
@ -74,6 +76,7 @@ public interface TaskItemMapper extends BaseMapper<TaskItem> {
|
||||
" p.platform_name AS platformName, " +
|
||||
" dt.type_name AS taskTypeName, " +
|
||||
" u.real_name AS publisherName, " +
|
||||
" r.real_name AS receiverName, " +
|
||||
" (SELECT COUNT(*) FROM task_item WHERE task_id = ti.task_id) AS totalItems " +
|
||||
"FROM task_item ti " +
|
||||
"LEFT JOIN task t ON ti.task_id = t.id " +
|
||||
@ -82,16 +85,21 @@ public interface TaskItemMapper extends BaseMapper<TaskItem> {
|
||||
"LEFT JOIN platform p ON t.platform_id = p.id " +
|
||||
"LEFT JOIN task_type dt ON ti.task_type_id = dt.id " +
|
||||
"LEFT JOIN sys_user u ON t.publisher_id = u.id " +
|
||||
"LEFT JOIN sys_user r ON ti.receiver_id = r.id " +
|
||||
"WHERE ti.status = 'in_progress' " +
|
||||
" AND t.deleted = 0 " +
|
||||
" <if test='receiverId != null'> AND ti.receiver_id = #{receiverId} </if>" +
|
||||
" <if test='deptId != null'> AND ti.receiver_dept_id = #{deptId} </if>" +
|
||||
"ORDER BY ti.update_time DESC" +
|
||||
"</script>")
|
||||
IPage<TaskItem> selectInProgressItems(Page<TaskItem> page,
|
||||
@Param("receiverId") Long receiverId);
|
||||
@Param("receiverId") Long receiverId,
|
||||
@Param("deptId") Long deptId);
|
||||
|
||||
/**
|
||||
* 查询已完成的子任务列表(按接单人,null表示查询所有-管理员)
|
||||
* 查询已完成的子任务列表
|
||||
* @param receiverId 接单人ID,null表示不按接单人过滤
|
||||
* @param deptId 部门ID,用于部门负责人查看本部门所有任务
|
||||
*/
|
||||
@Select("<script>" +
|
||||
"SELECT ti.*, " +
|
||||
@ -106,6 +114,7 @@ public interface TaskItemMapper extends BaseMapper<TaskItem> {
|
||||
" p.platform_name AS platformName, " +
|
||||
" dt.type_name AS taskTypeName, " +
|
||||
" u.real_name AS publisherName, " +
|
||||
" r.real_name AS receiverName, " +
|
||||
" (SELECT COUNT(*) FROM task_item WHERE task_id = ti.task_id) AS totalItems " +
|
||||
"FROM task_item ti " +
|
||||
"LEFT JOIN task t ON ti.task_id = t.id " +
|
||||
@ -114,13 +123,16 @@ public interface TaskItemMapper extends BaseMapper<TaskItem> {
|
||||
"LEFT JOIN platform p ON t.platform_id = p.id " +
|
||||
"LEFT JOIN task_type dt ON ti.task_type_id = dt.id " +
|
||||
"LEFT JOIN sys_user u ON t.publisher_id = u.id " +
|
||||
"LEFT JOIN sys_user r ON ti.receiver_id = r.id " +
|
||||
"WHERE ti.status = 'completed' " +
|
||||
" AND t.deleted = 0 " +
|
||||
" <if test='receiverId != null'> AND ti.receiver_id = #{receiverId} </if>" +
|
||||
" <if test='deptId != null'> AND ti.receiver_dept_id = #{deptId} </if>" +
|
||||
"ORDER BY ti.complete_time DESC" +
|
||||
"</script>")
|
||||
IPage<TaskItem> selectCompletedItems(Page<TaskItem> page,
|
||||
@Param("receiverId") Long receiverId);
|
||||
@Param("receiverId") Long receiverId,
|
||||
@Param("deptId") Long deptId);
|
||||
|
||||
/**
|
||||
* 根据任务ID查询所有子任务
|
||||
|
||||
@ -298,15 +298,55 @@ public class TaskApprovalService {
|
||||
}
|
||||
logApproval(taskId, approverId, 2, "approve", logComment);
|
||||
|
||||
// 发送钉钉群通知
|
||||
// 发送钉钉通知
|
||||
if (assignedReceiverId != null) {
|
||||
// 指定了设计师,发送群通知并@该设计师
|
||||
log.info("任务【{}】已指定给设计师,准备发送钉钉群通知", task.getTitle());
|
||||
// 指定了设计师,发送个人通知和群通知
|
||||
log.info("任务【{}】已指定给设计师,准备发送钉钉通知", task.getTitle());
|
||||
try {
|
||||
com.designhub.entity.User receiver = userMapper.selectById(assignedReceiverId);
|
||||
String receiverName = receiver != null ? receiver.getRealName() : "未知";
|
||||
String receiverPhone = receiver != null ? receiver.getPhone() : null;
|
||||
|
||||
// 1. 发送个人钉钉通知给设计师
|
||||
StringBuilder personalContent = new StringBuilder();
|
||||
personalContent.append("**任务名称**:").append(task.getTitle()).append(" \n");
|
||||
personalContent.append("**任务编号**:").append(task.getTaskNo()).append(" \n");
|
||||
personalContent.append("**任务积分**:").append(task.getScore()).append(" 分 \n");
|
||||
|
||||
if (task.getEstimatedHours() != null) {
|
||||
int hours = task.getEstimatedHours().intValue();
|
||||
int days = hours / 8;
|
||||
int remainingHours = hours % 8;
|
||||
String timeStr = days > 0 ? (days + "天" + (remainingHours > 0 ? remainingHours + "小时" : "")) : (hours + "小时");
|
||||
personalContent.append("**时效要求**:").append(timeStr).append(" \n");
|
||||
}
|
||||
|
||||
if (task.getBrandName() != null && !task.getBrandName().isEmpty()) {
|
||||
personalContent.append("**品牌**:").append(task.getBrandName()).append(" \n");
|
||||
}
|
||||
if (task.getPlatformName() != null && !task.getPlatformName().isEmpty()) {
|
||||
personalContent.append("**平台**:").append(task.getPlatformName()).append(" \n");
|
||||
}
|
||||
if (task.getSpuInfo() != null && !task.getSpuInfo().isEmpty()) {
|
||||
personalContent.append("**SPU**:").append(task.getSpuInfo()).append(" \n");
|
||||
}
|
||||
|
||||
if (task.getPublisherName() != null && !task.getPublisherName().isEmpty()) {
|
||||
personalContent.append(" \n**发起人**:").append(task.getPublisherName()).append(" \n");
|
||||
}
|
||||
|
||||
Notification notification = new Notification();
|
||||
notification.setReceiverId(assignedReceiverId);
|
||||
notification.setTitle("您有新任务指派");
|
||||
notification.setContent(personalContent.toString());
|
||||
notification.setNotificationType("TASK_ASSIGNED");
|
||||
notification.setRelatedType("task");
|
||||
notification.setRelatedId(task.getId());
|
||||
notification.setPushDingtalk(1); // 推送到钉钉
|
||||
notificationService.sendNotification(notification);
|
||||
log.info("任务指派个人通知已发送给设计师: userId={}", assignedReceiverId);
|
||||
|
||||
// 2. 发送群通知并@指定的设计师
|
||||
String title = "任务已指派";
|
||||
StringBuilder content = new StringBuilder();
|
||||
content.append("-------------------------------- \n");
|
||||
@ -328,16 +368,15 @@ public class TaskApprovalService {
|
||||
|
||||
content.append(" \n");
|
||||
content.append("-------------------------------- \n");
|
||||
content.append("请尽快处理!qd.yydd.ai \n");
|
||||
content.append("请尽快处理! \n");
|
||||
content.append("--------------------------------");
|
||||
|
||||
// 发送群通知并@指定的设计师
|
||||
java.util.List<String> atMobiles = receiverPhone != null ?
|
||||
java.util.Arrays.asList(receiverPhone) : null;
|
||||
dingTalkService.sendRobotMessage(title, content.toString(), atMobiles);
|
||||
log.info("任务指派群通知已发送,@手机号: {}", receiverPhone);
|
||||
} catch (Exception e) {
|
||||
log.error("发送任务指派群通知失败", e);
|
||||
log.error("发送任务指派通知失败", e);
|
||||
}
|
||||
} else {
|
||||
log.info("任务【{}】已发布到任务大厅,准备发送钉钉群通知", task.getTitle());
|
||||
|
||||
@ -48,18 +48,36 @@ public class TaskItemService {
|
||||
|
||||
/**
|
||||
* 获取进行中的子任务列表
|
||||
* @param receiverId 接单人ID,null表示不按接单人过滤
|
||||
* @param deptId 部门ID,用于部门负责人查看本部门所有任务
|
||||
*/
|
||||
public IPage<TaskItem> getInProgressItems(Integer page, Integer pageSize, Long receiverId, Long deptId) {
|
||||
Page<TaskItem> pageParam = new Page<>(page, pageSize);
|
||||
return taskItemMapper.selectInProgressItems(pageParam, receiverId, deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取进行中的子任务列表(向后兼容)
|
||||
*/
|
||||
public IPage<TaskItem> getInProgressItems(Integer page, Integer pageSize, Long receiverId) {
|
||||
Page<TaskItem> pageParam = new Page<>(page, pageSize);
|
||||
return taskItemMapper.selectInProgressItems(pageParam, receiverId);
|
||||
return getInProgressItems(page, pageSize, receiverId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已完成的子任务列表
|
||||
* @param receiverId 接单人ID,null表示不按接单人过滤
|
||||
* @param deptId 部门ID,用于部门负责人查看本部门所有任务
|
||||
*/
|
||||
public IPage<TaskItem> getCompletedItems(Integer page, Integer pageSize, Long receiverId, Long deptId) {
|
||||
Page<TaskItem> pageParam = new Page<>(page, pageSize);
|
||||
return taskItemMapper.selectCompletedItems(pageParam, receiverId, deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已完成的子任务列表(向后兼容)
|
||||
*/
|
||||
public IPage<TaskItem> getCompletedItems(Integer page, Integer pageSize, Long receiverId) {
|
||||
Page<TaskItem> pageParam = new Page<>(page, pageSize);
|
||||
return taskItemMapper.selectCompletedItems(pageParam, receiverId);
|
||||
return getCompletedItems(page, pageSize, receiverId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user