예제 #1
0
 def updateLinePrice(self, openid, data):
     busline_id = data.busline_id
     price = data.price
     site_ids = data.site_id.split("-")
     from_site_id = int(site_ids[0])
     to_site_id = int(site_ids[1])
     _ret = db.query("""SELECT * FROM LinePrice 
                                          WHERE BusLine_id={0} AND 
                                                from_site_id={1} AND 
                                                to_site_id  ={2} """.format(
         busline_id, from_site_id, to_site_id))
     if len(_ret) == 1:
         db.update("LinePrice",
                   where="id=$_ret[0].id",
                   price=price,
                   vars=locals())
     else:
         db.insert("LinePrice",
                   price=price,
                   BusLine_id=busline_id,
                   from_site_id=from_site_id,
                   to_site_id=to_site_id)
     cfgPara = uTools.formatPostMsg({
         "result": "success",
         "msg": "lineprice update succeed!"
     })
     return cfgPara
예제 #2
0
 def cfgBusSeat(self,openid,data):
     imei = data.imei
     
     db.update("Device",where="imei=$imei",vars=locals(),seat_type=data.seat_type,
                               seat_template=data.seat_template)
     ret =uTools.formatPostMsg({"result":"success"})
     return ret
예제 #3
0
    def updateLineSite(self, openid, data):
        busline_id = int(data.busline_id)
        name_change = data.name_change.split(";")
        end_change = data.end_change.split(";")
        #名称修改

        for site_name in name_change:
            if site_name == "":
                continue
            site_id, name = site_name.split(":")
            site_id = int(site_id)
            db.update("Sites", where="id=$site_id", name=name, vars=locals())
        #序号变更
        for endchange in end_change:
            if endchange == "":
                continue
            seq, is_end = endchange.split(":")
            seq = int(seq)
            db.update("LineSites",
                      where="busline_id=$busline_id AND seq=$seq",
                      is_end=is_end,
                      vars=locals())

        sites = linedb.getSitesByLineid(busline_id)
        cfgPara = uTools.formatPostMsg({
            "result": "success",
            "msg": "busline config succeed!",
            "sites": sites
        })
        return cfgPara
예제 #4
0
    def setLineName(self, openid, data):
        busline_id = int(data.busline_id)
        company_id = int(data.company_id)
        if busline_id == -1:  #新线路
            busgroupid = db.insert("DeviceGroup",
                                   belong_to="company",
                                   type="管理分组",
                                   created_at=datetime.datetime.now(),
                                   Customer_openid=openid,
                                   description="gxsaiwei",
                                   name='dengchewang')

            busline_id = db.insert("BusLine",
                                   from_name=data.src,
                                   to_name=data.dst,
                                   busgroupid=busgroupid,
                                   created_at=datetime.datetime.now(),
                                   company_id=company_id)
        else:
            db.update("BusLine",
                      where="id=$data.busline_id",
                      vars=locals(),
                      from_name=data.src,
                      to_name=data.dst,
                      created_at=datetime.datetime.now(),
                      company_id=company_id)
        buslines = linedb.getBusLineByOpenid4pc(openid, company_id)
        cfgPara = uTools.formatPostMsg({
            "result": "success",
            "buslines": buslines
        })
        return cfgPara
예제 #5
0
 def lost_seconds(self, imei):
     #设备信息
     _dev = db.query("SELECT * FROM Device WHERE imei='{0}'".format(imei))
     dev = _dev[0]
     #判定是否失联
     lost_alm_after_minutes = (15 if dev.lost_alm_after_minutes == 0 else
                               dev.lost_alm_after_minutes)
     lost_seconds = int(
         (datetime.datetime.now() - dev.heardbeat_at).total_seconds())
     #print("lost_seconds:{0}".format(lost_seconds))
     if lost_seconds > 7 * 24 * 60 * 60:
         lost_state = "long"
     elif lost_seconds > lost_alm_after_minutes * 60:
         lost_state = "short"
     else:
         lost_state = ""
         lost_seconds = 0
     _ret = db.query("SELECT * FROM Device WHERE imei='{0}'".format(imei))
     dev = _ret[0]
     if dev.lost_state == lost_state:  #状态没有变化
         db.update("Device",
                   where='imei=$imei',
                   vars=locals(),
                   report_needed=0)
     else:
         db.update("Device",
                   where='imei=$imei',
                   vars=locals(),
                   lost_state=lost_state,
                   report_needed=1)
     return lost_seconds
