文档服务地址:http://47.92.0.57:3000/ 周报索引地址:http://47.92.0.57:3000/s/NruNXRYmV

Commit 20524ed2 by 李景熙

修改Data中函数的返回

parent 8510e7fd
...@@ -2,6 +2,17 @@ from peewee import * ...@@ -2,6 +2,17 @@ from peewee import *
from Dao.model import mysql from Dao.model import mysql
class Result:
code: int
message: []
data: {}
def __init__(self, code, message, data):
self.code = code
self.message = message
self.data = data
class Data(Model): class Data(Model):
data_id = AutoField(primary_key=True, unique=True) data_id = AutoField(primary_key=True, unique=True)
slice_id = IntegerField(null=False) slice_id = IntegerField(null=False)
...@@ -17,9 +28,9 @@ def create_data(slice_id, url): ...@@ -17,9 +28,9 @@ def create_data(slice_id, url):
data = Data(slice_id=slice_id, url=url) data = Data(slice_id=slice_id, url=url)
data.save() data.save()
except Exception: except Exception:
print(0) return Result(0, "create failed", {})
else: else:
print(1) return Result(1, "create success", {})
# 根据数据id寻找数据url # 根据数据id寻找数据url
...@@ -27,11 +38,10 @@ def find_data(id): ...@@ -27,11 +38,10 @@ def find_data(id):
try: try:
data = Data.get(Data.data_id == id) data = Data.get(Data.data_id == id)
except Exception: except Exception:
print(0) return Result(0, "find failed", {})
else: else:
print(data.url) return Result(1, "find success", data.url)
if __name__ == '__main__': if __name__ == '__main__':
Data.drop_table()
Data.create_table() Data.create_table()
...@@ -3,6 +3,7 @@ from Dao import Task ...@@ -3,6 +3,7 @@ from Dao import Task
from peewee import * from peewee import *
from Dao.model import mysql from Dao.model import mysql
class Result: class Result:
code: int code: int
message: [] message: []
...@@ -76,7 +77,8 @@ def delete_slice(id): ...@@ -76,7 +77,8 @@ def delete_slice(id):
# 查找某任务下的分片 # 查找某任务下的分片
def find_slice_by_task(task_id): def find_slice_by_task(task_id):
try: try:
find = Slice.select(Slice.slice_id, Slice.document_number, Slice.type, Slice.model_id).where(Slice.task_id == task_id) find = Slice.select(Slice.slice_id, Slice.document_number, Slice.type, Slice.model_id).where(
Slice.task_id == task_id)
index = 0 index = 0
list = [] list = []
while index < len(find): while index < len(find):
......
...@@ -4,6 +4,7 @@ import math ...@@ -4,6 +4,7 @@ import math
from Dao import User from Dao import User
from Dao.model import mysql from Dao.model import mysql
class Result: class Result:
code: int code: int
message: [] message: []
......
...@@ -164,6 +164,7 @@ def get_username(id): ...@@ -164,6 +164,7 @@ def get_username(id):
else: else:
return tmp.userName return tmp.userName
if __name__ == '__main__': if __name__ == '__main__':
User.create_table() User.create_table()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment