影棚与地贴的关联 和 走新建模系统 通过数据库来连接

This commit is contained in:
dongchangxi committed 2023-10-16 15:07:43 +08:00
1 parent e69bb31be2
commit ae779d7d00
7 files changed
+63 -35

No files matched your search

+55 -27
View File
@@ -2,16 +2,20 @@
import pymysql, socket, time
import config
# 获取新的任务
def get_task(task_type):
try:
with pymysql.connect(
#公共连接库
def pymysqlAlias():
return pymysql.connect(
host=config.mysql_local['host'],
port=config.mysql_local['port'],
user=config.mysql_local['user'],
password=config.mysql_local['password'],
db=config.mysql_local['db'],
charset=config.mysql_local['charset'],) as conn:
charset=config.mysql_local['charset'],)
# 获取新的任务
def get_task(task_type):
try:
with pymysqlAlias() as conn:
cursor = conn.cursor()
sql = f'select task_key from tasks where task_type = "{task_type}" and status = 0 order by priority desc, id asc limit 1'
@@ -29,13 +33,7 @@ def get_task(task_type):
# 新增新的任务
def add_task(data):
try:
with pymysql.connect(
host=config.mysql_local['host'],
port=config.mysql_local['port'],
user=config.mysql_local['user'],
password=config.mysql_local['password'],
db=config.mysql_local['db'],
charset=config.mysql_local['charset'],) as conn:
with pymysqlAlias() as conn:
cursor = conn.cursor()
#判断是否是昆山教学的,是的话优先级设置为默认
@@ -55,13 +53,7 @@ def add_task(data):
# 开始任务
def start_task(data):
try:
with pymysql.connect(
host=config.mysql_local['host'],
port=config.mysql_local['port'],
user=config.mysql_local['user'],
password=config.mysql_local['password'],
db=config.mysql_local['db'],
charset=config.mysql_local['charset'],) as conn:
with pymysqlAlias() as conn:
cursor = conn.cursor()
hostname = socket.gethostname()
@@ -75,13 +67,7 @@ def start_task(data):
# 完成任务
def finish_task(data):
try:
with pymysql.connect(
host=config.mysql_local['host'],
port=config.mysql_local['port'],
user=config.mysql_local['user'],
password=config.mysql_local['password'],
db=config.mysql_local['db'],
charset=config.mysql_local['charset'],) as conn:
with pymysqlAlias() as conn:
cursor = conn.cursor()
hostname = socket.gethostname()
@@ -90,4 +76,46 @@ def finish_task(data):
cursor.execute(sql)
conn.commit()
except Exception as e:
print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行finish_task({data})异常: {str(e)}")
print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行finish_task({data})异常: {str(e)}")
# 根据影棚ID 获取影棚的配置,如果没有指定的配置,则返回默认配置
def get_floor_sticker_distances(psid,is_default = False):
try:
with pymysqlAlias() as conn:
cursor = conn.cursor()
sql = f'select a.studio_id,value from floor_sticker_link_studio as a left join floor_sticker_distances as b on a.floor_name = b.name where a.studio_id in (0,{psid})'
# print(f'sql: {sql}')
cursor.execute(sql)
result = cursor.fetchall()
if is_default:
return result[0]["value"]
if len(result) == 1:
return result[0]["value"]
if len(result) == 2:
for item in result:
if item["studio_id"] == psid:
return item["value"]
return "error-配置异常,该影棚有多个地贴配置"
except Exception as e:
print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行get_floor_sticker_distances()异常: {str(e)}")
return "error"
#判断是否要走新的建模系统
def is_new_make_psid(psid):
try:
with pymysqlAlias() as conn:
cursor = conn.cursor()
sql = f'select count(*) from new_make_psid where studio_id = {psid}'
print(f'sql: {sql}')
cursor.execute(sql)
result = cursor.fetchone()
if result[0] > 0:
return True
else:
return False
except Exception as e:
print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行is_new_make_psid()异常: {str(e)}")
return "error"