예제 #6
0
 def updateManagerDeviceGroup(self,openid,data):
     imei = data.imei
     _ret = db.query("SELECT * FROM BusLine WHERE id={0}".format(data.busline_id))
     busline =_ret[0]
     #更新分组信息
     self.changeDeviceGroup(openid,imei,busline.busgroupid)
     
     db.update("Device",where         = "imei=$imei",vars=locals(),
                        Distributor_id= 6, #何秋文的账号
                        name          = data.name,
                        phone         = data.phone,
                        arm_type      = (data.arm_type if data.has_key("arm_type") else "bus"))
     return imei
예제 #7
0
 def updateDeviceCfg(self,openid,data):
     imei = data.imei
     #更新服务期限
     if data.has_key("service_start") and devdb.isSuperManager(openid):
             db.update("Device",where     ="imei=$imei",vars=locals(),
                        name          = data.name,
                        phone         = data.phone,
                        service_start = data.service_start,
                        expired_at    = data.expired_at)
     else:
         db.update("Device",where     ="imei=$imei",vars=locals(),
                        name          = data.name,
                        phone         = data.phone)
     return imei
예제 #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
예제 #9
0
    def setLineSite(self, openid, data):
        busline_id = data.busline_id
        _ret = db.query(
            "SELECT MAX(seq)  AS max_seq FROM LineSites WHERE busline_id = {0}"
            .format(busline_id))
        max_seq = _ret[0].max_seq
        changeType = data.changeType
        #新加入的站点
        if changeType == "add-new":
            #依据微信上报信息获取位置信息
            _ret = db.query(
                "SELECT * FROM Customer WHERE openid='{0}'".format(openid))
            user = _ret[0]
            site_id = db.insert("Sites",
                                gpsLat=user.gpsLat,
                                gpsLng=user.gpsLng,
                                baiduLat=user.baiduLat,
                                baiduLng=user.baiduLng,
                                qqLat=user.qqLat,
                                qqLng=user.qqLng,
                                name=data.name,
                                address=user.address,
                                setting_type="manual")
            db.insert("LineSites",
                      site_id=site_id,
                      seq=max_seq + 1,
                      busline_id=busline_id)

        else:
            _ret = db.query(
                "SELECT * AS sum FROM LineSites WHERE busline_id = {0} AND seq={1}"
                .format(busline_id, data.old_seq))
            linesite = _ret[0]
            site_id = linesite.site_id
            db.update("Sites",
                      where="id=$site_id",
                      name=data.name,
                      vars=locals())
            db.update("LineSites",
                      where="id=$site_id",
                      vars=locals(),
                      seq=data.new_seq)
        linedb.orderLineSiteSeq(busline_id)
        sites = linedb.getSitesByLineid(busline_id)
        cfgPara = uTools.formatPostMsg({
            "result": "success",
            "msg": "busline config succeed!",
            "sites": sites
        })
        return cfgPara
예제 #10
0
 def updateSharePrivilege(self,openid,data):
     ghdId   = data.ghdId
     result = "fail"
     if data.has_key("ghd_act") and data.ghd_act == "delete":#删除操作,具有最高权限
         db.delete("GroupHasDevice",where="id=$ghdId",vars=locals())
         result = "success"
     else:
         if data.has_key("privilege") and  data.privilege in ["visible","invisible"]:
             db.update("GroupHasDevice",where="id=$ghdId",vars=locals(),privilege=data.privilege)
             result = "success"
         if data.has_key("no_help_theft") and  data.no_help_theft in [0,1]: 
             db.update("GroupHasDevice",where="id=$ghdId",vars=locals(),no_help_theft=data.no_help_theft)
             result = "success"
     ret = self.friendManager(openid,data.imei)
     return ret 
