Exemple #1
0
    def department_put():
        """
        修改部门职位信息
        :return: json
        """
        request_form = request.get_json()
        result = Auth.identify(Auth, request)
        if (result['status'] and result['data']):
            # user = Users.get(Users, result['data'])
            Departments.update(Departments, request_form['id'], request_form)
            department = Departments.get(Departments, request_form['id'])
            try:
                ret_authority_map = ast.literal_eval(department.authority_map)
            except:
                ret_authority_map = {}[department.authority_map] = department.authority_map
            ret = {
                'id': department.id,
                'department': department.department,
                'job': department.job,
                'authority_map': ret_authority_map

            }
            result = common.trueReturn(ret, "修改成功")

        return jsonify(result)
Exemple #2
0
    def server_status_get():
        app.logger.info("server_status_get")
        app.logger.info("request: %s", request)
        app.logger.info("当前访问用户:%s", request.remote_addr)
        # app.logger.info("Authorization:", request.headers['Authorization'])

        result = Auth.identify(Auth, request)
        # app.logger.info(result)
        app.logger.info("状态: %s 用户: %s ", result.get('status'), result.get('data'))
        if (result['status'] and result['data']):
            pass
        else:
            # return json.dumps(result, ensure_ascii=False)
            pass
            #return jsonify(result)

        cpu_used = str(psutil.cpu_percent()) + "%" # psutil.cpu_percent(interval=1, percpu=True)

        # memory_used = str(float('%.2f' % ((psutil.virtual_memory().total - psutil.virtual_memory().free)/(1024*1024)))) + "MB"
        # memory_free = str(float('%.2f' % (psutil.virtual_memory().free / (1024 * 1024)))) + "MB"
        # memory_total = str(float('%.2f' % (psutil.virtual_memory().total / (1024 * 1024)))) + "MB"
        #
        # disk_used = str(float('%.2f' % (psutil.disk_usage("/").used / (1024 * 1024 * 1024)))) + "GB"
        # disk_free = str(float('%.2f' % (psutil.disk_usage("/").free / (1024 * 1024 * 1024)))) + "GB"
        # disk_total = str(float('%.2f' % (psutil.disk_usage("/").total / (1024 * 1024 * 1024)))) + "GB"

        memory_used = str(float('%.2f' % (psutil.virtual_memory().total - psutil.virtual_memory().free)))
        memory_free = str(float('%.2f' % (psutil.virtual_memory().free )))
        memory_total = str(float('%.2f' % (psutil.virtual_memory().total)))

        disk_used = str(float('%.2f' % (psutil.disk_usage("/").used )))
        disk_free = str(float('%.2f' % (psutil.disk_usage("/").free)))
        disk_total = str(float('%.2f' % (psutil.disk_usage("/").total)))

        download_before = psutil.net_io_counters().bytes_recv
        time.sleep(0.1)
        download_after = psutil.net_io_counters().bytes_recv
        #download = str(float('%.2f' % ((download_after - download_before) / 0.1 / 1024))) + "KB/s"
        download = str(float('%.2f' % ((download_after - download_before) / 0.1)))

        upload_before = psutil.net_io_counters().bytes_sent
        time.sleep(0.1)
        upload_after = psutil.net_io_counters().bytes_sent
        #upload = str(float('%.2f' % ((upload_after - upload_before) / 0.1 / 1024))) + "KB/s"
        upload = str(float('%.2f' % ((upload_after - upload_before) / 0.1)))

        ret = {"CPU": {"used": cpu_used},
               "Memory": {"used": memory_used,
                          "free": memory_free,
                          "total": memory_total},
               "Disk": {"used": disk_used,
                        "free": disk_free,
                        "total": disk_total},
               "Network": {"upload": upload,
                           "download": download,
                           "max_upload": str(20*1024*1024),
                           "max_download": str(100*1024*1024)}
               }

        return jsonify(common.trueReturn(ret, ""))
