12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- # coding=utf-8
- import typing
- from apps.web.constant import DeviceCmdCode, MQTT_TIMEOUT
- from apps.web.core.adapter.zhixia2 import ChargingZHIXIA2Box
- from apps.web.core.device_define.cmCZ import DEFAULT_ACCOUNT_RULE
- from apps.web.core.exceptions import ServiceException
- from apps.web.core.networking import MessageSender
- if typing.TYPE_CHECKING:
- from apps.web.user.models import ConsumeRecord
- class DCServerBox(ChargingZHIXIA2Box):
- def _send_data(self, funCode, data, cmd=DeviceCmdCode.OPERATE_DEV_SYNC, timeout=MQTT_TIMEOUT.NORMAL):
- # 若是网关发送 则addr地址填充为0
- payload = {
- "IMEI": self.device.devNo,
- "funCode": funCode
- }
- if isinstance(data, dict):
- payload.update(data)
- else:
- payload["data"] = data
- result = MessageSender.send(
- device=self.device,
- cmd=cmd,
- payload=payload,
- timeout=timeout
- )
- if "rst" not in result:
- raise ServiceException({"result": 2, "description": u"串口通信异常(10001)"})
- if result["rst"] != 0:
- if result["rst"] == -1:
- raise ServiceException({"result": 2, "description": u"网络通信异常"})
- if result["rst"] == 1:
- raise ServiceException({"result": 2, "description": u"串口通信异常(10002)"})
- return result
- @property
- def deviceRule(self):
- rule = self.device.otherConf.get("rule", DEFAULT_ACCOUNT_RULE["rule"])
- for _item in rule:
- _item["price"] *= 100
- return rule
- @property
- def deviceDefaultPrice(self):
- defaultPrice = self.device.otherConf.get("defaultPrice", DEFAULT_ACCOUNT_RULE["defaultPrice"])
- return defaultPrice * 100
- def start_device_realiable(self, order): # type:(ConsumeRecord)->dict
- if order.is_on_point:
- raise ServiceException({"result": 2, "description": u"当前设备不支持远程上分,请直接给用户派币启动"})
- attachParas = order.attachParas
- package = order.package
- if attachParas is None:
- raise ServiceException({"result": 2, "description": u"请您选择合适的充电线路"})
- if "chargeIndex" not in attachParas:
- raise ServiceException({"result": 2, "description": u"请您选择合适的充电线路"})
- # portInfo = self._get_port_info(attachParas["chargeIndex"])
- # if portInfo["status"] != Const.DEV_WORK_STATUS_IDLE:
- # raise ServiceException({"result": 2, "description": u"当前端口正在工作中,请选择其他端口"})
- port = int(attachParas["chargeIndex"])
- rule = self.deviceRule
- defaultPrice = self.deviceDefaultPrice
- data = {
- 'order_type': "com_start",
- 'chargeTime': package["time"],
- "rule": rule,
- "defaultPrice": defaultPrice,
- "port": port,
- "order_id": order.orderNo,
- }
- return self._send_data(funCode="02", data=data)
- def analyze_event_data(self, data):
- pass
|