def upload_file(): """上传质检文档""" try: file = request.files.get('file') product_name = request.values.get('Product') filename = file.filename print(product_name) print(file.content_type) # 生成文件名和文件路径 # ext = file.filename.split('.')[-1] # filename = generate_filename() # user = Users.query.get(user_id) # full_filename = filename + '.' + ext root_path = get_root_path() file_path = os.path.join(root_path, file.filename) db_session.add( WordForm(FileName=filename, Product=product_name, FilePath=file_path)) db_session.commit() # filepath = current_app.config['UPLOAD_PATH'] # 保存 file.save(os.path.join(root_path, file.filename)) return json.dumps({ 'code': '1000', 'msg': '上传成功' }, cls=MyEncoder, ensure_ascii=False) except Exception as e: log(e) return json.dumps({'code': '2000', 'msg': str(e)})
def get_file(): if request.method == 'GET': product_name = request.values.get('Product') # pic_path = '%s.%s' % (filename.split('.')[0], filename.split('.')[-1]) print(product_name) # root_path = get_root_path() # filepath = os.path.join(root_path, current_app.config['UPLOAD_PATH']) # print(root_path) data = db_session.query(WordForm).filter_by(Product=product_name).all() return json.dumps({ 'code': '1000', 'msg': '请求成功', 'data': data }, cls=MyEncoder, ensure_ascii=False) # return send_from_directory(root_path, pic_path) if request.method == 'DELETE': no = request.values.get('Id') data = db_session.query(WordForm).filter_by(Id=no).first() db_session.delete(data) db_session.commit() return json.dumps({ 'code': '1000', 'msg': '删除成功' }, cls=MyEncoder, ensure_ascii=False)
def product_distribute(): """样品分发""" Action = request.values.get('Action') CheckProjectNO = request.values.get('CheckProjectNO') User = request.values.get('User') Account = request.values.get('Account') no = request.values.get('no') Group = request.values.get('Group') GroupUser = request.values.get('GroupUser') LaboratoryUser = request.values.get('LaboratoryUser') Time = request.values.get('Time') data = db_session.query(CheckForm).filter_by( CheckProjectNO=CheckProjectNO).first() if Action == 'J': data.Action = '检验' elif Action == 'F': data.Action = '复查' elif Action == 'L': data.Action = '留样' elif Action == '接收': data.Action = '接收' data.LaboratoryUser = LaboratoryUser data.Status = '检验中' data.OutUser = User data.Account = Account db_session.add(data) db_session.commit() db_session.add( Distribute(CheckProjectNO=CheckProjectNO, User=User, Group=Group, GroupUser=GroupUser, Time=Time)) db_session.commit() return json.dumps({'code': '1000', 'msg': '操作成功'}, ensure_ascii=False)
def sample(): """取样登记""" if request.method == 'GET': CheckProjectNO = request.values.get('CheckProjectNO') results = db_session.query(CheckProject).filter_by( No=CheckProjectNO).all() project = [] character = [] discern = [] inspect = [] content = [] microbe = [] data = [{ 'CheckProjectNO': CheckProjectNO, 'Project': project, 'Character': character, 'Discern': discern, 'Inspect': inspect, 'Content': content, 'Microbe': microbe }] for result in results: if result.Project is not None: project.append({'id': result.Id, 'value': result.Project}) if result.Character is not None: character.append({'id': result.Id, 'value': result.Character}) if result.Discern is not None: discern.append({'id': result.Id, 'value': result.Discern}) if result.Inspect is not None: inspect.append({'id': result.Id, 'value': result.Inspect}) if result.Content is not None: content.append({'id': result.Id, 'value': result.Content}) if result.Microbe is not None: microbe.append({'id': result.Id, 'value': result.Microbe}) return json.dumps({ 'code': '1000', 'msg': '成功', 'data': data }, cls=MyEncoder, ensure_ascii=False) if request.method == 'POST': CheckProjectNO = request.values.get('CheckProjectNO') SampleUser = request.values.get('SampleUser') data = db_session.query(CheckForm).filter_by( CheckProjectNO=CheckProjectNO).first() data.SampleUser = SampleUser data.Status = '待检验' db_session.add(data) db_session.commit() return json.dumps({ 'code': '1000', 'msg': '操作成功' }, cls=MyEncoder, ensure_ascii=False)
def receive(): CheckProjectNO = request.values.get('CheckProjectNO') SampleUser = request.values.get('SampleUser') ReceiveUser = request.values.get('ReceiveUser') data = db_session.query(CheckForm).filter_by( CheckProjectNO=CheckProjectNO).first() data.IntoUser = ReceiveUser db_session.add(data) db_session.commit() return json.dumps({ 'code': '1000', 'msg': '操作成功' }, cls=MyEncoder, ensure_ascii=False)
def check_verify(): """请验审核""" CheckProjectNO = request.values.get('CheckProjectNO') VerifyName = request.values.get('VerifyName') DateTime = request.values.get('DateTime') result = [] items = json.loads(CheckProjectNO) for item in items: data = db_session.query(CheckForm).filter_by( CheckProjectNO=item).first() data.VerifyUser = VerifyName data.VerifyDate = DateTime data.Status = '待取样' result.append(data) db_session.add_all(result) db_session.commit() return json.dumps({'code': '1000', 'msg': '操作成功'}, ensure_ascii=False)
def product_save(): """留样单""" db_session.add( ProductSave(CheckProjectNO=request.values.get('CheckProjectNO'), Name=request.values.get('Name'), Specs=request.values.get('Specs'), PackSpecs=request.values.get('PackSpecs'), ProductNumber=request.values.get('ProductNumber'), TheoreticalYield=request.values.get('TheoreticalYield'), BatchAmount=request.values.get('BatchAmount'), BatchDepartment=request.values.get('BatchDepartment'), BatchName=request.values.get('BatchName'), Handler=request.values.get('Handler'), ProductionDate=request.values.get('ProductionDate'), ValidityDate=request.values.get('ValidityDate'), Comment=request.values.get('Comment'), ProductSaveNo=get_uuid())) db_session.commit() return json.dumps({'code': '1000', 'msg': '操作成功'}, ensure_ascii=False)
def quality_standard(): """品名下质检的维护""" try: if request.method == 'GET': # 获取当前节点下的品名 No = request.values.get('No') qs_center = db_session.query(QualityStandardCenter).filter_by( No=No).first() character = [] discern = [] inspect = [] content = [] microbe = [] data = [{ 'No': No, 'Project': qs_center.Project, 'Source': qs_center.Source, 'Character': character, 'Discern': discern, 'Inspect': inspect, 'Content': content, 'Microbe': microbe }] character_data = db_session.query(QualityStandard).filter_by( Product=qs_center.Product, Type='Character').all() for result in character_data: character.append({'id': result.Id, 'value': result.Describe}) discern_data = db_session.query(QualityStandard).filter_by( Product=qs_center.Product, Type='Discern').all() for result in discern_data: discern.append({'id': result.Id, 'value': result.Describe}) inspect_data = db_session.query(QualityStandard).filter_by( Product=qs_center.Product, Type='Inspect').all() for result in inspect_data: inspect.append({'id': result.Id, 'value': result.Describe}) content_data = db_session.query(QualityStandard).filter_by( Product=qs_center.Product, Type='Content').all() for result in content_data: content.append({'id': result.Id, 'value': result.Describe}) microbe_data = db_session.query(QualityStandard).filter_by( Product=qs_center.Product, Type='Microbe').all() for result in microbe_data: microbe.append({'id': result.Id, 'value': result.Describe}) return json.dumps({ 'code': '1000', 'msg': '成功', 'data': data }, cls=MyEncoder, ensure_ascii=False) if request.method == 'POST': # 当前品名下的质检维护 No = request.values.get('No') Product = request.values.get('Product') data = request.values.get('Data') Type = request.values.get('Type') db_session.add( QualityStandard(No=No, Product=Product, Describe=data, Type=Type)) db_session.commit() return json.dumps({ 'code': '1000', 'msg': '添加成功' }, cls=MyEncoder, ensure_ascii=False) if request.method == 'PATCH': Id = request.values.get('Id') data = db_session.query(QualityStandard).filter_by(Id=Id).first() data.Describe = request.values.get('Data') db_session.add(data) db_session.commit() return json.dumps({ 'code': '1000', 'msg': '修改成功' }, cls=MyEncoder, ensure_ascii=False) if request.method == 'DELETE': Id = request.values.get('Id') data = db_session.query(QualityStandard).filter_by(Id=Id).first() db_session.delete(data) db_session.commit() return json.dumps({ 'code': '1000', 'msg': '删除成功' }, cls=MyEncoder, ensure_ascii=False) except Exception as e: log(e) return json.dumps({'code': '2000', 'msg': str(e)})
def classify_tree(): """分类树操作""" try: if request.method == 'GET': # factory = db_session.query(AreaMaintain).first() sql = "select ID,ChildrenTag from ClassifyTree" parent_tags = db_session.execute(sql).fetchall() tags_list = set(item[1] for item in parent_tags) children = [] i = 1 for item in tags_list: # 通过一级节点获取所有对应节点下的值 children2 = [] children1 = {"id": i, "label": item, "children": children2} query_data = db_session.query(ClassifyTree).filter_by( ChildrenTag=item).all() # parent_tag2 = set(item.ParentTag for item in query_data) i += 1 for data in query_data: rank2_data = { "id": data.TagCode, "label": data.TagName, "ParentTagCode": "1" } children2.append(rank2_data) children.append(children1) tree = [{"label": '希尔安药业', "children": children}] return json.dumps({ 'code': '1000', 'msg': '成功', 'data': tree }, cls=MyEncoder, ensure_ascii=False) if request.method == 'POST': parent_name = request.values.get('ParentName') children_name = request.values.get('ChildrenName') code = datetime.now().strftime('%H%M%S%Y%m%d') db_session.add( ClassifyTree(TagCode=code, TagName=children_name, ChildrenTag=parent_name)) db_session.commit() return json.dumps({ 'code': '1000', 'msg': '添加成功' }, cls=MyEncoder, ensure_ascii=False) if request.method == 'PATCH': code = request.values.get('Code') parent_name = request.values.get('ParentName') children_name = request.values.get('ChildrenName') new_type_name = "'" + request.values.get('ChildrenName') + "'" old_data = db_session.query(ClassifyTree).filter_by( TagCode=code).first() type_name = "'" + old_data.TagName + "'" sql = f'update QualityStandardCenter set Type={new_type_name} where Type={type_name}' db_session.execute(sql) data = db_session.query(ClassifyTree).filter_by( TagCode=code).first() data.TagName = children_name data.ChildrenTag = parent_name db_session.add(data) db_session.commit() return json.dumps({ 'code': '1000', 'msg': '修改成功' }, cls=MyEncoder, ensure_ascii=False) if request.method == 'DELETE': code = request.values.get('Code') children_name = "'" + request.values.get('ChildrenName') + "'" data = db_session.query(ClassifyTree).filter_by( TagCode=code).first() db_session.delete(data) db_session.commit() sql = f'delete from QualityStandardCenter where Type={children_name}' db_session.execute(sql) return json.dumps({ 'code': '1000', 'msg': '删除成功' }, cls=MyEncoder, ensure_ascii=False) except Exception as e: log(e) return json.dumps({'code': '2000', 'msg': str(e)})
def product(): """节点下品名的维护""" try: if request.method == 'GET': # 获取当前节点下的品名 code = request.values.get('Code') # 当前页码 page = int(request.values.get('Page')) # 每页记录数 per_page = int(request.values.get('PerPage')) tag = db_session.query(ClassifyTree).filter_by( TagCode=code).first() results = db_session.query(QualityStandardCenter).order_by( QualityStandardCenter.Id.asc()).filter_by( Type=tag.TagName).all() data = results[(page - 1) * per_page:page * per_page] return json.dumps( { 'code': '1000', 'msg': '成功', 'data': data, 'total': len(results) }, cls=MyEncoder, ensure_ascii=False) data = '' if request.method == 'POST': # 当前节点下品名的增加-修改 if request.values.get('Action') == 'add': data = QualityStandardCenter() data.No = get_short_id() # data.Product = request.values.get('Product') # data.Type = request.values.get('Type') # data.Code = request.values.get('Code') # data.Source = request.values.get('Source') # data.Project = request.values.get('Project') # data.Unit = request.values.get('Unit') # data.IntoUser = request.values.get('IntoUser') # data.IntoTime = request.values.get('IntoTime') # db_session.add(data) # db_session.commit() if request.values.get('Action') == 'update': No = request.values.get('No') data = db_session.query(QualityStandardCenter).filter_by( No=No).first() data.Product = request.values.get('Product') data.Type = request.values.get('Type') data.Code = request.values.get('Code') data.Source = request.values.get('Source') data.Project = request.values.get('Project') data.Unit = request.values.get('Unit') data.IntoUser = request.values.get('IntoUser') data.IntoTime = request.values.get('IntoTime') data.AlterTime = request.values.get('AlterTime') data.AlterUser = request.values.get('AlterUser') db_session.add(data) db_session.commit() return json.dumps({ 'code': '1000', 'msg': '操作成功' }, cls=MyEncoder, ensure_ascii=False) if request.method == 'DELETE': items = request.json.get('Id') for item in items: data = db_session.query(QualityStandardCenter).get(int(item)) quality_standard = db_session.query(QualityStandard).filter_by( No=data.No).all() for i in quality_standard: db_session.delete(i) db_session.commit() db_session.delete(data) db_session.commit() return json.dumps({ 'code': '1000', 'msg': '操作成功' }, cls=MyEncoder, ensure_ascii=False) except Exception as e: log(e) return json.dumps({'code': '2000', 'msg': str(e)})
def check_form(): """样品请检申请""" try: if request.method == 'GET': # 当前页码 page = int(request.values.get('Page')) # 每页记录数 per_page = int(request.values.get('PerPage')) status = request.values.get('Status') start_time = "'" + request.values.get('DateTime') + " 00:00:00'" end_time = "'" + request.values.get('DateTime') + " 23:59:59'" Product = request.values.get('Product') results = db_session.query(CheckForm).filter( CheckForm.Name == Product, CheckForm.Status == status, CheckForm.CheckDate.between(start_time, end_time)).order_by( CheckForm.Id.desc()).all() data = results[(page - 1) * per_page:page * per_page] return json.dumps( { 'code': '1000', 'msg': '成功', 'data': data, 'total': len(results) }, cls=MyEncoder, ensure_ascii=False) if request.method == 'POST': data = request.values CheckNumber = data.get('CheckNumber') ProductType = data.get('ProductType') Name = data.get('Name') Specs = data.get('Specs') Supplier = data.get('Supplier') ProductNumber = data.get('ProductNumber') Number = data.get('Number') Amount = data.get('Amount') Unit = data.get('Unit') CheckProcedure = data.get('CheckProcedure') check_project = data.get('CheckProject') CheckDepartment = data.get('CheckDepartment') CheckDate = data.get('CheckDate') CheckUser = data.get('CheckUser') Type = data.get('Type') Comment = data.get('Comment') CheckProjectNO = get_uuid() db_session.add( CheckForm(Name=Name, Specs=Specs, Supplier=Supplier, ProductNumber=ProductNumber, Number=Number, Amount=Amount, Unit=Unit, CheckProcedure=CheckProcedure, CheckDepartment=CheckDepartment, CheckDate=CheckDate, CheckUser=CheckUser, Type=Type, Comment=Comment, CheckProjectNO=CheckProjectNO, CheckNumber=CheckNumber, ProductType=ProductType, Life='待审核')) db_session.commit() json_data = json.loads(check_project) for result in json_data: data = [] for item in json_data[result]: c = CheckProject() c.No = CheckNumber c.Product = Name c.Describe = item c.Type = result c.CheckProjectNO = CheckProjectNO data.append(c) db_session.add_all(data) db_session.commit() return json.dumps({ 'code': '1000', 'msg': '操作成功' }, ensure_ascii=False) except Exception as e: log(e) return json.dumps({'code': '2000', 'msg': str(e)})