Exemple #3
0
 def login():
     """
     用户登录
     :return: json
     """
     request_form = request.get_json()
     username = request_form.get('username')
     password = request_form.get('password')
     if (not username or not password):
         return jsonify(common.falseReturn('', '用户名和密码不能为空'))
     else:
         return Auth.authenticate(Auth, username, password)
Exemple #4
0
 def department_delete():
     """
     删除部门职位信息
     :return: json
     """
     request_form = request.get_json()
     result = Auth.identify(Auth, request)
     if (result['status'] and result['data']):
         # user = Users.get(Users, result['data'])
         Departments.delete(Departments, request_form['id'])
         result = common.trueReturn("", "删除成功")
     return jsonify(result)
Exemple #5
0
    def put():
        """
        修改用户信息
        :return: json
        """
        request_form = request.get_json()
        print(1111111111)
        print(request_form)
        result = Auth.identify(Auth, request)
        print(22222222222222222)
        print(result)
        if (result['status'] and result['data']):
            #user = Users.get(Users, result['data'])

            if request_form.get("username"):
                isExist = Users.query.filter(and_(Users.username == request_form.get("username"), Users.id != request_form.get("id"))).count()
                if isExist > 0:
                    return jsonify(common.falseReturn('', '用户修改信息失败, 已经有该登陆名'))
            if request_form.get("truename"):
                isExist = Users.query.filter(and_(Users.truename == request_form.get("truename"), Users.id != request_form.get("id"))).count()
                if isExist > 0:
                    return jsonify(common.falseReturn('', '用户修改信息失败, 已经同名用户,推荐真实姓名后加数字进行标示'))

            Users.update(Users, request_form['id'], request_form)
            user, department = Users.get(Users, request_form['id'])
            try:
                ret_authority_map = ast.literal_eval(department.authority_map)
            except:
                ret_authority_map = {}[department.authority_map] = department.authority_map
            returnUser = {
                'id': user.id,
                'username': user.username,
                'truename': user.truename,
                'department_id': user.department_id,
                'department': department.department if department else "无填写",
                'job': department.job if department else "无填写",
                'authority_map': ret_authority_map,
                'contact_num': user.contact_num,
                'usertype': user.usertype,
                'working_city': user.working_city,
                'projects_index': user.projects_index,
                'login_time': user.login_time
            }
            result = common.trueReturn(returnUser, "修改成功")
        return jsonify(result)
Exemple #6
0
    def projectLists_progress():
        app.logger.info("projects_PUT_POST")
        app.logger.info("request: %s", request)
        app.logger.info("当前访问用户:%s", request.remote_addr)
        # app.logger.info("Authorization:", request.headers['Authorization'])

        result = Auth.identify(Auth, request)
        # app.logger.info(result)
        app.logger.info("状态: %s 用户: %s ", result.get('status'),
                        result.get('data'))
        if (result['status'] and result['data']):
            pass
        else:
            # return json.dumps(result, ensure_ascii=False)
            #return jsonify(result)
            pass

        if request.args.get("city"):
            db_name = CITY.get_db_name(request.args.get("city"))
        else:
            return jsonify(common.falseReturn("", "没有传city参数"))

        ret_array = []
        ret_map_values = ["待生产", "生产中", "已完成", "已出货", "已暂停"]

        # wait_for_producing_select_sql = ""

        # result = mysql.select_by_sql_with_long_time_cache(db_name, wait_for_producing_select_sql, need_col_name=True)
        # status_list = result
        # status_list = []
        for i in ret_map_values:
            sum = 1
            status_map = {}
            status_map["progress"] = i
            status_map["sum"] = sum
            ret_array.append(status_map)

        return jsonify(common.trueReturn(ret_array, ""))
