Esempio n. 1
0
    def startLineStat(self, openid, data):
        busline_id = data.busline_id
        company_id = data.company_id

        _ret = db.query(
            "SELECT * FROM BusLine WHERE id={0}".format(busline_id))
        busline = _ret[0]

        items = devdb.getDeviceByGroupid(openid, busline.busgroupid)
        line_name = busline.from_name + " " + busline.to_name

        jdkSign = objWeixin.get_jdk_sign(self.url)
        fixPara = icfg.getFixPara(openid,
                                  busline_id=busline_id,
                                  company_id=company_id)

        cfgPara = {
            "openid": openid,
            "buses": items,
            "busline_id": busline_id,
            "company_id": company_id,
            "line_name": line_name
        }
        _cfgPara = json.dumps(cfgPara, ensure_ascii=False)
        ret = self.render.start_busline_stat(_cfgPara, jdkSign, fixPara)
        return ret
Esempio n. 2
0
 def getAboutMsg(self,data):
     openid = objWeixin.getOpenid(data)
     imei = data.imei
     _ret = db.query('SELECT * FROM Device WHERE imei="{0}"'.format(imei))
     
     cfgPara = {
         "result":"failed"
     }
     if len(_ret)>0:
         dev = _ret[0]
         
         #查询该imei所属的管理分组
         _group = db.query("""SELECT *,DeviceGroup.id AS grpId FROM DeviceGroup,GroupHasDevice 
                                      WHERE GroupHasDevice.imei ='{0}' AND
                                            GroupHasDevice.devicegroup_id =DeviceGroup.id AND
                                            DeviceGroup.type = "管理分组"
                                      """.format(imei))
         if len(_group)>0:
             grp = _group[0]
             grpName = grp.name
             grpId   = grp.grpId
             _ret = db.query("SELECT * FROM BusLine WHERE busgroupid={0}".format(grpId))
             busline = _ret[0]
             busline_id = busline.id
             company_id = busline.company_id
         else:
             grpName = "未知"
             grpId   = -1
             company_id = 0
             busline_id = -1
         
         cfgPara = {
             "result"       :"success",
             "name"         :dev.name,
             "openid"       :openid,
             "busline_id"   :busline_id,
             "grpName"      :grpName,
             "grpId"        :grpId, 
             "devType"      :("天网1代" if dev.devType=="" else dev.devType),
             "manufacturer" :dev.manufacturer,
             "imei"         :dev.imei,
             "phone"        :dev.phone,
             "arm_type"     :dev.arm_type,
             "seat_type"    :dev.seat_type,
             "create_at"    :dev.regedit_at.strftime("%Y-%m-%d"), 
             "warehouse_id" :dev.warehouse_id,
             "company_id"   :company_id,
         }  
     if  web.ctx.method=='GET':
         sharePara=tradeObj.genPreSharePara("transfer",openid,imei)
         #设定缺省车型
         sharePara["sel"]={"midbus":"","bed":"","test":""}
         sharePara["sel"][dev.seat_type]='selected = "selected"'
         sharePara["company_id"]= company_id
         jdkSign = objWeixin.get_jdk_sign(self.env['url'])
         _cfgPara=json.dumps(cfgPara,ensure_ascii=False)
         ret = self.render.single_device_mgr(_cfgPara,jdkSign,sharePara)
     else:
         ret = uTools.formatPostMsg(cfgPara)
     return ret
Esempio n. 3
0
    def designLineSiteQQ(self, openid, data):
        jdkSign = objWeixin.get_jdk_sign(self.url)
        #对站点进行排序

        if data.has_key('busline_id'):  #已有的线路重新调整
            sites = linedb.getSitesByLineid(data.busline_id, "manual")
            busline = linedb.getBuslineByid(data.busline_id, format="string")
            linedb.orderLineSiteSeq(busline["id"])
        else:  #创建新的线路
            sites = {"manual": [], "auto": []}
            busline = {"id": -1, "from_name": "", "to_name": ""}
        user = userdb.getUserByOpenid(objWeixin.weixinName, openid)

        cfgPara = {
            "openid": openid,
            "sites": sites,
            "user": user,
            "busline": busline,
            "company_id": data.company_id
        }
        fixPara = icfg.getFixPara(openid,
                                  busline=busline,
                                  company_id=data.company_id)
        _cfgPara = json.dumps(cfgPara, ensure_ascii=False)
        ret = self.render.line_sites_qq(_cfgPara, jdkSign, fixPara)
        return ret
