优化涉及到的接口

This commit is contained in:
jinling.yang
2023-01-11 11:05:06 +08:00
50 changed files with 1351 additions and 161 deletions

View File

@@ -20,44 +20,32 @@ class Sf_Mrs_Connect(http.Controller):
"""
logging.info('get_cnc_processing_create:%s' % kw)
try:
res = {'status': 1, 'message': '成功'}
datas = request.httprequest.data
ret = json.loads(datas)
ret = json.loads(ret['result'])
for obj in ret:
cnc = request.env['sf.cnc.processing'].with_user(
request.env.ref("base.user_admin")).cnc_processing_create(obj)
# # 从ftp拉取对应的文件
model_code = cnc.workorder_id.product_id.barcode
processing_panel = cnc.workorder_id.processing_panel
logging.info('model_code:%s' % model_code)
server_dir = cnc.with_user(request.env.ref("base.user_admin")).download_file_tmp(model_code,
processing_panel)
# cnc_file_path = os.path.join('/', server_dir, cnc.program_name + '.nc')
# logging.info('cnc_file_path:%s' % cnc_file_path)
# cnc.with_user(request.env.ref("base.user_admin")).write_file(cnc_file_path, cnc)
logging.info('server_dir:%s' % server_dir)
for root, dirs, files in os.walk(server_dir):
for f in files:
logging.info('f:%s' % f)
logging.info('f[0]:%s' % f.split('.')[0])
if os.path.splitext(f)[1] == ".pdf":
full_path = os.path.join(server_dir, root, f)
logging.info('pdf:%s' % full_path)
if full_path != False:
if not cnc.workorder_id.cnc_worksheet:
cnc.workorder_id.cnc_worksheet = base64.b64encode(open(full_path, 'rb').read())
else:
logging.info('break:%s' % 'break')
continue
else:
logging.info('cnc.program_name:%s' % cnc.program_name)
if cnc.program_name == f.split('.')[0]:
logging.info('f[0]:%s' % f[0])
cnc_file_path = os.path.join(server_dir, root, f)
logging.info('cnc_file_path:%s' % cnc_file_path)
cnc.with_user(request.env.ref("base.user_admin")).write_file(cnc_file_path, cnc)
else:
continue
# 查询状态为进行中且类型为获取CNC加工程序的工单
cnc_workorder = request.env['mrp.workorder'].with_user(
request.env.ref("base.user_admin")).search([('production_id.name', '=', ret['production_order_no']),
('routing_type', '=', '获取CNC加工程序')])
if cnc_workorder:
# 拉取所有加工面的程序文件
# i = 1
for r in ret['processing_panel']:
download_state = request.env['sf.cnc.processing'].with_user(
request.env.ref("base.user_admin")).download_file_tmp(
ret['folder_name'], r)
if download_state == False:
res['status'] = -2
res['message'] = '制造订单号为%s的CNC程序文件从FTP拉取失败' % (cnc_workorder.production_id.name)
return json.JSONEncoder().encode(res)
request.env['sf.cnc.processing'].with_user(
request.env.ref("base.user_admin")).cnc_processing_create(cnc_workorder, ret)
return json.JSONEncoder().encode(res)
else:
res = {'status': 0, 'message': '该制造订单暂未开始'}
return json.JSONEncoder().encode(res)
except Exception as e:
res = {'status': -1, 'message': '系统解析失败'}
logging.info('get_cnc_processing_create error:%s' % e)
return json.JSONEncoder().encode(res)

View File

@@ -15,26 +15,31 @@ class FtpController():
ftp = FTP()
def __init__(self, host="192.168.50.202", port=21, username="ftpuser", password="123456"):
def __init__(self, host, port, username, password):
try:
self.ftp.connect(host, port)
self.ftp.login(username, password)
logging.info("连接成功: ")
logging.info("ftp连接成功")
except:
logging.info("连接失败: ")
logging.info("ftp连接失败")
return False
# 下载目录下的文件
def download_file_tree(self, target_dir, serverdir):
if not os.path.exists(serverdir):
os.makedirs(serverdir)
try:
logging.info("进入FTP目录 ")
self.ftp.cwd(target_dir) # 切换工作路径
logging.info('FTP目录:%s' % target_dir)
remotenames = self.ftp.nlst()
logging.info('FTP目录文件:%s' % remotenames)
for file in remotenames:
server = os.path.join(serverdir, file)
if file.find(".") != -1:
self.download_file(server, file)
else:
return
except:
return False
# 下载指定目录下的指定文件
def download_file(self, serverfile, remotefile):

View File

@@ -12,8 +12,12 @@ class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
token = fields.Char(string='TOKEN', default='b811ac06-3f00-11ed-9aed-0242ac110003')
sf_secret_key = fields.Char(string='密钥', default= 'wBmxej38OkErKhD6')
sf_url = fields.Char(string='访问地址', default= 'https://sf.cs.jikimo.com')
sf_secret_key = fields.Char(string='密钥', default='wBmxej38OkErKhD6')
sf_url = fields.Char(string='访问地址', default='https://sf.cs.jikimo.com')
ftp_host = fields.Char(string='FTP的ip')
ftp_port = fields.Char(string='FTP端口')
ftp_user = fields.Char(string='FTP用户')
ftp_password = fields.Char(string='FTP密码')
def sf_all_sync(self):
self.env['sf.production.materials'].sync_all_production_materials()
@@ -40,8 +44,6 @@ class ResConfigSettings(models.TransientModel):
_logger.info("同步资源库刀具")
# self.env['sf.processing.order'].sync_all_processing_order()
@api.model
def get_values(self):
"""
@@ -53,11 +55,19 @@ class ResConfigSettings(models.TransientModel):
token = config.get_param('token', default='')
sf_secret_key = config.get_param('sf_secret_key', default='')
sf_url = config.get_param('sf_url', default='')
ftp_host = config.get_param('ftp_host', default='')
ftp_port = config.get_param('ftp_port', default='')
ftp_user = config.get_param('ftp_user', default='')
ftp_password = config.get_param('ftp_password', default='')
values.update(
token=token,
sf_secret_key=sf_secret_key,
sf_url=sf_url,
ftp_host=ftp_host,
ftp_port=ftp_port,
ftp_user=ftp_user,
ftp_password=ftp_password
)
return values
@@ -67,4 +77,7 @@ class ResConfigSettings(models.TransientModel):
ir_config.set_param("token", self.token or "")
ir_config.set_param("sf_secret_key", self.sf_secret_key or "")
ir_config.set_param("sf_url", self.sf_url or "")
ir_config.set_param("ftp_host", self.ftp_host or "")
ir_config.set_param("ftp_port", self.ftp_port or "")
ir_config.set_param("ftp_user", self.ftp_user or "")
ir_config.set_param("ftp_password", self.ftp_password or "")