Exemple #7
0
    def api_status_get():
        app.logger.info("api_status_get")
        app.logger.info("request: %s", request)
        app.logger.info("当前访问用户:%s", request.remote_addr)
        # app.logger.info("Authorization:", request.headers['Authorization'])

        result = Auth.identify(Auth, request)
        # app.logger.info(result)
        app.logger.info("状态: %s 用户: %s ", result.get('status'), result.get('data'))
        if (result['status'] and result['data']):
            pass
        else:
            # return json.dumps(result, ensure_ascii=False)
            pass
            #return jsonify(result)

        '''
        [{
        "time": "",
        "person": "xxx",
        "api": [],
        }]
        '''

        ret = {"CPU": {"used": cpu_used},
               "Memory": {"used": memory_used,
                          "free": memory_free,
                          "total": memory_total},
               "Disk": {"used": disk_used,
                        "free": disk_free,
                        "total": disk_total},
               "Network": {"upload": upload,
                           "download": download,
                           "max_upload": "10000KB/s",
                           "max_download": "50000KB/s"}
               }

        return jsonify(common.trueReturn(ret, ""))
    def pictures_test():
        result = Auth.identify(Auth, request)
        if (result['status'] and result['data']):
            pass
        else:
            pass
            #return json.dumps(result, ensure_ascii=False)
        # print(request.data)
        # #print(request.headers)
        # print(request.form)
        # print(request.json)
        # print(request.stream)
        # print(request.input_stream)
        # print(request.get_data())
        # print(request.stream.read())
        # request_json = request.get_json()
        msg = ""

        print("有照片要上传")
        if request.method == 'POST':
            print(request.files)
            if 'file' not in request.files:
                return jsonify(common.falseReturn("", "上传失败,可能file参数不对"))
            f = request.files['file']
            #print(f)
            #print(type(f))

            #print(request.form)
            city = str(request.form.get('city'))
            filename = str(request.form.get('filename'))
            #if city == CITY.foshan.name:
            # 注意:没有的文件夹一定要先创建,不然会提示没有该路径
            filename = secure_filename(filename)
            filename_pre = filename.split('.')[0]
            global_id = filename.split('.')[0].split('_')[0]
            pictures_type = filename.split('.')[0].split('_')[1]
            filesuffix = filename.split('.')[1]
            #upload_path = os.path.join(dydatas_basepath + '/gd_dp_photos/' + city, filename)
            sum = 0
            '''
            for root, dirs, files in os.walk(dydatas_basepath + '/gd_dp_photos/' + city):
                # print('root_dir:', root)  # 当前目录路径
                # print('sub_dirs:', dirs)  # 当前路径下所有子目录
                # print('files:', files)  # 当前路径下所有非目录子文件
                for file in files:
                    if file.find(filename_pre) == 0:
                        sum += 1
            if sum == 0:
                filename = filename_pre + '.' + filesuffix
            else:
                msg = "---但是已经有该相同名字的图片了,检查下DZBM和图片类型是否正确,如果都正确,则是重复上传"
                filename = filename_pre + "_" + str(sum) + '.' + filesuffix
            #filename = global_id + "(" + str(sum) + ")" + '.' + filesuffix
            '''

            temp_file = tempfile.TemporaryFile()
            #print(tempfile)

            f.save(temp_file)

            temp_file.seek(0)
            upload_file_MD5 = get_MD5.GetFileMd5_from_file(temp_file)
            print("upload_file_MD5", upload_file_MD5)

            filename = filename_pre + '.' + filesuffix
            while (os.path.isfile(dydatas_basepath + '/gd_dp_photos/' + city +
                                  "/" + filename)):  # 入参需要是绝对路径
                # temp_MD5 = get_MD5.GetFileMd5(dydatas_basepath + '/gd_dp_photos/' + city + "/" + filename)
                temp_MD5 = get_MD5.GetFileMd5(dydatas_basepath +
                                              '/gd_dp_photos/' + city + "/" +
                                              filename)
                print("temp_MD5", temp_MD5)
                if upload_file_MD5 != temp_MD5:
                    sum += 1
                    filename = filename_pre + "_" + str(sum) + '.' + filesuffix
                else:
                    return jsonify(
                        common.falseReturn('',
                                           '已经有与filename相同命名的照片,' + filename,
                                           addition=common.false_Type.exist))

            #excel_name += '.xls'
            upload_path = os.path.join(
                dydatas_basepath + '/gd_dp_photos/' + city, filename)

            print("文件保存在:", upload_path)

            f.stream.seek(0)
            f.save(upload_path)
            #print(filename.split('.'))

            request_type = str(request.form.get('type'))
            if request_type == REQUEST_TYPE.picture.name:
                print("登记安装")
                # print(request_json.get('qrcode'))
                # print(request_json.get('installed_by'))
                # print(request_json.get('installed_coordinate'))
                #dzbm = filename.split('.')[0]

                database_name = 'fs_doorplate'
                if city == CITY.foshan.name:
                    database_name = 'fs_doorplate'
                    table_name = 'fs_dp'
                if city == CITY.guangzhou.name:
                    database_name = 'ws_doorplate'
                    table_name = 'gz_orders'

                #db = pymysql.connect("localhost", "root", "root", "丹灶数据库")
                db = pymysql.connect("localhost", "root", "root",
                                     database_name)
                # 使用cursor()方法获取操作游标
                cursor = db.cursor()

                #select_sql = "SELECT `index` FROM gis_ordered WHERE `DZBM` = " + "\'" + dzbm + "\'" + " LIMIT 1"
                select_sql = "SELECT `index` FROM " + table_name + " WHERE `global_id` = " + "\'" + global_id + "\'" + " LIMIT 1"

                if select_sql:
                    try:
                        # print(select_sql)
                        cursor.execute(select_sql)
                        # print(cursor.fetchall())
                        if cursor.fetchall():
                            pass
                        else:
                            # 提交到数据库执行
                            db.commit()
                            # 关闭数据库连接
                            db.close()
                            return jsonify(common.falseReturn(
                                "", "检查照片名称有无错误"))
                    except:
                        # 如果发生错误则回滚
                        # traceback.print_exc()
                        db.rollback()
                        # 关闭数据库连接
                        db.close()
                        return jsonify(common.falseReturn("", "上传失败"))

                # sql = "UPDATE gis_ordered  SET `installed_photos`=`installed_photos`+1 " + \
                #       " WHERE `DZBM` = " + "\'" + dzbm + "\'"


                sql = "UPDATE "+ table_name + " SET `installed_photos_" + pictures_type + "`=`installed_photos_" + pictures_type + "`+1 " + \
                      " WHERE `global_id` = " + "\'" + global_id + "\'"

                if sql:
                    try:
                        print(sql)
                        cursor.execute(sql)
                        # print(cursor.fetchall())
                        # 提交到数据库执行
                        db.commit()
                        # 关闭数据库连接
                        db.close()
                        return jsonify(common.trueReturn("", "上传成功" + msg))
                    except:
                        # 如果发生错误则回滚
                        # traceback.print_exc()
                        db.rollback()
                        # 关闭数据库连接
                        db.close()
                        return jsonify(common.falseReturn("", "上传失败"))

            # # return '成功上传'
            # return jsonify(common.trueReturn("", "上传成功"))

        return jsonify(common.falseReturn("", "未上传照片,可能是请求有问题"))
