206 lines
7.6 KiB
Python
206 lines
7.6 KiB
Python
import redis, os, sys,requests,platform,json
|
|
if platform.system() == 'Windows':
|
|
sys.path.append('E:\\make2\\libs\\')
|
|
#sys.path.append('libs')
|
|
else:
|
|
sys.path.append('/data/deploy/make3d/make2/libs/')
|
|
import config, libs,libs_db,libs_db_task_rc
|
|
|
|
def main(cmd, order_id):
|
|
if cmd == 'print': #order_id
|
|
key = 'model:printOrder'
|
|
elif cmd == 'repair': #reqpair_order_id
|
|
key = 'model:IndependentRepairTeamcheckGLBQueue'
|
|
elif cmd == 'make3d': #pid
|
|
key = 'model:make'
|
|
elif cmd == 'make3d10': #pid
|
|
key = 'model:make10'
|
|
elif cmd == 'foot': # print_id
|
|
key = 'model:foot'
|
|
elif cmd == 'rebuild': #pid
|
|
key = 'model:rebuild'
|
|
elif cmd == 'gs':
|
|
key = 'ai:ai_build'
|
|
elif cmd == 'gs_normals_image':
|
|
key="model:gs_normals_image"
|
|
|
|
if order_id == 'view':
|
|
if cmd == "rc_model_build":
|
|
nums = libs_db_task_rc.get_task_rc_count()
|
|
print(f'当前{cmd}队列长度:{nums}')
|
|
notify(f'当前{cmd}队列长度:{nums}')
|
|
else:
|
|
print(f"key-{key}")
|
|
print(f'当前{cmd}队列长度:{r.llen(key)}')
|
|
notify(f'当前{cmd}队列长度:{r.llen(key)}')
|
|
|
|
|
|
for i in r.lrange(key, 0, -1):
|
|
print(i)
|
|
print(f'当前{key}队列长度:{r.llen(key)}')
|
|
else:
|
|
order_ids = order_id.split(',')
|
|
for order_id in order_ids:
|
|
r.lpush(key, order_id)
|
|
print(f'已推送{order_id}到{key}, 当前队列长度:{r.llen(key)}')
|
|
|
|
|
|
def notify(content):
|
|
|
|
if content == "":
|
|
return "content 不能为空"
|
|
|
|
for user_agent_id in config.notify_user_Ids:
|
|
data = {
|
|
'userId': user_agent_id,
|
|
'message': content,
|
|
}
|
|
headers = {'Content-Type': 'application/json'}
|
|
message_send_url = "https://mp.api.suwa3d.com/api/qyNotify/sendMessage?userId="+user_agent_id+"&message="+content
|
|
response = requests.post(message_send_url, data=json.dumps(data), headers=headers)
|
|
|
|
|
|
|
|
def cmd(cmdName,pid):
|
|
if pid == "view":
|
|
key = ""
|
|
if cmdName == 'print': #order_id
|
|
key = 'model:printOrder'
|
|
elif cmdName == 'repair': #repair_order_id
|
|
key = 'model:IndependentRepairTeamcheckGLBQueue'
|
|
elif cmdName == 'make3d': #pid
|
|
key = 'model:make'
|
|
elif cmdName == 'make3d10': #pid
|
|
key = 'model:make10'
|
|
elif cmdName == 'foot': # print_id
|
|
key = 'model:foot'
|
|
|
|
if pid == 'view':
|
|
temp = ""
|
|
for i in r.lrange(key, 0, -1):
|
|
print(i)
|
|
temp += i.decode('utf-8') + ","
|
|
print(temp)
|
|
print(f'当前{cmd}队列长度:{r.llen(key)}')
|
|
notify(f'当前{cmd}队列长度:{r.llen(key)}')
|
|
exit()
|
|
else:
|
|
# for i in r.lrange(key, 0, -1):
|
|
# print(i)
|
|
print(f'当前{key}队列长度:{r.llen(key)}')
|
|
exit()
|
|
|
|
res = requests.get(f'https://mp.api.suwa3d.com/api/infoQuery/infoByPid?pid={pid}&cmd={cmdName}')
|
|
#获取res 的数据
|
|
res = res.json()
|
|
if res["code"] != 1000:
|
|
print("查询失败",res)
|
|
exit(1)
|
|
data = res["data"]
|
|
|
|
if cmdName == 'print':
|
|
#需要去吃查询pid 对应的order_id
|
|
#遍历data
|
|
for i in data:
|
|
#获取 pid 对应的数据
|
|
tempData = data[i]
|
|
if len(tempData) == 1:
|
|
#pid 只有对应的一笔数据就可以直接插入了
|
|
main(cmdName, str(tempData[0]["order_id"]))
|
|
else:
|
|
while True:
|
|
try:
|
|
|
|
tempDataStrings = listDataToStr(tempData,cmdName)
|
|
order_id = int(input("pid-"+i+"对应有多个数据,请从下列中选择正确的order_id填入\r\n"+tempDataStrings+"\r\n->"))
|
|
# 在这里处理用户输入的整数
|
|
print("输入的是: ", order_id)
|
|
main(cmdName, str(order_id))
|
|
break
|
|
except ValueError:
|
|
print("输入不满足要求,请重新输入")
|
|
elif cmdName == "repair":
|
|
#需要去吃查询pid 对应的repair_order_id
|
|
#遍历data
|
|
for i in data:
|
|
#获取 pid 对应的数据
|
|
tempData = data[i]
|
|
if len(tempData) == 1:
|
|
#pid 只有对应的一笔数据就可以直接插入了
|
|
main(cmdName, str(tempData[0]["model_repair_order_id"]))
|
|
else:
|
|
while True:
|
|
try:
|
|
tempDataStrings = listDataToStr(tempData,cmdName)
|
|
model_repair_order_id = int(input("pid-"+i+"对应有多个数据,请从下列中选择正确的model_repair_order_id填入\r\n"+tempDataStrings+"\r\n->"))
|
|
# 在这里处理用户输入的整数
|
|
print("输入的是: ", model_repair_order_id)
|
|
main(cmdName, str(model_repair_order_id))
|
|
break
|
|
except ValueError:
|
|
print("输入不满足要求,请重新输入")
|
|
elif cmdName == 'foot':
|
|
|
|
#遍历data
|
|
for i in data:
|
|
#获取 pid 对应的数据
|
|
tempData = data[i]
|
|
if len(tempData) == 1:
|
|
print("tempData",tempData)
|
|
#pid 只有对应的一笔数据就可以直接插入了
|
|
main(cmdName, str(tempData[0]["print_id"]))
|
|
else:
|
|
while True:
|
|
try:
|
|
#tempData 转字符串
|
|
tempDataStrings = listDataToStr(tempData,cmdName)
|
|
printId = int(input("pid-"+i+"对应有多个数据,请从下列中选择正确的print_id填入\r\n"+tempDataStrings+"\r\n->"))
|
|
# 在这里处理用户输入的整数
|
|
print("输入的是: ", printId)
|
|
main(cmdName, str(printId))
|
|
break
|
|
except ValueError:
|
|
print("输入不满足要求,请重新输入")
|
|
else:
|
|
print("不支持的命令",cmdName)
|
|
|
|
def listDataToStr(data,cmdName):
|
|
strMessage = ""
|
|
for i in data:
|
|
if cmdName == "foot":
|
|
strMessage += i['createTime']+" print_id:"+str(i['print_id'])+"\r\n"
|
|
elif cmdName == "repair":
|
|
strMessage += i['createTime']+" model_repair_order_id:"+str(i['model_repair_order_id'])+"\r\n"
|
|
else:
|
|
strMessage += i['createTime']+" order_id:"+str(i['order_id'])+"\r\n"
|
|
return strMessage
|
|
|
|
|
|
if __name__ == '__main__':
|
|
r = config.redis_remote
|
|
if len(sys.argv) == 3:
|
|
cmdName = sys.argv[1]
|
|
pid = sys.argv[2]
|
|
|
|
elif len(sys.argv) == 2:
|
|
cmd = sys.argv[1]
|
|
order_id = 'view'
|
|
if cmd == "auto_view":
|
|
arrCmd = ["print","foot","gs","rc_model_build","gs_normals_image"]
|
|
for cmdV in arrCmd:
|
|
main(cmdV, order_id)
|
|
|
|
exit(1)
|
|
else:
|
|
print('用法:python push_cmd.py <cmd> <order_id>')
|
|
exit(1)
|
|
|
|
|
|
#pid 可能是多个的,用逗号分隔,查询的时候接口应该也要支持多个的
|
|
if cmdName == 'make3d' or cmdName == 'make3d10' or cmdName == 'rebuild':
|
|
main(cmdName, pid)
|
|
elif cmd != "":
|
|
cmd(cmdName,pid)
|
|
else:
|
|
print('用法:python push_cmd.py <cmd> <order_id>')
|
|
exit(1) |