| | |
| | | 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) { |
| | |
| | | // 根据租户id和工单号查询数据库是否有记录,有则返回,没有则新增一条再返回 |
| | | orderVo = getOrSaveDryOrderVoDB(realTimeDataVo); |
| | | } |
| | | if (orderVo == null) { |
| | | log.error("工单不存在,工单号:"+realTimeDataVo.getWorkorder()+",设备:" + realTimeDataVo.getMachineid() +",药材:" + realTimeDataVo.getName()); |
| | | return Result.error("工单不存在"); |
| | | } |
| | | |
| | | // 2 更新工单实时数据 |
| | | // 2.1 将工单中的数据替换为最新数据 |
| | |
| | | orderVo.setState_valve(realTimeDataVo.getState_valve()); |
| | | orderVo.setOrderStatus(realTimeDataVo.getWorkorder_status()); |
| | | orderVo.setEqp_status(realTimeDataVo.getEqp_status()); |
| | | orderVo.setEqp_state(realTimeDataVo.getEqp_state()); |
| | | // orderVo.setEqp_state(realTimeDataVo.getEqp_state()); |
| | | orderVo.setWarning(realTimeDataVo.getEqp_warning()); |
| | | orderVo.setFault(realTimeDataVo.getEqp_fault()); |
| | | orderVo.setLevel(realTimeDataVo.getLevel()); |
| | |
| | | * @param realTimeDataVo |
| | | * @return |
| | | */ |
| | | @NotNull |
| | | 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); |
| | | |
| | | 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; |
| | | } |
| | |
| | | private DryHerbFormula queryHerbByIndexTenant(RealTimeDataVo realTimeDataVo) { |
| | | LambdaQueryWrapper<DryHerbFormula> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(DryHerbFormula::getTenantId, realTimeDataVo.getTenantid()); |
| | | queryWrapper.eq(DryHerbFormula::getCode, realTimeDataVo.getIndex()); |
| | | queryWrapper.eq(DryHerbFormula::getName, realTimeDataVo.getName()); |
| | | DryHerbFormula one = dryHerbFormulaService.getOne(queryWrapper); |
| | | // if (one == null) { |
| | | // one = new DryHerb(realTimeDataVo); |
| | | // herbService.save(one); |
| | | // } |
| | | if (one == null) { |
| | | one = new DryHerbFormula(realTimeDataVo); |
| | | DryEquipment dryEquipment = equipmentService.selectByTenantIdEquipmentId(realTimeDataVo.getTenantid() + "", realTimeDataVo.getMachineid()); |
| | | one.setEqpType(dryEquipment.getType()); |
| | | dryHerbFormulaService.save(one); |
| | | } |
| | | return one; |
| | | } |
| | | |
| | |
| | | public Result<?> queryMachineRealTImeData(RealTimeDataVo realTimeDataVo) { |
| | | TenantContext.setTenant(realTimeDataVo.getTenantid()+""); |
| | | |
| | | // 查询所有机台查询组装 |
| | | // 查询所有机台,查询语句组装 |
| | | LambdaQueryWrapper<DryEquipment> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(DryEquipment::getTenantId, realTimeDataVo.getTenantid()); |
| | | queryWrapper.eq(DryEquipment::getEnable, "Y"); |
| | |
| | | dList.add(50d); |
| | | } |
| | | |
| | | } else { |
| | | // 如果没有生产,效率置0 |
| | | dList.add(0d); |
| | | } |
| | | // 如果没有生产,效率置0 |
| | | dList.add(0d); |
| | | |
| | | }); |
| | | } |
| | | |