Exemple #9
0
    def apk():
        app.logger.info("server_status_get")
        app.logger.info("request: %s", request)
        app.logger.info("当前访问用户:%s", request.remote_addr)
        # app.logger.info("Authorization:", request.headers['Authorization'])

        result = Auth.identify(Auth, request)
        # app.logger.info(result)
        app.logger.info("状态: %s 用户: %s ", result.get('status'),
                        result.get('data'))
        if (result['status'] and result['data']):
            pass
        else:
            # return json.dumps(result, ensure_ascii=False)
            pass
            #return jsonify(result)

        if request.method == 'GET':
            request_type = request.args.get("type")

            name = request.args.get("name")

            apks_list = os.listdir(apks_path)
            apks_splits_list_temp = []
            for i in apks_list:
                if name:
                    if name == i.split("_")[0]:
                        apks_splits_list_temp.append([i] + i.split("_"))
                else:
                    apks_splits_list_temp.append([i] + i.split("_"))
            # apks_splits_list = [i.split("_") for i in apks_list]

            apks_splits_list = apks_splits_list_temp
            apks_splits_list.sort(reverse=True)

            if not name:
                ret_msg = ""
            else:
                ret_msg = "返回结果是服务器中name为" + name + "的"

            if request_type == "all":
                ret = []
                for i in apks_splits_list:
                    temp_map = {}
                    temp_map["upload_fath"] = os.path.join(apks_path, i[0])
                    temp_map["name"] = os.path.join(apks_path, i[1])
                    temp_map["version"] = os.path.join(apks_path, i[2])
                    temp_map["version_type"] = os.path.join(apks_path, i[3])
                    ret.append(temp_map)
                ret_msg += "所有的apks信息"
            else:
                # 默认返回最新的apks
                ret = [{
                    "upload_fath":
                    os.path.join(apks_path, apks_splits_list[0][0]),
                    "name":
                    apks_splits_list[0][1],
                    "version":
                    apks_splits_list[0][2],
                    "version_type":
                    apks_splits_list[0][3]
                }]
                ret_msg += "最新的apk信息"

            return common.trueReturn_json(ret, ret_msg)

        elif request.method == 'POST':
            #request_json = request.get_json()
            request_data = request.form

            name = request_data.get("name")  # apk 名字
            if not name:
                app.logger.info("没有传name参数")
                return common.falseReturn_json("", "没有传name参数")
            version = request_data.get("version")  # apk 版本号
            if not version:
                app.logger.info("没有传version参数")
                return common.falseReturn_json("", "没有传version参数")
            version_type = request_data.get("version_type")  # apk 版本类型
            if not version_type:
                app.logger.info("没有传version_type参数")
                return common.falseReturn_json("", "没有传version_type参数")

            filename = name + "_" + version + "_" + version_type + ".apk"

            f = request.files['file']
            if not f:
                app.logger.info("没有传file参数")
                return common.falseReturn_json("", "没有传文件")
            temp_file = tempfile.TemporaryFile()
            # app.logger.info(tempfile)

            f.save(temp_file)
            temp_file.seek(0)
            upload_file_MD5 = get_MD5.GetFileMd5_from_file(temp_file)
            app.logger.info("upload_file_MD5: %s", upload_file_MD5)
            filename_pre, filename_suffix = os.path.splitext(filename)
            upload_path = os.path.join(apks_path, filename)
            need_save = 1
            sum = 0
            while (os.path.isfile(os.path.join(apks_path,
                                               filename))):  # 入参需要是绝对路径
                # temp_MD5 = get_MD5.GetFileMd5(dydatas_basepath + '/gd_dp_photos/' + city + "/" + filename)
                temp_MD5 = get_MD5.GetFileMd5(os.path.join(
                    apks_path, filename))
                app.logger.info("temp_MD5: %s", temp_MD5)
                if upload_file_MD5 != temp_MD5:
                    sum += 1
                    filename = filename_pre + "_" + str(
                        sum) + '.' + filename_suffix
                else:
                    need_save = 0
                    app.logger.info('本地已经有相同文件了: %s', upload_path)
                    return common.falseReturn_json(
                        {"upload_fath": upload_path},
                        "服务器已经有该文件,请直接用",
                        addition=common.false_Type.exist)
                    break
            upload_path = os.path.join(apks_path, filename)
            upload_file_savename = filename

            if need_save:
                f.stream.seek(0)
                f.save(upload_path)
                app.logger.info("文件保存在:%s", upload_path)

            return common.trueReturn_json({"upload_fath": upload_path}, "成功上传")
