Exemple #1
0
    def post(self):
        opt = self.get_argument("opt")
        substid = self.get_argument('substid')
        mapnum1 = int(self.get_argument('mapnum1'))
        mapnum2 = int(self.get_argument('mapnum2'))
        distance = self.get_argument('distance', 100)

        fields = ['mapid', 'mapnum', 'NearMapIDs']

        sql = "select {}".format(','.join(fields))
        sql += " from {} where substid='{}' and mapnum={}"

        map1 = mysql_util.m_query_one(sql.format(T_MAPINFO,substid,mapnum1), fields)
        map2 = mysql_util.m_query_one(sql.format(T_MAPINFO,substid,mapnum2), fields)

        NearMapIDs1 = map1.get('NearMapIDs')
        NearMapIDs2 = map2.get('NearMapIDs')

        NearMapDistance1 = map1.get('NearMapDistance') or {}
        NearMapDistance2 = map2.get('NearMapDistance') or {}

        if NearMapIDs1:
            NearMapIDs1 = json.loads(NearMapIDs1)
        else:
            NearMapIDs1 = []

        NearMapIDs1 = set(NearMapIDs1)

        if NearMapIDs2:
            NearMapIDs2 = json.loads(NearMapIDs2)
        else:
            NearMapIDs2 = []

        NearMapIDs2 = set(NearMapIDs2)

        if opt == 'add':
            NearMapIDs1.add(mapnum2)
            NearMapDistance1[mapnum2] = distance

            NearMapIDs2.add(mapnum1)
            NearMapDistance2[mapnum1] = distance
        elif opt == 'del':
            if mapnum2 in NearMapIDs1:
                NearMapIDs1.remove(mapnum2)
            if mapnum1 in NearMapIDs2:
                NearMapIDs2.remove(mapnum1)

        NearMapIDs1 = list(NearMapIDs1)
        NearMapIDs2 = list(NearMapIDs2)

        sql = "update {} set NearMapIDs='{}',NearMapDistance='{}' where mapid='{}'".format(T_MAPINFO, json.dumps(NearMapIDs1), json.dumps(NearMapDistance1), map1.get('mapid'))
        print sql
        mysql_util.m_execute(sql)

        sql = "update {} set NearMapIDs='{}',NearMapDistance='{}' where mapid='{}'".format(T_MAPINFO, json.dumps(NearMapIDs2), json.dumps(NearMapDistance2), map2.get('mapid'))
        print sql
        mysql_util.m_execute(sql)
Exemple #2
0
def get_scheme_one(substid, schemenum):
    fields = ['SchemeID', 'SchemeNum', 'SchemePro', 'SchemeCycle', 'CycleUnit', 'PointNum', 'SchemeUsed']
    sql = "select {} from {} where substid='{}' and schemenum={}"

    data = mysql_util.m_query_one(sql.format(','.join(fields), 'Scheme', substid, schemenum), fields)

    return data
Exemple #3
0
def get_plan_one(substid, plannum):
    fields = ['PlanID', 'PlanNum', 'SchemeNum', 'PlanPro', 'PlanStartTime', 'PlanEndTime', 'PlanUsed']

    sql = "select {} from {} where substid='{}' and plannum={}"

    data = mysql_util.m_query_one(sql.format(','.join(fields), 'Plan', substid, plannum), fields)

    return data
Exemple #4
0
def get_map_info_one(substid, mapnum):
    fields_s = ['mapid', 'mapnum', 'mapx', 'mapy', 'phyid', 'name', 'used', 'NearMapIDs']

    sql = "select {}".format(','.join(fields_s))
    sql += " from {} where substid = '{}' and mapnum={}"

    data = mysql_util.m_query_one(sql.format(T_MAPINFO, substid, mapnum), fields_s)

    return data
Exemple #5
0
def get_eq_info_one(substid, eqnum):
    fields_s = ['eqid', 'eqnum', 'eqareaid', 'eqtype', 'eq618id', 'name', 'eqattribute', 'note', 'used', 'substid', 'name']
    fields_d = ['eqid', 'eqnum', 'eqareaid', 'eqtype', 'eq618id', 'name', 'eqattribute', 'note', 'used', 'substid', 'subst_name']

    sql = "select t1.{},t1.{},t1.{},t1.{},t1.{},t1.{},t1.{},t1.{},t1.{},t2.{},t2.{}".format(*fields_s)
    sql += " from {} t1, {} t2 where t1.substid = t2.substid and t1.substid='{}' and t1.eqnum={}"

    data = mysql_util.m_query_one(sql.format(T_MEASURINGDEVICE, T_SUBST_INFO,substid, eqnum), fields_d)

    return data
