You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
199 lines
10 KiB
199 lines
10 KiB
# -*- coding: utf-8 -*-
|
|
"""
|
|
api.entry
|
|
~~~~~~~~~~~~~~
|
|
|
|
有关进出库的接口.
|
|
|
|
:copyright: 云南新八达科技有限公司.
|
|
:author: 李进才.
|
|
"""
|
|
from sqlalchemy import or_, func
|
|
import datetime
|
|
|
|
from utils.PageHepler import db_page
|
|
from utils.apiDoc import *
|
|
from utils.dictionaryHelper import GetList
|
|
from utils.entryHelper import get_entry_list
|
|
import pandas as pd
|
|
|
|
|
|
@entry.route('/all')
|
|
class EntryAll(Resource):
|
|
@staticmethod
|
|
def post():
|
|
data = request.args
|
|
if data.get('query') is None:
|
|
return SuccessResponse(ResultCode.SOURCE_DATA_NONE, None, None)
|
|
reagentQuery = db.session.query(ReagtEntry.Name,
|
|
ReagtEntry.Specification,
|
|
ReagtEntry.Maker,
|
|
ReagtEntry.Unit,
|
|
ReagtEntry.CertificationCode,
|
|
ReagtEntry.Number,
|
|
ReagtEntry.Ratio,
|
|
ReagtEntry.SmallestUnit,
|
|
ReagtEntry.UnitPrice,
|
|
ReagtEntry.SellingPrice,
|
|
ReagtEntry.ProductionBatch,
|
|
ReagtEntry.MinValue,
|
|
ReagtEntry.MaxValue,
|
|
ReagtEntry.SupplierName,
|
|
ReagtEntry.TypeName,
|
|
ReagtEntry.Position,
|
|
ReagtEntry.EntryId).filter(
|
|
or_(ReagtEntry.Name.contains(data['query']), ReagtEntry.PinYinCode
|
|
.contains(data['query']))) \
|
|
.filter(ReagtEntry.Using == True)
|
|
return SuccessResponse(ResultCode.SUCCESS,
|
|
{'list': db_page(reagentQuery, ReagtEntry.EntryId, data, 6),
|
|
'totalNumber': reagentQuery.count()},
|
|
None)
|
|
|
|
|
|
@entry.route('/expiration')
|
|
class EntryExpiration(Resource):
|
|
@staticmethod
|
|
def get():
|
|
data = request.args
|
|
expirationReagentFilter = db.session.query(ReagtReagent.Name, ReagtStock.Expiration,
|
|
ReagtReagent.Specification, ReagtStock.Code,
|
|
ReagtStock.Position). \
|
|
join(ReagtReagent, ReagtStock.ReagentId == ReagtReagent.ReagentId). \
|
|
filter(ReagtStock.Expiration > datetime.now()). \
|
|
filter(ReagtStock.Expiration < (datetime.now() + timedelta(days=10))). \
|
|
order_by(ReagtStock.InTime.desc())
|
|
expirationReagentPaginate = expirationReagentFilter.paginate(int(data['pageNumber']), 8,
|
|
error_out=False)
|
|
resultList = [dict(zip(result.keys(), result)) for result in expirationReagentPaginate.items]
|
|
return SuccessResponse(ResultCode.SUCCESS, {'list': resultList,
|
|
'totalNumber': expirationReagentFilter.count()},
|
|
None)
|
|
|
|
|
|
@entry.route('/expirationExport')
|
|
class EntryExpirationExport(Resource):
|
|
@staticmethod
|
|
def get():
|
|
timestamp = datetime.now().timestamp()
|
|
expirationReagentFilter = db.session.query(ReagtReagent.Name, ReagtStock.Expiration,
|
|
ReagtStock.LastNumber,
|
|
ReagtReagent.Unit,
|
|
ReagtStock.MinNumberUnit,
|
|
ReagtReagent.SmallestUnit,
|
|
ReagtStock.SupplierName,
|
|
ReagtReagent.UnitPrice,
|
|
ReagtReagent.Maker,
|
|
ReagtStock.ProductionBatch,
|
|
ReagtReagent.MinValue,
|
|
ReagtReagent.MaxValue,
|
|
ReagtReagent.Specification, ReagtStock.Code,
|
|
ReagtStock.Position). \
|
|
join(ReagtReagent, ReagtStock.ReagentId == ReagtReagent.ReagentId). \
|
|
filter(ReagtStock.Expiration <= datetime.now()). \
|
|
order_by(ReagtStock.InTime.desc())
|
|
Name, Specification, LastNumber, Unit, MinNumberUnit, \
|
|
SmallestUnit, SupplierName, UnitPrice, \
|
|
Maker, ProductionBatch, Expiration, MaxValue, MinValue = [], [], [], [], [], [], [], [], [], [], [], [], []
|
|
for item in expirationReagentFilter:
|
|
Name.append(item.Name)
|
|
Specification.append(item.Specification)
|
|
LastNumber.append(item.LastNumber)
|
|
Unit.append(item.Unit)
|
|
MinNumberUnit.append(item.MinNumberUnit)
|
|
SmallestUnit.append(item.SmallestUnit)
|
|
SupplierName.append(item.SupplierName)
|
|
UnitPrice.append(item.UnitPrice)
|
|
Maker.append(item.Maker)
|
|
ProductionBatch.append(item.ProductionBatch)
|
|
Expiration.append(item.Expiration)
|
|
MaxValue.append(item.MaxValue)
|
|
MinValue.append(item.MinValue)
|
|
dit = {'耗材名称': Name, '规格': Specification, '数量(大单位)': LastNumber, '大单位': Unit,
|
|
'数量(小单位)': MinNumberUnit, '小单位': SmallestUnit, '供应商': SupplierName, '单价': UnitPrice,
|
|
'生产厂家': Maker, '产品批号': ProductionBatch, '效期': Expiration, '最大库存数量': MaxValue,
|
|
'最小库存数量': MinValue}
|
|
writer = pd.ExcelWriter('./file/' + '过期耗材汇总表' + str(timestamp).replace('.', '-') + '.xlsx')
|
|
df = pd.DataFrame(dit)
|
|
# columns参数用于指定生成的excel中列的顺序
|
|
df.to_excel(writer, columns=['耗材名称', '规格', '数量(大单位)', '大单位', '数量(小单位)', '小单位',
|
|
'供应商', '单价', '生产厂家', '产品批号', '效期', '最大库存数量',
|
|
'最小库存数量'], index=False, encoding='utf-8',
|
|
sheet_name='过期耗材汇总表')
|
|
writer.save()
|
|
return SuccessResponse(ResultCode.SUCCESS, '过期耗材汇总表' + str(timestamp).replace('.', '-'), None)
|
|
|
|
|
|
@entry.route('/bottomLimit')
|
|
class BottomLimit(Resource):
|
|
@staticmethod
|
|
def get():
|
|
bottomLimitFilter = db.session.query(ReagtReagent.Name, ReagtReagent.Specification,
|
|
ReagtReagent.MinValue,
|
|
func.sum(func.coalesce(ReagtStock.LastNumber, 0)).label('AllLastNumber')). \
|
|
join(ReagtStock, ReagtStock.ReagentId == ReagtReagent.ReagentId, isouter=True). \
|
|
filter(ReagtReagent.Using == True). \
|
|
group_by(ReagtReagent.Name, ReagtReagent.Specification, ReagtReagent.MinValue).subquery()
|
|
bottomLimitFilter = db.session.query(bottomLimitFilter.c.Name, bottomLimitFilter.c.Specification,
|
|
bottomLimitFilter.c.MinValue,
|
|
bottomLimitFilter.c.AllLastNumber,
|
|
(bottomLimitFilter.c.MinValue - bottomLimitFilter.c.AllLastNumber).label(
|
|
'Difference')
|
|
). \
|
|
filter(bottomLimitFilter.c.AllLastNumber < bottomLimitFilter.c.MinValue). \
|
|
order_by((bottomLimitFilter.c.MinValue - bottomLimitFilter.c.AllLastNumber))
|
|
bottomLimitPaginate = bottomLimitFilter.paginate(int(request.args['pageNumber']), 8, error_out=False)
|
|
resultList = [dict(zip(result.keys(), result)) for result in bottomLimitPaginate.items]
|
|
return SuccessResponse(ResultCode.SUCCESS, {'list': resultList,
|
|
'totalNumber': bottomLimitFilter.count()}, None)
|
|
|
|
|
|
@entry.route('/upperLimit')
|
|
class UpperLimit(Resource):
|
|
@staticmethod
|
|
def get():
|
|
upperLimitFilter = db.session.query(ReagtReagent.Name, ReagtReagent.Specification,
|
|
ReagtReagent.MaxValue,
|
|
func.sum(ReagtStock.LastNumber).label('AllLastNumber')). \
|
|
join(ReagtReagent, ReagtStock.ReagentId == ReagtReagent.ReagentId). \
|
|
group_by(ReagtReagent.Name, ReagtReagent.Specification, ReagtReagent.MaxValue).subquery()
|
|
upperLimitFilter = db.session.query(upperLimitFilter.c.Name, upperLimitFilter.c.Specification,
|
|
upperLimitFilter.c.MaxValue,
|
|
upperLimitFilter.c.AllLastNumber,
|
|
(upperLimitFilter.c.AllLastNumber - upperLimitFilter.c.MaxValue).label(
|
|
'Difference')). \
|
|
filter(upperLimitFilter.c.AllLastNumber > upperLimitFilter.c.MaxValue). \
|
|
order_by((upperLimitFilter.c.AllLastNumber - upperLimitFilter.c.MaxValue))
|
|
upperLimitPaginate = upperLimitFilter.paginate(int(request.args['pageNumber']), 8, error_out=False)
|
|
app.logger.info(upperLimitPaginate.items)
|
|
resultList = [dict(zip(result.keys(), result)) for result in upperLimitPaginate.items]
|
|
return SuccessResponse(ResultCode.SUCCESS, {'list': resultList,
|
|
'totalNumber': upperLimitFilter.count()}, None)
|
|
|
|
|
|
@entry.route('/specification')
|
|
class Specification(Resource):
|
|
@staticmethod
|
|
def get():
|
|
return get_entry_list(ReagtReagent.Specification, request.args)
|
|
|
|
|
|
@entry.route('/maker')
|
|
class Maker(Resource):
|
|
@staticmethod
|
|
def get():
|
|
return get_entry_list(ReagtReagent.Maker, request.args)
|
|
|
|
|
|
@entry.route('/unit')
|
|
class Unit(Resource):
|
|
@staticmethod
|
|
def get():
|
|
return get_entry_list(ReagtReagent.Unit, request.args)
|
|
|
|
|
|
@entry.route('/reagentType')
|
|
class ReagentType(Resource):
|
|
@staticmethod
|
|
def get():
|
|
return get_entry_list(ReagtReagent.TypeName, request.args)
|
|
|