Esempio n. 4
0
    def designLinePrice(self, openid, data):
        jdkSign = objWeixin.get_jdk_sign(self.url)
        busline_id = data.busline_id
        company_id = data.company_id
        #获取相关数据
        sites = linedb.getSitesByLineid(busline_id)
        prices = linedb.getLinePrice(busline_id)
        _ret = db.query(
            "SELECT * FROM BusLine WHERE id = {0}".format(busline_id))
        busline = _ret[0]
        line_name = busline.from_name + "-" + busline.to_name
        #结果拼装
        cfgPara = {
            "openid": openid,
            "sites": sites,
            "prices": prices,
            "line_name": line_name,
            "busline_id": busline_id,
            "company_id": company_id
        }

        fixPara = icfg.getFixPara(openid,
                                  busline_id=busline_id,
                                  company_id=company_id)
        _cfgPara = json.dumps(cfgPara, ensure_ascii=False)
        ret = self.render.design_line_price(_cfgPara, jdkSign, fixPara)
        return ret
Esempio n. 5
0
 def getLineBuses(self, openid, data):
     _ret = db.query("SELECT * FROM BusLine WHERE id={0}".format(
         data.busline_id))
     busline = _ret[0]
     #判定是否为赛维员工
     manager = linedb.getManageEmployee(openid)
     items = devdb.getDeviceByGroupid(openid, busline.busgroupid)
     line_name = busline.from_name + " " + busline.to_name
     if web.ctx.method == 'GET':
         jdkSign = objWeixin.get_jdk_sign(self.url)
         cfgPara = {
             "openid": openid,
             "items": items,
             "busline_id": data.busline_id,
             "busgroupid": busline.busgroupid,
             "company_id": data.company_id,
             "line_name": line_name
         }
         fixPara = icfg.getFixPara(openid,
                                   manager=manager,
                                   busline_id=data.busline_id,
                                   busgroupid=busline.busgroupid,
                                   company_id=busline.company_id)
         _cfgPara = json.dumps(cfgPara, ensure_ascii=False)
         ret = self.render.line_buses(_cfgPara, jdkSign, fixPara)
     else:
         cfgPara = {"items": items, "result": "succuss"}
         ret = uTools.formatPostMsg(cfgPara)
     return ret
Esempio n. 6
0
    def getMineTrackMsg(self, openid, data):
        #jdkSign = objWeixin.get_jdk_sign(self.url)
        company_id = data.company_id
        jdkSign = {}
        dev = devdb.getDevice(data.imei)

        if dev != "":
            #查询设备位置信息
            arm = historyTrackMgr.getMineTrack(dev['imei'])
            _ret = db.query(
                "SELECT * FROM BusLine WHERE busgroupid={0}".format(
                    dev["groupid"]))
            busline = _ret[0]

            sites = linedb.getSitesByLineid(busline.id, "manual")
            cfgPara = {
                "pt":
                arm,
                'openid':
                openid,
                'dev':
                dev,
                'busline_id':
                busline.id,
                'sites':
                sites["manual"],
                'url':
                "gxsaiwei/m/bustrack?act=MINE_TRACK&openid={0}&imei=".format(
                    openid),
                'imei':
                dev['imei'],
                "company_id":
                company_id,
            }
        else:
            cfgPara = {
                "pt": "",
                'openid': openid,
                'dev': "",
                'url': "#",
                'imei': "",
                'sites': [],
                'busline_id': -1,
                "company_id": company_id,
            }
        if web.ctx.method == 'GET':
            jdkSign = objWeixin.get_jdk_sign(self.url)
            sharePara = tradeObj.genPreSharePara("share_view", openid,
                                                 cfgPara['imei'])
            _cfgPara = json.dumps(cfgPara, ensure_ascii=False)
            ret = self.render.mytrackqq_v2(_cfgPara, jdkSign, sharePara)
            #ret = self.render.mytrackqq_v1(cfgPara,_cfgPara)
        else:
            ret = uTools.formatPostMsg(cfgPara)
        return ret
