コード例 #1
0
ファイル: seat.py プロジェクト: waterbocai/gps-track
 def getMsgReceiver(self, openid, data):
     imei = data.imei
     company = linedb.getCompanyByImei(imei)
     employee = linedb.getEmployeeByid4pc(company["id"], with_manager=True)
     rows = []
     for _type in employee:
         group = ("赛微" if _type == "saiwei" else "客户")
         for row in employee[_type]:
             row["group"] = group
             rows.append(row)
     cfgPara = {"total": len(row), "rows": rows}
     return uTools.formatPostMsg(cfgPara)
コード例 #2
0
ファイル: tradeorder.py プロジェクト: waterbocai/gps-track
    def procShareViewEvent2(self,trade_order_id,openid,msg):
        #获取交易信息
        _ret = icfg.db.query("SELECT * FROM  TradeOrder WHERE id={0}".format(trade_order_id))
        order = _ret[0]
        
        devLinks =[] #记录被分享的名字,含链接 
         
        #修改每一个imei的管理分组
        i = 0;
        trade = json.loads(order.trade) 
        for imei in trade["imeis"]:
            #获取该imei所属的公司
            company =linedb.getCompanyByImei(imei)
            company_id = company["id"] 
            #确认该用户是否已经在公司名下
            employee =linedb.getCompanyEmployeeByOpenid
            devLinks.append("{0}/m/bustrack?act=MINE_TRACK&imei={1}&company_id={2}".format(web.ctx.homedomain,imei,company_id)) 
            if employee!=None:#已经分享到了该用户
                icfg.db.update("CompanyHasEmployee",where="company_id=$company_id",vars=locals(),privilege="visible")
                continue
            else:
                #成为员工,权限为visible
                icfg.db.insert("CompanyHasEmployee",company_id=company_id,openid=openid,privilege="visible")      
        
        systemMsg = icfg.objWeixin.iconfig.systemMsg
        systemMsg["data"]["keyword2"]["value"] =datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        systemMsg["data"]["remark"]["value"]="点击查看设备信息"
        systemMsg["touser"] = openid
        
        if i==0:
            systemMsg["url"]=devLinks[0]+"&openid="+openid
            systemMsg["data"]["first"]["value"]   ="设备分享成功提醒"
            systemMsg["data"]["keyword1"]["value"]="重复处理"
            icfg.objWeixin.send_template_msg(systemMsg)
        else:
            #通知接受方用户
            user  = icfg.objWeixin.get_user_info(order.openid)
            systemMsg["url"]=devLinks[0]+"&openid="+openid
            systemMsg["data"]["first"]["value"]="设备分享成功提醒"
            systemMsg["data"]["keyword1"]["value"]="设备分享成功"
            systemMsg["data"]["remark"]["value"]="""分享朋友: {0}
点击查看详情""".format(user['nickname'])
            icfg.objWeixin.send_template_msg(systemMsg)
            
            #通知分享主人
            systemMsg["url"]=devLinks[0]+"&openid="+order.openid
            receiver  = icfg.objWeixin.get_user_info(msg.fromUser)
            systemMsg["data"]["remark"]["value"]="""接收朋友: {0}
点击查看详细""".format(receiver['nickname'])
            systemMsg["touser"] = order.openid
            icfg.objWeixin.send_template_msg(systemMsg)
        return msg.reply_text("留意系统消息")
コード例 #3
0
ファイル: busline.py プロジェクト: waterbocai/gps-track
    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
コード例 #4
0
ファイル: busline.py プロジェクト: waterbocai/gps-track
    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
コード例 #5
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
コード例 #6
0
ファイル: security.py プロジェクト: waterbocai/gps-track
    def assumeNotifyExceptMsg(self, dev, pos, event, eventMsg):
        company = linedb.getCompanyByImei(dev.imei)
        if company == None:  #还没有录入到公司,返回None
            return None
        busline = linedb.getBuslineByImei(dev.imei)
        exceptMsg = objWeixin.iconfig.exceptMsg
        exceptMsg["data"]["first"]["value"] = company["company"] + " 设备异常提醒"
        exceptMsg["data"]["keyword1"]["value"] = "线路-" + busline[
            "from_name"] + "<->" + busline["to_name"]
        exceptMsg["data"]["keyword2"]["value"] = "{0}({1})".format(
            dev.name, dev.imei)
        exceptMsg["data"]["keyword3"]["value"] = "\r\n".join(event)
        exceptMsg["data"]["keyword4"]["value"] = datetime.datetime.now(
        ).strftime("%Y-%m-%d %H:%M:%S")
        exceptMsg["data"]["remark"]["value"] = """异常描述:
{0}

最后检测到的情况:
-时间: {1}
-速度:{3}公里/小时
-位置:{2}
""".format(eventMsg, pos.gpsTime.strftime("%m-%d %H:%M:%S"), pos.addr,
           pos.speed)
        return exceptMsg
