manage_center_service.go 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  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").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 GetDrugAutoWarehouseOutNight(patient_id int64, advicedate int64, drugid int64, adviceid int64) (night []*models.DrugWarehouseOutInfo, err error) {
  189. 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
  190. return night, err
  191. }
  192. func UpdateDrugWarehouse(id int64, info models.DrugWarehouseInfo) error {
  193. err := writeDb.Model(&models.DrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", info.StockMinNumber)).Error
  194. return err
  195. }
  196. func UpdateDrugWarehouseOne(id int64, info models.DrugWarehouseInfo) error {
  197. err := writeDb.Model(&models.DrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", info.StockMaxNumber)).Error
  198. return err
  199. }
  200. 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) {
  201. db := readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id)
  202. if len(keyword) != 0 {
  203. keyword = "%" + keyword + "%"
  204. db = db.Where("drug_name Like ?", keyword)
  205. }
  206. if is_use != 0 {
  207. if is_use == 2 {
  208. db = db.Where("find_in_set('停用',drug_status) = 0")
  209. } else {
  210. db = db.Where("find_in_set('停用',drug_status) > 0")
  211. }
  212. }
  213. if is_charge == 1 {
  214. //if is_charge == 1 {
  215. // db = db.Where("find_in_set('收费',drug_status) > 0")
  216. //
  217. //} else {
  218. // db = db.Where("find_in_set('收费',drug_status) = 0")
  219. //}
  220. db = db.Where("is_record = ?", is_charge)
  221. }
  222. if is_charge == 2 {
  223. db = db.Where("is_record= 0 || is_record = 2")
  224. }
  225. if is_inject != 0 {
  226. //db = db.Where("drug_name Like ?", keyword)
  227. if is_inject == 1 {
  228. db = db.Where("find_in_set('注射类',drug_status) > 0")
  229. } else {
  230. db = db.Where("find_in_set('注射类',drug_status) = 0")
  231. }
  232. }
  233. if manufacturer > 0 {
  234. db = db.Where("manufacturer = ?", manufacturer)
  235. }
  236. if isRecord > 0 {
  237. db = db.Where("is_mark = ?", isRecord)
  238. }
  239. offset := (page - 1) * limit
  240. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
  241. return
  242. }
  243. func CreateMedicineInsurancePercentage(mip *models.MedicineInsurancePercentage) (err error) {
  244. err = writeDb.Create(mip).Error
  245. return
  246. }
  247. func CreateUnitSafeguard(dus *models.DrugUnitSafeguard) (err error) {
  248. err = writeDb.Create(dus).Error
  249. return
  250. }
  251. func AddSigleMZSick(dealer *models.OutpatientServiceSick) (error, *models.OutpatientServiceSick) {
  252. err := writeDb.Create(&dealer).Error
  253. return err, dealer
  254. }
  255. func ModifyMZSick(mesick *models.OutpatientServiceSick) error {
  256. err := writeDb.Save(&mesick).Error
  257. return err
  258. }
  259. func FindAllMZSickList(orgId int64, page int64, limit int64) (list []*models.OutpatientServiceSick, total int64, err error) {
  260. offset := (page - 1) * limit
  261. db := readDb.Model(&models.OutpatientServiceSick{})
  262. db = db.Where("user_org_id = ? AND status = 1", orgId)
  263. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
  264. return
  265. }
  266. func DeleteMZSickById(id int64) error {
  267. err := writeDb.Model(&models.OutpatientServiceSick{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  268. return err
  269. }
  270. func FindMZSickById(id int64) (*models.OutpatientServiceSick, error) {
  271. dealer := &models.OutpatientServiceSick{}
  272. err := readDb.Model(&models.OutpatientServiceSick{}).Where("id = ? AND status = 1", id).First(&dealer).Error
  273. return dealer, err
  274. }
  275. func GetDrugWareoutInfo(id int64) (*models.XtDrugWarehouseInfo, error) {
  276. info := models.XtDrugWarehouseInfo{}
  277. err = XTReadDB().Model(&info).Where("drug_id = ? and status = 1", id).Find(&info).Error
  278. if err == gorm.ErrRecordNotFound {
  279. return nil, err
  280. }
  281. if err != nil {
  282. return nil, err
  283. }
  284. return &info, nil
  285. }
  286. func GetDrugWareOutById(id int64) (*models.XtDrugWarehouseOutInfo, error) {
  287. info := models.XtDrugWarehouseOutInfo{}
  288. err := XTReadDB().Model(&info).Where("drug_id = ? and status = 1", id).Find(&info).Error
  289. if err == gorm.ErrRecordNotFound {
  290. return nil, err
  291. }
  292. if err != nil {
  293. return nil, err
  294. }
  295. return &info, nil
  296. }
  297. func DeleteBaseDrugById(id int64) error {
  298. drug := models.XtBaseDrug{}
  299. err := XTWriteDB().Model(&drug).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  300. return err
  301. }
  302. func AddSigleAddition(dealer *models.XtHisAddtionConfig) (error, *models.XtHisAddtionConfig) {
  303. err := writeDb.Create(&dealer).Error
  304. return err, dealer
  305. }
  306. func ModifyAddition(mesick *models.XtHisAddtionConfig) error {
  307. err := writeDb.Save(&mesick).Error
  308. return err
  309. }
  310. func FindAllAdditionList(orgId int64, page int64, limit int64) (list []*models.XtHisAddtionConfig, total int64, err error) {
  311. offset := (page - 1) * limit
  312. db := readDb.Model(&models.XtHisAddtionConfig{})
  313. db = db.Where("user_org_id = ? AND status = 1", orgId)
  314. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
  315. return
  316. }
  317. func DeleteAdditionById(id int64) error {
  318. err := writeDb.Model(&models.XtHisAddtionConfig{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  319. return err
  320. }
  321. func FindAdditionById(id int64) (*models.XtHisAddtionConfig, error) {
  322. dealer := &models.XtHisAddtionConfig{}
  323. err := readDb.Model(&models.XtHisAddtionConfig{}).Where("id = ? AND status = 1", id).First(&dealer).Error
  324. return dealer, err
  325. }
  326. func AddSigleDiagnose(dealer *models.HisXtDiagnoseConfig) (error, *models.HisXtDiagnoseConfig) {
  327. err := writeDb.Create(&dealer).Error
  328. return err, dealer
  329. }
  330. func ModifyDiagnose(mesick *models.HisXtDiagnoseConfig) error {
  331. err := writeDb.Save(&mesick).Error
  332. return err
  333. }
  334. func FindAllDiagnoseList(orgId int64, page int64, limit int64) (list []*models.HisXtDiagnoseConfig, total int64, err error) {
  335. offset := (page - 1) * limit
  336. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  337. db = db.Where("user_org_id = ? AND status = 1", orgId)
  338. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
  339. return
  340. }
  341. func DeleteDiagnoseById(id int64) error {
  342. err := writeDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  343. return err
  344. }
  345. func FindDiagnoseById(id int64) (*models.HisXtDiagnoseConfig, error) {
  346. dealer := &models.HisXtDiagnoseConfig{}
  347. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ? AND status = 1", id).First(&dealer).Error
  348. return dealer, err
  349. }
  350. func GetDoseCode(dose_id int64, user_org_id int64) (error, string) {
  351. var data models.DictDataconfig
  352. 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
  353. return err, data.Code
  354. }
  355. func GetAllDrugList(orgid int64) (drug []*models.BaseDrugLib, err error) {
  356. err = XTReadDB().Model(&drug).Where("org_id = ? and status = 1", orgid).Find(&drug).Error
  357. return drug, err
  358. }
  359. //自动退库分装方法
  360. func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) error {
  361. //查询该病人该药品是否有库存记录
  362. info, _ := GetDrugAutoWarehouseOutEight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
  363. list, _ := GetDrugAutoWarehouseOutNight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
  364. storeHouseConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
  365. //退库
  366. drug, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  367. //如果剩余数量 + 退库数量 < 总入库数量
  368. if len(list) > 0 {
  369. for _, its := range list {
  370. //查询该药品出库批次总入库数量
  371. druginfo, _ := GetDrugInfoSix(its.WarehouseInfoId, info.OrgId)
  372. var out_count int64 //该批次出库库存
  373. var sum_count int64 //该批次总库存
  374. var over_count int64 //剩余数量
  375. over_count = druginfo.StockMaxNumber*drug.MinNumber + druginfo.StockMinNumber
  376. if info.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  377. out_count = info.Count * drug.MinNumber
  378. }
  379. if info.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  380. out_count = info.Count
  381. }
  382. if info.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  383. out_count = info.Count
  384. }
  385. if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  386. sum_count = druginfo.WarehousingCount * drug.MinNumber
  387. }
  388. if druginfo.MaxUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  389. sum_count = druginfo.WarehousingCount
  390. }
  391. if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  392. sum_count = druginfo.WarehousingCount
  393. }
  394. fmt.Println("该批次剩余库存", over_count)
  395. fmt.Println("该批次退库数量", out_count)
  396. fmt.Println("该批次总入库数量", sum_count)
  397. if (over_count + out_count) <= sum_count {
  398. if its.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  399. //退库
  400. warehouseInfo := models.DrugWarehouseInfo{
  401. StockMinNumber: its.Count,
  402. }
  403. UpdateDrugWarehouse(its.WarehouseInfoId, warehouseInfo)
  404. }
  405. if its.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  406. warehouseInfo := models.DrugWarehouseInfo{
  407. StockMaxNumber: its.Count,
  408. }
  409. UpdateDrugWarehouseOne(its.WarehouseInfoId, warehouseInfo)
  410. }
  411. if its.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  412. warehouseInfo := models.DrugWarehouseInfo{
  413. StockMaxNumber: its.Count,
  414. }
  415. UpdateDrugWarehouseOne(its.WarehouseInfoId, warehouseInfo)
  416. }
  417. }
  418. }
  419. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  420. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  421. if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  422. operation_time := time.Now().Unix()
  423. ctime := time.Now().Unix()
  424. timeStr := time.Now().Format("2006-01-02")
  425. timeArr := strings.Split(timeStr, "-")
  426. total, _ := FindAllDrugCancelStockTotal(advice.UserOrgId)
  427. total = total + 1
  428. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  429. cancelStock := models.DrugCancelStock{
  430. OrderNumber: orderNumber,
  431. OperaTime: operation_time,
  432. OrgId: advice.UserOrgId,
  433. Creater: creater,
  434. Ctime: ctime,
  435. Status: 1,
  436. ReturnTime: advice.AdviceDate,
  437. Dealer: info.Dealer,
  438. Manufacturer: info.Manufacturer,
  439. Type: 1,
  440. StorehouseId: storeHouseConfig.DrugStorehouseOut,
  441. IsCheck: 1,
  442. }
  443. AddSigleDrugCancelStock(&cancelStock)
  444. manufactureName, _ := GetManufactureById(info.Manufacturer)
  445. dealer, _ := GetDealerById(info.Dealer)
  446. cancelInfo, _ := GetLastDrugCancelStockById(advice.UserOrgId)
  447. cancelStockInfo := models.DrugCancelStockInfo{
  448. OrderNumber: cancelInfo.OrderNumber,
  449. CancelStockId: cancelInfo.ID,
  450. DrugId: advice.DrugId,
  451. Count: prescribingNumber,
  452. Status: 1,
  453. Ctime: ctime,
  454. OrgId: advice.UserOrgId,
  455. Type: 1,
  456. Manufacturer: manufactureName.ManufacturerName,
  457. Dealer: dealer.DealerName,
  458. Total: 0,
  459. RetailPrice: info.RetailPrice,
  460. RetailTotalPrice: info.RetailTotalPrice,
  461. Price: info.Price,
  462. RegisterAccount: "",
  463. Remark: info.Remark,
  464. BatchNumber: info.BatchNumber,
  465. MaxUnit: advice.PrescribingNumberUnit,
  466. ProductDate: info.ProductDate,
  467. ExpiryDate: info.ExpiryDate,
  468. BatchNumberId: info.WarehouseInfoId,
  469. StorehouseId: storeHouseConfig.DrugStorehouseOut,
  470. IsCheck: 1,
  471. }
  472. flow := models.DrugFlow{
  473. WarehousingId: 0,
  474. DrugId: info.DrugId,
  475. Number: "",
  476. BatchNumber: info.BatchNumber,
  477. Count: prescribingNumber,
  478. UserOrgId: advice.UserOrgId,
  479. PatientId: 0,
  480. SystemTime: info.SysRecordTime,
  481. ConsumableType: 7,
  482. IsSys: 0,
  483. WarehousingOrder: "",
  484. WarehouseOutId: 0,
  485. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  486. IsEdit: 0,
  487. CancelStockId: cancelStock.ID,
  488. CancelOrderNumber: cancelStock.OrderNumber,
  489. Manufacturer: info.Manufacturer,
  490. Dealer: info.Dealer,
  491. Creator: creater,
  492. UpdateCreator: 0,
  493. Status: 1,
  494. Ctime: time.Now().Unix(),
  495. Mtime: 0,
  496. Price: info.Price,
  497. WarehousingDetailId: 0,
  498. WarehouseOutDetailId: 0,
  499. CancelOutDetailId: 0,
  500. ExpireDate: info.ExpiryDate,
  501. ProductDate: info.ProductDate,
  502. MaxUnit: advice.PrescribingNumberUnit,
  503. MinUnit: "",
  504. AdviceId: info.AdviceId,
  505. StorehouseId: storeHouseConfig.DrugStorehouseOut,
  506. }
  507. CreatedCancelStock(cancelStockInfo)
  508. CreateDrugFlowOne(flow)
  509. //删除出库记录
  510. UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID, info.WarehouseOutId)
  511. //删除流水
  512. UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID, info.ID)
  513. }
  514. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  515. houseConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
  516. operation_time := time.Now().Unix()
  517. ctime := time.Now().Unix()
  518. timeStr := time.Now().Format("2006-01-02")
  519. timeArr := strings.Split(timeStr, "-")
  520. total, _ := FindAllDrugCancelStockTotal(advice.UserOrgId)
  521. total = total + 1
  522. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  523. cancelStock := models.DrugCancelStock{
  524. OrderNumber: orderNumber,
  525. OperaTime: operation_time,
  526. OrgId: advice.UserOrgId,
  527. Creater: creater,
  528. Ctime: ctime,
  529. Status: 1,
  530. ReturnTime: advice.AdviceDate,
  531. Dealer: info.Dealer,
  532. Manufacturer: info.Manufacturer,
  533. Type: 1,
  534. StorehouseId: houseConfig.DrugStorehouseOut,
  535. IsCheck: 1,
  536. }
  537. AddSigleDrugCancelStock(&cancelStock)
  538. fmt.Println("到这里了吗32222222222222222222222222222222222222222222222")
  539. manufactureName, _ := GetManufactureById(info.Manufacturer)
  540. dealer, _ := GetDealerById(info.Dealer)
  541. cancelInfo, _ := GetLastDrugCancelStockById(advice.UserOrgId)
  542. cancelStockInfo := models.DrugCancelStockInfo{
  543. OrderNumber: cancelInfo.OrderNumber,
  544. CancelStockId: cancelInfo.ID,
  545. DrugId: info.DrugId,
  546. Count: prescribingNumber,
  547. Status: 1,
  548. Ctime: ctime,
  549. OrgId: advice.UserOrgId,
  550. Type: 1,
  551. Manufacturer: manufactureName.ManufacturerName,
  552. Dealer: dealer.DealerName,
  553. Total: 0,
  554. RetailPrice: info.RetailPrice,
  555. RetailTotalPrice: info.RetailTotalPrice,
  556. Price: info.Price,
  557. RegisterAccount: "",
  558. Remark: info.Remark,
  559. BatchNumber: info.BatchNumber,
  560. MaxUnit: advice.PrescribingNumberUnit,
  561. ProductDate: info.ProductDate,
  562. ExpiryDate: info.ExpiryDate,
  563. BatchNumberId: info.WarehouseInfoId,
  564. StorehouseId: houseConfig.DrugStorehouseOut,
  565. IsCheck: 1,
  566. }
  567. flow := models.DrugFlow{
  568. WarehousingId: 0,
  569. DrugId: info.DrugId,
  570. Number: "",
  571. BatchNumber: info.BatchNumber,
  572. Count: prescribingNumber,
  573. UserOrgId: advice.UserOrgId,
  574. PatientId: 0,
  575. SystemTime: info.SysRecordTime,
  576. ConsumableType: 7,
  577. IsSys: 0,
  578. WarehousingOrder: "",
  579. WarehouseOutId: 0,
  580. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  581. IsEdit: 0,
  582. CancelStockId: cancelStock.ID,
  583. CancelOrderNumber: cancelStock.OrderNumber,
  584. Manufacturer: info.Manufacturer,
  585. Dealer: info.Dealer,
  586. Creator: creater,
  587. UpdateCreator: 0,
  588. Status: 1,
  589. Ctime: time.Now().Unix(),
  590. Mtime: 0,
  591. Price: info.Price,
  592. WarehousingDetailId: 0,
  593. WarehouseOutDetailId: 0,
  594. CancelOutDetailId: 0,
  595. ExpireDate: info.ExpiryDate,
  596. ProductDate: info.ProductDate,
  597. MaxUnit: advice.PrescribingNumberUnit,
  598. MinUnit: "",
  599. AdviceId: info.AdviceId,
  600. StorehouseId: houseConfig.DrugStorehouseOut,
  601. }
  602. CreatedCancelStock(cancelStockInfo)
  603. CreateDrugFlowOne(flow)
  604. //删除出库记录
  605. UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID, info.WarehouseOutId)
  606. //删除流水
  607. UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID, info.ID)
  608. }
  609. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  610. houseConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
  611. if advice.PrescribingNumberUnit == drug.MaxUnit {
  612. warehouseInfo := models.DrugWarehouseInfo{
  613. StockMaxNumber: prescribingNumber,
  614. }
  615. UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  616. }
  617. operation_time := time.Now().Unix()
  618. ctime := time.Now().Unix()
  619. timeStr := time.Now().Format("2006-01-02")
  620. timeArr := strings.Split(timeStr, "-")
  621. total, _ := FindAllDrugCancelStockTotal(advice.UserOrgId)
  622. total = total + 1
  623. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  624. cancelStock := models.DrugCancelStock{
  625. OrderNumber: orderNumber,
  626. OperaTime: operation_time,
  627. OrgId: advice.UserOrgId,
  628. Creater: creater,
  629. Ctime: ctime,
  630. Status: 1,
  631. ReturnTime: advice.AdviceDate,
  632. Dealer: info.Dealer,
  633. Manufacturer: info.Manufacturer,
  634. Type: 1,
  635. StorehouseId: houseConfig.DrugStorehouseOut,
  636. IsCheck: 1,
  637. }
  638. AddSigleDrugCancelStock(&cancelStock)
  639. fmt.Println("到这里了吗32222222222222222222222222222222222222222222222")
  640. manufactureName, _ := GetManufactureById(info.Manufacturer)
  641. dealer, _ := GetDealerById(info.Dealer)
  642. cancelInfo, _ := GetLastDrugCancelStockById(advice.UserOrgId)
  643. cancelStockInfo := models.DrugCancelStockInfo{
  644. OrderNumber: cancelInfo.OrderNumber,
  645. CancelStockId: cancelInfo.ID,
  646. DrugId: info.DrugId,
  647. Count: prescribingNumber,
  648. Status: 1,
  649. Ctime: ctime,
  650. OrgId: advice.UserOrgId,
  651. Type: 1,
  652. Manufacturer: manufactureName.ManufacturerName,
  653. Dealer: dealer.DealerName,
  654. Total: 0,
  655. RetailPrice: info.RetailPrice,
  656. RetailTotalPrice: info.RetailTotalPrice,
  657. Price: info.Price,
  658. RegisterAccount: "",
  659. Remark: info.Remark,
  660. BatchNumber: info.BatchNumber,
  661. MaxUnit: advice.PrescribingNumberUnit,
  662. ProductDate: info.ProductDate,
  663. ExpiryDate: info.ExpiryDate,
  664. BatchNumberId: info.WarehouseInfoId,
  665. StorehouseId: houseConfig.DrugStorehouseOut,
  666. IsCheck: 1,
  667. }
  668. flow := models.DrugFlow{
  669. WarehousingId: 0,
  670. DrugId: info.DrugId,
  671. Number: "",
  672. BatchNumber: info.BatchNumber,
  673. Count: prescribingNumber,
  674. UserOrgId: advice.UserOrgId,
  675. PatientId: 0,
  676. SystemTime: info.SysRecordTime,
  677. ConsumableType: 7,
  678. IsSys: 0,
  679. WarehousingOrder: "",
  680. WarehouseOutId: 0,
  681. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  682. IsEdit: 0,
  683. CancelStockId: cancelStock.ID,
  684. CancelOrderNumber: cancelStock.OrderNumber,
  685. Manufacturer: info.Manufacturer,
  686. Dealer: info.Dealer,
  687. Creator: creater,
  688. UpdateCreator: 0,
  689. Status: 1,
  690. Ctime: time.Now().Unix(),
  691. Mtime: 0,
  692. Price: info.Price,
  693. WarehousingDetailId: 0,
  694. WarehouseOutDetailId: 0,
  695. CancelOutDetailId: 0,
  696. ExpireDate: info.ExpiryDate,
  697. ProductDate: info.ProductDate,
  698. MaxUnit: advice.PrescribingNumberUnit,
  699. MinUnit: "",
  700. AdviceId: info.AdviceId,
  701. StorehouseId: houseConfig.DrugStorehouseOut,
  702. }
  703. CreatedCancelStock(cancelStockInfo)
  704. CreateDrugFlowOne(flow)
  705. //删除出库记录
  706. UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID, info.WarehouseOutId)
  707. //删除流水
  708. UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID, info.ID)
  709. }
  710. //更新字典里面的库存
  711. stockInfo, _ := GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  712. //查询改药品信息
  713. medical, _ := GetBaseDrugMedical(advice.DrugId)
  714. var sum_count_one int64
  715. for _, its := range stockInfo {
  716. sum_count_one += its.StockMaxNumber*medical.MinNumber + its.StockMinNumber
  717. }
  718. UpdateBaseDrugSumTwo(advice.DrugId, sum_count_one, advice.UserOrgId)
  719. }
  720. return err
  721. }