Esempio n. 7
0
 def getOnlineState(self,openid,data):
     #查询纳入
     buses = devdb.getCompanyBusSate()
     if  web.ctx.method=='GET': 
         jdkSign = objWeixin.get_jdk_sign(self.env["url"])
         fixPara = icfg.getFixPara(openid)
         cfgPara = {"buses":buses,"openid":openid}
         _cfgPara =json.dumps(cfgPara,ensure_ascii=False)
         ret     = self.render.online_state(_cfgPara,jdkSign,fixPara)
     else:
         ret =uTools.formatPostMsg({"buses":buses})
     return ret
Esempio n. 8
0
 def bindNewDeviceMsg(self,openid,data):
     if  web.ctx.method=='GET':
         jdkSign = objWeixin.get_jdk_sign(self.env['url'])
         busline =linedb.getBuslineByid(data.busline_id,format="string")
         #company = linedb.getCompanyByBusline(data.busline_id)
         _cfgPara={"openid" :openid,"busline":busline}
         cfgPara = json.dumps(_cfgPara,ensure_ascii=False)
         ret = self.render.bind_new_devices(cfgPara,jdkSign)
     else:
         imei = self.updateManagerDeviceGroup(openid,data)
         #产品被卖出,更新卖出时间
         db.update("Device",where="imei=$imei",vars=locals(),saled_at=web.SQLLiteral('NOW()'))
         ret =  uTools.formatPostMsg({"result":"success","msg":"bind  succeed"})           
     return ret
Esempio n. 9
0
 def getOnlineTestViewMsg(self,openid):
     if openid not in ["vk","zongheng"]:
         return
     openid = "online-test"
     cfgPara = devdb.getDeviceDistrubtorView(openid)
     cfgPara["openid"]=openid
     #iUrl = "&".join(self.env["qrcode_url"].split("&")[0:2])+"&grpType={0}&grpName={1}".format(grpType,grpName)
     
     _cfgPara = json.dumps(cfgPara,ensure_ascii=False)
     if  web.ctx.method=='GET':
         jdkSign = objWeixin.get_jdk_sign(self.env["url"])
         fixPara = icfg.getFixPara(openid)
         ret = self.render.online_test(_cfgPara,jdkSign,fixPara)
     else:
         ret =_cfgPara
     return ret
Esempio n. 10
0
 def designLineSite(self, openid, data):
     jdkSign = objWeixin.get_jdk_sign(self.url)
     sites = [{
         "name": "无菊",
         "addr": "云南省红河州金平县无菊酒吧",
         "lat": 223.1455,
         "lng": 109.1231
     }, {
         "name": "蒙自",
         "addr": "云南省红河州蒙自县无菊酒吧",
         "lat": 223.1455,
         "lng": 109.1231
     }]
     cfgPara = {"openid": openid, "sites": sites}
     _cfgPara = json.dumps(cfgPara, ensure_ascii=False)
     ret = self.render.line_sites(_cfgPara, jdkSign,
                                  icfg.getFixPara(openid))
     return ret
Esempio n. 11
0
    def getCompanyBuses(self, openid, data):
        #manager = objWeixin.getManager(openid)
        #判定是否为赛维员工
        manager = linedb.getManageEmployee(openid)

        user = objWeixin.get_user_info2(openid, format="string")
        #获取公司信息
        company_id = uTools.get_data_value(data, "company_id", default=0)
        if company_id == 0:
            companys = linedb.getCompanyByOpenid(openid, format="string")
            company = companys[0]
            company_id = company["id"]
        else:
            company_id = int(company_id)
            company = linedb.getCompany(company_id, format="string")

        items = devdb.getBusesByCompany(openid, company["id"])

        if web.ctx.method == 'GET':
            jdkSign = objWeixin.get_jdk_sign(self.url)
            cfgPara = {
                "openid": openid,
                "devs": items,
                "company": company,
                "user": user
            }
            #生成分享链接
            share_app_link = "{0}/m/company?act=cert-company&company_id={1}".format(
                self.env["homedomain"], company_id)
            share_app_title = "扫一扫,成为-{0}-运营管理员 ".format(company["company"])
            fixPara = icfg.getFixPara(
                openid,
                manager=manager,
                company_id=company["id"],
                company_name=company["company"],
                share_app_link=share_app_link,
                share_app_title=share_app_title,
            )
            _cfgPara = json.dumps(cfgPara, ensure_ascii=False)
            ret = self.render.company_buses(_cfgPara, jdkSign, fixPara)
        else:
            cfgPara = {"devs": items, "result": "succuss"}
            ret = uTools.formatPostMsg(cfgPara)
        return ret
