def dao_update(self, subtransactions=False, nested=False): with db.auto_commit_db(subtransactions=subtransactions, nested=nested) as s: if is_not_empty(current_user) and is_not_empty(current_user.id): self.update_by = current_user.id self.update_date = datetime.utcnow() # 将对象添加到session中,解决从缓存读取更新报 not in session 异常 s.merge(self)
def data(date): """ 图片数据分类 :return: """ base_dir = os.path.join('D:/AIData', date) data_dir = os.path.join(base_dir, 'DATA') file_lists = FileUtil.get_files_by_suffix(base_dir, ['JPG', 'JPEG', 'PNG']) for file in file_lists: _, file_id, file_ext = FileUtil.get_path_name_ext(file) with db.auto_commit_db() as s: sql = "SELECT FILE_TYPE FROM ( " \ "SELECT DISTINCT " \ "SUBSTR(J.BIZ_TYPE, INSTR(J.BIZ_TYPE, '_', -1) + 1) AS FILE_TYPE " \ "FROM js_sys_file_upload J " \ "INNER JOIN ucl_loan_file_code U ON SUBSTR(J.BIZ_TYPE, INSTR(J.BIZ_TYPE, '_',-1) + 1) = U.FILE_CODE " \ "WHERE FILE_ID = :file_id " \ "order by FILE_TYPE) " \ "WHERE ROWNUM = 1" res = s.execute(sql, params={'file_id': file_id}, bind=db.get_engine(bind='YFC_UCL_PRD')) res = res.cursor.fetchone() if res: file_type = res[0] else: file_type = 'default' FileUtil.copy_file(file, os.path.join(data_dir, file_type)) print('OVER *******************************') return date
def dao_init_file(self, file_path, id=None, file_name=None, subtransactions=False, nested=False): """ 根据路径解析入库 :param nested: :param subtransactions: :param file_name :param file_path: 文件路径 :param id: :return: """ with db.auto_commit_db(subtransactions=subtransactions, nested=nested) as s: super().dao_create(id) # 计算文件 md5 self.md5_id = FileUtil.get_md5_path(file_path) # noinspection PyAttributeOutsideInit self.file_path = file_path _, self.file_name, self.file_format = FileUtil.get_path_name_ext( file_path) if is_not_empty(file_name): self.file_name = file_name self.file_size = FileUtil.get_file_size(file_path) s.add(self)
def dao_add(self, **kwargs): """ 添加字典 :param kwargs: :return: """ super().dao_create() with db.auto_commit_db(**kwargs) as s: s.add(self)
def dao_add(self, img_data_id, parent_file_id, file_id, **kwargs): """ 图片明细入库 :param img_data_id: 图片文件入库流水号 :param parent_file_id: 父级文件ID :param file_id: 图片文件ID :param kwargs: :return: """ super().dao_create() self.img_data_id = img_data_id self.parent_file_id = parent_file_id self.file_id = file_id with db.auto_commit_db(**kwargs) as s: s.add(self)
def dao_get_by_login_name(self, login_name): sql = "SELECT a.id, a.id AS 'current_user.id', a.company_id AS 'company.id', a.office_id AS 'office.id', " \ "a.login_name, a.login_name AS 'current_user.login_name', a.password, " \ "a.password AS 'current_user.password', a.no, a.no AS 'current_user.no', " \ "a.name, a.name AS 'current_user.name', " \ "a.email, a.phone, a.phone AS 'current_user.phone', " \ "a.mobile, a.mobile AS 'current_user.mobile', a.user_type, a.login_ip, a.login_date, " \ "a.remarks, a.login_flag, a.photo, a.create_by AS 'create_by.id', a.create_date, " \ "a.update_by AS 'update_by.id', a.update_date, a.del_flag, c.name AS 'company.name', " \ "c.parent_id AS 'company.parent.id', c.parent_ids AS 'company.parent_ids', " \ "ca.id AS 'company.area.id', ca.name AS 'company.area.name', " \ "ca.parent_id AS 'company.area.parent.id', ca.parent_ids AS 'company.area.parent_ids', " \ "o.name AS 'office.name', o.parent_id AS 'office.parent.id', o.parent_ids AS 'office.parent_ids', " \ "oa.id AS 'office.area.id', oa.name AS 'office.area.name', " \ "oa.parent_id AS 'office.area.parent.id', oa.parent_ids AS 'office.area.parent_ids', " \ "cu.id AS 'company.primary_person.id', cu.name AS 'company.primary_person.name', " \ "cu2.id AS 'company.deputy_person.id', cu2.name AS 'company.deputy_person.name', " \ "ou.id AS 'office.primary_person.id', ou.name AS 'office.primary_person.name', " \ "ou2.id AS 'office.deputy_person.id', ou2.name AS 'office.deputy_person.name'" \ "FROM [jeesite-yfc].[dbo].[sys_user] a " \ "LEFT JOIN [jeesite-yfc].[dbo].[sys_office] c ON c.id = a.company_id " \ "LEFT JOIN [jeesite-yfc].[dbo].[sys_area] ca ON ca.id = c.area_id " \ "LEFT JOIN [jeesite-yfc].[dbo].[sys_office] o ON o.id = a.office_id " \ "LEFT JOIN [jeesite-yfc].[dbo].[sys_area] oa ON oa.id = o.area_id " \ "LEFT JOIN [jeesite-yfc].[dbo].[sys_user] cu ON cu.id = c.primary_person " \ "LEFT JOIN [jeesite-yfc].[dbo].[sys_user] cu2 ON cu2.id = c.deputy_person " \ "LEFT JOIN [jeesite-yfc].[dbo].[sys_user] ou ON ou.id = o.primary_person " \ "LEFT JOIN [jeesite-yfc].[dbo].[sys_user] ou2 ON ou2.id = o.deputy_person " \ "WHERE a.login_name = :login_name AND a.del_flag = :del_flag " with db.auto_commit_db() as s: res = s.execute(sql, params={ 'login_name': login_name, 'del_flag': self.del_flag }, bind=db.get_engine(current_app, bind='JEESITE-YFC')) for user in res: return user.keys(), user
def dao_add(self, ocrFile, file_model, file_path): """ 数据入库 :param ocrFile: :param file_model :param file_path: 文件路径 :return: """ super().dao_create() with db.auto_commit_db(False, False, error_call=FileUtil.del_file, file_path=file_path) as s: # 文件入库 file_model.dao_init_file(file_path, id=file_model.id, file_name=ocrFile.file_data.file_name, nested=True) ocrFile.file_id = file_model.id ocrFile.dao_add(nested=True) self.ocr_file_id = ocrFile.id s.add(self)
def dao_add_info(self, loan_dir, subtransactions=False, nested=False): """ 信息入库 :param nested: :param subtransactions: :param loan_dir: 资料目录 :return: """ with db.auto_commit_db(subtransactions, nested, error_call=FileUtil.del_dir, dir_path=loan_dir) as s: s.add(self) # 写入磁盘 file_models = [] for file in self.file_data: file_path = base64_to_file(file.file_base64, loan_dir, file.file_name, file.file_format) # 文件入库 file_model = FileModel() file_model.dao_init_file(file_path, nested=True) file_models.append(file_model) # 图片处理明细信息 details = [] for file_model in file_models: if file_model.file_format.strip().upper( ) == FileFormat.PDF.value: # 文件为pdf, 分割 pdf, 更新资料信息 img_path = FileUtil.path_join( loan_dir, current_app.config.get('DATA_DIR_IMG'), file_model.id) page_num, img_num, fail_num, detail_info = PDFUtil.pdf_to_pic( file_model.file_path, img_path) images = detail_info.get('images', None) if img_num > 0 and is_not_empty(images): for image in images: if is_empty(image.get('error_msg', None)): # 图片文件入库 img_model = FileModel() img_model.dao_init_file(image.get( 'img_path', ''), nested=True) # 图片明细入库 img_detail = ImgDetailModel() img_detail.dao_add(self.id, file_model.id, img_model.id, nested=True) self.page_num += page_num self.success_num += img_num self.fail_num += fail_num details.append( dict(id=file_model.id, md5=file_model.md5_id, page_num=page_num, success_num=img_num, fail_num=fail_num)) else: # 文件备份, 迁移处理文件 new_img_path = FileUtil.copy_file( file_model.file_path, FileUtil.path_join( loan_dir, current_app.config.get('DATA_DIR_IMG'))) # 图片文件入库 img_model = FileModel() img_model.dao_init_file(new_img_path, nested=True) # 文件为图片, 图片明细入库 img_detail = ImgDetailModel() img_detail.dao_add(self.id, file_model.id, img_model.id, nested=True) self.page_num += 1 self.success_num += 1 self.fail_num += 0 details.append( dict(id=file_model.id, md5=file_model.md5_id, page_num=1, success_num=1, fail_num=0)) return dict(id=self.id, details=details)
def dao_add(self, **kwargs): super().dao_create() with db.auto_commit_db(**kwargs) as s: s.add(self)
def dao_create(self, id=None, **kwargs): super().dao_create(id) with db.auto_commit_db(**kwargs) as s: s.add(self)
def dao_delete(self, subtransactions=False, nested=False): with db.auto_commit_db(subtransactions=subtransactions, nested=nested) as s: s.delete(self)