Exemple #10
0
    def projects_PUT_POST():
        app.logger.info("projects_PUT_POST")
        app.logger.info("request: %s", request)
        app.logger.info("当前访问用户:%s", request.remote_addr)
        # app.logger.info("Authorization:", request.headers['Authorization'])

        result = Auth.identify(Auth, request)
        # app.logger.info(result)
        app.logger.info("状态: %s 用户: %s ", result.get('status'),
                        result.get('data'))
        if (result['status'] and result['data']):
            pass
        else:
            # return json.dumps(result, ensure_ascii=False)
            return jsonify(result)

        request_json = request.get_json()

        if request.method == 'PUT':

            if request_json.get('type') == PROJECTS_REQUEST_TYPE.projects.name:

                if not request_json.get("update_datas"):
                    return jsonify(common.falseReturn("", "没有要修改的数据"))
                else:
                    update_datas_map = request_json.get("update_datas")

                    select_status, select_msg, select_date, result = mysql.select_data(
                        "ws_doorplate",
                        "projects",
                        data_map=update_datas_map,
                        select_col=["index"])
                    # print("resultresult", result)
                    if not result:
                        pass
                    else:
                        return jsonify(
                            common.falseReturn(
                                {"index": result[0][0]},
                                "数据已经存在,新建失败,直接使用",
                                addition=common.false_Type.exist))

                if not request_json.get("index"):
                    return jsonify(common.falseReturn("", "没有传入要修改数据的index"))
                else:
                    index = request_json.get("index")

                status, msg, date, num = mysql.update_data(
                    "ws_doorplate",
                    "projects",
                    data_map=update_datas_map,
                    data_select_map={"index": index})

                if status:
                    long_time_cache.clear()
                    return jsonify(common.trueReturn("", msg))
                else:
                    return jsonify(common.falseReturn("", msg))
            else:
                return jsonify(common.falseReturn("", "传入的type不正确或者没有传type"))

        elif request.method == 'POST':

            if request_json.get('type') == PROJECTS_REQUEST_TYPE.projects.name:

                if not request_json.get("uploaded_by"):
                    if not result.get('data').get('username'):
                        uploaded_by = "没有填写"
                    else:
                        uploaded_by = result.get('data')["username"]
                else:
                    uploaded_by = request.args.get("uploaded_by")
                if not request_json.get("insert_datas"):
                    return jsonify(common.falseReturn("", "没有要新建的数据"))
                else:

                    insert_datas_map = request_json.get("insert_datas")

                    select_status, select_msg, select_date, result = mysql.select_data(
                        "ws_doorplate",
                        "projects",
                        data_map=insert_datas_map,
                        select_col=["index"])
                    #print("resultresult", result)
                    if not result:
                        pass
                    else:
                        return jsonify(
                            common.falseReturn(
                                {"index": result[0][0]},
                                "数据已经存在,新建失败,直接使用",
                                addition=common.false_Type.exist))

                    # 如果数据不存在,才增加时间然后往下走插入数据
                    insert_datas_map[
                        "uploaded_date"] = common.format_ymdhms_time_now()

                status, msg, date, num = mysql.insert_data(
                    "ws_doorplate",
                    "projects",
                    uploaded_by=uploaded_by,
                    data_map=insert_datas_map)

                select_status, select_msg, select_date, result = mysql.select_data(
                    "ws_doorplate",
                    "projects",
                    data_map=insert_datas_map,
                    select_col=["index"])

                status = status & select_status

                msg = msg + " \n " + select_msg

                if status:
                    long_time_cache.clear()
                    return jsonify(
                        common.trueReturn({"index": result[0][0]}, msg))
                else:
                    return jsonify(common.falseReturn("", msg))
            else:
                return jsonify(common.falseReturn("", "传入的type不正确或者没有传type"))

        else:
            return jsonify(common.falseReturn("", "后端出错"))