Esempio n. 12
0
    def startSingleBusStat(self, openid, data):
        busline_id = data.busline_id
        company_id = data.company_id
        imei = data.imei

        jdkSign = objWeixin.get_jdk_sign(self.url)
        fixPara = icfg.getFixPara(openid,
                                  busline_id=busline_id,
                                  company_id=company_id)

        cfgPara = {
            "openid": openid,
            "busline_id": busline_id,
            "company_id": company_id,
            "imei": imei
        }
        _cfgPara = json.dumps(cfgPara, ensure_ascii=False)
        ret = self.render.start_bus_stat(_cfgPara, jdkSign, fixPara)
        return ret
Esempio n. 13
0
 def home(self, openid, data):
     _ret = db.query("SELECT * FROM Device WHERE imei='{0}'".format(
         data.imei))
     dev = _ret[0]
     fireMinutes = 15 if dev.fireMinutes == 0 else dev.fireMinutes
     fireDistance = 200 if dev.fireDistance == 0 else dev.fireDistance
     moveSpeaker = "off" if dev.moveSpeaker is None else dev.moveSpeaker
     poweroffSpeaker = "off" if dev.poweroffSpeaker is None else dev.poweroffSpeaker
     _ret = db.query(
         "SELECT * FROM CurrentLocation WHERE imei='{0}'".format(data.imei))
     _devState = _ret[0]
     _cfgPara = {
         'openid':
         openid,
         'imei':
         data.imei,
         'fireMinutes':
         fireMinutes,
         'fireDistance':
         fireDistance,
         'moveSpeaker':
         moveSpeaker,
         'poweroffSpeaker':
         poweroffSpeaker,
         'monitorState':
         dev.monitorState,
         'alm_low_voltage':
         _devState.alm_low_voltage,
         'alm_power_off':
         _devState.alm_power_off,
         'lost_seconds':
         self.lost_seconds(data.imei),
         'lost_alm_after_minutes': (dev.lost_alm_after_minutes if
                                    dev.lost_alm_after_minutes > 0 else 15)
     }
     if web.ctx.method == 'GET':
         jdkSign = objWeixin.get_jdk_sign(self.env["url"])
         cfgPara = json.dumps(_cfgPara, ensure_ascii=False)
         ret = self.render.security_item(cfgPara, jdkSign)
     else:
         ret = uTools.formatPostMsg(_cfgPara)
     return ret
Esempio n. 14
0
    def getCompanyBusLines(self, openid, data):
        jdkSign = objWeixin.get_jdk_sign(self.url)
        user = objWeixin.get_user_info2(openid, format="string")
        #获取openid对应的公司
        manager = objWeixin.getManager(openid)
        company_mgr = linedb.getManageEmployee(openid)
        company_id = uTools.get_data_value(data, "company_id", default=0)

        ret = linedb.getBusLineByOpenid(openid, company_id)

        if len(ret["company_ids"]) == 0:  #不是有效员工
            if manager != None:  #是管理员
                return web.seeother(
                    "/company?act=manager-home&openid={0}".format(openid))
            else:
                return web.seeother(icfg.urlHome)
        else:
            company_id = ret["company_ids"][0]
            company = linedb.getCompany(company_id, format="string")
            employee = linedb.getEmployeeByid(company_id, with_manager=True)
            cfgPara = {
                "openid": openid,
                "user": user,
                "items": ret["items"],
                "company": company,
                "employee": employee
            }
            #生成分享链接
            share_app_link = "{0}/m/company?act=cert-company&company_id={1}".format(
                self.env["homedomain"], company_id)
            share_app_title = "扫一扫,成为-{0}-运营管理员 ".format(company["company"])
            mgr = ("manager"
                   if manager != None or company_mgr != None else None)
            fixPara = icfg.getFixPara(openid,
                                      manager=mgr,
                                      share_app_link=share_app_link,
                                      share_app_title=share_app_title,
                                      company_id=company_id)
            _cfgPara = json.dumps(cfgPara, ensure_ascii=False)
            ret = self.render.company_buslines(_cfgPara, jdkSign, fixPara)
        return ret
