diff --git a/jikimo_work_reporting_api/controllers/main.py b/jikimo_work_reporting_api/controllers/main.py index 54cd4cc6..c3ea7daa 100644 --- a/jikimo_work_reporting_api/controllers/main.py +++ b/jikimo_work_reporting_api/controllers/main.py @@ -6,7 +6,7 @@ from odoo.addons.sf_base.decorators.api_log import api_log class MainController(http.Controller): - @http.route('/api/manual_download_program', type='json', methods=['POST'], auth='wechat_token', cors='*') + @http.route('/api/manual_download_program', type='json', methods=['POST'], auth='public', cors='*') @api_log('人工线下加工编程文件传输', requester='报工系统') def manual_download_program(self): """ diff --git a/sf_machine_connect/controllers/controllers.py b/sf_machine_connect/controllers/controllers.py index a6eb4100..692fa10b 100644 --- a/sf_machine_connect/controllers/controllers.py +++ b/sf_machine_connect/controllers/controllers.py @@ -1300,9 +1300,6 @@ class Sf_Dashboard_Connect(http.Controller): machine_list = ast.literal_eval(kw['machine_list']) time_threshold = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) - alarm_last_24_time = 0.0 - alarm_all_time = 0.0 - def fetch_result_as_dict(cursor): """辅助函数:将查询结果转为字典""" columns = [desc[0] for desc in cursor.description] @@ -1311,6 +1308,9 @@ class Sf_Dashboard_Connect(http.Controller): # 获取当前时间的时间戳 current_timestamp = datetime.now().timestamp() for item in machine_list: + alarm_last_24_time = 0.0 + alarm_all_time = 0.0 + euipment_obj = request.env['maintenance.equipment'].sudo().search([('code', '=', item)]) # 机床上线时间段 first_online_duration = current_timestamp - euipment_obj.first_online_time.timestamp() diff --git a/sf_machine_connect/models/ftp_operate.py b/sf_machine_connect/models/ftp_operate.py index e8134ab2..8265b351 100644 --- a/sf_machine_connect/models/ftp_operate.py +++ b/sf_machine_connect/models/ftp_operate.py @@ -9,9 +9,13 @@ _logger = logging.getLogger(__name__) class FTP_P(FTP): """ - 重写FTP类,重写dirs方法 + 重写FTP类,重写dirs方法,增加编码处理 """ - + def __init__(self, host='', user='', passwd='', acct='', timeout=None, encoding='gbk'): + """初始化时指定编码方式""" + super().__init__(host, user, passwd, acct, timeout) + self.encoding = encoding + def dirs(self, *args): """List a directory in long form. By default list current directory to stdout. @@ -32,7 +36,50 @@ class FTP_P(FTP): tempdic['name'] = [file for file in r_files if file != "." and file != ".."] # 去除. .. return tempdic - # return [file for file in r_files if file != "." and file != ".."] + + def nlst(self, *args): + """Get a list of files in a directory.""" + files = [] + def append(line): + try: + if isinstance(line, bytes): + files.append(line.decode(self.encoding)) + else: + files.append(line) + except UnicodeDecodeError: + files.append(line.decode('utf-8', errors='replace')) + cmd = 'NLST' + if args: + cmd = cmd + ' ' + args[0] + self.retrlines(cmd, append) + return files + + def cwd(self, dirname): + """Change to a directory.""" + try: + if isinstance(dirname, bytes): + dirname = dirname.decode(self.encoding) + return super().cwd(dirname) + except UnicodeEncodeError: + return super().cwd(dirname.encode(self.encoding).decode('utf-8')) + + def storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None): + """Store a file in binary mode.""" + try: + if isinstance(cmd, bytes): + cmd = cmd.decode(self.encoding) + return super().storbinary(cmd, fp, blocksize, callback, rest) + except UnicodeEncodeError: + return super().storbinary(cmd.encode(self.encoding).decode('utf-8'), fp, blocksize, callback, rest) + + def retrbinary(self, cmd, callback, blocksize=8192, rest=None): + """Retrieve a file in binary mode.""" + try: + if isinstance(cmd, bytes): + cmd = cmd.decode(self.encoding) + return super().retrbinary(cmd, callback, blocksize, rest) + except UnicodeEncodeError: + return super().retrbinary(cmd.encode(self.encoding).decode('utf-8'), callback, blocksize, rest) # FTP接口类