Exemple #11
0
    def projects_get():
        app.logger.info("projects_get")
        app.logger.info("request: %s", request)
        app.logger.info("当前访问用户:%s", request.remote_addr)

        # app.logger.info("Authorization:", request.headers['Authorization'])

        result = Auth.identify(Auth, request)
        # app.logger.info(result)
        app.logger.info("状态: %s 用户: %s ", result.get('status'),
                        result.get('data'))
        if (result['status'] and result['data']):
            pass
        else:
            # return json.dumps(result, ensure_ascii=False)
            return jsonify(result)

        # col_name_map = mysql.get_col_name_map()
        #
        # col_name_list = get_col_name_list(request)

        request_json = request.get_json()

        if request.method == 'GET':

            #long_time_cache.clear()
            if request.args.get(
                    'type'
            ) == PROJECTS_REQUEST_TYPE.projects_status_detail.name:
                if not request.args.get("city"):
                    city = [i for i in CITY.items()]
                else:
                    city = [request.args.get("city")]

                return_datas = []
                for index, i in enumerate(city):
                    result, status_map, status_list, ret_map = get_projects_status(
                        i)
                    project_name_list, contract_batch_list, order_batch_list, order_id_list = get_projects_status_list(
                        i)
                    return_datas.append({
                        "city": i,
                        "project_name_list": project_name_list,
                        "contract_batch_list": contract_batch_list,
                        "order_batch_list": order_batch_list,
                        "order_id_list": order_id_list,
                        "details_list": status_list
                    })

                return jsonify(
                    common.trueReturn(
                        return_datas,
                        "orders: [[订单批号,订单号],....], contract_nums: 合同数量 ",
                        addition={"city_list": city}))

            elif request.args.get(
                    'type'
            ) == PROJECTS_REQUEST_TYPE.projects_status_static.name:
                # 获取项目管理状态信息
                '''
                临时版 2019-09-05
                '''
                if not request.args.get("city"):
                    city = [i for i in CITY.items()]
                else:
                    city = [request.args.get("city")]

                return_datas = []
                for index, i in enumerate(city):
                    result, status_detail_map, status_detail_list, ret_map = get_projects_status(
                        i, detail=True)
                    project_name_list, contract_batch_list, order_batch_list, order_id_list = get_projects_status_list(
                        i)

                    return_datas.append({
                        "city":
                        i,
                        "project_name_list":
                        project_name_list,
                        "contract_batch_list":
                        contract_batch_list,
                        "order_batch_list":
                        order_batch_list,
                        "order_id_list":
                        order_id_list,
                        "status_detail_map":
                        status_detail_map,
                        "status_detail_list":
                        status_detail_list,
                        "contract_nums":
                        len(status_detail_list),
                        "order_nums":
                        len(result),
                        "statics":
                        ret_map
                    })

                return jsonify(
                    common.trueReturn(
                        return_datas,
                        "orders: [[订单批号,订单号, 门牌数量],....], contract_nums: 合同数量 ",
                        addition={"city_list": city}))

            else:
                return jsonify(common.falseReturn("", "接口参数传递出错,检查type"))