Esempio n. 15
0
    def get_bustravel_detail(self, openid, data):
        span_id = data.span_id
        cfgPara = busdb.getDetailBusTravelStat(span_id)
        imei = cfgPara["imei"]
        company = linedb.getCompanyByImei(imei)
        dev = devdb.getDeviceByImei(imei, format="string")

        cfgPara["name"] = dev["name"]
        cfgPara["company_id"] = company["id"]
        cfgPara["openid"] = openid
        jdksign = objWeixin.get_jdk_sign(self.env["url"])

        sharePara = tradeObj.genPreSharePara("share-view", openid, imei)
        sharePara["blank_color"] = "#C0C0C0"
        sharePara["manager"] = objWeixin.getManager(openid)
        sharePara["company_id"] = company["id"]
        sharePara["openid"] = openid
        cfgPara = json.dumps(cfgPara, ensure_ascii=False)

        ret = self.render.bustravel_detail(cfgPara, jdksign, sharePara)
        return ret
Esempio n. 16
0
    def get_bustravel_current(self, openid, data):
        imei = data.imei
        company = linedb.getCompanyByImei(imei)
        dev = devdb.getDeviceByImei(imei, format="string")

        cfgPara = busdb.getCurrentBusTravelStat(imei)
        if cfgPara == None:  #暂时没有数据
            ret = web.seeother(
                "/device?act=seat-status-auto&openid={0}&imei={1}&company_id={2}"
                .format(openid, imei, company["id"]))
        else:
            cfgPara["name"] = dev["name"]
            cfgPara["imei"] = imei
            cfgPara["company_id"] = company["id"]

            jdksign = objWeixin.get_jdk_sign(self.env["url"])
            sharePara = tradeObj.genPreSharePara("share-view", openid, imei)
            sharePara["manager"] = objWeixin.getManager(openid)
            sharePara["company_id"] = company["id"]
            cfgPara = json.dumps(cfgPara, ensure_ascii=False)

            ret = self.render.bustravel_current(cfgPara, jdksign, sharePara)
        return ret
Esempio n. 17
0
 def resetSF(self, openid, data):
     imei = data.imei
     jdkSign = objWeixin.get_jdk_sign(self.env["url"])
     cfgPara = {"openid": openid}
     #判定该用户对该imei具有管理权限
     if self.openidOwnerImei(openid, imei) == False:  #不是管理者,不能解除告警
         cfgPara["result"] = "fails"
     else:
         db.update(
             "Device",
             where='imei=$imei',
             vars=locals(),
             stopTime="0000-00-00 00:00:00",
             stopBaiduLat=0,
             stopBaiduLng=0,
             monitorState='waiting0',
             monitor_at="0000-00-00 00:00:00",
         )
         cfgPara["result"] = "success"
     if web.ctx.method == 'GET':
         ret = self.render.fire_alarm_result(cfgPara, jdkSign)
     else:
         ret = uTools.formatPostMsg(cfgPara)
     return ret
Esempio n. 18
0
    def friendManager(self,openid,imei):
        items =[]
        #权限验证
        company  = linedb.getCompanyByImei(imei)
        employee = linedb.getCompanyEmployeeByOpenid(openid,company["id"])             
        if employee["privilege"]=="manager":#是设备主人   
            _grps = db.query("""SELECT *,GroupHasDevice.created_at AS received_at,GroupHasDevice.id AS ghdId
                                        FROM GroupHasDevice,DeviceGroup
                                        WHERE GroupHasDevice.imei='{0}' AND
                                          GroupHasDevice.devicegroup_id = DeviceGroup.id AND
                                          DeviceGroup.type ='视图分组'""".format(imei))

            for grp in _grps:
                _user = db.query("SELECT * FROM Customer WHERE openid='{0}'".format(grp.Customer_openid))
                for user in _user:
                    items.append({
                        "nickname"   :user.nickname,
                        "received_at":grp.received_at.strftime("%Y-%m-%d %H:%M:%S"),
                        "ghdId"      :grp.ghdId, 
                        "openid"     :grp.Customer_openid,
                        "privilege"  :grp.privilege
                    })
        _dev = db.query("SELECT * FROM Device WHERE imei='{0}'".format(imei))
        cfgPara={"openid" :openid,
             "items"  :items,
             "imei"   :imei,
             "devName":_dev[0].name
        }
        if  web.ctx.method=='GET':
            jdkSign = objWeixin.get_jdk_sign(self.env["url"])
            sharePara=tradeObj.genPreSharePara("share-view",openid,imei)
            _cfgPara =json.dumps(cfgPara,ensure_ascii=False)
            ret = self.render.friend_manager(_cfgPara,jdkSign,sharePara)
        else:
            ret =uTools.formatPostMsg(cfgPara)
        return ret
