| | |
| | | |
| | | import cn.hutool.core.date.DatePattern; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringPool; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.constant.WebsocketConst; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.common.system.api.ISysBaseAPI; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.modules.board.vo.EquAndon; |
| | | import org.jeecg.modules.mdc.dto.MdcEquProDto; |
| | |
| | | import org.jeecg.modules.mdc.util.DateUtils; |
| | | import org.jeecg.modules.mdc.vo.AndonOrderWebSocketVo; |
| | | import org.jeecg.modules.message.websocket.WebSocket; |
| | | import org.jeecg.modules.system.entity.SysUser; |
| | | import org.jeecg.modules.system.service.ISysDictService; |
| | | import org.jeecg.modules.system.service.ISysUserService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | |
| | | private ISysUserService userService; |
| | | @Resource |
| | | private ISysDictService sysDictService; |
| | | @Resource |
| | | private ISysBaseAPI sysBaseApi; |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void procedureCall(AndonOrder andonOrder) { |
| | | if (StringUtils.isBlank(andonOrder.getEquipmentId())) { |
| | | throw new JeecgBootException("请选择设备!"); |
| | |
| | | andonOrderInfo.setPlantName(equipmentIdToProductionIdMap != null && equipmentIdToProductionIdMap.containsKey(equipmentId) ? equipmentIdToProductionIdMap.get(equipmentId).getId() : null); |
| | | andonOrderInfo.setAndonType(StringPool.ONE); |
| | | andonOrderInfo.setOrderStatus(StringPool.ONE); |
| | | andonOrderInfo.setOperator(andonOrder.getOperator()); |
| | | andonOrderInfo.setOperator(userId); |
| | | andonOrderInfo.setOperateTime(new Date()); |
| | | andonOrderInfo.setResponder(userId); |
| | | andonOrderInfo.setResponder(andonOrder.getOperator()); |
| | | andonOrderInfo.setCallReason(andonOrder.getCallReason()); |
| | | list.add(andonOrderInfo); |
| | | } |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void responseData(List<String> ids) { |
| | | |
| | | if (CollectionUtils.isEmpty(ids)) { |
| | | throw new JeecgBootException("请选择要响应的数据"); |
| | | } |
| | | List<AndonOrder> andonOrderList = this.listByIds(ids); |
| | | List<AndonOrder> existAlreadyResponsedList = andonOrderList.stream().filter(andonOrder -> !"1".equals(andonOrder.getOrderStatus())).collect(Collectors.toList()); |
| | | if (CollectionUtils.isNotEmpty(existAlreadyResponsedList)) { |
| | | throw new JeecgBootException("存在已响应的安灯信息,无需重复响应"); |
| | | } |
| | | for (AndonOrder andonOrder : andonOrderList) { |
| | | andonOrder.setOrderStatus("2"); |
| | | andonOrder.setResponseTime(new Date()); |
| | | } |
| | | |
| | | //查询厂房信息 |
| | | List<String> equipmentIds = andonOrderList.stream().map(AndonOrder::getEquipmentId).collect(Collectors.toList()); |
| | | List<MdcEquProDto> equipmentList = mdcEquipmentService.findEquProList(equipmentIds); |
| | | Map<String, MdcEquProDto> equipmentIdToProductionIdMap = equipmentList.stream().collect(Collectors.toMap(MdcEquProDto::getEquipmentId, comRateDto -> comRateDto)); |
| | | |
| | | //保存成功后设备发送websocket消息 |
| | | if (this.updateBatchById(andonOrderList)) { |
| | | List<AndonOrderWebSocketVo> andonOrderWebSocketVoList = Lists.newArrayList(); |
| | | //设置websocket请求消息数据 |
| | | for (AndonOrder order : andonOrderList) { |
| | | AndonOrderWebSocketVo andonOrderWebSocketVo = new AndonOrderWebSocketVo(); |
| | | andonOrderWebSocketVo.setEquipmentId(order.getEquipmentId()); |
| | | andonOrderWebSocketVo.setCallPersonnel(userService.getById(order.getOperator()).getRealname()); |
| | | andonOrderWebSocketVo.setCallTime(DateUtils.format(order.getOperateTime(), DatePattern.NORM_DATE_PATTERN)); |
| | | andonOrderWebSocketVo.setCallReason(order.getCallReason()); |
| | | andonOrderWebSocketVo.setAndonType("程序呼叫"); |
| | | andonOrderWebSocketVo.setPersonResponsible(sysBaseApi.getUserById(order.getOperator()).getRealname()); |
| | | andonOrderWebSocketVo.setRepairTime(StringPool.EMPTY); |
| | | andonOrderWebSocketVo.setFaultInfo(StringPool.EMPTY); |
| | | andonOrderWebSocketVo.setType("close"); |
| | | andonOrderWebSocketVo.setPlantName(equipmentIdToProductionIdMap != null && equipmentIdToProductionIdMap.containsKey(order.getEquipmentId()) ? equipmentIdToProductionIdMap.get(order.getEquipmentId()).getProductionName() : null); |
| | | andonOrderWebSocketVoList.add(andonOrderWebSocketVo); |
| | | } |
| | | |
| | | //发送websocket请求 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put(WebsocketConst.MSG_CMD, "andon"); |
| | | jsonObject.put("data", andonOrderWebSocketVoList); |
| | | webSocket.sendMessage(jsonObject.toJSONString()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void dealWith(AndonOrder andonOrder) { |
| | | if (Objects.isNull(andonOrder)) { |
| | | throw new JeecgBootException("请选择需要处理的安灯信息"); |
| | | } |
| | | |
| | | if (StringUtils.isBlank(andonOrder.getResolutionDescreption())) { |
| | | throw new JeecgBootException("处理结果描述不能为空"); |
| | | } |
| | | |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | andonOrder.setProcessor(user.getId()); |
| | | andonOrder.setProcessTime(new Date()); |
| | | andonOrder.setOrderStatus("3"); |
| | | |
| | | this.updateById(andonOrder); |
| | | } |
| | | } |