예제 #11
0
    def updateOneLineSite(self, openid, data):
        site_id = data.site_id
        name = (data.name if data.has_key("name") else None)
        setting_type = (data.setting_type
                        if data.has_key("setting_type") else None)
        if name != None and setting_type != None:
            if setting_type != "manual":
                setting_type = None

            db.update("Sites",
                      where="id=$site_id",
                      name=name,
                      setting_type=setting_type,
                      vars=locals())
        if name == None and setting_type != None:
            if setting_type != "manual":
                setting_type = None
            db.update("Sites",
                      where="id=$site_id",
                      setting_type=setting_type,
                      vars=locals())
        if name != None and setting_type == None:
            db.update("Sites", where="id=$site_id", name=name, vars=locals())
        cfgPara = uTools.formatPostMsg({
            "result": "success",
            "msg": "update site succeed!"
        })
        return cfgPara
예제 #12
0
 def updateSecurityItem(self, openid, data):
     imei = data.imei
     result = db.update("Device",
                        where="imei=$imei",
                        vars=locals(),
                        fireMinutes=data.fireMinutes,
                        fireDistance=data.fireDistance,
                        moveSpeaker=data.moveSpeaker,
                        poweroffSpeaker=data.poweroffSpeaker,
                        lost_alm_after_minutes=data.lost_alm_after_minutes)
     cfgPara = {"openid": openid, "result": "success"}
     ret = uTools.formatPostMsg(cfgPara)
     return ret
예제 #13
0
 def monitorSetup(self, openid, imei, state):
     #初始化返回值
     cfgPara = {"openid": openid}
     if self.openidOwnerImei(openid, imei) == False:
         cfgPara["result"] = "fails:owner is invalid"
     elif state in ["fired", "waiting0"]:  #满足条件,更新数据库
         db.update("Device",
                   where='imei=$imei',
                   vars=locals(),
                   stopTime="0000-00-00 00:00:00",
                   stopBaiduLat=0,
                   stopBaiduLng=0,
                   monitorState=state,
                   monitor_at="0000-00-00 00:00:00")
         #从数据库中重新读取,确认数据正确
         _ret = db.query(
             "SELECT * FROM Device WHERE imei='{0}'".format(imei))
         cfgPara["state"] = _ret[0].monitorState
         cfgPara["result"] = "success"
     else:  #不符合更新条件
         cfgPara["result"] = "fails:state is invalid-{0}".format(state)
     ret = uTools.formatPostMsg(cfgPara)
     return ret
예제 #14
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
예제 #15
0
 def changeDeviceGroup(self,openid,imei,groupid): 
     #更新设备的现有分组信息
     db.update("GroupHasDevice",where='imei = $imei',vars=locals(),
                            devicegroup_id=groupid,
                            created_at   =web.SQLLiteral('NOW()'))
     return
