websocket方法调用(检测)

This commit is contained in:
许允枞 2024-11-09 10:57:53 +08:00
parent 8b74bc9496
commit fd94f59ee1
6 changed files with 92 additions and 4 deletions

View File

@ -8,11 +8,13 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.appBase.controller.admin.InspectionSocket;
import cn.iocoder.yudao.module.custom.entity.CustomerMain;
import cn.iocoder.yudao.module.custom.service.CustomerMainService;
import cn.iocoder.yudao.module.inspection.vo.DlInspectionWorkNodeVo;
@ -21,6 +23,7 @@ import cn.iocoder.yudao.module.partner.service.IPartnerCustomerInfoService;
import cn.iocoder.yudao.module.partner.service.IPartnerWorkerService;
import cn.iocoder.yudao.module.payment.service.IOrderInfoDetailService;
import cn.iocoder.yudao.module.payment.service.OrderInfoService;
import cn.iocoder.yudao.module.system.api.user.dto.UserDTO;
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.UserRoleDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
@ -86,6 +89,8 @@ public class InspectionInfoServiceImpl extends ServiceImpl<InspectionInfoMapper,
private CustomerMainService customerMainService;
@Autowired
private RoleService roleService;
@Autowired
private InspectionSocket inspectionSocket;
/**
* 查询请填写功能名称
@ -234,6 +239,15 @@ public class InspectionInfoServiceImpl extends ServiceImpl<InspectionInfoMapper,
});
workNodeService.saveBatch(inspectionWorkNodes);
//获取第一个节点的角色
Integer roleId = inspectionWorkNodes.get(0).getRoleId();
//根据角色id获取所有用户
List<UserDTO> listByUserId = roleService.getListByUserId(roleId);
if (CollUtil.isNotEmpty(listByUserId)) {
for (UserDTO userDTO : listByUserId) {
inspectionSocket.sendMessage("接工单", userDTO.getId().toString());
}
}
//检测步骤表插入检测开始
InspectionStepInfo stepInfo = new InspectionStepInfo();

View File

@ -1,9 +1,11 @@
package cn.iocoder.yudao.module.inspection.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.appBase.controller.admin.InspectionSocket;
import cn.iocoder.yudao.module.inspection.entity.DlInspectionProject;
import cn.iocoder.yudao.module.inspection.entity.InspectionInfo;
import cn.iocoder.yudao.module.inspection.entity.InspectionStepInfo;
@ -13,7 +15,9 @@ import cn.iocoder.yudao.module.inspection.service.DlInspectionProjectService;
import cn.iocoder.yudao.module.inspection.service.IInspectionInfoService;
import cn.iocoder.yudao.module.inspection.service.IInspectionWorkNodeService;
import cn.iocoder.yudao.module.inspection.service.InspectionStepInfoService;
import cn.iocoder.yudao.module.system.api.user.dto.UserDTO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.service.permission.RoleService;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@ -23,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@ -44,6 +49,10 @@ public class InspectionWorkNodeServiceImpl extends ServiceImpl<InspectionWorkNod
private DlInspectionProjectService inspectionProjectService;
@Autowired
private InspectionStepInfoService inspectionStepService;
@Autowired
private InspectionSocket inspectionSocket;
@Autowired
private RoleService roleService;
/**
* 员工接单
@ -183,6 +192,10 @@ public class InspectionWorkNodeServiceImpl extends ServiceImpl<InspectionWorkNod
} else {
//修改工单表当前流程
inspectionInfo.setNowOrderNum(workNode.getOrderNum() + 1);
//获取下一节点
InspectionWorkNode nextNode = getNextNode(inspectionWorkNodes, workNode);
List<UserDTO> listByUserId = roleService.getListByUserId(nextNode.getRoleId());
sendSocketMessage(listByUserId);
}
//将节点状态改为已完成
@ -193,6 +206,15 @@ public class InspectionWorkNodeServiceImpl extends ServiceImpl<InspectionWorkNod
inspectionInfoService.updateById(inspectionInfo);
}
private InspectionWorkNode getNextNode(List<InspectionWorkNode> inspectionWorkNodes, InspectionWorkNode workNode) {
for (InspectionWorkNode node : inspectionWorkNodes) {
if (node.getOrderNum() == workNode.getOrderNum() + 1) {
return node;
}
}
return null;
}
/**
* 根据检测id获取流程信息
*
@ -320,6 +342,11 @@ public class InspectionWorkNodeServiceImpl extends ServiceImpl<InspectionWorkNod
//跟新工单表
inspectionInfoService.updateById(info);
//获取重审的节点的roleID
Integer roleId = workNode.getRoleId();
List<UserDTO> listByUserId = roleService.getListByUserId(roleId);
sendSocketMessage(listByUserId);
// 添加步骤信息表
InspectionStepInfo stepInfo = new InspectionStepInfo();
stepInfo.setInspectionInfoId(Integer.parseInt(inspectionWorkNode.getInspectionInfoId().toString()));
@ -332,4 +359,16 @@ public class InspectionWorkNodeServiceImpl extends ServiceImpl<InspectionWorkNod
}
inspectionStepService.save(stepInfo);
}
public void sendSocketMessage(List<UserDTO> listByUserId) {
if (CollUtil.isNotEmpty(listByUserId)) {
for (UserDTO userDTO : listByUserId) {
try {
inspectionSocket.sendMessage("接工单", userDTO.getId().toString());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
}

View File

@ -42,4 +42,6 @@ public interface UserRoleMapper extends BaseMapperX<UserRoleDO> {
List<UserDTO> selectByRoleCode(@Param("tenantId") Long tenantId, @Param("roleCode") String roleCode);
IPage<UserDTO> selectListByRoleId(@Param("page") Page<UserDTO> page,@Param("role") RolePageReqVO role);
List<UserDTO> selectByRoleId(Integer roleId);
}

View File

@ -175,4 +175,11 @@ public interface RoleService {
* @return
*/
List<UserRoleDO> getByUserId(Long userId);
/**
* 根据角色id查询用户
* @param roleId
* @return
*/
List<UserDTO> getListByUserId(Integer roleId);
}

View File

@ -372,6 +372,18 @@ public class RoleServiceImpl implements RoleService {
return userRoleDOS;
}
/**
* 根据角色id查询用户
*
* @param roleId
* @return
*/
@Override
public List<UserDTO> getListByUserId(Integer roleId) {
List<UserDTO> userDTOS = userRoleMapper.selectByRoleId(roleId);
return userDTOS;
}
/**
* 获得自身的代理对象解决 AOP 生效问题
*

View File

@ -35,4 +35,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
</where>
</select>
<select id="selectByRoleId" resultType="cn.iocoder.yudao.module.system.api.user.dto.UserDTO">
SELECT
*
FROM
system_users
WHERE
id IN (
SELECT
user_id
FROM
system_user_role sur
WHERE
sur.role_id = #{roleId})
</select>
</mapper>