1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006 |
- package service
-
- import (
- "XT_New/models"
- "fmt"
- "github.com/jinzhu/gorm"
- "time"
- )
-
- func CreateAutomaticReduceRecord(config *models.GobalConfig) (err error) {
- err = writeDb.Model(&models.GobalConfig{}).Create(config).Error
- return
- }
-
- func CreateDrugAutomaticReduceRecord(config *models.DrugStockConfig) (err error) {
- err = writeDb.Model(&models.DrugStockConfig{}).Create(config).Error
- return
- }
-
- func FindAutomaticReduceRecordByOrgId(org_id int64) (err error, config models.GobalConfig) {
- err = readDb.Model(&models.GobalConfig{}).Where("status = 1 AND org_id = ?", org_id).First(&config).Error
- return
- }
-
- func FindDrugStockAutomaticReduceRecordByOrgId(org_id int64) (err error, config models.DrugStockConfig) {
- err = readDb.Model(&models.DrugStockConfig{}).Where("status = 1 AND org_id = ?", org_id).First(&config).Error
- return
- }
- func UpdateAutomaticReduceRecord(config *models.GobalConfig) (err error) {
- err = writeDb.Save(config).Error
- return
- }
-
- func UpdateGobalConfig(user_org_id int64) error {
-
- config := models.GobalConfig{}
- err := XTWriteDB().Model(&config).Where("org_id = ? and status = 1").Updates(map[string]interface{}{"is_open": 2}).Error
- return err
- }
-
- func UpdateDrugStockAutomaticReduceRecord(config *models.DrugStockConfig) (err error) {
- err = writeDb.Save(config).Error
- return
- }
-
- func CreatePrintTemplateRecord(template *models.GobalTemplate) (err error) {
- err = writeDb.Model(&models.GobalTemplate{}).Create(template).Error
- return
- }
-
- func FindPrintTemplateByOrgId(org_id int64) (err error, template models.GobalTemplate) {
- err = readDb.Model(&models.GobalTemplate{}).Where("status = 1 AND org_id = ?", org_id).Find(&template).Error
- return
- }
-
- func UpdatePrintTemplate(template *models.GobalTemplate) (err error) {
- err = writeDb.Save(template).Error
- return
- }
-
- func CreateConfigData(config *models.DataUploadConfig) (err error) {
- err = writeDb.Create(config).Error
- return
- }
-
- func SaveConfigData(config *models.DataUploadConfig) (err error) {
- err = writeDb.Save(config).Error
- return
- }
-
- func GetConfigData(org_id int64, config_type int64) (config models.DataUploadConfig, err error) {
- err = readDb.Model(&models.DataUploadConfig{}).Where("status = 1 AND org_id = ? AND config_type = ?", org_id, config_type).First(&config).Error
- return
- }
-
- func GetDockingStatus(config_type int64, province int64, city int64) (config models.DockingStatus, err error) {
- err = readDb.Model(&models.DockingStatus{}).Where("status = 1 AND docking_type = ? AND province_id = ? AND city_id = ?", config_type, province, city).First(&config).Error
- return
- }
-
- func GetConfigDataById(id int64) (config models.DataUploadConfig, err error) {
- err = readDb.Model(&models.DataUploadConfig{}).Where("id = ?", id).First(&config).Error
- return
- }
-
- func FindDoctorAdviceRecordByOrgId(org_id int64) (err error, config models.DoctorAdviceConfig) {
- err = readDb.Model(&models.DoctorAdviceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&config).Error
- return
- }
-
- func CreateDoctorAdviceRecord(config *models.DoctorAdviceConfig) (err error) {
- err = writeDb.Model(&models.DoctorAdviceConfig{}).Create(config).Error
- return
- }
-
- func UpdateDoctorAdviceRecord(config *models.DoctorAdviceConfig) (err error) {
- err = writeDb.Save(config).Error
- return
- }
-
- func UpdateFiledConfig(org_id int64) (err error) {
- err = writeDb.Model(&models.FiledConfig{}).Where("org_id = ? AND sys_module = 0", org_id).Updates(map[string]interface{}{"is_show": 1}).Error
- return
- }
-
- func FindAllHideFiledConfig(template_id int64) (err error, config []*models.FiledConfig) {
- err = readDb.Model(&models.FiledConfig{}).Where("sys_module = ? AND is_show = 2", template_id).Find(&config).Error
- return
- }
-
- func UpdateShowFieldConfig(org_id int64, fileds []string) (err error) {
- err = writeDb.Model(&models.FiledConfig{}).Where("org_id = ? AND filed_name in (?) AND sys_module = 0 ", org_id, fileds).Updates(map[string]interface{}{"is_show": 2}).Error
- return
- }
-
- func FindAllAdviceParentTemplate(org_id int64) (template []*models.DoctorAdviceParentTemplate) {
- readDb.Model(&models.DoctorAdviceParentTemplate{}).Preload("DoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
- return db.Preload("SubDoctorAdviceTemplate", "status = 1 AND org_id = ?", org_id).Where("status = 1 AND parent_id = 0 AND org_id = ?", org_id)
- }).Where("status = 1 AND org_id = ? ", org_id).Find(&template)
- return
- }
-
- func CreateDoctorParentTemplate(template *models.DoctorAdviceParentTemplate) (err error) {
- err = writeDb.Create(&template).Error
- return
- }
-
- func FindAllAdviceTemplates(org_id int64, parent_template_id int64) (template []*models.DoctorAdviceTemplate, err error) {
- err = readDb.Model(&models.DoctorAdviceTemplate{}).Where("status = 1 AND org_id = ? AND template_id = ?", org_id, parent_template_id).Find(&template).Error
- return
- }
-
- func CreateDoctorTemplate(template *models.DoctorAdviceTemplate) (err error) {
- err = writeDb.Create(&template).Error
- return
- }
-
- func CreateSystemDialysisSolution(solution *models.SystemPrescription) (err error) {
- err = writeDb.Create(solution).Error
- return
- }
-
- func UpdateSystemDialysisSolution(solution *models.SystemPrescription) (err error) {
- err = writeDb.Save(solution).Error
- return
- }
-
- func FindSystemDialysisSolution(orgID int64, id int64) (solution models.SystemPrescription, err error) {
- err = readDb.Model(&models.SystemPrescription{}).Where("id = ? and status=1 and user_org_id=?", id, orgID).First(&solution).Error
- return
- }
-
- func FindAllSystemPrescription(orgID int64) (solution []*models.SystemPrescription, err error) {
- err = readDb.Model(&models.SystemPrescription{}).Where("status=1 and user_org_id=?", orgID).Find(&solution).Error
- return
- }
-
- func FindSystemDialysisPrescriptionByMode(orgID int64, id int64) (solution models.SystemPrescription, err error) {
- err = readDb.Model(&models.SystemPrescription{}).Where("mode_id = ? and status=1 and user_org_id=?", id, orgID).First(&solution).Error
- return
- }
-
- func CreateAdviceInitConfig(adviceInit *models.AdviceInit) (err error) {
- err = writeDb.Create(&adviceInit).Error
- return
- }
-
- func FindAdviceInitConfig(org_id int64) (adviceInit models.AdviceInit, err error) {
- err = readDb.Model(&models.AdviceInit{}).Where("user_org_id = ? AND status = 1 ", org_id).First(&adviceInit).Error
- return
- }
-
- func GetPrint(ids []int64, orgid int64, advicetype int64, stoptype int64) (doctor []*models.DoctorAdvice, err error) {
- db := XTReadDB().Model(&doctor).Where("status =1")
- if len(ids) == 1 {
-
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- if advicetype > 0 {
- db = db.Where("advice_type = ?", advicetype)
- }
- if stoptype > 0 {
- db = db.Where("stop_state = ?", stoptype)
- }
-
- err = db.Where("groupno = ?", ids[0]).Find(&doctor).Error
- } else {
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- if advicetype > 0 {
- db = db.Where("advice_type = ?", advicetype)
- }
- if stoptype > 0 {
- db = db.Where("stop_state = ?", stoptype)
- }
- err = db.Where("groupno IN(?)", ids).Find(&doctor).Error
- }
-
- return doctor, err
- }
-
- func GetExportLogByType(org_id int64, log_type int64) (log []*models.ExportLog, err error) {
- err = readDb.Model(&models.ExportLog{}).Where("user_org_id = ? AND status = 1 AND log_type = ?", org_id, log_type).
- Preload("ExportErrLog", "status = 1").Order("export_time desc").Find(&log).Error
- return
- }
-
- func FindXTHisRecordByOrgId(org_id int64) (err error, config models.XtHisConfig) {
- err = readDb.Model(&models.XtHisConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&config).Error
- return
- }
-
- func FindHisStockPriceRecordByOrgId(org_id int64) (err error, config models.HisStockPriceConfig) {
- err = readDb.Model(&models.HisStockPriceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&config).Error
- return
- }
-
- func UpdateXTHisRecord(config *models.XtHisConfig) (err error) {
- err = writeDb.Save(config).Error
- return
- }
-
- func CreateXTHisRecord(config *models.XtHisConfig) (err error) {
- err = writeDb.Model(&models.XtHisConfig{}).Create(config).Error
- return
- }
-
- func CreateHisStockPriceRecord(config *models.HisStockPriceConfig) (err error) {
- err = writeDb.Model(&models.HisStockPriceConfig{}).Create(config).Error
- return
- }
-
- func UpdateHisStockPriceRecord(config *models.HisStockPriceConfig) (err error) {
- err = writeDb.Save(config).Error
- return
- }
-
- //TODO:项目开关
- func FindXTHisProjectByOrgId(org_id int64) (err error, config models.XtHisProjectConfig) {
- err = readDb.Model(&models.XtHisProjectConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&config).Error
- return
- }
-
- func FindXTHisProjectByOrgIdOne(org_id int64) (err error, config models.XtHisProjectConfig) {
- err = readDb.Model(&models.XtHisProjectConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&config).Error
- return
- }
-
- func UpdateXTHisProjectRecord(config *models.XtHisProjectConfig) (err error) {
- err = writeDb.Save(config).Error
- return
- }
-
- func CreateXTHisProjectRecord(config *models.XtHisProjectConfig) (err error) {
- err = writeDb.Model(&models.XtHisProjectConfig{}).Create(config).Error
- return
- }
-
- func GetExportHisOrderList(user_org_id int64, start_time int64, end_time int64, p_type int64) (order []*models.HisOrder, err error) {
- db := readDb.Model(&models.HisOrder{})
- if start_time != 0 {
- db = db.Where("his_order.settle_accounts_date>=?", start_time)
- }
- if end_time != 0 {
- db = db.Where("his_order.settle_accounts_date<=?", end_time)
- }
-
- if p_type > 0 {
- db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.order_status = 2 AND p_type = ? ", user_org_id, p_type)
-
- } else {
-
- db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.order_status = 2", user_org_id)
-
- }
-
- db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
- Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
- Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
- Preload("HisHospitalCheckRecord", "status = 1 AND user_org_id = ? AND in_hospital_status = 1 AND out_hospital_status = 1 ", user_org_id).
- Preload("HisPrescriptionInfo", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND user_org_id = ?", user_org_id).Preload("XtHisDepartment", "status = 1")
- })
- err = db.Order("setl_time asc").Find(&order).Error
- return
- }
-
- func GetDrugInOrderDetail(startime int64, endtime int64, orgid int64, orderType int64, manufacturerId int64, keyword string, page int64, limit int64, storehouse_id int64) (drugInfo []*models.BloodDrugWarehouseInfo, total int64, err error) {
-
- likeKey := "%" + keyword + "%"
- offset := (page - 1) * limit
-
- db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1 and x.is_check = 1")
- dbOne := XTReadDB().Table("xt_base_drug as t").Where("t.status =1")
- dbTwo := XTReadDB().Table("xt_drug_warehouse as s").Where("s.status = 1")
- dbThree := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
-
- fmt.Print(dbOne, dbTwo, dbThree)
- if startime > 0 {
- db = db.Where("x.ctime >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.org_id =?", orgid)
- }
-
- if storehouse_id > 0 {
- db = db.Where("x.storehouse_id = ?", storehouse_id)
- }
-
- if len(keyword) > 0 {
- db = db.Joins("left join sgj_xt.xt_drug_warehouse as o on o.id = x.warehousing_id left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = o.creater").Group("s.id")
- db = db.Where("x.warehousing_order like ? or t.drug_name like ? or r.user_name like ? ", likeKey, likeKey, likeKey)
-
- }
-
- if manufacturerId > 0 {
- err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.total_price,x.dealer,t.manufacturer,x.remark,x.ctime,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.storehouse_id,x.max_unit as count_unit,t.drug_type,t.drug_name,t.drug_spec,t.min_unit,t.dose,t.dose_unit,t.max_unit,t.min_number,s.creater").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ? and t.status =1", orgid).Where("t.manufacturer = ?", manufacturerId).Joins("left join xt_drug_warehouse as s on s.id = x.warehousing_id and s.org_id = ? and s.status =1", orgid).Order("x.id desc").Count(&total).Offset(offset).Limit(limit).Scan(&drugInfo).Error
- } else {
- err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.total_price,x.dealer,t.manufacturer,x.remark,x.ctime,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.storehouse_id,x.max_unit as count_unit,t.drug_type,t.drug_name,t.drug_spec,t.min_unit,t.dose,t.dose_unit,t.max_unit,t.min_number,s.creater").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ? and t.status =1", orgid).Joins("left join xt_drug_warehouse as s on s.id = x.warehousing_id and s.org_id = ? and s.status =1", orgid).Order("x.id desc").Count(&total).Offset(offset).Limit(limit).Scan(&drugInfo).Error
- }
-
- return drugInfo, total, err
- }
-
- func GetDrugReturnOrder(startime int64, endtime int64, orgid int64, orderType int64, manufacturerId int64, keyword string, limit int64, page int64) (returninfo []*models.BloodDrugSalesReturnInfo, total int64, err error) {
-
- likeKey := "%" + keyword + "%"
- offset := (page - 1) * limit
- db := XTReadDB().Table("xt_drug_sales_return_info as x").Where("x.status =1")
- dbOne := XTReadDB().Table("xt_base_drug as s").Where("s.status =1")
- dbTwo := XTReadDB().Table("xt_drug_sales_return as r").Where("r.status = 1")
- fmt.Print(dbOne, dbTwo)
- if startime > 0 {
- db = db.Where("x.ctime >= ?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if orderType > 0 {
- db = db.Where("x.type = ?", orderType)
- }
-
- if len(keyword) > 0 {
-
- db = db.Where("x.order_number like ? or s.drug_spec like ? or r.creater like ?", likeKey, likeKey, likeKey)
- }
-
- if manufacturerId > 0 {
- err = db.Select("x.id,x.drug_id,x.sales_return_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,x.dealer,x.manufacturer,x.retail_price,x.retail_total_price,x.number,s.drug_name,s.drug_spec,s.drug_type,s.min_unit,r.creater").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_sales_return as r on r.id = x.sales_return_id and r.org_id = ? and r.status =1", orgid).Where("r.manufacturer = ?", manufacturerId).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&returninfo).Error
- } else {
- err = db.Select("x.id,x.drug_id,x.sales_return_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,x.dealer,x.manufacturer,x.retail_price,x.retail_total_price,x.number,s.drug_name,s.drug_spec,s.drug_type,s.min_unit,r.creater").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_sales_return as r on r.id = x.sales_return_id and r.org_id = ? and r.status =1", orgid).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&returninfo).Error
- }
-
- return returninfo, total, err
- }
-
- func GetDrugOutOrder(startime int64, endtime int64, orgid int64, orderType int64, manufacturerId int64, keyword string, page int64, limit int64, storehouse_id int64) (outinfo []*models.BloodDrugWarehouseOutInfo, total int64, err error) {
-
- likeKey := "%" + keyword + "%"
- offset := (page - 1) * limit
- db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status =1 and x.is_check = 1")
- dbOne := XTReadDB().Table("xt_base_drug as b").Where("b.status =1")
- dbTwo := XTReadDB().Table("xt_drug_warehouse_out as t").Where("t.status = 1")
- fmt.Print(dbOne, dbTwo)
- if startime > 0 {
- db = db.Where("x.sys_record_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.sys_record_time <=?", endtime)
- }
-
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if orderType > 0 {
- db = db.Where("x.type = ?", orderType)
- }
-
- if storehouse_id > 0 {
- db = db.Where("x.storehouse_id = ?", storehouse_id)
- }
-
- if len(keyword) > 0 {
- db = db.Joins("left join sgj_xt.xt_drug_warehouse_out as o on o.id = x.warehouse_out_id left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = o.creater").Group("x.id")
- db = db.Where("x.warehouse_out_order_number like ? or b.drug_name like ? or r.user_name like ?", likeKey, likeKey, likeKey)
- }
-
- if manufacturerId > 0 {
- err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.count_unit,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,x.storehouse_id,b.drug_name,b.drug_spec,b.drug_type,b.min_unit,b.max_unit,b.min_number,b.dose,b.dose_unit,b.last_price,t.creater").Joins("left join xt_base_drug as b on b.id = x.drug_id and b.org_id = ? and b.status =1", orgid).Joins("left join xt_drug_warehouse_out as t on t.id = x.warehouse_out_id and t.org_id = ? and t.status =1", orgid).Where("t.manufacturer = ?", manufacturerId).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&outinfo).Error
- } else {
- err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.count_unit,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,x.storehouse_id,b.drug_name,b.drug_spec,b.drug_type,b.min_unit,b.max_unit,b.min_number,b.dose,b.dose_unit,b.last_price,t.creater").Joins("left join xt_base_drug as b on b.id = x.drug_id and b.org_id = ? and b.status =1", orgid).Joins("left join xt_drug_warehouse_out as t on t.id = x.warehouse_out_id and t.org_id = ? and t.status =1", orgid).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&outinfo).Error
- }
-
- return outinfo, total, err
- }
-
- func GetDrugCancelOrderPrint(startime int64, endtime int64, orgid int64, orderType int64, manufacturerId int64, keyword string, storehouse_id int64) (info []*models.BloodDrugCancelStockInfo, err error) {
- likeKey := "%" + keyword + "%"
- db := XTReadDB().Table("xt_drug_cancel_stock_info as x").Where("x.status =1")
- dbOne := XTReadDB().Table("xt_base_drug as s").Where("s.status =1")
- dbTwo := XTReadDB().Table("xt_drug_cancel_stock as t").Where("t.status = 1")
- fmt.Print(dbOne, dbTwo)
- if startime > 0 {
- db = db.Where("x.ctime >= ?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if orderType > 0 {
- db = db.Where("x.type = ? ", orderType)
- }
- if len(keyword) > 0 {
- db = db.Where("x.order_number like ? or s.drug_spec like ? or t.creater like ?", likeKey, likeKey, likeKey)
- }
- if storehouse_id > 0 {
- db = db.Where("x.storehouse_id = ?", storehouse_id)
- }
-
- if manufacturerId > 0 {
- err = db.Select("x.id,x.max_unit as unit,x.drug_id,x.cancel_stock_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,x.dealer,x.manufacturer,x.retail_price,x.retail_total_price,x.number,x.storehouse_id,s.drug_name,s.drug_type,s.drug_spec,s.min_unit,t.creater,s.dose,s.dose_unit,s.min_number,s.max_unit").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_cancel_stock as t on t.id = x.cancel_stock_id and t.org_id = ? and t.status =1", orgid).Where("t.manufacturer = ?", manufacturerId).Order("x.ctime desc").Group("x.drug_id").Scan(&info).Error
- } else {
- err = db.Select("x.id,x.max_unit as unit,x.drug_id,x.cancel_stock_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,x.dealer,x.manufacturer,x.retail_price,x.retail_total_price,x.number,x.storehouse_id,s.drug_name,s.drug_type,s.drug_spec,s.min_unit,t.creater,s.dose,s.dose_unit,s.min_number,s.max_unit").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_cancel_stock as t on t.id = x.cancel_stock_id and t.org_id = ? and t.status =1", orgid).Order("x.ctime desc").Group("x.drug_id").Scan(&info).Error
- }
-
- return info, err
- }
-
- func GetDrugCancelOrder(startime int64, endtime int64, orgid int64, orderType int64, manufacturerId int64, keyword string, page int64, limit int64, storehouse_id int64) (cancel []*models.BloodDrugCancelStockInfo, total int64, err error) {
-
- likeKey := "%" + keyword + "%"
- offset := (page - 1) * limit
- db := XTReadDB().Table("xt_drug_cancel_stock_info as x").Where("x.status =1")
- dbOne := XTReadDB().Table("xt_base_drug as s").Where("s.status =1")
- dbTwo := XTReadDB().Table("xt_drug_cancel_stock as t").Where("t.status = 1")
- fmt.Print(dbOne, dbTwo)
- if startime > 0 {
- db = db.Where("x.ctime >= ?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if orderType > 0 {
- db = db.Where("x.type = ? ", orderType)
- }
- if storehouse_id > 0 {
- db = db.Where("x.storehouse_id = ?", storehouse_id)
- }
- if len(keyword) > 0 {
- db = db.Joins("left join sgj_xt.xt_drug_cancel_stock as o on o.id = x.cancel_stock_id left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = o.creater").Group("o.id")
-
- db = db.Where("x.order_number like ? or s.drug_spec like ? or r.user_name like ? or s.drug_name like ?", likeKey, likeKey, likeKey, likeKey)
- }
-
- if manufacturerId > 0 {
- err = db.Select("x.id,x.max_unit as unit,x.drug_id,x.cancel_stock_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,x.dealer,x.manufacturer,x.retail_price,x.retail_total_price,x.number,x.storehouse_id,s.drug_name,s.drug_type,s.drug_spec,s.min_unit,t.creater,s.dose,s.dose_unit,s.min_number,s.max_unit").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_cancel_stock as t on t.id = x.cancel_stock_id and t.org_id = ? and t.status =1", orgid).Where("t.manufacturer = ?", manufacturerId).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&cancel).Error
- } else {
- err = db.Select("x.id,x.max_unit as unit,x.drug_id,x.cancel_stock_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,x.dealer,x.manufacturer,x.retail_price,x.retail_total_price,x.number,x.storehouse_id,s.drug_name,s.drug_type,s.drug_spec,s.min_unit,t.creater,s.dose,s.dose_unit,s.min_number,s.max_unit").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_cancel_stock as t on t.id = x.cancel_stock_id and t.org_id = ? and t.status =1", orgid).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&cancel).Error
- }
-
- return cancel, total, err
- }
-
- func FindPrintStockGoodInfoByType(types int, startTime int64, end_time int64, orgId int64) (list []*models.StockInfo, err error) {
-
- db := XTReadDB().Model(&models.StockInfo{})
- db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgId)
- if types == 1 {
- db = db.Joins("JOIN xt_warehouse_info AS info ON info.good_id=xt_good_information.id AND info.status = 1 AND info.org_id = ?", orgId).Group("xt_good_information.id")
- db = db.Preload("QueryWarehousingInfo", func(db *gorm.DB) *gorm.DB {
- return db.Where("xt_warehouse_info.org_id = ? AND xt_warehouse_info.status = 1", orgId).Joins("JOIN xt_warehouse AS warehouse ON warehouse.id = xt_warehouse_info.warehousing_id AND warehouse.status = 1 AND warehouse.warehousing_time >=? AND warehouse.warehousing_time<= ? AND warehouse.org_id = ?", startTime, end_time, orgId)
- })
- } else if types == 2 {
- db = db.Joins("JOIN xt_sales_return_info AS info ON info.good_id=xt_good_information.id AND info.status = 1 AND info.org_id = ?", orgId).Group("xt_good_information.id")
- db = db.Preload("QuerySalesReturnInfo", func(db *gorm.DB) *gorm.DB {
- return db.Where("xt_sales_return_info.org_id = ? AND xt_sales_return_info.status = 1", orgId).Joins("JOIN xt_sales_return AS sales ON sales.id = xt_sales_return_info.sales_return_id AND sales.status = 1 AND sales.return_time >=? AND sales.return_time<= ? AND sales.org_id = ?", startTime, end_time, orgId)
- })
-
- } else if types == 3 {
- db = db.Joins("JOIN xt_warehouse_out_info AS info ON info.good_id=xt_good_information.id AND info.status = 1 AND info.org_id = ?", orgId).Group("xt_good_information.id")
- db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
- return db.Where("xt_warehouse_out_info.org_id = ? AND xt_warehouse_out_info.status = 1", orgId).Joins("JOIN xt_warehouse_out ON xt_warehouse_out.id = xt_warehouse_out_info.warehouse_out_id AND xt_warehouse_out.status = 1 AND xt_warehouse_out.warehouse_out_time >=? AND xt_warehouse_out.warehouse_out_time<= ? AND xt_warehouse_out.org_id = ? ", startTime, end_time, orgId)
- })
-
- } else if types == 4 {
-
- db = db.Joins("JOIN xt_cancel_stock_info AS info ON info.good_id=xt_good_information.id AND info.status = 1 AND info.org_id = ?", orgId).Group("xt_good_information.id")
- db = db.Preload("QueryCancelStockInfo", func(db *gorm.DB) *gorm.DB {
- return db.Where("xt_cancel_stock_info.org_id = ? AND xt_cancel_stock_info.status = 1", orgId).Joins("JOIN xt_cancel_stock AS cancel ON cancel.id = xt_cancel_stock_info.cancel_stock_id AND cancel.status = 1 AND cancel.return_time >=? AND cancel.return_time<= ? AND cancel.org_id = ?", startTime, end_time, orgId)
- })
-
- }
- db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgId)
- err = db.Order("ctime desc").Find(&list).Error
- return
- }
-
- func GetOutStockTotalCountTwo(startime int64, endtime int64, orgid int64) (autoMatic []*models.NewXtAutomaticReduceDetail, err error) {
-
- err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.record_time,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time >= ? and x.record_time<=? and `status` = 1) as b GROUP BY good_id", orgid, startime, endtime).Scan(&autoMatic).Error
-
- return autoMatic, err
- }
-
- func AddMonitorOpen(config *models.XtMonitorConfig) error {
-
- err := XTWriteDB().Create(&config).Error
-
- return err
- }
-
- func UpdateMonitorOpen(orgid int64, config *models.XtMonitorConfig) error {
-
- err := XTWriteDB().Model(&config).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"is_open": config.IsOpen, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func GetMonitorConfig(orgid int64) (models.XtMonitorConfig, error) {
-
- config := models.XtMonitorConfig{}
- err := XTReadDB().Model(&config).Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
- return config, err
- }
-
- func AddOrderConfig(config *models.XtOrderConfig) error {
-
- err := XTWriteDB().Create(&config).Error
- return err
- }
-
- func UpdateOrderConfig(orgid int64, config *models.XtOrderConfig) error {
-
- err := XTWriteDB().Model(&config).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"is_open": config.IsOpen, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func GetOrderConfigById(orgid int64) (*models.XtOrderConfig, error) {
- config := models.XtOrderConfig{}
- err := XTReadDB().Model(&config).Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &config, nil
- }
-
- func GetOrderConfig(orgid int64) (models.XtOrderConfig, error) {
- config := models.XtOrderConfig{}
- err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
- return config, err
- }
-
- func GetMonitorConfigById(orgid int64) (*models.XtMonitorConfig, error) {
-
- config := models.XtMonitorConfig{}
- err := XTReadDB().Model(&config).Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &config, nil
- }
-
- func GetDrugAutoMaticList(orgid int64, warehouse_out_id int64, record_time int64, warehouse_out_order_number string) (auto []*models.VmDrugAutomaticReduceDetail, err error) {
-
- db := XTReadDB().Table("xt_drug_automatic_reduce_detail as x").Where("x.status = 1")
- err = db.Select("x.org_id,x.warehouse_out_id,x.record_time,x.drug_id,sum(x.count) as total").Where("x.org_id = ? and x.record_time = ? and x.status= 1 and x.warehouse_out_order_number = ?", orgid, record_time, warehouse_out_order_number).Group("x.drug_id").Scan(&auto).Error
- return auto, err
-
- }
-
- func GetAllBaseDrugList(orgid int64) (drug []*models.BaseDrugLib, err error) {
-
- err = XTReadDB().Model(&drug).Where("org_id = ? and status = 1", orgid).Find(&drug).Error
- return drug, err
- }
-
- func GetDrugWarehuseOrderInfo(orgid int64) (drug []*models.DrugWarehouseInfo, err error) {
-
- err = XTReadDB().Where("org_id = ? and status = 1", orgid).Group("drug_id").Find(&drug).Error
- return drug, err
- }
-
- func GetDrugStockList(page int64, limit int64, keyword string, drugcategory int64, startime int64, endtime int64, orgid int64) (list []*models.StDrugWarehouseInfo, total int64, err error) {
- offset := (page - 1) * limit
- db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
- likeKey := "%" + keyword + "%"
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
-
- if startime > 0 {
- db = db.Where("x.ctime >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
- if drugcategory > 0 && len(keyword) == 0 {
- err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id =?", orgid).Where("t.drug_type = ?", drugcategory).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
- return
- }
- if drugcategory <= 0 && len(keyword) == 0 {
- err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ?", orgid).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
- return
- }
-
- if len(keyword) > 0 && drugcategory == 0 {
- err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id=?", orgid).Where("t.drug_name like ?", likeKey).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
- return
- }
- if len(keyword) <= 0 && drugcategory == 0 {
- err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ?", orgid).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
- return
- }
-
- if len(keyword) > 0 && drugcategory > 0 {
- err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ?", orgid).Where("t.drug_type = ? or t.drug_name like ?", drugcategory, likeKey).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
- return
- }
-
- return list, total, err
- }
-
- func GetAllBaseDurgListCount(page int64, limit int64, keyword string, drugcategory int64, startime int64, endtime int64, orgid int64, storehouse_id int64, drug_id int64) (drug []*models.VmBaseDrug, total int64, err error) {
-
- offset := (page - 1) * limit
- db := XTReadDB().Table("xt_base_drug").Where("status = 1")
- likeKey := "%" + keyword + "%"
- if orgid > 0 {
- db = db.Where("org_id = ?", orgid)
- }
- if drugcategory > 0 {
- db = db.Where("drug_type = ?", drugcategory)
- }
-
- if len(keyword) > 0 {
- db = db.Where("drug_name like ?", likeKey)
- }
-
- if drug_id > 0 {
- db = db.Where("id = ?", drug_id)
- }
-
- err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Preload("DrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
- if startime > 0 {
- db = db.Where("ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("ctime<=?", endtime)
- }
- if storehouse_id > 0 {
- db = db.Where("storehouse_id = ?", storehouse_id)
- }
- return db.Where("status = 1 and is_check = 1")
- }).Preload("DrugCancelStockInfo", func(db *gorm.DB) *gorm.DB {
- if startime > 0 {
- db = db.Where("ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("ctime<=?", endtime)
- }
- return db.Where("status = 1")
- }).Preload("DrugWarehouse", func(db *gorm.DB) *gorm.DB {
- if startime > 0 {
- db = db.Where("ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("ctime<=?", endtime)
- }
- if storehouse_id > 0 {
- db = db.Where("storehouse_id = ?", storehouse_id)
- }
- return db.Group("drug_id,storehouse_id").Where("status = 1")
- }).Preload("DrugWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
- if startime > 0 {
- db = db.Where("ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("ctime<=?", endtime)
- }
- return db.Where("status = 1")
- }).Find(&drug).Error
-
- return drug, total, err
- }
-
- func GetDrugStockFlow(drugid int64, startime int64, endtime int64, page int64, limit int64, orgid int64) (list []*models.StDrugWarehouseInfo, total int64, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_base_drug as t").Where("t.status =1 ")
- fmt.Println(table)
- offset := (page - 1) * limit
- if startime > 0 {
- db = db.Where("x.ctime >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
-
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
-
- if drugid > 0 {
- db = db.Where("x.drug_id = ?", drugid)
- }
-
- err = db.Joins("left join xt_base_drug as t on t.id = x.drug_id and t.status = 1 and t.org_id = ?", orgid).Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,x.ctime,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Offset(offset).Count(&total).Order("x.ctime desc").Scan(&list).Error
- return list, total, err
- }
-
- func GetDrugStockOutFlow(drugid int64, startime int64, endtime int64, page int64, limit int64, orgid int64, stocktype int64) (list []*models.VmDrugWarehouseOutInfo, total int64, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
- fmt.Println(table)
- offset := (page - 1) * limit
- if startime > 0 {
- db = db.Where("x.ctime >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
-
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
-
- if drugid > 0 {
- db = db.Where("x.drug_id = ?", drugid)
- }
- if stocktype == 1 {
- db = db.Where("x.is_sys = 0")
- }
- if stocktype == 2 {
- db = db.Where("x.is_sys = 1")
- }
- err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.org_id,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,x.warehouse_info_id,x.ctime,x.batch_number,x.count_unit,t.drug_name,t.drug_type,t.min_number,t.min_unit,t.max_unit").Joins("left join xt_base_drug as t on t.id = x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
- return list, total, err
- }
-
- func GetBatchOrderDetail(drugid int64, orgid int64, page int64, limit int64, startime int64, endtime int64, start_first_time int64, end_first_time int64) (drug []*models.DrugWarehouseInfo, total int64, err error) {
- offset := (page - 1) * limit
- db := XTReadDB().Model(&drug).Where("status = 1 and is_check = 1")
- if drugid > 0 {
- db = db.Where("drug_id = ?", drugid)
- }
- if orgid > 0 {
- db = db.Where("org_id = ?", orgid)
- }
- if startime > 0 {
- db = db.Where("ctime >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("ctime <=?", endtime)
- }
- if start_first_time > 0 {
- db = db.Where("expiry_date >=?", start_first_time)
- }
- if end_first_time > 0 {
- db = db.Where("expiry_date <=?", end_first_time)
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Order("id desc").Find(&drug).Error
- return drug, total, err
- }
-
- func GetDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseInfo, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
-
- if startime > 0 {
- db = db.Where("x.ctime >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- err = db.Select("sum(x.warehousing_count) as count,x.drug_id").Group("x.drug_id").Scan(&info).Error
- return info, err
- }
-
- func GetMinCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
- db := readDb2.Table("xt_drug_warehouse_info as x").Where("x.status = 1")
-
- if startime > 0 {
- db = db.Where("x.ctime >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- err = db.Select("sum(x.warehousing_count) as warehousing_count,x.drug_id").Group("x.drug_id").Scan(&info).Error
- return info, err
- }
-
- func GetOutDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseInfo, err error) {
- db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
-
- if startime > 0 {
- db = db.Where("x.ctime >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- err = db.Select("sum(x.count) as count,x.drug_id,x.count_unit").Group("x.drug_id").Find(&info).Error
- return info, err
- }
-
- func GetAutoDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugAutomaticReduceDetail, err error) {
- db := XTReadDB().Table("xt_drug_automatic_reduce_detail as x").Where("x.status = 1")
-
- if startime > 0 {
- db = db.Where("x.record_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.record_time<=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- err = db.Select("sum(x.count) as count,x.drug_id,x.count_unit").Find(&info).Error
- return info, err
-
- }
-
- func GetCancelDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugCancelStockInfo, err error) {
-
- db := XTReadDB().Table(" xt_drug_cancel_stock_info as x").Where("x.status = 1")
-
- if startime > 0 {
- db = db.Where("x.ctime >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- err = db.Select("sum(x.count) as count,x.drug_id").Group("x.drug_id").Scan(&info).Error
- return info, err
- }
-
- func GetAllCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
- db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
-
- if startime > 0 {
- db = db.Where("x.ctime >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- err = db.Find(&info).Error
- return info, err
- }
-
- func GetSingleOrderDetail(id int64, orgid int64) (info []*models.VmDrugWarehouseOutInfo, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1 and x.count>0")
- table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
- fmt.Println(table)
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if id > 0 {
- db = db.Where("x.warehouse_out_id in(?)", id)
- }
-
- err = db.Select("x.id,x.warehouse_out_id,x.drug_id,sum(x.count) as count,x.count_unit,x.price,x.product_date,x.expiry_date,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.retail_price as total_price,x.retail_total_price,x.storehouse_id,x.stock_count,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,x.number,x.batch_number,x.admin_user_id,t.dose,t.dose_unit,t.last_price,t.min_price,t.medical_insurance_number,t.retail_price ,x.warehouse_info_id").Joins("left join xt_base_drug as t on t.id = x.drug_id").Group("x.drug_id").Scan(&info).Error
- return info, err
- }
-
- func GetDrugWarehouseOutDetailSeventy(id int64, org_id int64) (info []*models.DrugWarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("warehouse_out_id in(?) and org_id = ? and status =1", id, org_id).Find(&info).Error
- return info, err
- }
-
- func GetDrugStockFlowDetail(record_time int64, orgid int64) (drugflow []*models.XtDrugAutomaticReduceDetail, err error) {
-
- err = XTReadDB().Where("record_time = ? and org_id = ? and status = 1", record_time, orgid).Preload("XtBaseDrug", "status = 1").Find(&drugflow).Error
- return drugflow, err
- }
-
- func GetSingeOrderFlow(id int64, orgid int64) (outInfo []*models.VmDrugWarehouseOutInfo, err error) {
- db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
- fmt.Println(table)
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if id > 0 {
- db = db.Where("x.warehouse_out_id in(?)", id)
- }
-
- err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.count,x.count_unit,x.price,x.total_price,x.product_date,x.expiry_date,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.retail_price,x.number,x.batch_number,t.dose,t.dose_unit,t.last_price,t.min_price").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&outInfo).Error
- return outInfo, err
- }
-
- func GetAllSingleDrugDetail(id int64, orgid int64) (outInfo []*models.VmDrugWarehouseOutInfo, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
- fmt.Println(table)
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if id > 0 {
- db = db.Where("x.warehouse_out_id = ?", id)
- }
-
- err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.count,x.count_unit,x.price,x.total_price,x.product_date,x.expiry_date,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,x.number,x.batch_number,t.dose,t.dose_unit,t.last_price,t.min_price").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&outInfo).Error
- return outInfo, err
- }
-
- func GetDrugFlowList(id int64, orgid int64) (stockflow []*models.DrugFlow, err error) {
-
- err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Preload("BaseDrugLib", "org_id = ? and status = 1", orgid).Preload("DrugWarehouseInfoOne", "org_id = ? and status = 1", orgid).Find(&stockflow).Error
- return stockflow, err
- }
-
- func GetDrugFlowListGroupById(id int64, orgid int64) (drugFlow []*models.DrugFlowNight, err error) {
-
- err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Group("warehousing_detail_id").Find(&drugFlow).Error
- return drugFlow, err
- }
-
- func GetDrugFlowListGroupByIdOne(id int64, orgid int64) (drugFlow []*models.DrugFlow, err error) {
-
- err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Group("batch_number").Find(&drugFlow).Error
- return drugFlow, err
- }
-
- func FindDrugStockUserDetailByIdThree(id int64, record_time int64, org_id int64) (user []*DrugAutomaticReduceDetail, err error, total int64) {
-
- db := readDb.Model(&user)
- db = db.Preload("Drug", "org_id = ? AND status = 1", org_id)
- db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
- db = db.Preload("DrugWarehouseOutInfo", "drug_id = ? and sys_record_time = ? and status = 1 and org_id = ?", id, record_time, org_id)
- db = db.Where("status = 1 AND org_id = ? AND drug_id = ? AND record_time =?", org_id, id, record_time)
- db = db.Count(&total)
- err = db.Find(&user).Error
- return user, err, total
- }
-
- func FindeDrugWarehouserInfo(ware_out_id int64, drug_id int64, orgid int64) (outInfo []*models.DrugWarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("warehouse_out_id = ? and drug_id = ? and org_id = ? and status = 1", ware_out_id, drug_id, orgid).Find(&outInfo).Error
-
- return outInfo, err
- }
-
- func GetDrugFlowBatch(ware_out_id int64, drug_id int64, orgid int64) (flow []*models.DrugFlow, err error) {
-
- err = XTReadDB().Where("warehouse_out_id = ? and drug_id = ? and user_org_id = ? and status = 1", ware_out_id, drug_id, orgid).Find(&flow).Error
- return flow, err
- }
-
- func GetDrugWarehouseOutInfoFlow(drug_id int64, start_time int64, end_time int64, user_org_id int64) (info []*models.XtDrugWarehouseOutInfo, err error) {
-
- db := XTReadDB().Model(&info).Where("status = 1")
- if start_time > 0 {
- db = db.Where("sys_record_time >=?", start_time)
- }
- if end_time > 0 {
- db = db.Where("sys_record_time <=?", end_time)
- }
- if user_org_id > 0 {
- db = db.Where("user_org_id = ?", user_org_id)
- }
- err = db.Find(&info).Error
- return info, err
- }
-
- func GetAllBaseDrugListTwenty(orgid int64) (drug []*models.BaseDrugLibTwenty, err error) {
-
- err = XTReadDB().Model(&drug).Where("org_id = ? and status = 1 AND find_in_set('停用',drug_status) = 0", orgid).Find(&drug).Error
- return drug, err
- }
|