示例#1
0
    def insert_data(self):
        if 'dataArr' in self.req.form:
            try:
                list_data = json.loads(self.req.form['dataArr'])
                if len(list_data) == 0:
                    return make_response('dataArr错误')
            except:
                return make_response('dataArr错误')
        else:
            return make_response('dataArr错误')

        for item in list_data:
            item['create_name'] = self.dict_login['username']
            item['create_time'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
            item['update_name'] = ''
            item['update_time'] = ''

        result = mysqldb.insert_data(self.table_name, list_data)
        # print(result)

        if result:
            # 操作记录
            content = 'dataArr=' + re.sub(r'\"', "'", json.dumps(list_data, ensure_ascii=False))
            dict_record = {'username': self.dict_login['username'], 'dbName': self.table_name, 'action': '增加', 'content': content, 'os': self.dict_login['os'], 'px': self.dict_login['px'], 'ip': self.req.remote_addr, 'time': time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}
            mysqldb.set_record(dict_record)

            return make_response('操作成功')
        else:
            return make_response('操作失败')
示例#2
0
    def insert_data():
        if 'dataArr' in req.form:
            try:
                list_data = json.loads(req.form['dataArr'])
                if len(list_data) == 0:
                    return make_response('dataArr错误')
            except:
                return make_response('dataArr错误')
        else:
            return make_response('dataArr错误')

        upload_files = req.files.getlist("file")
        for i, file in enumerate(upload_files):
            now_time = time.strftime("%Y-%m-%d-%H-%M-%S",
                                     time.localtime()) + "-" + str(
                                         time.time())[11:15]
            now_path = os.path.dirname(
                os.path.dirname(__file__)
            ) + "/static/uploadFile/" + now_time + "___" + file.filename
            if not os.path.exists(now_path):
                file.save(now_path)
            else:
                pass
            url = "/static/uploadFile/" + now_time + "___" + file.filename
            list_data[i]['name'] = file.filename
            list_data[i]['size'] = os.path.getsize(now_path)
            list_data[i]['url'] = url
            list_data[i]['create_name'] = dict_login['username']
            list_data[i]['create_time'] = time.strftime(
                "%Y-%m-%d %H:%M:%S", time.localtime())

        # print(list_data)
        result = mysqldb.insert_data(table_name, list_data)
        # print(result)

        if result:
            # 操作记录
            content = 'dataArr=' + re.sub(
                r'\"', "'", json.dumps(list_data, ensure_ascii=False))
            dict_record = {
                'username': dict_login['username'],
                'dbName': table_name,
                'action': '上传文件',
                'content': content,
                'os': dict_login['os'],
                'px': dict_login['px'],
                'ip': req.remote_addr,
                'time': time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
            }
            mysqldb.set_record(dict_record)

            return make_response('操作成功')
        else:
            return make_response('操作失败')
示例#3
0
    def insert_data():
        if 'dataArr' in req.form:
            try:
                list_data = json.loads(req.form['dataArr'])
                if len(list_data) == 0:
                    return make_response('dataArr错误')
            except:
                return make_response('dataArr错误')
        else:
            return make_response('dataArr错误')

        if len(list_data) > 1:
            return make_response('不支持批量插入')

        for item in list_data:
            item['create_name'] = dict_login['username']
            item['create_time'] = time.strftime("%Y-%m-%d %H:%M:%S",
                                                time.localtime())

        # 查询角色权限是否存在
        str_where = 'power_id=' + str(
            list_data[0]['power_id']) + ' and model_id=' + str(
                list_data[0]['model_id']
            ) + ' and function_en="' + list_data[0]['function_en'] + '"'
        str_field = 'power_id,model_id,function_en'
        args = {'pre_page_num': 1, 'curr_page': 1, 'sort': ''}
        result = mysqldb.find_data(table_name, str_where, str_field, args)
        if result['count'] > 0:
            return make_response('该角色权限已存在')

        result = mysqldb.insert_data(table_name, list_data)
        # print(result)

        if result:
            # 操作记录
            content = 'dataArr=' + re.sub(
                r'\"', "'", json.dumps(list_data, ensure_ascii=False))
            dict_record = {
                'username': dict_login['username'],
                'dbName': table_name,
                'action': '增加',
                'content': content,
                'os': dict_login['os'],
                'px': dict_login['px'],
                'ip': req.remote_addr,
                'time': time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
            }
            mysqldb.set_record(dict_record)

            return make_response('操作成功')
        else:
            return make_response('操作失败')
示例#4
0
    def insert_data(self):
        if 'dataArr' in self.req.form:
            try:
                list_data = json.loads(self.req.form['dataArr'])
                if len(list_data) == 0:
                    return make_response('dataArr错误')
            except:
                return make_response('dataArr错误')
        else:
            return make_response('dataArr错误')

        list_username = []
        for item in list_data:
            if not item['username'] and not item['password']:
                return make_response('用户名和密码不能为空')
            if len(item['password']) < 6:
                return make_response('密码长度不能小于6')

            password = "******" + item['password'] + item['password'][0:3]
            md5 = hashlib.md5()
            md5.update(password.encode(encoding='utf-8'))
            md5_password = md5.hexdigest()
            item['password'] = md5_password

            item['create_name'] = self.dict_login['username']
            item['create_time'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
            item['update_name'] = ''
            item['update_time'] = ''
            list_username.append(item['username'])

        str_where = 'username in ' + re.sub(r'\,', '', str(tuple(list_username)))
        str_field = 'id, username'
        args = {'pre_page_num': 0, 'curr_page': 0, 'sort': ''}
        find_result = mysqldb.find_data(self.table_name, str_where, str_field, args)
        if find_result['count'] != 0:
            return make_response('用户名已存在')

        result = mysqldb.insert_data(self.table_name, list_data)
        # print(result)

        if result:
            # 操作记录
            content = 'dataArr=' + re.sub(r'\"', "'", json.dumps(list_data, ensure_ascii=False))
            dict_record = {'username': self.dict_login['username'], 'dbName': self.table_name, 'action': '增加', 'content': content, 'os': self.dict_login['os'], 'px': self.dict_login['px'], 'ip': self.req.remote_addr, 'time': time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}
            mysqldb.set_record(dict_record)

            return make_response('操作成功')
        else:
            return make_response('操作失败')
示例#5
0
    def insert_data_fn(self,list_data):
        result = mysqldb.insert_data(self.table_name, list_data)
        # print(result)
        if result:
            print('插入list_data成功')

            # 操作记录
            content = 'dataArr=' + re.sub(r'\"', "'", json.dumps(list_data, ensure_ascii=False))
            dict_record = {'username': self.dict_login['username'], 'dbName': self.table_name, 'action': '增加', 'content': content,
                           'os': self.dict_login['os'], 'px': self.dict_login['px'], 'ip': self.req.remote_addr,
                           'time': time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}
            mysqldb.set_record(dict_record)

            return make_response('操作成功')
        else:
            return make_response('操作失败')
示例#6
0
    def insert_data():
        if 'dataArr' in req.form:
            try:
                list_data = json.loads(req.form['dataArr'])
                if len(list_data) == 0:
                    return make_response('dataArr错误')
            except:
                return make_response('dataArr错误')
        else:
            return make_response('dataArr错误')

        for item in list_data:
            item['create_name'] = dict_login['username']
            item['create_time'] = time.strftime("%Y-%m-%d %H:%M:%S",
                                                time.localtime())

        result = mysqldb.insert_data(table_name, list_data)
        # print(result)

        if result:
            return make_response('操作成功')
        else:
            return make_response('操作失败')