Exemple #6
0
def get_map_info(mapid=None):
    fields = ['mapid', 'name', 'substid', 'mapnum']
    if not mapid:
        sql = "select {} from {}".format(','.join(fields),T_MAPINFO)
        data,p = mysql_util.m_query(sql, fields,findall=True)
    else:
        sql = "select {} from {} where mapid='{}'".format(','.join(fields),T_MAPINFO,mapid)
        data = mysql_util.m_query_one(sql, fields)

    return data
Exemple #7
0
            def get_body(fs, f, fields_name):
                fields = ['task_id', 'czjg'] + fs
                sql = "select {}".format(','.join(fields))
                sql += " from {} where task_id='{}'"

                data = mysql_util.m_query_one(sql.format('JQR_GC_04F{}'.format(f),task_id), fields)
                if data.get('czjg'):
                    body = ''
                    for n, fields_n in enumerate(fields_name):
                        body += '{}: {},'.format(fields_n, data.get(fs[n]) or '')

                    return [f, body]
Exemple #8
0
def get_subst_info(uid = None, substid = None):
    fields = ['substid', 'name', 'fid', 'location_name', 'location_lat', 'location_lng']
    if not substid:
        sql = "select {} from {}"
        if uid:
            substid = mongo_util.m_find_one(T_PASSPORT,_id=ObjectId(uid)).get('substid') or ['']
            substid = ["'" + item + "'" for item in substid]
            sql += " where substid IN ({})".format(','.join(substid))
        data,p = mysql_util.m_query(sql.format(','.join(fields), T_SUBST_INFO), fields, findall=True)
    else:
        sql = "select {} from {} where substid='{}'"
        data = mysql_util.m_query_one(sql.format(','.join(fields), T_SUBST_INFO, substid), fields)

    return data
Exemple #9
0
    def get(self):
        substid = self.get_argument('substid', None)
        data = {}
        users = []

        if substid:
            fields_s = ['substid', 'areaid', 'name', 'location_name', 'location_lat', 'location_lng']
            sql = "select {}".format(','.join(fields_s))
            sql += " from {} where substid='{}'"
            data = mysql_util.m_query_one(sql.format(T_SUBST_INFO, substid), fields_s)

            users,t = mongo_util.m_list(T_PASSPORT,substid = substid,findall = True,fields={'_id': 1, 'loginname': 1})

        self.render("manageSubst_add.html", data = data, users=users)
Exemple #10
0
    def get(self):
        fn = int(self.get_argument('fn'))
        euaddr = self.get_argument('euaddr')

        table = "Params_F{}".format(fn)
        columns = PARAMS_SETTINGS_MAP.get(fn)
        fields = [item.get('column') for item in columns]

        eu = mysql_util.m_query_one("select {} from {} where euaddr='{}'".format(','.join(fields), table, euaddr),fields)

        for ps in PARAMS_SETTINGS:
            if ps[1] == fn:
                data = copy.deepcopy(ps[2])
                for d in data:
                    d.pop('type', None)
                break
        self.write(dict(data = data, eu = eu))
Exemple #11
0
def get_measuring_point_one(substid, pointnum):
    fields = ['pointid', 'pointnum', 'patroltype', 'eqid','name']
    sql = "select {} from {} where substid='{}' and pointnum={}"
    data = mysql_util.m_query_one(sql.format(','.join(fields), T_MEASURING_POINT_INFO, substid, pointnum), fields)

    return data