Exemple #12
0
    def department_get():
        """
        获取部门职位信息
        :return: json
        """

        result = Auth.identify(Auth, request)
        if (result['status'] and result['data']):
            pass
        else:
            pass

        des_id = request.args.get('id') if request.args.get('id') else None
        if des_id:
            department = Departments.get(Departments, des_id)
            print(department)
            if department:
                try:
                    ret_authority_map = ast.literal_eval(department.authority_map)
                except:
                    ret_authority_map = {}[department.authority_map] = department.authority_map
                ret = [{
                    'id': department.id,
                    'department': department.department,
                    'job': department.job,
                    'authority_map': ret_authority_map

                }]
            else:
                result = common.falseReturn("", "找不到该部门职位信息", {"departments_count": 0})
                return jsonify(result)
        else:
            departments = Departments.get_all(Departments)
            ret = []
            for department in departments:
                try:
                    ret_authority_map = ast.literal_eval(department.authority_map)
                except:
                    ret_authority_map = {}[department.authority_map] = department.authority_map
                ret.append({
                    'id': department.id,
                    'department': department.department,
                    'job': department.job,
                    'authority_map': ret_authority_map
                })

        # elif int(all) == -1:
        #     department = Departments.get_by_departmentname(Departments, request.args.get('department'))
        #     print(department)
        #     if department:
        #         ret = [{
        #             'id': department.id,
        #             'department': department.department,
        #             'job': department.job,
        #             'authority_map': department.authority_map
        #
        #         }]
        #     else:
        #         result = common.falseReturn("", "找不到该部门职位信息", {"departments_count": 0})
        #         return jsonify(result)
        result = common.trueReturn(ret, "请求成功", {"departments_count": len(ret)})
        return jsonify(result)