View File

@@ -14,22 +14,49 @@
<div class="o_setting_left_pane"/>
<div class="o_setting_right_pane">
<div class="text-muted">
<label for="token"/>
<field name="token" />
<label for="sf_url"/>
<field name="sf_url"/>
</div>
<div class="text-muted">
<label for="token" string="Token"/>
<field name="token"/>
</div>
<div class="text-muted">
<label for="sf_secret_key"/>
<field name="sf_secret_key"/>
</div>
<div class="text-muted">
<label for="sf_url"/>
<field name="sf_url"/>
<div class="col-12 col-lg-6 o_setting_box">
<button type="object" class="oe_highlight" name="sf_all_sync"
string="同步资源库基础数据"
/>
</div>
</div>
</div>
</div>
</div>
<div>
<h2>FTP参数配置</h2>
<div class="row mt16 o_settings_container" id="pay_api">
<div class="col-12 col-lg-6 o_setting_box">
<button type="object" class="oe_highlight" name="sf_all_sync" string="同步资源库所有基础数据"
/>
<div class="o_setting_left_pane"/>
<div class="o_setting_right_pane">
<div class="text-muted">
<label for="ftp_host" string="访问地址"/>
<field name="ftp_host"/>
</div>
<div class="text-muted">
<label for="ftp_port" string="端口"/>
<field name="ftp_port"/>
</div>
<div class="text-muted">
<label for="ftp_user" string="用户"/>
<field name="ftp_user"/>
</div>
<div class="text-muted">
<label for="ftp_password" string="密码"/>
<field name="ftp_password" password="True"/>
</div>
</div>
</div>
</div>
</div>