コード例 #7
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   
コード例 #8
0
ファイル: tradeorder.py プロジェクト: waterbocai/gps-track
    def procShareViewEvent(self,trade_order_id,openid,msg):
        #获取交易信息
        _ret = icfg.db.query("SELECT * FROM  TradeOrder WHERE id={0}".format(trade_order_id))
        order = _ret[0]
        
        devLinks =[] #记录被分享的名字,含链接 
         
        #修改每一个imei的管理分组
        i = 0;
        trade = json.loads(order.trade) 
        for imei in trade["imeis"]:
            #确认该设备是否已经被分享给了该用户
            _dev = icfg.db.query("""SELECT *,GroupHasDevice.id AS ghdId FROM GroupHasDevice,DeviceGroup
                                        WHERE GroupHasDevice.imei = '{0}' AND 
                                              GroupHasDevice.devicegroup_id =DeviceGroup.id AND 
                                              DeviceGroup.type ='视图分组' AND
                                              DeviceGroup.Customer_openid ='{1}'
                                              """.format(imei,openid))
            company =linedb.getCompanyByImei(imei)
            company_id = company["id"] 
            devLinks.append("{0}/m/bustrack?act=MINE_TRACK&imei={1}&company_id={2}".format(web.ctx.homedomain,imei,company_id))      
            if len(_dev)>0:#已经分享到了该用户,不要再处理
                dev =_dev[0]
                #ghdId =dev.ghdId
                #把可视权限开启
                icfg.db.update("GroupHasDevice",where="id=$dev.ghdId",vars=locals(),privilege="visible")
                continue
            else:
                #选定目标用户视图分组,缺省id最小的组
                _ret = icfg.db.query("""SELECT * FROM DeviceGroup 
                                WHERE Customer_openid='{0}' AND type='视图分组' 
                                ORDER BY id""".format(openid))
                if len(_ret)==0:#从来没有分组,自动创建一个分组
                    grpId = icfg.db.insert("DeviceGroup", type="视图分组",name="分享来的",
                                        Customer_openid=openid,
                                        created_at=datetime.datetime.now())
                else:
                    grpId = _ret[0].id
                icfg.db.insert("GroupHasDevice",imei=imei,devicegroup_id=grpId,
                                           privilege="visible",created_at=datetime.datetime.now())
                _ret = icfg.db.query("SELECT * FROM Device WHERE imei='{0}'".format(imei))
                dev = _ret[0]
                i+=1
                
        
        systemMsg = icfg.objWeixin.iconfig.systemMsg
        systemMsg["data"]["keyword2"]["value"] =datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        systemMsg["data"]["remark"]["value"]="点击查看设备信息"
        systemMsg["touser"] = openid
        
        if i==0:
            systemMsg["url"]=devLinks[0]+"&openid="+openid
            systemMsg["data"]["first"]["value"]   ="设备分享成功提醒"
            systemMsg["data"]["keyword1"]["value"]="重复处理"
            icfg.objWeixin.send_template_msg(systemMsg)
        else:
            #通知接受方用户
            user  = icfg.objWeixin.get_user_info(order.openid)
            systemMsg["url"]=devLinks[0]+"&openid="+openid
            systemMsg["data"]["first"]["value"]="设备分享成功提醒"
            systemMsg["data"]["keyword1"]["value"]="设备分享成功"
            systemMsg["data"]["remark"]["value"]="""分享朋友: {0}
点击查看详情""".format(user['nickname'])
            icfg.objWeixin.send_template_msg(systemMsg)
            
            #通知分享主人
            systemMsg["url"]=devLinks[0]+"&openid="+order.openid
            receiver  = icfg.objWeixin.get_user_info(msg.fromUser)
            systemMsg["data"]["remark"]["value"]="""接收朋友: {0}
点击查看详细""".format(receiver['nickname'])
            systemMsg["touser"] = order.openid
            icfg.objWeixin.send_template_msg(systemMsg)
        return msg.reply_text("留意系统消息")