Commit 6df67ee0 by yanglei

update

parent 7b2fe02d
...@@ -118,22 +118,23 @@ def machine_query(): ...@@ -118,22 +118,23 @@ def machine_query():
user_info = Management.query.filter_by().first() user_info = Management.query.filter_by().first()
if not user_info: if not user_info:
return TOKEN_NOT_VALID_ERROR return TOKEN_NOT_VALID_ERROR
if "machine_no" in json_date: machine_no = json_date["machine_no"] if "machine_no" in json_date else ""
machine_no = json_date["machine_no"] machine_mac = json_date["machine_mac"] if "machine_mac" in json_date else ""
query1 = "select a.* ,b.management_id FROM machine as a JOIN management_machine as b ON " \ place_name = json_date["place_name"] if "place_name" in json_date else ""
"a.machine_no = b.machine_no WHERE management_id='{}' and a.machine_no like '{}' limit {},{}".\ if "status" in json_date:
format(user_id, "%"+machine_no+"%", (page-1)*page_size, page*page_size) status = json_date["status"]
elif "machine_mac" in json_date:
machine_mac = json_date["machine_mac"]
# machine_result = Machine.query.filter(Machine.mac.like("%"+machine_mac+"%")).offset((page-1)*page_size).limit(page_size)
query1 = "select a.* ,b.management_id FROM machine as a JOIN management_machine as b ON " \ query1 = "select a.* ,b.management_id FROM machine as a JOIN management_machine as b ON " \
"a.machine_no = b.machine_no WHERE management_id='{}' and mac like '{}' limit {},{}". \ "a.machine_no = b.machine_no WHERE management_id='{}' and a.machine_no like '{}' and " \
format(user_id, "%"+machine_mac+"%", (page - 1) * page_size, page * page_size) "a.mac like '{}' and a.address like '{}' and a.status ={} limit {},{}".\
format(user_id, "%"+machine_no+"%", "%"+machine_mac+"%", "%"+place_name+"%", status,
(page-1)*page_size, page*page_size)
else: else:
query1 = "select a.* ,b.management_id FROM machine as a JOIN management_machine as b ON " \ query1 = "select a.* ,b.management_id FROM machine as a JOIN management_machine as b ON " \
"a.machine_no = b.machine_no WHERE management_id={} limit {},{}". \ "a.machine_no = b.machine_no WHERE management_id='{}' and a.machine_no like '{}' and " \
format(user_id, (page - 1) * page_size, page * page_size) "a.mac like '{}' and a.address like '{}' limit {},{}". \
machine_result =db.session.execute(query1).fetchall() format(user_id, "%" + machine_no + "%", "%" + machine_mac + "%", "%" + place_name + "%",
(page - 1) * page_size, page * page_size)
machine_result = db.session.execute(query1).fetchall()
result_date = [] result_date = []
# # 将数据遍历和筛选 # # 将数据遍历和筛选
for i in machine_result: for i in machine_result:
......
...@@ -11,7 +11,7 @@ from config.commen_config import LOGIN_TYPE ...@@ -11,7 +11,7 @@ from config.commen_config import LOGIN_TYPE
from models.base_model import db from models.base_model import db
from models.models import TallymanAccount, TallymanMachine, TallymanLoginRecord, Machine, Hatch, TallyRecord,\ from models.models import TallymanAccount, TallymanMachine, TallymanLoginRecord, Machine, Hatch, TallyRecord,\
TallymanPlace, Management TallymanPlace, Management, TallymanMachine
from service.tallyman_service import TallymanService from service.tallyman_service import TallymanService
from utils.error_code import TALLYMAN_ACCOUNT_EXIST, PHONE_NOT_VALID_ERROR, TOKEN_NOT_VALID_ERROR, PASSWORD_ERROR, \ from utils.error_code import TALLYMAN_ACCOUNT_EXIST, PHONE_NOT_VALID_ERROR, TOKEN_NOT_VALID_ERROR, PASSWORD_ERROR, \
TALLYMAN_ACCOUNT_NOT_EXIST, MACHINE_NOT_EXIST_ERROR, HATCH_NOT_EXIST_ERROR, MACHINE_ACTIVATED_ERROR,\ TALLYMAN_ACCOUNT_NOT_EXIST, MACHINE_NOT_EXIST_ERROR, HATCH_NOT_EXIST_ERROR, MACHINE_ACTIVATED_ERROR,\
...@@ -86,11 +86,20 @@ def tallyman(): ...@@ -86,11 +86,20 @@ def tallyman():
if not user_res: if not user_res:
return TOKEN_NOT_VALID_ERROR return TOKEN_NOT_VALID_ERROR
# 多表查询 # 多表查询
if "status" in json_date:
status = json_date["status"]
query1 = "SELECT a.*,b.management_id,c.place_id , d.place_name FROM ((tallyman_account as a JOIN " \ query1 = "SELECT a.*,b.management_id,c.place_id , d.place_name FROM ((tallyman_account as a JOIN " \
"management_tallyman as b on a.id = b.tallyman_id) JOIN tallyman_place as c on c.user_id = a.id) " \ "management_tallyman as b on a.id = b.tallyman_id) JOIN tallyman_place as c on c.user_id = a.id) " \
"JOIN place as d ON d.id = c.place_id WHERE b.management_id = {} and a.user_name like '{}' and" \ "JOIN place as d ON d.id = c.place_id WHERE b.management_id = {} and a.user_name like '{}' and" \
" d.place_name like '{}' limit {},{}"\ " d.place_name like '{}' and a.status = {} LIMIT {},{}" \
.format(user_id, "%"+tallyman+"%", "%"+place_name+"%", (page-1)*page_size, page*page_size) .format(user_id, "%" + tallyman + "%", "%" + place_name + "%", status,(page - 1) * page_size, page * page_size)
else:
query1 = "SELECT a.*,b.management_id,c.place_id , d.place_name FROM ((tallyman_account as a JOIN " \
"management_tallyman as b on a.id = b.tallyman_id) JOIN tallyman_place as c on c.user_id = a.id) " \
"JOIN place as d ON d.id = c.place_id WHERE b.management_id = {} and a.user_name like '{}' and" \
" d.place_name like '{}' LIMIT {},{}" \
.format(user_id, "%" + tallyman + "%", "%" + place_name + "%", (page - 1) * page_size,
page * page_size)
tallyman_result = db.session.execute(query1).fetchall() tallyman_result = db.session.execute(query1).fetchall()
result_date = [] result_date = []
for i in tallyman_result: for i in tallyman_result:
...@@ -128,4 +137,24 @@ def edit_man(): ...@@ -128,4 +137,24 @@ def edit_man():
db.session.add(man_result) db.session.add(man_result)
return BaseResponse(date={"success": True}) return BaseResponse(date={"success": True})
# 为补货员添加机器 # 为补货员添加机器,需要tally_id,machine,place_id
\ No newline at end of file @tallyman_route.route("/give_machine", methods=["POST"])
def for_machine():
json_date = request.get_json()
tallyman_id = json_date["tallyman_id"]
machine = json_date["machine"]
place_id = json_date["place_id"]
for i in machine:
tallYman_machine = TallymanMachine()
tallYman_machine.user_id = tallyman_id
tallYman_machine.machine_no = i
tallYman_machine.status = 1
db.session.add(tallYman_machine)
db.session.commit()
tallyman_place = TallymanPlace()
tallyman_place.place_id = place_id
tallyman_place.user_id = tallyman_id
tallyman_place.status = 1
db.session.add(tallyman_place)
db.session.commit()
return BaseResponse(date={"success": True})
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