Exemple #13
0
    def get():
        """
        获取用户信息
        :return: json
        """

        result = Auth.identify(Auth, request)
        if (result['status'] and result['data']):
            pass
        else:
            pass

        all = request.args.get('all')
        if int(all) == 1:
            users = Users.get_all(Users)
            returnUser = []
            for user, department in users:

                #print("typeuser.register_time", type(user.register_time))
                if not user.login_time:
                    login_time = 0
                else:
                    login_time = user.login_time

                try:
                    ret_authority_map = ast.literal_eval(department.authority_map)
                except:
                    ret_authority_map = {}[department.authority_map] = department.authority_map
                returnUser.append({
                'id': user.id,
                'username': user.username,
                'truename': user.truename,
                'contact_num': user.contact_num,
                'department_id': user.department_id,
                'department': department.department if department else "无填写",
                'job': department.job if department else "无填写",
                'authority_map': ret_authority_map,
                'usertype': user.usertype,
                'working_city': user.working_city,
                'projects_index': user.projects_index,
                'login_time': datetime.datetime.fromtimestamp(float(login_time)).strftime('%Y-%m-%d %H:%M:%S'),
                'register_time': user.register_time.strftime('%Y-%m-%d %H:%M:%S')
                })
                #print(user)

        elif int(all) == 0:
            if not result['status']:
                return jsonify(result)
            user, department = Users.get(Users, result['data']['id'])
            if not user.login_time:
                login_time = 0
            else:
                login_time = user.login_time
            try:
                ret_authority_map = ast.literal_eval(department.authority_map)
            except:
                ret_authority_map = {}[department.authority_map] = department.authority_map
            returnUser = [{
                'id': user.id,
                'username': user.username,
                'truename': user.truename,
                'contact_num': user.contact_num,
                'department_id': user.department_id,
                'department': department.department if department else "无填写",
                'job': department.job if department else "无填写",
                'authority_map': ret_authority_map,
                'usertype': user.usertype,
                'working_city': user.working_city,
                'projects_index': user.projects_index,
                'login_time': datetime.datetime.fromtimestamp(float(login_time)).strftime('%Y-%m-%d %H:%M:%S'),
                'register_time': user.register_time.strftime('%Y-%m-%d %H:%M:%S')

            }]
        elif int(all) == -1:
            user, department = Users.get_by_username(Users, request.args.get('username'))
            print(user)
            if user:
                if not user.login_time:
                    login_time = 0
                else:
                    login_time = user.login_time
                try:
                    ret_authority_map = ast.literal_eval(department.authority_map)
                except:
                    ret_authority_map = {}[department.authority_map] = department.authority_map
                returnUser = [{
                    'id': user.id,
                    'username': user.username,
                    'truename': user.truename,
                    'contact_num': user.contact_num,
                    'department_id': user.department_id,
                    'department': department.department if department else "无填写",
                    'job': department.job if department else "无填写",
                    'authority_map': ret_authority_map,
                    'usertype': user.usertype,
                    'working_city': user.working_city,
                    'projects_index': user.projects_index,
                    'login_time': datetime.datetime.fromtimestamp(float(login_time)).strftime('%Y-%m-%d %H:%M:%S'),
                    'register_time': user.register_time.strftime('%Y-%m-%d %H:%M:%S')

                }]
            else:
                result = common.falseReturn("", "找不到该用户信息", {"users_count": 0})
                return jsonify(result)
        result = common.trueReturn(returnUser, "请求成功", {"users_count": len(returnUser)})
        return jsonify(result)