Commit ca1af819 authored by wdy's avatar wdy

删除用户判断

parent cf6a7b06
......@@ -22,6 +22,10 @@
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
......
package com.ruoyi.system.domain.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
@ApiModel("检验员VO")
public class UserCountVo {
@ApiModelProperty("检验员id")
private Long userId;
@ApiModelProperty("用户所进行任务数量")
private Long countNum;
@ApiModelProperty("用户名")
private String nikeName;
}
package com.ruoyi.system.mapper;
import java.util.List;
import com.ruoyi.system.domain.vo.UserCountVo;
import org.apache.ibatis.annotations.Param;
import com.ruoyi.common.core.domain.entity.SysUser;
......@@ -138,4 +139,11 @@ public interface SysUserMapper
* @return
*/
List<SysUser> selectUserListByRoleId(@Param("roleId") Long roleId);
/**
* 查询用户所含进行中任务数
* @param userIds
* @return
*/
List<UserCountVo> countTaskByUserId(@Param("userIds") Long[] userIds);
}
......@@ -6,6 +6,7 @@ import java.util.stream.Collectors;
import javax.validation.Validator;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.system.domain.vo.UserCountVo;
import com.ruoyi.system.mapper.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -475,6 +476,17 @@ public class SysUserServiceImpl implements ISysUserService
checkUserAllowed(new SysUser(userId));
checkUserDataScope(userId);
}
List<UserCountVo> list = userMapper.countTaskByUserId(userIds);
StringBuilder msg = new StringBuilder();
for (UserCountVo countVo : list) {
if (countVo.getCountNum() > 0) {
msg.append(countVo.getNikeName()).append("、");
}
}
if (StringUtils.isNotEmpty(msg.toString())) {
msg = new StringBuilder(msg.substring(0, msg.length() - 1));
throw new ServiceException("用户:" + msg +"存在进行中的任务,不能删除");
}
// 删除用户与角色关联
userRoleMapper.deleteUserRole(userIds);
// 删除用户与岗位关联
......
......@@ -229,5 +229,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{userId}
</foreach>
</delete>
<select id="countTaskByUserId" resultType="com.ruoyi.system.domain.vo.UserCountVo">
select count(*) countNum, tr.user_id userId, s.nick_name nikeName
from t_task t
left join t_task_user_relation tr on tr.task_id = t.id
left join sys_user s on s.user_id = tr.user_id
where t.task_status in ('NEW','PENDING') and tr.user_id in
<foreach item="item" collection="userIds" open="(" separator="," close=")">
#{item}
</foreach>
group by tr.user_id
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment