| | |
| | | import org.apache.mina.core.service.IoAcceptor; |
| | | import org.apache.mina.core.service.IoHandler; |
| | | import org.apache.mina.core.session.IoSession; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.eclipse.paho.client.mqttv3.MqttClient; |
| | | import org.eclipse.paho.client.mqttv3.MqttException; |
| | | import org.eclipse.paho.client.mqttv3.MqttMessage; |
| | | import org.jeecg.common.api.CommonAPI; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.config.TenantContext; |
| | | import org.jeecg.common.config.mqtoken.UserTokenContext; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.constant.MqttConstant; |
| | | import org.jeecg.common.system.util.JwtUtil; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.common.util.RedisUtil; |
| | | import org.jeecg.common.util.SpringContextUtils; |
| | | import org.jeecg.modules.dry.common.CacheConstants; |
| | | import org.jeecg.modules.dry.entity.*; |
| | | import org.jeecg.modules.dry.mqtt.MqttUtil; |
| | | import org.jeecg.modules.dry.service.*; |
| | | import org.jeecg.modules.dry.socket.ServerHandler; |
| | | import org.jeecg.modules.dry.socket.SocketServerConfig; |
| | |
| | | import org.jeecg.modules.dry.vo.*; |
| | | import org.jetbrains.annotations.NotNull; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.security.auth.login.LoginContext; |
| | | import java.io.IOException; |
| | | import java.io.ObjectOutputStream; |
| | | import java.net.Socket; |
| | |
| | | |
| | | private String token; |
| | | |
| | | @Value(value = "${jeecg.mqtt.role}") |
| | | private String role; |
| | | |
| | | @Autowired |
| | | private MqttUtil mqttUtil; |
| | | |
| | | public String getTemporaryToken() { |
| | | if (token == null) { |
| | |
| | | */ |
| | | private DryOrderVo saveNewOrder(RealTimeDataVo realTimeDataVo) { |
| | | DryOrderVo orderVo; |
| | | // 查询药材 |
| | | DryHerbFormula herbFormula = queryHerbByIndexTenant(realTimeDataVo); |
| | | |
| | | // 查询设备 |
| | | DryEquipment equ = queryEquipmentByCodeTenant(realTimeDataVo); |
| | | if (equ == null) { |
| | | log.error("未找到设备:"+realTimeDataVo.getIndex() +","+realTimeDataVo.getName() +",机台:" + realTimeDataVo.getMachineid()); |
| | | return null; |
| | | } |
| | | // 查询药材 |
| | | DryHerbFormula herbFormula = queryHerbByIndexTenant(realTimeDataVo); |
| | | |
| | | // 创建新工单 |
| | | orderVo = new DryOrderVo(realTimeDataVo); |
| | | if (herbFormula == null) { |
| | | log.error("未找到药材:"+realTimeDataVo.getIndex() +","+realTimeDataVo.getName() +",机台:" + realTimeDataVo.getMachineid()); |
| | | return null; |
| | | } |
| | | // 创建新工单 |
| | | orderVo = new DryOrderVo(realTimeDataVo); |
| | | |
| | | orderVo.setHerbId(herbFormula.getId()); |
| | | orderVo.setEquId(equ.getId()); |
| | | DryOrder dryOrder = BeanUtil.toBean(orderVo, DryOrder.class); |
| | |
| | | queryWrapper.eq(DryEquipment::getCode, realTimeDataVo.getMachineid()); |
| | | DryEquipment one = equipmentService.getOne(queryWrapper); |
| | | if (one == null) { |
| | | one = new DryEquipment(realTimeDataVo); |
| | | equipmentService.save(one); |
| | | log.error(role+"保存实时数据,未找到设备:"+realTimeDataVo.getMachineid()); |
| | | // one = new DryEquipment(realTimeDataVo); |
| | | // equipmentService.save(one); |
| | | if (MqttConstant.ROLE_ADMIN.equals(role)) { |
| | | MqttMessage mqttMessage = new MqttMessage(); |
| | | mqttMessage.setQos(0); |
| | | JSONObject object = new JSONObject(); |
| | | object.put("code", realTimeDataVo.getMachineid()); |
| | | mqttMessage.setPayload(object.toJSONString().getBytes()); |
| | | try { |
| | | mqttUtil.getMqttClient().publish(String.format(MqttConstant.SERVICE_REQ_EQUIPMENT, TenantContext.getTenant()) ,mqttMessage); |
| | | }catch (MqttException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | return null; |
| | | } |
| | | return one; |
| | | } |