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

Commit f43bf59a by 李景熙

添加后端发布任务时数据库中文件相关信息的修改

parent a0a1bc40
from peewee import * from peewee import *
from Dao.model import mysql from Dao.model import mysql
from Dao import Slice
class Result: class Result:
...@@ -16,6 +17,7 @@ class Result: ...@@ -16,6 +17,7 @@ class Result:
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)
name = CharField(null=False, max_length=30)
url = CharField(null=False, unique=True) url = CharField(null=False, unique=True)
class Meta: class Meta:
...@@ -23,9 +25,10 @@ class Data(Model): ...@@ -23,9 +25,10 @@ class Data(Model):
# 向数据库中添加原始数据 # 向数据库中添加原始数据
def create_data(slice_id, url): def create_data(slice_id, name, url):
try: try:
data = Data(slice_id=slice_id, url=url) Slice.add_file(slice_id)
data = Data(slice_id=slice_id, name=name, url=url)
data.save() data.save()
except Exception: except Exception:
return Result(0, "create failed", {}) return Result(0, "create failed", {})
...@@ -44,4 +47,5 @@ def find_data(id): ...@@ -44,4 +47,5 @@ def find_data(id):
if __name__ == '__main__': if __name__ == '__main__':
Data.drop_table()
Data.create_table() Data.create_table()
...@@ -103,6 +103,18 @@ def find_slice_by_task(task_id): ...@@ -103,6 +103,18 @@ def find_slice_by_task(task_id):
return Result(1, "find success", list) return Result(1, "find success", list)
# 添加文件
def add_file(slice_id):
try:
s = Slice.get(Slice.slice_id == slice_id)
except:
return False
else:
s.document_number += 1
s.save()
return True
if __name__ == '__main__': if __name__ == '__main__':
# create_text_slice(1,1) # create_text_slice(1,1)
# create_pic_slice(1, "标注坐标(30,100)") # create_pic_slice(1, "标注坐标(30,100)")
......
import json import json
from flask import Blueprint from flask import Blueprint
from flask import request from flask import request
from Dao import Task, Slice from Dao import Task, Slice, Data
task = Blueprint("task", __name__, url_prefix="/api/task") task = Blueprint("task", __name__, url_prefix="/api/task")
...@@ -42,16 +42,30 @@ def create_task(): ...@@ -42,16 +42,30 @@ def create_task():
i = 0 i = 0
print(data) print(data)
while i < len(data['task']['domains']): while i < len(data['task']['domains']):
# 创建分片具体内容还有问题,待修复 s = Slice.create_text_slice(tid, data['task']['domains'][i]['piecesOptions'])
Slice.create_text_slice(tid, data['task']['domains'][i]['piecesOptions']) j = 0
while j < len(data['task']['domains'][i]['fileName']):
Data.create_data(s.data, data['task']['domains'][i]['fileName'][j]['name'],
data['task']['domains'][i]['fileName'][j]['url'])
j += 1
i += 1 i += 1
i = 0 i = 0
while i < len(data['task']['pictureDomains']): while i < len(data['task']['pictureDomains']):
Slice.create_pic_slice(tid, data['task']['pictureDomains'][i]['textarea']) s = Slice.create_pic_slice(tid, data['task']['pictureDomains'][i]['textarea'])
j = 0
while j < len(data['task']['pictureDomains'][i]['fileName']):
Data.create_data(s.data, data['task']['pictureDomains'][i]['fileName'][j]['name'],
data['task']['pictureDomains'][i]['fileName'][j]['url'])
j += 1
i += 1 i += 1
i = 0 i = 0
while i < len(data['task']['layerDomains']): while i < len(data['task']['layerDomains']):
Slice.create_layer_slice(tid, data['task']['layerDomains'][i]['textarea']) s = Slice.create_layer_slice(tid, data['task']['layerDomains'][i]['textarea'])
j = 0
while j < len(data['task']['layerDomains'][i]['fileName']):
Data.create_data(s.data, data['task']['layerDomains'][i]['fileName'][j]['name'],
data['task']['layerDomains'][i]['fileName'][j]['url'])
j += 1
i += 1 i += 1
res = { res = {
'code': ret.code, 'code': ret.code,
......
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