new_stock_service.go 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. package service
  2. import (
  3. "XT_New/models"
  4. "github.com/jinzhu/gorm"
  5. )
  6. func GetGoodStockCount(user_org_id int64, storehouse_id int64, good_id int64) (*models.XtGoodStockCount, error) {
  7. goodStock := models.XtGoodStockCount{}
  8. var err error
  9. err = XTReadDB().Where("user_org_id = ? and storehouse_id = ? and good_id = ?", user_org_id, storehouse_id, good_id).Find(&goodStock).Error
  10. if err == gorm.ErrRecordNotFound {
  11. return nil, err
  12. }
  13. if err != nil {
  14. return nil, err
  15. }
  16. return &goodStock, nil
  17. }
  18. func CreateGoodCount(good models.XtGoodStockCount) error {
  19. db := writeDb.Begin()
  20. err := db.Create(&good).Error
  21. if err != nil {
  22. db.Rollback()
  23. return err
  24. }
  25. db.Commit()
  26. return err
  27. }
  28. func UpdateGoodStockCount(user_org_id int64, storehouse_id int64, good_id int64, count int64, flush_count int64) error {
  29. db := writeDb.Begin()
  30. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count + ?", count)).Error
  31. if err != nil {
  32. db.Rollback()
  33. return err
  34. }
  35. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
  36. if err != nil {
  37. db.Rollback()
  38. return err
  39. }
  40. db.Commit()
  41. return err
  42. }
  43. func UpdateGoodInCount(count int64, user_org_id int64, good_id int64, storehouse_id int64, flush_count int64) error {
  44. db := writeDb.Begin()
  45. err := db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and good_id = ? and storehouse_id = ? and status = 1", user_org_id, good_id, storehouse_id).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count - ?", count)).Error
  46. if err != nil {
  47. db.Rollback()
  48. return err
  49. }
  50. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and good_id = ? and storehouse_id = ? and status = 1", user_org_id, good_id, storehouse_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
  51. if err != nil {
  52. db.Rollback()
  53. return err
  54. }
  55. db.Commit()
  56. return err
  57. }
  58. func CreateGoodErrcode(errcode models.XtGoodErrcode) error {
  59. err := writeDb.Create(&errcode).Error
  60. return err
  61. }
  62. func GetGoodStockList(orgId int64, storehouse_id int64, good_type int64, keyword string, page int64, limit int64, ids []int64) (good []*models.GoodInformation, total int64, err error) {
  63. offset := (page - 1) * limit
  64. likeKey := "%" + keyword + "%"
  65. db := XTReadDB().Table("xt_good_information as x").Where("x.status = 1 and x.org_id =? and find_in_set('停用',x.good_status) = 0", orgId)
  66. if good_type == 2 {
  67. db = db.Where(" x.total_count<=x.stock_warn_count")
  68. }
  69. if good_type == 3 {
  70. db = db.Where("x.sum_count = 0")
  71. }
  72. if good_type == 4 {
  73. db = db.Where("x.sum_count > 0")
  74. }
  75. if len(keyword) > 0 {
  76. db = db.Where("good_name like ? or manufacturer in(?)", likeKey, ids)
  77. }
  78. db = db.Preload("XtGoodStockCount", func(db *gorm.DB) *gorm.DB {
  79. if storehouse_id > 0 {
  80. db = db.Where("storehouse_id = ?", storehouse_id)
  81. }
  82. return db.Where("status = 1 and user_org_id = ?", orgId)
  83. })
  84. db = db.Preload("GoodStockCount", func(db *gorm.DB) *gorm.DB {
  85. if storehouse_id > 0 {
  86. db = db.Where("storehouse_id = ?", storehouse_id)
  87. }
  88. return db.Where("status = 1 and user_org_id = ?", orgId).Group("good_id,storehouse_id")
  89. })
  90. db = db.Preload("WarehousingInfo", func(db *gorm.DB) *gorm.DB {
  91. if storehouse_id > 0 {
  92. db = db.Where("storehouse_id = ?", storehouse_id)
  93. }
  94. return db.Where("status = 1 and org_id = ? and is_check = 1", orgId)
  95. })
  96. if orgId == 10489 {
  97. err = db.Count(&total).Offset(offset).Limit(limit).Order("x.sum_count desc").Find(&good).Error
  98. } else {
  99. err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Find(&good).Error
  100. }
  101. return good, total, err
  102. }
  103. func GetSumGoodList(orgid int64, storehouse_id int64, good_id int64) (info []*models.WarehousingInfo, err error) {
  104. err = XTReadDB().Where("org_id = ? and storehouse_id = ? and good_id = ? and status =1 and is_check = 1", orgid, storehouse_id, good_id).Find(&info).Error
  105. return info, err
  106. }
  107. func UpdateSumGood(orgid int64, storehouse_id int64, good_id int64, flush_count int64) error {
  108. db := writeDb.Begin()
  109. err := db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", orgid, storehouse_id, good_id).Updates(map[string]interface{}{"flush_count": flush_count}).Error
  110. if err != nil {
  111. db.Rollback()
  112. return err
  113. }
  114. db.Commit()
  115. return err
  116. }
  117. func UpdateSumCount(user_org_id int64, storehouse_id int64, good_id int64, count int64) error {
  118. ut := XTWriteDB().Begin()
  119. err = ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count - ?", count)).Error
  120. if err != nil {
  121. ut.Rollback()
  122. return err
  123. }
  124. ut.Commit()
  125. return err
  126. }
  127. func UpdateActSumCount(user_org_id int64, storehouse_id int64, good_id int64, count int64) error {
  128. ut := XTWriteDB().Begin()
  129. err = ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_act_out_count", gorm.Expr("stock_act_out_count - ?", count)).Error
  130. if err != nil {
  131. ut.Rollback()
  132. return err
  133. }
  134. ut.Commit()
  135. return err
  136. }
  137. func GetHisPrescriptionList(orgid int64) (project []*models.HisPrescriptionProject, err error) {
  138. err = XTReadDB().Where("user_org_id = ? and status= 1 and record_date =1690819200", orgid).Find(&project).Error
  139. return project, err
  140. }
  141. func UpdateGoodFlow(project_id int64, price float64) error {
  142. flow := models.VmStockFlow{}
  143. err := XTWriteDB().Model(&flow).Where("warehousing_id = ? and user_org_id =10265", project_id).Updates(map[string]interface{}{"price": price}).Error
  144. err = XTWriteDB().Model(models.WarehouseOutInfo{}).Where("warehouse_info_id = ? and org_id =10265", project_id).Updates(map[string]interface{}{"price": price}).Error
  145. return err
  146. }
  147. func GetSendGoodInformation(org_id int64) (info []*models.WarehousingInfo, err error) {
  148. err = XTReadDB().Where("org_id = ? and is_check = 1 and status = 1", org_id).Find(&info).Error
  149. return info, err
  150. }
  151. func GetStockFlush(storehouse_id int64, good_id int64, orgid int64) (*models.XtGoodStockCount, error) {
  152. stockCount := models.XtGoodStockCount{}
  153. var err error
  154. err = XTReadDB().Where("storehouse_id =? and good_id = ? and user_org_id = ?", storehouse_id, good_id, orgid).Find(&stockCount).Error
  155. if err == gorm.ErrRecordNotFound {
  156. return nil, err
  157. }
  158. if err != nil {
  159. return nil, err
  160. }
  161. return &stockCount, nil
  162. }
  163. func CreateGoodCountSix(good models.XtGoodStockCount) error {
  164. err := XTWriteDB().Create(&good).Error
  165. return err
  166. }
  167. func UpdateGoodCount(warehousingCount int64, stock_count int64, out_count int64, storehouse_id int64, good_id int64, orgid int64, cancel_count int64, act_count int64) error {
  168. err := XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count+?", warehousingCount)).Error
  169. err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"stock_out_count": out_count}).Error
  170. err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).UpdateColumn("flush_count", gorm.Expr("flush_count + ?", stock_count)).Error
  171. err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"stock_cancel_count": cancel_count}).Error
  172. err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"stock_act_out_count": act_count}).Error
  173. return err
  174. }
  175. func UpdateGoodCountSend(warehousingCount int64, stock_count int64, out_count int64, storehouse_id int64, good_id int64, orgid int64, cancel_count int64, act_count int64) error {
  176. err := XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Updates(map[string]interface{}{"stock_in_count": warehousingCount}).Error
  177. err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"stock_out_count": out_count}).Error
  178. err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"flush_count": stock_count}).Error
  179. err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"stock_cancel_count": cancel_count}).Error
  180. err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"stock_act_out_count": act_count}).Error
  181. return err
  182. }
  183. func GetAllCancelCount(storehouse_id int64, good_id int64, org_id int64) (flow []*models.VmStockFlow, err error) {
  184. err = XTReadDB().Where("storehouse_id = ? and good_id = ? and user_org_id = ? and (consumable_type = 4 or consumable_type= 7) and status = 1", storehouse_id, good_id, org_id).Find(&flow).Error
  185. return flow, err
  186. }
  187. func GetAllStockOutCount(storehouse_id int64, good_id int64, org_id int64) (flow []*models.VmStockFlow, err error) {
  188. err = XTReadDB().Where("storehouse_id = ? and good_id = ? and user_org_id = ? and (consumable_type = 2 or consumable_type= 3)", storehouse_id, good_id, org_id).Find(&flow).Error
  189. return flow, err
  190. }
  191. func GetActStockOutCount(storehouse_id int64, good_id int64, org_id int64) (flow []*models.VmStockFlow, err error) {
  192. err = XTReadDB().Where("storehouse_id = ? and good_id = ? and user_org_id = ? and (consumable_type = 2 or consumable_type= 3) and status = 1", storehouse_id, good_id, org_id).Find(&flow).Error
  193. return flow, err
  194. }
  195. func GetDrugStockCount(storehouse_id int64, drug_id int64, org_id int64) (*models.XtDrugStockCount, error) {
  196. drugStockCount := models.XtDrugStockCount{}
  197. var err error
  198. err = XTReadDB().Where("storehouse_id = ? and drug_id = ? and user_org_id = ? and status = 1", storehouse_id, drug_id, org_id).Find(&drugStockCount).Error
  199. if err == gorm.ErrRecordNotFound {
  200. return nil, err
  201. }
  202. if err != nil {
  203. return nil, err
  204. }
  205. return &drugStockCount, nil
  206. }
  207. func GetDrugStockCountSix(storehouse_id int64, drug_id int64, org_id int64) (models.XtDrugStockCount, error) {
  208. drugStockCount := models.XtDrugStockCount{}
  209. err = XTReadDB().Where("storehouse_id = ? and drug_id = ? and user_org_id = ? and status = 1", storehouse_id, drug_id, org_id).Find(&drugStockCount).Error
  210. return drugStockCount, err
  211. }
  212. func CreateDrugStockSum(drug models.XtDrugStockCount) error {
  213. ut := XTWriteDB().Begin()
  214. err := ut.Create(&drug).Error
  215. if err != nil {
  216. ut.Rollback()
  217. return err
  218. }
  219. ut.Commit()
  220. return err
  221. }
  222. func AddDrugStockSum(storehouse_id int64, drug_id int64, user_org_id int64, waresing_count int64, over_count int64) error {
  223. db := writeDb.Begin()
  224. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count + ?", waresing_count)).Error
  225. if err != nil {
  226. db.Rollback()
  227. return err
  228. }
  229. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
  230. if err != nil {
  231. db.Rollback()
  232. return err
  233. }
  234. db.Commit()
  235. return err
  236. }
  237. func UpdateDrugStockSum(storehouse_id int64, drug_id int64, user_org_id int64, waresing_count int64, over_count int64) error {
  238. db := writeDb.Begin()
  239. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"sum_in_count": waresing_count}).Error
  240. if err != nil {
  241. db.Rollback()
  242. return err
  243. }
  244. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
  245. if err != nil {
  246. db.Rollback()
  247. return err
  248. }
  249. db.Commit()
  250. return err
  251. }
  252. func ReduceDrugStockCount(storehouse_id int64, drug_id int64, user_org_id int64, waresing_count int64, over_count int64) error {
  253. db := writeDb.Begin()
  254. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count - ?", waresing_count)).Error
  255. if err != nil {
  256. db.Rollback()
  257. return err
  258. }
  259. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
  260. if err != nil {
  261. db.Rollback()
  262. return err
  263. }
  264. db.Commit()
  265. return err
  266. }
  267. func AddCancelSumCount(storehouse_id int64, drug_id int64, user_org_id int64, cancel_count int64, over_count int64) error {
  268. db := writeDb.Begin()
  269. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_cancel_count", gorm.Expr("sum_cancel_count + ?", cancel_count)).Error
  270. if err != nil {
  271. db.Rollback()
  272. return err
  273. }
  274. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
  275. if err != nil {
  276. db.Rollback()
  277. return err
  278. }
  279. db.Commit()
  280. return err
  281. }
  282. func AddCancelSumCountOne(storehouse_id int64, drug_id int64, user_org_id int64, cancel_count int64) error {
  283. db := writeDb.Begin()
  284. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_cancel_count", gorm.Expr("sum_cancel_count + ?", cancel_count)).Error
  285. if err != nil {
  286. db.Rollback()
  287. return err
  288. }
  289. db.Commit()
  290. return err
  291. }
  292. func AddNewCancelSumCountOne(storehouse_id int64, drug_id int64, user_org_id int64, cancel_count int64, tx *gorm.DB) error {
  293. err = tx.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_cancel_count", gorm.Expr("sum_cancel_count + ?", cancel_count)).Error
  294. if err != nil {
  295. tx.Rollback()
  296. return err
  297. }
  298. return err
  299. }
  300. func ReduceCancelSumCount(storehouse_id int64, drug_id int64, user_org_id int64, cancel_count int64, over_count int64) error {
  301. db := writeDb.Begin()
  302. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_cancel_count", gorm.Expr("sum_cancel_count - ?", cancel_count)).Error
  303. if err != nil {
  304. db.Rollback()
  305. return err
  306. }
  307. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
  308. if err != nil {
  309. db.Rollback()
  310. return err
  311. }
  312. db.Commit()
  313. return err
  314. }
  315. func UpdateSumDrug(orgid int64, storehouse_id int64, drug_id int64, flush_count int64) error {
  316. db := writeDb.Begin()
  317. err := db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", orgid, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
  318. if err != nil {
  319. db.Rollback()
  320. return err
  321. }
  322. db.Commit()
  323. return err
  324. }
  325. func UpdateSumOutDrug(orgid int64, storehouse_id int64, drug_id int64, sum_out_count int64) error {
  326. db := writeDb.Begin()
  327. err := db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", orgid, storehouse_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count - ?", sum_out_count)).Error
  328. if err != nil {
  329. db.Rollback()
  330. return err
  331. }
  332. db.Commit()
  333. return err
  334. }
  335. func GetAutoGoodLastCount(goodid int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  336. detail := models.AutomaticReduceDetail{}
  337. err := XTReadDB().Where("good_id = ? and count = ? and record_time = ? and patient_id = ?", goodid, count, record_time, patient_id).Last(&detail).Error
  338. return detail, err
  339. }
  340. func UpdateLastAutoCount(id int64, count int64) error {
  341. detail := models.AutomaticReduceDetail{}
  342. err := XTWriteDB().Model(&detail).Where("id = ?", id).Update(map[string]interface{}{"count": count, "status": 1}).Error
  343. return err
  344. }
  345. func GetWareOutInfo(good_id int64, record_date int64, user_org_id int64, patient_id int64, order_id int64) (outinfo []*models.WarehouseOutInfo, err error) {
  346. err = XTReadDB().Where("good_id = ? and sys_record_time = ? and org_id = ? and status = 1 and patient_id = ? and order_id = ?", good_id, record_date, user_org_id, patient_id, order_id).Find(&outinfo).Error
  347. return outinfo, err
  348. }
  349. func AddGoodStockCount(storehouse_id int64, good_id int64, user_org_id int64, count int64) error {
  350. db := writeDb.Begin()
  351. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count + ?", count)).Error
  352. if err != nil {
  353. db.Rollback()
  354. return err
  355. }
  356. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("flush_count", gorm.Expr("flush_count + ?", count)).Error
  357. if err != nil {
  358. db.Rollback()
  359. return err
  360. }
  361. db.Commit()
  362. return err
  363. }
  364. func AddDrugStockCount(storehouse_id int64, drug_id int64, user_org_id int64, count int64) error {
  365. db := writeDb.Begin()
  366. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count + ?", count)).Error
  367. if err != nil {
  368. db.Rollback()
  369. return err
  370. }
  371. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("flush_count", gorm.Expr("flush_count + ?", count)).Error
  372. if err != nil {
  373. db.Rollback()
  374. return err
  375. }
  376. db.Commit()
  377. return err
  378. }
  379. func ReduceStockCount(storehouse_id int64, good_id int64, user_org_id int64, count int64) error {
  380. db := writeDb.Begin()
  381. //err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count - ?", count)).Error
  382. //if err != nil {
  383. // db.Rollback()
  384. // return err
  385. //}
  386. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count + ?", count)).Error
  387. if err != nil {
  388. db.Rollback()
  389. return err
  390. }
  391. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_act_out_count", gorm.Expr("stock_act_out_count + ?", count)).Error
  392. if err != nil {
  393. db.Rollback()
  394. return err
  395. }
  396. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("flush_count", gorm.Expr("flush_count - ?", count)).Error
  397. if err != nil {
  398. db.Rollback()
  399. return err
  400. }
  401. db.Commit()
  402. return err
  403. }
  404. func ReduceStockCountTwo(storehouse_id int64, good_id int64, user_org_id int64, count int64) error {
  405. db := writeDb.Begin()
  406. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count + ?", count)).Error
  407. if err != nil {
  408. db.Rollback()
  409. return err
  410. }
  411. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_act_out_count", gorm.Expr("stock_act_out_count + ?", count)).Error
  412. if err != nil {
  413. db.Rollback()
  414. return err
  415. }
  416. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("flush_count", gorm.Expr("flush_count - ?", count)).Error
  417. if err != nil {
  418. db.Rollback()
  419. return err
  420. }
  421. db.Commit()
  422. return err
  423. }
  424. func ReduceDrugStockCountSix(storehouse_id int64, drug_id int64, user_org_id int64, count int64) error {
  425. db := writeDb.Begin()
  426. //err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count - ?", count)).Error
  427. //if err != nil {
  428. // db.Rollback()
  429. // return err
  430. //}
  431. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count + ?", count)).Error
  432. if err != nil {
  433. db.Rollback()
  434. return err
  435. }
  436. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_act_out_count", gorm.Expr("sum_act_out_count + ?", count)).Error
  437. if err != nil {
  438. db.Rollback()
  439. return err
  440. }
  441. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("flush_count", gorm.Expr("flush_count - ?", count)).Error
  442. if err != nil {
  443. db.Rollback()
  444. return err
  445. }
  446. db.Commit()
  447. return err
  448. }
  449. func ReduceDrugStockCountSeven(storehouse_id int64, drug_id int64, user_org_id int64, count int64) error {
  450. db := writeDb.Begin()
  451. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count + ?", count)).Error
  452. if err != nil {
  453. db.Rollback()
  454. return err
  455. }
  456. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_act_out_count", gorm.Expr("sum_act_out_count + ?", count)).Error
  457. if err != nil {
  458. db.Rollback()
  459. return err
  460. }
  461. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("flush_count", gorm.Expr("flush_count - ?", count)).Error
  462. if err != nil {
  463. db.Rollback()
  464. return err
  465. }
  466. db.Commit()
  467. return err
  468. }
  469. func GetWarehouseOutInfoByProjectIdList(project_id int64, org_id int64, storehouse_id int64, good_id int64, patient_id int64, sys_record_time int64) (info []*models.WarehouseOutInfoNight, err error) {
  470. err = XTReadDB().Where("project_id = ? and org_id = ? and storehouse_id = ? and good_id = ? and patient_id = ? and sys_record_time = ? and status = 1", project_id, org_id, storehouse_id, good_id, patient_id, sys_record_time).Find(&info).Error
  471. return info, err
  472. }
  473. func GetWarehouseStockFlow(warehouse_info_id int64, good_id int64, user_org_id int64, patient_id int64, system_time int64) (models.VmStockFlow, error) {
  474. stockFlow := models.VmStockFlow{}
  475. err := XTReadDB().Where("warehousing_detail_id = ? and good_id = ? and user_org_id = ? and patient_id = ? AND consumable_type = 7 and system_time = ?", warehouse_info_id, good_id, user_org_id, patient_id, system_time).Find(&stockFlow).Error
  476. return stockFlow, err
  477. }
  478. func AddCountFlowOne(warehouse_info_id int64, good_id int64, user_org_id int64, patient_id int64, count int64, system_time int64, over_count int64) error {
  479. stockFlow := models.VmStockFlow{}
  480. err := XTWriteDB().Model(&stockFlow).Where("warehousing_detail_id = ? and good_id = ? and user_org_id = ? and patient_id = ? AND consumable_type = 7 and system_time = ?", warehouse_info_id, good_id, user_org_id, patient_id, system_time).UpdateColumn("count", gorm.Expr("count + ?", count)).Error
  481. err = XTWriteDB().Model(&stockFlow).Where("warehousing_detail_id = ? and good_id = ? and user_org_id = ? and patient_id = ? AND consumable_type = 7 and system_time = ?").Update(map[string]interface{}{"over_count": over_count}).Error
  482. return err
  483. }
  484. func GetWarehouseOutInfo(user_org_id int64) (info []*models.WarehouseOut, err error) {
  485. err = XTReadDB().Where("org_id = ? and status =1", 10485).Find(&info).Error
  486. return info, err
  487. }
  488. func UpdateWarehosueOutInfo(id int64, sys_record_time int64) (models.WarehouseOutInfo, error) {
  489. info := models.WarehouseOutInfo{}
  490. err := XTWriteDB().Model(&info).Where("warehouse_out_id = ? and org_id = ? ", id, 10485).Updates(map[string]interface{}{"sys_record_time": sys_record_time, "ctime": sys_record_time}).Error
  491. return info, err
  492. }