manage_center_service.go 38KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  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. if druginfo.MaxUnit != druginfo.MinUnit {
  386. over_count = druginfo.StockMaxNumber*drug.MinNumber + druginfo.StockMinNumber
  387. }
  388. if druginfo.MaxUnit == druginfo.MinUnit {
  389. over_count = druginfo.StockMaxNumber + druginfo.StockMinNumber
  390. }
  391. if infos.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  392. out_count = infos.Count * drug.MinNumber
  393. }
  394. if infos.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  395. out_count = infos.Count
  396. }
  397. if infos.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  398. out_count = infos.Count
  399. }
  400. if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  401. sum_count = druginfo.WarehousingCount * drug.MinNumber
  402. }
  403. if druginfo.MaxUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  404. sum_count = druginfo.WarehousingCount
  405. }
  406. if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  407. sum_count = druginfo.WarehousingCount
  408. }
  409. fmt.Println("//剩余数量", over_count)
  410. fmt.Println("该批出出库数量3223323232wo", out_count)
  411. fmt.Println("g该批次总库存wowowoowow", sum_count)
  412. if (over_count + out_count) <= sum_count {
  413. if its.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  414. fmt.Print("itscoutn233232223999wi", its.Count)
  415. //退库
  416. warehouseInfo := models.DrugWarehouseInfo{
  417. StockMinNumber: its.Count,
  418. }
  419. UpdateDrugWarehouse(its.WarehouseInfoId, warehouseInfo)
  420. //增加退库数量
  421. AddCancelSumCountOne(storeHouseConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, its.Count)
  422. //出库数量减少
  423. UpdateSumOutDrug(advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, advice.DrugId, its.Count)
  424. }
  425. if its.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  426. fmt.Print("itscoutn999888", its.Count)
  427. warehouseInfo := models.DrugWarehouseInfo{
  428. StockMaxNumber: its.Count,
  429. }
  430. UpdateDrugWarehouseOne(its.WarehouseInfoId, warehouseInfo)
  431. //增加退库数量
  432. AddCancelSumCountOne(storeHouseConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, its.Count*drug.MinNumber)
  433. //出库数量减少
  434. UpdateSumOutDrug(advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, advice.DrugId, its.Count*drug.MinNumber)
  435. }
  436. if its.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  437. fmt.Print("itscoutnwohhhhwhw", its.Count)
  438. warehouseInfo := models.DrugWarehouseInfo{
  439. StockMaxNumber: its.Count,
  440. }
  441. UpdateDrugWarehouseOne(its.WarehouseInfoId, warehouseInfo)
  442. //增加退库数量
  443. AddCancelSumCountOne(storeHouseConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, its.Count*drug.MinNumber)
  444. //出库数量减少
  445. UpdateSumOutDrug(advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, advice.DrugId, its.Count*drug.MinNumber)
  446. }
  447. }
  448. }
  449. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  450. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  451. if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  452. operation_time := time.Now().Unix()
  453. ctime := time.Now().Unix()
  454. timeStr := time.Now().Format("2006-01-02")
  455. timeArr := strings.Split(timeStr, "-")
  456. total, _ := FindAllDrugCancelStockTotal(advice.UserOrgId)
  457. total = total + 1
  458. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  459. cancelStock := models.DrugCancelStock{
  460. OrderNumber: orderNumber,
  461. OperaTime: operation_time,
  462. OrgId: advice.UserOrgId,
  463. Creater: creater,
  464. Ctime: ctime,
  465. Status: 1,
  466. ReturnTime: advice.AdviceDate,
  467. Dealer: info.Dealer,
  468. Manufacturer: info.Manufacturer,
  469. Type: 1,
  470. StorehouseId: storeHouseConfig.DrugStorehouseOut,
  471. IsCheck: 1,
  472. }
  473. AddSigleDrugCancelStock(&cancelStock)
  474. manufactureName, _ := GetManufactureById(info.Manufacturer)
  475. dealer, _ := GetDealerById(info.Dealer)
  476. cancelInfo, _ := GetLastDrugCancelStockById(advice.UserOrgId)
  477. cancelStockInfo := models.DrugCancelStockInfo{
  478. OrderNumber: cancelInfo.OrderNumber,
  479. CancelStockId: cancelInfo.ID,
  480. DrugId: advice.DrugId,
  481. Count: prescribingNumber,
  482. Status: 1,
  483. Ctime: ctime,
  484. OrgId: advice.UserOrgId,
  485. Type: 1,
  486. Manufacturer: manufactureName.ManufacturerName,
  487. Dealer: dealer.DealerName,
  488. Total: 0,
  489. RetailPrice: info.RetailPrice,
  490. RetailTotalPrice: info.RetailTotalPrice,
  491. Price: info.Price,
  492. RegisterAccount: "",
  493. Remark: info.Remark,
  494. BatchNumber: info.BatchNumber,
  495. MaxUnit: advice.PrescribingNumberUnit,
  496. ProductDate: info.ProductDate,
  497. ExpiryDate: info.ExpiryDate,
  498. BatchNumberId: info.WarehouseInfoId,
  499. StorehouseId: storeHouseConfig.DrugStorehouseOut,
  500. IsCheck: 1,
  501. }
  502. //查询剩余库存
  503. stockInfo, _ := GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  504. var sum_count int64
  505. for _, its := range stockInfo {
  506. if its.MaxUnit == drug.MaxUnit {
  507. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  508. }
  509. sum_count += its.StockMaxNumber + its.StockMinNumber
  510. }
  511. var count_one int64
  512. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  513. count_one = prescribingNumber * drug.MinNumber
  514. }
  515. if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  516. count_one = prescribingNumber
  517. }
  518. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  519. count_one = prescribingNumber * drug.MinNumber
  520. }
  521. flow := models.DrugFlow{
  522. WarehousingId: info.WarehouseInfoId,
  523. DrugId: info.DrugId,
  524. Number: "",
  525. BatchNumber: info.BatchNumber,
  526. Count: count_one,
  527. UserOrgId: advice.UserOrgId,
  528. PatientId: advice.PatientId,
  529. SystemTime: info.SysRecordTime,
  530. ConsumableType: 7,
  531. IsSys: 0,
  532. WarehousingOrder: "",
  533. WarehouseOutId: 0,
  534. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  535. IsEdit: 0,
  536. CancelStockId: cancelStock.ID,
  537. CancelOrderNumber: cancelStock.OrderNumber,
  538. Manufacturer: info.Manufacturer,
  539. Dealer: info.Dealer,
  540. Creator: creater,
  541. UpdateCreator: 0,
  542. Status: 1,
  543. Ctime: time.Now().Unix(),
  544. Mtime: 0,
  545. Price: info.Price,
  546. WarehousingDetailId: info.WarehouseInfoId,
  547. WarehouseOutDetailId: 0,
  548. CancelOutDetailId: 0,
  549. ExpireDate: info.ExpiryDate,
  550. ProductDate: info.ProductDate,
  551. MaxUnit: drug.MinUnit,
  552. MinUnit: "",
  553. AdviceId: info.AdviceId,
  554. StorehouseId: storeHouseConfig.DrugStorehouseOut,
  555. OverCount: sum_count,
  556. }
  557. CreatedCancelStock(cancelStockInfo)
  558. CreateDrugFlowOne(flow)
  559. //删除出库记录
  560. UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
  561. //删除流水
  562. UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  563. }
  564. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  565. houseConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
  566. operation_time := time.Now().Unix()
  567. ctime := time.Now().Unix()
  568. timeStr := time.Now().Format("2006-01-02")
  569. timeArr := strings.Split(timeStr, "-")
  570. total, _ := FindAllDrugCancelStockTotal(advice.UserOrgId)
  571. total = total + 1
  572. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  573. cancelStock := models.DrugCancelStock{
  574. OrderNumber: orderNumber,
  575. OperaTime: operation_time,
  576. OrgId: advice.UserOrgId,
  577. Creater: creater,
  578. Ctime: ctime,
  579. Status: 1,
  580. ReturnTime: advice.AdviceDate,
  581. Dealer: info.Dealer,
  582. Manufacturer: info.Manufacturer,
  583. Type: 1,
  584. StorehouseId: houseConfig.DrugStorehouseOut,
  585. IsCheck: 1,
  586. }
  587. AddSigleDrugCancelStock(&cancelStock)
  588. manufactureName, _ := GetManufactureById(info.Manufacturer)
  589. dealer, _ := GetDealerById(info.Dealer)
  590. cancelInfo, _ := GetLastDrugCancelStockById(advice.UserOrgId)
  591. cancelStockInfo := models.DrugCancelStockInfo{
  592. OrderNumber: cancelInfo.OrderNumber,
  593. CancelStockId: cancelInfo.ID,
  594. DrugId: info.DrugId,
  595. Count: prescribingNumber,
  596. Status: 1,
  597. Ctime: ctime,
  598. OrgId: advice.UserOrgId,
  599. Type: 1,
  600. Manufacturer: manufactureName.ManufacturerName,
  601. Dealer: dealer.DealerName,
  602. Total: 0,
  603. RetailPrice: info.RetailPrice,
  604. RetailTotalPrice: info.RetailTotalPrice,
  605. Price: info.Price,
  606. RegisterAccount: "",
  607. Remark: info.Remark,
  608. BatchNumber: info.BatchNumber,
  609. MaxUnit: advice.PrescribingNumberUnit,
  610. ProductDate: info.ProductDate,
  611. ExpiryDate: info.ExpiryDate,
  612. BatchNumberId: info.WarehouseInfoId,
  613. StorehouseId: houseConfig.DrugStorehouseOut,
  614. IsCheck: 1,
  615. }
  616. //查询剩余库存
  617. stockInfo, _ := GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  618. var sum_count int64
  619. for _, its := range stockInfo {
  620. if its.MaxUnit == drug.MaxUnit {
  621. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  622. }
  623. sum_count += its.StockMaxNumber + its.StockMinNumber
  624. }
  625. var count_one int64
  626. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  627. count_one = prescribingNumber * drug.MinNumber
  628. }
  629. if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  630. count_one = prescribingNumber
  631. }
  632. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  633. count_one = prescribingNumber * drug.MinNumber
  634. }
  635. flow := models.DrugFlow{
  636. WarehousingId: info.WarehouseInfoId,
  637. DrugId: info.DrugId,
  638. Number: "",
  639. BatchNumber: info.BatchNumber,
  640. Count: count_one,
  641. UserOrgId: advice.UserOrgId,
  642. PatientId: advice.PatientId,
  643. SystemTime: info.SysRecordTime,
  644. ConsumableType: 7,
  645. IsSys: 0,
  646. WarehousingOrder: "",
  647. WarehouseOutId: 0,
  648. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  649. IsEdit: 0,
  650. CancelStockId: cancelStock.ID,
  651. CancelOrderNumber: cancelStock.OrderNumber,
  652. Manufacturer: info.Manufacturer,
  653. Dealer: info.Dealer,
  654. Creator: creater,
  655. UpdateCreator: 0,
  656. Status: 1,
  657. Ctime: time.Now().Unix(),
  658. Mtime: 0,
  659. Price: info.Price,
  660. WarehousingDetailId: info.WarehouseInfoId,
  661. WarehouseOutDetailId: 0,
  662. CancelOutDetailId: 0,
  663. ExpireDate: info.ExpiryDate,
  664. ProductDate: info.ProductDate,
  665. MaxUnit: drug.MinUnit,
  666. MinUnit: "",
  667. AdviceId: info.AdviceId,
  668. StorehouseId: houseConfig.DrugStorehouseOut,
  669. OverCount: sum_count,
  670. }
  671. CreatedCancelStock(cancelStockInfo)
  672. CreateDrugFlowOne(flow)
  673. //删除出库记录
  674. UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
  675. //删除流水
  676. UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  677. }
  678. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  679. houseConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
  680. operation_time := time.Now().Unix()
  681. ctime := time.Now().Unix()
  682. timeStr := time.Now().Format("2006-01-02")
  683. timeArr := strings.Split(timeStr, "-")
  684. total, _ := FindAllDrugCancelStockTotal(advice.UserOrgId)
  685. total = total + 1
  686. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  687. cancelStock := models.DrugCancelStock{
  688. OrderNumber: orderNumber,
  689. OperaTime: operation_time,
  690. OrgId: advice.UserOrgId,
  691. Creater: creater,
  692. Ctime: ctime,
  693. Status: 1,
  694. ReturnTime: advice.AdviceDate,
  695. Dealer: info.Dealer,
  696. Manufacturer: info.Manufacturer,
  697. Type: 1,
  698. StorehouseId: houseConfig.DrugStorehouseOut,
  699. IsCheck: 1,
  700. }
  701. AddSigleDrugCancelStock(&cancelStock)
  702. manufactureName, _ := GetManufactureById(info.Manufacturer)
  703. dealer, _ := GetDealerById(info.Dealer)
  704. cancelInfo, _ := GetLastDrugCancelStockById(advice.UserOrgId)
  705. cancelStockInfo := models.DrugCancelStockInfo{
  706. OrderNumber: cancelInfo.OrderNumber,
  707. CancelStockId: cancelInfo.ID,
  708. DrugId: info.DrugId,
  709. Count: prescribingNumber,
  710. Status: 1,
  711. Ctime: ctime,
  712. OrgId: advice.UserOrgId,
  713. Type: 1,
  714. Manufacturer: manufactureName.ManufacturerName,
  715. Dealer: dealer.DealerName,
  716. Total: 0,
  717. RetailPrice: info.RetailPrice,
  718. RetailTotalPrice: info.RetailTotalPrice,
  719. Price: info.Price,
  720. RegisterAccount: "",
  721. Remark: info.Remark,
  722. BatchNumber: info.BatchNumber,
  723. MaxUnit: advice.PrescribingNumberUnit,
  724. ProductDate: info.ProductDate,
  725. ExpiryDate: info.ExpiryDate,
  726. BatchNumberId: info.WarehouseInfoId,
  727. StorehouseId: houseConfig.DrugStorehouseOut,
  728. IsCheck: 1,
  729. }
  730. //查询剩余库存
  731. stockInfo, _ := GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  732. var sum_count int64
  733. for _, its := range stockInfo {
  734. if its.MaxUnit == drug.MaxUnit {
  735. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  736. }
  737. sum_count += its.StockMaxNumber + its.StockMinNumber
  738. }
  739. flow := models.DrugFlow{
  740. WarehousingId: info.WarehouseInfoId,
  741. DrugId: info.DrugId,
  742. Number: "",
  743. BatchNumber: info.BatchNumber,
  744. Count: prescribingNumber,
  745. UserOrgId: advice.UserOrgId,
  746. PatientId: 0,
  747. SystemTime: info.SysRecordTime,
  748. ConsumableType: 7,
  749. IsSys: 0,
  750. WarehousingOrder: "",
  751. WarehouseOutId: 0,
  752. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  753. IsEdit: 0,
  754. CancelStockId: cancelStock.ID,
  755. CancelOrderNumber: cancelStock.OrderNumber,
  756. Manufacturer: info.Manufacturer,
  757. Dealer: info.Dealer,
  758. Creator: creater,
  759. UpdateCreator: 0,
  760. Status: 1,
  761. Ctime: time.Now().Unix(),
  762. Mtime: 0,
  763. Price: info.Price,
  764. WarehousingDetailId: info.WarehouseInfoId,
  765. WarehouseOutDetailId: 0,
  766. CancelOutDetailId: 0,
  767. ExpireDate: info.ExpiryDate,
  768. ProductDate: info.ProductDate,
  769. MaxUnit: advice.PrescribingNumberUnit,
  770. MinUnit: "",
  771. AdviceId: info.AdviceId,
  772. StorehouseId: houseConfig.DrugStorehouseOut,
  773. OverCount: sum_count,
  774. }
  775. CreatedCancelStock(cancelStockInfo)
  776. CreateDrugFlowOne(flow)
  777. //删除出库记录
  778. UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
  779. //删除流水
  780. UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  781. }
  782. //更新字典里面的库存
  783. stockInfo, _ := GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  784. //查询改药品信息
  785. medical, _ := GetBaseDrugMedical(advice.DrugId)
  786. var sum_count_one int64
  787. for _, its := range stockInfo {
  788. if its.MaxUnit == medical.MaxUnit {
  789. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  790. }
  791. sum_count_one += its.StockMaxNumber + its.StockMinNumber
  792. }
  793. UpdateBaseDrugSumTwo(advice.DrugId, sum_count_one, advice.UserOrgId)
  794. //更新库存
  795. UpdateSumDrug(advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, advice.DrugId, sum_count_one)
  796. }
  797. return err
  798. }
  799. func GoodAutoAddCancelInfo(good *models.NewDialysisBeforePrepareGoods, creater int64) error {
  800. //查询已经出库数量
  801. info, _ := GetWareOutInfo(good.GoodId, good.RecordDate, good.UserOrgId, good.PatientId, good.OrderId)
  802. if len(info) > 0 {
  803. houseConfig, _ := GetAllStoreHouseConfig(good.UserOrgId)
  804. operation_time := time.Now().Unix()
  805. //创建退库单
  806. timeStr := time.Now().Format("2006-01-02")
  807. timeArr := strings.Split(timeStr, "-")
  808. total, _ := FindAllCancelStockTotal(good.UserOrgId)
  809. total = total + 1
  810. orderNumber := "CKTKD" + strconv.FormatInt(good.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  811. cancelStock := models.CancelStock{
  812. OrderNumber: orderNumber,
  813. OperaTime: operation_time,
  814. OrgId: good.UserOrgId,
  815. Creater: creater,
  816. Ctime: time.Now().Unix(),
  817. Status: 1,
  818. ReturnTime: good.RecordDate,
  819. Type: 1,
  820. StorehouseId: houseConfig.StorehouseOutInfo,
  821. IsCheck: 1,
  822. }
  823. _, msgerrkonde := GetCancelStockDetailByOrderNumberOne(good.RecordDate, good.UserOrgId)
  824. if msgerrkonde == gorm.ErrRecordNotFound {
  825. AddSigleCancelStock(&cancelStock)
  826. }
  827. cancel, _ := GetLastCancelStockById(good.UserOrgId)
  828. for _, item := range info {
  829. manufacturer, _ := GetManufactureById(item.Manufacturer)
  830. deaerler, _ := GetDealerById(item.Dealer)
  831. cancelStockInfo := models.CancelStockInfo{
  832. GoodId: good.GoodId,
  833. CancelStockId: cancel.ID,
  834. GoodTypeId: good.GoodTypeId,
  835. Count: item.Count,
  836. Price: item.Price,
  837. Total: 0,
  838. ProductDate: item.ProductDate,
  839. ExpiryDate: item.ExpiryDate,
  840. Ctime: time.Now().Unix(),
  841. Status: 1,
  842. OrgId: good.UserOrgId,
  843. OrderNumber: cancel.OrderNumber,
  844. Type: 0,
  845. Dealer: deaerler.DealerName,
  846. Manufacturer: manufacturer.ManufacturerName,
  847. Number: item.Number,
  848. RegisterAccount: "",
  849. Remark: "",
  850. WarehouseInfoId: item.WarehouseInfotId,
  851. PatientId: item.PatientId,
  852. RecordDate: item.SysRecordTime,
  853. StorehouseId: houseConfig.StorehouseOutInfo,
  854. IsCheck: 1,
  855. }
  856. CreateCancelStockInfoOne(&cancelStockInfo)
  857. cancelInfo, _ := GetLastCancelStockInfoByGoodId(good.GoodId)
  858. goodList, _ := GetSumGoodList(item.OrgId, houseConfig.StorehouseOutInfo, item.GoodId)
  859. var over_count int64
  860. for _, it := range goodList {
  861. over_count += it.StockCount
  862. }
  863. flow := models.VmStockFlow{
  864. WarehousingId: item.WarehouseInfotId,
  865. GoodId: item.GoodId,
  866. Number: item.Number,
  867. LicenseNumber: item.LicenseNumber,
  868. Count: item.Count,
  869. UserOrgId: item.OrgId,
  870. PatientId: item.PatientId,
  871. SystemTime: item.SysRecordTime,
  872. ConsumableType: 7,
  873. IsSys: 0,
  874. WarehousingOrder: "",
  875. WarehouseOutId: item.WarehouseOutId,
  876. WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
  877. IsEdit: 0,
  878. CancelStockId: cancel.ID,
  879. CancelOrderNumber: cancel.OrderNumber,
  880. Manufacturer: manufacturer.ID,
  881. Dealer: 0,
  882. Creator: creater,
  883. UpdateCreator: 0,
  884. Status: 1,
  885. Ctime: time.Now().Unix(),
  886. Mtime: 0,
  887. Price: item.Price,
  888. WarehousingDetailId: item.WarehouseInfotId,
  889. WarehouseOutDetailId: item.ID,
  890. CancelOutDetailId: cancelInfo.ID,
  891. ProductDate: item.ProductDate,
  892. ExpireDate: item.ExpiryDate,
  893. StorehouseId: houseConfig.StorehouseOutInfo,
  894. OverCount: over_count,
  895. }
  896. CreateStockFlowOne(flow)
  897. //回退库存
  898. UpDateWarehouseInfoByStockDelete(item.WarehouseInfotId, item.Count, item.PatientId, item.SysRecordTime, item.GoodId)
  899. //退库数量增加
  900. UpdateSumAddCancelCount(good.UserOrgId, good.GoodId, houseConfig.StorehouseOutInfo, good.Count)
  901. //出库数量减少
  902. UpdateSumCount(good.UserOrgId, houseConfig.StorehouseOutInfo, good.GoodId, good.Count)
  903. //删除出库表
  904. DeleteAutoRedeceDetailTenOne(good.UserOrgId, item.PatientId, item.SysRecordTime, item.GoodId, item.OrderId)
  905. goodListOne, _ := GetSumGoodList(item.OrgId, houseConfig.StorehouseOutInfo, item.GoodId)
  906. var flush_count int64
  907. for _, it := range goodListOne {
  908. flush_count += it.StockCount
  909. }
  910. //更新剩余库存
  911. UpdateSumGood(good.UserOrgId, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  912. }
  913. }
  914. return err
  915. }