新增图片管理 定义文档

This commit is contained in:
pengtao 2019-09-06 17:42:01 +08:00
parent 49625478a4
commit 9d1b3b8a45
2 changed files with 294 additions and 0 deletions

141
handler/priv_map.py Normal file
View File

@ -0,0 +1,141 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from flask import Flask, jsonify
from flask_restful import reqparse, abort, Api, Resource
import logging
from mysql.mmysql import MysqlBase
from prod_config import mysql_promotion_config
import pdb
log = logging.getLogger(__name__)
parser = reqparse.RequestParser()
parser.add_argument('id')
parser.add_argument('name')
parser.add_argument('contact')
parser.add_argument('appid')
parser.add_argument('appkey')
parser.add_argument('status')
parser.add_argument('tel')
parser.add_argument('user')
class Company(Resource):
def __init__(self):
self.args = parser.parse_args()
self.mydb = MysqlBase(**mysql_promotion_config)
def get(self):
status = self.args['status']
id = self.args['id']
user = self.args['user']
all_data = []
try:
if status:
sql = f"select id,name,contact,tel,appid,appkey,status,user from company where status={status};"
elif id:
sql = f"select id,name,contact,tel,appid,appkey,status,user from company where id={id};"
elif user:
sql = f"select id,name,contact,tel,appid,appkey,status,user from company where user='{user}';"
else:
sql = f"select id,name,contact,tel,appid,appkey,status,user from company ;"
data = self.mydb.query(sql)
log.info(f"get data from db was {data}")
if data:
for line in data:
if line:
company = {}
company['id'], company['name'], company['contact'], company['tel'], company['appid'], company[
'appkey'], company['status'], company['user'] = line
all_data.append(company)
del company
else:
log.info(f"{data} not found in mysql !")
return jsonify({'code': 200, 'message': []})
except Exception:
log.error(f"get company status={status} failed! ", exc_info=True)
return jsonify({'code': 500})
return jsonify({'code': 200, 'message': all_data})
def delete(self):
id = self.args['id']
try:
del_sql = f'update ad set in_used=0 where id={id};'
self.mydb.change(del_sql)
except Exception:
log.error(f"remove {id} failed!", exc_info=True)
return jsonify({'code': 500})
return jsonify({'code': 200})
def get_random(self, num=8):
import random
import string
return ''.join(random.sample(string.ascii_letters + string.digits, num))
def get_appid(self):
appid = self.get_random()
# check appid not in db
check_appid = f"select appid from company where appid='{appid}'"
data = self.mydb.query(check_appid)
if data:
self.get_appid()
return appid
def get_companyid(self):
max_id = f"select id from company order by id desc limit 1"
data = self.mydb.query(max_id)
log.info(f"1 {data}")
try:
max = int(data[0][0]) + 1
log.info(f"max id was {max}!")
except Exception:
log.error(f"error with get company id ", exc_info=True)
max = 1001
return max
def post(self):
try:
company = {}
company['name'] = self.args['name']
company['contact'] = self.args['contact']
company['tel'] = self.args['tel']
company['user'] = self.args['user']
company['id'] = self.get_companyid()
company['appid'] = self.get_appid()
company['appkey'] = 'undefined'
self.mydb.insert("company", company)
except Exception:
log.error("set values to company mysql failed!", exc_info=True)
return jsonify({'code': 500})
return jsonify({'code': 200})
def put(self):
try:
company = {}
company['id'] = self.args['id']
company['name'] = self.args['name']
company['contact'] = self.args['contact']
company['tel'] = self.args['tel']
company['user'] = self.args['user']
company['status'] = self.args['status'] or 0
company['appid'] = self.args['appid']
company['appkey'] = self.args['appkey']
sel_sql = f"select name from company where id={self.args['id']};"
data = self.mydb.query(sel_sql)
if data:
condition = f"id='{self.args['id']}'"
self.mydb.update("company", company, condition)
return jsonify({'code': 200})
else:
return jsonify({'code': 404, 'message': f"{self.args['id']} not found in mysql!"})
except Exception:
log.error("update values to company mysql failed!", exc_info=True)
return jsonify({'code': 500})

153
priv_maps.md Normal file
View File

@ -0,0 +1,153 @@
### 图库管理接口文档
管理账号及图片的信息,基于账号返回图片列表
TODO
#### 1、获得图片列表
##### 接口地址
http://154.8.214.202:5015/interface/maps
##### 返回格式json
##### 请求方式get
##### 请求示范
http://154.8.214.202:5015/maps
http://154.8.214.202:5015/interface/maps?user=xxx
##### 请求参数说明
| 名称 | 类型 | 必填 | 说明 |
| ---- | ----- | ---- | ------------------------ |
| user | vchar | 是 | 账号信息 |
| | | | 上述参数为空返回所有信息 |
##### 返回参数说明
| 名称 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------- |
| mapid | int | 否 | 自动产生的图片ID |
| user | string | 是 | 账号 |
| url | string | 是 | 图片存放的URL地址 |
##### 返回示例
{
"code": 200,
"message": [
{
“url”:'xxxx',
"user": "None"
}
]
}
#### 2、新增图片信息
##### 接口地址
http://154.8.214.202:5015/interface/maps
##### 返回格式json
##### 请求方式post
##### 请求示范
http://154.8.214.202:5015/interface/company?
##### 请求参数说明
| 名称 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | -------- |
| url | string | 是 | 联系电话 |
| user | string | 是 | 登录账号 |
##### 返回参数说明
| 名称 | 类型 | 必填 | 说明 |
| ---- | ---- | ---- | -------- |
| code | int | 是 | 返回状态 |
| | | | |
##### 返回示例
{
"code": 200
}
#### 3、更改公司信息
##### 接口地址
http://154.8.214.202:5015/interface/mpas
##### 返回格式json
##### 请求方式put
##### 请求示范
http://154.8.214.202:5015/interface/company?appid=zpoHY37u&appkey=undefined&contact=miles001&id=1006&name=kingsome&status=1&tel=17771&user=assd
##### 请求参数说明
| 名称 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | -------------- |
| user | string | 是 | 登录账号 |
| mapid | int | 是 | 图片id(唯一值) |
| url | string | 是 | 图片存放地址 |
##### 返回参数说明
| 名称 | 类型 | 必填 | 说明 |
| ---- | ---- | ---- | -------- |
| code | int | 是 | 返回状态 |
| | | | |
##### 返回示例
{
"code": 200
}
#### 4、删除图片信息
##### 接口地址
http://154.8.214.202:5015/interface/maps
##### 返回格式json
##### 请求方式delete
##### 请求示范
http://154.8.214.202:5015/interface/maps
##### 请求参数说明
| 名称 | 类型 | 必填 | 说明 |
| ----- | ---- | ---- | -------------- |
| mapid | int | 是 | 图片id(唯一值) |
##### 返回参数说明
| 名称 | 类型 | 必填 | 说明 |
| ---- | ---- | ---- | -------- |
| code | int | 是 | 返回状态 |
| | | | |
##### 返回示例
{
"code": 200
}