manage_center_service.go 38KB

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