예제 #16
0
    def setLineSite2(self, openid, data):
        busline_id = data.busline_id
        _ret = db.query(
            "SELECT COUNT(*) AS sum FROM LineSites WHERE busline_id = {0}".
            format(busline_id))
        site_sum = _ret[0]
        #新加入的站点
        if (site_sum < data.old_seq):
            changeType = "add-new"  #缺省是增加新站点
        else:
            changeType = "renew-old"
            _ret = db.query(
                "SELECT * AS sum FROM LineSites WHERE busline_id = {0} AND seq={1}"
                .format(busline_id, data.old_seq))
            linesite = _ret[0]

        #调整现有站点顺序
        if (data.new_seq < data.old_seq):  #站点向前调整顺序
            changeSites = db.query(
                "SELECT * FROM LineSites WHERE seq>={0} AND seq<{1}".format(
                    data.new_seq, data.old_seq))
            for site in changeSites:
                db.update("LineSites",
                          where="id=$site.id",
                          seq=site.seq + 1,
                          vars=locals())
        else:
            changeSites = db.query(
                "SELECT * FROM LineSites WHERE seq>{0} AND seq<={1}".format(
                    data.old_seq, data.new_seq))
            for site in changeSites:
                db.update("LineSites",
                          where="id=$site.id",
                          seq=site.seq - 1,
                          vars=locals())

        if changeType == "add-new":
            #依据微信上报信息获取位置信息
            _ret = db.query(
                "SELECT * FROM Customer WHERE openid='{0}'".format(openid))
            user = _ret[0]
            site_id = db.insert("Sites",
                                gpsLat=user.gpsLat,
                                gpsLng=user.gpsLng,
                                baiduLat=user.baiduLat,
                                baiduLng=user.baiduLng,
                                qqLat=user.qqLat,
                                qqLng=user.qqLng,
                                name=data.name,
                                address=user.address,
                                setting_type="manual")
            db.insert("LineSites",
                      site_id=site_id,
                      seq=data.new_seq,
                      busline_id=busline_id)
        else:
            site_id = linesite.site_id
            db.update("Sites",
                      where="id=$site_id",
                      name=data.name,
                      vars=locals())
            db.update("LineSites", where="id=$linesite,id", seq=data.new_seq)
        sites = linedb.getSitesByLineid(busline_id)
        cfgPara = uTools.formatPostMsg({
            "result": "success",
            "msg": "busline config succeed!",
            "sites": sites
        })
        return cfgPara
예제 #17
0
 def autoSecurity(self, imei):
     _ret = db.query(
         "SELECT * FROM CurrentLocation WHERE imei ='{0}'".format(imei))
     pos = _ret[0]
     #获取设防条件
     _ret = db.query("SELECT * FROM Device WHERE imei='{0}'".format(imei))
     dev = _ret[0]
     if dev.monitorState in ['fired', 'going_out']:  #用户主动放弃监控
         return
     elif dev.monitorState == 'on':  #已经启动监控  :
         if pos.speed < 0.5:  #车辆处于静止状态,安全范围内,
             return
         else:  #车辆在移动中!需要进一步确认是否在安全距离内
             ret = self.bdmap.routematrix(
                 [[dev.stopBaiduLat, dev.stopBaiduLng]],
                 [[pos.baiduLat, pos.baiduLng]])
             movedDistance = int(ret[0]["distance"]["value"])  #移动距离
             #安全位置缺省为200米
             fireDistance = (200
                             if dev.fireDistance == 0 else dev.fireDistance)
             if movedDistance < fireDistance:  #在安全范围内,
                 return
             else:  #促发告警
                 db.update("Device",
                           where='imei=$imei',
                           vars=locals(),
                           monitorState="going_out")
     elif dev.monitorState == 'waiting0':  #等待监控
         if pos.speed > 0:  #车处于运行状态中
             return
             #不需要监控
         else:  #用户停车了,开始监控准备:设置开始时间以及停止位置 ,当停车时间超过设定值则会启动监控
             db.update("Device",
                       where='imei=$imei',
                       vars=locals(),
                       stopTime=datetime.datetime.now(),
                       stopBaiduLat=pos.baiduLat,
                       stopBaiduLng=pos.baiduLng,
                       monitorState="waiting1")
     elif dev.monitorState == 'waiting1':  #等待监控
         #已经完成第一次的静止检测,需要考虑是否需要促发告警还是继续等待
         if pos.speed < 0.5:  #车处于静止状态
             #达到了促发设防条件,促发时间缺省为15分钟
             fireMinutes = (15 if dev.fireMinutes == 0 else dev.fireMinutes)
             if (datetime.datetime.now() -
                     dev.stopTime).total_seconds() >= fireMinutes * 60:
                 db.update("Device",
                           where='imei=$imei',
                           vars=locals(),
                           monitorState="on",
                           monitor_at=datetime.datetime.now())
             else:  #没有达到监控条件,继续等待
                 return
         else:  #车处于运行状态中,没有达到监控条件,设防恢复为初始态
             db.update("Device",
                       where='imei=$imei',
                       vars=locals(),
                       stopTime="0000-00-00 00:00:00",
                       stopBaiduLat=0,
                       stopBaiduLng=0,
                       monitorState="waiting0")
     return