123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- # -*- coding: utf-8 -*-
- # !/usr/bin/env python
- import json
- import logging
- from typing import TYPE_CHECKING
- from apps.web.constant import Const
- from apps.web.core.adapter.kehang import KeHangBox
- from apps.web.core.device_define.kehang import BillingType
- from apps.web.core.adapter.policy_common import PolicyCommon
- from apps.web.core.device_define.kehang import KeHangDeviceSettingsValidator
- from apps.web.core.exceptions import ServiceException
- from apps.web.device.models import Device
- from apps.web.user.models import ConsumeRecord
- logger = logging.getLogger(__name__)
- if TYPE_CHECKING:
- pass
- class KHPOLICYBox(PolicyCommon,KeHangBox):
- def start_device_realiable(self, order):
- return super(KHPOLICYBox, self).start_device_realiable(order)
- def set_device_function_param(self, request, lastSetConf):
- validator = KeHangDeviceSettingsValidator(request.POST)
- if not validator.is_valid():
- raise ServiceException({"result": 2, "description": json.dumps(validator.str_errors)})
- data = validator.suit_data()
- if not self._set_card_coin_time(
- data["maxPower"], data["cardCost"], data["coin1Time"], data["coin2Time"], data["coin3Time"]
- ):
- raise ServiceException({"result": 2, "description": u"参数设置失败,请重试(0001)"})
- if not self._set_card_coin_enable(data["isCardEnable"], data["isCoinEnable"]):
- raise ServiceException({"result": 2, "description": u"参数设置失败,请重试(0002)"})
- if not self._set_stop_refund(data["isAutoStop"], data["isCardRefund"]):
- raise ServiceException({"result": 2, "description": u"参数设置失败,请重试(0003)"})
- if not self._set_power_step(*data["powerStep"]):
- raise ServiceException({"result": 2, "description": u"参数设置失败,请重试(0004)"})
- if not self._set_free_voice(data["isFree"], data["voice"]):
- raise ServiceException({"result": 2, "description": u"参数设置失败,请重试(0005)"})
- if not self._set_float_and_noload(
- data["floatPower"], data["floatTime"], data["noloadPower"], data["noloadTime"], data["minConsume"]
- ):
- raise ServiceException({"result": 2, "description": u"参数设置失败,请重试(0006)"})
- if not self._set_card_time(data["card1Time"], data["card2Time"], data["card3Time"]):
- raise ServiceException({"result": 2, "description": u"参数设置失败,请重试(0007)"})
- if not self._set_consume_type(data["consumeType"], data["billingType"]):
- raise ServiceException({"result": 2, "description": u"参数设置失败,请重试(0008)"})
- if data["billingType"] == 2:
- if self.device.devTypeCode != Const.DEVICE_TYPE_CODE_KE_HANG_POLICY:
- raise ServiceException({"result": 2, "description": u"参数设置失败,您设备版本太低(0009)"})
- # 保存数据库一次
- otherConf = self.device["otherConf"]
- otherConf.update(validator.validated_data)
- Device.objects.filter(devNo=self.device.devNo).update(otherConf=otherConf)
- def get_port_info(self, port):
- """ 获取设备端口的使用详情 """
- result = self._get_port_charge_info(port)
- left = result["left"]
- power = result["power"] / 10.0
- portCache = Device.get_port_control_cache(self.device.devNo, str(port))
- billingType = portCache.get("billingType")
- needKind = portCache.get("needKind")
- orderNo = portCache.get("orderNo")
- openId = portCache.get("openId")
- order = ConsumeRecord.objects.filter(orderNo=orderNo, openId=openId).first() # type: ConsumeRecord
- if order:
- portCache["nickname"] = order.user.nickname
- if needKind and billingType is not None:
- if billingType == BillingType.TIME:
- portCache[needKind] = portCache["needValue"]
- portCache["leftTime"] = left
- elif billingType == BillingType.ELEC:
- portCache[needKind] = portCache["needValue"] / 100.0
- portCache["leftElec"] = left / 100.0
- portCache["power"] = power
- return portCache
|