Browse Source

主板添加了testing状态 会引发经销商获取端口异常

zjl 2 years ago
parent
commit
48672039c4
2 changed files with 27 additions and 164 deletions
  1. 9 4
      apps/web/core/adapter/weifule_policy.py
  2. 18 160
      apps/web/dealer/views.py

+ 9 - 4
apps/web/core/adapter/weifule_policy.py

@@ -730,7 +730,7 @@ class POLICYBox(PolicyBase):
         return self.stop_charging_port(int(port))
 
     @staticmethod
-    def __translate_status_from_str(status):
+    def _translate_status_from_str(status):
         dictConf = {
             'idle': Const.DEV_WORK_STATUS_IDLE,
             'busy': Const.DEV_WORK_STATUS_WORKING,
@@ -757,18 +757,23 @@ class POLICYBox(PolicyBase):
         for port, exec_orders in exec_queue.items():
             if port not in portList:
                 continue
-            result = {'index': port}
+
+            # 主板添加了testing状态 会引发经销商获取端口异常
+            if not exec_orders:
+                result = {'index': port, 'status': Const.DEV_WORK_STATUS_IDLE}
+            else:
+                result = {'index': port, 'status': self._translate_status_from_str(exec_orders[0]['status'])}
+
             onePortParam = portParam.get(port, {})
             _wait = []
             for exec_order in exec_orders:
                 order = get_consume_order(orderNo=exec_order['id'])  # type: ConsumeRecord
 
-                if exec_order['status'] == 'running':
+                if exec_order['status'] in ['running', 'testing']:
                     result['voltage'] = round(onePortParam.get('volt', 0), 2)
                     result['power'] = round(onePortParam.get('watt', 0), 2)
                     result['ampere'] = round((onePortParam.get('ampr', 0) * 0.001), 2)
                     result['devTemp'] = round((portInfo.get('mach_temp', 0)), 2)
-                    result['status'] = self.__translate_status_from_str(exec_order['status'])
                     result['usedTime'] = round(exec_order.get('time', 0) / 60.0, 2)
                     result['usedElec'] = round(exec_order.get('elec', 0) * 0.000001, 4)
 

+ 18 - 160
apps/web/dealer/views.py

@@ -11279,7 +11279,7 @@ def getDevicePort(request):
     # type: (WSGIRequest)->JsonResponse
 
     def cmp_by_port(x, y):
-        if (str(x['index']).isdigit() and str(y['index']).isdigit()):
+        if str(x['index']).isdigit() and str(y['index']).isdigit():
             if int(x['index']) < int(y['index']):
                 return -1
             elif int(x['index']) > int(y['index']):
@@ -11315,55 +11315,12 @@ def getDevicePort(request):
     else:
         isManager = False
 
-    devTypeCode = dev.devType['code']
-
     smartBox = dev.deviceAdapter
 
     if hasattr(smartBox, 'dealer_get_device_port'):
         portList = getattr(smartBox, 'dealer_get_device_port')()
         return JsonResponse({"result": 1, "description": "", "payload": {"portList": portList}})
 
-    if devTypeCode in [Const.DEVICE_TYPE_CODE_GEZIGUI_485,
-                       Const.DEVICE_TYPE_CODE_CHARGE_ZHONGSHAN, Const.DEVICE_TYPE_CODE_CHARGE_WEIFULE_CAR,
-                       Const.DEVICE_TYPE_CODE_CAR_WEIFULE_CHARGING_DOUB,
-                       Const.DEVICE_TYPE_CODE_CAR_WEIFULE_21KW,
-                       Const.DEVICE_TYPE_CODE_CAR_WEIFILE_HOME_JFPG,
-                       Const.DEVICE_TYPE_CODE_CAR_WEIFILE_HOME_DOUB_JFPG,
-                       Const.DEVICE_TYPE_CODE_CHARGE_ZHONGSHAN_BILLASSERVICE]:
-        portList = smartBox.get_port_status_from_dev()
-        return JsonResponse({"result": 1, "description": "", "payload": {"portList": portList}})
-
-
-    if devTypeCode == Const.DEVICE_TYPE_CODE_WATER_DISPENSER:
-        ctrInfo = Device.get_dev_control_cache(dev.devNo)
-
-        if ctrInfo is None or ('1' not in ctrInfo and '2' not in ctrInfo):
-            portList = {}
-        else:
-            statusDict = {}
-            statusInfoDict = {}
-            for _ in range(1, 3):
-                tempPort = str(_)
-                if ctrInfo[tempPort].get('status', 0) == 0:
-                    statusDict[tempPort] = 'idle'
-                    statusInfoDict[tempPort] = ctrInfo[tempPort].get('statusErrorInfo', u'无')
-                elif ctrInfo[tempPort].get('status', 0) == 1:
-                    statusDict[tempPort] = 'busy'
-                    statusInfoDict[tempPort] = ctrInfo[tempPort].get('statusErrorInfo', u'无')
-                elif ctrInfo[tempPort].get('status', 0) == 3:
-                    statusDict[tempPort] = 'fault'
-                    statusInfoDict[tempPort] = ctrInfo[tempPort].get('statusErrorInfo', u'无')
-                else:
-                    statusDict[tempPort] = 'fault'
-                    statusInfoDict[tempPort] = ctrInfo[tempPort].get('statusErrorInfo', u'无')
-
-            portList = [
-                {'index': '1', 'status': statusDict['1'], 'statusErrorInfo': statusInfoDict.get('1', u'无')},
-                {'index': '2', 'status': statusDict['2'], 'statusErrorInfo': statusInfoDict.get('2', u'无')}
-            ]
-
-        return JsonResponse({"result": 1, "description": "", "payload": {"portList": portList}})
-
     try:
         # 先从设备上取信息,然后从缓存中取信息
         portDict = smartBox.dealer_get_port_status()
@@ -11379,88 +11336,14 @@ def getDevicePort(request):
 
     unit = smartBox.show_pay_unit
 
-    statsMap = {str(Const.DEV_WORK_STATUS_IDLE): 'idle',
-                str(Const.DEV_WORK_STATUS_WORKING): 'busy',
-                str(Const.DEV_WORK_STATUS_FAULT): 'fault',
-                str(Const.DEV_WORK_STATUS_FORBIDDEN): 'ban',
-                str(Const.DEV_WORK_STATUS_CONNECTED): 'connected',
-                str(Const.DEV_WORK_STATUS_FINISHED): 'finished'}
-
-    # TODO zjl get_port_using_detail 这块太复杂 后续一定要整改!!! 目前先做if分支处理
-    if devTypeCode in [Const.DEVICE_TYPE_CODE_CHARGING_AQKJ, Const.DEVICE_TYPE_CODE_CHARGING_AQKJ_NEW]:
-        elecInfo = smartBox._query_elec()
-        for port, valueDict in portDict.items():
-            voltage = "{:.2f}".format(float(valueDict.get("voltage", "0")))
-            batteryImei = valueDict.get("batteryImei", "")
-            doorStatus = valueDict.get("doorStatus")
-            doorStatus = smartBox.translate_door_status_to_unicode(doorStatus)
-            tempStatus = statsMap.get(str(valueDict.get("status")))
-            elecPoint = valueDict.get("elec")
-
-            tempDict = {
-                "index": port,
-                "status": tempStatus,
-                "doorStatus": doorStatus,
-                "voltage": voltage,
-                "batteryImei": batteryImei if batteryImei else u"无电池",
-                "elecPoint": elecPoint
-            }
-            tempDict.update(elecInfo.get(port))
-            portList.append(tempDict)
-
-        portList.sort(cmp=cmp_by_port)
-        return JsonResponse({"result": 1, "description": "", "payload": {"portList": portList}})
-
-    if devTypeCode in [Const.DEVICE_TYPE_CODE_YWT_HUANDIANGUI]:
-        portList = []
-        for k, v in portDict.items():
-            tempDict = {
-                'index': k,
-                'status': statsMap.get(str(v.get("status"))),
-                'doorStatus': v['state_of_lock']=='lock' and '关闭' or '打开',
-                'batteryVoltage': v['battery_volt'],
-                'batteryImei': v['battery_id'],
-                'elecPoint': v['battery_ratio'],
-                'devTemp': v['box_temp'],
-                'power': v['current_power'],
-            }
-            portList.append(tempDict)
-
-        portList.sort(cmp=cmp_by_port)
-        return JsonResponse({"result": 1, "description": "", "payload": {"portList": portList}})
-
-
-    if devTypeCode in [Const.DEVICE_TYPE_CODE_CABINET_NEW]:
-        doorStatus = smartBox._get_door_status()
-        for port, valueDict in portDict.items():
-            voltage = "{:.2f}".format(float(valueDict.get("voltage", "0")))
-
-            tempDict = {
-                "index": port,
-                "status": statsMap.get(str(valueDict["status"])),
-                "doorStatus": doorStatus.get(port, u"未知"),
-            }
-
-            valueDict.update(tempDict)
-            portList.append(valueDict)
-
-        portList.sort(
-            key=lambda x: int(x['index']) if isinstance(x['index'], str) and x["index"].isdigit() else x['index'])
-        return JsonResponse({"result": 1, "description": "", "payload": {"portList": portList}})
-
-    if devTypeCode in [Const.DEVICE_TYPE_CODE_CABINET]:
-        for port, valueDict in portDict.items():
-            tempStatus = statsMap.get(str(valueDict.get("status")))
-
-            tempDict = {
-                "index": port,
-                "status": tempStatus,
-            }
-            valueDict.update(tempDict)
-            portList.append(valueDict)
-
-        portList.sort(cmp=cmp_by_port)
-        return JsonResponse({"result": 1, "description": "", "payload": {"portList": portList}})
+    statsMap = {
+        str(Const.DEV_WORK_STATUS_IDLE): 'idle',
+        str(Const.DEV_WORK_STATUS_WORKING): 'busy',
+        str(Const.DEV_WORK_STATUS_FAULT): 'fault',
+        str(Const.DEV_WORK_STATUS_FORBIDDEN): 'ban',
+        str(Const.DEV_WORK_STATUS_CONNECTED): 'connected',
+        str(Const.DEV_WORK_STATUS_FINISHED): 'finished'
+    }
 
     busyPortList = []
     for port, valueDict in portDict.items():
@@ -11472,34 +11355,15 @@ def getDevicePort(request):
 
     busyPortInfoDict = smartBox.get_many_port_info(busyPortList)
 
-    if devTypeCode in [Const.DEVICE_TYPE_CODE_CHARGING_HAINIAO_DOUBLE]:
-        ctrInfo = Device.get_dev_control_cache(dev.devNo)
-        for port, valueDict in portDict.items():
-            vStatus = valueDict.get('status', None)
-            if vStatus == Const.DEV_WORK_STATUS_WORKING:
-                portDetail = smartBox.get_port_using_detail(port, ctrInfo)
-                if portDetail.get('timeUnit', None) == u'秒':
-                    portDetail.update({'needTime':str(portDetail['needTime'][:-2]) + '秒'})
-                portDetail.update({"index": str(port), "status": 'busy'})
-                portList.append(portDetail)
-        portList.sort(
-            key=lambda x: int(x['index']) if isinstance(x['index'], str) and x["index"].isdigit() else x['index'])
-        map(charge_pay_coin_unit, portList, [unit for x in xrange(len(portList))])
-        for _ in portList:
-            if 'elec' in _:
-                _.pop('elec')
-        portList.sort(cmp=cmp_by_port)
-        return JsonOkResponse(payload={"isManager": isManager, "portList": portList})
-
     if busyPortInfoDict:
-        for info in busyPortInfoDict.values():
-            if info['status'] == Const.DEV_WORK_STATUS_WORKING:
-                info.update({'status':statsMap[str(info['status'])]})
-                if info.has_key('needTime') and str(info['needTime']).isdigit():
-                    info.update({'needTime':u'%s分钟' % info['needTime']})
+        for _info in busyPortInfoDict.values():
+            if 'status' in _info and _info['status'] == Const.DEV_WORK_STATUS_WORKING:
+                _info.update({'status': statsMap[str(_info['status'])]})
+                if 'needTime' in _info and str(_info['needTime']).isdigit():
+                    _info.update({'needTime': u'%s分钟' % _info['needTime']})
             else:
-                info = {'status':'idle', 'index':str(info['index'])}
-            portList.append(info)
+                _info = {'status': 'idle', 'index': str(_info['index'])}
+            portList.append(_info)
     else:
         ctrInfo = Device.get_dev_control_cache(dev.devNo)
 
@@ -11510,16 +11374,9 @@ def getDevicePort(request):
                 portDetail.update({"index": str(port), "status": 'busy'})
                 portList.append(portDetail)
 
-    portList.sort(key=lambda x: int(x['index']) if isinstance(x['index'], str) and x["index"].isdigit() else x['index'])
+    portList.sort(key=lambda _port: int(_port['index']) if isinstance(_port['index'], str) and _port["index"].isdigit() else _port['index'])
     map(charge_pay_coin_unit, portList, [unit for x in xrange(len(portList))])
 
-    # todo 删掉已充电量, 只保留订购电量 (微付乐的板子需要电量,不能去掉。按道理,这个是业务自己不返回elec,不能放在公共代码这里改)
-    if devTypeCode not in [Const.DEVICE_TYPE_CODE_CHANGING_WEIFULE, Const.DEVICE_TYPE_CODE_CHANGING_WEIFULE2, \
-                           Const.DEVICE_TYPE_CODE_CHANGING_DIANCHUANCARCHARGING, Const.DEVICE_TYPE_CODE_SUZHOU_BEISIYUN]:
-        for _ in portList:
-            if 'elec' in _:
-                _.pop('elec')
-
     if dev.support_power_graph and (
             'showPG_in_port_detail' in dev.owner.features or dev.driverCode in [Const.DEVICE_TYPE_CODE_WEIFULE_ANJIAN]):
         for item in portList:
@@ -11528,6 +11385,7 @@ def getDevicePort(request):
     portList.sort(cmp=cmp_by_port)
     return JsonOkResponse(payload={"isManager": isManager, "portList": portList})
 
+
 @error_tolerate(nil=DefaultJsonErrorResponse)
 @permission_required(ROLE.dealer, ROLE.subaccount)
 def getTempPackages(request):