parent
0f34cfad26
commit
55094f77d4
@ -0,0 +1,216 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
'''
|
||||||
|
@Date:2022/08/27 11:05:06
|
||||||
|
'''
|
||||||
|
import sys
|
||||||
|
sys.path.append('.')
|
||||||
|
import string
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
from openpyxl.workbook import Workbook
|
||||||
|
from openpyxl.styles import Alignment, Side, Border, Font, PatternFill
|
||||||
|
|
||||||
|
class ReportData:
|
||||||
|
def __init__(self):
|
||||||
|
|
||||||
|
# 新建一个workbook
|
||||||
|
self.wb = Workbook()
|
||||||
|
# 定义设置样式
|
||||||
|
self.a = 0
|
||||||
|
self.key_list = [
|
||||||
|
"remark7", "remark8", "category", "remark9",
|
||||||
|
"name", "english_name","purity","cas_number","standard_code",
|
||||||
|
"unit_code","speci","net_weight_unit", "export_count","remark6",
|
||||||
|
"production_date", "shelf_life", "expiration_date",
|
||||||
|
"price", "is_supervise", "remain", "manufacturer",
|
||||||
|
"storage_condition", "remark10"
|
||||||
|
]
|
||||||
|
self.finds_name = [
|
||||||
|
"申购单编号","采购单编号", "药剂类别", "所属项目", "药剂名称", "英文名称", "纯度等级", "CAS码", "批号", "编号", "规格", "规格单位", "导入数量",
|
||||||
|
"导入单位", "生产日期", "保质期(天)", "到期日期", "价格(元)", "重点监管", "预估质量(g/ml)", "生产厂商", "储存条件", "包装是否完好、标签是否清晰"
|
||||||
|
]
|
||||||
|
|
||||||
|
def set_style(self, title='sheet1'):
|
||||||
|
# 如果是第一次调用则删除默认创建的sheet表
|
||||||
|
if self.a == 0:
|
||||||
|
self.wb.remove(self.wb['Sheet'])
|
||||||
|
self.a += 1
|
||||||
|
# 创建第几个sheet
|
||||||
|
self.ws = self.wb.create_sheet()
|
||||||
|
# 设置sheet的标题
|
||||||
|
self.ws.title = title
|
||||||
|
# 生成ascii_uppercase生成所有大写字母
|
||||||
|
self.upper_string = string.ascii_uppercase
|
||||||
|
# 水平对齐, 居中对齐
|
||||||
|
self.alignment_style = Alignment(
|
||||||
|
horizontal='center', vertical='center')
|
||||||
|
# 定义字体
|
||||||
|
self.font_size = Font(size=9)
|
||||||
|
for col in self.upper_string:
|
||||||
|
self.ws.column_dimensions[col].width = 10
|
||||||
|
|
||||||
|
# 创建第三行, 需要传入一个列表用来写入单元格的值
|
||||||
|
def create_row3(self, data_list):
|
||||||
|
for data in range(1, len(data_list) + 1):
|
||||||
|
# 第三行写入值
|
||||||
|
self.ws.cell(row=1, column=data).value = data_list[data - 1]
|
||||||
|
|
||||||
|
# 创建多行固定样式 start_row从第几行开始有规律 传入一个数据库获取的列表对象的值, 传入一个数据对象keys列表
|
||||||
|
def create_multiple_rows(self, start_row, data_list, keys_list):
|
||||||
|
# 从第4行创建
|
||||||
|
for row_number in range(start_row, len(data_list) + start_row):
|
||||||
|
# 设置每一行的行高
|
||||||
|
# self.ws.row_dimensions[row_number].height = 18
|
||||||
|
# 遍历每一个对象的长度
|
||||||
|
col_ = 1
|
||||||
|
for key_ in keys_list:
|
||||||
|
# 写入值
|
||||||
|
try:
|
||||||
|
value = data_list[row_number - start_row][key_]
|
||||||
|
except:
|
||||||
|
value = ""
|
||||||
|
try:
|
||||||
|
value = int(value)
|
||||||
|
self.ws.cell(row=row_number, column=col_).number_format = '0'
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
self.ws.cell(row=row_number, column=col_).value = value
|
||||||
|
col_ += 1
|
||||||
|
|
||||||
|
# 保存文件
|
||||||
|
def save(self, file_path):
|
||||||
|
self.wb.save('{}.xlsx'.format(file_path))
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
# 关闭文件
|
||||||
|
def close(self):
|
||||||
|
self.wb.close()
|
||||||
|
|
||||||
|
# 替换空白
|
||||||
|
def replace_space(self, length):
|
||||||
|
self.max_lines = self.ws.max_row
|
||||||
|
upper_letter_str = string.ascii_uppercase[:length]
|
||||||
|
for upper_letter in upper_letter_str:
|
||||||
|
for row_ in range(1, self.max_lines + 1):
|
||||||
|
b = self.ws[upper_letter + str(row_)].value
|
||||||
|
# print(b)
|
||||||
|
if not b:
|
||||||
|
self.ws[upper_letter + str(row_)].value = 'null'
|
||||||
|
|
||||||
|
# 编辑excel表格中列药剂状态1 2 3 替换为在库 出库 空瓶
|
||||||
|
def editor_status(self, col_):
|
||||||
|
self.max_lines = self.ws.max_row
|
||||||
|
for row_ in range(4, self.max_lines + 1):
|
||||||
|
b = self.ws[col_ + str(row_)].value
|
||||||
|
if b == 1:
|
||||||
|
self.ws[col_ + str(row_)].value = '在库'
|
||||||
|
elif b == 2:
|
||||||
|
self.ws[col_ + str(row_)].value = '出库'
|
||||||
|
elif b == 3:
|
||||||
|
self.ws[col_ + str(row_)].value = '空瓶'
|
||||||
|
|
||||||
|
# 编辑药剂重点监管列为1 0 替换为是 否
|
||||||
|
def editor_isSupervise(self, col_):
|
||||||
|
self.max_lines = self.ws.max_row
|
||||||
|
for row_ in range(4, self.max_lines + 1):
|
||||||
|
b = self.ws[col_ + str(row_)].value
|
||||||
|
if b == 1:
|
||||||
|
self.ws[col_ + str(row_)].value = '是'
|
||||||
|
elif b == 0:
|
||||||
|
self.ws[col_ + str(row_)].value = '否'
|
||||||
|
|
||||||
|
# 编辑操作类型 1 2 3 入库 领用 归还
|
||||||
|
def editor_RecordType(self, col_):
|
||||||
|
self.max_lines = self.ws.max_row
|
||||||
|
for row_ in range(4, self.max_lines + 1):
|
||||||
|
b = self.ws[col_ + str(row_)].value
|
||||||
|
if b == 1:
|
||||||
|
self.ws[col_ + str(row_)].value = '入库'
|
||||||
|
elif b == 2:
|
||||||
|
self.ws[col_ + str(row_)].value = '领用'
|
||||||
|
elif b == 3:
|
||||||
|
self.ws[col_ + str(row_)].value = '归还'
|
||||||
|
|
||||||
|
# 替换sqlAlchemy时间格式
|
||||||
|
def editor_time(self, keys_list, params):
|
||||||
|
self.max_lines = self.ws.max_row
|
||||||
|
for row_ in range(4, self.max_lines + 1):
|
||||||
|
col_ = string.ascii_uppercase[keys_list.index(params)]
|
||||||
|
b = self.ws[col_ + str(row_)].value
|
||||||
|
if b:
|
||||||
|
if len(b) == 19:
|
||||||
|
self.ws[col_ + str(row_)].value = b.replace('T', ' ')
|
||||||
|
else:
|
||||||
|
self.ws[col_ + str(row_)].value = "/"
|
||||||
|
|
||||||
|
# 编辑用户管理列为1 0 替换为正常 禁用
|
||||||
|
def editor_user_status(self, col_):
|
||||||
|
self.max_lines = self.ws.max_row
|
||||||
|
for row_ in range(4, self.max_lines + 1):
|
||||||
|
b = self.ws[col_ + str(row_)].value
|
||||||
|
if b == 1:
|
||||||
|
self.ws[col_ + str(row_)].value = '正常'
|
||||||
|
elif b == 0:
|
||||||
|
self.ws[col_ + str(row_)].value = '禁用'
|
||||||
|
|
||||||
|
# 构建文件内容
|
||||||
|
def build_file(self, data_list):
|
||||||
|
# data_list = kwargs.pop("data_list")
|
||||||
|
key_list = self.key_list
|
||||||
|
finds_name = self.finds_name
|
||||||
|
self.set_style(title="Sheet")
|
||||||
|
self.create_row3(finds_name)
|
||||||
|
self.create_multiple_rows(2, data_list, key_list)
|
||||||
|
for i in key_list:
|
||||||
|
if "date" in i:
|
||||||
|
self.editor_time(key_list, i)
|
||||||
|
if "status" in i:
|
||||||
|
self.editor_status(string.ascii_uppercase[key_list.index(i)])
|
||||||
|
if "is_supervise" in i:
|
||||||
|
self.editor_isSupervise(string.ascii_uppercase[key_list.index(i)])
|
||||||
|
if "record_type" == i:
|
||||||
|
self.editor_RecordType(
|
||||||
|
string.ascii_uppercase[key_list.index(i)])
|
||||||
|
return self
|
||||||
|
|
||||||
|
# 下载文件
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def download_excel(filename, chunk_size=512):
|
||||||
|
try:
|
||||||
|
f = open(filename, 'rb')
|
||||||
|
except:
|
||||||
|
return
|
||||||
|
while True:
|
||||||
|
c = f.read(chunk_size)
|
||||||
|
if c:
|
||||||
|
yield c
|
||||||
|
else:
|
||||||
|
f.close()
|
||||||
|
os.remove(filename)
|
||||||
|
break
|
||||||
|
|
||||||
|
# if __name__ == '__main__':
|
||||||
|
# obj = ReportData()
|
||||||
|
# obj.build_file(data_list=[{"name":"测试试剂123", "shelf_life":5}])
|
||||||
|
# obj.save("测试表1")
|
||||||
|
# data_dict = {
|
||||||
|
# "data_list":[
|
||||||
|
# {"name": "申购单编号", "purity":"11~15%", "export_count":"2", "production_date":"2023/01/01", "shelf_life": '5'}
|
||||||
|
# ],
|
||||||
|
# "key_list": [
|
||||||
|
# "remark7", "remark8", "category", "remark9",
|
||||||
|
# "name", "english_name","purity","cas_number","standard_code",
|
||||||
|
# "unit_code","speci","net_weight_unit", "export_count","remark6",
|
||||||
|
# "production_date", "shelf_life", "expiration_date",
|
||||||
|
# "price", "is_supervise", "remain", "manufacturer",
|
||||||
|
# "storage_condition", "remark10"
|
||||||
|
# ],
|
||||||
|
# "finds_name": [
|
||||||
|
# "申购单编号","采购单编号", "药剂类别", "所属项目", "药剂名称", "英文名称", "纯度等级", "CAS码", "批号", "编号", "规格", "规格单位", "导入数量",
|
||||||
|
# "导入单位", "生产日期", "保质期(天)", "到期日期", "价格(元)", "重点监管", "预估质量(g/ml)", "生产厂商", "储存条件", "包装是否完好、标签是否清晰"
|
||||||
|
# ],
|
||||||
|
# }
|
||||||
|
# obj = obj.build_file(**data_dict)
|
||||||
|
# obj.save("测试表")
|
@ -0,0 +1,136 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
'''
|
||||||
|
@Date: 2023/01/05 14:10:45
|
||||||
|
'''
|
||||||
|
import sys
|
||||||
|
sys.path.append('.')
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
from flask import Blueprint, request, jsonify, g
|
||||||
|
from sqlalchemy import and_, or_
|
||||||
|
from db_logic.medicament_shengou import BllMedicamntShenGou
|
||||||
|
from models.medicament_models import EntityMedicamntShenGou
|
||||||
|
from Common.report_shen_gou import ReportData
|
||||||
|
from db_logic.user import BllUser
|
||||||
|
from Common.Utils import Utils, PageParam
|
||||||
|
from Common.auth import token_auth
|
||||||
|
from apps.report.dows_utils import dows_flie
|
||||||
|
|
||||||
|
shengou_bp = Blueprint("shengou", __name__)
|
||||||
|
|
||||||
|
# 展示列表,根据用户角色是否展示全部
|
||||||
|
@shengou_bp.route("/get_list", methods=["POST"])
|
||||||
|
@token_auth.login_required
|
||||||
|
def get_shengou_list():
|
||||||
|
user = g.current_user
|
||||||
|
page = request.values.get("page")
|
||||||
|
page_size = request.values.get("page_size")
|
||||||
|
page_param = PageParam(int(page), int(page_size))
|
||||||
|
data = BllMedicamntShenGou().get_list(user=user, page_param=page_param)
|
||||||
|
user_list = BllUser().findList()
|
||||||
|
user_dict = {}
|
||||||
|
for i in user_list:
|
||||||
|
user_dict[i.user_id] = i.real_name
|
||||||
|
data_list = []
|
||||||
|
for i in data:
|
||||||
|
i_dict = dict(i._mapping)
|
||||||
|
i_dict['user_name'] = user_dict.get(i_dict["user_id"])
|
||||||
|
i_dict["solve_user_name"] = user_dict.get(i_dict["solve_user_id"], '')
|
||||||
|
i_dict["solve_user_pt_name"] = user_dict.get(i_dict["solve_user_id_pt"], '')
|
||||||
|
data_list.append(i_dict)
|
||||||
|
return jsonify(Utils.true_return(data= {"data_list":data_list, "total_count": page_param.totalRecords}))
|
||||||
|
|
||||||
|
|
||||||
|
# 创建申请记录
|
||||||
|
@shengou_bp.route("/add", methods=["POST"])
|
||||||
|
@token_auth.login_required
|
||||||
|
def add_drug_shengou():
|
||||||
|
func_type = request.values.get("func_type")
|
||||||
|
use_doc = request.values.get("use_doc")
|
||||||
|
use_content = request.values.get("use_content")
|
||||||
|
|
||||||
|
if not use_content:
|
||||||
|
return jsonify(Utils.false_return(msg='内容为空,无需提交'))
|
||||||
|
obj = EntityMedicamntShenGou(
|
||||||
|
user_id = g.current_user.user_id,
|
||||||
|
create_date = Utils.get_str_datetime(),
|
||||||
|
is_solve = 0,
|
||||||
|
use_content = use_content,
|
||||||
|
func_type=func_type,
|
||||||
|
use_doc=use_doc
|
||||||
|
)
|
||||||
|
BllMedicamntShenGou().insert(obj)
|
||||||
|
return jsonify(Utils.true_return())
|
||||||
|
|
||||||
|
# 修改个人申请
|
||||||
|
@shengou_bp.route("/update", methods=["POST"])
|
||||||
|
@token_auth.login_required
|
||||||
|
def update_shengou():
|
||||||
|
shengou_id = request.values.get("id")
|
||||||
|
use_content = request.values.get("use_content")
|
||||||
|
if not use_content:
|
||||||
|
return jsonify(Utils.false_return(msg='内容为空,无需提交'))
|
||||||
|
user = g.current_user
|
||||||
|
user_apply_obj = BllMedicamntShenGou().findEntity(
|
||||||
|
and_(
|
||||||
|
EntityMedicamntShenGou.id == shengou_id,
|
||||||
|
EntityMedicamntShenGou.user_id == user.user_id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if not user_apply_obj:
|
||||||
|
return jsonify(Utils.false_return(msg="只能修改自己的申请!"))
|
||||||
|
user_apply_obj.use_content=use_content
|
||||||
|
BllMedicamntShenGou().update(user_apply_obj)
|
||||||
|
return jsonify(Utils.true_return())
|
||||||
|
|
||||||
|
|
||||||
|
# 处理消息
|
||||||
|
@shengou_bp.route("/solve", methods=["POST"])
|
||||||
|
@token_auth.login_required
|
||||||
|
def solve_shengou():
|
||||||
|
shengou_id =request.values.get("id")
|
||||||
|
user_id = g.current_user.user_id
|
||||||
|
obj = BllMedicamntShenGou().findEntity(EntityMedicamntShenGou.id == shengou_id)
|
||||||
|
if obj.is_solve == 1:
|
||||||
|
return jsonify(Utils.false_return(msg="已受理,无需重复受理"))
|
||||||
|
if str(request.values.get('result')) == "0":
|
||||||
|
obj.information = request.values.get("information")
|
||||||
|
obj.is_solve = 2
|
||||||
|
else:
|
||||||
|
if not obj.solve_user_id:
|
||||||
|
obj.solve_user_id = user_id
|
||||||
|
else:
|
||||||
|
if user_id == obj.solve_user_id:
|
||||||
|
return jsonify(Utils.false_return(msg="不能位同一人审批"))
|
||||||
|
obj.solve_user_id_pt=user_id
|
||||||
|
obj.is_solve = 1
|
||||||
|
obj.solve_date = Utils.get_str_datetime()
|
||||||
|
BllMedicamntShenGou().update(obj)
|
||||||
|
return jsonify(Utils.true_return())
|
||||||
|
|
||||||
|
# 导出申购单
|
||||||
|
@shengou_bp.route("/dowload", methods=["GET", "POST"])
|
||||||
|
@token_auth.login_required
|
||||||
|
def dowload_shengou():
|
||||||
|
shengou_id = request.values.get("id")
|
||||||
|
obj = BllMedicamntShenGou().findEntity(EntityMedicamntShenGou.id == shengou_id)
|
||||||
|
if obj and obj.is_solve == 1:
|
||||||
|
try:
|
||||||
|
file_path = os.path.join(os.getcwd(), "report_file")
|
||||||
|
if not os.path.exists(file_path):
|
||||||
|
os.makedirs(file_path)
|
||||||
|
obj_report = ReportData()
|
||||||
|
obj = obj_report.build_file(json.loads(obj.use_content))
|
||||||
|
rsp_file_name = f"tem_申购单_{Utils.get_file_name_datetime()}"
|
||||||
|
obj.save(os.path.join(file_path, rsp_file_name))
|
||||||
|
# u_path = Utils.getUDiskPath()
|
||||||
|
# if u_path:
|
||||||
|
# obj.save(os.path.join(u_path, rsp_file_name))
|
||||||
|
rep = dows_flie(file_path, rsp_file_name)
|
||||||
|
return rep
|
||||||
|
# return jsonify(Utils.true_return())
|
||||||
|
except Exception as error:
|
||||||
|
print(error)
|
||||||
|
return jsonify(Utils.false_return(msg=f"导出错误:{error}"))
|
||||||
|
return jsonify(Utils.false_return(msg="申购单导出错误"))
|
@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
'''
|
||||||
|
@Date: 2023/01/05 14:09:40
|
||||||
|
'''
|
||||||
|
import sys
|
||||||
|
sys.path.append('.')
|
||||||
|
|
||||||
|
|
||||||
|
from db_logic.db_base import Repository
|
||||||
|
from Common.Utils import Utils
|
||||||
|
from models.medicament_models import EntityMedicamntShenGou
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class BllMedicamntShenGou(Repository):
|
||||||
|
def __init__(self, entityType=EntityMedicamntShenGou):
|
||||||
|
return super().__init__(entityType)
|
||||||
|
|
||||||
|
def get_list(self, user, page_param):
|
||||||
|
filter_base = ""
|
||||||
|
if "管理员" not in user.role_name:
|
||||||
|
filter_base += f" user_id='{user.user_id}'"
|
||||||
|
if filter_base:
|
||||||
|
filter_base = f" where {filter_base}"
|
||||||
|
|
||||||
|
sql_all = f"""
|
||||||
|
select * from rms_medicamnt_shengou {filter_base}
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
count_number = self.execute(f"select count(*) num from ({sql_all})a ").fetchone().num
|
||||||
|
except Exception:
|
||||||
|
count_number = 0
|
||||||
|
if page_param:
|
||||||
|
page_param.totalRecords = count_number
|
||||||
|
sql_all = Utils.sql_paging_assemble(sql_all, page_param)
|
||||||
|
return self.execute(sql_all).fetchall()
|
@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
'''
|
||||||
|
@Date:2022/07/19 09:43:08
|
||||||
|
'''
|
||||||
|
import sys
|
||||||
|
sys.path.append(".")
|
||||||
|
from db_logic.db_base import Repository
|
||||||
|
from models.medicament_models import EntityVariety
|
||||||
|
|
||||||
|
|
||||||
|
#药剂品种业务逻辑类
|
||||||
|
class BllVariety(Repository):
|
||||||
|
def __init__(self, entityType=EntityVariety):
|
||||||
|
return super().__init__(entityType)
|
||||||
|
|
@ -0,0 +1,203 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
'''
|
||||||
|
@Date:2022/08/27 11:05:06
|
||||||
|
'''
|
||||||
|
import sys
|
||||||
|
from types import CellType
|
||||||
|
sys.path.append('.')
|
||||||
|
import string
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
from openpyxl.workbook import Workbook
|
||||||
|
from openpyxl.styles import Alignment, Side, Border, Font, PatternFill
|
||||||
|
|
||||||
|
class ReportData:
|
||||||
|
def __init__(self):
|
||||||
|
|
||||||
|
# 新建一个workbook
|
||||||
|
self.wb = Workbook()
|
||||||
|
# 定义设置样式
|
||||||
|
self.a = 0
|
||||||
|
|
||||||
|
def set_style(self, title='sheet1'):
|
||||||
|
# 如果是第一次调用则删除默认创建的sheet表
|
||||||
|
if self.a == 0:
|
||||||
|
self.wb.remove(self.wb['Sheet'])
|
||||||
|
self.a += 1
|
||||||
|
# 创建第几个sheet
|
||||||
|
self.ws = self.wb.create_sheet()
|
||||||
|
# 设置sheet的标题
|
||||||
|
self.ws.title = title
|
||||||
|
# 生成ascii_uppercase生成所有大写字母
|
||||||
|
self.upper_string = string.ascii_uppercase
|
||||||
|
# 水平对齐, 居中对齐
|
||||||
|
self.alignment_style = Alignment(
|
||||||
|
horizontal='center', vertical='center')
|
||||||
|
# 定义字体
|
||||||
|
self.font_size = Font(size=9)
|
||||||
|
for col in self.upper_string:
|
||||||
|
self.ws.column_dimensions[col].width = 10
|
||||||
|
|
||||||
|
# 创建第三行, 需要传入一个列表用来写入单元格的值
|
||||||
|
def create_row3(self, data_list):
|
||||||
|
for data in range(1, len(data_list) + 1):
|
||||||
|
# 第三行写入值
|
||||||
|
self.ws.cell(row=1, column=data).value = data_list[data - 1]
|
||||||
|
|
||||||
|
# 创建多行固定样式 start_row从第几行开始有规律 传入一个数据库获取的列表对象的值, 传入一个数据对象keys列表
|
||||||
|
def create_multiple_rows(self, start_row, data_list, keys_list):
|
||||||
|
# 从第4行创建
|
||||||
|
for row_number in range(start_row, len(data_list) + start_row):
|
||||||
|
# 设置每一行的行高
|
||||||
|
# self.ws.row_dimensions[row_number].height = 18
|
||||||
|
# 遍历每一个对象的长度
|
||||||
|
col_ = 1
|
||||||
|
for key_ in keys_list:
|
||||||
|
# 写入值
|
||||||
|
try:
|
||||||
|
value = data_list[row_number - start_row][key_]
|
||||||
|
except:
|
||||||
|
value = ""
|
||||||
|
try:
|
||||||
|
value = int(value)
|
||||||
|
self.ws.cell(row=row_number, column=col_).number_format = '0'
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
self.ws.cell(row=row_number, column=col_).value = value
|
||||||
|
col_ += 1
|
||||||
|
|
||||||
|
# 保存文件
|
||||||
|
def save(self, file_path):
|
||||||
|
self.wb.save('{}.xlsx'.format(file_path))
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
# 关闭文件
|
||||||
|
def close(self):
|
||||||
|
self.wb.close()
|
||||||
|
|
||||||
|
# 替换空白
|
||||||
|
def replace_space(self, length):
|
||||||
|
self.max_lines = self.ws.max_row
|
||||||
|
upper_letter_str = string.ascii_uppercase[:length]
|
||||||
|
for upper_letter in upper_letter_str:
|
||||||
|
for row_ in range(1, self.max_lines + 1):
|
||||||
|
b = self.ws[upper_letter + str(row_)].value
|
||||||
|
# print(b)
|
||||||
|
if not b:
|
||||||
|
self.ws[upper_letter + str(row_)].value = 'null'
|
||||||
|
|
||||||
|
# 编辑excel表格中列药剂状态1 2 3 替换为在库 出库 空瓶
|
||||||
|
def editor_status(self, col_):
|
||||||
|
self.max_lines = self.ws.max_row
|
||||||
|
for row_ in range(4, self.max_lines + 1):
|
||||||
|
b = self.ws[col_ + str(row_)].value
|
||||||
|
if b == 1:
|
||||||
|
self.ws[col_ + str(row_)].value = '在库'
|
||||||
|
elif b == 2:
|
||||||
|
self.ws[col_ + str(row_)].value = '出库'
|
||||||
|
elif b == 3:
|
||||||
|
self.ws[col_ + str(row_)].value = '空瓶'
|
||||||
|
|
||||||
|
# 编辑药剂重点监管列为1 0 替换为是 否
|
||||||
|
def editor_isSupervise(self, col_):
|
||||||
|
self.max_lines = self.ws.max_row
|
||||||
|
for row_ in range(4, self.max_lines + 1):
|
||||||
|
b = self.ws[col_ + str(row_)].value
|
||||||
|
if b == 1:
|
||||||
|
self.ws[col_ + str(row_)].value = '是'
|
||||||
|
elif b == 0:
|
||||||
|
self.ws[col_ + str(row_)].value = '否'
|
||||||
|
|
||||||
|
# 编辑操作类型 1 2 3 入库 领用 归还
|
||||||
|
def editor_RecordType(self, col_):
|
||||||
|
self.max_lines = self.ws.max_row
|
||||||
|
for row_ in range(4, self.max_lines + 1):
|
||||||
|
b = self.ws[col_ + str(row_)].value
|
||||||
|
if b == 1:
|
||||||
|
self.ws[col_ + str(row_)].value = '入库'
|
||||||
|
elif b == 2:
|
||||||
|
self.ws[col_ + str(row_)].value = '领用'
|
||||||
|
elif b == 3:
|
||||||
|
self.ws[col_ + str(row_)].value = '归还'
|
||||||
|
|
||||||
|
# 替换sqlAlchemy时间格式
|
||||||
|
def editor_time(self, keys_list, params):
|
||||||
|
self.max_lines = self.ws.max_row
|
||||||
|
for row_ in range(4, self.max_lines + 1):
|
||||||
|
col_ = string.ascii_uppercase[keys_list.index(params)]
|
||||||
|
b = self.ws[col_ + str(row_)].value
|
||||||
|
if b:
|
||||||
|
if len(b) == 19:
|
||||||
|
self.ws[col_ + str(row_)].value = b.replace('T', ' ')
|
||||||
|
else:
|
||||||
|
self.ws[col_ + str(row_)].value = "/"
|
||||||
|
|
||||||
|
# 编辑用户管理列为1 0 替换为正常 禁用
|
||||||
|
def editor_user_status(self, col_):
|
||||||
|
self.max_lines = self.ws.max_row
|
||||||
|
for row_ in range(4, self.max_lines + 1):
|
||||||
|
b = self.ws[col_ + str(row_)].value
|
||||||
|
if b == 1:
|
||||||
|
self.ws[col_ + str(row_)].value = '正常'
|
||||||
|
elif b == 0:
|
||||||
|
self.ws[col_ + str(row_)].value = '禁用'
|
||||||
|
|
||||||
|
# 构建文件内容
|
||||||
|
def build_file(self,**kwargs):
|
||||||
|
data_list = kwargs.pop("data_list")
|
||||||
|
key_list = kwargs.pop("key_list")
|
||||||
|
finds_name = kwargs.pop("finds_name")
|
||||||
|
self.set_style(title="Sheet")
|
||||||
|
self.create_row3(finds_name)
|
||||||
|
self.create_multiple_rows(2, data_list, key_list)
|
||||||
|
for i in key_list:
|
||||||
|
if "date" in i:
|
||||||
|
self.editor_time(key_list, i)
|
||||||
|
if "status" in i:
|
||||||
|
self.editor_status(string.ascii_uppercase[key_list.index(i)])
|
||||||
|
if "is_supervise" in i:
|
||||||
|
self.editor_isSupervise(string.ascii_uppercase[key_list.index(i)])
|
||||||
|
if "record_type" == i:
|
||||||
|
self.editor_RecordType(
|
||||||
|
string.ascii_uppercase[key_list.index(i)])
|
||||||
|
return self
|
||||||
|
|
||||||
|
# 下载文件
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def download_excel(filename, chunk_size=512):
|
||||||
|
try:
|
||||||
|
f = open(filename, 'rb')
|
||||||
|
except:
|
||||||
|
return
|
||||||
|
while True:
|
||||||
|
c = f.read(chunk_size)
|
||||||
|
if c:
|
||||||
|
yield c
|
||||||
|
else:
|
||||||
|
f.close()
|
||||||
|
os.remove(filename)
|
||||||
|
break
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
obj = ReportData()
|
||||||
|
data_dict = {
|
||||||
|
"data_list":[
|
||||||
|
{"name": "申购单编号", "purity":"11~15%", "export_count":"2", "production_date":"2023/01/01", "shelf_life": '5'}
|
||||||
|
],
|
||||||
|
"key_list": [
|
||||||
|
"remark7", "remark8", "category", "remark9",
|
||||||
|
"name", "english_name","purity","cas_number","standard_code",
|
||||||
|
"unit_code","speci","net_weight_unit", "export_count","remark6",
|
||||||
|
"production_date", "shelf_life", "expiration_date",
|
||||||
|
"price", "is_supervise", "remain", "manufacturer",
|
||||||
|
"storage_condition", "remark10"
|
||||||
|
],
|
||||||
|
"finds_name": [
|
||||||
|
"申购单编号","采购单编号", "药剂类别", "所属项目", "药剂名称", "英文名称", "纯度等级", "CAS码", "批号", "编号", "规格", "规格单位", "导入数量",
|
||||||
|
"导入单位", "生产日期", "保质期(天)", "到期日期", "价格(元)", "重点监管", "预估质量(g/ml)", "生产厂商", "储存条件", "包装是否完好、标签是否清晰"
|
||||||
|
],
|
||||||
|
}
|
||||||
|
obj = obj.build_file(**data_dict)
|
||||||
|
obj.save("测试表")
|
Loading…
Reference in new issue