|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
@Date:2022/07/29 09:03:39
|
|
|
|
'''
|
|
|
|
from flask import Blueprint, jsonify, request
|
|
|
|
from Common.Utils import Utils, PageParam
|
|
|
|
from db_logic.client import BllClient
|
|
|
|
from Common.auth import token_auth
|
|
|
|
from models.client_models import EntityClient
|
|
|
|
|
|
|
|
client_router = Blueprint("client", __name__)
|
|
|
|
|
|
|
|
|
|
|
|
# 查看client列表
|
|
|
|
@client_router.route("/client_list", methods=["POST"])
|
|
|
|
@token_auth.login_required
|
|
|
|
def get_client_list():
|
|
|
|
data = BllClient().get_all_client_list()
|
|
|
|
data_list = Utils.msyql_table_model(data)
|
|
|
|
return jsonify(Utils.true_return(data={"data_list": data_list}))
|
|
|
|
|
|
|
|
|
|
|
|
# 查看列表
|
|
|
|
@client_router.route("/get_list", methods=["GET","POST"])
|
|
|
|
# @token_auth.login_required
|
|
|
|
def getclient_list():
|
|
|
|
seach_word = request.values.get("seach_word")
|
|
|
|
page = request.values.get("page", 1)
|
|
|
|
page_size = request.values.get("page_size", 100)
|
|
|
|
page_param = PageParam(int(page), int(page_size))
|
|
|
|
data = BllClient().get_client_seach(
|
|
|
|
seach_word=seach_word, page_param=page_param
|
|
|
|
)
|
|
|
|
data_list = Utils.msyql_table_model(data)
|
|
|
|
return jsonify(Utils.true_return(data={"data_list": data_list, "total_count": page_param.totalRecords}))
|
|
|
|
|
|
|
|
|
|
|
|
# 新增and编辑
|
|
|
|
@client_router.route("/add_or_update", methods=["GET", "POST"])
|
|
|
|
# @token_auth.login_required
|
|
|
|
def client_add_update():
|
|
|
|
finds = [
|
|
|
|
"client_title", "client_code", "client_type", "place", "filter_production_date",
|
|
|
|
"filter_shelf_life_warning_value", "contact_people_name", "contact_phone", "description"
|
|
|
|
]
|
|
|
|
client_id = request.values.get("client_id")
|
|
|
|
obj = BllClient().findEntity(
|
|
|
|
EntityClient.client_code == request.values.get("client_code")
|
|
|
|
)
|
|
|
|
if client_id:
|
|
|
|
client_obj = BllClient().findEntity(
|
|
|
|
EntityClient.client_id==client_id
|
|
|
|
)
|
|
|
|
if obj:
|
|
|
|
if client_obj.client_id != obj.client_id:
|
|
|
|
return jsonify(Utils.false_return())
|
|
|
|
for i in finds:
|
|
|
|
setattr(client_obj, i, request.values.get(i))
|
|
|
|
BllClient().update(client_obj)
|
|
|
|
return jsonify(Utils.true_return(msg="修改成功"))
|
|
|
|
else:
|
|
|
|
if obj:
|
|
|
|
return jsonify(Utils.false_return(msg="柜体需要不能重复"))
|
|
|
|
client_obj = EntityClient()
|
|
|
|
for i in finds:
|
|
|
|
setattr(client_obj, i, request.values.get(i))
|
|
|
|
|
|
|
|
BllClient().insert(client_obj)
|
|
|
|
return jsonify(Utils.true_return(msg="添加成功"))
|
|
|
|
|
|
|
|
# 锁定或解锁柜体
|
|
|
|
@client_router.route("/update_status", methods=["GET", "POST"])
|
|
|
|
# @token_auth.login_required
|
|
|
|
def update_status():
|
|
|
|
status_type = request.values.get("status_type")
|
|
|
|
client_id = request.values.get("client_id")
|
|
|
|
obj = BllClient()
|
|
|
|
client_obj = obj.findEntity(EntityClient.client_id == client_id)
|
|
|
|
if client_obj:
|
|
|
|
client_obj.is_enabled=status_type
|
|
|
|
obj.update(client_obj)
|
|
|
|
return jsonify(Utils.true_return(msg="修改成功"))
|
|
|
|
else:
|
|
|
|
return jsonify(Utils.false_return("柜体不存在"))
|