Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download
RobotPreset.py 3.46 KB
Copy Edit Web IDE Raw Blame History
fzc authored 2019-08-14 10:34 . 预置点信息提交
from flask_restful import Resource
from auth import auth
from flask import abort, request, jsonify, g, url_for
from user import User
from api import app
from flask_sqlalchemy import SQLAlchemy
from api import app
import json
db = SQLAlchemy(app)
class Preset(db.Model):
__tablename__ = 'robot_preset'
ID = db.Column(db.Integer,primary_key=True,nullable=False,unique=True)
position = db.Column(db.Float,nullable=False,default=0.00)
cameraState = db.Column(db.Integer,nullable=False,default=0)
rodState = db.Column(db.String(10),nullable=False,default='')
speed = db.Column(db.Float,nullable=False,default=0.00)
charge = db.Column(db.Integer,nullable=False,default=0)
stayTime = db.Column(db.Integer,nullable=False,default=0)
def to_json(self):
return {
"ID":self.ID,
"position":self.position,
"cameraState":self.cameraState,
"rodState":self.rodState,
"speed":self.speed,
"charge":self.charge,
"stayTime":self.stayTime
}
class RobotPresetList(Resource):
def get(self):
msg = {}
data = []
page = request.args.get('page')
page_size = request.args.get('page_size')
if (int(page) < 0 or int(page_size) <= 0):
msg['code'] = -1
msg['msg'] = 'params is error'
else:
list_data = Preset.query.order_by(Preset.ID).limit(page_size).offset(int(page) * int(page_size))
list_count = Preset.query.count()
for i in list_data:
data.append(i.to_json())
msg['code'] = 200
msg['data'] = {
'count' : list_count,
'list_data' : data
}
msg['msg'] = 'success'
return msg
class AddPreset(Resource):
def post(self):
msg = {}
data = []
#json_data = json.loads(request.get_data())
position = float(request.args.get('position'))
cramera_state = int(request.args.get('cramera_state'))
rod_state = request.args.get('rod_state')
speed = float(request.args.get('speed'))
charge = int(request.args.get('charge'))
stay_time = int(request.args.get('stay_time'))
if( charge == 1 and speed > 0):
msg['code'] = -1
msg['msg'] = 'params is error'
elif( charge == 1 and stay_time <= 0):
msg['code'] = -1
msg['msg'] = 'params is error'
else:
preset = Preset( position = position, cameraState = cramera_state, rodState = rod_state, speed = speed, charge = charge,stayTime = stay_time)
try:
db.session.add(preset)
db.session.commit()
msg['code'] = 200
msg['msg'] = 'success'
except Exception as e:
db.session.rollback()
msg['code'] = 500
msg['msg'] = 'server error'
return msg
class DeletePreset(Resource):
def get(self):
msg = {}
data = []
ID = request.args.get('id')
try:
preset = Preset.query.filter( Preset.ID == ID ).first()
db.session.delete(preset)
db.session.commit()
except Exception as e:
db.session.rollback()
msg['code'] = 500
msg['msg'] = 'no recond'
else:
msg['code'] = 200
msg['msg'] = 'success'
return msg

Comment ( 0 )

Sign in for post a comment