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

Commit 23847cf2 by 李梓桢

图片标注前端接口

parents a6299476 60b27bd5
...@@ -12,3 +12,4 @@ yarn-error.log* ...@@ -12,3 +12,4 @@ yarn-error.log*
*.ntvs* *.ntvs*
*.njsproj *.njsproj
*.sln *.sln
env
\ No newline at end of file
...@@ -5,17 +5,17 @@ ...@@ -5,17 +5,17 @@
<div class="tasklist"> <div class="tasklist">
<div class="task-item" v-for="(item, index) in tasks" :key='index'> <div class="task-item" v-for="(item, index) in tasks" :key='index'>
<div>{{item.name}}</div> <div>{{item.name}}</div>
<div>发布者:{{item.creator}}&emsp;&emsp;发布时间:{{item.date}}&emsp;&emsp;任务状态:待审核 <div>发布者:{{item.creator}}&emsp;&emsp;发布时间:{{item.date|formatDate}}&emsp;&emsp;任务状态:待审核
</div> </div>
<el-button class="task-enter-btn1" type="primary" @click="detail(item)" plain>审核任务</el-button> <el-button class="task-enter-btn1" type="primary" @click="detail(item)" plain>审核任务</el-button>
</div> </div>
</div> </div>
<div class="page-navigator"> <div class="page-navigator">
<el-pagination <el-pagination
:page-size="20" :page-size="pageSize"
:pager-count="11" :page-count="pageNum"
layout="prev, pager, next" :current-page="currentPage"
:total="1000"> layout="prev, pager, next">
</el-pagination> </el-pagination>
</div> </div>
</div> </div>
...@@ -24,29 +24,33 @@ ...@@ -24,29 +24,33 @@
</template> </template>
<script> <script>
const mock = true
if (mock) require('@/mock/api.js')
export default { export default {
name: 'checktask', name: 'checktask',
data () { data () {
return { return {
activeName: '待审核任务', activeName: '待审核任务',
tasks: [] tasks: [],
pageSize: 10,
currentPage: 1,
pageNum: 0
} }
}, },
mounted () { beforeMount () {
this.axios.get('/getTasks').then(res => { var self = this
this.tasks = res.data this.axios.get('/task/getTasks', {
params: {
pageSize: self.pageSize,
currentPage: self.currentPage,
creator: self.$store.state.userInfo.userId,
state: 'checking'
}
}).then(res => {
console.log(res)
self.tasks = res.data.tasks
self.pageNum = res.data.pageNum
}) })
}, },
methods: { methods: {
handleClick (tab, event) {
console.log(tab, event)
},
deleteRow (index, rows) { // 删除改行
rows.splice(index, 1)
},
detail (task) { detail (task) {
this.$router.push({ this.$router.push({
name: 'checkdetail', name: 'checkdetail',
...@@ -70,17 +74,6 @@ export default { ...@@ -70,17 +74,6 @@ export default {
background-color: white; background-color: white;
padding: 30px 20px 30px 20px; padding: 30px 20px 30px 20px;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
.filter-container{
.filter-item{
display: flex;
align-items: center;
margin-bottom: 15px;
.filter-input{
margin-left: 20px;
width: 300px;
}
}
}
.tasklist-container{ .tasklist-container{
.tasklist{ .tasklist{
.task-item{ .task-item{
...@@ -109,25 +102,5 @@ export default { ...@@ -109,25 +102,5 @@ export default {
margin-top: 30px; margin-top: 30px;
} }
} }
.taskhall-right{
float: right;
width: 25%;
.notice{
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
margin-bottom: 30px;
.notice-title{
background-color: $theme-color;
color: white;
padding: 10px 0;
}
.notice-body{
background-color: white;
height: 200px;
display: flex;
align-items: center;
justify-content: center;
}
}
}
} }
</style> </style>
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<div class="tasklist"> <div class="tasklist">
<div class="task-item" v-for="(item, index) in tasks" :key='index'> <div class="task-item" v-for="(item, index) in tasks" :key='index'>
<div>{{item.name}}</div> <div>{{item.name}}</div>
<div>发布者:{{item.creator}}&emsp;&emsp;发布时间:{{item.date}}&emsp;&emsp;任务状态:已完成 <div>发布者:{{item.creator}}&emsp;&emsp;发布时间:{{item.date|formatDate}}&emsp;&emsp;任务状态:已完成
</div> </div>
<el-button class="task-enter-btn1" type="primary" @click="detail(item)" plain>查看任务</el-button> <el-button class="task-enter-btn1" type="primary" @click="detail(item)" plain>查看任务</el-button>
<el-button class="task-enter-btn2" type="primary" plain>导出任务</el-button> <el-button class="task-enter-btn2" type="primary" plain>导出任务</el-button>
...@@ -13,10 +13,10 @@ ...@@ -13,10 +13,10 @@
</div> </div>
<div class="page-navigator"> <div class="page-navigator">
<el-pagination <el-pagination
:page-size="20" :page-size="pageSize"
:pager-count="11" :page-count="pageNum"
layout="prev, pager, next" :current-page="currentPage"
:total="1000"> layout="prev, pager, next">
</el-pagination> </el-pagination>
</div> </div>
</div> </div>
...@@ -25,29 +25,33 @@ ...@@ -25,29 +25,33 @@
</template> </template>
<script> <script>
const mock = true
if (mock) require('@/mock/api.js')
export default { export default {
name: 'ongoingtask', name: 'ongoingtask',
data () { data () {
return { return {
activeName: '我的任务', activeName: '我的任务',
tasks: [] tasks: [],
pageSize: 10,
currentPage: 1,
pageNum: 0
} }
}, },
mounted () { beforeMount () {
this.axios.get('/getTasks').then(res => { var self = this
this.tasks = res.data this.axios.get('/task/getTasks', {
params: {
pageSize: self.pageSize,
currentPage: self.currentPage,
executor: self.$store.state.userInfo.userId,
state: 'completed'
}
}).then(res => {
console.log(res)
self.tasks = res.data.tasks
self.pageNum = res.data.pageNum
}) })
}, },
methods: { methods: {
handleClick (tab, event) {
console.log(tab, event)
},
deleteRow (index, rows) { // 删除改行
rows.splice(index, 1)
},
detail (task) { detail (task) {
this.$router.push({ this.$router.push({
name: 'completeddetail', name: 'completeddetail',
...@@ -71,17 +75,6 @@ export default { ...@@ -71,17 +75,6 @@ export default {
background-color: white; background-color: white;
padding: 30px 20px 30px 20px; padding: 30px 20px 30px 20px;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
.filter-container{
.filter-item{
display: flex;
align-items: center;
margin-bottom: 15px;
.filter-input{
margin-left: 20px;
width: 300px;
}
}
}
.tasklist-container{ .tasklist-container{
.tasklist{ .tasklist{
.task-item{ .task-item{
...@@ -115,25 +108,5 @@ export default { ...@@ -115,25 +108,5 @@ export default {
margin-top: 30px; margin-top: 30px;
} }
} }
.taskhall-right{
float: right;
width: 25%;
.notice{
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
margin-bottom: 30px;
.notice-title{
background-color: $theme-color;
color: white;
padding: 10px 0;
}
.notice-body{
background-color: white;
height: 200px;
display: flex;
align-items: center;
justify-content: center;
}
}
}
} }
</style> </style>
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<div class="tasklist"> <div class="tasklist">
<div class="task-item" v-for="(item, index) in tasks" :key='index'> <div class="task-item" v-for="(item, index) in tasks" :key='index'>
<div>{{item.name}}</div> <div>{{item.name}}</div>
<div>发布者:{{item.creator}}&emsp;&emsp;发布时间:{{item.date}}&emsp;&emsp;任务状态:已发布 <div>发布者:{{item.creator}}&emsp;&emsp;发布时间:{{item.date|formatDate}}&emsp;&emsp;任务状态:已发布
</div> </div>
<el-button class="task-enter-btn1" type="primary" plain @click="revise">修改</el-button> <el-button class="task-enter-btn1" type="primary" plain @click="revise">修改</el-button>
<el-button class="task-enter-btn2" @click="deleteRow(index, tasks)" type="primary" plain>删除</el-button> <el-button class="task-enter-btn2" @click="deleteRow(index, tasks)" type="primary" plain>删除</el-button>
...@@ -13,10 +13,10 @@ ...@@ -13,10 +13,10 @@
</div> </div>
<div class="page-navigator"> <div class="page-navigator">
<el-pagination <el-pagination
:page-size="20" :page-size="pageSize"
:pager-count="11" :page-count="pageNum"
layout="prev, pager, next" :current-page="currentPage"
:total="1000"> layout="prev, pager, next">
</el-pagination> </el-pagination>
</div> </div>
</div> </div>
...@@ -25,29 +25,33 @@ ...@@ -25,29 +25,33 @@
</template> </template>
<script> <script>
const mock = true
if (mock) {
require('@/mock/api.js'
)
}
export default { export default {
name: 'publishtask', name: 'publishtask',
data () { data () {
return { return {
activeName: '我的发布', activeName: '我的发布',
tasks: [] tasks: [],
pageSize: 10,
currentPage: 1,
pageNum: 0
} }
}, },
mounted () { beforeMount () {
this.axios.get('/getTasks').then(res => { var self = this
this.tasks = res.data this.axios.get('/task/getTasks', {
params: {
pageSize: self.pageSize,
currentPage: self.currentPage,
creator: self.$store.state.userInfo.userId,
state: ''
}
}).then(res => {
console.log(res)
self.tasks = res.data.tasks
self.pageNum = res.data.pageNum
}) })
}, },
methods: { methods: {
handleClick (tab, event) {
console.log(tab, event)
},
deleteRow (index, rows) { // 删除改行 deleteRow (index, rows) { // 删除改行
this.$confirm('确定要删除吗?', '提示', { this.$confirm('确定要删除吗?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
...@@ -78,17 +82,6 @@ export default { ...@@ -78,17 +82,6 @@ export default {
background-color: white; background-color: white;
padding: 30px 20px 30px 20px; padding: 30px 20px 30px 20px;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
.filter-container{
.filter-item{
display: flex;
align-items: center;
margin-bottom: 15px;
.filter-input{
margin-left: 20px;
width: 300px;
}
}
}
.tasklist-container{ .tasklist-container{
.tasklist{ .tasklist{
.task-item{ .task-item{
...@@ -122,25 +115,5 @@ export default { ...@@ -122,25 +115,5 @@ export default {
margin-top: 30px; margin-top: 30px;
} }
} }
.taskhall-right{
float: right;
width: 25%;
.notice{
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
margin-bottom: 30px;
.notice-title{
background-color: $theme-color;
color: white;
padding: 10px 0;
}
.notice-body{
background-color: white;
height: 200px;
display: flex;
align-items: center;
justify-content: center;
}
}
}
} }
</style> </style>
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
<div class="filter-container"> <div class="filter-container">
<div class="filter-item"> <div class="filter-item">
任务名称: 任务名称:
<el-input class="filter-input" prefix-icon="el-icon-search" v-model="keywords" placeholder="请输入查询条件"></el-input> <el-input class="filter-input" prefix-icon="el-icon-search" v-model="keyword" placeholder="请输入查询条件"></el-input>
</div> </div>
<div class="filter-item"> <div class="filter-item">
<el-button class="filter-button" type="primary">查询</el-button> <el-button class="filter-button" type="primary" @click="search()">查询</el-button>
</div> </div>
<el-divider></el-divider> <el-divider></el-divider>
</div> </div>
...@@ -15,16 +15,16 @@ ...@@ -15,16 +15,16 @@
<div class="tasklist"> <div class="tasklist">
<div class="task-item" v-for="(item, index) in tasks" :key='index'> <div class="task-item" v-for="(item, index) in tasks" :key='index'>
<div>{{item.name}}</div> <div>{{item.name}}</div>
<div>发布人:{{item.creator}}&emsp;&emsp;发布时间:{{item.date}}</div> <div>发布人:{{item.creator}}&emsp;&emsp;发布时间:{{item.date|formatDate}}</div>
<el-button class="task-enter-btn" type="primary" plain @click="enterTask(item)">进入任务</el-button> <el-button class="task-enter-btn" type="primary" plain @click="enterTask(item)">进入任务</el-button>
</div> </div>
</div> </div>
<div class="page-navigator"> <div class="page-navigator">
<el-pagination <el-pagination
:page-size="20" :page-size="pageSize"
:pager-count="11" :page-count="pageNum"
layout="prev, pager, next" :current-page="currentPage"
:total="1000"> layout="prev, pager, next">
</el-pagination> </el-pagination>
</div> </div>
</div> </div>
...@@ -53,12 +53,23 @@ export default { ...@@ -53,12 +53,23 @@ export default {
return { return {
activeName: '任务大厅', activeName: '任务大厅',
tasks: [], tasks: [],
keywords: '' keyword: '',
pageSize: 10,
currentPage: 1,
pageNum: 0
} }
}, },
mounted () { beforeMount () {
this.axios.get('/getTasks').then(res => { var self = this
this.tasks = res.data this.axios.get('/task/getTasks', {
params: {
pageSize: self.pageSize,
currentPage: self.currentPage
}
}).then(res => {
console.log(res)
self.tasks = res.data.tasks
self.pageNum = res.data.pageNum
}) })
}, },
methods: { methods: {
...@@ -70,6 +81,20 @@ export default { ...@@ -70,6 +81,20 @@ export default {
name: 'task', name: 'task',
params: { task: encodeURIComponent(JSON.stringify(task)) } params: { task: encodeURIComponent(JSON.stringify(task)) }
}) })
},
search () {
var self = this
this.axios.get('/task/getTasks', {
params: {
pageSize: self.pageSize,
currentPage: self.currentPage,
keyword: self.keyword
}
}).then(res => {
console.log(res)
self.tasks = res.data.tasks
self.pageNum = res.data.pageNum
})
} }
} }
} }
......
...@@ -5,17 +5,17 @@ ...@@ -5,17 +5,17 @@
<div class="tasklist"> <div class="tasklist">
<div class="task-item" v-for="(item, index) in tasks" :key='index'> <div class="task-item" v-for="(item, index) in tasks" :key='index'>
<div>{{item.name}}</div> <div>{{item.name}}</div>
<div>发布者:{{item.creator}}&emsp;&emsp;发布时间:{{item.date}} <div>发布者:{{item.creator}}&emsp;&emsp;发布时间:{{item.date|formatDate}}
</div> </div>
<el-button class="task-enter-btn1" @click="detail(item)" type="primary" plain>查看任务详情</el-button> <el-button class="task-enter-btn1" @click="detail(item)" type="primary" plain>查看任务详情</el-button>
</div> </div>
</div> </div>
<div class="page-navigator"> <div class="page-navigator">
<el-pagination <el-pagination
:page-size="20" :page-size="pageSize"
:pager-count="11" :page-count="pageNum"
layout="prev, pager, next" :current-page="currentPage"
:total="1000"> layout="prev, pager, next">
</el-pagination> </el-pagination>
</div> </div>
</div> </div>
...@@ -24,29 +24,32 @@ ...@@ -24,29 +24,32 @@
</template> </template>
<script> <script>
const mock = true
if (mock) require('@/mock/api.js')
export default { export default {
name: 'ongoingtask', name: 'ongoingtask',
data () { data () {
return { return {
activeName: '我的任务', activeName: '我的任务',
tasks: [] tasks: [],
pageSize: 10,
currentPage: 1,
pageNum: 0
} }
}, },
mounted () { beforeMount () {
this.axios.get('/getTasks').then(res => { var self = this
this.tasks = res.data this.axios.get('/task/getTasks', {
params: {
pageSize: self.pageSize,
currentPage: self.currentPage,
executor: self.$store.state.userInfo.userId
}
}).then(res => {
console.log(res)
self.tasks = res.data.tasks
self.pageNum = res.data.pageNum
}) })
}, },
methods: { methods: {
handleClick (tab, event) {
console.log(tab, event)
},
deleteRow (index, rows) { // 删除改行
rows.splice(index, 1)
},
detail (task) { detail (task) {
this.$router.push({ this.$router.push({
name: 'ongoingtaskdetail', name: 'ongoingtaskdetail',
...@@ -70,17 +73,6 @@ export default { ...@@ -70,17 +73,6 @@ export default {
background-color: white; background-color: white;
padding: 30px 20px 30px 20px; padding: 30px 20px 30px 20px;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
.filter-container{
.filter-item{
display: flex;
align-items: center;
margin-bottom: 15px;
.filter-input{
margin-left: 20px;
width: 300px;
}
}
}
.tasklist-container{ .tasklist-container{
.tasklist{ .tasklist{
.task-item{ .task-item{
...@@ -109,25 +101,5 @@ export default { ...@@ -109,25 +101,5 @@ export default {
margin-top: 30px; margin-top: 30px;
} }
} }
.taskhall-right{
float: right;
width: 25%;
.notice{
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
margin-bottom: 30px;
.notice-title{
background-color: $theme-color;
color: white;
padding: 10px 0;
}
.notice-body{
background-color: white;
height: 200px;
display: flex;
align-items: center;
justify-content: center;
}
}
}
} }
</style> </style>
...@@ -29,9 +29,13 @@ axios.interceptors.response.use(function (response) { ...@@ -29,9 +29,13 @@ axios.interceptors.response.use(function (response) {
}) })
Vue.use(VueAxios, axios) Vue.use(VueAxios, axios)
Vue.use(ElementUI)
Vue.config.productionTip = false Vue.config.productionTip = false
Vue.use(ElementUI) // 时间过滤器 全局
Vue.filter('formatDate', function (value) {
return value.substr(0, 10)
})
/* eslint-disable no-new */ /* eslint-disable no-new */
new Vue({ new Vue({
......
<<<<<<< HEAD
import Mock from 'mockjs' import Mock from 'mockjs'
Mock.mock('http://localhost:9100/api/getTasks', { Mock.mock('http://localhost:9100/api/getTasks', {
'status': 0, 'status': 0,
...@@ -78,3 +79,35 @@ Mock.mock(/\/api\/file\/getFiles\?pieceId=[0-9]+/, { ...@@ -78,3 +79,35 @@ Mock.mock(/\/api\/file\/getFiles\?pieceId=[0-9]+/, {
}] }]
}) })
=======
import Mock from 'mockjs'
// Mock.mock('http://localhost:9100/api/task/getTasks', {
// 'status': 0,
// 'data|10': [{
// 'id|1-9999': 1,
// 'name|1': ['冰箱物品标注', '新通路图片', '人脸识别', '客服语音', '行人十字画框', '动物打点标注'],
// 'creator|1': ['王强', '赵信良', '李轩辕', '田予欢', '张三', '李斯'],
// 'date': Mock.Random.date('yyyy/MM/dd')
// }]
// })
Mock.mock(/\/api\/getPieces\?id=[0-9]+/, {
'status': 0,
'data|5-10': [{
'id|1-65535': 1,
'fileNum|10-50': 1,
'template|1': ['人脸识别标注模板', '动物标注模板', '本文标注模板', '桥梁标注模板', '植物标注模板'],
'type|1': ['文本', '图片', '图层']
}]
})
Mock.mock(/\/api\/file\/getFiles\?pieceId=[0-9]+/, {
'status': 0,
'data|1-5': [{
'id|1-65535': 1,
'name': '标注文件.xxx',
'size|10-30': 1,
'state|0-1': 1
}]
})
>>>>>>> 60b27bd547f3588270c6c1978b5d5d6f37ad8567
...@@ -11,7 +11,19 @@ mysql = MySQLDatabase( ...@@ -11,7 +11,19 @@ mysql = MySQLDatabase(
mysql.connect() mysql.connect()
class Result:
code: int
message: []
data: {}
def __init__(self, code, message, data):
self.code = code
self.message = message
self.data = data
class Slice(Model): class Slice(Model):
slice_id = AutoField(primary_key=True, unique=True)
task_id = IntegerField(null=False) task_id = IntegerField(null=False)
model_id = CharField(null=True) model_id = CharField(null=True)
illustration = TextField(null=True) illustration = TextField(null=True)
...@@ -25,32 +37,27 @@ class Slice(Model): ...@@ -25,32 +37,27 @@ class Slice(Model):
# 创建分片 # 创建分片
def create_slice(task_id, model_id, document_number, type): def create_slice(task_id, model_id, document_number, type):
if not Slice.table_exists():
Slice.create_table()
try: try:
if Task.find_id(task_id):
slice = Slice(task_id=task_id, model_id=model_id, document_number=document_number, type=type) slice = Slice(task_id=task_id, model_id=model_id, document_number=document_number, type=type)
slice.save() slice.save()
except:
return Result(0, "create failed", {})
else: else:
print(0) return Result(1, "create success", slice.slice_id)
return False
except Exception:
print(0)
else:
print(slice.id)
# 删除分片 # 删除分片
def delete_slice(id): def delete_slice(id):
if not Slice.table_exists():
Slice.create_table()
try: try:
Slice.delete().where(Slice.id == id); Slice.delete().where(Slice.slice_id == id);
except Exception: except:
print(0) return Result(0, "delete failed", {})
else: else:
print(1) return Result(1, "delete success", {})
if __name__ == '__main__': if __name__ == '__main__':
Slice.drop_table()
# 建表
Slice.create_table()
create_slice(1, 5, 10, False) create_slice(1, 5, 10, False)
from peewee import * from peewee import *
from Dao import User from Dao import User
import datetime import datetime
import math
mysql = MySQLDatabase( mysql = MySQLDatabase(
'sys', 'sys',
...@@ -17,11 +18,13 @@ class Result: ...@@ -17,11 +18,13 @@ class Result:
code: int code: int
message: [] message: []
data: {} data: {}
pages: int
def __init__(self, code, message, data): def __init__(self, code, message, data, pages):
self.code = code self.code = code
self.message = message self.message = message
self.data = data self.data = data
self.pages = pages
class Task(Model): class Task(Model):
...@@ -44,31 +47,77 @@ def create_task(publish_id, slice_number, task_name): ...@@ -44,31 +47,77 @@ def create_task(publish_id, slice_number, task_name):
task = Task(publish_id=publish_id, slice_number=slice_number, task_name=task_name) task = Task(publish_id=publish_id, slice_number=slice_number, task_name=task_name)
task.save() task.save()
else: else:
return Result(0, "User not exist", {}) return Result(0, "User not exist", {}, 0)
except: except:
return Result(0, "create failed", {}) return Result(0, "create failed", {}, 0)
else: else:
return Result(1, "create success", {}) return Result(1, "create success", task.task_id, 0)
# 根据任务名称查找任务 # 根据任务名称查找任务
def find_task_by_name(task_name): def find_task_by_name(task_name, start, num):
try: try:
query = Task.select(Task.task_id, Task.task_name, Task.publish_id, Task.publish_time).where(Task.task_name.contains(task_name)).dicts() find = Task.select(Task.task_id, Task.task_name, Task.publish_id, Task.publish_time).where(Task.task_name.contains(task_name))
index = 0
list = []
while index < len(find) and index < num:
list.append(
{
'id': find[index+start].task_id,
'creator': find[index+start].publish_id,
'name': find[index+start].task_name,
'date': find[index+start].publish_time.strftime("%Y-%m-%d %H:%M:%S")
}
)
index += 1
except: except:
return Result(0, "find failed", {}) return Result(0, "find failed", {}, 0)
else: else:
return Result(1, "find success", query) return Result(1, "find success", list, math.ceil(len(find)/num))
# 查找所有任务 # 查找所有任务
def find_task(): def find_task(start, num):
try: try:
query = Task.select(Task.task_id, Task.task_name, Task.publish_id, Task.publish_time).dicts() find = Task.select(Task.task_id, Task.task_name, Task.publish_id, Task.publish_time)
index = 0
list = []
while index < len(find) and index < num:
list.append(
{
'id': find[index+start].task_id,
'creator': find[index+start].publish_id,
'name': find[index+start].task_name,
'date': find[index+start].publish_time.strftime("%Y-%m-%d %H:%M:%S")
}
)
index += 1
except: except:
return Result(0, "find failed", {}) return Result(0, "find failed", {}, 0)
else: else:
return Result(1, "find success", query) return Result(1, "find success", list, math.ceil(len(find)/num))
# 查找与该发布者相关的任务
def find_task_by_creator(creator, start, num):
try:
find = Task.select(Task.task_id, Task.task_name, Task.publish_id, Task.publish_time).where(Task.publish_id == creator)
index = 0
list = []
while index < len(find) and index < num:
list.append(
{
'id': find[index+start].task_id,
'creator': find[index+start].publish_id,
'name': find[index+start].task_name,
'date': find[index+start].publish_time.strftime("%Y-%m-%d %H:%M:%S")
}
)
index += 1
except:
return Result(0, "find failed", {}, 0)
else:
return Result(1, "find success", list, math.ceil(len(find)/num))
# 删除任务 # 删除任务
...@@ -76,13 +125,16 @@ def delete_task(task_id): ...@@ -76,13 +125,16 @@ def delete_task(task_id):
try: try:
Task.delete().where(Task.id == task_id) Task.delete().where(Task.id == task_id)
except: except:
return Result(0, "delete failed", {}) return Result(0, "delete failed", {}, 0)
else: else:
return Result(1, "delete success", {}) return Result(1, "delete success", {}, 0)
if __name__ == '__main__': if __name__ == '__main__':
# 建表
# Task.create_table()
# 添加数据
# Task.create_task(publish_id, slice_number, task_name)
r = find_task() r = find_task()
for row in r.data: for row in r.data:
print(row) print(row)
print(len(r.data))
...@@ -2,27 +2,33 @@ import json ...@@ -2,27 +2,33 @@ import json
from flask import Blueprint from flask import Blueprint
from flask import request from flask import request
from Dao import Task from Dao import Task
import math
task = Blueprint("task", __name__, url_prefix="/api/task") task = Blueprint("task", __name__, url_prefix="/api/task")
@task.route("/getTasks", methods=["GET"]) @task.route("/getTasks", methods=["GET"])
def get_tasks(): def get_tasks():
pageSize = request.args['pageSize'] pageSize = request.args['pageSize']
currentPage = request.args['currentPage'] currentPage = request.args['currentPage']
keyword = request.args['keyword'] keyword = request.args.get('keyword')
executor = request.args.get('executor')
creator = request.args.get('creator')
state = request.args.get('state')
# get函数用于可选参数,在未接收到参数时返回空值
pagesize = int(pageSize) pagesize = int(pageSize)
currentpage = int(currentPage) currentpage = int(currentPage)
if keyword: if keyword:
ret = Task.find_task_by_name(keyword) ret = Task.find_task_by_name(keyword, pagesize*(currentpage-1), pagesize)
elif creator:
ret = Task.find_task_by_creator(creator, pagesize * (currentpage - 1), pagesize)
else: else:
ret = Task.find_task() ret = Task.find_task(pagesize*(currentpage-1), pagesize)
num = len(ret.data)
Num = math.ceil(num/pagesize)
res = { res = {
'code': ret.code, 'code': ret.code,
'message': ret.message, 'message': ret.message,
'tasks': json.dumps(ret.data), 'data': {
'pageNum': Num 'tasks': ret.data,
'pageNum': ret.pages
}
} }
return json.dumps(res) return json.dumps(res)
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