Esempio n. 19
0
 def getSeatsByImeiAuto(self, roleType,openid,data):
     if data.has_key("imei"):
         imei = data.imei
     else:
         imei = devdb.getDemoDeviceImei() #演示大巴
     #判定该用户对imei的可视权限--暂缺
     if data.has_key("his_datetime") or roleType=="operator-history":
         if data.has_key("his_datetime"):
             his_datetime = data.his_datetime  
         else:
             his_datetime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
             seatStatus= busdb.getSeatStatus(imei,his_datetime)  
     else:
         seatStatus  = busdb.getSeatStatus(imei)
         
     cfgPara=seatStatus["param"]
     
     _typeMap = {"region":"区间检测","timer":"定时分析","timely":"及时数据"}
     if seatStatus["region"]!=None:
         _type="region"
     elif seatStatus["timer"]!=None:
          _type="timer"
     else:
         _type="timely"
     
     cfgPara["srcType"] =_typeMap[_type]
     for key in seatStatus[_type]:
         cfgPara[key] = seatStatus[_type][key]
     
     
     dev      = devdb.getDeviceByImei(imei,format="string")
     company  = linedb.getCompanyByImei(imei)
     
     cfgPara["name"]        =dev["name"]
     cfgPara["dev"]         =dev
     cfgPara["company_id"]  =company["id"]
     cfgPara["heartbeat_at"]=dev["heardbeat_at"]
     cfgPara["openid"]      =openid
     #修正统计座位数
     seat_num = 0
     for seat in dev["seat_template"].split(";"):
         if seat.split(",")[0]!="":
             seat_num+=1
     cfgPara["seat_num"] = seat_num
     cfgPara["sum"]["空座"] = seat_num -cfgPara["sum"]["有人"]
     
     
     cfgPara["openid"]      =openid        
     if  web.ctx.method=='POST':
         ret =uTools.formatPostMsg(cfgPara)
     else:
         if dev["seat_template"]==None or dev["seat_template"]=="":
             ret = web.seeother('/device?act=bus-config&imei={0}&openid={1}'.format(imei,openid))
         else:
             jdksign = objWeixin.get_jdk_sign(self.env["url"])
             sharePara=tradeObj.genPreSharePara("share-view",openid,cfgPara["dev"]['imei'])
             
             sharePara["seat_template"] = self.seat_template(dev["seat_template"])
             sharePara["blank_color"]="#C0C0C0"
             sharePara["manager"] = linedb.getManageEmployee(openid)
             sharePara["company_id"]  =company["id"]
             cfgPara = json.dumps(cfgPara,ensure_ascii=False)
             if roleType=="operator":
                 ret = self.render.seat_status_auto(cfgPara,jdksign,sharePara)
             elif roleType=="operator-history":
                 ret = self.render.seat_status_his(cfgPara,jdksign,sharePara)
             else:
                     
                 if dev["seat_type"]=="bed":
                     ret = self.render.bed_status_auto(cfgPara,jdksign,sharePara)
                 elif  dev["seat_type"]=="midbus":
                     ret = self.render.seat_midbus_status_auto(cfgPara,jdksign,sharePara)
                 elif  dev["seat_type"]=="seat53":
                     if imei=='681501000179443':
                         print("sharePara----sharePara")
                         print(sharePara)
                     ret = self.render.seat53_status_auto(cfgPara,jdksign,sharePara)
                 elif  dev["seat_type"]=="seat39":
                     ret = self.render.seat39_status_auto(cfgPara,jdksign,sharePara)
                 else:
                     ret = web.seeother('/device?act=bus-config&imei={0}&openid={1}'.format(imei,openid))
     return ret