Exemple #12
0
    def post(self):
        fn = self.get_argument('fn')
        euaddr = self.get_argument('euaddr')
        euaddrs = euaddr.split(',')

        PACK_BODY_SERVICE_CODE = "200101"
        PACK_BODY_TASK_ID = FUNC_PACK_BODY_TASK_ID()
        PACK_BODY_APP_DATA = "{},|".format(fn)
        PACK_BODY = '|'.join([PACK_BODY_SERVICE_CODE, PACK_BODY_TASK_ID, PACK_BODY_ACK_TAG, PACK_BODY_PROC_NUMBER,PACK_BODY_APP_DATA])
        PACK = "".join([PACK_START, "%08d" % len(PACK_BODY), PACK_BODY_START, PACK_BODY, PACK_CRC, PACK_END])

        fn = fn.split(',')

        # JQR_PARAM_FLAG
        # EuAddr nvarchar(16),                    #虚拟终端地址
        # UID nvarchar(24),                      #操作人编号
        # ADDON nvarchar(50),                    #修改日期
        # NOTE nvarchar(200),                    #备注
        # F_FLAG int(4),>->--->--->--->--->--->---#F参数下发标志
        # F1_FLAG int(4),>>--->--->--->--->--->---#F1参数下发标志

        for euaddr in euaddrs:
            if not mysql_util.m_count("select euaddr from JQR_PARAM_FLAG where euaddr='{}'".format(euaddr)):
                mysql_util.m_execute("insert JQR_PARAM_FLAG(euaddr) values ('{}')".format(euaddr))
            for f in fn:
                if not mysql_util.m_count("select euaddr from JQR_GC_04F{} where euaddr='{}'".format(f, euaddr)):
                    mysql_util.m_execute("insert JQR_GC_04F{}(euaddr) values ('{}')".format(f, euaddr))

                param_flag = dict(EuAddr = euaddr, UID = self.uid, ADDON = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), F_FLAG = "1")
                param_flag['F{}_FLAG'.format(f)] = "1"

                values = ','.join([k+"='"+v+"'" for k, v in param_flag.items()])
                sql = "update JQR_PARAM_FLAG set {} where euaddr='{}'".format(values, euaddr)
                print sql
                mysql_util.m_execute(sql)



                #args = dict(TASK_ID = PACK_BODY_TASK_ID,uid = self.uid, EuAddr = euaddr,
                #    addon = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))

                args = dict(uid = self.uid, EuAddr = euaddr,
                    addon = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))

                #获取参数
                columns = PARAMS_SETTINGS_MAP.get(int(f))
                fields = [item.get('column') for item in columns]
                if not fields: continue
                eu = mysql_util.m_query_one("select {} from {} where euaddr={}".format(','.join(fields),"Params_F{}".format(f),euaddr),fields)

                if f=='3':
                    fields = ['mapid', 'mapnum', 'substid', 'mapx', 'mapy', 'phyid', 'name', 'used','NearMapIDs','NearMapDistance']
                    mapids = eu.get('mapids','').split(',')
                    mysql_util.m_execute("delete from JQR_GC_04F{} where euaddr={}".format(f,euaddr))
                    for mapid in mapids:
                        mapinfo=mysql_util.m_query_one("select {} from {} where mapid='{}'".format(','.join(fields),T_MAPINFO,mapid),fields)

                        NearMapIDs = json.loads(mapinfo.get('NearMapIDs') or '[]')
                        NearMapDistance = json.loads(mapinfo.get('NearMapDistance') or '{}')
                        NearMapIDs = [str(item)+","+NearMapDistance.get(str(item), '200') for item in NearMapIDs]

                        args.update(mapnum=mapinfo.get('mapnum'),phyid=mapinfo.get('phyid'),mapused=mapinfo.get('used'),
                                    NearMapIDs=','.join(NearMapIDs)+",",NearMapCount=len(NearMapIDs), MSA='MSA')
                        values = ','.join(["'" + str(item) + "'" if isinstance(item,(str,unicode)) else str(item) for item in args.values()])
                        sql = "insert into JQR_GC_04F{}({}) values ({})".format(f, ','.join(args.keys()), values)

                        #values = ','.join([k+"='"+str(v)+"'" for k, v in args.items()])
                        #sql = "update JQR_GC_04F{} set {} where euaddr='{}'".format(f, values, euaddr)
                        print sql
                        mysql_util.m_execute(sql)
                elif f in ['4','5']:
                    fields = ['pointid', 'pointnum', 'PAttribute', 'mapid', 'mapnum', 'eqid', 'dataid', 'name', 'used', 'RigPrePoint','LefPrePoint']
                    pointids = eu.get('pointids','').split(',')
                    mysql_util.m_execute("delete from JQR_GC_04F{} where euaddr={}".format(f,euaddr))
                    for pointid in pointids:
                        sql = "select t.{},t.{},t.{},t1.{},t1.{},t.{},t.{},t.{},t.{},t.{},t.{}".format(*fields)
                        sql += " from {} t, {} t1 where pointid='{}' and t.mapid=t1.mapid".format(T_MEASURING_POINT_INFO, T_MAPINFO,pointid)
                        print sql
                        info=mysql_util.m_query_one(sql,fields)
                        if f=='4':
                            args.update(pointnum=info.get('pointnum'),mapnum=info.get('mapnum'),eqid=info.get('eqid'),dataid=info.get('dataid'), pointused=info.get('used'),RigPrePoint=info.get('RigPrePoint'),LefPrePoint=info.get('LefPrePoint'), MSA='MSA')
                        elif f=='5':
                            args.update(pointnum=info.get('pointnum'),pointused=info.get('used'),MSA='MSA')
                        values = ','.join(["'" + str(item) + "'" if isinstance(item,(str,unicode)) else str(item) for item in args.values()])
                        sql = "insert into JQR_GC_04F{}({}) values ({})".format(f, ','.join(args.keys()), values)
                        #values = ','.join([k+"='"+str(v)+"'" for k, v in args.items()])
                        #sql = "update JQR_GC_04F{} set {} where euaddr='{}'".format(f, values, euaddr)
                        print sql
                        mysql_util.m_execute(sql)
                elif f in ['8']:
                    SchemeIDS = eu.get('SchemeIDS').split(',')
                    mysql_util.m_execute("delete from JQR_GC_04F{} where euaddr={}".format(f,euaddr))
                    mysql_util.m_execute("delete from JQR_GC_04F{}_MEAPIONT_PARAM where euaddr={}".format(f,euaddr))
                    for SchemeID in SchemeIDS:
                        fields = ['SchemeID', 'SchemeNum', 'SchemePro', 'SchemeCycle', 'CycleUnit', 'PointNum', 'SchemeUsed']
                        Scheme = mysql_util.m_query_one("select {} from {} where SchemeID='{}'".format(','.join(fields),'Scheme',SchemeID),fields)
                        args1 = copy.copy(args)
                        args1.update(SchemeUsed=Scheme.get('SchemeUsed'),SchemeNum=Scheme.get('SchemeNum'),SchemePro=Scheme.get('SchemePro'),SchemeCycle=Scheme.get('SchemeCycle'),MSA='MSA')

                        values=','.join(["'" + str(item) + "'" if isinstance(item,(str,unicode)) else str(item) for item in args1.values()])
                        sql = "insert into JQR_GC_04F{}({}) values ({})".format(f, ','.join(args1.keys()), values)
                        print sql
                        mysql_util.m_execute(sql)

                        args2 = copy.copy(args)
                        args2.pop('uid', None)
                        args2.pop('addon', None)
                        PointNums = Scheme.get('PointNum').split(',')
                        for PointNum in PointNums:
                            args2.update(SchemeNum = Scheme.get('SchemeNum'), PointNum = PointNum)
                            values=','.join(["'" + str(item) + "'" if isinstance(item,(str,unicode)) else str(item) for item in args2.values()])
                            sql = "insert into JQR_GC_04F{}_MEAPIONT_PARAM({}) values ({})".format(f, ','.join(args2.keys()), values)
                            print sql
                            mysql_util.m_execute(sql)

                elif f in ['9']:
                    PlanIDS = eu.get('PlanIDS').split(',')
                    mysql_util.m_execute("delete from JQR_GC_04F{} where euaddr={}".format(f,euaddr))
                    mysql_util.m_execute("delete from JQR_GC_04F{}_SCHEME_PARAM where euaddr={}".format(f,euaddr))
                    for PlanID in PlanIDS:
                        fields = ['PlanID', 'PlanNum', 'SchemeNum', 'PlanPro', 'PlanStartTime', 'PlanEndTime', 'PlanUsed']
                        Plan = mysql_util.m_query_one("select {} from {} where PlanID='{}'".format(','.join(fields),'Plan',PlanID),fields)

                        args1 = copy.copy(args)
                        args1.update(PlanUsed=Plan.get('PlanUsed'),PlanNum=Plan.get('PlanNum'),PlanPro=Plan.get('PlanPro'),PlanStartTime=Plan.get('PlanStartTime'),PlanEndTime=Plan.get('PlanEndTime'),MSA='MSA')

                        values=','.join(["'" + str(item) + "'" if isinstance(item,(str,unicode)) else str(item) for item in args1.values()])
                        sql = "insert into JQR_GC_04F{}({}) values ({})".format(f, ','.join(args1.keys()), values)
                        print sql
                        mysql_util.m_execute(sql)

                        args2 = copy.copy(args)
                        args2.pop('uid', None)
                        args2.pop('addon', None)
                        SchemeNums=Plan.get('SchemeNum').split(',')
                        for SchemeNum in SchemeNums:
                            args2.update(PlanNum = Plan.get('PlanNum'), SchemeNum = SchemeNum)
                            values=','.join(["'" + str(item) + "'" if isinstance(item,(str,unicode)) else str(item) for item in args2.values()])
                            sql = "insert into JQR_GC_04F{}_SCHEME_PARAM({}) values ({})".format(f, ','.join(args2.keys()), values)
                            print sql
                            mysql_util.m_execute(sql)
                else:
                    args.update(eu)
                    #values = ','.join(["'" + str(item) + "'" if isinstance(item,(str,unicode)) else str(item) for item in args.values()])
                    #sql = "insert into JQR_GC_04F{}({}) values ({})".format(f, ','.join(args.keys()), values)

                    values = ','.join([k+"='"+str(v)+"'" for k, v in args.items()])
                    sql = "update JQR_GC_04F{} set {} where euaddr='{}'".format(f, values, euaddr)
                    print sql
                    mysql_util.m_execute(sql)

        #print PACK
        #redis_cluster = get_context().get_redis_cluster()
        #redis_cluster.rpush('1_d_001', PACK)

        self.write(dict(status = True))