¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.mdc.service.impl; |
| | | |
| | | import cn.hutool.core.date.DatePattern; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.parser.Feature; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringPool; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import org.apache.commons.compress.utils.Lists; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.constant.WebsocketConst; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.common.util.TranslateDictTextUtils; |
| | | import org.jeecg.modules.board.vo.EquAndon; |
| | | import org.jeecg.modules.mdc.dto.MdcEquProDto; |
| | | import org.jeecg.modules.mdc.entity.AndonOrder; |
| | | import org.jeecg.modules.mdc.mapper.AndonOrderMapper; |
| | | import org.jeecg.modules.mdc.service.IAndonOrderService; |
| | | import org.jeecg.modules.mdc.service.IMdcEquipmentService; |
| | | 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.service.ISysDictService; |
| | | import org.jeecg.modules.system.service.ISysUserService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Description: andon_order |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-06-11 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Service |
| | | public class AndonOrderServiceImpl extends ServiceImpl<AndonOrderMapper, AndonOrder> implements IAndonOrderService { |
| | | |
| | | @Resource |
| | | private IMdcEquipmentService mdcEquipmentService; |
| | | @Resource |
| | | private WebSocket webSocket; |
| | | @Resource |
| | | private ISysUserService userService; |
| | | @Resource |
| | | private ISysDictService sysDictService; |
| | | |
| | | @Override |
| | | public void procedureCall(AndonOrder andonOrder) { |
| | | if (StringUtils.isBlank(andonOrder.getEquipmentId())) { |
| | | throw new JeecgBootException("è¯·éæ©è®¾å¤ï¼"); |
| | | } |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | String userId = user.getId(); |
| | | List<String> equipmentIds = Arrays.asList(andonOrder.getEquipmentId().split(StringPool.COMMA)); |
| | | |
| | | List<MdcEquProDto> equipmentList = mdcEquipmentService.findEquProList(equipmentIds); |
| | | Map<String, MdcEquProDto> equipmentIdToProductionIdMap = equipmentList.stream().collect(Collectors.toMap(MdcEquProDto::getEquipmentId, comRateDto -> comRateDto)); |
| | | List<AndonOrder> list = Lists.newArrayList(); |
| | | for (String equipmentId : equipmentIds) { |
| | | AndonOrder andonOrderInfo = new AndonOrder(); |
| | | andonOrderInfo.setEquipmentId(equipmentId); |
| | | 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.setOperateTime(new Date()); |
| | | andonOrderInfo.setResponder(userId); |
| | | andonOrderInfo.setCallReason(andonOrder.getCallReason()); |
| | | list.add(andonOrderInfo); |
| | | } |
| | | |
| | | if (this.saveBatch(list)) { |
| | | List<AndonOrderWebSocketVo> andonOrderWebSocketVoList = Lists.newArrayList(); |
| | | //设置websocketè¯·æ±æ¶æ¯æ°æ® |
| | | for (AndonOrder order : list) { |
| | | 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(user.getRealname()); |
| | | andonOrderWebSocketVo.setRepairTime(StringPool.EMPTY); |
| | | andonOrderWebSocketVo.setFaultInfo(StringPool.EMPTY); |
| | | 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 |
| | | public List<EquAndon> equAndonList(List<String> equipmentIdList) { |
| | | List<EquAndon> result = new ArrayList<>(); |
| | | List<AndonOrder> andonOrderList = this.baseMapper.equAndonList(equipmentIdList); |
| | | if (andonOrderList != null && !andonOrderList.isEmpty()) { |
| | | andonOrderList.forEach(andonOrder -> { |
| | | EquAndon equAndon = new EquAndon(); |
| | | equAndon.setEquipmentId(andonOrder.getEquipmentId()); |
| | | StringBuilder infoBuilder = new StringBuilder(); |
| | | infoBuilder.append("å®ç¯ç±»å: ").append(sysDictService.queryDictTextByKey("andon_type",andonOrder.getAndonType())).append("\n"); |
| | | infoBuilder.append("å®ç¯äºº: ").append(sysDictService.queryTableDictTextByKey("sys_user", "realname", "id", andonOrder.getOperator())).append("\n"); |
| | | infoBuilder.append("å®ç¯æ¶é´: ").append(DateUtils.format(andonOrder.getOperateTime(), DateUtils.STR_DATE_TIME_SMALL)).append("\n"); |
| | | infoBuilder.append("å®ç¯ç¶æ: ").append(sysDictService.queryDictTextByKey("order_status",andonOrder.getOrderStatus())).append("\n"); |
| | | equAndon.setAndonInfo(infoBuilder.toString()); |
| | | result.add(equAndon); |
| | | }); |
| | | } |
| | | return result; |
| | | } |
| | | } |