manage_center_service.go 37KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "strconv"
  7. "strings"
  8. "time"
  9. )
  10. func GetDictionaryConfigList(orgID int64) (dataconfig interface{}, err error) {
  11. var configList []*models.DictionaryDataconfig
  12. err = readDb.Model(&models.DictionaryDataconfig{}).Where("(org_id in (0,?) and status = 1) or (status = 0 and delete_id_system > 0 and org_id = ?)", orgID, orgID).Order("orders asc, id asc").Find(&configList).Error
  13. if err != nil {
  14. return nil, err
  15. }
  16. // configResult := make([]*ConfigViewModel,0)
  17. childConfig := make(map[int64][]*models.DictionaryDataconfig)
  18. resultConfig := make(map[string][]*models.DictionaryConfigViewModel)
  19. deleteSystemChilds := make([]*models.DictionaryDataconfig, 0)
  20. editSystemChilds := make([]*models.DictionaryDataconfig, 0)
  21. for _, config := range configList {
  22. if config.Status == 1 && config.DeleteIdSystem > 0 {
  23. editSystemChilds = append(editSystemChilds, config)
  24. }
  25. if config.Status == 0 && config.DeleteIdSystem > 0 {
  26. deleteSystemChilds = append(deleteSystemChilds, config)
  27. }
  28. }
  29. continueFlag := false
  30. for _, config := range configList {
  31. continueFlag = false
  32. if config.ParentId == 0 {
  33. newConfig := &models.DictionaryConfigViewModel{
  34. ID: config.ID,
  35. ParentId: config.ParentId,
  36. Module: config.Module,
  37. OrgId: config.OrgId,
  38. Name: config.Name,
  39. FieldName: config.FieldName,
  40. Value: config.Value,
  41. CreateUserId: config.CreateUserId,
  42. Status: config.Status,
  43. Remark: config.Remark,
  44. Title: config.Title,
  45. Content: config.Content,
  46. }
  47. // configResult = append(configResult,newConfig)
  48. result := resultConfig[config.Module]
  49. if result == nil {
  50. result = make([]*models.DictionaryConfigViewModel, 0)
  51. }
  52. for _, vm := range editSystemChilds {
  53. if vm.DeleteIdSystem == config.ID {
  54. continueFlag = true
  55. break
  56. }
  57. }
  58. for _, _vm := range deleteSystemChilds {
  59. if _vm.DeleteIdSystem == config.ID {
  60. continueFlag = true
  61. break
  62. }
  63. }
  64. if config.OrgId != 0 && config.Status == 0 && config.DeleteIdSystem > 0 {
  65. continue
  66. }
  67. if continueFlag {
  68. continue
  69. }
  70. result = append(result, newConfig)
  71. resultConfig[config.Module] = result
  72. } else {
  73. childs := childConfig[config.ParentId]
  74. if childs == nil {
  75. childs = make([]*models.DictionaryDataconfig, 0)
  76. }
  77. continueFlag := false
  78. for _, vm := range editSystemChilds {
  79. if vm.DeleteIdSystem == config.ID {
  80. continueFlag = true
  81. break
  82. }
  83. }
  84. for _, _vm := range deleteSystemChilds {
  85. if _vm.DeleteIdSystem == config.ID {
  86. continueFlag = true
  87. break
  88. }
  89. }
  90. if config.OrgId != 0 && config.Status == 0 && config.DeleteIdSystem > 0 {
  91. continue
  92. }
  93. if continueFlag {
  94. continue
  95. }
  96. childs = append(childs, config)
  97. childConfig[config.ParentId] = childs
  98. }
  99. }
  100. for _, vm := range resultConfig {
  101. for _, _vm := range vm {
  102. _vm.Childs = childConfig[_vm.ID]
  103. }
  104. // vm.Childs = childConfig[vm.ID]
  105. }
  106. return resultConfig, err
  107. }
  108. func CreateDictionaryConfig(dataconfig *models.DictionaryDataconfig) (err error) {
  109. // readDb.Model(&models.Dataconfig{}).Where("module = ? and parent_id = 0 and org_id in (0,?)",dataconfig.Module,dataconfig.OrgId).Count(&total)
  110. err = readDb.Create(&dataconfig).Error
  111. return
  112. }
  113. func GetDictionaryChildValue(module string, parent_id int64, org_id int64) (value int) {
  114. readDb.Model(&models.DictionaryDataconfig{}).Where("module=? and parent_id=? and org_id in (0,?)", module, parent_id, org_id).Count(&value)
  115. return
  116. }
  117. func FindDictionaryConfigByTitle(module string, title string, org_id int64) (dataconfig models.DictionaryDataconfig, err error) {
  118. err = readDb.Model(&models.DictionaryDataconfig{}).Where("module=? and title=? and org_id in (0,?) and status = 1", module, title, org_id).First(&dataconfig).Error
  119. return
  120. }
  121. func UpdateDictionaryTemplate(dataconfig *models.DictionaryDataconfig) (err error) {
  122. err = readDb.Model(&models.DictionaryDataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"title": dataconfig.Title, "content": dataconfig.Content, "update_time": dataconfig.UpdatedTime, "remark": dataconfig.Remark}).Error
  123. return
  124. }
  125. func UpdateDictionaryChildConfig(dataconfig *models.DictionaryDataconfig) (err error) {
  126. err = readDb.Model(&models.DictionaryDataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"name": dataconfig.Name, "update_time": dataconfig.UpdatedTime, "remark": dataconfig.Remark, "orders": dataconfig.Order, "code": dataconfig.Code}).Error
  127. return
  128. }
  129. func DeleteDictionaryChildConfig(dataconfig *models.DictionaryDataconfig) (err error) {
  130. err = readDb.Model(&models.DictionaryDataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"status": dataconfig.Status, "update_time": dataconfig.UpdatedTime}).Error
  131. return
  132. }
  133. func CreateBaseDrugLib(lib *models.BaseDrugLib) (err error) {
  134. err = writeDb.Create(&lib).Error
  135. return
  136. }
  137. func UpdateBaseDrugLib(lib *models.BaseDrugLib) (err error) {
  138. err = writeDb.Save(lib).Error
  139. return
  140. }
  141. func FindBaseDrugLibRecordCount(lib *models.BaseDrugLib) (count int64) {
  142. readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND drug_name = ? AND drug_category = ? AND drug_spec=? AND drug_type=? AND status = 1", lib.OrgId, lib.DrugName, lib.DrugCategory, lib.DrugSpec, lib.DrugType).Count(&count)
  143. return
  144. }
  145. func FindBaseDrugLibRecordCountOne(lib *models.BaseDrugLib) (count int64) {
  146. readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? and drug_name = ? and dose = ? and dose_unit = ? and min_number = ? and min_unit = ? and max_unit = ? and manufacturer = ? and status = 1", lib.OrgId, lib.DrugName, lib.Dose, lib.DoseUnit, lib.MinNumber, lib.MinUnit, lib.MaxUnit, lib.Manufacturer).Count(&count)
  147. return
  148. }
  149. func FindAllDrugLibRecordTotal(org_id int64) (count int64) {
  150. readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Count(&count)
  151. return
  152. }
  153. func FindBaseDrugLibRecord(org_id int64, id int64) (lib models.BaseDrugLib, err error) {
  154. err = readDb.Model(&models.BaseDrugLib{}).Where("id = ? AND org_id = ? AND status = 1", id, org_id).First(&lib).Error
  155. return
  156. }
  157. func FindBaseDrugLibRecordSeven(org_id int64, id int64) (lib models.BaseDrugLibSeven, err error) {
  158. err = readDb.Select("id,drug_name,max_unit,min_number,min_unit,sum_count,is_user,is_pharmacy").Where("org_id = ? AND id = ? AND status = 1", org_id, id).First(&lib).Error
  159. return
  160. }
  161. func GetDrugAutoWarehouseOut(patient_id int64, advicedate int64, drugid int64) (*models.DrugWarehouseOutInfo, error) {
  162. detail := models.DrugWarehouseOutInfo{}
  163. err := XTReadDB().Model(&detail).Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1", patient_id, advicedate, drugid).Find(&detail).Error
  164. if err == gorm.ErrRecordNotFound {
  165. return nil, err
  166. }
  167. if err != nil {
  168. return nil, err
  169. }
  170. return &detail, nil
  171. }
  172. func GetDrugAutoWarehouseOutSeven(patient_id int64, advicedate int64, drugid int64, adviceid int64) (*models.DrugWarehouseOutInfo, error) {
  173. detail := models.DrugWarehouseOutInfo{}
  174. err := XTReadDB().Model(&detail).Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1 and advice_id = ?", patient_id, advicedate, drugid, adviceid).Find(&detail).Error
  175. if err == gorm.ErrRecordNotFound {
  176. return nil, err
  177. }
  178. if err != nil {
  179. return nil, err
  180. }
  181. return &detail, nil
  182. }
  183. func GetDrugAutoWarehouseOutEight(patient_id int64, advicedate int64, drugid int64, adviceid int64) (models.DrugWarehouseOutInfo, error) {
  184. detail := models.DrugWarehouseOutInfo{}
  185. err = XTReadDB().Model(&detail).Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1 and advice_id = ?", patient_id, advicedate, drugid, adviceid).Find(&detail).Error
  186. return detail, err
  187. }
  188. func GetDrugAutoWarehouseOutTen(patient_id int64, advicedate int64, drugid int64, adviceid int64, warehouse_info_id int64) (models.DrugWarehouseOutInfo, error) {
  189. detail := models.DrugWarehouseOutInfo{}
  190. err = XTReadDB().Model(&detail).Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1 and advice_id = ? and warehouse_info_id = ?", patient_id, advicedate, drugid, adviceid, warehouse_info_id).Find(&detail).Error
  191. return detail, err
  192. }
  193. func GetDrugAutoWarehouseOutNight(patient_id int64, advicedate int64, drugid int64, adviceid int64) (night []*models.DrugWarehouseOutInfo, err error) {
  194. err = XTReadDB().Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1 and advice_id = ?", patient_id, advicedate, drugid, adviceid).Find(&night).Error
  195. return night, err
  196. }
  197. func UpdateDrugWarehouse(id int64, info models.DrugWarehouseInfo) error {
  198. err := writeDb.Model(&models.DrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", info.StockMinNumber)).Error
  199. return err
  200. }
  201. func UpdateDrugWarehouseOne(id int64, info models.DrugWarehouseInfo) error {
  202. err := writeDb.Model(&models.DrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", info.StockMaxNumber)).Error
  203. return err
  204. }
  205. func GetBaseDrugLibList(org_id int64, keyword string, page int64, limit int64, is_use int64, is_charge int64, is_inject int64, manufacturer int64, isRecord int64) (list []*models.BaseDrugLib, total int64, err error) {
  206. db := readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id)
  207. if len(keyword) != 0 {
  208. keyword = "%" + keyword + "%"
  209. db = db.Where("drug_name Like ?", keyword)
  210. }
  211. if is_use != 0 {
  212. if is_use == 2 {
  213. db = db.Where("find_in_set('停用',drug_status) = 0")
  214. } else {
  215. db = db.Where("find_in_set('停用',drug_status) > 0")
  216. }
  217. }
  218. if is_charge == 1 {
  219. //if is_charge == 1 {
  220. // db = db.Where("find_in_set('收费',drug_status) > 0")
  221. //
  222. //} else {
  223. // db = db.Where("find_in_set('收费',drug_status) = 0")
  224. //}
  225. db = db.Where("is_record = ?", is_charge)
  226. }
  227. if is_charge == 2 {
  228. db = db.Where("is_record= 0 || is_record = 2")
  229. }
  230. if is_inject != 0 {
  231. //db = db.Where("drug_name Like ?", keyword)
  232. if is_inject == 1 {
  233. db = db.Where("find_in_set('注射类',drug_status) > 0")
  234. } else {
  235. db = db.Where("find_in_set('注射类',drug_status) = 0")
  236. }
  237. }
  238. if manufacturer > 0 {
  239. db = db.Where("manufacturer = ?", manufacturer)
  240. }
  241. if isRecord > 0 {
  242. db = db.Where("is_mark = ?", isRecord)
  243. }
  244. offset := (page - 1) * limit
  245. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
  246. return
  247. }
  248. func CreateMedicineInsurancePercentage(mip *models.MedicineInsurancePercentage) (err error) {
  249. err = writeDb.Create(mip).Error
  250. return
  251. }
  252. func CreateUnitSafeguard(dus *models.DrugUnitSafeguard) (err error) {
  253. err = writeDb.Create(dus).Error
  254. return
  255. }
  256. func AddSigleMZSick(dealer *models.OutpatientServiceSick) (error, *models.OutpatientServiceSick) {
  257. err := writeDb.Create(&dealer).Error
  258. return err, dealer
  259. }
  260. func ModifyMZSick(mesick *models.OutpatientServiceSick) error {
  261. err := writeDb.Save(&mesick).Error
  262. return err
  263. }
  264. func FindAllMZSickList(orgId int64, page int64, limit int64) (list []*models.OutpatientServiceSick, total int64, err error) {
  265. offset := (page - 1) * limit
  266. db := readDb.Model(&models.OutpatientServiceSick{})
  267. db = db.Where("user_org_id = ? AND status = 1", orgId)
  268. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
  269. return
  270. }
  271. func DeleteMZSickById(id int64) error {
  272. err := writeDb.Model(&models.OutpatientServiceSick{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  273. return err
  274. }
  275. func FindMZSickById(id int64) (*models.OutpatientServiceSick, error) {
  276. dealer := &models.OutpatientServiceSick{}
  277. err := readDb.Model(&models.OutpatientServiceSick{}).Where("id = ? AND status = 1", id).First(&dealer).Error
  278. return dealer, err
  279. }
  280. func GetDrugWareoutInfo(id int64) (*models.XtDrugWarehouseInfo, error) {
  281. info := models.XtDrugWarehouseInfo{}
  282. err = XTReadDB().Model(&info).Where("drug_id = ? and status = 1", id).Find(&info).Error
  283. if err == gorm.ErrRecordNotFound {
  284. return nil, err
  285. }
  286. if err != nil {
  287. return nil, err
  288. }
  289. return &info, nil
  290. }
  291. func GetDrugWareOutById(id int64) (*models.XtDrugWarehouseOutInfo, error) {
  292. info := models.XtDrugWarehouseOutInfo{}
  293. err := XTReadDB().Model(&info).Where("drug_id = ? and status = 1", id).Find(&info).Error
  294. if err == gorm.ErrRecordNotFound {
  295. return nil, err
  296. }
  297. if err != nil {
  298. return nil, err
  299. }
  300. return &info, nil
  301. }
  302. func DeleteBaseDrugById(id int64) error {
  303. drug := models.XtBaseDrug{}
  304. err := XTWriteDB().Model(&drug).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  305. return err
  306. }
  307. func AddSigleAddition(dealer *models.XtHisAddtionConfig) (error, *models.XtHisAddtionConfig) {
  308. err := writeDb.Create(&dealer).Error
  309. return err, dealer
  310. }
  311. func ModifyAddition(mesick *models.XtHisAddtionConfig) error {
  312. err := writeDb.Save(&mesick).Error
  313. return err
  314. }
  315. func FindAllAdditionList(orgId int64, page int64, limit int64) (list []*models.XtHisAddtionConfig, total int64, err error) {
  316. offset := (page - 1) * limit
  317. db := readDb.Model(&models.XtHisAddtionConfig{})
  318. db = db.Where("user_org_id = ? AND status = 1", orgId)
  319. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
  320. return
  321. }
  322. func DeleteAdditionById(id int64) error {
  323. err := writeDb.Model(&models.XtHisAddtionConfig{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  324. return err
  325. }
  326. func FindAdditionById(id int64) (*models.XtHisAddtionConfig, error) {
  327. dealer := &models.XtHisAddtionConfig{}
  328. err := readDb.Model(&models.XtHisAddtionConfig{}).Where("id = ? AND status = 1", id).First(&dealer).Error
  329. return dealer, err
  330. }
  331. func AddSigleDiagnose(dealer *models.HisXtDiagnoseConfig) (error, *models.HisXtDiagnoseConfig) {
  332. err := writeDb.Create(&dealer).Error
  333. return err, dealer
  334. }
  335. func ModifyDiagnose(mesick *models.HisXtDiagnoseConfig) error {
  336. err := writeDb.Save(&mesick).Error
  337. return err
  338. }
  339. func FindAllDiagnoseList(orgId int64, page int64, limit int64) (list []*models.HisXtDiagnoseConfig, total int64, err error) {
  340. offset := (page - 1) * limit
  341. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  342. db = db.Where("user_org_id = ? AND status = 1", orgId)
  343. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
  344. return
  345. }
  346. func DeleteDiagnoseById(id int64) error {
  347. err := writeDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  348. return err
  349. }
  350. func FindDiagnoseById(id int64) (*models.HisXtDiagnoseConfig, error) {
  351. dealer := &models.HisXtDiagnoseConfig{}
  352. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ? AND status = 1", id).First(&dealer).Error
  353. return dealer, err
  354. }
  355. func GetDoseCode(dose_id int64, user_org_id int64) (error, string) {
  356. var data models.DictDataconfig
  357. err := readDb.Model(&models.DictDataconfig{}).Where(" (user_org_id = ? Or user_org_id = 0) AND parent_id = 4 AND module = 'system' AND status = 1 AND value = ?", user_org_id, dose_id).First(&data).Error
  358. return err, data.Code
  359. }
  360. func GetAllDrugList(orgid int64) (drug []*models.BaseDrugLib, err error) {
  361. err = XTReadDB().Model(&drug).Where("org_id = ? and status = 1", orgid).Find(&drug).Error
  362. return drug, err
  363. }
  364. //自动退库分装方法
  365. func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) error {
  366. //查询该批次病人该药品出库数据
  367. info, _ := GetDrugAutoWarehouseOutEight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
  368. list, _ := GetDrugAutoWarehouseOutNight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
  369. fmt.Println("lsit233323232323233232332wo", list)
  370. storeHouseConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
  371. //退库
  372. drug, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  373. //如果剩余数量 + 退库数量 < 总入库数量
  374. if len(list) > 0 {
  375. for _, its := range list {
  376. fmt.Println("its,23322323323223232332wo", its.WarehouseInfoId)
  377. //查询该批次病人该药品出库数据
  378. infos, _ := GetDrugAutoWarehouseOutTen(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID, its.WarehouseInfoId)
  379. fmt.Println("info2332323232332233223wo", infos.Count)
  380. //查询该药品出库批次总入库数量
  381. druginfo, _ := GetDrugInfoSix(its.WarehouseInfoId, infos.OrgId)
  382. var out_count int64 //该批次出库库存
  383. var sum_count int64 //该批次总库存
  384. var over_count int64 //剩余数量
  385. over_count = druginfo.StockMaxNumber*drug.MinNumber + druginfo.StockMinNumber
  386. if infos.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  387. out_count = info.Count * drug.MinNumber
  388. }
  389. if infos.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  390. out_count = infos.Count
  391. }
  392. if infos.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  393. out_count = infos.Count
  394. }
  395. if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  396. sum_count = druginfo.WarehousingCount * drug.MinNumber
  397. }
  398. if druginfo.MaxUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  399. sum_count = druginfo.WarehousingCount
  400. }
  401. if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  402. sum_count = druginfo.WarehousingCount
  403. }
  404. fmt.Println("//剩余数量", over_count)
  405. fmt.Println("该批出出库数量3223323232wo", out_count)
  406. fmt.Println("g该批次总库存wowowoowow", sum_count)
  407. if (over_count + out_count) <= sum_count {
  408. if its.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  409. //退库
  410. warehouseInfo := models.DrugWarehouseInfo{
  411. StockMinNumber: its.Count,
  412. }
  413. UpdateDrugWarehouse(its.WarehouseInfoId, warehouseInfo)
  414. //增加退库数量
  415. AddCancelSumCountOne(storeHouseConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, its.Count)
  416. //出库数量减少
  417. UpdateSumOutDrug(advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, advice.DrugId, its.Count)
  418. }
  419. if its.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  420. warehouseInfo := models.DrugWarehouseInfo{
  421. StockMaxNumber: its.Count,
  422. }
  423. UpdateDrugWarehouseOne(its.WarehouseInfoId, warehouseInfo)
  424. //增加退库数量
  425. AddCancelSumCountOne(storeHouseConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, its.Count*drug.MinNumber)
  426. //出库数量减少
  427. UpdateSumOutDrug(advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, advice.DrugId, its.Count*drug.MinNumber)
  428. }
  429. if its.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  430. warehouseInfo := models.DrugWarehouseInfo{
  431. StockMaxNumber: its.Count,
  432. }
  433. UpdateDrugWarehouseOne(its.WarehouseInfoId, warehouseInfo)
  434. //增加退库数量
  435. AddCancelSumCountOne(storeHouseConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, its.Count*drug.MinNumber)
  436. //出库数量减少
  437. UpdateSumOutDrug(advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, advice.DrugId, its.Count*drug.MinNumber)
  438. }
  439. }
  440. }
  441. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  442. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  443. if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  444. operation_time := time.Now().Unix()
  445. ctime := time.Now().Unix()
  446. timeStr := time.Now().Format("2006-01-02")
  447. timeArr := strings.Split(timeStr, "-")
  448. total, _ := FindAllDrugCancelStockTotal(advice.UserOrgId)
  449. total = total + 1
  450. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  451. cancelStock := models.DrugCancelStock{
  452. OrderNumber: orderNumber,
  453. OperaTime: operation_time,
  454. OrgId: advice.UserOrgId,
  455. Creater: creater,
  456. Ctime: ctime,
  457. Status: 1,
  458. ReturnTime: advice.AdviceDate,
  459. Dealer: info.Dealer,
  460. Manufacturer: info.Manufacturer,
  461. Type: 1,
  462. StorehouseId: storeHouseConfig.DrugStorehouseOut,
  463. IsCheck: 1,
  464. }
  465. AddSigleDrugCancelStock(&cancelStock)
  466. manufactureName, _ := GetManufactureById(info.Manufacturer)
  467. dealer, _ := GetDealerById(info.Dealer)
  468. cancelInfo, _ := GetLastDrugCancelStockById(advice.UserOrgId)
  469. cancelStockInfo := models.DrugCancelStockInfo{
  470. OrderNumber: cancelInfo.OrderNumber,
  471. CancelStockId: cancelInfo.ID,
  472. DrugId: advice.DrugId,
  473. Count: prescribingNumber,
  474. Status: 1,
  475. Ctime: ctime,
  476. OrgId: advice.UserOrgId,
  477. Type: 1,
  478. Manufacturer: manufactureName.ManufacturerName,
  479. Dealer: dealer.DealerName,
  480. Total: 0,
  481. RetailPrice: info.RetailPrice,
  482. RetailTotalPrice: info.RetailTotalPrice,
  483. Price: info.Price,
  484. RegisterAccount: "",
  485. Remark: info.Remark,
  486. BatchNumber: info.BatchNumber,
  487. MaxUnit: advice.PrescribingNumberUnit,
  488. ProductDate: info.ProductDate,
  489. ExpiryDate: info.ExpiryDate,
  490. BatchNumberId: info.WarehouseInfoId,
  491. StorehouseId: storeHouseConfig.DrugStorehouseOut,
  492. IsCheck: 1,
  493. }
  494. //查询剩余库存
  495. stockInfo, _ := GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  496. var sum_count int64
  497. for _, its := range stockInfo {
  498. if its.MaxUnit == drug.MaxUnit {
  499. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  500. }
  501. sum_count += its.StockMaxNumber + its.StockMinNumber
  502. }
  503. var count_one int64
  504. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  505. count_one = prescribingNumber * drug.MinNumber
  506. }
  507. if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  508. count_one = prescribingNumber
  509. }
  510. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  511. count_one = prescribingNumber * drug.MinNumber
  512. }
  513. flow := models.DrugFlow{
  514. WarehousingId: info.WarehouseInfoId,
  515. DrugId: info.DrugId,
  516. Number: "",
  517. BatchNumber: info.BatchNumber,
  518. Count: count_one,
  519. UserOrgId: advice.UserOrgId,
  520. PatientId: advice.PatientId,
  521. SystemTime: info.SysRecordTime,
  522. ConsumableType: 7,
  523. IsSys: 0,
  524. WarehousingOrder: "",
  525. WarehouseOutId: 0,
  526. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  527. IsEdit: 0,
  528. CancelStockId: cancelStock.ID,
  529. CancelOrderNumber: cancelStock.OrderNumber,
  530. Manufacturer: info.Manufacturer,
  531. Dealer: info.Dealer,
  532. Creator: creater,
  533. UpdateCreator: 0,
  534. Status: 1,
  535. Ctime: time.Now().Unix(),
  536. Mtime: 0,
  537. Price: info.Price,
  538. WarehousingDetailId: info.WarehouseInfoId,
  539. WarehouseOutDetailId: 0,
  540. CancelOutDetailId: 0,
  541. ExpireDate: info.ExpiryDate,
  542. ProductDate: info.ProductDate,
  543. MaxUnit: drug.MinUnit,
  544. MinUnit: "",
  545. AdviceId: info.AdviceId,
  546. StorehouseId: storeHouseConfig.DrugStorehouseOut,
  547. OverCount: sum_count,
  548. }
  549. CreatedCancelStock(cancelStockInfo)
  550. CreateDrugFlowOne(flow)
  551. //删除出库记录
  552. UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
  553. //删除流水
  554. UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  555. }
  556. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  557. houseConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
  558. operation_time := time.Now().Unix()
  559. ctime := time.Now().Unix()
  560. timeStr := time.Now().Format("2006-01-02")
  561. timeArr := strings.Split(timeStr, "-")
  562. total, _ := FindAllDrugCancelStockTotal(advice.UserOrgId)
  563. total = total + 1
  564. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  565. cancelStock := models.DrugCancelStock{
  566. OrderNumber: orderNumber,
  567. OperaTime: operation_time,
  568. OrgId: advice.UserOrgId,
  569. Creater: creater,
  570. Ctime: ctime,
  571. Status: 1,
  572. ReturnTime: advice.AdviceDate,
  573. Dealer: info.Dealer,
  574. Manufacturer: info.Manufacturer,
  575. Type: 1,
  576. StorehouseId: houseConfig.DrugStorehouseOut,
  577. IsCheck: 1,
  578. }
  579. AddSigleDrugCancelStock(&cancelStock)
  580. manufactureName, _ := GetManufactureById(info.Manufacturer)
  581. dealer, _ := GetDealerById(info.Dealer)
  582. cancelInfo, _ := GetLastDrugCancelStockById(advice.UserOrgId)
  583. cancelStockInfo := models.DrugCancelStockInfo{
  584. OrderNumber: cancelInfo.OrderNumber,
  585. CancelStockId: cancelInfo.ID,
  586. DrugId: info.DrugId,
  587. Count: prescribingNumber,
  588. Status: 1,
  589. Ctime: ctime,
  590. OrgId: advice.UserOrgId,
  591. Type: 1,
  592. Manufacturer: manufactureName.ManufacturerName,
  593. Dealer: dealer.DealerName,
  594. Total: 0,
  595. RetailPrice: info.RetailPrice,
  596. RetailTotalPrice: info.RetailTotalPrice,
  597. Price: info.Price,
  598. RegisterAccount: "",
  599. Remark: info.Remark,
  600. BatchNumber: info.BatchNumber,
  601. MaxUnit: advice.PrescribingNumberUnit,
  602. ProductDate: info.ProductDate,
  603. ExpiryDate: info.ExpiryDate,
  604. BatchNumberId: info.WarehouseInfoId,
  605. StorehouseId: houseConfig.DrugStorehouseOut,
  606. IsCheck: 1,
  607. }
  608. //查询剩余库存
  609. stockInfo, _ := GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  610. var sum_count int64
  611. for _, its := range stockInfo {
  612. if its.MaxUnit == drug.MaxUnit {
  613. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  614. }
  615. sum_count += its.StockMaxNumber + its.StockMinNumber
  616. }
  617. var count_one int64
  618. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  619. count_one = prescribingNumber * drug.MinNumber
  620. }
  621. if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  622. count_one = prescribingNumber
  623. }
  624. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  625. count_one = prescribingNumber * drug.MinNumber
  626. }
  627. flow := models.DrugFlow{
  628. WarehousingId: info.WarehouseInfoId,
  629. DrugId: info.DrugId,
  630. Number: "",
  631. BatchNumber: info.BatchNumber,
  632. Count: count_one,
  633. UserOrgId: advice.UserOrgId,
  634. PatientId: advice.PatientId,
  635. SystemTime: info.SysRecordTime,
  636. ConsumableType: 7,
  637. IsSys: 0,
  638. WarehousingOrder: "",
  639. WarehouseOutId: 0,
  640. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  641. IsEdit: 0,
  642. CancelStockId: cancelStock.ID,
  643. CancelOrderNumber: cancelStock.OrderNumber,
  644. Manufacturer: info.Manufacturer,
  645. Dealer: info.Dealer,
  646. Creator: creater,
  647. UpdateCreator: 0,
  648. Status: 1,
  649. Ctime: time.Now().Unix(),
  650. Mtime: 0,
  651. Price: info.Price,
  652. WarehousingDetailId: info.WarehouseInfoId,
  653. WarehouseOutDetailId: 0,
  654. CancelOutDetailId: 0,
  655. ExpireDate: info.ExpiryDate,
  656. ProductDate: info.ProductDate,
  657. MaxUnit: drug.MinUnit,
  658. MinUnit: "",
  659. AdviceId: info.AdviceId,
  660. StorehouseId: houseConfig.DrugStorehouseOut,
  661. OverCount: sum_count,
  662. }
  663. CreatedCancelStock(cancelStockInfo)
  664. CreateDrugFlowOne(flow)
  665. //删除出库记录
  666. UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
  667. //删除流水
  668. UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  669. }
  670. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  671. houseConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
  672. operation_time := time.Now().Unix()
  673. ctime := time.Now().Unix()
  674. timeStr := time.Now().Format("2006-01-02")
  675. timeArr := strings.Split(timeStr, "-")
  676. total, _ := FindAllDrugCancelStockTotal(advice.UserOrgId)
  677. total = total + 1
  678. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  679. cancelStock := models.DrugCancelStock{
  680. OrderNumber: orderNumber,
  681. OperaTime: operation_time,
  682. OrgId: advice.UserOrgId,
  683. Creater: creater,
  684. Ctime: ctime,
  685. Status: 1,
  686. ReturnTime: advice.AdviceDate,
  687. Dealer: info.Dealer,
  688. Manufacturer: info.Manufacturer,
  689. Type: 1,
  690. StorehouseId: houseConfig.DrugStorehouseOut,
  691. IsCheck: 1,
  692. }
  693. AddSigleDrugCancelStock(&cancelStock)
  694. manufactureName, _ := GetManufactureById(info.Manufacturer)
  695. dealer, _ := GetDealerById(info.Dealer)
  696. cancelInfo, _ := GetLastDrugCancelStockById(advice.UserOrgId)
  697. cancelStockInfo := models.DrugCancelStockInfo{
  698. OrderNumber: cancelInfo.OrderNumber,
  699. CancelStockId: cancelInfo.ID,
  700. DrugId: info.DrugId,
  701. Count: prescribingNumber,
  702. Status: 1,
  703. Ctime: ctime,
  704. OrgId: advice.UserOrgId,
  705. Type: 1,
  706. Manufacturer: manufactureName.ManufacturerName,
  707. Dealer: dealer.DealerName,
  708. Total: 0,
  709. RetailPrice: info.RetailPrice,
  710. RetailTotalPrice: info.RetailTotalPrice,
  711. Price: info.Price,
  712. RegisterAccount: "",
  713. Remark: info.Remark,
  714. BatchNumber: info.BatchNumber,
  715. MaxUnit: advice.PrescribingNumberUnit,
  716. ProductDate: info.ProductDate,
  717. ExpiryDate: info.ExpiryDate,
  718. BatchNumberId: info.WarehouseInfoId,
  719. StorehouseId: houseConfig.DrugStorehouseOut,
  720. IsCheck: 1,
  721. }
  722. //查询剩余库存
  723. stockInfo, _ := GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  724. var sum_count int64
  725. for _, its := range stockInfo {
  726. if its.MaxUnit == drug.MaxUnit {
  727. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  728. }
  729. sum_count += its.StockMaxNumber + its.StockMinNumber
  730. }
  731. flow := models.DrugFlow{
  732. WarehousingId: info.WarehouseInfoId,
  733. DrugId: info.DrugId,
  734. Number: "",
  735. BatchNumber: info.BatchNumber,
  736. Count: prescribingNumber,
  737. UserOrgId: advice.UserOrgId,
  738. PatientId: 0,
  739. SystemTime: info.SysRecordTime,
  740. ConsumableType: 7,
  741. IsSys: 0,
  742. WarehousingOrder: "",
  743. WarehouseOutId: 0,
  744. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  745. IsEdit: 0,
  746. CancelStockId: cancelStock.ID,
  747. CancelOrderNumber: cancelStock.OrderNumber,
  748. Manufacturer: info.Manufacturer,
  749. Dealer: info.Dealer,
  750. Creator: creater,
  751. UpdateCreator: 0,
  752. Status: 1,
  753. Ctime: time.Now().Unix(),
  754. Mtime: 0,
  755. Price: info.Price,
  756. WarehousingDetailId: info.WarehouseInfoId,
  757. WarehouseOutDetailId: 0,
  758. CancelOutDetailId: 0,
  759. ExpireDate: info.ExpiryDate,
  760. ProductDate: info.ProductDate,
  761. MaxUnit: advice.PrescribingNumberUnit,
  762. MinUnit: "",
  763. AdviceId: info.AdviceId,
  764. StorehouseId: houseConfig.DrugStorehouseOut,
  765. OverCount: sum_count,
  766. }
  767. CreatedCancelStock(cancelStockInfo)
  768. CreateDrugFlowOne(flow)
  769. //删除出库记录
  770. UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
  771. //删除流水
  772. UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  773. }
  774. //更新字典里面的库存
  775. stockInfo, _ := GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  776. //查询改药品信息
  777. medical, _ := GetBaseDrugMedical(advice.DrugId)
  778. var sum_count_one int64
  779. for _, its := range stockInfo {
  780. if its.MaxUnit == medical.MaxUnit {
  781. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  782. }
  783. sum_count_one += its.StockMaxNumber + its.StockMinNumber
  784. }
  785. UpdateBaseDrugSumTwo(advice.DrugId, sum_count_one, advice.UserOrgId)
  786. //更新库存
  787. UpdateSumDrug(advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, advice.DrugId, sum_count_one)
  788. }
  789. return err
  790. }
  791. func GoodAutoAddCancelInfo(good *models.NewDialysisBeforePrepareGoods, creater int64) error {
  792. fmt.Print("order_id223233232323223323223wo", good.OrderId)
  793. //查询已经出库数量
  794. info, _ := GetWareOutInfo(good.GoodId, good.RecordDate, good.UserOrgId, good.PatientId, good.OrderId)
  795. if len(info) > 0 {
  796. houseConfig, _ := GetAllStoreHouseConfig(good.UserOrgId)
  797. operation_time := time.Now().Unix()
  798. //创建退库单
  799. timeStr := time.Now().Format("2006-01-02")
  800. timeArr := strings.Split(timeStr, "-")
  801. total, _ := FindAllCancelStockTotal(good.UserOrgId)
  802. total = total + 1
  803. orderNumber := "CKTKD" + strconv.FormatInt(good.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  804. cancelStock := models.CancelStock{
  805. OrderNumber: orderNumber,
  806. OperaTime: operation_time,
  807. OrgId: good.UserOrgId,
  808. Creater: creater,
  809. Ctime: time.Now().Unix(),
  810. Status: 1,
  811. ReturnTime: good.RecordDate,
  812. Type: 1,
  813. StorehouseId: houseConfig.StorehouseOutInfo,
  814. IsCheck: 1,
  815. }
  816. _, msgerrkonde := GetCancelStockDetailByOrderNumberOne(good.RecordDate, good.UserOrgId)
  817. if msgerrkonde == gorm.ErrRecordNotFound {
  818. AddSigleCancelStock(&cancelStock)
  819. }
  820. cancel, _ := GetLastCancelStockById(good.UserOrgId)
  821. for _, item := range info {
  822. manufacturer, _ := GetManufactureById(item.Manufacturer)
  823. deaerler, _ := GetDealerById(item.Dealer)
  824. cancelStockInfo := models.CancelStockInfo{
  825. GoodId: good.GoodId,
  826. CancelStockId: cancel.ID,
  827. GoodTypeId: good.GoodTypeId,
  828. Count: item.Count,
  829. Price: item.Price,
  830. Total: 0,
  831. ProductDate: item.ProductDate,
  832. ExpiryDate: item.ExpiryDate,
  833. Ctime: time.Now().Unix(),
  834. Status: 1,
  835. OrgId: good.UserOrgId,
  836. OrderNumber: cancel.OrderNumber,
  837. Type: 0,
  838. Dealer: deaerler.DealerName,
  839. Manufacturer: manufacturer.ManufacturerName,
  840. Number: item.Number,
  841. RegisterAccount: "",
  842. Remark: "",
  843. WarehouseInfoId: item.WarehouseInfotId,
  844. PatientId: item.PatientId,
  845. RecordDate: item.SysRecordTime,
  846. StorehouseId: houseConfig.StorehouseOutInfo,
  847. IsCheck: 1,
  848. }
  849. CreateCancelStockInfoOne(&cancelStockInfo)
  850. cancelInfo, _ := GetLastCancelStockInfoByGoodId(good.GoodId)
  851. goodList, _ := GetSumGoodList(item.OrgId, houseConfig.StorehouseOutInfo, item.GoodId)
  852. var over_count int64
  853. for _, it := range goodList {
  854. over_count += it.StockCount
  855. }
  856. flow := models.VmStockFlow{
  857. WarehousingId: item.WarehouseInfotId,
  858. GoodId: item.GoodId,
  859. Number: item.Number,
  860. LicenseNumber: item.LicenseNumber,
  861. Count: item.Count,
  862. UserOrgId: item.OrgId,
  863. PatientId: item.PatientId,
  864. SystemTime: item.SysRecordTime,
  865. ConsumableType: 7,
  866. IsSys: 0,
  867. WarehousingOrder: "",
  868. WarehouseOutId: item.WarehouseOutId,
  869. WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
  870. IsEdit: 0,
  871. CancelStockId: cancel.ID,
  872. CancelOrderNumber: cancel.OrderNumber,
  873. Manufacturer: manufacturer.ID,
  874. Dealer: 0,
  875. Creator: creater,
  876. UpdateCreator: 0,
  877. Status: 1,
  878. Ctime: time.Now().Unix(),
  879. Mtime: 0,
  880. Price: item.Price,
  881. WarehousingDetailId: item.WarehouseInfotId,
  882. WarehouseOutDetailId: item.ID,
  883. CancelOutDetailId: cancelInfo.ID,
  884. ProductDate: item.ProductDate,
  885. ExpireDate: item.ExpiryDate,
  886. StorehouseId: houseConfig.StorehouseOutInfo,
  887. OverCount: over_count,
  888. }
  889. CreateStockFlowOne(flow)
  890. //回退库存
  891. UpDateWarehouseInfoByStockDelete(item.WarehouseInfotId, item.Count, item.PatientId, item.SysRecordTime, item.GoodId)
  892. //退库数量增加
  893. UpdateSumAddCancelCount(good.UserOrgId, good.GoodId, houseConfig.StorehouseOutInfo, good.Count)
  894. //出库数量减少
  895. UpdateSumCount(good.UserOrgId, houseConfig.StorehouseOutInfo, good.GoodId, good.Count)
  896. //删除出库表
  897. DeleteAutoRedeceDetailTenOne(good.UserOrgId, item.PatientId, item.SysRecordTime, item.GoodId, item.OrderId)
  898. goodListOne, _ := GetSumGoodList(item.OrgId, houseConfig.StorehouseOutInfo, item.GoodId)
  899. var flush_count int64
  900. for _, it := range goodListOne {
  901. flush_count += it.StockCount
  902. }
  903. //更新剩余库存
  904. UpdateSumGood(good.UserOrgId, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  905. }
  906. }
  907. return err
  908. }